[PT1-785] Feature/anchored minimal - #229
Conversation
…time for anchored order, updated solidity
| "dependencies": { | ||
| "@1inch/delegating": "1.1.0", | ||
| "@1inch/limit-order-protocol-contract": "4.3.3", | ||
| "@1inch/limit-order-protocol-contract": "1inch/limit-order-protocol#c4970e319d309fb605185b65b36162f5ece3abd6", |
There was a problem hiding this comment.
We need to publish the npm package with the new version.
| function _anchoredTime(uint256 flaggedTime, bytes32 orderHash) private view returns (uint256) { | ||
| uint256 announcedTime = _ORDER_REGISTRATOR.announcedAt(orderHash); | ||
| if (announcedTime == 0) revert OrderNotAnnounced(); | ||
| return Math.max(flaggedTime & _ANCHOR_TIMESTAMP_MASK, announcedTime); |
There was a problem hiding this comment.
Did not get it. Which role has the flaggedTime here, why using Math.max?
There was a problem hiding this comment.
As synced, flaggedTime is not needed; here use return announcedTime;
It would be good if this will not produce one more if, to drop 3 redundant bytes though: calldata is uint32 ts with high bit not set or bytes1 of value 0x80
There was a problem hiding this comment.
Use order registrator for 0x80000000 timestamp
| const LOP_COMPILER_SETTINGS = JSON.parse(JSON.stringify(DEFAULT_COMPILER_SETTINGS)); | ||
| LOP_COMPILER_SETTINGS.version = '0.8.30'; | ||
|
|
||
| const LOW_OPTIMIZER_COMPILER_SETTINGS = JSON.parse(JSON.stringify(LOP_COMPILER_SETTINGS)); |
| ``` | ||
|
|
||
| Parameters are read from a `.env` file as `OPS_*` variables. `OPS_NETWORK` and `OPS_CHAIN_ID` are always required; each target validates its own additions, so `deploy-settlement`, for example, also needs `OPS_ROUTER_V6_ADDRESS`, `OPS_ACCESS_TOKEN_ADDRESS`, `OPS_WETH_ADDRESS` and `OPS_SETTLEMENT_OWNER_ADDRESS`. Contracts are deployed through a CREATE3 deployer so that the same address is used on every chain, which needs `OPS_CREATE3_DEPLOYER_ADDRESS` and a salt; zkSync Era does not support CREATE3 and falls back to a plain deployment. | ||
| Parameters are read from a `.env` file as `OPS_*` variables. `OPS_NETWORK` and `OPS_CHAIN_ID` are always required; each target validates its own additions, so `deploy-settlement`, for example, also needs `OPS_ROUTER_V6_ADDRESS`, `OPS_ACCESS_TOKEN_ADDRESS`, `OPS_WETH_ADDRESS`, `OPS_SETTLEMENT_OWNER_ADDRESS` and `OPS_ORDER_REGISTRATOR_ADDRESS`. The OrderRegistrator must implement the `announcedAt(bytes32)` getter introduced in Limit Order Protocol 4.3.5. Contracts are deployed through a CREATE3 deployer so that the same address is used on every chain, which needs `OPS_CREATE3_DEPLOYER_ADDRESS` and a salt; zkSync Era does not support CREATE3 and falls back to a plain deployment. |
There was a problem hiding this comment.
The OrderRegistrator must implement the
announcedAt(bytes32)getter introduced in Limit Order Protocol 4.3.5
Does it make sense to add the text here?
| await weth.connect(alice).deposit({ value: ether('1') }); | ||
|
|
||
| const settlementExtension = await deployContract('Settlement', [lopv4, accessToken, weth, owner]); | ||
| const settlementExtension = await deployContract('Settlement', [lopv4, accessToken, weth, owner, ethers.ZeroAddress]); |
There was a problem hiding this comment.
Feels like Gas measurements are not properly updated
| }); | ||
| orderRegistratorInterface.decodeFunctionResult('announcedAt', result); | ||
| } catch (error) { | ||
| throw new Error(`OrderRegistrator at ${orderRegistratorAddress} does not implement announcedAt(bytes32)`, { |
There was a problem hiding this comment.
The other deploy parameters does not have same-level validations. Is it meaningful to execute such checks for OrderRegistrator?
| * bytes3 gasBumpEstimate; | ||
| * bytes4 gasPriceEstimate; | ||
| * bytes4 auctionStartTime; | ||
| * bytes4 auctionStartTime; // top bit is the anchor flag, see `_ANCHOR_FLAG_MASK` |
There was a problem hiding this comment.
Comment inside of comment. Declare outside or remove or rename field to be self-explaining
| error InvalidResult(uint256 actual, uint256 expected); | ||
|
|
||
| constructor(IERC20 accessToken, address weth, address owner) SimpleSettlement(address(this), accessToken, weth, owner) {} | ||
| constructor(IERC20 accessToken, address weth, address owner) SimpleSettlement(address(this), accessToken, weth, owner, IOrderRegistrator(address(0))) {} |
There was a problem hiding this comment.
Why hardcoding zero-address instead of meaningful value?
| import { IOrderMixin } from "@1inch/limit-order-protocol-contract/contracts/interfaces/IOrderMixin.sol"; | ||
|
|
||
| import { IOrderRegistrator } from "@1inch/limit-order-protocol-contract/contracts/interfaces/IOrderRegistrator.sol"; | ||
| import { SimpleSettlement } from "./SimpleSettlement.sol"; |
There was a problem hiding this comment.
Broken style: there was a whitespace between module and local imports
| using Math for uint256; | ||
|
|
||
| /// @dev Top bit of a uint32 timestamp (auction start time / whitelist allowed time) opts the order | ||
| /// into anchoring: effective time = max(timestamp without the flag, OrderRegistrator.announcedAt(orderHash)). |
There was a problem hiding this comment.
Why documenting protocol behavior in natspec of random constant?
| error InvalidEstimatedTakingAmount(); | ||
| error OrderNotAnnounced(); | ||
|
|
||
| IOrderRegistrator private immutable _ORDER_REGISTRATOR; |
There was a problem hiding this comment.
Why constants - errors - immutables layout? The errors - constants - immutables would be more consistent
| * @param whitelistData Whitelist data is a tightly packed struct of the following format: | ||
| * ``` | ||
| * 4 bytes - allowed time | ||
| * 4 bytes - allowed time (top bit is the anchor flag, see `_ANCHOR_FLAG_MASK`) |
There was a problem hiding this comment.
Comments referring to another comments in another file part is hard to read
| uint80 maskedTakerAddress = uint80(uint160(taker)); | ||
| uint256 allowedTime = uint32(bytes4(whitelistData)); | ||
| if (allowedTime & _ANCHOR_FLAG_MASK != 0) { | ||
| allowedTime = _anchoredTime(allowedTime, orderHash); |
There was a problem hiding this comment.
The _anchoredTime reassigns 2 different timestamps: whitelist start timestamp and auction start timestamp which potentially are different. Is it intended? If so, that should be explicit
Change Summary
What does this PR change?
Add anchored based order via order registrator and timestamp flag