diff --git a/.github/workflows/test-metadata.yaml b/.github/workflows/test-metadata.yaml deleted file mode 100644 index f69ceb66f..000000000 --- a/.github/workflows/test-metadata.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: Test metadata - -on: [push] - -jobs: - test: - strategy: - matrix: - meta-file: [src/concrete/OrderBook.meta.json, src/concrete/GenericPoolOrderBookV3FlashBorrower.meta.json, src/concrete/GenericPoolOrderBookV3ArbOrderTaker.meta.json, src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.meta.json] - name: Test metadata - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - run: cargo install rain_cli@0.8.0 - - run: rain meta validate -i ${{ matrix.meta-file }} -m interpreter-caller-meta-v1 - diff --git a/flake.nix b/flake.nix index 03bdcdc8c..97b2a47d1 100644 --- a/flake.nix +++ b/flake.nix @@ -10,31 +10,18 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = rainix.pkgs.${system}; - - in rec { - packages = rec { - concrete-contracts = ["OrderBook" "GenericPoolOrderBookV3FlashBorrower" "GenericPoolOrderBookV3ArbOrderTaker" "RouteProcessorOrderBookV3ArbOrderTaker"]; - build-meta-cmd = contract: '' - rain meta build \ - -i <(rain meta solc artifact -c abi -i out/${contract}.sol/${contract}.json) -m solidity-abi-v2 -t json -e deflate -l en \ - -i src/concrete/${contract}.meta.json -m interpreter-caller-meta-v1 -t json -e deflate -l en \ - ''; - build-single-meta = contract: '' - ${(build-meta-cmd contract)} -o meta/${contract}.rain.meta; - ''; - - build-meta = rainix.mkTask.${system} { name = "build-meta"; body = ('' - set -x; - mkdir -p meta; - forge build --force; - '' + pkgs.lib.concatStrings (map build-single-meta concrete-contracts)); }; - - deploy-single-contract = contract: '' - forge script script/Deploy${contract}.sol:Deploy${contract} --legacy --verify --broadcast --rpc-url "''${CI_DEPLOY_RPC_URL}" --etherscan-api-key "''${EXPLORER_VERIFICATION_KEY}" \ - --sig='run(bytes)' \ - "$( ${(build-meta-cmd contract)} -E hex )" \ - ; - ''; + concrete-contracts = ["OrderBook" "GenericPoolOrderBookV3FlashBorrower" "GenericPoolOrderBookV3ArbOrderTaker" "RouteProcessorOrderBookV3ArbOrderTaker"]; + deploy-single-contract = contract: '' + forge script script/Deploy${contract}.sol:Deploy${contract} \ + --legacy \ + --verify \ + --broadcast \ + --rpc-url "''${CI_DEPLOY_RPC_URL}" \ + --etherscan-api-key "''${EXPLORER_VERIFICATION_KEY}" \ + ; + ''; + in { + packages = { deploy-contracts = rainix.mkTask.${system} { name = "deploy-contracts"; body = ('' set -euo pipefail; forge build --force; @@ -42,8 +29,12 @@ cast wallet address "''${DEPLOYMENT_KEY}"; '' + pkgs.lib.concatStrings (map deploy-single-contract concrete-contracts)); }; - default = build-meta; - ci-prep = build-meta; + ci-prep = rainix.mkTask.${system} { name = "ci-prep"; body = '' + set -euo pipefail; + forge install --shallow; + forge build --force; + ''; }; + } // rainix.packages.${system}; devShells = rainix.devShells.${system}; diff --git a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol index d4952a087..159f9a087 100644 --- a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol +++ b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol @@ -1,11 +1,8 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import {Script, console2} from "forge-std/Script.sol"; -import { - GenericPoolOrderBookV3ArbOrderTaker, - DeployerDiscoverableMetaV3ConstructionConfig -} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; +import {Script} from "forge-std/Script.sol"; +import {GenericPoolOrderBookV3ArbOrderTaker} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// @title DeployGenericPoolOrderBookV3ArbOrderTaker @@ -13,17 +10,11 @@ import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// is intended to be run on every commit by CI to a testnet such as mumbai, then /// cross chain deployed to whatever mainnet is required, by users. contract DeployGenericPoolOrderBookV3ArbOrderTaker is Script { - /// We are avoiding using ffi here, instead forcing the script runner to - /// provide the built metadata. On CI this is achieved by using the rain cli. - function run(bytes memory meta) external { + function run() external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - console2.log("GenericPoolOrderBookV3ArbOrderTaker meta hash:"); - console2.logBytes32(keccak256(meta)); - vm.startBroadcast(deployerPrivateKey); - GenericPoolOrderBookV3ArbOrderTaker deployed = - new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); + GenericPoolOrderBookV3ArbOrderTaker deployed = new GenericPoolOrderBookV3ArbOrderTaker(I9R_DEPLOYER); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol index 5f18a1719..29668f2f2 100644 --- a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol +++ b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol @@ -1,11 +1,8 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import {Script, console2} from "forge-std/Script.sol"; -import { - GenericPoolOrderBookV3FlashBorrower, - DeployerDiscoverableMetaV3ConstructionConfig -} from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; +import {Script} from "forge-std/Script.sol"; +import {GenericPoolOrderBookV3FlashBorrower} from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// @title DeployGenericPoolOrderBookV3FlashBorrower @@ -13,17 +10,11 @@ import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// is intended to be run on every commit by CI to a testnet such as mumbai, then /// cross chain deployed to whatever mainnet is required, by users. contract DeployGenericPoolOrderBookV3FlashBorrower is Script { - /// We are avoiding using ffi here, instead forcing the script runner to - /// provide the built metadata. On CI this is achieved by using the rain cli. - function run(bytes memory meta) external { + function run() external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - console2.log("DeployGenericPoolOrderBookV3FlashBorrower meta hash:"); - console2.logBytes32(keccak256(meta)); - vm.startBroadcast(deployerPrivateKey); - GenericPoolOrderBookV3FlashBorrower deployed = - new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); + GenericPoolOrderBookV3FlashBorrower deployed = new GenericPoolOrderBookV3FlashBorrower(I9R_DEPLOYER); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployOrderBook.sol b/script/DeployOrderBook.sol index f2af4a542..d3c07503c 100644 --- a/script/DeployOrderBook.sol +++ b/script/DeployOrderBook.sol @@ -1,19 +1,16 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import {Script, console2} from "forge-std/Script.sol"; -import {OrderBook, DeployerDiscoverableMetaV3ConstructionConfig} from "src/concrete/OrderBook.sol"; +import {Script} from "forge-std/Script.sol"; +import {OrderBook} from "src/concrete/OrderBook.sol"; import {I9R_DEPLOYER} from "./DeployConstants.sol"; contract DeployOrderBook is Script { - function run(bytes memory meta) external { + function run() external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - console2.log("DeployOrderBook meta hash:"); - console2.logBytes32(keccak256(meta)); - vm.startBroadcast(deployerPrivateKey); - OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); + OrderBook deployed = new OrderBook(I9R_DEPLOYER); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol index 07fef9cf7..a2934d5ff 100644 --- a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol +++ b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol @@ -1,11 +1,8 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import {Script, console2} from "forge-std/Script.sol"; -import { - RouteProcessorOrderBookV3ArbOrderTaker, - DeployerDiscoverableMetaV3ConstructionConfig -} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; +import {Script} from "forge-std/Script.sol"; +import {RouteProcessorOrderBookV3ArbOrderTaker} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// @title DeployRouteProcessorOrderBookV3ArbOrderTaker @@ -13,17 +10,11 @@ import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// is intended to be run on every commit by CI to a testnet such as mumbai, then /// cross chain deployed to whatever mainnet is required, by users. contract DeployRouteProcessorOrderBookV3ArbOrderTaker is Script { - /// We are avoiding using ffi here, instead forcing the script runner to - /// provide the built metadata. On CI this is achieved by using the rain cli. - function run(bytes memory meta) external { + function run() external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - console2.log("RouteProcessorOrderBookV3ArbOrderTaker meta hash:"); - console2.logBytes32(keccak256(meta)); - vm.startBroadcast(deployerPrivateKey); - RouteProcessorOrderBookV3ArbOrderTaker deployed = - new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); + RouteProcessorOrderBookV3ArbOrderTaker deployed = new RouteProcessorOrderBookV3ArbOrderTaker(I9R_DEPLOYER); (deployed); vm.stopBroadcast(); } diff --git a/src/abstract/OrderBookV3ArbOrderTaker.sol b/src/abstract/OrderBookV3ArbOrderTaker.sol index a8de82d20..5ffcd0aa6 100644 --- a/src/abstract/OrderBookV3ArbOrderTaker.sol +++ b/src/abstract/OrderBookV3ArbOrderTaker.sol @@ -9,11 +9,7 @@ import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {Initializable} from "openzeppelin-contracts/contracts/proxy/utils/Initializable.sol"; import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol"; -import { - DeployerDiscoverableMetaV3, - DeployerDiscoverableMetaV3ConstructionConfig, - LibMeta -} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; +import {LibDeployerDiscoverable} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import {EvaluableConfigV3, SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; import {SourceIndexV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "rain.factory/src/interface/ICloneableV2.sol"; @@ -55,7 +51,6 @@ abstract contract OrderBookV3ArbOrderTaker is ReentrancyGuard, Initializable, ICloneableV2, - DeployerDiscoverableMetaV3, ERC165 { using SafeERC20 for IERC20; @@ -67,9 +62,9 @@ abstract contract OrderBookV3ArbOrderTaker is IInterpreterV2 public sI9r; IInterpreterStoreV1 public sI9rStore; - constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config) - DeployerDiscoverableMetaV3(metaHash, config) - { + constructor(address deployer) { + LibDeployerDiscoverable.touchDeployerV3(deployer); + _disableInitializers(); } diff --git a/src/abstract/OrderBookV3FlashBorrower.sol b/src/abstract/OrderBookV3FlashBorrower.sol index dfb3f08d2..1c5eacb09 100644 --- a/src/abstract/OrderBookV3FlashBorrower.sol +++ b/src/abstract/OrderBookV3FlashBorrower.sol @@ -7,11 +7,7 @@ import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol"; import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {ReentrancyGuard} from "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol"; import {Initializable} from "openzeppelin-contracts/contracts/proxy/utils/Initializable.sol"; -import { - DeployerDiscoverableMetaV3, - DeployerDiscoverableMetaV3ConstructionConfig, - LibMeta -} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; +import {LibDeployerDiscoverable} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import {LibEncodedDispatch, EncodedDispatch} from "rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; import {LibContext} from "rain.interpreter/src/lib/caller/LibContext.sol"; import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol"; @@ -98,7 +94,6 @@ abstract contract OrderBookV3FlashBorrower is ICloneableV2, ReentrancyGuard, Initializable, - DeployerDiscoverableMetaV3, ERC165 { using Address for address; @@ -119,9 +114,9 @@ abstract contract OrderBookV3FlashBorrower is /// The associated store for the interpreter. IInterpreterStoreV1 public sI9rStore; - constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config) - DeployerDiscoverableMetaV3(metaHash, config) - { + constructor(address deployer) { + LibDeployerDiscoverable.touchDeployerV3(deployer); + // Arb contracts are expected to be cloned proxies so allowing // initialization of the implementation is a security risk. _disableInitializers(); diff --git a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.meta.json b/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.meta.json deleted file mode 100644 index 23cd68e4b..000000000 --- a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.meta.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "Generic pool order book v3 arb order taker", - "abiName": "GenericPoolOrderBookV3ArbOrderTaker", - "desc": "A generic order taker that takes loans after takeOrders() execution from an order book and can source external liquidity from any basic onchain AMM pool to cover the loan and specific orderbook orders. Supports expression based access gating.", - "alias": "generic-pool-order-book-v3-arb-order-taker", - "methods": [{ - "name": "stub", - "abiName": "stub", - "desc": "Stub.", - "inputs": [{ - "name": "stub", - "abiName": "stub", - "desc": "Stub.", - "path": "stub" - }], - "expressions": [] - }] -} \ No newline at end of file diff --git a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol b/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol index 8ae3e077e..5ee6dc541 100644 --- a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol +++ b/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol @@ -6,15 +6,11 @@ import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.so import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; import {Address} from "lib/openzeppelin-contracts/contracts/utils/Address.sol"; -bytes32 constant CALLER_META_HASH = bytes32(0xe1d075e6f17f6706d942759ec359deb7f354ab4ac55e58eda2870c0ab3a89fa5); - contract GenericPoolOrderBookV3ArbOrderTaker is OrderBookV3ArbOrderTaker { using SafeERC20 for IERC20; using Address for address; - constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) - OrderBookV3ArbOrderTaker(CALLER_META_HASH, config) - {} + constructor(address deployer) OrderBookV3ArbOrderTaker(deployer) {} /// @inheritdoc OrderBookV3ArbOrderTaker function onTakeOrders( diff --git a/src/concrete/GenericPoolOrderBookV3FlashBorrower.meta.json b/src/concrete/GenericPoolOrderBookV3FlashBorrower.meta.json deleted file mode 100644 index 6aa19f374..000000000 --- a/src/concrete/GenericPoolOrderBookV3FlashBorrower.meta.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "Generic pool order book v3 flash borrower", - "abiName": "GenericPoolOrderBookV3FlashBorrower", - "desc": "A generic flash borrower that takes loans from an order book and can source external liquidity from any basic onchain AMM pool to cover the loan and specific orderbook orders. Supports expression based access gating.", - "alias": "generic-pool-order-book-v3-flash-borrower", - "methods": [{ - "name": "stub", - "abiName": "stub", - "desc": "Stub.", - "inputs": [{ - "name": "stub", - "abiName": "stub", - "desc": "Stub.", - "path": "stub" - }], - "expressions": [] - }] - } diff --git a/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol b/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol index 3ce2eea61..d820920bf 100644 --- a/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol +++ b/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol @@ -1,15 +1,19 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "src/interface/ierc3156/IERC3156FlashLender.sol"; -import "src/interface/ierc3156/IERC3156FlashBorrower.sol"; - -import "src/abstract/OrderBookV3FlashBorrower.sol"; - -/// @dev Metadata hash for `DeployerDiscoverableMetaV1`. -/// - ABI for GenericPoolOrderBookV3FlashBorrower -/// - Interpreter caller metadata V1 for GenericPoolOrderBookV3FlashBorrower -bytes32 constant CALLER_META_HASH = bytes32(0x52cdec296c4ecb0b2452c9e314df50e1b5d52fef03927934b7426ff6f150f0fe); +import {IERC3156FlashLender} from "src/interface/ierc3156/IERC3156FlashLender.sol"; +import {IERC3156FlashBorrower} from "src/interface/ierc3156/IERC3156FlashBorrower.sol"; + +import { + OrderBookV3FlashBorrower, + OrderBookV3FlashBorrowerConfigV2, + ICloneableV2, + MinimumOutput, + SafeERC20, + IERC20, + Address, + TakeOrdersConfigV2 +} from "src/abstract/OrderBookV3FlashBorrower.sol"; /// @title GenericPoolOrderBookV3FlashBorrower /// Implements the OrderBookV3FlashBorrower interface for a external liquidity @@ -25,9 +29,7 @@ contract GenericPoolOrderBookV3FlashBorrower is OrderBookV3FlashBorrower { using SafeERC20 for IERC20; using Address for address; - constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) - OrderBookV3FlashBorrower(CALLER_META_HASH, config) - {} + constructor(address deployer) OrderBookV3FlashBorrower(deployer) {} /// @inheritdoc OrderBookV3FlashBorrower function _exchange(TakeOrdersConfigV2 memory takeOrders, bytes memory exchangeData) internal virtual override { diff --git a/src/concrete/OrderBook.meta.json b/src/concrete/OrderBook.meta.json deleted file mode 100644 index b282b7ac8..000000000 --- a/src/concrete/OrderBook.meta.json +++ /dev/null @@ -1,159 +0,0 @@ -{ - "name": "Order Book", - "abiName": "OrderBook", - "desc": "An orderbook that deploys strategies represented as interpreter expressions rather than individual orders. The order book contract itself behaves similarly to an ERC4626 vault but with much more fine grained control over how tokens are allocated and moved internally by their owners, and without any concept of 'shares'. Token owners MAY deposit and withdraw their tokens under arbitrary vault IDs on a per-token basis, then define orders that specify how tokens move between vaults according to an expression. The expression returns a maximum amount and a token input/output ratio from the perpective of the order. When two expressions intersect, as in their ratios are the inverse of each other, then tokens can move between vaults. \n For example, consider order A with input TKNA and output TKNB with a constant ratio of 100:1. This order in isolation has no ability to move tokens. If an order B appears with input TKNB and output TKNA and a ratio of 1:100 then this is a perfect match with order A. In this case 100 TKNA will move from order B to order A and 1 TKNB will move from order A to order B. \n IO ratios are always specified as input:output and are 18 decimal fixed point values. The maximum amount that can be moved in the current clearance is also set by the order expression as an 18 decimal fixed point value. \n Typically orders will not clear when their match is exactly 1:1 as the clearer needs to pay gas to process the match. Each order will get exactly the ratio it calculates when it does clear so if there is _overlap_ in the ratios then the clearer keeps the difference. In our above example, consider order B asking a ratio of 1:110 instead of 1:100. In this case 100 TKNA will move from order B to order A and 10 TKNA will move to the clearer's vault and 1 TKNB will move from order A to order B. In the case of fixed prices this is not very interesting as order B could more simply take order A directly for cheaper rather than involving a third party. Indeed, Orderbook supports a direct 'take orders' method that works similar to a 'market buy'. In the case of dynamic expression based ratios, it allows both order A and order B to clear non-interactively according to their strategy, trading off active management, dealing with front-running, MEV, etc. for zero-gas and exact-ratio clearance. \n The general invariant for clearing and take orders is: \n ``` \n ratioA = InputA / OutputA \n ratioB = InputB / OutputB \n ratioA * ratioB = ( InputA * InputB ) / ( OutputA * OutputB ) \n OutputA >= InputB \n OutputB >= InputA \n So ratioA * ratioB <= 1 \n ``` \n Orderbook is `IERC3156FlashLender` compliant with a 0 fee flash loan implementation to allow external liquidity from other onchain DEXes to match against orderbook expressions. All deposited tokens across all vaults are available for flashloan, the flashloan MAY BE REPAID BY CALLING TAKE ORDER such that Orderbook's liability to its vaults is decreased by an incoming trade from the flashloan borrower. See `ZeroExOrderBookFlashBorrower` for an example of how this works in practise. \nOrderbook supports many to many input/output token relationship, for example some order can specify an array of stables it would be willing to accept in return for some ETH. This removes the need for a combinatorial explosion of order strategies between like assets but introduces the issue of token decimal handling. End users understand that 'one' USDT is roughly equal to 'one' DAI, but onchain this is incorrect by _12 orders of magnitude_. This is because 'one' DAI is `1e18` tokens and 'one' USDT is `1e6` tokens. The orderbook is allowing orders to deploy expressions that define _economic equivalence_ but this doesn't map 1:1 with numeric equivalence in a many to many setup behind token decimal convensions. The solution is to require that end users who place orders provide the decimals of each token they include in their valid IO lists, and to calculate all amounts and ratios in their expressions _as though they were 18 decimal fixed point values_. Orderbook will then automatically rescale the expression values before applying the final vault movements. If an order provides the 'wrong' decimal values for some token then it will simply calculate its own ratios and amounts incorrectly which will either lead to no matching orders or a very bad trade for the order owner. There is no way that misrepresenting decimals can attack some other order by a counterparty. Orderbook DOES NOT read decimals from tokens onchain because A. this would be gas for an external call to a cold token contract and B. the ERC20 standard specifically states NOT to read decimals from the interface onchain. \nWhen two orders clear there are NO TOKEN MOVEMENTS, only internal vault balances are updated from the input and output vaults. Typically this results in less gas per clear than calling external token transfers and also avoids issues with reentrancy, allowances, external balances etc. This also means that REBASING TOKENS AND TOKENS WITH DYNAMIC BALANCE ARE NOT SUPPORTED. Orderbook ONLY WORKS IF TOKEN BALANCES ARE 1:1 WITH ADDITION/SUBTRACTION PER VAULT MOVEMENT. \nDust due to rounding errors always favours the order. Output max is rounded down and IO ratios are rounded up. Input and output amounts are always converted to absolute values before applying to vault balances such that orderbook always retains fully collateralised inventory of underlying token balances to support withdrawals, with the caveat that dynamic token balanes are not supported. \nWhen an order clears it is NOT removed. Orders remain active until the owner deactivates them. This is gas efficient as order owners MAY deposit more tokens in a vault with an order against it many times and the order strategy will continue to be clearable according to its expression. As vault IDs are `uint256` values there are effectively infinite possible vaults for any token so there is no limit to how many active orders any address can have at one time. This also allows orders to be daisy chained arbitrarily where output vaults for some order are the input vaults for some other order. \nExpression storage is namespaced by order owner, so gets and sets are unique to each onchain address. Order owners MUST TAKE CARE not to override their storage sets globally across all their orders, which they can do most simply by hashing the order hash into their get/set keys inside the expression. This gives maximum flexibility for shared state across orders without allowing order owners to attack and overwrite values stored by orders placed by their counterparty. \nNote that each order specifies its own interpreter and deployer so the owner is responsible for not corrupting their own calculations with bad interpreters. This also means the Orderbook MUST assume the interpreter, and notably the interpreter's store, is malicious and guard against reentrancy etc. \nAs Orderbook supports any expression that can run on any `IInterpreterV1` and counterparties are available to the order, order strategies are free to implement KYC/membership, tracking, distributions, stock, buybacks, etc. etc.", - "alias": "orderbook", - "methods": [ - { - "name": "addOrder", - "abiName": "addOrder", - "desc": "Adds a new order", - "inputs": [ - { - "name": "Valid inputs", - "abiName": "validInputs", - "desc": "Token address, vault ID and decimals combinations that are valid inputs for this Order.", - "path": "[25].inputs[0].components[0]" - }, - { - "name": "Valid outputs", - "abiName": "validOutputs", - "desc": "Token address, vault ID and decimals combinations that are valid outputs for this Order.", - "path": "[25].inputs[0].components[1]" - } - ], - "expressions": [ - { - "name": "Order", - "abiName": "evaluableConfig", - "desc": "An expression for the order. Orderbook context is actually fairly complex. The calling context column is populated before calculate order, but the remaining columns are only available to handle IO as they depend on the full evaluation of calculuate order, and cross referencing against the same from the counterparty, as well as accounting limits such as current vault balances, etc. The token address and decimals for vault inputs and outputs IS available to the calculate order entrypoint, but not the final vault balances/diff.", - "path": "[25].inputs[0].components[2]", - "signedContext": true, - "callerContext": false, - "contextColumns": [ - { - "name": "Base", - "desc": "Base context column.", - "alias": "base", - "cells": [ - { - "name": "Caller", - "desc": "The contract or EOA that called OrderBook.", - "alias": "orderbook-caller-address" - }, - { - "name": "OrderBook Contract", - "desc": "The address of the OrderBook contract.", - "alias": "orderbook-contract-address" - } - ] - }, - { - "name": "Calling context", - "desc": "Contextual data available to both calculate order and handle IO. The order hash, order owner and order counterparty. IMPORTANT NOTE that the typical base context of an order with the caller will often be an unrelated clearer of the order rather than the owner or counterparty.", - "alias": "calling-context", - "cells": [ - { - "name": "Order hash", - "desc": "The hash of the order.", - "alias": "order-hash" - }, - { - "name": "Order owner address", - "desc": "The address of the owner of the order.", - "alias": "order-owner-address" - }, - { - "name": "Counterparty", - "desc": "The address of the counterparty of the order.", - "alias": "counterparty-address" - } - ] - }, - { - "name": "Calculations", - "desc": "Calculations column contains the DECIMAL RESCALED calculations but otherwise provided as-is according to calculate order entrypoint.", - "alias": "calculations", - "cells": [ - { - "name": "Order output max", - "desc": "The output max rescaled to 18 decimals and capped by vault balance.", - "alias": "order-output-max" - }, - { - "name": "Order IO ratio", - "desc": "The IO ratio rescaled to 18 decimals.", - "alias": "order-io-ratio" - } - ] - }, - { - "name": "Vault inputs", - "desc": "Vault inputs are the literal token amounts and vault balances before and after for the input token from the perspective of the order. MAY be significantly different to the calculated amount due to insufficient vault balances from either the owner or counterparty, etc.", - "alias": "vault-inputs", - "cells": [ - { - "name": "Vault input token address", - "desc": "The vault input token address.", - "alias": "vault-input-token-address" - }, - { - "name": "Vault input token decimals", - "desc": "The vault input token decimals.", - "alias": "vault-input-token-decimals" - }, - { - "name": "Vault input ID", - "desc": "The vault input ID", - "alias": "vault-input-id" - }, - { - "name": "Vault input balance before", - "desc": "The balance of the vault for this order's input token, before clearing", - "alias": "vault-input-balance-before" - }, - { - "name": "Vault input balance increase", - "desc": "The amount the input vault balance increased by.", - "alias": "vault-input-balance-increase" - } - ] - }, - { - "name": "Vault outputs", - "desc": "Vault outputs are the same as vault inputs but for the output token from the perspective of the order.", - "alias": "vault-outputs", - "cells": [ - { - "name": "Vault output token address", - "desc": "The vault output token address.", - "alias": "vault-output-token-address" - }, - { - "name": "Vault output token decimals", - "desc": "The vault output token decimals.", - "alias": "vault-output-token-decimals" - }, - { - "name": "Vault output ID", - "desc": "The vault output ID", - "alias": "vault-output-id" - }, - { - "name": "Vault output balance before", - "desc": "The balance of the vault for this order's output token, before clearing", - "alias": "vault-output-balance-before" - }, - { - "name": "Vault output balance decrease", - "desc": "The amount the output vault balance decreased by.", - "alias": "vault-output-balance-decrease" - } - ] - } - ] - } - ] - } - ] -} diff --git a/src/concrete/OrderBook.sol b/src/concrete/OrderBook.sol index e33f1aecc..76d2f8d6d 100644 --- a/src/concrete/OrderBook.sol +++ b/src/concrete/OrderBook.sol @@ -13,11 +13,7 @@ import {LibFixedPointDecimalArithmeticOpenZeppelin} from import {LibFixedPointDecimalScale} from "rain.math.fixedpoint/lib/LibFixedPointDecimalScale.sol"; import {LibEncodedDispatch, EncodedDispatch} from "rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; import {LibContext} from "rain.interpreter/src/lib/caller/LibContext.sol"; -import { - DeployerDiscoverableMetaV3, - DeployerDiscoverableMetaV3ConstructionConfig, - LibMeta -} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; +import {LibDeployerDiscoverable} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol"; import { SourceIndexV2, StateNamespace, IInterpreterV2 @@ -42,6 +38,8 @@ import {EvaluableV2} from "rain.interpreter/src/lib/caller/LibEvaluable.sol"; import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterStoreV1.sol"; import {IExpressionDeployerV3} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; import {LibNamespace} from "rain.interpreter/src/lib/ns/LibNamespace.sol"; +import {LibMeta} from "rain.metadata/LibMeta.sol"; +import {IMetaV1} from "rain.metadata/IMetaV1.sol"; /// This will exist in a future version of Open Zeppelin if their main branch is /// to be believed. @@ -154,9 +152,6 @@ uint256 constant CONTEXT_VAULT_IO_BALANCE_DIFF = 4; /// @dev Length of a vault IO column. uint256 constant CONTEXT_VAULT_IO_ROWS = 5; -/// @dev Hash of the caller contract metadata for construction. -bytes32 constant CALLER_META_HASH = bytes32(0x4383dd3c5a557f161038940161f880963e1d4a31e8f2da771427b891956ad831); - /// All information resulting from an order calculation that allows for vault IO /// to be calculated and applied, then the handle IO entrypoint to be dispatched. /// @param outputMax The UNSCALED maximum output calculated by the order @@ -203,7 +198,7 @@ type Input18Amount is uint256; /// @title OrderBook /// See `IOrderBookV1` for more documentation. -contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3FlashLender, DeployerDiscoverableMetaV3 { +contract OrderBook is IOrderBookV3, IMetaV1, ReentrancyGuard, Multicall, OrderBookV3FlashLender { using LibUint256Array for uint256[]; using SafeERC20 for IERC20; using LibOrder for OrderV2; @@ -235,9 +230,9 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash /// Open Zeppelin upgradeable contracts. Orderbook itself does NOT support /// factory deployments as each order is a unique expression deployment /// rather than needing to wrap up expressions with proxies. - constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) - DeployerDiscoverableMetaV3(CALLER_META_HASH, config) - {} + constructor(address deployer) { + LibDeployerDiscoverable.touchDeployerV3(deployer); + } /// @inheritdoc IOrderBookV3 function vaultBalance(address owner, address token, uint256 vaultId) external view override returns (uint256) { diff --git a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.meta.json b/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.meta.json deleted file mode 100644 index 3f534d2f2..000000000 --- a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.meta.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "RouteProcessor order book v3 arb order taker", - "abiName": "RouteProcessorOrderBookV3ArbOrderTaker", - "desc": "A RouteProcessor specific order taker contract for bots to arb with. Supports expression based access gating.", - "alias": "route-processor-order-book-v3-arb-order-taker", - "methods": [{ - "name": "stub", - "abiName": "stub", - "desc": "Stub.", - "inputs": [{ - "name": "stub", - "abiName": "stub", - "desc": "Stub.", - "path": "stub" - }], - "expressions": [] - }] -} \ No newline at end of file diff --git a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol b/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol index d277b2be8..250b5e529 100644 --- a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol +++ b/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol @@ -1,24 +1,24 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "sushixswap-v2/src/interfaces/IRouteProcessor.sol"; +import {IRouteProcessor} from "sushixswap-v2/src/interfaces/IRouteProcessor.sol"; -import "../abstract/OrderBookV3ArbOrderTaker.sol"; +import { + OrderBookV3ArbOrderTaker, + OrderBookV3ArbOrderTakerConfigV1, + MinimumOutput +} from "../abstract/OrderBookV3ArbOrderTaker.sol"; import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; import {Address} from "lib/openzeppelin-contracts/contracts/utils/Address.sol"; -bytes32 constant CALLER_META_HASH = bytes32(0xb5923e408032e4f76298ae26c496091f2d8f16a7c968bbd5ee83bf90b5aca00e); - contract RouteProcessorOrderBookV3ArbOrderTaker is OrderBookV3ArbOrderTaker { using SafeERC20 for IERC20; using Address for address; IRouteProcessor public sRouteProcessor; - constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) - OrderBookV3ArbOrderTaker(CALLER_META_HASH, config) - {} + constructor(address deployer) OrderBookV3ArbOrderTaker(deployer) {} /// @inheritdoc OrderBookV3ArbOrderTaker function _beforeInitialize(bytes memory data) internal virtual override { diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol index 5a3127c55..876d17493 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol @@ -5,7 +5,6 @@ import {GenericPoolOrderBookV3ArbOrderTakerTest} from "test/util/abstract/Generi import { GenericPoolOrderBookV3ArbOrderTaker, - DeployerDiscoverableMetaV3ConstructionConfig, OrderBookV3ArbOrderTakerConfigV1, MinimumOutput } from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; diff --git a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol index 3388be4d8..4eca90f36 100644 --- a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol @@ -3,13 +3,8 @@ pragma solidity =0.8.19; import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol"; -import {GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_META_PATH} from - "test/util/lib/LibGenericPoolOrderBookV3FlashBorrowerConstants.sol"; - import { GenericPoolOrderBookV3FlashBorrower, - DeployerDiscoverableMetaV3ConstructionConfig, - CALLER_META_HASH as GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_CALLER_META_HASH, MinimumOutput, ICloneableV2, OrderBookV3FlashBorrowerConfigV2 @@ -24,11 +19,10 @@ import { contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) { - (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) = buildConstructorConfig( - GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_META_PATH, - GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_CALLER_META_HASH - ); - return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3FlashBorrower(config))); + address deployer = buildConstructorConfig(); + address iArb = address(new GenericPoolOrderBookV3FlashBorrower(deployer)); + vm.label(iArb, "iArb"); + return ArbTestConstructorConfig(deployer, iArb); } constructor() ArbTest(buildArbTestConstructorConfig()) { diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index 4d780163d..d72cc9952 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -12,7 +12,6 @@ import { } from "src/interface/unstable/IOrderBookV3.sol"; import { RouteProcessorOrderBookV3ArbOrderTaker, - DeployerDiscoverableMetaV3ConstructionConfig, OrderBookV3ArbOrderTakerConfigV1, MinimumOutput } from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index 46a3986b8..42cf25827 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -4,13 +4,17 @@ pragma solidity =0.8.19; import {Test, console2} from "forge-std/Test.sol"; import {Clones} from "openzeppelin-contracts/contracts/proxy/Clones.sol"; -import "test/util/lib/LibTestConstants.sol"; -import {DeployerDiscoverableMetaV3ConstructionConfig} from - "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; +import {REVERTING_MOCK_BYTECODE} from "test/util/lib/LibTestConstants.sol"; import {IExpressionDeployerV3} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; -import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; -import "test/util/concrete/Refundoor.sol"; -import "test/util/concrete/FlashLendingMockOrderBook.sol"; +import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; +import {Refundoor} from "test/util/concrete/Refundoor.sol"; +import { + FlashLendingMockOrderBook, + OrderV2, + TakeOrderConfigV2, + IO, + SignedContextV1 +} from "test/util/concrete/FlashLendingMockOrderBook.sol"; contract Token is ERC20 { constructor() ERC20("Token", "TKN") {} @@ -36,19 +40,24 @@ abstract contract ArbTest is Test { constructor(ArbTestConstructorConfig memory config) { iDeployer = config.deployer; + vm.label(iDeployer, "iDeployer"); iImplementation = config.implementation; + vm.label(iImplementation, "iImplementation"); iArb = Clones.clone(iImplementation); + vm.label(iArb, "iArb"); iTakerInput = new Token(); + vm.label(address(iTakerInput), "iTakerInput"); iTakerOutput = new Token(); + vm.label(address(iTakerOutput), "iTakerOutput"); iRefundoor = address(new Refundoor()); + vm.label(iRefundoor, "iRefundoor"); iOrderBook = new FlashLendingMockOrderBook(); + vm.label(address(iOrderBook), "iOrderBook"); } - function buildConstructorConfig(string memory metaPath, bytes32 expectedHash) - internal - returns (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) - { + function buildConstructorConfig() internal returns (address deployer) { deployer = address(uint160(uint256(keccak256("deployer.rain.test")))); + vm.label(deployer, "deployer"); // All non-mocked calls will revert. vm.etch(deployer, REVERTING_MOCK_BYTECODE); vm.mockCall( @@ -57,16 +66,6 @@ abstract contract ArbTest is Test { // Don't need any io for the "before arb" expression. abi.encode(address(0), address(0), address(0), "0000") ); - bytes memory meta = vm.readFileBinary(metaPath); - bytes32 metaHash = keccak256(meta); - if (metaHash != expectedHash) { - console2.log("ArbTest meta hash:", metaPath); - console2.logBytes32(metaHash); - console2.log("expected ArbTest meta hash:"); - console2.logBytes32(expectedHash); - revert("ArbTest: invalid meta hash"); - } - config = DeployerDiscoverableMetaV3ConstructionConfig(deployer, meta); } function buildTakeOrderConfig(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) diff --git a/test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol b/test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol index 272336b7f..9ca82bd5b 100644 --- a/test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol +++ b/test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol @@ -4,9 +4,7 @@ pragma solidity =0.8.19; import {ArbTest, ArbTestConstructorConfig} from "./ArbTest.sol"; import { GenericPoolOrderBookV3ArbOrderTaker, - DeployerDiscoverableMetaV3ConstructionConfig, - OrderBookV3ArbOrderTakerConfigV1, - CALLER_META_HASH as GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_CALLER_META_HASH + OrderBookV3ArbOrderTakerConfigV1 } from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; import { OrderV2, @@ -16,16 +14,11 @@ import { TakeOrdersConfigV2 } from "src/interface/unstable/IOrderBookV3.sol"; import {ICloneableV2} from "rain.factory/src/interface/ICloneableV2.sol"; -import {GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH} from - "test/util/lib/LibGenericPoolOrderBookV3ArbOrderTakerConstants.sol"; contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) { - (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) = buildConstructorConfig( - GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH, - GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_CALLER_META_HASH - ); - return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3ArbOrderTaker(config))); + address deployer = buildConstructorConfig(); + return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3ArbOrderTaker(deployer))); } constructor() ArbTest(buildArbTestConstructorConfig()) { diff --git a/test/util/abstract/IOrderBookV3Stub.sol b/test/util/abstract/IOrderBookV3Stub.sol index 963543d73..de6320c15 100644 --- a/test/util/abstract/IOrderBookV3Stub.sol +++ b/test/util/abstract/IOrderBookV3Stub.sol @@ -1,7 +1,16 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "src/interface/unstable/IOrderBookV3.sol"; +import { + IOrderBookV3, + OrderConfigV2, + OrderV2, + ClearConfig, + SignedContextV1, + IERC3156FlashBorrower, + TakeOrdersConfigV2, + IERC3156FlashLender +} from "src/interface/unstable/IOrderBookV3.sol"; abstract contract IOrderBookV3Stub is IOrderBookV3 { /// @inheritdoc IOrderBookV3 diff --git a/test/util/abstract/OrderBookExternalMockTest.sol b/test/util/abstract/OrderBookExternalMockTest.sol index e8108b4b6..6d2263acd 100644 --- a/test/util/abstract/OrderBookExternalMockTest.sol +++ b/test/util/abstract/OrderBookExternalMockTest.sol @@ -8,7 +8,6 @@ import {IExpressionDeployerV3} from "rain.interpreter/src/interface/unstable/IEx import {IMetaV1} from "rain.metadata/LibMeta.sol"; import {REVERTING_MOCK_BYTECODE} from "test/util/lib/LibTestConstants.sol"; -import {ORDER_BOOK_META_PATH} from "test/util/lib/LibOrderBookConstants.sol"; import {IOrderBookV3Stub} from "test/util/abstract/IOrderBookV3Stub.sol"; import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; import {IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; @@ -16,9 +15,7 @@ import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterSt import {IOrderBookV3, OrderConfigV2, OrderV2} from "src/interface/unstable/IOrderBookV3.sol"; import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {LibOrder} from "src/lib/LibOrder.sol"; -import {OrderBook, CALLER_META_HASH as ORDERBOOK_CALLER_META_HASH} from "src/concrete/OrderBook.sol"; -import {DeployerDiscoverableMetaV3ConstructionConfig} from - "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; +import {OrderBook} from "src/concrete/OrderBook.sol"; /// @title OrderBookExternalTest /// Abstract contract that performs common setup needed for testing an orderbook @@ -53,16 +50,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), abi.encode(iInterpreter, iStore, address(0), "00020000") ); - bytes memory meta = vm.readFileBinary(ORDER_BOOK_META_PATH); - bytes32 metaHash = keccak256(meta); - if (metaHash != ORDERBOOK_CALLER_META_HASH) { - console2.log("OrderBookExternalMockTest orderbook meta hash:"); - console2.logBytes(abi.encodePacked(metaHash)); - console2.log("expected OrderBookExternalMockTest orderbook meta hash:"); - console2.logBytes(abi.encodePacked(ORDERBOOK_CALLER_META_HASH)); - } - iOrderbook = - IOrderBookV3(address(new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(address(iDeployer), meta)))); + iOrderbook = IOrderBookV3(address(new OrderBook(address(iDeployer)))); iToken0 = IERC20(address(uint160(uint256(keccak256("token0.rain.test"))))); vm.etch(address(iToken0), REVERTING_MOCK_BYTECODE); diff --git a/test/util/abstract/OrderBookExternalRealTest.sol b/test/util/abstract/OrderBookExternalRealTest.sol index ebc3c50d6..5de84dee9 100644 --- a/test/util/abstract/OrderBookExternalRealTest.sol +++ b/test/util/abstract/OrderBookExternalRealTest.sol @@ -11,18 +11,12 @@ import { } from "rain.interpreter/src/concrete/RainterpreterExpressionDeployerNPE2.sol"; import {LibAllStandardOpsNP} from "rain.interpreter/src/lib/op/LibAllStandardOpsNP.sol"; import {REVERTING_MOCK_BYTECODE} from "test/util/lib/LibTestConstants.sol"; -import {ORDER_BOOK_META_PATH} from "test/util/lib/LibOrderBookConstants.sol"; import {IOrderBookV3Stub} from "test/util/abstract/IOrderBookV3Stub.sol"; import {IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterStoreV1.sol"; import {IExpressionDeployerV3} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; import {IOrderBookV3} from "src/interface/unstable/IOrderBookV3.sol"; -import { - OrderBook, - IERC20, - DeployerDiscoverableMetaV3ConstructionConfig, - CALLER_META_HASH as ORDERBOOK_CALLER_META_HASH -} from "src/concrete/OrderBook.sol"; +import {OrderBook, IERC20} from "src/concrete/OrderBook.sol"; import {IERC1820Registry} from "rain.erc1820/interface/IERC1820Registry.sol"; import {IERC1820_REGISTRY} from "rain.erc1820/lib/LibIERC1820.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; @@ -71,17 +65,7 @@ abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { ) ) ); - bytes memory orderbookMeta = vm.readFileBinary(ORDER_BOOK_META_PATH); - bytes32 orderbookMetaHash = keccak256(orderbookMeta); - if (orderbookMetaHash != ORDERBOOK_CALLER_META_HASH) { - console2.log("orderbook meta hash:"); - console2.logBytes(abi.encodePacked(orderbookMetaHash)); - console2.log("expected orderbook meta hash:"); - console2.logBytes(abi.encodePacked(ORDERBOOK_CALLER_META_HASH)); - } - iOrderbook = IOrderBookV3( - address(new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(address(iDeployer), orderbookMeta))) - ); + iOrderbook = IOrderBookV3(address(new OrderBook(address(iDeployer)))); iToken0 = IERC20(address(uint160(uint256(keccak256("token0.rain.test"))))); vm.etch(address(iToken0), REVERTING_MOCK_BYTECODE); diff --git a/test/util/abstract/OrderBookSelfTest.sol b/test/util/abstract/OrderBookSelfTest.sol index 2eede248c..68fb50c28 100644 --- a/test/util/abstract/OrderBookSelfTest.sol +++ b/test/util/abstract/OrderBookSelfTest.sol @@ -1,12 +1,11 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "lib/forge-std/src/Test.sol"; +import {Test} from "lib/forge-std/src/Test.sol"; -import "test/util/lib/LibTestConstants.sol"; -import "test/util/lib/LibOrderBookConstants.sol"; +import {REVERTING_MOCK_BYTECODE} from "test/util/lib/LibTestConstants.sol"; -import "src/concrete/OrderBook.sol"; +import {OrderBook, IExpressionDeployerV3} from "src/concrete/OrderBook.sol"; /// @title OrderBookSelfTest /// Abstract contract that is an `OrderBook` and can be used to test itself. @@ -26,11 +25,5 @@ abstract contract OrderBookSelfTest is Test, OrderBook { vm.resumeGasMetering(); } - function constructMeta() internal returns (bytes memory meta) { - vm.pauseGasMetering(); - meta = vm.readFileBinary(ORDER_BOOK_META_PATH); - vm.resumeGasMetering(); - } - - constructor() OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(constructDeployer(), constructMeta())) {} + constructor() OrderBook(constructDeployer()) {} } diff --git a/test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol b/test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol index 8c0330958..1587b3870 100644 --- a/test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol +++ b/test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol @@ -4,9 +4,7 @@ pragma solidity =0.8.19; import {ArbTest, ArbTestConstructorConfig} from "./ArbTest.sol"; import { RouteProcessorOrderBookV3ArbOrderTaker, - DeployerDiscoverableMetaV3ConstructionConfig, - OrderBookV3ArbOrderTakerConfigV1, - CALLER_META_HASH as ROUTE_PROCESSOR_ORDER_BOOK_V3_ARB_ORDER_TAKER_CALLER_META_HASH + OrderBookV3ArbOrderTakerConfigV1 } from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; import { OrderV2, @@ -16,16 +14,11 @@ import { TakeOrdersConfigV2 } from "src/interface/unstable/IOrderBookV3.sol"; import {ICloneableV2} from "rain.factory/src/interface/ICloneableV2.sol"; -import {ROUTE_PROCESSOR_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH} from - "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol"; contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) { - (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) = buildConstructorConfig( - ROUTE_PROCESSOR_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH, - ROUTE_PROCESSOR_ORDER_BOOK_V3_ARB_ORDER_TAKER_CALLER_META_HASH - ); - return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config))); + address deployer = buildConstructorConfig(); + return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(deployer))); } constructor() ArbTest(buildArbTestConstructorConfig()) { diff --git a/test/util/lib/LibGenericPoolOrderBookV3ArbOrderTakerConstants.sol b/test/util/lib/LibGenericPoolOrderBookV3ArbOrderTakerConstants.sol deleted file mode 100644 index 229519c74..000000000 --- a/test/util/lib/LibGenericPoolOrderBookV3ArbOrderTakerConstants.sol +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-License-Identifier: CAL -pragma solidity ^0.8.18; - -string constant GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH = - "meta/GenericPoolOrderBookV3ArbOrderTaker.rain.meta"; diff --git a/test/util/lib/LibGenericPoolOrderBookV3FlashBorrowerConstants.sol b/test/util/lib/LibGenericPoolOrderBookV3FlashBorrowerConstants.sol deleted file mode 100644 index 0467a8199..000000000 --- a/test/util/lib/LibGenericPoolOrderBookV3FlashBorrowerConstants.sol +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-License-Identifier: CAL -pragma solidity ^0.8.18; - -string constant GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_META_PATH = - "meta/GenericPoolOrderBookV3FlashBorrower.rain.meta"; diff --git a/test/util/lib/LibOrderBookConstants.sol b/test/util/lib/LibOrderBookConstants.sol deleted file mode 100644 index 7e3dff10d..000000000 --- a/test/util/lib/LibOrderBookConstants.sol +++ /dev/null @@ -1,4 +0,0 @@ -// SPDX-License-Identifier: CAL -pragma solidity ^0.8.18; - -string constant ORDER_BOOK_META_PATH = "meta/OrderBook.rain.meta"; diff --git a/test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol b/test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol deleted file mode 100644 index d89752cf7..000000000 --- a/test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-License-Identifier: CAL -pragma solidity ^0.8.18; - -string constant ROUTE_PROCESSOR_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH = - "meta/RouteProcessorOrderBookV3ArbOrderTaker.rain.meta";