From fe3fa90a723d491154e319b36656a5fea1dcb3e3 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 21 Nov 2023 16:01:01 +0400 Subject: [PATCH 01/14] update i9r --- .gitmodules | 6 ++--- lib/rain.interpreter | 2 +- ...loyGenericPoolOrderBookV3ArbOrderTaker.sol | 2 +- ...loyGenericPoolOrderBookV3FlashBorrower.sol | 2 +- script/DeployOrderBook.sol | 2 +- ...RouteProcessorOrderBookV3ArbOrderTaker.sol | 2 +- src/abstract/OrderBookV3ArbOrderTaker.sol | 12 +++++----- src/abstract/OrderBookV3FlashBorrower.sol | 16 +++++++------- .../GenericPoolOrderBookV3ArbOrderTaker.sol | 2 +- .../GenericPoolOrderBookV3FlashBorrower.sol | 2 +- src/concrete/OrderBook.sol | 22 +++++++++---------- ...RouteProcessorOrderBookV3ArbOrderTaker.sol | 2 +- src/interface/IOrderBookV2.sol | 2 +- src/interface/deprecated/IOrderBookV1.sol | 2 +- src/interface/unstable/IOrderBookV3.sol | 4 ++-- ...cPoolOrderBookV3ArbOrderTaker.sender.t.sol | 4 ++-- ...cPoolOrderBookV3FlashBorrower.sender.t.sol | 4 ++-- test/concrete/OrderBook.addOrder.mock.t.sol | 2 +- test/concrete/OrderBook.clear.mock.t.sol | 2 +- .../OrderBook.takeOrder.maximumInput.t.sol | 2 +- .../OrderBookV3FlashLender.reentrant.t.sol | 2 +- ...essorOrderBookV3ArbOrderTaker.sender.t.sol | 4 ++-- test/util/abstract/ArbTest.sol | 12 +++++----- .../abstract/OrderBookExternalMockTest.sol | 14 ++++++------ .../abstract/OrderBookExternalRealTest.sol | 14 ++++++------ test/util/abstract/OrderBookSelfTest.sol | 4 ++-- test/util/lib/LibTestAddOrder.sol | 2 +- 27 files changed, 73 insertions(+), 73 deletions(-) diff --git a/.gitmodules b/.gitmodules index 23a83524e..ce230cde8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,9 +22,9 @@ [submodule "lib/rain.solmem"] path = lib/rain.solmem url = https://github.com/rainprotocol/rain.solmem -[submodule "lib/rain.interpreter"] - path = lib/rain.interpreter - url = https://github.com/rainprotocol/rain.interpreter [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts +[submodule "lib/rain.interpreter"] + path = lib/rain.interpreter + url = https://github.com/rainprotocol/rain.interpreter diff --git a/lib/rain.interpreter b/lib/rain.interpreter index 2c5bca1d2..5222a43e9 160000 --- a/lib/rain.interpreter +++ b/lib/rain.interpreter @@ -1 +1 @@ -Subproject commit 2c5bca1d2300b611b1a25a90cf4c28f752c5ae39 +Subproject commit 5222a43e9a088b41a7eca4a3d283721fccbc1058 diff --git a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol index 37bab2c2a..af41180bf 100644 --- a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol +++ b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol @@ -22,7 +22,7 @@ contract DeployGenericPoolOrderBookV3ArbOrderTaker is Script { vm.startBroadcast(deployerPrivateKey); GenericPoolOrderBookV3ArbOrderTaker deployed = - new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV2ConstructionConfig ( + new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig ( i9rDeployer, meta )); diff --git a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol index acabf8345..5ee9286c4 100644 --- a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol +++ b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol @@ -22,7 +22,7 @@ contract DeployGenericPoolOrderBookV3FlashBorrower is Script { vm.startBroadcast(deployerPrivateKey); GenericPoolOrderBookV3FlashBorrower deployed = - new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV2ConstructionConfig ( + new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV3ConstructionConfig ( i9rDeployer, meta )); diff --git a/script/DeployOrderBook.sol b/script/DeployOrderBook.sol index 3b1e734e3..43cef91e4 100644 --- a/script/DeployOrderBook.sol +++ b/script/DeployOrderBook.sol @@ -15,7 +15,7 @@ contract DeployOrderBook is Script { console2.logBytes32(keccak256(meta)); vm.startBroadcast(deployerPrivateKey); - OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV2ConstructionConfig ( + OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig ( i9rDeployer, meta )); diff --git a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol index 2e2ed6ad7..6672bf902 100644 --- a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol +++ b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol @@ -22,7 +22,7 @@ contract DeployRouteProcessorOrderBookV3ArbOrderTaker is Script { vm.startBroadcast(deployerPrivateKey); RouteProcessorOrderBookV3ArbOrderTaker deployed = - new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV2ConstructionConfig ( + new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig ( i9rDeployer, meta )); diff --git a/src/abstract/OrderBookV3ArbOrderTaker.sol b/src/abstract/OrderBookV3ArbOrderTaker.sol index 42c25845a..948302163 100644 --- a/src/abstract/OrderBookV3ArbOrderTaker.sol +++ b/src/abstract/OrderBookV3ArbOrderTaker.sol @@ -8,10 +8,10 @@ import {Initializable} from "lib/openzeppelin-contracts/contracts/proxy/utils/In import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; import {Address} from "lib/openzeppelin-contracts/contracts/utils/Address.sol"; import { - DeployerDiscoverableMetaV2, - DeployerDiscoverableMetaV2ConstructionConfig, + DeployerDiscoverableMetaV3, + DeployerDiscoverableMetaV3ConstructionConfig, LibMeta -} from "lib/rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol"; +} from "lib/rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import "lib/rain.factory/src/interface/ICloneableV2.sol"; import "lib/rain.interpreter/src/lib/caller/LibContext.sol"; import "lib/rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; @@ -47,7 +47,7 @@ abstract contract OrderBookV3ArbOrderTaker is ReentrancyGuard, Initializable, ICloneableV2, - DeployerDiscoverableMetaV2, + DeployerDiscoverableMetaV3, ERC165 { using SafeERC20 for IERC20; @@ -59,8 +59,8 @@ abstract contract OrderBookV3ArbOrderTaker is IInterpreterV1 public sI9r; IInterpreterStoreV1 public sI9rStore; - constructor(bytes32 metaHash, DeployerDiscoverableMetaV2ConstructionConfig memory config) - DeployerDiscoverableMetaV2(metaHash, config) + constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config) + DeployerDiscoverableMetaV3(metaHash, config) { _disableInitializers(); } diff --git a/src/abstract/OrderBookV3FlashBorrower.sol b/src/abstract/OrderBookV3FlashBorrower.sol index 7401d4bf2..13c2f112e 100644 --- a/src/abstract/OrderBookV3FlashBorrower.sol +++ b/src/abstract/OrderBookV3FlashBorrower.sol @@ -8,10 +8,10 @@ import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.so import {ReentrancyGuard} from "lib/openzeppelin-contracts/contracts/security/ReentrancyGuard.sol"; import {Initializable} from "lib/openzeppelin-contracts/contracts/proxy/utils/Initializable.sol"; import { - DeployerDiscoverableMetaV2, - DeployerDiscoverableMetaV2ConstructionConfig, + DeployerDiscoverableMetaV3, + DeployerDiscoverableMetaV3ConstructionConfig, LibMeta -} from "lib/rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol"; +} from "lib/rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import {LibEncodedDispatch, EncodedDispatch} from "lib/rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; import {LibContext} from "lib/rain.interpreter/src/lib/caller/LibContext.sol"; import {LibBytecode} from "lib/rain.interpreter/src/lib/bytecode/LibBytecode.sol"; @@ -20,8 +20,8 @@ import {EvaluableConfigV2} from "rain.interpreter/src/lib/caller/LibEvaluable.so import {IOrderBookV3, TakeOrdersConfigV2, NoOrders} from "../interface/unstable/IOrderBookV3.sol"; import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "lib/rain.factory/src/interface/ICloneableV2.sol"; import { - IInterpreterV1, SourceIndex, DEFAULT_STATE_NAMESPACE -} from "lib/rain.interpreter/src/interface/IInterpreterV1.sol"; + IInterpreterV2, SourceIndex, DEFAULT_STATE_NAMESPACE +} from "lib/rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import {IERC3156FlashBorrower} from "../interface/ierc3156/IERC3156FlashBorrower.sol"; import {IInterpreterStoreV1} from "lib/rain.interpreter/src/interface/IInterpreterStoreV1.sol"; import {BadLender, MinimumOutput, NonZeroBeforeArbStack, Initializing} from "./OrderBookV3ArbCommon.sol"; @@ -91,7 +91,7 @@ abstract contract OrderBookV3FlashBorrower is ICloneableV2, ReentrancyGuard, Initializable, - DeployerDiscoverableMetaV2, + DeployerDiscoverableMetaV3, ERC165 { using Address for address; @@ -112,8 +112,8 @@ abstract contract OrderBookV3FlashBorrower is /// The associated store for the interpreter. IInterpreterStoreV1 public sI9rStore; - constructor(bytes32 metaHash, DeployerDiscoverableMetaV2ConstructionConfig memory config) - DeployerDiscoverableMetaV2(metaHash, config) + constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config) + DeployerDiscoverableMetaV3(metaHash, config) { // Arb contracts are expected to be cloned proxies so allowing // initialization of the implementation is a security risk. diff --git a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol b/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol index 315a5d4f9..eee3f0606 100644 --- a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol +++ b/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol @@ -12,7 +12,7 @@ contract GenericPoolOrderBookV3ArbOrderTaker is OrderBookV3ArbOrderTaker { using SafeERC20 for IERC20; using Address for address; - constructor(DeployerDiscoverableMetaV2ConstructionConfig memory config) + constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) OrderBookV3ArbOrderTaker(CALLER_META_HASH, config) {} diff --git a/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol b/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol index 8a73ce80b..9506f7d87 100644 --- a/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol +++ b/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol @@ -25,7 +25,7 @@ contract GenericPoolOrderBookV3FlashBorrower is OrderBookV3FlashBorrower { using SafeERC20 for IERC20; using Address for address; - constructor(DeployerDiscoverableMetaV2ConstructionConfig memory config) + constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) OrderBookV3FlashBorrower(CALLER_META_HASH, config) {} diff --git a/src/concrete/OrderBook.sol b/src/concrete/OrderBook.sol index c5dc6b4db..6c44b29bb 100644 --- a/src/concrete/OrderBook.sol +++ b/src/concrete/OrderBook.sol @@ -14,12 +14,12 @@ import {LibFixedPointDecimalScale} from "rain.math.fixedpoint/lib/LibFixedPointD import {LibEncodedDispatch, EncodedDispatch} from "rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; import {LibContext} from "rain.interpreter/src/lib/caller/LibContext.sol"; import { - DeployerDiscoverableMetaV2, - DeployerDiscoverableMetaV2ConstructionConfig, + DeployerDiscoverableMetaV3, + DeployerDiscoverableMetaV3ConstructionConfig, LibMeta -} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol"; +} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol"; -import {SourceIndex, StateNamespace, IInterpreterV1} from "rain.interpreter/src/interface/IInterpreterV1.sol"; +import {SourceIndex, StateNamespace, IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import { IOrderBookV3, NoOrders, @@ -38,7 +38,7 @@ import {LibUint256Array} from "rain.solmem/lib/LibUint256Array.sol"; import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; import {Evaluable} from "rain.interpreter/src/lib/caller/LibEvaluable.sol"; import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterStoreV1.sol"; -import {IExpressionDeployerV2} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV2.sol"; +import {IExpressionDeployerV3} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; /// This will exist in a future version of Open Zeppelin if their main branch is /// to be believed. @@ -188,7 +188,7 @@ type Input18Amount is uint256; /// @title OrderBook /// See `IOrderBookV1` for more documentation. -contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3FlashLender, DeployerDiscoverableMetaV2 { +contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3FlashLender, DeployerDiscoverableMetaV3 { using LibUint256Array for uint256[]; using SafeERC20 for IERC20; using LibOrder for Order; @@ -220,8 +220,8 @@ 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(DeployerDiscoverableMetaV2ConstructionConfig memory config) - DeployerDiscoverableMetaV2(CALLER_META_HASH, config) + constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) + DeployerDiscoverableMetaV3(CALLER_META_HASH, config) {} /// @inheritdoc IOrderBookV3 @@ -608,7 +608,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash return; } - // Emit the Clear event before `eval`. + // Emit the Clear event before `eval2`. emit Clear(msg.sender, aliceOrder, bobOrder, clearConfig); } OrderIOCalculation memory aliceOrderIOCalculation = calculateOrderIO( @@ -707,7 +707,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash (uint256[] memory calculateOrderStack, uint256[] memory calculateOrderKVs) = order .evaluable .interpreter - .eval(order.evaluable.store, namespace, _calculateOrderDispatch(order.evaluable.expression), context); + .eval2(order.evaluable.store, namespace, _calculateOrderDispatch(order.evaluable.expression), context); Output18Amount orderOutputMax18 = Output18Amount.wrap(calculateOrderStack[calculateOrderStack.length - 2]); uint256 orderIORatio = calculateOrderStack[calculateOrderStack.length - 1]; @@ -805,7 +805,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash .order .evaluable .interpreter - .eval( + .eval2( orderIOCalculation.order.evaluable.store, orderIOCalculation.namespace, _handleIODispatch(orderIOCalculation.order.evaluable.expression), diff --git a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol b/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol index d92d20c08..d622c7027 100644 --- a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol +++ b/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol @@ -16,7 +16,7 @@ contract RouteProcessorOrderBookV3ArbOrderTaker is OrderBookV3ArbOrderTaker { IRouteProcessor public sRouteProcessor; - constructor(DeployerDiscoverableMetaV2ConstructionConfig memory config) + constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config) OrderBookV3ArbOrderTaker(CALLER_META_HASH, config) {} diff --git a/src/interface/IOrderBookV2.sol b/src/interface/IOrderBookV2.sol index ffacfbf49..c7ed6f94f 100644 --- a/src/interface/IOrderBookV2.sol +++ b/src/interface/IOrderBookV2.sol @@ -321,7 +321,7 @@ interface IOrderBookV2 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param orderHash The hash of the order as it is recorded onchain. Only /// the hash is stored in Orderbook storage to avoid paying gas to store the /// entire order. - event AddOrder(address sender, IExpressionDeployerV2 expressionDeployer, Order order, uint256 orderHash); + event AddOrder(address sender, IExpressionDeployerV3 expressionDeployer, Order order, uint256 orderHash); /// An order has been removed from the orderbook. This effectively /// deactivates it. Orders can be added again after removal. diff --git a/src/interface/deprecated/IOrderBookV1.sol b/src/interface/deprecated/IOrderBookV1.sol index 9126be7ad..5de30e657 100644 --- a/src/interface/deprecated/IOrderBookV1.sol +++ b/src/interface/deprecated/IOrderBookV1.sol @@ -321,7 +321,7 @@ interface IOrderBookV1 is IERC3156FlashLender, IInterpreterCallerV1 { /// @param orderHash The hash of the order as it is recorded onchain. Only /// the hash is stored in Orderbook storage to avoid paying gas to store the /// entire order. - event AddOrder(address sender, IExpressionDeployerV2 expressionDeployer, Order order, uint256 orderHash); + event AddOrder(address sender, IExpressionDeployerV3 expressionDeployer, Order order, uint256 orderHash); /// An order has been removed from the orderbook. This effectively /// deactivates it. Orders can be added again after removal. diff --git a/src/interface/unstable/IOrderBookV3.sol b/src/interface/unstable/IOrderBookV3.sol index dbcfb12fe..9c979cf48 100644 --- a/src/interface/unstable/IOrderBookV3.sol +++ b/src/interface/unstable/IOrderBookV3.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.18; import "../ierc3156/IERC3156FlashLender.sol"; import { - EvaluableConfigV2, IExpressionDeployerV2, Evaluable + EvaluableConfigV2, IExpressionDeployerV3, Evaluable } from "lib/rain.interpreter/src/lib/caller/LibEvaluable.sol"; import "lib/rain.interpreter/src/interface/IInterpreterCallerV2.sol"; @@ -262,7 +262,7 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param orderHash The hash of the order as it is recorded onchain. Only /// the hash is stored in Orderbook storage to avoid paying gas to store the /// entire order. - event AddOrder(address sender, IExpressionDeployerV2 expressionDeployer, Order order, bytes32 orderHash); + event AddOrder(address sender, IExpressionDeployerV3 expressionDeployer, Order order, bytes32 orderHash); /// An order has been removed from the orderbook. This effectively /// deactivates it. Orders can be added again after removal. diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol index d70915d03..840094fc2 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol @@ -12,7 +12,7 @@ import "src/interface/unstable/IOrderBookV3.sol"; contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) { - (address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) = + (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) = buildConstructorConfig(GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH); return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3ArbOrderTaker(config))); } @@ -21,7 +21,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { ICloneableV2(iArb).initialize( abi.encode( OrderBookV3ArbOrderTakerConfigV1( - address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" + address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" ) ) ); diff --git a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol index 70dd26d2b..cc1bd81b7 100644 --- a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol @@ -12,7 +12,7 @@ import "src/interface/unstable/IOrderBookV3.sol"; contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) { - (address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) = + (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) = buildConstructorConfig(GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_META_PATH); return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3FlashBorrower(config))); } @@ -21,7 +21,7 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { ICloneableV2(iArb).initialize( abi.encode( OrderBookV3FlashBorrowerConfigV2( - address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" + address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" ) ) ); diff --git a/test/concrete/OrderBook.addOrder.mock.t.sol b/test/concrete/OrderBook.addOrder.mock.t.sol index ea0321e85..9caa43ad2 100644 --- a/test/concrete/OrderBook.addOrder.mock.t.sol +++ b/test/concrete/OrderBook.addOrder.mock.t.sol @@ -78,7 +78,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { config.evaluableConfig.deployer = iDeployer; vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector), + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), abi.encode(iInterpreter, iStore, expression) ); vm.expectRevert(abi.encodeWithSelector(NotRainMetaV1.selector, config.meta)); diff --git a/test/concrete/OrderBook.clear.mock.t.sol b/test/concrete/OrderBook.clear.mock.t.sol index 37613f19b..befabdca0 100644 --- a/test/concrete/OrderBook.clear.mock.t.sol +++ b/test/concrete/OrderBook.clear.mock.t.sol @@ -8,7 +8,7 @@ import {OrderBookExternalMockTest} from "test/util/abstract/OrderBookExternalMoc import {OrderConfigV2, Order, IO, ClearConfig} from "src/interface/unstable/IOrderBookV3.sol"; import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; -import {IInterpreterV1} from "rain.interpreter/src/interface/IInterpreterV1.sol"; +import {IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; /// @title OrderBookClearTest /// Tests clearing an order. diff --git a/test/concrete/OrderBook.takeOrder.maximumInput.t.sol b/test/concrete/OrderBook.takeOrder.maximumInput.t.sol index 1d56f4dff..0e5740436 100644 --- a/test/concrete/OrderBook.takeOrder.maximumInput.t.sol +++ b/test/concrete/OrderBook.takeOrder.maximumInput.t.sol @@ -13,7 +13,7 @@ import { EvaluableConfigV2, OrderConfigV2 } from "src/interface/unstable/IOrderBookV3.sol"; -import {IParserV1} from "rain.interpreter/src/interface/unstable/IParserV1.sol"; +import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; contract OrderBookTakeOrderMaximumInputTest is OrderBookExternalRealTest { /// If there is some live order(s) but the maxTakerInput is zero we error as diff --git a/test/concrete/OrderBookV3FlashLender.reentrant.t.sol b/test/concrete/OrderBookV3FlashLender.reentrant.t.sol index 4132e7470..fc4f593f4 100644 --- a/test/concrete/OrderBookV3FlashLender.reentrant.t.sol +++ b/test/concrete/OrderBookV3FlashLender.reentrant.t.sol @@ -12,7 +12,7 @@ import { TakeOrdersConfigV2, ClearConfig } from "src/interface/unstable/IOrderBookV3.sol"; -import {IParserV1} from "rain.interpreter/src/interface/unstable/IParserV1.sol"; +import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; import {IERC3156FlashBorrower} from "src/interface/ierc3156/IERC3156FlashBorrower.sol"; import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index 5f24a5597..844e34e55 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -13,7 +13,7 @@ import "rain.factory/src/interface/ICloneableV2.sol"; contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) { - (address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) = + (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) = buildConstructorConfig(ROUTE_PROCESSOR_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH); return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config))); } @@ -23,7 +23,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { abi.encode( OrderBookV3ArbOrderTakerConfigV1( address(iOrderBook), - EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), + EvaluableConfigV2(IExpressionDeployerV3(address(0)), "", new uint256[](0)), abi.encode(iRefundoor) ) ) diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index 8529b1ade..2ba7c2e73 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -5,9 +5,9 @@ import "forge-std/Test.sol"; import "openzeppelin-contracts/contracts/proxy/Clones.sol"; import "test/util/lib/LibTestConstants.sol"; -import {DeployerDiscoverableMetaV2ConstructionConfig} from - "rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol"; -import {IExpressionDeployerV2} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV2.sol"; +import {DeployerDiscoverableMetaV3ConstructionConfig} from + "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.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"; @@ -46,20 +46,20 @@ abstract contract ArbTest is Test { function buildConstructorConfig(string memory metaPath) internal - returns (address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) + returns (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) { deployer = address(uint160(uint256(keccak256("deployer.rain.test")))); // All non-mocked calls will revert. vm.etch(deployer, REVERTING_MOCK_BYTECODE); vm.mockCall( deployer, - abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector), + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), abi.encode(address(0), address(0), address(0)) ); bytes memory meta = vm.readFileBinary(metaPath); console2.log("RouteProcessorOrderBookV3ArbOrderTakerTest meta hash:"); console2.logBytes32(keccak256(meta)); - config = DeployerDiscoverableMetaV2ConstructionConfig(deployer, meta); + config = DeployerDiscoverableMetaV3ConstructionConfig(deployer, meta); } function buildTakeOrderConfig(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) diff --git a/test/util/abstract/OrderBookExternalMockTest.sol b/test/util/abstract/OrderBookExternalMockTest.sol index 93b95945f..b1b302a69 100644 --- a/test/util/abstract/OrderBookExternalMockTest.sol +++ b/test/util/abstract/OrderBookExternalMockTest.sol @@ -3,7 +3,7 @@ pragma solidity =0.8.19; import "lib/forge-std/src/Test.sol"; -import "lib/rain.interpreter/src/interface/unstable/IExpressionDeployerV2.sol"; +import "lib/rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; import "lib/rain.metadata/src/LibMeta.sol"; import "test/util/lib/LibTestConstants.sol"; @@ -27,7 +27,7 @@ import "src/concrete/OrderBook.sol"; abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { IInterpreterV1 immutable iInterpreter; IInterpreterStoreV1 immutable iStore; - IExpressionDeployerV2 immutable iDeployer; + IExpressionDeployerV3 immutable iDeployer; IOrderBookV3 immutable iOrderbook; IERC20 immutable iToken0; IERC20 immutable iToken1; @@ -38,19 +38,19 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { vm.etch(address(iInterpreter), REVERTING_MOCK_BYTECODE); iStore = IInterpreterStoreV1(address(uint160(uint256(keccak256("store.rain.test"))))); vm.etch(address(iStore), REVERTING_MOCK_BYTECODE); - iDeployer = IExpressionDeployerV2(address(uint160(uint256(keccak256("deployer.rain.test"))))); + iDeployer = IExpressionDeployerV3(address(uint160(uint256(keccak256("deployer.rain.test"))))); // All non-mocked calls will revert. vm.etch(address(iDeployer), REVERTING_MOCK_BYTECODE); vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector), + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), abi.encode(iInterpreter, iStore, address(0)) ); bytes memory meta = vm.readFileBinary(ORDER_BOOK_META_PATH); console2.log("OrderBookExternalMockTest meta hash:"); console2.logBytes(abi.encodePacked(keccak256(meta))); iOrderbook = - IOrderBookV3(address(new OrderBook(DeployerDiscoverableMetaV2ConstructionConfig(address(iDeployer), meta)))); + IOrderBookV3(address(new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(address(iDeployer), meta)))); iToken0 = IERC20(address(uint160(uint256(keccak256("token0.rain.test"))))); vm.etch(address(iToken0), REVERTING_MOCK_BYTECODE); @@ -71,7 +71,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { assertTrue(!iOrderbook.orderExists(orderHash)); vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector), + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), abi.encode(iInterpreter, iStore, expression) ); vm.expectEmit(false, false, false, true); @@ -100,7 +100,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { // mock. vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector), + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), abi.encode(iInterpreter, iStore, expression) ); vm.record(); diff --git a/test/util/abstract/OrderBookExternalRealTest.sol b/test/util/abstract/OrderBookExternalRealTest.sol index c97b36158..84e8607f9 100644 --- a/test/util/abstract/OrderBookExternalRealTest.sol +++ b/test/util/abstract/OrderBookExternalRealTest.sol @@ -2,20 +2,20 @@ pragma solidity =0.8.19; import "lib/forge-std/src/Test.sol"; -import {RainterpreterNP} from "lib/rain.interpreter/src/concrete/RainterpreterNP.sol"; -import "lib/rain.interpreter/src/concrete/RainterpreterStore.sol"; -import "lib/rain.interpreter/src/concrete/RainterpreterExpressionDeployerNP.sol"; +import {RainterpreterNPE2} from "lib/rain.interpreter/src/concrete/RainterpreterNPE2.sol"; +import {RainterpreterStoreNPE2} from "lib/rain.interpreter/src/concrete/RainterpreterStoreNPE2.sol"; +import {RainterpreterExpressionDeployerNPE2} from "lib/rain.interpreter/src/concrete/RainterpreterExpressionDeployerNPE2.sol"; import "test/util/lib/LibTestConstants.sol"; import "test/util/lib/LibOrderBookConstants.sol"; import "test/util/abstract/IOrderBookV3Stub.sol"; -import {OrderBook, IERC20, DeployerDiscoverableMetaV2ConstructionConfig} from "src/concrete/OrderBook.sol"; +import {OrderBook, IERC20, DeployerDiscoverableMetaV3ConstructionConfig} from "src/concrete/OrderBook.sol"; abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { IInterpreterV1 internal immutable iInterpreter; IInterpreterStoreV1 internal immutable iStore; - IExpressionDeployerV2 internal immutable iDeployer; + IExpressionDeployerV3 internal immutable iDeployer; IOrderBookV3 internal immutable iOrderbook; IERC20 internal immutable iToken0; IERC20 internal immutable iToken1; @@ -37,7 +37,7 @@ abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { bytes memory deployerMeta = LibAllStandardOpsNP.authoringMeta(); console2.log("current deployer meta hash:"); console2.logBytes32(keccak256(deployerMeta)); - iDeployer = IExpressionDeployerV2( + iDeployer = IExpressionDeployerV3( address( new RainterpreterExpressionDeployerNP(RainterpreterExpressionDeployerConstructionConfig( address(iInterpreter), @@ -50,7 +50,7 @@ abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { console2.log("orderbook meta hash:"); console2.logBytes(abi.encodePacked(keccak256(orderbookMeta))); iOrderbook = IOrderBookV3( - address(new OrderBook(DeployerDiscoverableMetaV2ConstructionConfig(address(iDeployer), orderbookMeta))) + address(new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(address(iDeployer), orderbookMeta))) ); iToken0 = IERC20(address(uint160(uint256(keccak256("token0.rain.test"))))); diff --git a/test/util/abstract/OrderBookSelfTest.sol b/test/util/abstract/OrderBookSelfTest.sol index 6635991b3..e52f760c4 100644 --- a/test/util/abstract/OrderBookSelfTest.sol +++ b/test/util/abstract/OrderBookSelfTest.sol @@ -20,7 +20,7 @@ abstract contract OrderBookSelfTest is Test, OrderBook { vm.etch(address(deployer), REVERTING_MOCK_BYTECODE); vm.mockCall( address(deployer), - abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector), + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), abi.encode(address(0), address(0), address(0)) ); vm.resumeGasMetering(); @@ -32,5 +32,5 @@ abstract contract OrderBookSelfTest is Test, OrderBook { vm.resumeGasMetering(); } - constructor() OrderBook(DeployerDiscoverableMetaV2ConstructionConfig(constructDeployer(), constructMeta())) {} + constructor() OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(constructDeployer(), constructMeta())) {} } diff --git a/test/util/lib/LibTestAddOrder.sol b/test/util/lib/LibTestAddOrder.sol index 53dedbbe1..0ffe18296 100644 --- a/test/util/lib/LibTestAddOrder.sol +++ b/test/util/lib/LibTestAddOrder.sol @@ -32,7 +32,7 @@ library LibTestAddOrder { /// Valid config has a few requirements. Mutates the config in place. /// Anything that doesn't meet the requirements will just be set to 0 values /// as this is faster than forcing the fuzzer to rebuild with assume. - function conformConfig(OrderConfigV2 memory config, IExpressionDeployerV2 deployer) internal pure { + function conformConfig(OrderConfigV2 memory config, IExpressionDeployerV3 deployer) internal pure { if (config.meta.length > 0) { // This is a bit of a hack, but it's the easiest way to get a valid // meta document. From 19b42b03470a9e16218de51101de073a675ecab4 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 21 Nov 2023 23:02:32 +0400 Subject: [PATCH 02/14] wip on e2 --- .gitmodules | 6 +- lib/rain.factory | 2 +- lib/rain.interpreter | 2 +- src/abstract/OrderBookV3ArbOrderTaker.sol | 56 +++++--- src/abstract/OrderBookV3FlashBorrower.sol | 41 +++--- src/concrete/OrderBook.sol | 121 +++++++++++------- .../{ => deprecated}/IOrderBookV2.sol | 9 +- src/interface/unstable/IOrderBookV3.sol | 74 ++++++++--- .../unstable/IOrderBookV3ArbOrderTaker.sol | 4 +- src/lib/LibOrder.sol | 10 +- ...cPoolOrderBookV3ArbOrderTaker.sender.t.sol | 10 +- ...cPoolOrderBookV3FlashBorrower.sender.t.sol | 10 +- test/concrete/OrderBook.addOrder.mock.t.sol | 40 +++--- test/concrete/OrderBook.addOrder.t.sol | 46 +++---- .../OrderBook.clear.handleIO.revert.t.sol | 23 ++-- test/concrete/OrderBook.clear.mock.t.sol | 11 +- .../concrete/OrderBook.removeOrder.mock.t.sol | 37 +++--- .../OrderBook.takeOrder.handleIO.revert.t.sol | 21 ++- .../OrderBook.takeOrder.maximumInput.t.sol | 24 ++-- test/concrete/OrderBook.takeOrder.noop.t.sol | 33 ++--- .../OrderBook.takeOrder.precision.t.sol | 23 ++-- .../OrderBook.takeOrder.tokenMismatch.t.sol | 24 ++-- ...Book.takeOrder.tokenMismatchDecimals.t.sol | 24 ++-- .../OrderBookV3FlashLender.reentrant.t.sol | 16 +-- ...essorOrderBookV3ArbOrderTaker.sender.t.sol | 10 +- test/lib/LibOrder.t.sol | 4 +- test/util/abstract/ArbTest.sol | 12 +- test/util/abstract/IOrderBookV3Stub.sol | 4 +- .../abstract/OrderBookExternalMockTest.sol | 46 ++++--- .../abstract/OrderBookExternalRealTest.sol | 38 ++++-- test/util/abstract/OrderBookSelfTest.sol | 4 +- .../concrete/FlashLendingMockOrderBook.sol | 6 +- test/util/lib/LibTestAddOrder.sol | 23 ++-- 33 files changed, 466 insertions(+), 348 deletions(-) rename src/interface/{ => deprecated}/IOrderBookV2.sol (98%) diff --git a/.gitmodules b/.gitmodules index ce230cde8..dfb7e6e98 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,9 +10,6 @@ [submodule "lib/rain.lib.memkv"] path = lib/rain.lib.memkv url = https://github.com/rainprotocol/rain.lib.memkv -[submodule "lib/rain.factory"] - path = lib/rain.factory - url = https://github.com/rainprotocol/rain.factory [submodule "lib/sushixswap-v2"] path = lib/sushixswap-v2 url = https://github.com/rainprotocol/sushixswap-v2 @@ -28,3 +25,6 @@ [submodule "lib/rain.interpreter"] path = lib/rain.interpreter url = https://github.com/rainprotocol/rain.interpreter +[submodule "lib/rain.factory"] + path = lib/rain.factory + url = https://github.com/rainprotocol/rain.factory diff --git a/lib/rain.factory b/lib/rain.factory index e6babfcc5..0a02f9119 160000 --- a/lib/rain.factory +++ b/lib/rain.factory @@ -1 +1 @@ -Subproject commit e6babfcc5788bb387878d6915955228b2a4cfc70 +Subproject commit 0a02f91190531aa7bf7f7b28d31a9bb70e9e7a0a diff --git a/lib/rain.interpreter b/lib/rain.interpreter index 5222a43e9..059d6405c 160000 --- a/lib/rain.interpreter +++ b/lib/rain.interpreter @@ -1 +1 @@ -Subproject commit 5222a43e9a088b41a7eca4a3d283721fccbc1058 +Subproject commit 059d6405c4315a1c681492c9c73315d06bcff162 diff --git a/src/abstract/OrderBookV3ArbOrderTaker.sol b/src/abstract/OrderBookV3ArbOrderTaker.sol index 948302163..27f7c8d29 100644 --- a/src/abstract/OrderBookV3ArbOrderTaker.sol +++ b/src/abstract/OrderBookV3ArbOrderTaker.sol @@ -12,16 +12,22 @@ import { DeployerDiscoverableMetaV3ConstructionConfig, LibMeta } from "lib/rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; -import "lib/rain.factory/src/interface/ICloneableV2.sol"; -import "lib/rain.interpreter/src/lib/caller/LibContext.sol"; -import "lib/rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; -import "lib/rain.interpreter/src/lib/bytecode/LibBytecode.sol"; - -import "../interface/unstable/IOrderBookV3.sol"; -import "../interface/unstable/IOrderBookV3OrderTaker.sol"; -import "../interface/unstable/IOrderBookV3ArbOrderTaker.sol"; - -import "./OrderBookV3ArbCommon.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 "lib/rain.factory/src/interface/ICloneableV2.sol"; +import {EncodedDispatch, LibEncodedDispatch} from "lib/rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; + +import {IOrderBookV3, NoOrders} from "../interface/unstable/IOrderBookV3.sol"; +import {IOrderBookV3ArbOrderTaker, IOrderBookV3OrderTaker} from "../interface/unstable/IOrderBookV3ArbOrderTaker.sol"; +import {IInterpreterV2, DEFAULT_STATE_NAMESPACE} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; +import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterStoreV1.sol"; +import {TakeOrdersConfigV2} from "../interface/unstable/IOrderBookV3.sol"; +import {BadLender, MinimumOutput, NonZeroBeforeArbStack, Initializing} from "./OrderBookV3ArbCommon.sol"; +import {LibContext} from "rain.interpreter/src/lib/caller/LibContext.sol"; +import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol"; + +/// Thrown when "before arb" wants inputs that we don't have. +error NonZeroBeforeArbInputs(uint256 inputs); /// Config for `OrderBookV3ArbOrderTakerConfigV1` to initialize. /// @param orderBook The `IOrderBookV3` to use for `takeOrders`. @@ -30,13 +36,13 @@ import "./OrderBookV3ArbCommon.sol"; /// the `beforeInitialize` hook. struct OrderBookV3ArbOrderTakerConfigV1 { address orderBook; - EvaluableConfigV2 evaluableConfig; + EvaluableConfigV3 evaluableConfig; bytes implementationData; } /// @dev "Before arb" is evaluabled before the arb is executed. Ostensibly this /// is to allow for access control to the arb, the return values are ignored. -SourceIndex constant BEFORE_ARB_SOURCE_INDEX = SourceIndex.wrap(0); +SourceIndexV2 constant BEFORE_ARB_SOURCE_INDEX = SourceIndexV2.wrap(0); /// @dev "Before arb" has no return values. uint256 constant BEFORE_ARB_MIN_OUTPUTS = 0; /// @dev "Before arb" has no return values. @@ -56,7 +62,7 @@ abstract contract OrderBookV3ArbOrderTaker is IOrderBookV3 public sOrderBook; EncodedDispatch public sI9rDispatch; - IInterpreterV1 public sI9r; + IInterpreterV2 public sI9r; IInterpreterStoreV1 public sI9rStore; constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config) @@ -103,18 +109,25 @@ abstract contract OrderBookV3ArbOrderTaker is if (LibBytecode.sourceCount(config.evaluableConfig.bytecode) > 0) { address expression; - uint256[] memory entrypoints = new uint256[](1); - entrypoints[SourceIndex.unwrap(BEFORE_ARB_SOURCE_INDEX)] = BEFORE_ARB_MIN_OUTPUTS; - + bytes memory io; // We have to trust the deployer because it produces the expression // address for dispatch anyway. // All external functions on this contract have `onlyNotInitializing` // modifier on them so can't be reentered here anyway. //slither-disable-next-line reentrancy-benign - (sI9r, sI9rStore, expression) = config.evaluableConfig.deployer.deployExpression( - config.evaluableConfig.bytecode, config.evaluableConfig.constants, entrypoints + (sI9r, sI9rStore, expression, io) = config.evaluableConfig.deployer.deployExpression2( + config.evaluableConfig.bytecode, config.evaluableConfig.constants ); - sI9rDispatch = LibEncodedDispatch.encode(expression, BEFORE_ARB_SOURCE_INDEX, BEFORE_ARB_MAX_OUTPUTS); + { + uint256 inputs; + assembly ("memory-safe") { + inputs := and(mload(add(io, 1)), 0xFF) + } + if (inputs != 0) { + revert NonZeroBeforeArbInputs(inputs); + } + } + sI9rDispatch = LibEncodedDispatch.encode2(expression, BEFORE_ARB_SOURCE_INDEX, BEFORE_ARB_MAX_OUTPUTS); } return ICLONEABLE_V2_SUCCESS; @@ -138,11 +151,12 @@ abstract contract OrderBookV3ArbOrderTaker is // Run the access control dispatch if it is set. EncodedDispatch dispatch = sI9rDispatch; if (EncodedDispatch.unwrap(dispatch) > 0) { - (uint256[] memory stack, uint256[] memory kvs) = sI9r.eval( + (uint256[] memory stack, uint256[] memory kvs) = sI9r.eval2( sI9rStore, DEFAULT_STATE_NAMESPACE, dispatch, - LibContext.build(new uint256[][](0), new SignedContextV1[](0)) + LibContext.build(new uint256[][](0), new SignedContextV1[](0)), + new uint256[](0) ); // This can only happen if interpreter is broken. if (stack.length > 0) { diff --git a/src/abstract/OrderBookV3FlashBorrower.sol b/src/abstract/OrderBookV3FlashBorrower.sol index 13c2f112e..5464afa23 100644 --- a/src/abstract/OrderBookV3FlashBorrower.sol +++ b/src/abstract/OrderBookV3FlashBorrower.sol @@ -16,16 +16,15 @@ import {LibEncodedDispatch, EncodedDispatch} from "lib/rain.interpreter/src/lib/ import {LibContext} from "lib/rain.interpreter/src/lib/caller/LibContext.sol"; import {LibBytecode} from "lib/rain.interpreter/src/lib/bytecode/LibBytecode.sol"; import {ON_FLASH_LOAN_CALLBACK_SUCCESS} from "../interface/ierc3156/IERC3156FlashBorrower.sol"; -import {EvaluableConfigV2} from "rain.interpreter/src/lib/caller/LibEvaluable.sol"; import {IOrderBookV3, TakeOrdersConfigV2, NoOrders} from "../interface/unstable/IOrderBookV3.sol"; import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "lib/rain.factory/src/interface/ICloneableV2.sol"; import { - IInterpreterV2, SourceIndex, DEFAULT_STATE_NAMESPACE + IInterpreterV2, SourceIndexV2, DEFAULT_STATE_NAMESPACE } from "lib/rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import {IERC3156FlashBorrower} from "../interface/ierc3156/IERC3156FlashBorrower.sol"; import {IInterpreterStoreV1} from "lib/rain.interpreter/src/interface/IInterpreterStoreV1.sol"; import {BadLender, MinimumOutput, NonZeroBeforeArbStack, Initializing} from "./OrderBookV3ArbCommon.sol"; -import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {EvaluableConfigV3, SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; /// Thrown when the initiator is not the order book. /// @param badInitiator The untrusted initiator of the flash loan. @@ -37,6 +36,9 @@ error FlashLoanFailed(); /// Thrown when the swap fails. error SwapFailed(); +/// Thrown when "Before arb" expects inputs. +error NonZeroBeforeArbInputs(); + /// Config for `OrderBookV3FlashBorrower` to initialize. /// @param orderBook The `IOrderBookV3` contract to arb against. /// @param evaluableConfig The config to eval for access control to arb. @@ -44,17 +46,19 @@ error SwapFailed(); /// the `beforeInitialize` hook. struct OrderBookV3FlashBorrowerConfigV2 { address orderBook; - EvaluableConfigV2 evaluableConfig; + EvaluableConfigV3 evaluableConfig; bytes implementationData; } /// @dev "Before arb" is evaluated before the flash loan is taken. Ostensibly /// allows for some kind of access control to the arb. -SourceIndex constant BEFORE_ARB_SOURCE_INDEX = SourceIndex.wrap(0); +SourceIndexV2 constant BEFORE_ARB_SOURCE_INDEX = SourceIndexV2.wrap(0); +/// @dev "Before arb" has no inputs. +uint256 constant BEFORE_ARB_MIN_INPUTS = 0; /// @dev "Before arb" has no outputs. uint256 constant BEFORE_ARB_MIN_OUTPUTS = 0; /// @dev "Before arb" has no outputs. -uint16 constant BEFORE_ARB_MAX_OUTPUTS = 0; +uint256 constant BEFORE_ARB_MAX_OUTPUTS = 0; /// @title OrderBookV3FlashBorrower /// @notice Abstract contract that liq-source specifialized contracts can inherit @@ -108,7 +112,7 @@ abstract contract OrderBookV3FlashBorrower is /// The encoded dispatch that will run for access control to `arb`. EncodedDispatch public sI9rDispatch; /// The interpreter that will eval access control to `arb`. - IInterpreterV1 public sI9r; + IInterpreterV2 public sI9r; /// The associated store for the interpreter. IInterpreterStoreV1 public sI9rStore; @@ -156,18 +160,24 @@ abstract contract OrderBookV3FlashBorrower is if (LibBytecode.sourceCount(config.evaluableConfig.bytecode) > 0) { address expression; - uint256[] memory entrypoints = new uint256[](1); - entrypoints[SourceIndex.unwrap(BEFORE_ARB_SOURCE_INDEX)] = BEFORE_ARB_MIN_OUTPUTS; - + bytes memory io; // We have to trust the deployer because it produces the expression // address for the dispatch anyway. // All external functions on this contract have `onlyNotInitializing` // modifier on them so can't be reentered here anyway. //slither-disable-next-line reentrancy-benign - (sI9r, sI9rStore, expression) = config.evaluableConfig.deployer.deployExpression( - config.evaluableConfig.bytecode, config.evaluableConfig.constants, entrypoints + (sI9r, sI9rStore, expression, io) = config.evaluableConfig.deployer.deployExpression2( + config.evaluableConfig.bytecode, config.evaluableConfig.constants ); - sI9rDispatch = LibEncodedDispatch.encode(expression, BEFORE_ARB_SOURCE_INDEX, BEFORE_ARB_MAX_OUTPUTS); + // There can't be any inputs because we don't pass any in. + uint256 inputs; + assembly ("memory-safe") { + inputs := and(mload(add(io, 1)), 0xFF) + } + if (inputs > 0) { + revert NonZeroBeforeArbInputs(); + } + sI9rDispatch = LibEncodedDispatch.encode2(expression, BEFORE_ARB_SOURCE_INDEX, BEFORE_ARB_MAX_OUTPUTS); } return ICLONEABLE_V2_SUCCESS; @@ -278,11 +288,12 @@ abstract contract OrderBookV3FlashBorrower is // Run the access control dispatch if it is set. EncodedDispatch dispatch = sI9rDispatch; if (EncodedDispatch.unwrap(dispatch) > 0) { - (uint256[] memory stack, uint256[] memory kvs) = sI9r.eval( + (uint256[] memory stack, uint256[] memory kvs) = sI9r.eval2( sI9rStore, DEFAULT_STATE_NAMESPACE, dispatch, - LibContext.build(new uint256[][](0), new SignedContextV1[](0)) + LibContext.build(new uint256[][](0), new SignedContextV1[](0)), + new uint256[](0) ); // This can only happen if the interpreter is broken. if (stack.length > 0) { diff --git a/src/concrete/OrderBook.sol b/src/concrete/OrderBook.sol index 6c44b29bb..a854a1fc8 100644 --- a/src/concrete/OrderBook.sol +++ b/src/concrete/OrderBook.sol @@ -19,13 +19,13 @@ import { LibMeta } from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol"; -import {SourceIndex, StateNamespace, IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; +import {SourceIndexV2, StateNamespace, IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import { IOrderBookV3, NoOrders, - Order, + OrderV2, OrderConfigV2, - TakeOrderConfig, + TakeOrderConfigV2, TakeOrdersConfigV2, ClearConfig, ClearStateChange, @@ -36,7 +36,7 @@ import {LibOrder} from "../lib/LibOrder.sol"; import {OrderBookV3FlashLender} from "../abstract/OrderBookV3FlashLender.sol"; import {LibUint256Array} from "rain.solmem/lib/LibUint256Array.sol"; import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; -import {Evaluable} from "rain.interpreter/src/lib/caller/LibEvaluable.sol"; +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"; @@ -69,6 +69,18 @@ error MinimumInput(uint256 minimumInput, uint256 input); /// @param owner The owner of both orders. error SameOwner(address owner); +/// Thrown when calculate order expression wants inputs. +/// @param inputs The inputs the expression wants. +error UnsupportedCalculateInputs(uint256 inputs); + +/// Thrown when calculate order expression offers too few outputs. +/// @param outputs The outputs the expression offers. +error UnsupportedCalculateOutputs(uint256 outputs); + +/// Thrown when handle IO expression wants inputs. +/// @param inputs The inputs the expression wants. +error UnsupportedHandleInputs(uint256 inputs); + /// @dev Stored value for a live order. NOT a boolean because storing a boolean /// is more expensive than storing a uint256. uint256 constant ORDER_LIVE = 1; @@ -79,10 +91,10 @@ uint256 constant ORDER_LIVE = 1; uint256 constant ORDER_DEAD = 0; /// @dev Entrypoint to a calculate the amount and ratio of an order. -SourceIndex constant CALCULATE_ORDER_ENTRYPOINT = SourceIndex.wrap(0); +SourceIndexV2 constant CALCULATE_ORDER_ENTRYPOINT = SourceIndexV2.wrap(0); /// @dev Entrypoint to handle the final internal vault movements resulting from /// matching multiple calculated orders. -SourceIndex constant HANDLE_IO_ENTRYPOINT = SourceIndex.wrap(1); +SourceIndexV2 constant HANDLE_IO_ENTRYPOINT = SourceIndexV2.wrap(1); /// @dev Minimum outputs for calculate order are the amount and ratio. uint256 constant CALCULATE_ORDER_MIN_OUTPUTS = 2; @@ -171,8 +183,8 @@ bytes32 constant CALLER_META_HASH = bytes32(0xd6912c2a900b10b78c9c43592b8690b48c /// IO state changes. /// @param kvs KVs returned from calculate order entrypoint to pass to the store /// before calling handle IO entrypoint. -struct OrderIOCalculation { - Order order; +struct OrderIOCalculationV2 { + OrderV2 order; uint256 outputIOIndex; Output18Amount outputMax; //solhint-disable-next-line var-name-mixedcase @@ -191,7 +203,7 @@ type Input18Amount is uint256; contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3FlashLender, DeployerDiscoverableMetaV3 { using LibUint256Array for uint256[]; using SafeERC20 for IERC20; - using LibOrder for Order; + using LibOrder for OrderV2; using LibUint256Array for uint256; using Math for uint256; using LibFixedPointDecimalScale for uint256; @@ -270,33 +282,55 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash function addOrder(OrderConfigV2 calldata config) external nonReentrant returns (bool stateChanged) { uint256 sourceCount = LibBytecode.sourceCount(config.evaluableConfig.bytecode); if (sourceCount == 0) { - revert OrderNoSources(msg.sender); + revert OrderNoSources(); } if (sourceCount == 1) { - revert OrderNoHandleIO(msg.sender); + revert OrderNoHandleIO(); } if (config.validInputs.length == 0) { - revert OrderNoInputs(msg.sender); + revert OrderNoInputs(); } if (config.validOutputs.length == 0) { - revert OrderNoOutputs(msg.sender); + revert OrderNoOutputs(); } - (IInterpreterV1 interpreter, IInterpreterStoreV1 store, address expression) = config + (IInterpreterV2 interpreter, IInterpreterStoreV1 store, address expression, bytes memory io) = config .evaluableConfig .deployer - .deployExpression( + .deployExpression2( config.evaluableConfig.bytecode, - config.evaluableConfig.constants, - LibUint256Array.arrayFrom(CALCULATE_ORDER_MIN_OUTPUTS, HANDLE_IO_MIN_OUTPUTS) + config.evaluableConfig.constants ); + { + uint256 calculateInputs; + uint256 calculateOutputs; + uint256 handleInputs; + assembly ("memory-safe") { + let ioWord := mload(add(io, 0x20)) + calculateInputs := byte(0, ioWord) + calculateOutputs := byte(1, ioWord) + handleInputs := byte(2, ioWord) + } + + if (calculateInputs != 0) { + revert UnsupportedCalculateInputs(calculateInputs); + } + + if (calculateOutputs < CALCULATE_ORDER_MIN_OUTPUTS) { + revert UnsupportedCalculateOutputs(calculateOutputs); + } + + if (handleInputs != 0) { + revert UnsupportedHandleInputs(handleInputs); + } + } // Merge our view on the sender/owner and handle IO emptiness with the - // config and deployer's view on the `Evaluable` to produce the final + // config and deployer's view on the `EvaluableV2` to produce the final // order. - Order memory order = Order( + OrderV2 memory order = OrderV2( msg.sender, - LibBytecode.sourceOpsLength(config.evaluableConfig.bytecode, SourceIndex.unwrap(HANDLE_IO_ENTRYPOINT)) > 0, - Evaluable(interpreter, store, expression), + LibBytecode.sourceOpsCount(config.evaluableConfig.bytecode, SourceIndexV2.unwrap(HANDLE_IO_ENTRYPOINT)) > 0, + EvaluableV2(interpreter, store, expression), config.validInputs, config.validOutputs ); @@ -323,7 +357,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash } /// @inheritdoc IOrderBookV3 - function removeOrder(Order calldata order) external nonReentrant returns (bool stateChanged) { + function removeOrder(OrderV2 calldata order) external nonReentrant returns (bool stateChanged) { if (msg.sender != order.owner) { revert NotOrderOwner(msg.sender, order.owner); } @@ -348,8 +382,8 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash revert NoOrders(); } - TakeOrderConfig memory takeOrderConfig; - Order memory order; + TakeOrderConfigV2 memory takeOrderConfig; + OrderV2 memory order; // Allocate a region of memory to hold pointers. We don't know how many // will run at this point, but we conservatively set aside a slot for @@ -357,7 +391,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash // resize the array later. There's no guarantee that a dynamic solution // would even be cheaper gas-wise, and it would almost certainly be more // complex. - OrderIOCalculation[] memory orderIOCalculationsToHandle; + OrderIOCalculationV2[] memory orderIOCalculationsToHandle; { uint256 length = config.orders.length; assembly ("memory-safe") { @@ -421,7 +455,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash if (sOrders[orderHash] == ORDER_DEAD) { emit OrderNotFound(msg.sender, order.owner, orderHash); } else { - OrderIOCalculation memory orderIOCalculation = calculateOrderIO( + OrderIOCalculationV2 memory orderIOCalculation = calculateOrderIO( order, takeOrderConfig.inputIOIndex, takeOrderConfig.outputIOIndex, @@ -546,8 +580,8 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash /// @inheritdoc IOrderBookV3 function clear( - Order memory aliceOrder, - Order memory bobOrder, + OrderV2 memory aliceOrder, + OrderV2 memory bobOrder, ClearConfig calldata clearConfig, SignedContextV1[] memory aliceSignedContext, SignedContextV1[] memory bobSignedContext @@ -611,10 +645,10 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash // Emit the Clear event before `eval2`. emit Clear(msg.sender, aliceOrder, bobOrder, clearConfig); } - OrderIOCalculation memory aliceOrderIOCalculation = calculateOrderIO( + OrderIOCalculationV2 memory aliceOrderIOCalculation = calculateOrderIO( aliceOrder, clearConfig.aliceInputIOIndex, clearConfig.aliceOutputIOIndex, bobOrder.owner, bobSignedContext ); - OrderIOCalculation memory bobOrderIOCalculation = calculateOrderIO( + OrderIOCalculationV2 memory bobOrderIOCalculation = calculateOrderIO( bobOrder, clearConfig.bobInputIOIndex, clearConfig.bobOutputIOIndex, aliceOrder.owner, aliceSignedContext ); ClearStateChange memory clearStateChange = @@ -656,12 +690,12 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash /// @param signedContext Any signed context provided by the clearer/taker /// that the order may need for its calculations. function calculateOrderIO( - Order memory order, + OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, address counterparty, SignedContextV1[] memory signedContext - ) internal view returns (OrderIOCalculation memory) { + ) internal view returns (OrderIOCalculationV2 memory) { unchecked { bytes32 orderHash = order.hash(); @@ -707,7 +741,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash (uint256[] memory calculateOrderStack, uint256[] memory calculateOrderKVs) = order .evaluable .interpreter - .eval2(order.evaluable.store, namespace, _calculateOrderDispatch(order.evaluable.expression), context); + .eval2(order.evaluable.store, namespace, _calculateOrderDispatch(order.evaluable.expression), context, new uint256[](0)); Output18Amount orderOutputMax18 = Output18Amount.wrap(calculateOrderStack[calculateOrderStack.length - 2]); uint256 orderIORatio = calculateOrderStack[calculateOrderStack.length - 1]; @@ -741,7 +775,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash context[CONTEXT_CALCULATIONS_COLUMN] = LibUint256Array.arrayFrom(Output18Amount.unwrap(orderOutputMax18), orderIORatio); - return OrderIOCalculation( + return OrderIOCalculationV2( order, outputIOIndex, orderOutputMax18, orderIORatio, context, namespace, calculateOrderKVs ); } @@ -756,7 +790,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash /// vault. /// @param orderIOCalculation The verbatim order IO calculation returned by /// `_calculateOrderIO`. - function recordVaultIO(uint256 input, uint256 output, OrderIOCalculation memory orderIOCalculation) internal { + function recordVaultIO(uint256 input, uint256 output, OrderIOCalculationV2 memory orderIOCalculation) internal { orderIOCalculation.context[CONTEXT_VAULT_INPUTS_COLUMN][CONTEXT_VAULT_IO_BALANCE_DIFF] = input; orderIOCalculation.context[CONTEXT_VAULT_OUTPUTS_COLUMN][CONTEXT_VAULT_IO_BALANCE_DIFF] = output; @@ -778,7 +812,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash emit Context(msg.sender, orderIOCalculation.context); } - function handleIO(OrderIOCalculation memory orderIOCalculation) internal { + function handleIO(OrderIOCalculationV2 memory orderIOCalculation) internal { // Apply state changes to the interpreter store after the vault balances // are updated, but before we call handle IO. We want handle IO to see // a consistent view on sets from calculate IO. @@ -809,7 +843,8 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash orderIOCalculation.order.evaluable.store, orderIOCalculation.namespace, _handleIODispatch(orderIOCalculation.order.evaluable.expression), - orderIOCalculation.context + orderIOCalculation.context, + new uint256[](0) ); // There's nothing to be done with the stack. (handleIOStack); @@ -835,8 +870,8 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash /// @return clearStateChange The clear state change with absolute inputs and /// outputs for Alice and Bob. function calculateClearStateChange( - OrderIOCalculation memory aliceOrderIOCalculation, - OrderIOCalculation memory bobOrderIOCalculation + OrderIOCalculationV2 memory aliceOrderIOCalculation, + OrderIOCalculationV2 memory bobOrderIOCalculation ) internal pure returns (ClearStateChange memory clearStateChange) { // Calculate the clear state change for Alice. (clearStateChange.aliceInput, clearStateChange.aliceOutput) = @@ -848,8 +883,8 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash } function calculateClearStateAlice( - OrderIOCalculation memory aliceOrderIOCalculation, - OrderIOCalculation memory bobOrderIOCalculation + OrderIOCalculationV2 memory aliceOrderIOCalculation, + OrderIOCalculationV2 memory bobOrderIOCalculation ) internal pure returns (uint256 aliceInput, uint256 aliceOutput) { // Always round IO calculations up so that the counterparty pays more. // This is the max input that bob can afford, given his own IO ratio @@ -886,10 +921,10 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash } function _calculateOrderDispatch(address expression_) internal pure returns (EncodedDispatch) { - return LibEncodedDispatch.encode(expression_, CALCULATE_ORDER_ENTRYPOINT, CALCULATE_ORDER_MAX_OUTPUTS); + return LibEncodedDispatch.encode2(expression_, CALCULATE_ORDER_ENTRYPOINT, CALCULATE_ORDER_MAX_OUTPUTS); } function _handleIODispatch(address expression_) internal pure returns (EncodedDispatch) { - return LibEncodedDispatch.encode(expression_, HANDLE_IO_ENTRYPOINT, HANDLE_IO_MAX_OUTPUTS); + return LibEncodedDispatch.encode2(expression_, HANDLE_IO_ENTRYPOINT, HANDLE_IO_MAX_OUTPUTS); } } diff --git a/src/interface/IOrderBookV2.sol b/src/interface/deprecated/IOrderBookV2.sol similarity index 98% rename from src/interface/IOrderBookV2.sol rename to src/interface/deprecated/IOrderBookV2.sol index c7ed6f94f..4f25a93e2 100644 --- a/src/interface/IOrderBookV2.sol +++ b/src/interface/deprecated/IOrderBookV2.sol @@ -1,9 +1,10 @@ // SPDX-License-Identifier: CAL pragma solidity ^0.8.18; -import "./ierc3156/IERC3156FlashLender.sol"; -import "lib/rain.interpreter/src/lib/caller/LibEvaluable.sol"; -import "lib/rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {IERC3156FlashLender} from "../ierc3156/IERC3156FlashLender.sol"; +import {EvaluableConfig, Evaluable} from "lib/rain.interpreter/src/interface/deprecated/IInterpreterCallerV1.sol"; +import {SignedContextV1, IInterpreterCallerV2} from "lib/rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {IExpressionDeployerV2} from "lib/rain.interpreter/src/interface/deprecated/IExpressionDeployerV2.sol"; /// Configuration for a deposit. All deposits are processed by and for /// `msg.sender` so the vaults are unambiguous here. @@ -321,7 +322,7 @@ interface IOrderBookV2 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param orderHash The hash of the order as it is recorded onchain. Only /// the hash is stored in Orderbook storage to avoid paying gas to store the /// entire order. - event AddOrder(address sender, IExpressionDeployerV3 expressionDeployer, Order order, uint256 orderHash); + event AddOrder(address sender, IExpressionDeployerV2 expressionDeployer, Order order, uint256 orderHash); /// An order has been removed from the orderbook. This effectively /// deactivates it. Orders can be added again after removal. diff --git a/src/interface/unstable/IOrderBookV3.sol b/src/interface/unstable/IOrderBookV3.sol index 9c979cf48..b4676f3c7 100644 --- a/src/interface/unstable/IOrderBookV3.sol +++ b/src/interface/unstable/IOrderBookV3.sol @@ -3,12 +3,12 @@ pragma solidity ^0.8.18; import "../ierc3156/IERC3156FlashLender.sol"; import { - EvaluableConfigV2, IExpressionDeployerV3, Evaluable + IExpressionDeployerV3, EvaluableV2 } from "lib/rain.interpreter/src/lib/caller/LibEvaluable.sol"; -import "lib/rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {EvaluableConfigV3, IInterpreterCallerV2, SignedContextV1} from "lib/rain.interpreter/src/interface/IInterpreterCallerV2.sol"; /// Import unmodified structures from older versions of `IOrderBook`. -import {IO, Order, TakeOrderConfig, ClearConfig, ClearStateChange} from "../IOrderBookV2.sol"; +import {IO, ClearConfig, ClearStateChange} from "../deprecated/IOrderBookV2.sol"; /// Thrown when take orders is called with no orders. error NoOrders(); @@ -31,10 +31,48 @@ error ZeroMaximumInput(); struct OrderConfigV2 { IO[] validInputs; IO[] validOutputs; - EvaluableConfigV2 evaluableConfig; + EvaluableConfigV3 evaluableConfig; bytes meta; } +/// Config for an individual take order from the overall list of orders in a +/// call to `takeOrders`. +/// @param order The order being taken this iteration. +/// @param inputIOIndex The index of the input token in `order` to match with the +/// take order output. +/// @param outputIOIndex The index of the output token in `order` to match with +/// the take order input. +/// @param signedContext Optional additional signed context relevant to the +/// taken order. +struct TakeOrderConfigV2 { + OrderV2 order; + uint256 inputIOIndex; + uint256 outputIOIndex; + SignedContextV1[] signedContext; +} + +/// Defines a fully deployed order ready to evaluate by Orderbook. Identical to +/// `Order` except for the newer `EvaluableV2`. +/// @param owner The owner of the order is the `msg.sender` that added the order. +/// @param handleIO true if there is a "handle IO" entrypoint to run. If false +/// the order book MAY skip calling the interpreter to save gas. +/// @param evaluable Standard `EvaluableV2` with entrypoints for both +/// "calculate order" and "handle IO". The latter MAY be empty bytes, in which +/// case it will be skipped at runtime to save gas. +/// @param validInputs A list of input tokens that are economically equivalent +/// for the purpose of processing this order. Inputs are relative to the order +/// so these tokens will be sent to the owners vault. +/// @param validOutputs A list of output tokens that are economically equivalent +/// for the purpose of processing this order. Outputs are relative to the order +/// so these tokens will be sent from the owners vault. +struct OrderV2 { + address owner; + bool handleIO; + EvaluableV2 evaluable; + IO[] validInputs; + IO[] validOutputs; +} + /// Config for a list of orders to take sequentially as part of a `takeOrders` /// call. /// @param minimumInput Minimum input from the perspective of the order taker. @@ -54,7 +92,7 @@ struct TakeOrdersConfigV2 { uint256 minimumInput; uint256 maximumInput; uint256 maximumIORatio; - TakeOrderConfig[] orders; + TakeOrderConfigV2[] orders; bytes data; } @@ -214,20 +252,16 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 { error ZeroWithdrawTargetAmount(address sender, address token, uint256 vaultId); /// MUST be thrown by `addOrder` if the order has no associated calculation. - /// @param sender `msg.sender` adding the order. - error OrderNoSources(address sender); + error OrderNoSources(); /// MUST be thrown by `addOrder` if the order has no associated handle IO. - /// @param sender `msg.sender` adding the order. - error OrderNoHandleIO(address sender); + error OrderNoHandleIO(); /// MUST be thrown by `addOrder` if the order has no inputs. - /// @param sender `msg.sender` adding the order. - error OrderNoInputs(address sender); + error OrderNoInputs(); /// MUST be thrown by `addOrder` if the order has no outputs. - /// @param sender `msg.sender` adding the order. - error OrderNoOutputs(address sender); + error OrderNoOutputs(); /// Some tokens have been deposited to a vault. /// @param sender `msg.sender` depositing tokens. Delegated deposits are NOT @@ -262,14 +296,14 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param orderHash The hash of the order as it is recorded onchain. Only /// the hash is stored in Orderbook storage to avoid paying gas to store the /// entire order. - event AddOrder(address sender, IExpressionDeployerV3 expressionDeployer, Order order, bytes32 orderHash); + event AddOrder(address sender, IExpressionDeployerV3 expressionDeployer, OrderV2 order, bytes32 orderHash); /// An order has been removed from the orderbook. This effectively /// deactivates it. Orders can be added again after removal. /// @param sender `msg.sender` removing the order and is owner of the order. /// @param order The removed order. /// @param orderHash The hash of the removed order. - event RemoveOrder(address sender, Order order, bytes32 orderHash); + event RemoveOrder(address sender, OrderV2 order, bytes32 orderHash); /// Some order has been taken by `msg.sender`. This is the same as them /// placing inverse orders then immediately clearing them all, but costs less @@ -280,7 +314,7 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param config All config defining the orders to attempt to take. /// @param input The input amount from the perspective of sender. /// @param output The output amount from the perspective of sender. - event TakeOrder(address sender, TakeOrderConfig config, uint256 input, uint256 output); + event TakeOrder(address sender, TakeOrderConfigV2 config, uint256 input, uint256 output); /// Emitted when attempting to match an order that either never existed or /// was removed. An event rather than an error so that we allow attempting @@ -312,7 +346,7 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param alice One of the orders. /// @param bob The other order. /// @param clearConfig Additional config required to process the clearance. - event Clear(address sender, Order alice, Order bob, ClearConfig clearConfig); + event Clear(address sender, OrderV2 alice, OrderV2 bob, ClearConfig clearConfig); /// Emitted after two orders clear. Includes all final state changes in the /// vault balances, including the clearer's vaults. @@ -413,7 +447,7 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param order The `Order` data exactly as it was added. /// @return stateChanged True if the order was removed, false if it did not /// exist. - function removeOrder(Order calldata order) external returns (bool stateChanged); + function removeOrder(OrderV2 calldata order) external returns (bool stateChanged); /// Allows `msg.sender` to attempt to fill a list of orders in sequence /// without needing to place their own order and clear them. This works like @@ -505,8 +539,8 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 { /// @param aliceSignedContext Optional signed context that is relevant to A. /// @param bobSignedContext Optional signed context that is relevant to B. function clear( - Order memory alice, - Order memory bob, + OrderV2 memory alice, + OrderV2 memory bob, ClearConfig calldata clearConfig, SignedContextV1[] memory aliceSignedContext, SignedContextV1[] memory bobSignedContext diff --git a/src/interface/unstable/IOrderBookV3ArbOrderTaker.sol b/src/interface/unstable/IOrderBookV3ArbOrderTaker.sol index 9a1fa234b..f321dd666 100644 --- a/src/interface/unstable/IOrderBookV3ArbOrderTaker.sol +++ b/src/interface/unstable/IOrderBookV3ArbOrderTaker.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: CAL pragma solidity ^0.8.18; -import "./IOrderBookV3OrderTaker.sol"; -import "./IOrderBookV3.sol"; +import {IOrderBookV3OrderTaker} from "./IOrderBookV3OrderTaker.sol"; +import {TakeOrdersConfigV2} from "./IOrderBookV3.sol"; interface IOrderBookV3ArbOrderTaker is IOrderBookV3OrderTaker { function arb(TakeOrdersConfigV2 calldata takeOrders, uint256 minimumSenderOutput) external payable; diff --git a/src/lib/LibOrder.sol b/src/lib/LibOrder.sol index d2338fbac..ad47b9aa4 100644 --- a/src/lib/LibOrder.sol +++ b/src/lib/LibOrder.sol @@ -4,15 +4,15 @@ pragma solidity ^0.8.18; import "../interface/unstable/IOrderBookV3.sol"; /// @title LibOrder -/// @notice Consistent handling of `Order` for where it matters w.r.t. +/// @notice Consistent handling of `OrderV2` for where it matters w.r.t. /// determinism and security. library LibOrder { - /// Hashes `Order` in a secure and deterministic way. Uses abi.encode rather - /// than abi.encodePacked to guard against potential collisions where many - /// inputs encode to the same output bytes. + /// Hashes `OrderV2` in a secure and deterministic way. Uses abi.encode + /// rather than abi.encodePacked to guard against potential collisions where + /// many inputs encode to the same output bytes. /// @param order The order to hash. /// @return The hash of `order`. - function hash(Order memory order) internal pure returns (bytes32) { + function hash(OrderV2 memory order) internal pure returns (bytes32) { return keccak256(abi.encode(order)); } } diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol index 840094fc2..060871c64 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol @@ -21,14 +21,14 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { ICloneableV2(iArb).initialize( abi.encode( OrderBookV3ArbOrderTakerConfigV1( - address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" + address(iOrderBook), EvaluableConfigV3(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" ) ) ); } - function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { - TakeOrderConfig[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); + function testTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); GenericPoolOrderBookV3ArbOrderTaker(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(iRefundoor, iRefundoor, "")), @@ -37,7 +37,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { } function testMinimumOutput( - Order memory order, + OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, uint256 minimumOutput, @@ -47,7 +47,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { minimumOutput = bound(minimumOutput, mintAmount + 1, type(uint256).max); iTakerOutput.mint(iArb, mintAmount); - TakeOrderConfig[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); + TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); vm.expectRevert(abi.encodeWithSelector(MinimumOutput.selector, minimumOutput, mintAmount)); GenericPoolOrderBookV3ArbOrderTaker(iArb).arb( diff --git a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol index cc1bd81b7..b022b7721 100644 --- a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol @@ -21,14 +21,14 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { ICloneableV2(iArb).initialize( abi.encode( OrderBookV3FlashBorrowerConfigV2( - address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" + address(iOrderBook), EvaluableConfigV3(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" ) ) ); } - function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { - TakeOrderConfig[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); + function testTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); GenericPoolOrderBookV3FlashBorrower(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""), @@ -38,7 +38,7 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { } function testMinimumOutput( - Order memory order, + OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, uint256 minimumOutput, @@ -48,7 +48,7 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { minimumOutput = bound(minimumOutput, mintAmount + 1, type(uint256).max); iTakerOutput.mint(iArb, mintAmount); - TakeOrderConfig[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); + TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); vm.expectRevert(abi.encodeWithSelector(MinimumOutput.selector, minimumOutput, mintAmount)); GenericPoolOrderBookV3FlashBorrower(iArb).arb( diff --git a/test/concrete/OrderBook.addOrder.mock.t.sol b/test/concrete/OrderBook.addOrder.mock.t.sol index 9caa43ad2..ff2da95c8 100644 --- a/test/concrete/OrderBook.addOrder.mock.t.sol +++ b/test/concrete/OrderBook.addOrder.mock.t.sol @@ -1,8 +1,12 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "test/util/abstract/OrderBookExternalMockTest.sol"; -import "test/util/lib/LibTestAddOrder.sol"; +import {OrderBookExternalMockTest} from "test/util/abstract/OrderBookExternalMockTest.sol"; +import {OrderConfigV2, OrderV2, IO} from "src/interface/unstable/IOrderBookV3.sol"; +import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; +import {NotRainMetaV1, META_MAGIC_NUMBER_V1} from "rain.metadata/IMetaV1.sol"; +import {LibMeta} from "rain.metadata/LibMeta.sol"; +import {IExpressionDeployerV3} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; /// @title OrderBookAddOrderMockTest /// @notice Tests the addOrder function of the OrderBook contract. @@ -13,7 +17,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { config.evaluableConfig.bytecode = ""; vm.expectRevert(abi.encodeWithSelector(OrderNoSources.selector, owner)); iOrderbook.addOrder(config); - (Order memory order, bytes32 orderHash) = + (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, address(0)); (order); assertTrue(!iOrderbook.orderExists(orderHash)); @@ -26,7 +30,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { config.validInputs = new IO[](0); vm.expectRevert(abi.encodeWithSelector(OrderNoInputs.selector, owner)); iOrderbook.addOrder(config); - (Order memory order, bytes32 orderHash) = + (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, address(0)); (order); assertTrue(!iOrderbook.orderExists(orderHash)); @@ -40,7 +44,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { config.validOutputs = new IO[](0); vm.expectRevert(abi.encodeWithSelector(OrderNoOutputs.selector, owner)); iOrderbook.addOrder(config); - (Order memory order, bytes32 orderHash) = + (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, address(0)); (order); assertTrue(!iOrderbook.orderExists(orderHash)); @@ -58,7 +62,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { vm.assume(config.validInputs.length > 0); vm.assume(config.validOutputs.length > 0); config.meta = new bytes(0); - (Order memory order, bytes32 orderhash) = addOrderWithChecks(owner, config, expression); + (OrderV2 memory order, bytes32 orderhash) = addOrderWithChecks(owner, config, expression); (order); (orderhash); } @@ -78,13 +82,13 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { config.evaluableConfig.deployer = iDeployer; vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), - abi.encode(iInterpreter, iStore, expression) + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(iInterpreter, iStore, expression, "") ); vm.expectRevert(abi.encodeWithSelector(NotRainMetaV1.selector, config.meta)); iOrderbook.addOrder(config); - (Order memory order, bytes32 orderHash) = + (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, expression); (order); assertTrue(!iOrderbook.orderExists(orderHash)); @@ -104,7 +108,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { // meta document. config.meta = abi.encodePacked(META_MAGIC_NUMBER_V1, config.meta); - (Order memory order, bytes32 orderHash) = addOrderWithChecks(owner, config, expression); + (OrderV2 memory order, bytes32 orderHash) = addOrderWithChecks(owner, config, expression); (order); (orderHash); } @@ -119,8 +123,8 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { ) public { vm.assume(alice != bob); LibTestAddOrder.conformConfig(config, iDeployer); - (Order memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, config, expression); - (Order memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, config, expression); + (OrderV2 memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, config, expression); + (OrderV2 memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, config, expression); (aliceOrder); (bobOrder); assertTrue(aliceOrderHash != bobOrderHash); @@ -139,8 +143,8 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { vm.assume(alice != bob); LibTestAddOrder.conformConfig(aliceConfig, iDeployer); LibTestAddOrder.conformConfig(bobConfig, iDeployer); - (Order memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, aliceConfig, aliceExpression); - (Order memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, bobConfig, bobExpression); + (OrderV2 memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, aliceConfig, aliceExpression); + (OrderV2 memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, bobConfig, bobExpression); (aliceOrder); (bobOrder); assertTrue(aliceOrderHash != bobOrderHash); @@ -157,15 +161,15 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { ) public { LibTestAddOrder.conformConfig(configOne, iDeployer); LibTestAddOrder.conformConfig(configTwo, iDeployer); - (Order memory expectedOrderOne, bytes32 expectedOrderOneHash) = + (OrderV2 memory expectedOrderOne, bytes32 expectedOrderOneHash) = LibTestAddOrder.expectedOrder(alice, configOne, iInterpreter, iStore, expressionOne); - (Order memory expectedOrderTwo, bytes32 expectedOrderTwoHash) = + (OrderV2 memory expectedOrderTwo, bytes32 expectedOrderTwoHash) = LibTestAddOrder.expectedOrder(alice, configTwo, iInterpreter, iStore, expressionTwo); (expectedOrderOne); (expectedOrderTwo); assertTrue(expectedOrderOneHash != expectedOrderTwoHash); - (Order memory orderOne, bytes32 orderOneHash) = addOrderWithChecks(alice, configOne, expressionOne); - (Order memory orderTwo, bytes32 orderTwoHash) = addOrderWithChecks(alice, configTwo, expressionTwo); + (OrderV2 memory orderOne, bytes32 orderOneHash) = addOrderWithChecks(alice, configOne, expressionOne); + (OrderV2 memory orderTwo, bytes32 orderTwoHash) = addOrderWithChecks(alice, configTwo, expressionTwo); (orderOne); (orderTwo); assertTrue(orderOneHash != orderTwoHash); diff --git a/test/concrete/OrderBook.addOrder.t.sol b/test/concrete/OrderBook.addOrder.t.sol index 4e1aa4a3a..ae5568cca 100644 --- a/test/concrete/OrderBook.addOrder.t.sol +++ b/test/concrete/OrderBook.addOrder.t.sol @@ -1,8 +1,10 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "test/util/abstract/OrderBookExternalRealTest.sol"; +import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRealTest.sol"; import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; +import {OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; +import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; /// @title OrderBookAddOrderTest /// @notice A test harness for testing the OrderBook addOrder function. @@ -27,28 +29,28 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { iOrderbook.addOrder(config); } - /// A stack of 0 for calculate order reverts. - function testAddOrderRealZeroStackCalculateReverts(address owner, OrderConfigV2 memory config) public { - LibTestAddOrder.conformConfig(config, iDeployer); - (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(":;:;"); - config.evaluableConfig.constants = constants; - config.evaluableConfig.bytecode = bytecode; - vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 0, 2)); - vm.prank(owner); - iOrderbook.addOrder(config); - } + // /// A stack of 0 for calculate order reverts. + // function testAddOrderRealZeroStackCalculateReverts(address owner, OrderConfigV2 memory config) public { + // LibTestAddOrder.conformConfig(config, iDeployer); + // (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(":;:;"); + // config.evaluableConfig.constants = constants; + // config.evaluableConfig.bytecode = bytecode; + // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 0, 2)); + // vm.prank(owner); + // iOrderbook.addOrder(config); + // } - /// A stack of 1 for calculate order reverts. - function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfigV2 memory config) public { - LibTestAddOrder.conformConfig(config, iDeployer); - (bytes memory bytecode, uint256[] memory constants) = - IParserV1(address(iDeployer)).parse("_:block-timestamp();:;"); - config.evaluableConfig.constants = constants; - config.evaluableConfig.bytecode = bytecode; - vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 1, 2)); - vm.prank(owner); - iOrderbook.addOrder(config); - } + // /// A stack of 1 for calculate order reverts. + // function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfigV2 memory config) public { + // LibTestAddOrder.conformConfig(config, iDeployer); + // (bytes memory bytecode, uint256[] memory constants) = + // IParserV1(address(iDeployer)).parse("_:block-timestamp();:;"); + // config.evaluableConfig.constants = constants; + // config.evaluableConfig.bytecode = bytecode; + // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 1, 2)); + // vm.prank(owner); + // iOrderbook.addOrder(config); + // } /// A stack of 2 for calculate order deploys. function testAddOrderRealTwoStackCalculateReverts(address owner, OrderConfigV2 memory config) public { diff --git a/test/concrete/OrderBook.clear.handleIO.revert.t.sol b/test/concrete/OrderBook.clear.handleIO.revert.t.sol index 4c10cec41..124cfbe9e 100644 --- a/test/concrete/OrderBook.clear.handleIO.revert.t.sol +++ b/test/concrete/OrderBook.clear.handleIO.revert.t.sol @@ -3,16 +3,11 @@ pragma solidity =0.8.19; import {Vm} from "forge-std/Vm.sol"; import { - OrderBookExternalRealTest, - OrderConfigV2, - IO, - TakeOrderConfig, - Order, - IParserV1, - EvaluableConfigV2, - ClearConfig, - SignedContextV1 + OrderBookExternalRealTest } from "test/util/abstract/OrderBookExternalRealTest.sol"; +import {ClearConfig, OrderV2, TakeOrderConfigV2, IO, OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; +import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; import {EnsureFailed} from "rain.interpreter/src/lib/op/logic/LibOpEnsureNP.sol"; /// @title OrderBookClearHandleIORevertTest @@ -21,7 +16,7 @@ import {EnsureFailed} from "rain.interpreter/src/lib/op/logic/LibOpEnsureNP.sol" contract OrderBookClearHandleIORevertTest is OrderBookExternalRealTest { function userDeposit(bytes memory rainString, address owner, address inputToken, address outputToken) internal - returns (Order memory) + returns (OrderV2 memory) { uint256 vaultId = 0; @@ -47,7 +42,7 @@ contract OrderBookClearHandleIORevertTest is OrderBookExternalRealTest { assertEq(iOrderbook.vaultBalance(owner, outputToken, vaultId), type(uint256).max); (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(rainString); - EvaluableConfigV2 memory evaluableConfig = EvaluableConfigV2(iDeployer, bytecode, constants); + EvaluableConfigV3 memory evaluableConfig = EvaluableConfigV3(iDeployer, bytecode, constants); config = OrderConfigV2(validInputs, validOutputs, evaluableConfig, ""); vm.prank(owner); @@ -55,7 +50,7 @@ contract OrderBookClearHandleIORevertTest is OrderBookExternalRealTest { iOrderbook.addOrder(config); Vm.Log[] memory entries = vm.getRecordedLogs(); assertEq(entries.length, 3); - (,, Order memory order,) = abi.decode(entries[2].data, (address, address, Order, bytes32)); + (,, OrderV2 memory order,) = abi.decode(entries[2].data, (address, address, OrderV2, bytes32)); return order; } @@ -71,8 +66,8 @@ contract OrderBookClearHandleIORevertTest is OrderBookExternalRealTest { address alice = address(0x102); address bob = address(0x103); - Order memory aliceOrder = userDeposit(aliceString, alice, aliceInputToken, aliceOutputToken); - Order memory bobOrder = userDeposit(bobString, bob, aliceOutputToken, aliceInputToken); + OrderV2 memory aliceOrder = userDeposit(aliceString, alice, aliceInputToken, aliceOutputToken); + OrderV2 memory bobOrder = userDeposit(bobString, bob, aliceOutputToken, aliceInputToken); ClearConfig memory clearConfig = ClearConfig(0, 0, 0, 0, 0, 0); if (aliceErr.length > 0) { vm.expectRevert(aliceErr); diff --git a/test/concrete/OrderBook.clear.mock.t.sol b/test/concrete/OrderBook.clear.mock.t.sol index befabdca0..de0e5a439 100644 --- a/test/concrete/OrderBook.clear.mock.t.sol +++ b/test/concrete/OrderBook.clear.mock.t.sol @@ -5,10 +5,11 @@ import {Test} from "lib/forge-std/src/Test.sol"; import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {OrderBookExternalMockTest} from "test/util/abstract/OrderBookExternalMockTest.sol"; -import {OrderConfigV2, Order, IO, ClearConfig} from "src/interface/unstable/IOrderBookV3.sol"; +import {OrderConfigV2, OrderV2, IO, ClearConfig} from "src/interface/unstable/IOrderBookV3.sol"; import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; import {IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; +import {NotOrderOwner} from "src/concrete/OrderBook.sol"; /// @title OrderBookClearTest /// Tests clearing an order. @@ -32,12 +33,12 @@ contract OrderBookClearTest is OrderBookExternalMockTest { // -- Add two orders with similar IO tokens (swapped) // Add alice order with a input token (iToken0) and output token (iToken1) - (Order memory aliceOrder, bytes32 aliceOrderHash) = + (OrderV2 memory aliceOrder, bytes32 aliceOrderHash) = _addOrderMockInternal(alice, aliceConfig, expression, iToken0, iToken1); assertTrue(iOrderbook.orderExists(aliceOrderHash)); // Add bob order with a input token (iToken1) and output token (iToken0) - (Order memory bobOrder, bytes32 bobOrderHash) = + (OrderV2 memory bobOrder, bytes32 bobOrderHash) = _addOrderMockInternal(bob, bobConfig, expression, iToken1, iToken0); assertTrue(iOrderbook.orderExists(bobOrderHash)); @@ -61,7 +62,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { orderStack[1] = 1e18; // orderIORatio vm.mockCall( address(iInterpreter), - abi.encodeWithSelector(IInterpreterV1.eval.selector), + abi.encodeWithSelector(IInterpreterV2.eval2.selector), abi.encode(orderStack, new uint256[](0)) ); @@ -78,7 +79,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { address expression, IERC20 inputToken, IERC20 outputToken - ) internal returns (Order memory, bytes32) { + ) internal returns (OrderV2 memory, bytes32) { vm.assume(config.validInputs.length > 0); vm.assume(config.validOutputs.length > 0); config.evaluableConfig.bytecode = hex"02000000040000000000000000"; diff --git a/test/concrete/OrderBook.removeOrder.mock.t.sol b/test/concrete/OrderBook.removeOrder.mock.t.sol index 4e508260a..d017b487a 100644 --- a/test/concrete/OrderBook.removeOrder.mock.t.sol +++ b/test/concrete/OrderBook.removeOrder.mock.t.sol @@ -1,7 +1,10 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "test/util/abstract/OrderBookExternalMockTest.sol"; +import {OrderBookExternalMockTest} from "test/util/abstract/OrderBookExternalMockTest.sol"; +import {OrderConfigV2, OrderV2} from "src/interface/unstable/IOrderBookV3.sol"; +import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; +import {NotOrderOwner} from "src/concrete/OrderBook.sol"; /// @title OrderBookRemoveOrderMockTest /// @notice A contract to test the OrderBook removeOrder function. @@ -13,7 +16,7 @@ contract OrderBookRemoveOrderMockTest is OrderBookExternalMockTest { LibTestAddOrder.conformConfig(config, iDeployer); vm.assume(alice != bob); - (Order memory expectedOrder, bytes32 expectedOrderHash) = + (OrderV2 memory expectedOrder, bytes32 expectedOrderHash) = LibTestAddOrder.expectedOrder(alice, config, iInterpreter, iStore, expression); // It will revert even if the order has not been added yet. @@ -22,7 +25,7 @@ contract OrderBookRemoveOrderMockTest is OrderBookExternalMockTest { iOrderbook.removeOrder(expectedOrder); // And will revert after the order is added. - (Order memory order, bytes32 orderHash) = addOrderWithChecks(alice, config, expression); + (OrderV2 memory order, bytes32 orderHash) = addOrderWithChecks(alice, config, expression); assertEq(orderHash, expectedOrderHash); vm.expectRevert(abi.encodeWithSelector(NotOrderOwner.selector, bob, alice)); @@ -42,7 +45,7 @@ contract OrderBookRemoveOrderMockTest is OrderBookExternalMockTest { function testRemoveOrderAddRemoveMulti(address alice, OrderConfigV2 memory config, address expression) external { LibTestAddOrder.conformConfig(config, iDeployer); - Order memory order; + OrderV2 memory order; bytes32 orderHashA; bytes32 orderHashB; // Each iteration is quite slow so 3 is about as much as we want to do. @@ -59,7 +62,7 @@ contract OrderBookRemoveOrderMockTest is OrderBookExternalMockTest { /// An order MUST NOT change state if it does not exist. function testRemoveOrderDoesNotExist(address alice, OrderConfigV2 memory config, address expression) external { LibTestAddOrder.conformConfig(config, iDeployer); - (Order memory order, bytes32 orderHash) = + (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(alice, config, iInterpreter, iStore, expression); assertFalse(iOrderbook.orderExists(orderHash)); vm.record(); @@ -85,16 +88,16 @@ contract OrderBookRemoveOrderMockTest is OrderBookExternalMockTest { LibTestAddOrder.conformConfig(configOne, iDeployer); LibTestAddOrder.conformConfig(configTwo, iDeployer); - (Order memory expectedOrderOne, bytes32 expectedOrderHashOne) = + (OrderV2 memory expectedOrderOne, bytes32 expectedOrderHashOne) = LibTestAddOrder.expectedOrder(alice, configOne, iInterpreter, iStore, expressionOne); - (Order memory expectedOrderTwo, bytes32 expectedOrderHashTwo) = + (OrderV2 memory expectedOrderTwo, bytes32 expectedOrderHashTwo) = LibTestAddOrder.expectedOrder(alice, configTwo, iInterpreter, iStore, expressionTwo); (expectedOrderOne); (expectedOrderTwo); vm.assume(expectedOrderHashOne != expectedOrderHashTwo); - (Order memory orderOne, bytes32 orderHashOne) = addOrderWithChecks(alice, configOne, expressionOne); - (Order memory orderTwo, bytes32 orderHashTwo) = addOrderWithChecks(alice, configTwo, expressionTwo); + (OrderV2 memory orderOne, bytes32 orderHashOne) = addOrderWithChecks(alice, configOne, expressionOne); + (OrderV2 memory orderTwo, bytes32 orderHashTwo) = addOrderWithChecks(alice, configTwo, expressionTwo); assertEq(orderHashOne, expectedOrderHashOne); assertEq(orderHashTwo, expectedOrderHashTwo); removeOrderWithChecks(alice, orderOne); @@ -107,8 +110,8 @@ contract OrderBookRemoveOrderMockTest is OrderBookExternalMockTest { { LibTestAddOrder.conformConfig(config, iDeployer); vm.assume(alice != bob); - (Order memory orderAlice, bytes32 orderHashAlice) = addOrderWithChecks(alice, config, expression); - (Order memory orderBob, bytes32 orderHashBob) = addOrderWithChecks(bob, config, expression); + (OrderV2 memory orderAlice, bytes32 orderHashAlice) = addOrderWithChecks(alice, config, expression); + (OrderV2 memory orderBob, bytes32 orderHashBob) = addOrderWithChecks(bob, config, expression); assertTrue(orderHashAlice != orderHashBob); // Owners can't interfere with each other. @@ -139,19 +142,19 @@ contract OrderBookRemoveOrderMockTest is OrderBookExternalMockTest { vm.assume(alice != bob); // Ensure the configs are different. - (Order memory expectedOrderOne, bytes32 expectedOrderHashOne) = + (OrderV2 memory expectedOrderOne, bytes32 expectedOrderHashOne) = LibTestAddOrder.expectedOrder(address(0), configOne, iInterpreter, iStore, expressionOne); - (Order memory expectedOrderTwo, bytes32 expectedOrderHashTwo) = + (OrderV2 memory expectedOrderTwo, bytes32 expectedOrderHashTwo) = LibTestAddOrder.expectedOrder(address(0), configTwo, iInterpreter, iStore, expressionTwo); (expectedOrderOne); (expectedOrderTwo); vm.assume(expectedOrderHashOne != expectedOrderHashTwo); } - Order memory orderAliceOne; - Order memory orderBobOne; - Order memory orderAliceTwo; - Order memory orderBobTwo; + OrderV2 memory orderAliceOne; + OrderV2 memory orderBobOne; + OrderV2 memory orderAliceTwo; + OrderV2 memory orderBobTwo; { bytes32 orderHashAliceOne; bytes32 orderHashBobOne; diff --git a/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol b/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol index 29ccbf434..4c121969d 100644 --- a/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol +++ b/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol @@ -3,17 +3,12 @@ pragma solidity =0.8.19; import {Vm} from "forge-std/Vm.sol"; import { - OrderBookExternalRealTest, - OrderConfigV2, - IO, - IParserV1, - EvaluableConfigV2, - Order, - TakeOrderConfig, - SignedContextV1, - TakeOrdersConfigV2 + OrderBookExternalRealTest } from "test/util/abstract/OrderBookExternalRealTest.sol"; +import {ClearConfig, OrderV2, TakeOrderConfigV2, IO, OrderConfigV2, TakeOrdersConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; import {EnsureFailed} from "rain.interpreter/src/lib/op/logic/LibOpEnsureNP.sol"; +import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; +import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; /// @title OrderBookTakeOrderHandleIORevertTest /// @notice A test harness for testing the OrderBook takeOrder function will run @@ -43,20 +38,20 @@ contract OrderBookTakeOrderHandleIORevertTest is OrderBookExternalRealTest { iOrderbook.deposit(outputToken, vaultId, type(uint256).max); assertEq(iOrderbook.vaultBalance(address(this), outputToken, vaultId), type(uint256).max); - TakeOrderConfig[] memory orders = new TakeOrderConfig[](configs.length); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](configs.length); for (uint256 i = 0; i < configs.length; i++) { (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(configs[i]); - EvaluableConfigV2 memory evaluableConfig = EvaluableConfigV2(iDeployer, bytecode, constants); + EvaluableConfigV3 memory evaluableConfig = EvaluableConfigV3(iDeployer, bytecode, constants); config = OrderConfigV2(validInputs, validOutputs, evaluableConfig, ""); vm.recordLogs(); iOrderbook.addOrder(config); Vm.Log[] memory entries = vm.getRecordedLogs(); assertEq(entries.length, 3); - (,, Order memory order,) = abi.decode(entries[2].data, (address, address, Order, bytes32)); + (,, OrderV2 memory order,) = abi.decode(entries[2].data, (address, address, OrderV2, bytes32)); - orders[i] = TakeOrderConfig(order, 0, 0, new SignedContextV1[](0)); + orders[i] = TakeOrderConfigV2(order, 0, 0, new SignedContextV1[](0)); } TakeOrdersConfigV2 memory takeOrdersConfig = TakeOrdersConfigV2(0, maxInput, type(uint256).max, orders, ""); diff --git a/test/concrete/OrderBook.takeOrder.maximumInput.t.sol b/test/concrete/OrderBook.takeOrder.maximumInput.t.sol index 0e5740436..665780efd 100644 --- a/test/concrete/OrderBook.takeOrder.maximumInput.t.sol +++ b/test/concrete/OrderBook.takeOrder.maximumInput.t.sol @@ -4,28 +4,28 @@ pragma solidity =0.8.19; import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {OrderBookExternalRealTest, Vm} from "test/util/abstract/OrderBookExternalRealTest.sol"; import { - Order, - SignedContextV1, - TakeOrderConfig, + OrderV2, + TakeOrderConfigV2, TakeOrdersConfigV2, ZeroMaximumInput, IO, - EvaluableConfigV2, + EvaluableConfigV3, OrderConfigV2 } from "src/interface/unstable/IOrderBookV3.sol"; +import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; contract OrderBookTakeOrderMaximumInputTest is OrderBookExternalRealTest { /// If there is some live order(s) but the maxTakerInput is zero we error as /// the caller has full control over this, and it would cause none of the /// orders to be taken. - function testTakeOrderNoopZeroMaxTakerInput(Order memory order, SignedContextV1 memory signedContext) external { + function testTakeOrderNoopZeroMaxTakerInput(OrderV2 memory order, SignedContextV1 memory signedContext) external { vm.assume(order.validInputs.length > 0); vm.assume(order.validOutputs.length > 0); - TakeOrderConfig[] memory orders = new TakeOrderConfig[](1); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](1); SignedContextV1[] memory signedContexts = new SignedContextV1[](1); signedContexts[0] = signedContext; - orders[0] = TakeOrderConfig(order, 0, 0, signedContexts); + orders[0] = TakeOrderConfigV2(order, 0, 0, signedContexts); TakeOrdersConfigV2 memory config = TakeOrdersConfigV2(0, 0, type(uint256).max, orders, ""); vm.expectRevert(ZeroMaximumInput.selector); (uint256 totalTakerInput, uint256 totalTakerOutput) = iOrderbook.takeOrders(config); @@ -54,7 +54,7 @@ contract OrderBookTakeOrderMaximumInputTest is OrderBookExternalRealTest { address bob = address(uint160(uint256(keccak256("bob.rain.test")))); uint256 vaultId = 0; - Order[] memory orders = new Order[](testOrders.length); + OrderV2[] memory orders = new OrderV2[](testOrders.length); for (uint256 i = 0; i < testOrders.length; i++) { { @@ -66,7 +66,7 @@ contract OrderBookTakeOrderMaximumInputTest is OrderBookExternalRealTest { inputs[0] = IO(address(iToken0), 18, vaultId); IO[] memory outputs = new IO[](1); outputs[0] = IO(address(iToken1), 18, vaultId); - EvaluableConfigV2 memory evaluableConfig = EvaluableConfigV2(iDeployer, bytecode, constants); + EvaluableConfigV3 memory evaluableConfig = EvaluableConfigV3(iDeployer, bytecode, constants); orderConfig = OrderConfigV2(inputs, outputs, evaluableConfig, ""); } @@ -75,7 +75,7 @@ contract OrderBookTakeOrderMaximumInputTest is OrderBookExternalRealTest { iOrderbook.addOrder(orderConfig); Vm.Log[] memory entries = vm.getRecordedLogs(); assertEq(entries.length, 3); - (,, Order memory order,) = abi.decode(entries[2].data, (address, address, Order, bytes32)); + (,, OrderV2 memory order,) = abi.decode(entries[2].data, (address, address, OrderV2, bytes32)); orders[i] = order; } } @@ -108,9 +108,9 @@ contract OrderBookTakeOrderMaximumInputTest is OrderBookExternalRealTest { } } - TakeOrderConfig[] memory takeOrders = new TakeOrderConfig[](orders.length); + TakeOrderConfigV2[] memory takeOrders = new TakeOrderConfigV2[](orders.length); for (uint256 i = 0; i < orders.length; i++) { - takeOrders[i] = TakeOrderConfig(orders[i], 0, 0, new SignedContextV1[](0)); + takeOrders[i] = TakeOrderConfigV2(orders[i], 0, 0, new SignedContextV1[](0)); } TakeOrdersConfigV2 memory config = TakeOrdersConfigV2(0, maximumTakerInput, type(uint256).max, takeOrders, ""); diff --git a/test/concrete/OrderBook.takeOrder.noop.t.sol b/test/concrete/OrderBook.takeOrder.noop.t.sol index 26524ead2..9f148bb71 100644 --- a/test/concrete/OrderBook.takeOrder.noop.t.sol +++ b/test/concrete/OrderBook.takeOrder.noop.t.sol @@ -1,22 +1,25 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "src/lib/LibOrder.sol"; +import {Vm} from "forge-std/Test.sol"; +import {LibOrder} from "src/lib/LibOrder.sol"; -import "test/util/abstract/OrderBookExternalRealTest.sol"; +import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRealTest.sol"; import {NoOrders} from "src/concrete/OrderBook.sol"; +import {OrderV2, TakeOrdersConfigV2, TakeOrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; +import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; /// @title OrderBookTakeOrderNoopTest /// @notice A test harness for testing the OrderBook takeOrder function. Focuses /// on the no-op case. contract OrderBookTakeOrderNoopTest is OrderBookExternalRealTest { - using LibOrder for Order; + using LibOrder for OrderV2; /// Take orders makes no sense without any orders in the input array and the /// caller has full control over this so we error. function testTakeOrderNoopZeroOrders() external { TakeOrdersConfigV2 memory config = - TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, new TakeOrderConfig[](0), ""); + TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, new TakeOrderConfigV2[](0), ""); vm.expectRevert(NoOrders.selector); (uint256 totalTakerInput, uint256 totalTakerOutput) = iOrderbook.takeOrders(config); (totalTakerInput, totalTakerOutput); @@ -28,7 +31,7 @@ contract OrderBookTakeOrderNoopTest is OrderBookExternalRealTest { /// transaction in this case as there may be other orders in the input array /// in the general case. function testTakeOrderNoopNonLiveOrderOne( - Order memory order, + OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, SignedContextV1 memory signedContext @@ -41,8 +44,8 @@ contract OrderBookTakeOrderNoopTest is OrderBookExternalRealTest { // malformed orders to be passed in, and still show that nothing happens. SignedContextV1[] memory signedContexts = new SignedContextV1[](1); signedContexts[0] = signedContext; - TakeOrderConfig memory orderConfig = TakeOrderConfig(order, inputIOIndex, outputIOIndex, signedContexts); - TakeOrderConfig[] memory orders = new TakeOrderConfig[](1); + TakeOrderConfigV2 memory orderConfig = TakeOrderConfigV2(order, inputIOIndex, outputIOIndex, signedContexts); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](1); orders[0] = orderConfig; TakeOrdersConfigV2 memory config = TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""); vm.expectEmit(address(iOrderbook)); @@ -57,8 +60,8 @@ contract OrderBookTakeOrderNoopTest is OrderBookExternalRealTest { /// Same as above but with two orders. function testTakeOrderNoopNonLiveOrderTwo( - Order memory order1, - Order memory order2, + OrderV2 memory order1, + OrderV2 memory order2, uint256 inputIOIndex1, uint256 outputIOIndex1, uint256 inputIOIndex2, @@ -84,19 +87,19 @@ contract OrderBookTakeOrderNoopTest is OrderBookExternalRealTest { TakeOrdersConfigV2 memory config; { - TakeOrderConfig[] memory orders; + TakeOrderConfigV2[] memory orders; { // We don't bound the input or output indexes as we want to allow // malformed orders to be passed in, and still show that nothing happens. SignedContextV1[] memory signedContexts1 = new SignedContextV1[](1); signedContexts1[0] = signedContext1; - TakeOrderConfig memory orderConfig1 = - TakeOrderConfig(order1, inputIOIndex1, outputIOIndex1, signedContexts1); + TakeOrderConfigV2 memory orderConfig1 = + TakeOrderConfigV2(order1, inputIOIndex1, outputIOIndex1, signedContexts1); SignedContextV1[] memory signedContexts2 = new SignedContextV1[](1); signedContexts2[0] = signedContext2; - TakeOrderConfig memory orderConfig2 = - TakeOrderConfig(order2, inputIOIndex2, outputIOIndex2, signedContexts2); - orders = new TakeOrderConfig[](2); + TakeOrderConfigV2 memory orderConfig2 = + TakeOrderConfigV2(order2, inputIOIndex2, outputIOIndex2, signedContexts2); + orders = new TakeOrderConfigV2[](2); orders[0] = orderConfig1; orders[1] = orderConfig2; } diff --git a/test/concrete/OrderBook.takeOrder.precision.t.sol b/test/concrete/OrderBook.takeOrder.precision.t.sol index 9ef9ee4a2..f61841d2e 100644 --- a/test/concrete/OrderBook.takeOrder.precision.t.sol +++ b/test/concrete/OrderBook.takeOrder.precision.t.sol @@ -1,18 +1,13 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; +import {Vm} from "forge-std/Test.sol"; import { - OrderBookExternalRealTest, - OrderConfigV2, - IO, - EvaluableConfigV2, - IParserV1, - Vm, - Order, - TakeOrderConfig, - SignedContextV1, - TakeOrdersConfigV2 + OrderBookExternalRealTest } from "test/util/abstract/OrderBookExternalRealTest.sol"; +import {OrderV2, TakeOrdersConfigV2, TakeOrderConfigV2, IO, OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; +import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; +import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; /// @title OrderBookTakeOrderPrecisionTest /// @notice A test harness for testing the OrderBook takeOrder function. @@ -36,7 +31,7 @@ contract OrderBookTakeOrderPrecisionTest is OrderBookExternalRealTest { // These numbers are known to cause large rounding errors if the // precision is not handled correctly. (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(rainString); - EvaluableConfigV2 memory evaluableConfig = EvaluableConfigV2(iDeployer, bytecode, constants); + EvaluableConfigV3 memory evaluableConfig = EvaluableConfigV3(iDeployer, bytecode, constants); config = OrderConfigV2(validInputs, validOutputs, evaluableConfig, ""); // Etch with invalid. vm.etch(outputToken, hex"fe"); @@ -54,10 +49,10 @@ contract OrderBookTakeOrderPrecisionTest is OrderBookExternalRealTest { iOrderbook.addOrder(config); Vm.Log[] memory entries = vm.getRecordedLogs(); assertEq(entries.length, 3); - (,, Order memory order,) = abi.decode(entries[2].data, (address, address, Order, bytes32)); + (,, OrderV2 memory order,) = abi.decode(entries[2].data, (address, address, OrderV2, bytes32)); - TakeOrderConfig[] memory orders = new TakeOrderConfig[](1); - orders[0] = TakeOrderConfig(order, 0, 0, new SignedContextV1[](0)); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](1); + orders[0] = TakeOrderConfigV2(order, 0, 0, new SignedContextV1[](0)); TakeOrdersConfigV2 memory takeOrdersConfig = TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""); (uint256 totalTakerInput, uint256 totalTakerOutput) = iOrderbook.takeOrders(takeOrdersConfig); diff --git a/test/concrete/OrderBook.takeOrder.tokenMismatch.t.sol b/test/concrete/OrderBook.takeOrder.tokenMismatch.t.sol index 5f8634621..339ac99b4 100644 --- a/test/concrete/OrderBook.takeOrder.tokenMismatch.t.sol +++ b/test/concrete/OrderBook.takeOrder.tokenMismatch.t.sol @@ -1,8 +1,10 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "test/util/abstract/OrderBookExternalRealTest.sol"; +import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRealTest.sol"; +import {OrderV2, IO, TakeOrderConfigV2, TakeOrdersConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; import {TokenMismatch} from "src/concrete/OrderBook.sol"; +import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; /// @title OrderBookTakeOrderTokenMismatchTest /// @notice A test harness for testing the OrderBook takeOrder function. @@ -14,10 +16,10 @@ contract OrderBookTakeOrderTokenMismatchTest is OrderBookExternalRealTest { /// pass in. /// Test a mismatch in the input tokens. function testTokenMismatchInputs( - Order memory a, + OrderV2 memory a, uint256 aInputIOIndex, uint256 aOutputIOIndex, - Order memory b, + OrderV2 memory b, uint256 bInputIOIndex, uint256 bOutputIOIndex, uint256 maxTakerInput, @@ -38,9 +40,9 @@ contract OrderBookTakeOrderTokenMismatchTest is OrderBookExternalRealTest { // Line up outputs so we don't trigger that code path. b.validOutputs[bOutputIOIndex].token = a.validOutputs[aOutputIOIndex].token; - TakeOrderConfig[] memory orders = new TakeOrderConfig[](2); - orders[0] = TakeOrderConfig(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); - orders[1] = TakeOrderConfig(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](2); + orders[0] = TakeOrderConfigV2(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); + orders[1] = TakeOrderConfigV2(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); TakeOrdersConfigV2 memory config = TakeOrdersConfigV2(0, maxTakerInput, maxIORatio, orders, ""); vm.expectRevert( abi.encodeWithSelector( @@ -53,10 +55,10 @@ contract OrderBookTakeOrderTokenMismatchTest is OrderBookExternalRealTest { /// Test a mismatch in the output tokens. function testTokenMismatchOutputs( - Order memory a, + OrderV2 memory a, uint256 aInputIOIndex, uint256 aOutputIOIndex, - Order memory b, + OrderV2 memory b, uint256 bInputIOIndex, uint256 bOutputIOIndex, uint256 maxTakerInput, @@ -77,9 +79,9 @@ contract OrderBookTakeOrderTokenMismatchTest is OrderBookExternalRealTest { // Line up inputs so we don't trigger that code path. b.validInputs[bInputIOIndex].token = a.validInputs[aInputIOIndex].token; - TakeOrderConfig[] memory orders = new TakeOrderConfig[](2); - orders[0] = TakeOrderConfig(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); - orders[1] = TakeOrderConfig(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](2); + orders[0] = TakeOrderConfigV2(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); + orders[1] = TakeOrderConfigV2(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); TakeOrdersConfigV2 memory config = TakeOrdersConfigV2(0, maxTakerInput, maxIORatio, orders, ""); vm.expectRevert( abi.encodeWithSelector( diff --git a/test/concrete/OrderBook.takeOrder.tokenMismatchDecimals.t.sol b/test/concrete/OrderBook.takeOrder.tokenMismatchDecimals.t.sol index c4b1a66f0..43c22d682 100644 --- a/test/concrete/OrderBook.takeOrder.tokenMismatchDecimals.t.sol +++ b/test/concrete/OrderBook.takeOrder.tokenMismatchDecimals.t.sol @@ -1,8 +1,10 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "test/util/abstract/OrderBookExternalRealTest.sol"; +import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRealTest.sol"; import {TokenDecimalsMismatch} from "src/concrete/OrderBook.sol"; +import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {TakeOrderConfigV2, TakeOrdersConfigV2, OrderV2} from "src/interface/unstable/IOrderBookV3.sol"; /// @title OrderBookTakeOrderTokenMismatchDecimalsTest /// @notice A test harness for testing the OrderBook takeOrder function. @@ -14,10 +16,10 @@ contract OrderBookTakeOrderTokenMismatchDecimalsTest is OrderBookExternalRealTes /// pass in. /// Test a mismatch in the input tokens decimals. function testTokenMismatchInputs( - Order memory a, + OrderV2 memory a, uint256 aInputIOIndex, uint256 aOutputIOIndex, - Order memory b, + OrderV2 memory b, uint256 bInputIOIndex, uint256 bOutputIOIndex ) external { @@ -39,9 +41,9 @@ contract OrderBookTakeOrderTokenMismatchDecimalsTest is OrderBookExternalRealTes // Line up output decimals so we don't trigger that code path. b.validOutputs[bOutputIOIndex].decimals = a.validOutputs[aOutputIOIndex].decimals; - TakeOrderConfig[] memory orders = new TakeOrderConfig[](2); - orders[0] = TakeOrderConfig(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); - orders[1] = TakeOrderConfig(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](2); + orders[0] = TakeOrderConfigV2(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); + orders[1] = TakeOrderConfigV2(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); TakeOrdersConfigV2 memory config = TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""); vm.expectRevert( abi.encodeWithSelector( @@ -56,10 +58,10 @@ contract OrderBookTakeOrderTokenMismatchDecimalsTest is OrderBookExternalRealTes /// Test a mismatch in the output tokens decimals. function testTokenMismatchOutputs( - Order memory a, + OrderV2 memory a, uint256 aInputIOIndex, uint256 aOutputIOIndex, - Order memory b, + OrderV2 memory b, uint256 bInputIOIndex, uint256 bOutputIOIndex ) external { @@ -81,9 +83,9 @@ contract OrderBookTakeOrderTokenMismatchDecimalsTest is OrderBookExternalRealTes // Line up input decimals so we don't trigger that code path. b.validInputs[bInputIOIndex].decimals = a.validInputs[aInputIOIndex].decimals; - TakeOrderConfig[] memory orders = new TakeOrderConfig[](2); - orders[0] = TakeOrderConfig(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); - orders[1] = TakeOrderConfig(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](2); + orders[0] = TakeOrderConfigV2(a, aInputIOIndex, aOutputIOIndex, new SignedContextV1[](0)); + orders[1] = TakeOrderConfigV2(b, bInputIOIndex, bOutputIOIndex, new SignedContextV1[](0)); TakeOrdersConfigV2 memory config = TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""); vm.expectRevert( abi.encodeWithSelector( diff --git a/test/concrete/OrderBookV3FlashLender.reentrant.t.sol b/test/concrete/OrderBookV3FlashLender.reentrant.t.sol index fc4f593f4..d45402377 100644 --- a/test/concrete/OrderBookV3FlashLender.reentrant.t.sol +++ b/test/concrete/OrderBookV3FlashLender.reentrant.t.sol @@ -7,8 +7,8 @@ import {Reenteroor} from "test/util/concrete/Reenteroor.sol"; import { IOrderBookV3, OrderConfigV2, - Order, - TakeOrderConfig, + OrderV2, + TakeOrderConfigV2, TakeOrdersConfigV2, ClearConfig } from "src/interface/unstable/IOrderBookV3.sol"; @@ -111,7 +111,7 @@ contract OrderBookV3FlashLenderReentrant is OrderBookExternalRealTest { } /// Can reenter and remove an order from within a flash loan. - function testReenterRemoveOrder(uint256 loanAmount, Order memory order) external { + function testReenterRemoveOrder(uint256 loanAmount, OrderV2 memory order) external { // Create a flash borrower. Reenteroor borrower = new Reenteroor(); order.owner = address(borrower); @@ -129,10 +129,10 @@ contract OrderBookV3FlashLenderReentrant is OrderBookExternalRealTest { vm.recordLogs(); iOrderbook.addOrder(config); Vm.Log[] memory entries = vm.getRecordedLogs(); - (,, Order memory order,) = abi.decode(entries[2].data, (address, address, Order, bytes32)); + (,, OrderV2 memory order,) = abi.decode(entries[2].data, (address, address, OrderV2, bytes32)); - TakeOrderConfig[] memory orders = new TakeOrderConfig[](1); - orders[0] = TakeOrderConfig(order, 0, 0, new SignedContextV1[](0)); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](1); + orders[0] = TakeOrderConfigV2(order, 0, 0, new SignedContextV1[](0)); TakeOrdersConfigV2 memory takeOrdersConfig = TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""); @@ -171,13 +171,13 @@ contract OrderBookV3FlashLenderReentrant is OrderBookExternalRealTest { vm.prank(alice); iOrderbook.addOrder(aliceConfig); Vm.Log[] memory entries = vm.getRecordedLogs(); - (,, Order memory aliceOrder,) = abi.decode(entries[2].data, (address, address, Order, bytes32)); + (,, OrderV2 memory aliceOrder,) = abi.decode(entries[2].data, (address, address, OrderV2, bytes32)); vm.recordLogs(); vm.prank(bob); iOrderbook.addOrder(bobConfig); entries = vm.getRecordedLogs(); - (,, Order memory bobOrder,) = abi.decode(entries[2].data, (address, address, Order, bytes32)); + (,, OrderV2 memory bobOrder,) = abi.decode(entries[2].data, (address, address, OrderV2, bytes32)); ClearConfig memory clearConfig = ClearConfig(0, 0, 0, 0, 0, 0); diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index 844e34e55..39724f37c 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -23,15 +23,15 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { abi.encode( OrderBookV3ArbOrderTakerConfigV1( address(iOrderBook), - EvaluableConfigV2(IExpressionDeployerV3(address(0)), "", new uint256[](0)), + EvaluableConfigV3(IExpressionDeployerV3(address(0)), "", new uint256[](0)), abi.encode(iRefundoor) ) ) ); } - function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { - TakeOrderConfig[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); + function testTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); RouteProcessorOrderBookV3ArbOrderTaker(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(bytes("0x00"))), 0 @@ -39,7 +39,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { } function testMinimumOutput( - Order memory order, + OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, uint256 minimumOutput, @@ -49,7 +49,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { minimumOutput = bound(minimumOutput, mintAmount + 1, type(uint256).max); iTakerOutput.mint(iArb, mintAmount); - TakeOrderConfig[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); + TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); vm.expectRevert(abi.encodeWithSelector(MinimumOutput.selector, minimumOutput, mintAmount)); RouteProcessorOrderBookV3ArbOrderTaker(iArb).arb( diff --git a/test/lib/LibOrder.t.sol b/test/lib/LibOrder.t.sol index 414af3dbb..a5bdb52d6 100644 --- a/test/lib/LibOrder.t.sol +++ b/test/lib/LibOrder.t.sol @@ -9,12 +9,12 @@ import "src/lib/LibOrder.sol"; /// Exercises the LibOrder library. contract LibOrderTest is Test { /// Hashing should always produce the same result for the same input. - function testHashEqual(Order memory a) public { + function testHashEqual(OrderV2 memory a) public { assertTrue(LibOrder.hash(a) == LibOrder.hash(a)); } /// Hashing should always produce different results for different inputs. - function testHashNotEqual(Order memory a, Order memory b) public { + function testHashNotEqual(OrderV2 memory a, OrderV2 memory b) public { assertTrue(LibOrder.hash(a) != LibOrder.hash(b)); } } diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index 2ba7c2e73..6ad71c77c 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -53,8 +53,8 @@ abstract contract ArbTest is Test { vm.etch(deployer, REVERTING_MOCK_BYTECODE); vm.mockCall( deployer, - abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), - abi.encode(address(0), address(0), address(0)) + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(address(0), address(0), address(0), "") ); bytes memory meta = vm.readFileBinary(metaPath); console2.log("RouteProcessorOrderBookV3ArbOrderTakerTest meta hash:"); @@ -62,10 +62,10 @@ abstract contract ArbTest is Test { config = DeployerDiscoverableMetaV3ConstructionConfig(deployer, meta); } - function buildTakeOrderConfig(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) + function buildTakeOrderConfig(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) internal view - returns (TakeOrderConfig[] memory) + returns (TakeOrderConfigV2[] memory) { if (order.validInputs.length == 0) { order.validInputs = new IO[](1); @@ -79,8 +79,8 @@ abstract contract ArbTest is Test { order.validInputs[inputIOIndex].token = address(iTakerOutput); order.validOutputs[outputIOIndex].token = address(iTakerInput); - TakeOrderConfig[] memory orders = new TakeOrderConfig[](1); - orders[0] = TakeOrderConfig(order, inputIOIndex, outputIOIndex, new SignedContextV1[](0)); + TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](1); + orders[0] = TakeOrderConfigV2(order, inputIOIndex, outputIOIndex, new SignedContextV1[](0)); return orders; } diff --git a/test/util/abstract/IOrderBookV3Stub.sol b/test/util/abstract/IOrderBookV3Stub.sol index 1fcf4e7ec..f8e63659d 100644 --- a/test/util/abstract/IOrderBookV3Stub.sol +++ b/test/util/abstract/IOrderBookV3Stub.sol @@ -15,12 +15,12 @@ abstract contract IOrderBookV3Stub is IOrderBookV3 { } /// @inheritdoc IOrderBookV3 - function removeOrder(Order calldata) external pure returns (bool) { + function removeOrder(OrderV2 calldata) external pure returns (bool) { revert("removeOrder"); } /// @inheritdoc IOrderBookV3 - function clear(Order memory, Order memory, ClearConfig calldata, SignedContextV1[] memory, SignedContextV1[] memory) + function clear(OrderV2 memory, OrderV2 memory, ClearConfig calldata, SignedContextV1[] memory, SignedContextV1[] memory) external pure { diff --git a/test/util/abstract/OrderBookExternalMockTest.sol b/test/util/abstract/OrderBookExternalMockTest.sol index b1b302a69..1f839d10d 100644 --- a/test/util/abstract/OrderBookExternalMockTest.sol +++ b/test/util/abstract/OrderBookExternalMockTest.sol @@ -1,17 +1,23 @@ // 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 {console2} from "forge-std/console2.sol"; -import "lib/rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; -import "lib/rain.metadata/src/LibMeta.sol"; +import {IExpressionDeployerV3} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV3.sol"; +import {IMetaV1} from "rain.metadata/LibMeta.sol"; -import "test/util/lib/LibTestConstants.sol"; -import "test/util/lib/LibOrderBookConstants.sol"; -import "test/util/abstract/IOrderBookV3Stub.sol"; -import "test/util/lib/LibTestAddOrder.sol"; - -import "src/concrete/OrderBook.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"; +import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterStoreV1.sol"; +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} from "src/concrete/OrderBook.sol"; +import {DeployerDiscoverableMetaV3ConstructionConfig} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; /// @title OrderBookExternalTest /// Abstract contract that performs common setup needed for testing an orderbook @@ -25,7 +31,7 @@ import "src/concrete/OrderBook.sol"; /// Inherits from Test so that it can be used as a base contract for other tests. /// Implements IOrderBookV3 so that it has access to all the relevant events. abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { - IInterpreterV1 immutable iInterpreter; + IInterpreterV2 immutable iInterpreter; IInterpreterStoreV1 immutable iStore; IExpressionDeployerV3 immutable iDeployer; IOrderBookV3 immutable iOrderbook; @@ -34,7 +40,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { constructor() { vm.pauseGasMetering(); - iInterpreter = IInterpreterV1(address(uint160(uint256(keccak256("interpreter.rain.test"))))); + iInterpreter = IInterpreterV2(address(uint160(uint256(keccak256("interpreter.rain.test"))))); vm.etch(address(iInterpreter), REVERTING_MOCK_BYTECODE); iStore = IInterpreterStoreV1(address(uint160(uint256(keccak256("store.rain.test"))))); vm.etch(address(iStore), REVERTING_MOCK_BYTECODE); @@ -43,8 +49,8 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { vm.etch(address(iDeployer), REVERTING_MOCK_BYTECODE); vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), - abi.encode(iInterpreter, iStore, address(0)) + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(iInterpreter, iStore, address(0), "") ); bytes memory meta = vm.readFileBinary(ORDER_BOOK_META_PATH); console2.log("OrderBookExternalMockTest meta hash:"); @@ -63,16 +69,16 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { /// storage accesses. function addOrderWithChecks(address owner, OrderConfigV2 memory config, address expression) internal - returns (Order memory, bytes32) + returns (OrderV2 memory, bytes32) { config.evaluableConfig.deployer = iDeployer; - (Order memory order, bytes32 orderHash) = + (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, expression); assertTrue(!iOrderbook.orderExists(orderHash)); vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), - abi.encode(iInterpreter, iStore, expression) + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(iInterpreter, iStore, expression, "") ); vm.expectEmit(false, false, false, true); emit AddOrder(owner, iDeployer, order, orderHash); @@ -100,8 +106,8 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { // mock. vm.mockCall( address(iDeployer), - abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), - abi.encode(iInterpreter, iStore, expression) + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(iInterpreter, iStore, expression, "") ); vm.record(); vm.recordLogs(); @@ -120,7 +126,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { /// Boilerplate to remove an order with a mocked deployer and checks events /// and storage accesses. - function removeOrderWithChecks(address owner, Order memory order) internal { + function removeOrderWithChecks(address owner, OrderV2 memory order) internal { bytes32 orderHash = LibOrder.hash(order); // This check assumes the order exists before we try to remove it. assertTrue(iOrderbook.orderExists(orderHash)); diff --git a/test/util/abstract/OrderBookExternalRealTest.sol b/test/util/abstract/OrderBookExternalRealTest.sol index 84e8607f9..ce094642a 100644 --- a/test/util/abstract/OrderBookExternalRealTest.sol +++ b/test/util/abstract/OrderBookExternalRealTest.sol @@ -1,28 +1,37 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "lib/forge-std/src/Test.sol"; -import {RainterpreterNPE2} from "lib/rain.interpreter/src/concrete/RainterpreterNPE2.sol"; -import {RainterpreterStoreNPE2} from "lib/rain.interpreter/src/concrete/RainterpreterStoreNPE2.sol"; -import {RainterpreterExpressionDeployerNPE2} from "lib/rain.interpreter/src/concrete/RainterpreterExpressionDeployerNPE2.sol"; - -import "test/util/lib/LibTestConstants.sol"; -import "test/util/lib/LibOrderBookConstants.sol"; -import "test/util/abstract/IOrderBookV3Stub.sol"; - +import {Test, Vm, console2} from "forge-std/Test.sol"; +import {RainterpreterNPE2} from "rain.interpreter/src/concrete/RainterpreterNPE2.sol"; +import {RainterpreterStoreNPE2} from "rain.interpreter/src/concrete/RainterpreterStoreNPE2.sol"; +import {RainterpreterExpressionDeployerNPE2, RainterpreterExpressionDeployerNPE2ConstructionConfig} 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} 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"; +import {RainterpreterParserNPE2} from "rain.interpreter/src/concrete/RainterpreterParserNPE2.sol"; abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { - IInterpreterV1 internal immutable iInterpreter; - IInterpreterStoreV1 internal immutable iStore; IExpressionDeployerV3 internal immutable iDeployer; + IInterpreterV2 internal immutable iInterpreter; + IInterpreterStoreV1 internal immutable iStore; + IParserV1 internal immutable iParser; IOrderBookV3 internal immutable iOrderbook; IERC20 internal immutable iToken0; IERC20 internal immutable iToken1; constructor() { - iInterpreter = IInterpreterV1(new RainterpreterNP()); - iStore = IInterpreterStoreV1(new RainterpreterStore()); + iInterpreter = IInterpreterV2(new RainterpreterNPE2()); + iStore = IInterpreterStoreV1(new RainterpreterStoreNPE2()); + iParser = IParserV1(new RainterpreterParserNPE2()); // Deploy the expression deployer. vm.etch(address(IERC1820_REGISTRY), REVERTING_MOCK_BYTECODE); @@ -39,9 +48,10 @@ abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { console2.logBytes32(keccak256(deployerMeta)); iDeployer = IExpressionDeployerV3( address( - new RainterpreterExpressionDeployerNP(RainterpreterExpressionDeployerConstructionConfig( + new RainterpreterExpressionDeployerNPE2(RainterpreterExpressionDeployerNPE2ConstructionConfig( address(iInterpreter), address(iStore), + address(iParser), deployerMeta )) ) diff --git a/test/util/abstract/OrderBookSelfTest.sol b/test/util/abstract/OrderBookSelfTest.sol index e52f760c4..9d49ce726 100644 --- a/test/util/abstract/OrderBookSelfTest.sol +++ b/test/util/abstract/OrderBookSelfTest.sol @@ -20,8 +20,8 @@ abstract contract OrderBookSelfTest is Test, OrderBook { vm.etch(address(deployer), REVERTING_MOCK_BYTECODE); vm.mockCall( address(deployer), - abi.encodeWithSelector(IExpressionDeployerV3.deployExpression.selector), - abi.encode(address(0), address(0), address(0)) + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(address(0), address(0), address(0), "") ); vm.resumeGasMetering(); } diff --git a/test/util/concrete/FlashLendingMockOrderBook.sol b/test/util/concrete/FlashLendingMockOrderBook.sol index 79f21c3be..66bf219cd 100644 --- a/test/util/concrete/FlashLendingMockOrderBook.sol +++ b/test/util/concrete/FlashLendingMockOrderBook.sol @@ -25,8 +25,8 @@ contract FlashLendingMockOrderBook is IOrderBookV3 { } function clear( - Order memory alice, - Order memory bob, + OrderV2 memory alice, + OrderV2 memory bob, ClearConfig calldata clearConfig, SignedContextV1[] memory aliceSignedContextV1, SignedContextV1[] memory bobSignedContextV1 @@ -34,7 +34,7 @@ contract FlashLendingMockOrderBook is IOrderBookV3 { function deposit(address token, uint256 vaultId, uint256 amount) external {} function flashFee(address token, uint256 amount) external view returns (uint256) {} function maxFlashLoan(address token) external view returns (uint256) {} - function removeOrder(Order calldata order) external returns (bool stateChanged) {} + function removeOrder(OrderV2 calldata order) external returns (bool stateChanged) {} function vaultBalance(address owner, address token, uint256 id) external view returns (uint256 balance) {} function withdraw(address token, uint256 vaultId, uint256 targetAmount) external {} diff --git a/test/util/lib/LibTestAddOrder.sol b/test/util/lib/LibTestAddOrder.sol index 0ffe18296..443807561 100644 --- a/test/util/lib/LibTestAddOrder.sol +++ b/test/util/lib/LibTestAddOrder.sol @@ -1,10 +1,15 @@ // SPDX-License-Identifier: CAL pragma solidity ^0.8.19; -import "lib/rain.metadata/src/LibMeta.sol"; -import "src/interface/unstable/IOrderBookV3.sol"; -import "src/lib/LibOrder.sol"; -import "src/concrete/OrderBook.sol"; +import {META_MAGIC_NUMBER_V1} from "lib/rain.metadata/src/LibMeta.sol"; +import {LibOrder} from "src/lib/LibOrder.sol"; +import {OrderConfigV2, OrderV2, IO} from "src/interface/unstable/IOrderBookV3.sol"; +import {IInterpreterV2, SourceIndexV2} 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 {EvaluableV2} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {HANDLE_IO_ENTRYPOINT} from "src/concrete/OrderBook.sol"; +import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol"; library LibTestAddOrder { /// A little boilerplate to make it easier to build the order that we expect @@ -12,15 +17,15 @@ library LibTestAddOrder { function expectedOrder( address owner, OrderConfigV2 memory config, - IInterpreterV1 interpreter, + IInterpreterV2 interpreter, IInterpreterStoreV1 store, address expression - ) internal pure returns (Order memory, bytes32) { - Evaluable memory expectedEvaluable = Evaluable(interpreter, store, expression); - Order memory order = Order( + ) internal pure returns (OrderV2 memory, bytes32) { + EvaluableV2 memory expectedEvaluable = EvaluableV2(interpreter, store, expression); + OrderV2 memory order = OrderV2( owner, LibBytecode.sourceCount(config.evaluableConfig.bytecode) > 1 - && LibBytecode.sourceOpsLength(config.evaluableConfig.bytecode, SourceIndex.unwrap(HANDLE_IO_ENTRYPOINT)) + && LibBytecode.sourceOpsCount(config.evaluableConfig.bytecode, SourceIndexV2.unwrap(HANDLE_IO_ENTRYPOINT)) > 0, expectedEvaluable, config.validInputs, From 31f5a4488778fc671e28239031275b63dcee22c9 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 21 Nov 2023 23:14:02 +0400 Subject: [PATCH 03/14] fix compile --- .gitmodules | 6 +++--- lib/rain.interpreter | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index dfb7e6e98..1aeddb0af 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,9 +22,9 @@ [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts -[submodule "lib/rain.interpreter"] - path = lib/rain.interpreter - url = https://github.com/rainprotocol/rain.interpreter [submodule "lib/rain.factory"] path = lib/rain.factory url = https://github.com/rainprotocol/rain.factory +[submodule "lib/rain.interpreter"] + path = lib/rain.interpreter + url = https://github.com/rainprotocol/rain.interpreter diff --git a/lib/rain.interpreter b/lib/rain.interpreter index 059d6405c..3ea90f4f9 160000 --- a/lib/rain.interpreter +++ b/lib/rain.interpreter @@ -1 +1 @@ -Subproject commit 059d6405c4315a1c681492c9c73315d06bcff162 +Subproject commit 3ea90f4f970210690065bb54b4e21fb648d17f7f From 3b1a33187d88e0b79c72827ef149ce4b8b42b593 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 22 Nov 2023 10:07:54 +0400 Subject: [PATCH 04/14] wip on tests --- .gitmodules | 6 ++-- foundry.toml | 2 +- lib/rain.interpreter | 2 +- ...ericPoolOrderBookV3ArbOrderTaker.rain.meta | Bin 1412 -> 1429 bytes ...ericPoolOrderBookV3FlashBorrower.rain.meta | Bin 1414 -> 1422 bytes meta/OrderBook.rain.meta | Bin 5752 -> 5803 bytes ...rocessorOrderBookV3ArbOrderTaker.rain.meta | Bin 1361 -> 1380 bytes ...loyGenericPoolOrderBookV3FlashBorrower.sol | 4 +-- script/DeployOrderBook.sol | 4 +-- src/abstract/OrderBookV3ArbOrderTaker.sol | 25 ++++++++------- src/abstract/OrderBookV3FlashBorrower.sol | 29 +++++++++--------- src/concrete/OrderBook.sol | 7 +++-- ...RouteProcessorOrderBookV3ArbOrderTaker.sol | 2 +- test/concrete/OrderBook.addOrder.t.sol | 2 +- ...essorOrderBookV3ArbOrderTaker.sender.t.sol | 8 +++-- test/util/abstract/ArbTest.sol | 2 ++ .../abstract/OrderBookExternalRealTest.sol | 4 ++- 17 files changed, 55 insertions(+), 42 deletions(-) diff --git a/.gitmodules b/.gitmodules index 1aeddb0af..dfb7e6e98 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,9 +22,9 @@ [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts -[submodule "lib/rain.factory"] - path = lib/rain.factory - url = https://github.com/rainprotocol/rain.factory [submodule "lib/rain.interpreter"] path = lib/rain.interpreter url = https://github.com/rainprotocol/rain.interpreter +[submodule "lib/rain.factory"] + path = lib/rain.factory + url = https://github.com/rainprotocol/rain.factory diff --git a/foundry.toml b/foundry.toml index 410b434f7..0d45c9a29 100644 --- a/foundry.toml +++ b/foundry.toml @@ -22,7 +22,7 @@ cbor_metadata = false # Build metadata used for testing rain meta aware contracts in this folder rather # than expose ffi to forge. -fs_permissions = [{ access = "read", path = "./meta"}] +fs_permissions = [{ access = "read", path = "./meta"}, {access = "read", path = "./lib/rain.interpreter/meta/RainterpreterExpressionDeployerNPE2.rain.meta"}] [fuzz] runs = 5096 \ No newline at end of file diff --git a/lib/rain.interpreter b/lib/rain.interpreter index 3ea90f4f9..ad53f8a60 160000 --- a/lib/rain.interpreter +++ b/lib/rain.interpreter @@ -1 +1 @@ -Subproject commit 3ea90f4f970210690065bb54b4e21fb648d17f7f +Subproject commit ad53f8a603bbec175761b9ac25bf3de52cf71cf8 diff --git a/meta/GenericPoolOrderBookV3ArbOrderTaker.rain.meta b/meta/GenericPoolOrderBookV3ArbOrderTaker.rain.meta index d24819ceffdaaf82bbd3c2619317b7ac7af0c16c..025eed4d7d5bafff9657d8b6103cf8d742477863 100644 GIT binary patch delta 1077 zcmV-51j_q_3zZ9h{|br5bnbX`r2tt37VTKgZrd;new88TT-t8Kw%fXPn1OWxnl6VG zIVcv}YPBUplG9{E-+h#SWm~r8w7qP*1hGYtpD6Mp>FeJ!#*>6>*Wb=s8zDcja+`G7OcNW^}@lHGEmQwg8> z)V++~4sPjx94^J@<2P^X!?AjQx%Oxq+M*d+A$+2-m~j@TvBTtid@~7kN}@ry7rFjL zsu7Z>FTaU}#9LEO^^`<_FbB4)e(@EKDe#3UPmkHl#Q$(M_*{^Ic;0AdQw}yE=IusyC0J zpwJ1M-UPm0H%J`Wnmh6YrTQzzIg(In=sYh9_F160)Ts}n2VybG#pqIEs?Hhdt7L;A zQQ%yEl()A!!3@owuE;&e0``$lHS1IdD}1*I^U2|B9R99Gf(6*bN%KP9xuMYK#xg0D zJkHf%WR-4yA`$czn?Yrs4Nh5h+6-Aa$FDa*4AI8Wd5cts)4i{{W@Y8D5*w4JlQV_uUarBM27OJ(~4@DYP1x1!PwIT^-w{zk2P3%c*dQjVag^ zq09>}eH|A;MgQ)Ob%bT@vsL`+V%CW_r^P*RuM@R6ibBX@%+n4@c?9H^q>&D&yD@V+ zB3RfpD{Fw;ty<;-Q?vdlFXVl-%MI(nl4u81*5P=RX?KGiECNH^hjEk0;18;pc$W%) z=OWLfcXvY?cG}qsjrJ|7JCcnJ-e!se`YE@%Iak31YJ>5mswlV9xELq9+4Yd7e$_A^INwC=+^&~XWu-g&2N1^ zs`AC^AZtY9gO+=|^6X@KPV#>Y`b)-tpr?&J0|U>ChilT{O3#$*L}n&>!q184yuG&XcFagmaFno(+ZiISH+(`Z;SMmn-aH4eWieq)bz5gtc_H5|tSaCuh0!9S vmjUNaiPx=B@P>q7_u7S!l@TgU5+St;O7RiSYYejO0d~@9)_(xA5(IJqk%AV{ delta 1060 zcmV+<1l#+S3xo@Q{|br5bnbX`r2tt31?^bPZrd;new88TT-yC$+ihJt%)q(;OV`7S z92ARfwc3&)$!W5o?>@?QY}t}+Ic+c7E4Q-1AcZ zBG(8h(3fAuLgKBdU~&Efq&R_VA>o5uFExqprn#k)Jvr~opW3AUMi?)0a)PP4OGS?0uSud{-aZS3El_J| zI8RkylFlcyp)etFBE;Px+K_6rL^r*N&bFD^gLJkhz02dLpnIooG}_L9TXqX%Ls%BAR1V%Yzb^i`C>kf?Aj_P2NW5;L@T zx*&IdAS>8MAyvg;X)Am;2=me5YaITzL4t+Q#7X-?-uj`?r^YfVl>*My;%$|$e&GFop^6r+yM_dPlur>#4N=ubtozz95*CSbVU8lo8Jx5!me0F8yb}<+4g~{ zSpSq4%I?~uE)CE6Vp%mqY?$dLA7yd(~CzHqBGjq88dt~N~X;8H3a3hhPqxm zB;=}Mx-1%!?qKH`0f}7Wx~OubnB3gr?^gbt7hfHwO>TWYsM`b!3&#|=CKqt3I3Yt~}Qz?5@;BC`;^2rl1lWEUq3SKu##A8^v*dTHj1gX*9b znj|Him8yc&bV8;SXt%~JqdRd+~Gx=^|Re>Ok77;xUIDbmK>I{L`BnG=0&#r{5 ej8J)&38_`I7a!rg)(G1jT_>Gp^#`*f1abkzyBvuC diff --git a/meta/GenericPoolOrderBookV3FlashBorrower.rain.meta b/meta/GenericPoolOrderBookV3FlashBorrower.rain.meta index 080da2a532176ab412cd5ca4deee61da22bc1ec1..2c75b2420e9bca8cb8f97a13d24cd47df35a0fd5 100644 GIT binary patch delta 1080 zcmV-81jqY^3yuqa{|br5bnbX`r2tt38SPljZreBzewD&!Uz+SLy1i|h1S_Cf19dlt z7CzA8Bw-_w0!cY`i@bY>`lTdFBAo;U+FlGxoZ);N&U`bY&)*h|XSr63xA->}X(l-E z>XC5`l9S})A%n%+1))@eQj6t+lhnMRkR{>(65r^q$m4Qz0>(h6FmoiLn{C~r4TN`oxTv^e1mOx=eX`C6AbO5$BBZ*l$!q&R~cA>kjnjY^T@ zl-HWX_hCNmkwnhNXreKxKM=+XDtLW_sne6z80<5Dh&9lEG2VM7QEZIS>>bKG9MNw< z|Icev26tDyMNW{B4yniy{0&JIEW2l+u*YODpgw1Fce%^Fy1{Mcy2Yo9wUZ5_JNpe#?${J*!1-eUv zax{B?AeN$BiY_Il$eok1!Z{fd70y+Cd)KE0v7ZSHxCf9G>=U2jIiPqee0K=*$>D1p z{-#BO_1?ru_d?#dq0r~X5|m0F=jxEY%C}#T2*xVLKTO zWLEsOlbN-zy>K} zD9T<6x!;fE9*R4zdmMXL(VLF!teHL?B_SU$8W3vOY3XL|n4qgl>bhu4`m^Cg?DdWV z`xwj5EsV97^@t<4xGJhFE2h6;12OD>9&%oMpb4A)=rj~&_n$4I`7zBsoO$*^BPaPi zMExW~)YFEhiE-)0!!_$Lt!K&&B9l#gwe;xgLJEybE2LN+Lvu5nB6#z;^M{j4i%La* z%V{{X1Ax2B9>Uu(cnAZApX4*5K3wS>nn@tJ_FtLY@vZG$oAg?zUzvTA@A yMvI1C2An&}|LBd8HzWqTPp^cmEK+%v38__7i_hdzX9(^Ozd@(jd=w8Ne!d#N$^U2@;v@T)o{(9}fHnc-C zv_betV=3b-%~OZT<@{z6>zpK$a4$>!t6U=_PhY+lD~Wflyv6xvkm3}sg@pg)cCAT# z7v`2;p67fl(;Jie17W<#=9fp9dUetogM9|E2KqmLhHTFyij9$yt)aYzk^L>`PrNo| zaCgO9rSZXhWd0Uu}I2GdV7;Q+3TB4g?MCbd= z>_OtK>G|s9X^Mk+j0J^3*o-F9mraNEk>3scem0@hc#SznGRREYv7Qq0l; zMR|ndj^v4ssJnS{yCGWH6{~1NqcSDCJ}?#QxAH>S-MZYcnJkFC?#81;4~GSF0nsXd zGNgSRFNp&Dq>8|sR5+V>CcL{7(y-UgK4`XQQNyulZcI0m6wtS&)vK2_6lE`k-0nwm z2gMDS{f(_t^hO&yW2VnWNyyiS27(&)Sh`s|CgiGOx-J@${$Mu|dA;MnKE}dx17nS4 zJ>1AGu8Jzdin(vtIt=@UoEKkL!sb4IIt_){oo9<^en4}NWu6_-$VvW;Pru0c^tf?p zVo-YaaLqbA>zQ(c$Yc|r96dU^kTT=i6;djXp}84O5xn_U`O`_IMWv#D??+=l_f@97!Q@$EFgb8gs#TEgR(_(Z_g)m#$lw!wh&Ouk!LHNXp_MMKXf1I``g qfAt2)YZ8OqqgO&!7O6bTgw!gk#bqA-5o<7L1$n8Op9?ecejSQtIuNNkJ^u|#^@w(;+5 zm>(r1k39M5JmGXsgvVBxqj`X@fWqy`h|z5y!YKT`AorSwm;O$;$Y>d0#YIRY@l_j-`yfBvFb6Foj{Gq{fF3I)WUl6#6|#Bon%A)zFU!f`yJgzwN| zx)nq9l&?y8luTC-`N<|6^eWm(SJ>b}t&Y|9E{tVQv~;LBNvUQz$@a9FY3?vZwCXr% zR@aD7b!3h#b*Sd{lYK|j5Ab->Zq#_&(rU~klI;h7O!^1c15z}+*kq`wUJA>0I0Sp>* zHm|3kCCK! z@p{sKzi7%ThKFqTZU!iK_DlBYFDjztl5t=Pw$FiOToL2R-OMBaF;gC?l@6eP z*T>RA!BXzjps3WMMnYA&?&bz#JcC1eb2ZQ_xIBtbqsQ~j_a|A7cm+%MvH)AZV+xC> z{MW7SyT#ey!1fug`1c6&f&I8T(zn|;qW~koNO0Fi0Oa@B$n+Fj3OS#2@fSc^Q99t| zcLvWHJZJFUufbDjx`)l>V8OwHgN1j00}J3JwclDbuG)A~l`gjR__k8^qLX@leTnR0 zDoUg{A1*hym7BnBHceF8IkknG%gn4^~^uZw|z>Saoo?{|3e zwZk(TRoS3a2Vy9fP%OzpCOO(Su$>HA(fl{uTy)ZrWj#WA2c5q;J^Z~`>l;3QM_NUh zvx~Kdu`eKVe~lzzPGgN4gS+|5_=?u4s!>((O-bQy#N}>WkmiCk7o@$@%Zh6pvK2nK z`wEAF4g(zqz5@*Gi+QrSBC1!;hBc>sTCSxa_qJfPOHJ6MFD$CwMX~IfW1qi zw8oRLwkrDUBVD4EmUNdD&1Yf-q3eJAe7s=&&etNM>Rqx1lyUKni+7xVL3m>Z!9L#E z-hEdEJq`;T7C0>UC|D4eo^(S3SDACLl{s=Bl{g6e+UYALso@wgtH9DV+x zK04l+$EFX*u!Lh^$PFHqS_Q=-TC!VZ2^~BjUNorHW`JzXA!z;PRkLZ^`)IC zop;uX;HTE2D21B{Sh5~j)C&Pdh=+opVMX$Ux%#w@D5t&G<>`21&$e}NM5sybceB~8 zjSEm+fa(I&k9|2mGXT@9AbJbw^n$Yce`YK!{gg--3X@!6b4?|Gg2Q2l!w!dCkyL{S zu1M;&i=?DYQItuQd{|br5bnbX`r2tt57wue2Z`(K!{wsygz9dD9ptt6Q8fYpY$!38K ze4r&d;YK12l5%V;`rmg%OD6TEB*%4PUfNhBXE;Ohn+HdF{BK0)B9>zG4gU05v|tp| z^e3SbbBeY=uw#SR@O26KK=4lvnG0c)@E>>&?O2D2^t{hzh=A zi|N)3)l(bjIOtV$ldiPEg<2h}?OhtnUTNh}bCOcc(#!X>nQ7rL#kB4? zX;!z0P<3QZ-byK&of7L8`+;Z>;)%C6hLa7^eX;X@V!2m-cP!>U9?GwMW8T4k!#8E} z(`NxLZA%MK5K7VsC}!0N4I7Pk^SQthR>Pa0vzP`QHI&dj)4Ty5eSFVeFulY+iBKr= zQ#h-Wz@RZ>vt|lfgj~NHA|fRH=YdPCMd*iJ+4LKCiR#gB!X%~p#2%F zR>Q=5oSFn6Rw;UQN(a#ExU^7mHn(a}R2nfOrK;RW<0$hS2I;NULak(b6`@ws`#lJM zygWy|goWELxHj*X($XnMYNPpn(JgpVLxwB<1A=Q{KdFze?RL#Yh!Nl;Bup*<#Ged& z^2;ryOiQ--b0DoK9q{ryW9N*WGj<=-*eN94!Pat+;2^<4!iRtaaE`iftOgft;?*TA zZ9Tn>jDzT89^X(RJD7?RDM`r6^+WA{7Oy3$0Wek5lvP zBxsLUayBkN za{-zQ&_3V=#VwB55+B?hg~LCGe-8iNJ^l^DyJi8%;EWGzPxo|ONkN`$foPkOut{53 z)Rv2KadTUNc~TFJgER^9aAHnHm`y{h+dX>OSQpDW^&TNQX}T)zMvB#4TN@RCnLsXU zv;&39$^x`E&O>F@Z&fQ;|6+)LGi}baS*pRdTye;|MBOXR3#LX$M5U-SHtp`<2F-J& zm-!|Oi$3V(D8r_hv+&z4G>|UHV(9``)oSOW1fi>af?}j#{a)2Prs{pI7L;+3j*E1h zIrxx~&gQneF5GcA;Bdg< zuI)tWy|b1CzjhWyDcnSVz>4+Aqh16sLVOg4Eh|za%++UWL^bW5E>F)pdbX*0BSKAb zx0}swZCr5bf>Rfq9`AMh)BsDfUg$lf&`YWw{`sz`@hrtem9R|CS zC|447z$H<#y#&gn$qFBAG*3*w=(J@DqQ{lF+z##-A4(>n5k~Vc0hUq|@fwP=-ZqN1 sx25~Zi%s)=&QXY{|5kaSUeWu({%(Nz7by3)$G~x7rvsVUG5G^1Xd;kCd diff --git a/meta/RouteProcessorOrderBookV3ArbOrderTaker.rain.meta b/meta/RouteProcessorOrderBookV3ArbOrderTaker.rain.meta index 783bc65f656a0ae353bfe0ea95c84d1487ee0dc1..0201272b33e383469a1cafafc80043686167d3c5 100644 GIT binary patch delta 1095 zcmV-N1i1Ur3gilZ{|br5bnbX`r2tt3DD7Cya@#f#ewB>Qy4Y?zX>M`sPB~LY9n00B z866;EZKEau4ge}rJAU^r_zMys3Ci{*$wea)i`@^4-EVjK<-Y~vS+3RM1OAOgnh6fP zdSqOKDiR_(EeT<1EcnkICiqW)kb1B%^R| zO8u)`BcwoIeikcxCy9b(_be0+K&_>5eo#Z?u$;}p!i3_b5KpIQLyFT9-SjTHK4fMO(r8V#n~T?> zdh-|y3QpJzCh(VShs2SsxhGFhYPe!tBMIe(&dZ`;p9Q*0PJNg>5KB=mMVAs&b*{)z zB^wQYi3;bczP-%_W@zzrN1i}du+KuOnNuCC@ZBTK7l*HL`1=+K7GM)6-3xi|heBT) z%dAuiI9G>}RlfTNiD0PMj4BIkaO$$tXUN7mVZ8}rNOp$Kd!#y^?nBkJC@ZIx*pwVz zNyF;aIT6v(CIZEuMe}ov6oA6k?WQo;oBI5RiM4Cpx13 z#?0@CXl2)|q5&HApqQ1;b6H*7~sq8(60hZ9hy{S9`siVSg|#!aGtKdNGX z=3OeBivpA0-wkOvXm2kx*|#WnB%2z%%@hapQ)zW`W{Y`PlRgZISYZbl0 z%Fdec(@`?#i$ViJ)hMiVYt~K)x~inEi?*acR(eJ}B6qkhsyr#?H@5|F>wnIRZyxjJ zw;>-j`C@gDEu!f`%RgQPb}|De`7s86eIsMg%f_COf#=P`HS2I?V9Gg>S%}^RmvA?- zi<5;b@Rz}lIB#*iHdDq)l~4;!l9J9!RY7WcA=5JJ)i@IgerJ>L1UrV)N^3zyzsm8j znQY?yow5sW&*1AkVECOoBRYN@2YAg5pHNHK0cO{m*8sMzCXBgmb4Han^4-ckssce6 zEh2hzaJPsE{*)p{jUqVsoLz4K(x10K_2$)k5`#SuR6yneibI?Tv~nxxKUaL&rrfNr3aWC z6l>dx+LA|-Lju!xXJtFKY{|Bqwin=%iLKS{r`7JayZ-)r#(0)%HG7MHW07Wp1Fs$# z*C07bE_WHs-p&Z65|oLKn-rc3N z%wzrRw6b){R4g_i$vS~^)NpnDUhqh;a4mO62zK+3MQMn2+9Gm@}huw*x!=v=}F zK6NkSH-lS$oWte#eEjlNb2!%Q->==8(2qpjc1)sJU#i<0%4_J^-+=zg_ofW)ws?booM5W%QjsJ0Ymz9Kx6eXh3)ET~ z&QsNwr1QyaC`?G42yu6aHl!LY(M`{yvu$SfAf4?=@9Ow*DAzp3f`St^y@~XF)gn`5 zO#{E1O(@mR+-FDzxuMmPob9tfd&%MH(F3s*Ai+Xt;-q~cul-QyV`G_=N&)9;@wUp>KadFe zNPkdSV5708|1Lw;&I#)g5JR#yblxG=;dJk-auIJ8p(&*Ml8 z$wR42h@{zfOE^s+T3GjJ)~C>FWEPNF@z+j&X4bq8!sS)C#0C*;t;)Oz(&xAcYWnwg zjw3AVVOJloPP{iQ?tllKr^8SbVwPf-IusQUjvJCEI->sO&F_Y2VOOl84UNi_Z2Q1e ztbfW2Wq0dy!)mY~cDkE@673EP<^rNcWJvokUJ?cPK@}5kQsHb8nDG8iNW)fp`=HT( zo<+H1(b({7CMlrrORHB$HWXzqO}Smu+Y~ok_BXap(HU**j2S)~B~xbl8iI0LLtU>O z5^_~BT^0>Vcd+w}fJClwT~s+zOm1%RcPoF+i?0sTCbvEx)!Ab8jt!#m5z9YV1@y#QRm6SHES_tV9Ggvky(gd2A6L)vWt_2EASV=cQ|Qry)^U1L3L0I zO_Gw%N>xE>Iw8|A>*+8P34Upl@CZAG(@JAOMQ`MA*o?OC{vO$dw_)&e8Zi9QoDm)0 z4g);nhEJ#^>;SXt&0_#tRd+~6ZvjoRe>Ok77;x;xC=xCU!;gpqX-TvK4;ex ufb{3>i_WBaO=7TzflA0qTa{;-kXl81@eyKf&Dq`gdeUiDe*m*J1TO)-qZ`x! diff --git a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol index 5ee9286c4..b6abc9cc0 100644 --- a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol +++ b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "lib/forge-std/src/Script.sol"; -import "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; +import {Script, console2} from "forge-std/Script.sol"; +import {GenericPoolOrderBookV3FlashBorrower, DeployerDiscoverableMetaV3ConstructionConfig} from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; /// @title DeployGenericPoolOrderBookV3FlashBorrower /// @notice A script that deploys a `GenericPoolOrderBookV3FlashBorrower`. This diff --git a/script/DeployOrderBook.sol b/script/DeployOrderBook.sol index 43cef91e4..80f3b5407 100644 --- a/script/DeployOrderBook.sol +++ b/script/DeployOrderBook.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "lib/forge-std/src/Script.sol"; -import "src/concrete/OrderBook.sol"; +import {Script, console2} from "forge-std/Script.sol"; +import {OrderBook, DeployerDiscoverableMetaV3ConstructionConfig} from "src/concrete/OrderBook.sol"; contract DeployOrderBook is Script { function run(bytes memory meta) external { diff --git a/src/abstract/OrderBookV3ArbOrderTaker.sol b/src/abstract/OrderBookV3ArbOrderTaker.sol index 27f7c8d29..6ce61a832 100644 --- a/src/abstract/OrderBookV3ArbOrderTaker.sol +++ b/src/abstract/OrderBookV3ArbOrderTaker.sol @@ -1,22 +1,24 @@ // SPDX-License-Identifier: CAL pragma solidity ^0.8.19; -import {ERC165, IERC165} from "lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol"; -import {ReentrancyGuard} from "lib/openzeppelin-contracts/contracts/security/ReentrancyGuard.sol"; -import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import {Initializable} from "lib/openzeppelin-contracts/contracts/proxy/utils/Initializable.sol"; -import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; -import {Address} from "lib/openzeppelin-contracts/contracts/utils/Address.sol"; +import {console2} from "forge-std/console2.sol"; + +import {ERC165, IERC165} from "openzeppelin-contracts/contracts/utils/introspection/ERC165.sol"; +import {ReentrancyGuard} from "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol"; +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 "lib/rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; +} 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 "lib/rain.factory/src/interface/ICloneableV2.sol"; -import {EncodedDispatch, LibEncodedDispatch} from "lib/rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; - +import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "rain.factory/src/interface/ICloneableV2.sol"; +import {EncodedDispatch, LibEncodedDispatch} from "rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; +import {LibNamespace} from "rain.interpreter/src/lib/ns/LibNamespace.sol"; import {IOrderBookV3, NoOrders} from "../interface/unstable/IOrderBookV3.sol"; import {IOrderBookV3ArbOrderTaker, IOrderBookV3OrderTaker} from "../interface/unstable/IOrderBookV3ArbOrderTaker.sol"; import {IInterpreterV2, DEFAULT_STATE_NAMESPACE} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; @@ -68,6 +70,7 @@ abstract contract OrderBookV3ArbOrderTaker is constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config) DeployerDiscoverableMetaV3(metaHash, config) { + console2.log("obv3aot constructor"); _disableInitializers(); } @@ -153,7 +156,7 @@ abstract contract OrderBookV3ArbOrderTaker is if (EncodedDispatch.unwrap(dispatch) > 0) { (uint256[] memory stack, uint256[] memory kvs) = sI9r.eval2( sI9rStore, - DEFAULT_STATE_NAMESPACE, + LibNamespace.qualifyNamespace(DEFAULT_STATE_NAMESPACE, address(this)), dispatch, LibContext.build(new uint256[][](0), new SignedContextV1[](0)), new uint256[](0) diff --git a/src/abstract/OrderBookV3FlashBorrower.sol b/src/abstract/OrderBookV3FlashBorrower.sol index 5464afa23..487529ad6 100644 --- a/src/abstract/OrderBookV3FlashBorrower.sol +++ b/src/abstract/OrderBookV3FlashBorrower.sol @@ -1,30 +1,31 @@ // SPDX-License-Identifier: CAL pragma solidity ^0.8.19; -import {ERC165, IERC165} from "lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol"; -import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; -import {Address} from "lib/openzeppelin-contracts/contracts/utils/Address.sol"; -import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import {ReentrancyGuard} from "lib/openzeppelin-contracts/contracts/security/ReentrancyGuard.sol"; -import {Initializable} from "lib/openzeppelin-contracts/contracts/proxy/utils/Initializable.sol"; +import {ERC165, IERC165} from "openzeppelin-contracts/contracts/utils/introspection/ERC165.sol"; +import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; +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 "lib/rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; -import {LibEncodedDispatch, EncodedDispatch} from "lib/rain.interpreter/src/lib/caller/LibEncodedDispatch.sol"; -import {LibContext} from "lib/rain.interpreter/src/lib/caller/LibContext.sol"; -import {LibBytecode} from "lib/rain.interpreter/src/lib/bytecode/LibBytecode.sol"; +} 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"; import {ON_FLASH_LOAN_CALLBACK_SUCCESS} from "../interface/ierc3156/IERC3156FlashBorrower.sol"; import {IOrderBookV3, TakeOrdersConfigV2, NoOrders} from "../interface/unstable/IOrderBookV3.sol"; -import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "lib/rain.factory/src/interface/ICloneableV2.sol"; +import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "rain.factory/src/interface/ICloneableV2.sol"; import { IInterpreterV2, SourceIndexV2, DEFAULT_STATE_NAMESPACE -} from "lib/rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; +} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import {IERC3156FlashBorrower} from "../interface/ierc3156/IERC3156FlashBorrower.sol"; -import {IInterpreterStoreV1} from "lib/rain.interpreter/src/interface/IInterpreterStoreV1.sol"; +import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterStoreV1.sol"; import {BadLender, MinimumOutput, NonZeroBeforeArbStack, Initializing} from "./OrderBookV3ArbCommon.sol"; import {EvaluableConfigV3, SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; +import {LibNamespace} from "rain.interpreter/src/lib/ns/LibNamespace.sol"; /// Thrown when the initiator is not the order book. /// @param badInitiator The untrusted initiator of the flash loan. @@ -290,7 +291,7 @@ abstract contract OrderBookV3FlashBorrower is if (EncodedDispatch.unwrap(dispatch) > 0) { (uint256[] memory stack, uint256[] memory kvs) = sI9r.eval2( sI9rStore, - DEFAULT_STATE_NAMESPACE, + LibNamespace.qualifyNamespace(DEFAULT_STATE_NAMESPACE, address(this)), dispatch, LibContext.build(new uint256[][](0), new SignedContextV1[](0)), new uint256[](0) diff --git a/src/concrete/OrderBook.sol b/src/concrete/OrderBook.sol index a854a1fc8..271512ce1 100644 --- a/src/concrete/OrderBook.sol +++ b/src/concrete/OrderBook.sol @@ -39,6 +39,7 @@ import {SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCaller 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"; /// This will exist in a future version of Open Zeppelin if their main branch is /// to be believed. @@ -152,7 +153,7 @@ uint256 constant CONTEXT_VAULT_IO_BALANCE_DIFF = 4; uint256 constant CONTEXT_VAULT_IO_ROWS = 5; /// @dev Hash of the caller contract metadata for construction. -bytes32 constant CALLER_META_HASH = bytes32(0xd6912c2a900b10b78c9c43592b8690b48c804fb78bbdcb3ceee1f56db830d137); +bytes32 constant CALLER_META_HASH = bytes32(0x2b317d8d308f0a16f5782cbec6cbc8de1cec7b337a90bd9ca8f1a38112f675c5); /// 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. @@ -741,7 +742,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash (uint256[] memory calculateOrderStack, uint256[] memory calculateOrderKVs) = order .evaluable .interpreter - .eval2(order.evaluable.store, namespace, _calculateOrderDispatch(order.evaluable.expression), context, new uint256[](0)); + .eval2(order.evaluable.store, LibNamespace.qualifyNamespace(namespace, address(this)), _calculateOrderDispatch(order.evaluable.expression), context, new uint256[](0)); Output18Amount orderOutputMax18 = Output18Amount.wrap(calculateOrderStack[calculateOrderStack.length - 2]); uint256 orderIORatio = calculateOrderStack[calculateOrderStack.length - 1]; @@ -841,7 +842,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash .interpreter .eval2( orderIOCalculation.order.evaluable.store, - orderIOCalculation.namespace, + LibNamespace.qualifyNamespace(orderIOCalculation.namespace, address(this)), _handleIODispatch(orderIOCalculation.order.evaluable.expression), orderIOCalculation.context, new uint256[](0) diff --git a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol b/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol index d622c7027..332de0454 100644 --- a/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol +++ b/src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol @@ -8,7 +8,7 @@ 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(0xe45ec12419e88f2fed9938b77267520926dc4a2b09229e92f25c2f512ac445b2); +bytes32 constant CALLER_META_HASH = bytes32(0x6b0cdd85f2332f483d4cf2ad85c9538af7c47632abd119a748d313b3681f8932); contract RouteProcessorOrderBookV3ArbOrderTaker is OrderBookV3ArbOrderTaker { using SafeERC20 for IERC20; diff --git a/test/concrete/OrderBook.addOrder.t.sol b/test/concrete/OrderBook.addOrder.t.sol index ae5568cca..1e21a1d32 100644 --- a/test/concrete/OrderBook.addOrder.t.sol +++ b/test/concrete/OrderBook.addOrder.t.sol @@ -13,7 +13,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { function testAddOrderRealNoSourcesReverts(address owner, OrderConfigV2 memory config) public { LibTestAddOrder.conformConfig(config, iDeployer); config.evaluableConfig.bytecode = hex""; - vm.expectRevert(abi.encodeWithSelector(OrderNoSources.selector, owner)); + vm.expectRevert(abi.encodeWithSelector(OrderNoSources.selector)); vm.prank(owner); iOrderbook.addOrder(config); } diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index 39724f37c..5facee199 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; +import {console2} from "forge-std/Test.sol"; + import "test/util/lib/LibTestConstants.sol"; import "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol"; @@ -15,10 +17,12 @@ 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); + console2.log("buildArbTestConstructorConfig"); return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config))); } constructor() ArbTest(buildArbTestConstructorConfig()) { + console2.log("foo"); ICloneableV2(iArb).initialize( abi.encode( OrderBookV3ArbOrderTakerConfigV1( @@ -30,7 +34,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { ); } - function testTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + function testRouteProcessorTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); RouteProcessorOrderBookV3ArbOrderTaker(iArb).arb( @@ -38,7 +42,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { ); } - function testMinimumOutput( + function testRouteProcessorMinimumOutput( OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index 6ad71c77c..db5ad5016 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -35,6 +35,7 @@ abstract contract ArbTest is Test { address iArb; constructor(ArbTestConstructorConfig memory config) { + console2.log("constructor"); iDeployer = config.deployer; iImplementation = config.implementation; iArb = Clones.clone(iImplementation); @@ -48,6 +49,7 @@ abstract contract ArbTest is Test { internal returns (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) { + console2.log("bcc"); deployer = address(uint160(uint256(keccak256("deployer.rain.test")))); // All non-mocked calls will revert. vm.etch(deployer, REVERTING_MOCK_BYTECODE); diff --git a/test/util/abstract/OrderBookExternalRealTest.sol b/test/util/abstract/OrderBookExternalRealTest.sol index ce094642a..e451b7edb 100644 --- a/test/util/abstract/OrderBookExternalRealTest.sol +++ b/test/util/abstract/OrderBookExternalRealTest.sol @@ -19,6 +19,8 @@ import {IERC1820_REGISTRY} from "rain.erc1820/lib/LibIERC1820.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; import {RainterpreterParserNPE2} from "rain.interpreter/src/concrete/RainterpreterParserNPE2.sol"; +string constant DEPLOYER_META_PATH = "lib/rain.interpreter/meta/RainterpreterExpressionDeployerNPE2.rain.meta"; + abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { IExpressionDeployerV3 internal immutable iDeployer; IInterpreterV2 internal immutable iInterpreter; @@ -43,7 +45,7 @@ abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { vm.mockCall( address(IERC1820_REGISTRY), abi.encodeWithSelector(IERC1820Registry.setInterfaceImplementer.selector), "" ); - bytes memory deployerMeta = LibAllStandardOpsNP.authoringMeta(); + bytes memory deployerMeta = vm.readFileBinary(DEPLOYER_META_PATH); console2.log("current deployer meta hash:"); console2.logBytes32(keccak256(deployerMeta)); iDeployer = IExpressionDeployerV3( From b73aa67b61986385f053dcb3423f53ae8693ab59 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 22 Nov 2023 10:21:16 +0400 Subject: [PATCH 05/14] wip on tests --- src/concrete/OrderBook.sol | 4 ++-- test/concrete/OrderBook.addOrder.t.sol | 10 +++++----- test/concrete/OrderBook.clear.handleIO.revert.t.sol | 2 +- .../concrete/OrderBook.takeOrder.handleIO.revert.t.sol | 2 +- test/concrete/OrderBook.takeOrder.maximumInput.t.sol | 2 +- test/concrete/OrderBook.takeOrder.precision.t.sol | 2 +- test/concrete/OrderBookV3FlashLender.reentrant.t.sol | 8 ++++---- test/util/abstract/ArbTest.sol | 4 +--- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/concrete/OrderBook.sol b/src/concrete/OrderBook.sol index 271512ce1..89faed4fb 100644 --- a/src/concrete/OrderBook.sol +++ b/src/concrete/OrderBook.sol @@ -744,8 +744,8 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash .interpreter .eval2(order.evaluable.store, LibNamespace.qualifyNamespace(namespace, address(this)), _calculateOrderDispatch(order.evaluable.expression), context, new uint256[](0)); - Output18Amount orderOutputMax18 = Output18Amount.wrap(calculateOrderStack[calculateOrderStack.length - 2]); - uint256 orderIORatio = calculateOrderStack[calculateOrderStack.length - 1]; + Output18Amount orderOutputMax18 = Output18Amount.wrap(calculateOrderStack[1]); + uint256 orderIORatio = calculateOrderStack[0]; { // The order owner can't send more than the smaller of their vault diff --git a/test/concrete/OrderBook.addOrder.t.sol b/test/concrete/OrderBook.addOrder.t.sol index 1e21a1d32..fbf88d263 100644 --- a/test/concrete/OrderBook.addOrder.t.sol +++ b/test/concrete/OrderBook.addOrder.t.sol @@ -21,7 +21,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { /// No handle IO reverts. function testAddOrderRealNoHandleIOReverts(address owner, OrderConfigV2 memory config) public { LibTestAddOrder.conformConfig(config, iDeployer); - (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(":;"); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(":;"); config.evaluableConfig.bytecode = bytecode; config.evaluableConfig.constants = constants; vm.expectRevert(abi.encodeWithSelector(OrderNoHandleIO.selector, owner)); @@ -32,7 +32,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { // /// A stack of 0 for calculate order reverts. // function testAddOrderRealZeroStackCalculateReverts(address owner, OrderConfigV2 memory config) public { // LibTestAddOrder.conformConfig(config, iDeployer); - // (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(":;:;"); + // (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(":;:;"); // config.evaluableConfig.constants = constants; // config.evaluableConfig.bytecode = bytecode; // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 0, 2)); @@ -44,7 +44,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { // function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfigV2 memory config) public { // LibTestAddOrder.conformConfig(config, iDeployer); // (bytes memory bytecode, uint256[] memory constants) = - // IParserV1(address(iDeployer)).parse("_:block-timestamp();:;"); + // IParserV1(address(iParser)).parse("_:block-timestamp();:;"); // config.evaluableConfig.constants = constants; // config.evaluableConfig.bytecode = bytecode; // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 1, 2)); @@ -56,7 +56,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { function testAddOrderRealTwoStackCalculateReverts(address owner, OrderConfigV2 memory config) public { LibTestAddOrder.conformConfig(config, iDeployer); (bytes memory bytecode, uint256[] memory constants) = - IParserV1(address(iDeployer)).parse("_ _:block-timestamp() chain-id();:;"); + IParserV1(address(iParser)).parse("_ _:block-timestamp() chain-id();:;"); config.evaluableConfig.constants = constants; config.evaluableConfig.bytecode = bytecode; vm.prank(owner); @@ -67,7 +67,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { function testAddOrderRealThreeStackCalculate(address owner, OrderConfigV2 memory config) public { LibTestAddOrder.conformConfig(config, iDeployer); (bytes memory bytecode, uint256[] memory constants) = - IParserV1(address(iDeployer)).parse("_ _ _:block-timestamp() chain-id() block-number();:;"); + IParserV1(address(iParser)).parse("_ _ _:block-timestamp() chain-id() block-number();:;"); config.evaluableConfig.constants = constants; config.evaluableConfig.bytecode = bytecode; vm.prank(owner); diff --git a/test/concrete/OrderBook.clear.handleIO.revert.t.sol b/test/concrete/OrderBook.clear.handleIO.revert.t.sol index 124cfbe9e..ba14f5de7 100644 --- a/test/concrete/OrderBook.clear.handleIO.revert.t.sol +++ b/test/concrete/OrderBook.clear.handleIO.revert.t.sol @@ -41,7 +41,7 @@ contract OrderBookClearHandleIORevertTest is OrderBookExternalRealTest { iOrderbook.deposit(outputToken, vaultId, type(uint256).max); assertEq(iOrderbook.vaultBalance(owner, outputToken, vaultId), type(uint256).max); - (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(rainString); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(rainString); EvaluableConfigV3 memory evaluableConfig = EvaluableConfigV3(iDeployer, bytecode, constants); config = OrderConfigV2(validInputs, validOutputs, evaluableConfig, ""); diff --git a/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol b/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol index 4c121969d..532ac4b42 100644 --- a/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol +++ b/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol @@ -41,7 +41,7 @@ contract OrderBookTakeOrderHandleIORevertTest is OrderBookExternalRealTest { TakeOrderConfigV2[] memory orders = new TakeOrderConfigV2[](configs.length); for (uint256 i = 0; i < configs.length; i++) { - (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(configs[i]); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(configs[i]); EvaluableConfigV3 memory evaluableConfig = EvaluableConfigV3(iDeployer, bytecode, constants); config = OrderConfigV2(validInputs, validOutputs, evaluableConfig, ""); diff --git a/test/concrete/OrderBook.takeOrder.maximumInput.t.sol b/test/concrete/OrderBook.takeOrder.maximumInput.t.sol index 665780efd..a62add95f 100644 --- a/test/concrete/OrderBook.takeOrder.maximumInput.t.sol +++ b/test/concrete/OrderBook.takeOrder.maximumInput.t.sol @@ -61,7 +61,7 @@ contract OrderBookTakeOrderMaximumInputTest is OrderBookExternalRealTest { OrderConfigV2 memory orderConfig; { (bytes memory bytecode, uint256[] memory constants) = - IParserV1(address(iDeployer)).parse(testOrders[i].orderString); + IParserV1(address(iParser)).parse(testOrders[i].orderString); IO[] memory inputs = new IO[](1); inputs[0] = IO(address(iToken0), 18, vaultId); IO[] memory outputs = new IO[](1); diff --git a/test/concrete/OrderBook.takeOrder.precision.t.sol b/test/concrete/OrderBook.takeOrder.precision.t.sol index f61841d2e..f01aaee6b 100644 --- a/test/concrete/OrderBook.takeOrder.precision.t.sol +++ b/test/concrete/OrderBook.takeOrder.precision.t.sol @@ -30,7 +30,7 @@ contract OrderBookTakeOrderPrecisionTest is OrderBookExternalRealTest { validOutputs[0] = IO(outputToken, outputTokenDecimals, vaultId); // These numbers are known to cause large rounding errors if the // precision is not handled correctly. - (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(rainString); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(rainString); EvaluableConfigV3 memory evaluableConfig = EvaluableConfigV3(iDeployer, bytecode, constants); config = OrderConfigV2(validInputs, validOutputs, evaluableConfig, ""); // Etch with invalid. diff --git a/test/concrete/OrderBookV3FlashLender.reentrant.t.sol b/test/concrete/OrderBookV3FlashLender.reentrant.t.sol index d45402377..74ea053e8 100644 --- a/test/concrete/OrderBookV3FlashLender.reentrant.t.sol +++ b/test/concrete/OrderBookV3FlashLender.reentrant.t.sol @@ -102,7 +102,7 @@ contract OrderBookV3FlashLenderReentrant is OrderBookExternalRealTest { function testReenterAddOrder(uint256 loanAmount, OrderConfigV2 memory config) external { LibTestAddOrder.conformConfig(config, iDeployer); (bytes memory bytecode, uint256[] memory constants) = - IParserV1(address(iDeployer)).parse("_ _:max-int-value() 1e18;:;"); + IParserV1(address(iParser)).parse("_ _:max-int-value() 1e18;:;"); config.evaluableConfig.bytecode = bytecode; config.evaluableConfig.constants = constants; // Create a flash borrower. @@ -122,7 +122,7 @@ contract OrderBookV3FlashLenderReentrant is OrderBookExternalRealTest { function testReenterTakeOrder(uint256 loanAmount, OrderConfigV2 memory config) external { LibTestAddOrder.conformConfig(config, iDeployer); (bytes memory bytecode, uint256[] memory constants) = - IParserV1(address(iDeployer)).parse("_ _:max-int-value() 1e18;:;"); + IParserV1(address(iParser)).parse("_ _:max-int-value() 1e18;:;"); config.evaluableConfig.bytecode = bytecode; config.evaluableConfig.constants = constants; @@ -155,12 +155,12 @@ contract OrderBookV3FlashLenderReentrant is OrderBookExternalRealTest { LibTestAddOrder.conformConfig(aliceConfig, iDeployer); (bytes memory bytecode, uint256[] memory constants) = - IParserV1(address(iDeployer)).parse("_ _:max-int-value() 1e18;:;"); + IParserV1(address(iParser)).parse("_ _:max-int-value() 1e18;:;"); aliceConfig.evaluableConfig.bytecode = bytecode; aliceConfig.evaluableConfig.constants = constants; LibTestAddOrder.conformConfig(bobConfig, iDeployer); - (bytecode, constants) = IParserV1(address(iDeployer)).parse("_ _:max-int-value() 1e18;:;"); + (bytecode, constants) = IParserV1(address(iParser)).parse("_ _:max-int-value() 1e18;:;"); bobConfig.evaluableConfig.bytecode = bytecode; bobConfig.evaluableConfig.constants = constants; diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index db5ad5016..9341021df 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "forge-std/Test.sol"; +import {Test, console2} from "forge-std/Test.sol"; import "openzeppelin-contracts/contracts/proxy/Clones.sol"; import "test/util/lib/LibTestConstants.sol"; @@ -35,7 +35,6 @@ abstract contract ArbTest is Test { address iArb; constructor(ArbTestConstructorConfig memory config) { - console2.log("constructor"); iDeployer = config.deployer; iImplementation = config.implementation; iArb = Clones.clone(iImplementation); @@ -49,7 +48,6 @@ abstract contract ArbTest is Test { internal returns (address deployer, DeployerDiscoverableMetaV3ConstructionConfig memory config) { - console2.log("bcc"); deployer = address(uint160(uint256(keccak256("deployer.rain.test")))); // All non-mocked calls will revert. vm.etch(deployer, REVERTING_MOCK_BYTECODE); From 006881b9a46a4b44b2bdb19fb8339da0fade5def Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 22 Nov 2023 12:17:03 +0400 Subject: [PATCH 06/14] wip on tests --- src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol | 2 +- .../GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol | 4 ++-- test/concrete/OrderBook.addOrder.mock.t.sol | 8 ++++---- test/concrete/OrderBook.addOrder.t.sol | 2 +- .../RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol | 4 ---- test/util/abstract/ArbTest.sol | 2 +- test/util/abstract/OrderBookExternalMockTest.sol | 6 +++--- test/util/abstract/OrderBookSelfTest.sol | 2 +- test/util/lib/LibTestAddOrder.sol | 3 ++- 9 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol b/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol index eee3f0606..73e700840 100644 --- a/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol +++ b/src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol @@ -6,7 +6,7 @@ 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(0x9059bb5e174f68880ee6c97e424fb152304bfff2949242eca6ca1783e843fa32); +bytes32 constant CALLER_META_HASH = bytes32(0xa519e069ba4e0d8fdcd8feb0a65292ee147333ffe032fa8341e427db6d78ed1c); contract GenericPoolOrderBookV3ArbOrderTaker is OrderBookV3ArbOrderTaker { using SafeERC20 for IERC20; diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol index 060871c64..1773bea2e 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol @@ -27,7 +27,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { ); } - function testTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + function testGenericPoolTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); GenericPoolOrderBookV3ArbOrderTaker(iArb).arb( @@ -36,7 +36,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { ); } - function testMinimumOutput( + function testGenericPoolMinimumOutput( OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, diff --git a/test/concrete/OrderBook.addOrder.mock.t.sol b/test/concrete/OrderBook.addOrder.mock.t.sol index ff2da95c8..9a579d9db 100644 --- a/test/concrete/OrderBook.addOrder.mock.t.sol +++ b/test/concrete/OrderBook.addOrder.mock.t.sol @@ -15,7 +15,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { function testAddOrderWithoutCalculationsReverts(address owner, OrderConfigV2 memory config) public { vm.prank(owner); config.evaluableConfig.bytecode = ""; - vm.expectRevert(abi.encodeWithSelector(OrderNoSources.selector, owner)); + vm.expectRevert(abi.encodeWithSelector(OrderNoSources.selector)); iOrderbook.addOrder(config); (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, address(0)); @@ -28,7 +28,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { vm.prank(owner); config.evaluableConfig.bytecode = hex"02000000040000000000000000"; config.validInputs = new IO[](0); - vm.expectRevert(abi.encodeWithSelector(OrderNoInputs.selector, owner)); + vm.expectRevert(abi.encodeWithSelector(OrderNoInputs.selector)); iOrderbook.addOrder(config); (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, address(0)); @@ -42,7 +42,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { config.evaluableConfig.bytecode = hex"02000000040000000000000000"; vm.assume(config.validInputs.length > 0); config.validOutputs = new IO[](0); - vm.expectRevert(abi.encodeWithSelector(OrderNoOutputs.selector, owner)); + vm.expectRevert(abi.encodeWithSelector(OrderNoOutputs.selector)); iOrderbook.addOrder(config); (OrderV2 memory order, bytes32 orderHash) = LibTestAddOrder.expectedOrder(owner, config, iInterpreter, iStore, address(0)); @@ -83,7 +83,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest { vm.mockCall( address(iDeployer), abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(iInterpreter, iStore, expression, "") + abi.encode(iInterpreter, iStore, expression, hex"00020000") ); vm.expectRevert(abi.encodeWithSelector(NotRainMetaV1.selector, config.meta)); iOrderbook.addOrder(config); diff --git a/test/concrete/OrderBook.addOrder.t.sol b/test/concrete/OrderBook.addOrder.t.sol index fbf88d263..2185d265b 100644 --- a/test/concrete/OrderBook.addOrder.t.sol +++ b/test/concrete/OrderBook.addOrder.t.sol @@ -24,7 +24,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(":;"); config.evaluableConfig.bytecode = bytecode; config.evaluableConfig.constants = constants; - vm.expectRevert(abi.encodeWithSelector(OrderNoHandleIO.selector, owner)); + vm.expectRevert(abi.encodeWithSelector(OrderNoHandleIO.selector)); vm.prank(owner); iOrderbook.addOrder(config); } diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index 5facee199..d98dc528b 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import {console2} from "forge-std/Test.sol"; - import "test/util/lib/LibTestConstants.sol"; import "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol"; @@ -17,12 +15,10 @@ 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); - console2.log("buildArbTestConstructorConfig"); return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config))); } constructor() ArbTest(buildArbTestConstructorConfig()) { - console2.log("foo"); ICloneableV2(iArb).initialize( abi.encode( OrderBookV3ArbOrderTakerConfigV1( diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index 9341021df..9a20844ee 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -54,7 +54,7 @@ abstract contract ArbTest is Test { vm.mockCall( deployer, abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(address(0), address(0), address(0), "") + abi.encode(address(0), address(0), address(0), "00020000") ); bytes memory meta = vm.readFileBinary(metaPath); console2.log("RouteProcessorOrderBookV3ArbOrderTakerTest meta hash:"); diff --git a/test/util/abstract/OrderBookExternalMockTest.sol b/test/util/abstract/OrderBookExternalMockTest.sol index 1f839d10d..016182600 100644 --- a/test/util/abstract/OrderBookExternalMockTest.sol +++ b/test/util/abstract/OrderBookExternalMockTest.sol @@ -50,7 +50,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { vm.mockCall( address(iDeployer), abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(iInterpreter, iStore, address(0), "") + abi.encode(iInterpreter, iStore, address(0), "00020000") ); bytes memory meta = vm.readFileBinary(ORDER_BOOK_META_PATH); console2.log("OrderBookExternalMockTest meta hash:"); @@ -78,7 +78,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { vm.mockCall( address(iDeployer), abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(iInterpreter, iStore, expression, "") + abi.encode(iInterpreter, iStore, expression, hex"00020000") ); vm.expectEmit(false, false, false, true); emit AddOrder(owner, iDeployer, order, orderHash); @@ -107,7 +107,7 @@ abstract contract OrderBookExternalMockTest is Test, IMetaV1, IOrderBookV3Stub { vm.mockCall( address(iDeployer), abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(iInterpreter, iStore, expression, "") + abi.encode(iInterpreter, iStore, expression, hex"00020000") ); vm.record(); vm.recordLogs(); diff --git a/test/util/abstract/OrderBookSelfTest.sol b/test/util/abstract/OrderBookSelfTest.sol index 9d49ce726..2eede248c 100644 --- a/test/util/abstract/OrderBookSelfTest.sol +++ b/test/util/abstract/OrderBookSelfTest.sol @@ -21,7 +21,7 @@ abstract contract OrderBookSelfTest is Test, OrderBook { vm.mockCall( address(deployer), abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(address(0), address(0), address(0), "") + abi.encode(address(0), address(0), address(0), "00020000") ); vm.resumeGasMetering(); } diff --git a/test/util/lib/LibTestAddOrder.sol b/test/util/lib/LibTestAddOrder.sol index 443807561..b21943aa2 100644 --- a/test/util/lib/LibTestAddOrder.sol +++ b/test/util/lib/LibTestAddOrder.sol @@ -52,6 +52,7 @@ library LibTestAddOrder { config.validOutputs = new IO[](1); config.validOutputs[0] = IO(address(0), 0, 0); } - config.evaluableConfig.bytecode = hex"02000000040000000000000000"; + // Taken from parser for "_ _:1e18 1e18;:;". + config.evaluableConfig.bytecode = hex"020000000c02020002010000000100000000000000"; } } From 13e7e6b8d4ad0d04d07baf257fdfaebcdbf2d20b Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 22 Nov 2023 12:34:32 +0400 Subject: [PATCH 07/14] fix tests --- .gas-snapshot | 142 +++++++++--------- ...loyGenericPoolOrderBookV3FlashBorrower.sol | 5 +- src/abstract/OrderBookV3FlashBorrower.sol | 4 +- .../GenericPoolOrderBookV3FlashBorrower.sol | 2 +- src/concrete/OrderBook.sol | 17 ++- src/interface/unstable/IOrderBookV3.sol | 8 +- ...cPoolOrderBookV3ArbOrderTaker.sender.t.sol | 4 +- ...cPoolOrderBookV3FlashBorrower.sender.t.sol | 8 +- .../OrderBook.clear.handleIO.revert.t.sol | 4 +- .../OrderBook.takeOrder.handleIO.revert.t.sol | 11 +- .../OrderBook.takeOrder.precision.t.sol | 6 +- ...essorOrderBookV3ArbOrderTaker.sender.t.sol | 4 +- test/util/abstract/IOrderBookV3Stub.sol | 11 +- .../abstract/OrderBookExternalMockTest.sol | 3 +- .../abstract/OrderBookExternalRealTest.sol | 5 +- 15 files changed, 131 insertions(+), 103 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 596b166e8..b20a5f7e6 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,92 +1,90 @@ -GenericPoolOrderBookV3ArbOrderTakerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332013, ~: 330346) -GenericPoolOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266192, ~: 265239) -GenericPoolOrderBookV3FlashBorrowerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 609043, ~: 605031) -GenericPoolOrderBookV3FlashBorrowerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 522442, ~: 519665) +GenericPoolOrderBookV3ArbOrderTakerTest:testGenericPoolMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332052, ~: 330383) +GenericPoolOrderBookV3ArbOrderTakerTest:testGenericPoolTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266210, ~: 265260) +GenericPoolOrderBookV3FlashBorrowerTest:testGenericPoolOrderBookV3FlashBorrowerMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 609059, ~: 605057) +GenericPoolOrderBookV3FlashBorrowerTest:testGenericPoolOrderBookV3FlashBorrowerTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 522448, ~: 519675) LibOrderTest:testHashEqual((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[])) (runs: 5096, μ: 196882, ~: 195948) LibOrderTest:testHashNotEqual((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[])) (runs: 5096, μ: 298108, ~: 295793) -OrderBookAddOrderMockTest:testAddOrderSameAccountWithDifferentConfig(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,address) (runs: 5096, μ: 2776550, ~: 2764101) -OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithDifferentConfig(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,address) (runs: 5096, μ: 2598395, ~: 2573145) -OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithSameConfig(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 2495879, ~: 2483615) -OrderBookAddOrderMockTest:testAddOrderWithCalculationsInputsAndOutputsSucceeds(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 1295278, ~: 1291768) -OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaEmitsMetaV1(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 1305903, ~: 1301693) -OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 702817, ~: 702452) -OrderBookAddOrderMockTest:testAddOrderWithoutCalculationsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 225204, ~: 222658) -OrderBookAddOrderMockTest:testAddOrderWithoutInputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 180738, ~: 180602) -OrderBookAddOrderMockTest:testAddOrderWithoutOutputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 181522, ~: 180944) -OrderBookAddOrderTest:testAddOrderRealNoHandleIOReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 173437, ~: 171095) -OrderBookAddOrderTest:testAddOrderRealNoSourcesReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 176629, ~: 174639) -OrderBookAddOrderTest:testAddOrderRealOneStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 186730, ~: 184388) -OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 723949, ~: 717416) -OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 717244, ~: 710711) -OrderBookAddOrderTest:testAddOrderRealZeroStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 182024, ~: 179682) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 629944) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 612268) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 612253) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO3() (gas: 629982) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO4() (gas: 642423) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO5() (gas: 555978) -OrderBookClearTest:testClearSimple(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),uint256,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),uint256,address,address,uint256,uint256) (runs: 5096, μ: 569599, ~: 569270) +OrderBookAddOrderMockTest:testAddOrderSameAccountWithDifferentConfig(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,address) (runs: 5096, μ: 2778415, ~: 2765965) +OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithDifferentConfig(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,address) (runs: 5096, μ: 2600373, ~: 2575117) +OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithSameConfig(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 2498007, ~: 2485547) +OrderBookAddOrderMockTest:testAddOrderWithCalculationsInputsAndOutputsSucceeds(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 1296186, ~: 1292677) +OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaEmitsMetaV1(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 1306812, ~: 1302603) +OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 703198, ~: 702834) +OrderBookAddOrderMockTest:testAddOrderWithoutCalculationsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 225041, ~: 222495) +OrderBookAddOrderMockTest:testAddOrderWithoutInputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 180462, ~: 180326) +OrderBookAddOrderMockTest:testAddOrderWithoutOutputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 181258, ~: 180681) +OrderBookAddOrderTest:testAddOrderRealNoHandleIOReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 173061, ~: 170719) +OrderBookAddOrderTest:testAddOrderRealNoSourcesReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 176464, ~: 174474) +OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 725463, ~: 718929) +OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 718735, ~: 712201) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 637093) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 619410) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 619395) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO3() (gas: 637131) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO4() (gas: 650594) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO5() (gas: 560228) +OrderBookClearTest:testClearSimple(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),uint256,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),uint256,address,address,uint256,uint256) (runs: 5096, μ: 571829, ~: 571538) OrderBookClearTest:testFlashLoanToNonReceiver(uint256,bytes,bytes32,bytes) (runs: 5096, μ: 28752, ~: 28661) OrderBookDepositTest:testDepositEvent(address,uint256,uint256) (runs: 5096, μ: 38710, ~: 38710) -OrderBookDepositTest:testDepositFail(address,uint256,uint256) (runs: 5096, μ: 8937393460516740791, ~: 8937393460516740786) +OrderBookDepositTest:testDepositFail(address,uint256,uint256) (runs: 5096, μ: 8937393460516740788, ~: 8937393460516740786) OrderBookDepositTest:testDepositGas00() (gas: 8176) OrderBookDepositTest:testDepositGas01() (gas: 34642) -OrderBookDepositTest:testDepositMany((address,address,uint256,uint248)[]) (runs: 5096, μ: 5241523, ~: 4958934) +OrderBookDepositTest:testDepositMany((address,address,uint256,uint248)[]) (runs: 5096, μ: 5149740, ~: 4820767) OrderBookDepositTest:testDepositOverflow(address,uint256,uint256,uint256) (runs: 5096, μ: 46667, ~: 46667) -OrderBookDepositTest:testDepositReentrancy(address,uint256,uint256,address,uint256,uint256) (runs: 5096, μ: 596098, ~: 597676) +OrderBookDepositTest:testDepositReentrancy(address,uint256,uint256,address,uint256,uint256) (runs: 5096, μ: 596141, ~: 597676) OrderBookDepositTest:testDepositSimple(address,uint256,uint256) (runs: 5096, μ: 37712, ~: 37712) OrderBookDepositTest:testDepositZero(address,uint256) (runs: 5096, μ: 12639, ~: 12639) OrderBookDepositTest:testVaultBalanceNoDeposits(address,uint256) (runs: 5096, μ: 6135, ~: 6135) -OrderBookRemoveOrderMockTest:testRemoveOrderAddRemoveMulti(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 7247993, ~: 7174461) -OrderBookRemoveOrderMockTest:testRemoveOrderDifferent(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 5046655, ~: 5004628) -OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwners(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 4860524, ~: 4822798) -OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwnersDifferent(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 10434451, ~: 10321656) -OrderBookRemoveOrderMockTest:testRemoveOrderDoesNotExist(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 386436, ~: 384448) -OrderBookRemoveOrderMockTest:testRemoveOrderOnlyOwner(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 2606450, ~: 2590636) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO0() (gas: 282916) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO1() (gas: 495749) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO10(uint256) (runs: 5096, μ: 878430, ~: 836750) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO2() (gas: 495915) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO3() (gas: 690855) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO4() (gas: 708540) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO5() (gas: 708561) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO6() (gas: 708353) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO7(uint256) (runs: 5096, μ: 1022470, ~: 1022199) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO8(uint256) (runs: 5096, μ: 1217981, ~: 1217713) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO9(uint256) (runs: 5096, μ: 1020159, ~: 939210) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrders(uint256,uint256) (runs: 5096, μ: 483323, ~: 501086) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrdersMultipleOwners(uint256,uint256,uint256) (runs: 5096, μ: 532058, ~: 558239) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleAnyDeposit(uint256,uint256) (runs: 5096, μ: 290502, ~: 295936) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumInput(uint256,uint256) (runs: 5096, μ: 275711, ~: 278060) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumOutput(uint256) (runs: 5096, μ: 275942, ~: 275876) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderUnlimitedMax(uint256) (runs: 5096, μ: 269545, ~: 269275) +OrderBookRemoveOrderMockTest:testRemoveOrderAddRemoveMulti(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 7251567, ~: 7178043) +OrderBookRemoveOrderMockTest:testRemoveOrderDifferent(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 5048742, ~: 5006707) +OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwners(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 4862699, ~: 4824975) +OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwnersDifferent(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 10439221, ~: 10325141) +OrderBookRemoveOrderMockTest:testRemoveOrderDoesNotExist(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 386341, ~: 384353) +OrderBookRemoveOrderMockTest:testRemoveOrderOnlyOwner(address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),address) (runs: 5096, μ: 2607347, ~: 2591533) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO0() (gas: 286845) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO1() (gas: 499663) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO10(uint256) (runs: 5096, μ: 881707, ~: 837687) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO2() (gas: 499829) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO3() (gas: 694760) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO4() (gas: 712453) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO5() (gas: 712474) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO6() (gas: 712266) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO7(uint256) (runs: 5096, μ: 1029675, ~: 1029405) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO8(uint256) (runs: 5096, μ: 1225189, ~: 1224920) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO9(uint256) (runs: 5096, μ: 1021085, ~: 938201) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrders(uint256,uint256) (runs: 5096, μ: 485689, ~: 503562) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrdersMultipleOwners(uint256,uint256,uint256) (runs: 5096, μ: 534273, ~: 560716) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleAnyDeposit(uint256,uint256) (runs: 5096, μ: 292843, ~: 298422) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumInput(uint256,uint256) (runs: 5096, μ: 278253, ~: 280546) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumOutput(uint256) (runs: 5096, μ: 278432, ~: 278362) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderUnlimitedMax(uint256) (runs: 5096, μ: 272028, ~: 271757) OrderBookTakeOrderMaximumInputTest:testTakeOrderNoopZeroMaxTakerInput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),(address,uint256[],bytes)) (runs: 5096, μ: 185762, ~: 184115) -OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderOne((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,uint256[],bytes)) (runs: 5096, μ: 429838, ~: 428425) -OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderTwo((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256,(address,uint256[],bytes),(address,uint256[],bytes)) (runs: 5096, μ: 847255, ~: 844850) +OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderOne((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,uint256[],bytes)) (runs: 5096, μ: 429868, ~: 428457) +OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderTwo((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256,(address,uint256[],bytes),(address,uint256[],bytes)) (runs: 5096, μ: 847318, ~: 844873) OrderBookTakeOrderNoopTest:testTakeOrderNoopZeroOrders() (gas: 12358) -OrderBookTakeOrderPrecisionTest:testTakeOrderPrecisionKnownBad01() (gas: 2629544) -OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchInputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 619265, ~: 615316) -OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchOutputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 619982, ~: 616076) -OrderBookTakeOrderTokenMismatchTest:testTokenMismatchInputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 618233, ~: 615901) -OrderBookTakeOrderTokenMismatchTest:testTokenMismatchOutputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 619563, ~: 617215) +OrderBookTakeOrderPrecisionTest:testTakeOrderPrecisionKnownBad01() (gas: 2632077) +OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchInputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 619193, ~: 614892) +OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchOutputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 620134, ~: 616108) +OrderBookTakeOrderTokenMismatchTest:testTokenMismatchInputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 618300, ~: 615952) +OrderBookTakeOrderTokenMismatchTest:testTokenMismatchOutputs((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 619596, ~: 617164) OrderBookV3FlashLenderFeeTest:testFlashFee(address,uint256) (runs: 5096, μ: 3702, ~: 3702) OrderBookV3FlashLenderMaxFlashLoanTest:testFlashMaxLoan(uint256) (runs: 5096, μ: 7638, ~: 7638) OrderBookV3FlashLenderMockSuccessTest:testFlashLoanToReceiver(uint256,bytes) (runs: 5096, μ: 14721, ~: 14674) -OrderBookV3FlashLenderReentrant:testReenterAddOrder(uint256,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 18621561, ~: 18497524) -OrderBookV3FlashLenderReentrant:testReenterCheckOrderExists(bytes32,uint256) (runs: 5096, μ: 552771, ~: 553611) -OrderBookV3FlashLenderReentrant:testReenterClear(uint256,address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 37709735, ~: 37616965) -OrderBookV3FlashLenderReentrant:testReenterDeposit(uint256,uint256,uint256) (runs: 5096, μ: 628333, ~: 630052) -OrderBookV3FlashLenderReentrant:testReenterReadVaultBalances(uint256,uint256) (runs: 5096, μ: 597383, ~: 598938) -OrderBookV3FlashLenderReentrant:testReenterRemoveOrder(uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[])) (runs: 5096, μ: 17734084, ~: 17708028) -OrderBookV3FlashLenderReentrant:testReenterTakeOrder(uint256,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 19224537, ~: 19063930) -OrderBookV3FlashLenderReentrant:testReenterWithdraw(uint256,uint256,uint256) (runs: 5096, μ: 604691, ~: 606629) +OrderBookV3FlashLenderReentrant:testReenterAddOrder(uint256,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 18620167, ~: 18493610) +OrderBookV3FlashLenderReentrant:testReenterCheckOrderExists(bytes32,uint256) (runs: 5096, μ: 552732, ~: 553611) +OrderBookV3FlashLenderReentrant:testReenterClear(uint256,address,address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes),((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 37691976, ~: 37610240) +OrderBookV3FlashLenderReentrant:testReenterDeposit(uint256,uint256,uint256) (runs: 5096, μ: 628422, ~: 630052) +OrderBookV3FlashLenderReentrant:testReenterReadVaultBalances(uint256,uint256) (runs: 5096, μ: 597379, ~: 598938) +OrderBookV3FlashLenderReentrant:testReenterRemoveOrder(uint256,(address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[])) (runs: 5096, μ: 17727199, ~: 17723209) +OrderBookV3FlashLenderReentrant:testReenterTakeOrder(uint256,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 19227598, ~: 19079033) +OrderBookV3FlashLenderReentrant:testReenterWithdraw(uint256,uint256,uint256) (runs: 5096, μ: 604742, ~: 606629) OrderBookV3FlashLenderTransferTest:testFlashLoanTransferFail(uint256,uint256,bool) (runs: 5096, μ: 1344450, ~: 1344917) -OrderBookV3FlashLenderTransferTest:testFlashLoanTransferSuccess(uint256,bool) (runs: 5096, μ: 1288441, ~: 1297392) +OrderBookV3FlashLenderTransferTest:testFlashLoanTransferSuccess(uint256,bool) (runs: 5096, μ: 1288429, ~: 1289421) OrderBookWithdrawTest:testWithdrawEmptyVault(address,address,uint256,uint256) (runs: 5096, μ: 15251, ~: 15251) -OrderBookWithdrawTest:testWithdrawFailure(address,uint256,uint256,uint256) (runs: 5096, μ: 8937393460516716964, ~: 8937393460516698169) -OrderBookWithdrawTest:testWithdrawFullVault(address,uint256,uint256,uint256) (runs: 5096, μ: 39264, ~: 39262) +OrderBookWithdrawTest:testWithdrawFailure(address,uint256,uint256,uint256) (runs: 5096, μ: 8937393460516716949, ~: 8937393460516698157) +OrderBookWithdrawTest:testWithdrawFullVault(address,uint256,uint256,uint256) (runs: 5096, μ: 39263, ~: 39262) OrderBookWithdrawTest:testWithdrawMany((bool,address,address,uint256,uint248)[]) (runs: 5096, μ: 3169906, ~: 3156574) OrderBookWithdrawTest:testWithdrawPartialVault(address,uint256,uint256,uint256) (runs: 5096, μ: 49439, ~: 49439) OrderBookWithdrawTest:testWithdrawZero(address,address,uint256) (runs: 5096, μ: 12809, ~: 12809) -RouteProcessorOrderBookV3ArbOrderTakerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332180, ~: 330641) -RouteProcessorOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266353, ~: 265402) \ No newline at end of file +RouteProcessorOrderBookV3ArbOrderTakerTest:testRouteProcessorMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332202, ~: 330538) +RouteProcessorOrderBookV3ArbOrderTakerTest:testRouteProcessorTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266376, ~: 265424) \ No newline at end of file diff --git a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol index b6abc9cc0..18860b0ca 100644 --- a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol +++ b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol @@ -2,7 +2,10 @@ pragma solidity =0.8.19; import {Script, console2} from "forge-std/Script.sol"; -import {GenericPoolOrderBookV3FlashBorrower, DeployerDiscoverableMetaV3ConstructionConfig} from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; +import { + GenericPoolOrderBookV3FlashBorrower, + DeployerDiscoverableMetaV3ConstructionConfig +} from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; /// @title DeployGenericPoolOrderBookV3FlashBorrower /// @notice A script that deploys a `GenericPoolOrderBookV3FlashBorrower`. This diff --git a/src/abstract/OrderBookV3FlashBorrower.sol b/src/abstract/OrderBookV3FlashBorrower.sol index 487529ad6..dfb3f08d2 100644 --- a/src/abstract/OrderBookV3FlashBorrower.sol +++ b/src/abstract/OrderBookV3FlashBorrower.sol @@ -19,7 +19,9 @@ import {ON_FLASH_LOAN_CALLBACK_SUCCESS} from "../interface/ierc3156/IERC3156Flas import {IOrderBookV3, TakeOrdersConfigV2, NoOrders} from "../interface/unstable/IOrderBookV3.sol"; import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "rain.factory/src/interface/ICloneableV2.sol"; import { - IInterpreterV2, SourceIndexV2, DEFAULT_STATE_NAMESPACE + IInterpreterV2, + SourceIndexV2, + DEFAULT_STATE_NAMESPACE } from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import {IERC3156FlashBorrower} from "../interface/ierc3156/IERC3156FlashBorrower.sol"; import {IInterpreterStoreV1} from "rain.interpreter/src/interface/IInterpreterStoreV1.sol"; diff --git a/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol b/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol index 9506f7d87..ea62e9cc3 100644 --- a/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol +++ b/src/concrete/GenericPoolOrderBookV3FlashBorrower.sol @@ -9,7 +9,7 @@ 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(0xc527f81e4dac946943b3ffe7a99d82535b44a79eb92692159566eea43659365e); +bytes32 constant CALLER_META_HASH = bytes32(0x5307fcdf3fa283e1e7d5d58baaa516cdefb10aba9eb23211d9cfb11afd6e4b4c); /// @title GenericPoolOrderBookV3FlashBorrower /// Implements the OrderBookV3FlashBorrower interface for a external liquidity diff --git a/src/concrete/OrderBook.sol b/src/concrete/OrderBook.sol index 89faed4fb..7bf43f22c 100644 --- a/src/concrete/OrderBook.sol +++ b/src/concrete/OrderBook.sol @@ -19,7 +19,9 @@ import { LibMeta } from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol"; -import {SourceIndexV2, StateNamespace, IInterpreterV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; +import { + SourceIndexV2, StateNamespace, IInterpreterV2 +} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol"; import { IOrderBookV3, NoOrders, @@ -297,10 +299,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash (IInterpreterV2 interpreter, IInterpreterStoreV1 store, address expression, bytes memory io) = config .evaluableConfig .deployer - .deployExpression2( - config.evaluableConfig.bytecode, - config.evaluableConfig.constants - ); + .deployExpression2(config.evaluableConfig.bytecode, config.evaluableConfig.constants); { uint256 calculateInputs; uint256 calculateOutputs; @@ -742,7 +741,13 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash (uint256[] memory calculateOrderStack, uint256[] memory calculateOrderKVs) = order .evaluable .interpreter - .eval2(order.evaluable.store, LibNamespace.qualifyNamespace(namespace, address(this)), _calculateOrderDispatch(order.evaluable.expression), context, new uint256[](0)); + .eval2( + order.evaluable.store, + LibNamespace.qualifyNamespace(namespace, address(this)), + _calculateOrderDispatch(order.evaluable.expression), + context, + new uint256[](0) + ); Output18Amount orderOutputMax18 = Output18Amount.wrap(calculateOrderStack[1]); uint256 orderIORatio = calculateOrderStack[0]; diff --git a/src/interface/unstable/IOrderBookV3.sol b/src/interface/unstable/IOrderBookV3.sol index b4676f3c7..5516eb773 100644 --- a/src/interface/unstable/IOrderBookV3.sol +++ b/src/interface/unstable/IOrderBookV3.sol @@ -2,10 +2,12 @@ pragma solidity ^0.8.18; import "../ierc3156/IERC3156FlashLender.sol"; +import {IExpressionDeployerV3, EvaluableV2} from "lib/rain.interpreter/src/lib/caller/LibEvaluable.sol"; import { - IExpressionDeployerV3, EvaluableV2 -} from "lib/rain.interpreter/src/lib/caller/LibEvaluable.sol"; -import {EvaluableConfigV3, IInterpreterCallerV2, SignedContextV1} from "lib/rain.interpreter/src/interface/IInterpreterCallerV2.sol"; + EvaluableConfigV3, + IInterpreterCallerV2, + SignedContextV1 +} from "lib/rain.interpreter/src/interface/IInterpreterCallerV2.sol"; /// Import unmodified structures from older versions of `IOrderBook`. import {IO, ClearConfig, ClearStateChange} from "../deprecated/IOrderBookV2.sol"; diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol index 1773bea2e..2c3b9b7de 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol @@ -27,7 +27,9 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { ); } - function testGenericPoolTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + function testGenericPoolTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) + public + { TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); GenericPoolOrderBookV3ArbOrderTaker(iArb).arb( diff --git a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol index b022b7721..4b088e914 100644 --- a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol @@ -27,7 +27,11 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { ); } - function testTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + function testGenericPoolOrderBookV3FlashBorrowerTakeOrdersSender( + OrderV2 memory order, + uint256 inputIOIndex, + uint256 outputIOIndex + ) public { TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); GenericPoolOrderBookV3FlashBorrower(iArb).arb( @@ -37,7 +41,7 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { ); } - function testMinimumOutput( + function testGenericPoolOrderBookV3FlashBorrowerMinimumOutput( OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex, diff --git a/test/concrete/OrderBook.clear.handleIO.revert.t.sol b/test/concrete/OrderBook.clear.handleIO.revert.t.sol index ba14f5de7..733c4e7a1 100644 --- a/test/concrete/OrderBook.clear.handleIO.revert.t.sol +++ b/test/concrete/OrderBook.clear.handleIO.revert.t.sol @@ -2,9 +2,7 @@ pragma solidity =0.8.19; import {Vm} from "forge-std/Vm.sol"; -import { - OrderBookExternalRealTest -} from "test/util/abstract/OrderBookExternalRealTest.sol"; +import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRealTest.sol"; import {ClearConfig, OrderV2, TakeOrderConfigV2, IO, OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; diff --git a/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol b/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol index 532ac4b42..2562d1cf4 100644 --- a/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol +++ b/test/concrete/OrderBook.takeOrder.handleIO.revert.t.sol @@ -2,10 +2,15 @@ pragma solidity =0.8.19; import {Vm} from "forge-std/Vm.sol"; +import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRealTest.sol"; import { - OrderBookExternalRealTest -} from "test/util/abstract/OrderBookExternalRealTest.sol"; -import {ClearConfig, OrderV2, TakeOrderConfigV2, IO, OrderConfigV2, TakeOrdersConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; + ClearConfig, + OrderV2, + TakeOrderConfigV2, + IO, + OrderConfigV2, + TakeOrdersConfigV2 +} from "src/interface/unstable/IOrderBookV3.sol"; import {EnsureFailed} from "rain.interpreter/src/lib/op/logic/LibOpEnsureNP.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; diff --git a/test/concrete/OrderBook.takeOrder.precision.t.sol b/test/concrete/OrderBook.takeOrder.precision.t.sol index f01aaee6b..27273344c 100644 --- a/test/concrete/OrderBook.takeOrder.precision.t.sol +++ b/test/concrete/OrderBook.takeOrder.precision.t.sol @@ -2,10 +2,10 @@ pragma solidity =0.8.19; import {Vm} from "forge-std/Test.sol"; +import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRealTest.sol"; import { - OrderBookExternalRealTest -} from "test/util/abstract/OrderBookExternalRealTest.sol"; -import {OrderV2, TakeOrdersConfigV2, TakeOrderConfigV2, IO, OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; + OrderV2, TakeOrdersConfigV2, TakeOrderConfigV2, IO, OrderConfigV2 +} from "src/interface/unstable/IOrderBookV3.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol"; diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index d98dc528b..a5f649f53 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -30,7 +30,9 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { ); } - function testRouteProcessorTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + function testRouteProcessorTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) + public + { TakeOrderConfigV2[] memory orders = buildTakeOrderConfig(order, inputIOIndex, outputIOIndex); RouteProcessorOrderBookV3ArbOrderTaker(iArb).arb( diff --git a/test/util/abstract/IOrderBookV3Stub.sol b/test/util/abstract/IOrderBookV3Stub.sol index f8e63659d..963543d73 100644 --- a/test/util/abstract/IOrderBookV3Stub.sol +++ b/test/util/abstract/IOrderBookV3Stub.sol @@ -20,10 +20,13 @@ abstract contract IOrderBookV3Stub is IOrderBookV3 { } /// @inheritdoc IOrderBookV3 - function clear(OrderV2 memory, OrderV2 memory, ClearConfig calldata, SignedContextV1[] memory, SignedContextV1[] memory) - external - pure - { + function clear( + OrderV2 memory, + OrderV2 memory, + ClearConfig calldata, + SignedContextV1[] memory, + SignedContextV1[] memory + ) external pure { revert("clear"); } diff --git a/test/util/abstract/OrderBookExternalMockTest.sol b/test/util/abstract/OrderBookExternalMockTest.sol index 016182600..85f11f5c6 100644 --- a/test/util/abstract/OrderBookExternalMockTest.sol +++ b/test/util/abstract/OrderBookExternalMockTest.sol @@ -17,7 +17,8 @@ import {IOrderBookV3, OrderConfigV2, OrderV2} from "src/interface/unstable/IOrde import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {LibOrder} from "src/lib/LibOrder.sol"; import {OrderBook} from "src/concrete/OrderBook.sol"; -import {DeployerDiscoverableMetaV3ConstructionConfig} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; +import {DeployerDiscoverableMetaV3ConstructionConfig} from + "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol"; /// @title OrderBookExternalTest /// Abstract contract that performs common setup needed for testing an orderbook diff --git a/test/util/abstract/OrderBookExternalRealTest.sol b/test/util/abstract/OrderBookExternalRealTest.sol index e451b7edb..deb2fed34 100644 --- a/test/util/abstract/OrderBookExternalRealTest.sol +++ b/test/util/abstract/OrderBookExternalRealTest.sol @@ -4,7 +4,10 @@ pragma solidity =0.8.19; import {Test, Vm, console2} from "forge-std/Test.sol"; import {RainterpreterNPE2} from "rain.interpreter/src/concrete/RainterpreterNPE2.sol"; import {RainterpreterStoreNPE2} from "rain.interpreter/src/concrete/RainterpreterStoreNPE2.sol"; -import {RainterpreterExpressionDeployerNPE2, RainterpreterExpressionDeployerNPE2ConstructionConfig} from "rain.interpreter/src/concrete/RainterpreterExpressionDeployerNPE2.sol"; +import { + RainterpreterExpressionDeployerNPE2, + RainterpreterExpressionDeployerNPE2ConstructionConfig +} 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"; From ad1437d0c0824a58419605ecd1157afb563f8c3e Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 22 Nov 2023 15:33:54 +0400 Subject: [PATCH 08/14] update deployer --- script/DeployOrderBook.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/DeployOrderBook.sol b/script/DeployOrderBook.sol index 80f3b5407..36ff5a195 100644 --- a/script/DeployOrderBook.sol +++ b/script/DeployOrderBook.sol @@ -8,8 +8,8 @@ contract DeployOrderBook is Script { function run(bytes memory meta) external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); // @todo pull this from subgraph. - // hardcoded from CI https://github.com/rainprotocol/rain.interpreter/actions/runs/6101787278/job/16558857505 - address i9rDeployer = 0xAb0A13cC2654CbaDABabC9952a090928F4ff569A; + // hardcoded from CI https://github.com/rainprotocol/rain.interpreter/actions/runs/6953107467/job/18917750124 + address i9rDeployer = 0xa5aDC3F2A7A8Cf7b5172D76d8b26c3d49272297B; console2.log("DeployOrderBook meta hash:"); console2.logBytes32(keccak256(meta)); From 7982d854c3d5d3727783ac00f7714e3bae1d3a1d Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 24 Nov 2023 14:56:49 +0400 Subject: [PATCH 09/14] tests for bad init --- src/abstract/OrderBookV3ArbOrderTaker.sol | 1 - ...ricPoolOrderBookV3ArbOrderTaker.init.t.sol | 37 ++++++++++++ ...cPoolOrderBookV3ArbOrderTaker.sender.t.sol | 44 ++++++--------- ...ocessorOrderBookV3ArbOrderTaker.init.t.sol | 37 ++++++++++++ ...essorOrderBookV3ArbOrderTaker.sender.t.sol | 56 +++++++++---------- test/util/abstract/ArbTest.sol | 7 ++- ...enericPoolOrderBookV3ArbOrderTakerTest.sol | 37 ++++++++++++ ...eProcessorOrderBookV3ArbOrderTakerTest.sol | 39 +++++++++++++ 8 files changed, 199 insertions(+), 59 deletions(-) create mode 100644 test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol create mode 100644 test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol create mode 100644 test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol create mode 100644 test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol diff --git a/src/abstract/OrderBookV3ArbOrderTaker.sol b/src/abstract/OrderBookV3ArbOrderTaker.sol index 6ce61a832..a8de82d20 100644 --- a/src/abstract/OrderBookV3ArbOrderTaker.sol +++ b/src/abstract/OrderBookV3ArbOrderTaker.sol @@ -70,7 +70,6 @@ abstract contract OrderBookV3ArbOrderTaker is constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config) DeployerDiscoverableMetaV3(metaHash, config) { - console2.log("obv3aot constructor"); _disableInitializers(); } diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol new file mode 100644 index 000000000..d7c3286b6 --- /dev/null +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: CAL +pragma solidity =0.8.19; + +import {GenericPoolOrderBookV3ArbOrderTakerTest} from "test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol"; +import {Clones} from "openzeppelin-contracts/contracts/proxy/Clones.sol"; +import {ICloneableV2} from "rain.factory/src/interface/ICloneableV2.sol"; +import {OrderBookV3ArbOrderTakerConfigV1} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; +import {EvaluableConfigV3, IExpressionDeployerV3} from "src/interface/unstable/IOrderBookV3.sol"; +import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; +import {NonZeroBeforeArbInputs} from "src/abstract/OrderBookV3ArbOrderTaker.sol"; + +contract GenericPoolOrderBookV3ArbOrderTakerInitTest is GenericPoolOrderBookV3ArbOrderTakerTest { + function testGenericPoolOrderBookV3ArbOrderTakerInitInvalidInputs() public { + address testArb = Clones.clone(iImplementation); + vm.mockCall( + iDeployer, + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(address(0), address(0), address(0), "0100") + ); + vm.expectRevert(abi.encodeWithSelector(NonZeroBeforeArbInputs.selector, 48)); + ICloneableV2(testArb).initialize( + abi.encode( + OrderBookV3ArbOrderTakerConfigV1( + address(0), + EvaluableConfigV3( + IExpressionDeployerV3(iDeployer), + // Need a nonzero source count to enter the code path + // that deploys the "before arb" expression. + hex"01", + new uint256[](0) + ), + "" + ) + ) + ); + } +} diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol index 2c3b9b7de..5a3127c55 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol @@ -1,32 +1,24 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol"; -import "openzeppelin-contracts/contracts/proxy/Clones.sol"; - -import "test/util/lib/LibTestConstants.sol"; -import "test/util/lib/LibGenericPoolOrderBookV3ArbOrderTakerConstants.sol"; - -import "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; -import "src/interface/unstable/IOrderBookV3.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); - return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3ArbOrderTaker(config))); - } - - constructor() ArbTest(buildArbTestConstructorConfig()) { - ICloneableV2(iArb).initialize( - abi.encode( - OrderBookV3ArbOrderTakerConfigV1( - address(iOrderBook), EvaluableConfigV3(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" - ) - ) - ); - } - +import {GenericPoolOrderBookV3ArbOrderTakerTest} from "test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol"; + +import { + GenericPoolOrderBookV3ArbOrderTaker, + DeployerDiscoverableMetaV3ConstructionConfig, + OrderBookV3ArbOrderTakerConfigV1, + MinimumOutput +} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; +import {ICloneableV2} from "rain.factory/src/interface/ICloneableV2.sol"; +import { + OrderV2, + EvaluableConfigV3, + IExpressionDeployerV3, + TakeOrderConfigV2, + TakeOrdersConfigV2 +} from "src/interface/unstable/IOrderBookV3.sol"; + +contract GenericPoolOrderBookV3ArbOrderTakerSenderTest is GenericPoolOrderBookV3ArbOrderTakerTest { function testGenericPoolTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol new file mode 100644 index 000000000..b38c06a50 --- /dev/null +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: CAL +pragma solidity =0.8.19; + +import {RouteProcessorOrderBookV3ArbOrderTakerTest} from + "test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol"; +import {Clones} from "openzeppelin-contracts/contracts/proxy/Clones.sol"; +import {ICloneableV2} from "rain.factory/src/interface/ICloneableV2.sol"; +import {OrderBookV3ArbOrderTakerConfigV1} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; +import {EvaluableConfigV3, IExpressionDeployerV3} from "src/interface/unstable/IOrderBookV3.sol"; +import {NonZeroBeforeArbInputs} from "src/abstract/OrderBookV3ArbOrderTaker.sol"; + +contract RouteProcessorOrderBookV3ArbOrderTakerInitTest is RouteProcessorOrderBookV3ArbOrderTakerTest { + function testRouteProcessorOrderBookV3ArbOrderTakerInitInvalidInputs() public { + address testArb = Clones.clone(iImplementation); + vm.mockCall( + iDeployer, + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(address(0), address(0), address(0), "0100") + ); + vm.expectRevert(abi.encodeWithSelector(NonZeroBeforeArbInputs.selector, 48)); + ICloneableV2(testArb).initialize( + abi.encode( + OrderBookV3ArbOrderTakerConfigV1( + address(0), + EvaluableConfigV3( + IExpressionDeployerV3(iDeployer), + // Need a nonzero source count to enter the code path + // that deploys the "before arb" expression. + hex"01", + new uint256[](0) + ), + abi.encode(iRefundoor) + ) + ) + ); + } +} diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index a5f649f53..6496f1836 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -1,35 +1,33 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "test/util/lib/LibTestConstants.sol"; -import "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol"; - -import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol"; - -import "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; -import "src/interface/unstable/IOrderBookV3.sol"; - -import "rain.factory/src/interface/ICloneableV2.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); - return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config))); - } - - constructor() ArbTest(buildArbTestConstructorConfig()) { - ICloneableV2(iArb).initialize( - abi.encode( - OrderBookV3ArbOrderTakerConfigV1( - address(iOrderBook), - EvaluableConfigV3(IExpressionDeployerV3(address(0)), "", new uint256[](0)), - abi.encode(iRefundoor) - ) - ) - ); - } - +import {RouteProcessorOrderBookV3ArbOrderTakerTest} from + "test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol"; + +// import "test/util/lib/LibTestConstants.sol"; +// import "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol"; + +// import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol"; + +// import "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; +// import "src/interface/unstable/IOrderBookV3.sol"; + +// import "rain.factory/src/interface/ICloneableV2.sol"; +import { + OrderV2, + EvaluableConfigV3, + IExpressionDeployerV3, + TakeOrderConfigV2, + TakeOrdersConfigV2 +} from "src/interface/unstable/IOrderBookV3.sol"; +import { + RouteProcessorOrderBookV3ArbOrderTaker, + DeployerDiscoverableMetaV3ConstructionConfig, + OrderBookV3ArbOrderTakerConfigV1, + MinimumOutput +} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; + +contract RouteProcessorOrderBookV3ArbOrderTakerSenderTest is RouteProcessorOrderBookV3ArbOrderTakerTest { function testRouteProcessorTakeOrdersSender(OrderV2 memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index 9a20844ee..765d7c807 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -2,7 +2,7 @@ pragma solidity =0.8.19; import {Test, console2} from "forge-std/Test.sol"; -import "openzeppelin-contracts/contracts/proxy/Clones.sol"; +import {Clones} from "openzeppelin-contracts/contracts/proxy/Clones.sol"; import "test/util/lib/LibTestConstants.sol"; import {DeployerDiscoverableMetaV3ConstructionConfig} from @@ -54,10 +54,11 @@ abstract contract ArbTest is Test { vm.mockCall( deployer, abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(address(0), address(0), address(0), "00020000") + // 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); - console2.log("RouteProcessorOrderBookV3ArbOrderTakerTest meta hash:"); + console2.log("ArbTest meta hash:"); console2.logBytes32(keccak256(meta)); config = DeployerDiscoverableMetaV3ConstructionConfig(deployer, meta); } diff --git a/test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol b/test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol new file mode 100644 index 000000000..1bacedc89 --- /dev/null +++ b/test/util/abstract/GenericPoolOrderBookV3ArbOrderTakerTest.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: CAL +pragma solidity =0.8.19; + +import {ArbTest, ArbTestConstructorConfig} from "./ArbTest.sol"; +import { + GenericPoolOrderBookV3ArbOrderTaker, + DeployerDiscoverableMetaV3ConstructionConfig, + OrderBookV3ArbOrderTakerConfigV1 +} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; +import { + OrderV2, + EvaluableConfigV3, + IExpressionDeployerV3, + TakeOrderConfigV2, + 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); + return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3ArbOrderTaker(config))); + } + + constructor() ArbTest(buildArbTestConstructorConfig()) { + ICloneableV2(iArb).initialize( + abi.encode( + OrderBookV3ArbOrderTakerConfigV1( + address(iOrderBook), EvaluableConfigV3(IExpressionDeployerV3(address(0)), "", new uint256[](0)), "" + ) + ) + ); + } +} diff --git a/test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol b/test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol new file mode 100644 index 000000000..3eaacf4ec --- /dev/null +++ b/test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: CAL +pragma solidity =0.8.19; + +import {ArbTest, ArbTestConstructorConfig} from "./ArbTest.sol"; +import { + RouteProcessorOrderBookV3ArbOrderTaker, + DeployerDiscoverableMetaV3ConstructionConfig, + OrderBookV3ArbOrderTakerConfigV1 +} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; +import { + OrderV2, + EvaluableConfigV3, + IExpressionDeployerV3, + TakeOrderConfigV2, + 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); + return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config))); + } + + constructor() ArbTest(buildArbTestConstructorConfig()) { + ICloneableV2(iArb).initialize( + abi.encode( + OrderBookV3ArbOrderTakerConfigV1( + address(iOrderBook), + EvaluableConfigV3(IExpressionDeployerV3(address(0)), "", new uint256[](0)), + abi.encode(iRefundoor) + ) + ) + ); + } +} From f2d9cf5c25931d8390a5f22a29069dfa53efd28b Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 24 Nov 2023 15:11:00 +0400 Subject: [PATCH 10/14] fuzz --- .gas-snapshot | 10 ++++++---- .../GenericPoolOrderBookV3ArbOrderTaker.init.t.sol | 9 ++++++--- .../RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol | 9 ++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index b20a5f7e6..e3a83024c 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,5 +1,6 @@ -GenericPoolOrderBookV3ArbOrderTakerTest:testGenericPoolMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332052, ~: 330383) -GenericPoolOrderBookV3ArbOrderTakerTest:testGenericPoolTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266210, ~: 265260) +GenericPoolOrderBookV3ArbOrderTakerInitTest:testGenericPoolOrderBookV3ArbOrderTakerInitInvalidInputs(bytes) (runs: 5096, μ: 112556, ~: 112571) +GenericPoolOrderBookV3ArbOrderTakerSenderTest:testGenericPoolMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332057, ~: 330383) +GenericPoolOrderBookV3ArbOrderTakerSenderTest:testGenericPoolTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266214, ~: 265260) GenericPoolOrderBookV3FlashBorrowerTest:testGenericPoolOrderBookV3FlashBorrowerMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 609059, ~: 605057) GenericPoolOrderBookV3FlashBorrowerTest:testGenericPoolOrderBookV3FlashBorrowerTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 522448, ~: 519675) LibOrderTest:testHashEqual((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[])) (runs: 5096, μ: 196882, ~: 195948) @@ -86,5 +87,6 @@ OrderBookWithdrawTest:testWithdrawFullVault(address,uint256,uint256,uint256) (ru OrderBookWithdrawTest:testWithdrawMany((bool,address,address,uint256,uint248)[]) (runs: 5096, μ: 3169906, ~: 3156574) OrderBookWithdrawTest:testWithdrawPartialVault(address,uint256,uint256,uint256) (runs: 5096, μ: 49439, ~: 49439) OrderBookWithdrawTest:testWithdrawZero(address,address,uint256) (runs: 5096, μ: 12809, ~: 12809) -RouteProcessorOrderBookV3ArbOrderTakerTest:testRouteProcessorMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332202, ~: 330538) -RouteProcessorOrderBookV3ArbOrderTakerTest:testRouteProcessorTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266376, ~: 265424) \ No newline at end of file +RouteProcessorOrderBookV3ArbOrderTakerInitTest:testRouteProcessorOrderBookV3ArbOrderTakerInitInvalidInputs(bytes) (runs: 5096, μ: 135462, ~: 135478) +RouteProcessorOrderBookV3ArbOrderTakerSenderTest:testRouteProcessorMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 332199, ~: 330538) +RouteProcessorOrderBookV3ArbOrderTakerSenderTest:testRouteProcessorTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 266375, ~: 265424) \ No newline at end of file diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol index d7c3286b6..75de5d4b1 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.init.t.sol @@ -10,14 +10,17 @@ import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; import {NonZeroBeforeArbInputs} from "src/abstract/OrderBookV3ArbOrderTaker.sol"; contract GenericPoolOrderBookV3ArbOrderTakerInitTest is GenericPoolOrderBookV3ArbOrderTakerTest { - function testGenericPoolOrderBookV3ArbOrderTakerInitInvalidInputs() public { + function testGenericPoolOrderBookV3ArbOrderTakerInitInvalidInputs(bytes memory io) public { + vm.assume(io.length >= 2); + vm.assume(io.length % 2 == 0); + vm.assume(io[0] != 0); address testArb = Clones.clone(iImplementation); vm.mockCall( iDeployer, abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(address(0), address(0), address(0), "0100") + abi.encode(address(0), address(0), address(0), io) ); - vm.expectRevert(abi.encodeWithSelector(NonZeroBeforeArbInputs.selector, 48)); + vm.expectRevert(abi.encodeWithSelector(NonZeroBeforeArbInputs.selector, uint256(uint8(io[0])))); ICloneableV2(testArb).initialize( abi.encode( OrderBookV3ArbOrderTakerConfigV1( diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol index b38c06a50..125d8345e 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.init.t.sol @@ -10,14 +10,17 @@ import {EvaluableConfigV3, IExpressionDeployerV3} from "src/interface/unstable/I import {NonZeroBeforeArbInputs} from "src/abstract/OrderBookV3ArbOrderTaker.sol"; contract RouteProcessorOrderBookV3ArbOrderTakerInitTest is RouteProcessorOrderBookV3ArbOrderTakerTest { - function testRouteProcessorOrderBookV3ArbOrderTakerInitInvalidInputs() public { + function testRouteProcessorOrderBookV3ArbOrderTakerInitInvalidInputs(bytes memory io) public { + vm.assume(io.length >= 2); + vm.assume(io.length % 2 == 0); + vm.assume(io[0] != 0); address testArb = Clones.clone(iImplementation); vm.mockCall( iDeployer, abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), - abi.encode(address(0), address(0), address(0), "0100") + abi.encode(address(0), address(0), address(0), io) ); - vm.expectRevert(abi.encodeWithSelector(NonZeroBeforeArbInputs.selector, 48)); + vm.expectRevert(abi.encodeWithSelector(NonZeroBeforeArbInputs.selector, uint256(uint8(io[0])))); ICloneableV2(testArb).initialize( abi.encode( OrderBookV3ArbOrderTakerConfigV1( From a40dbcf443feb090780db5a854b0c59315caf436 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 24 Nov 2023 15:16:27 +0400 Subject: [PATCH 11/14] lint --- ...RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index 6496f1836..4d780163d 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -3,16 +3,6 @@ pragma solidity =0.8.19; import {RouteProcessorOrderBookV3ArbOrderTakerTest} from "test/util/abstract/RouteProcessorOrderBookV3ArbOrderTakerTest.sol"; - -// import "test/util/lib/LibTestConstants.sol"; -// import "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol"; - -// import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol"; - -// import "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; -// import "src/interface/unstable/IOrderBookV3.sol"; - -// import "rain.factory/src/interface/ICloneableV2.sol"; import { OrderV2, EvaluableConfigV3, From 6db18b135bf177745e0ad58ef8c1250f6d7c231e Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 24 Nov 2023 15:40:00 +0400 Subject: [PATCH 12/14] tests for io on add order --- .gas-snapshot | 13 +++- test/concrete/OrderBook.addOrder.t.sol | 103 ++++++++++++++++++++----- 2 files changed, 92 insertions(+), 24 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index e3a83024c..f76548d27 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -14,10 +14,17 @@ OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaReverts(address,((address, OrderBookAddOrderMockTest:testAddOrderWithoutCalculationsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 225041, ~: 222495) OrderBookAddOrderMockTest:testAddOrderWithoutInputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 180462, ~: 180326) OrderBookAddOrderMockTest:testAddOrderWithoutOutputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 181258, ~: 180681) -OrderBookAddOrderTest:testAddOrderRealNoHandleIOReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 173061, ~: 170719) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts1(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 243931, ~: 241589) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts2(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 245629, ~: 243287) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsRevertsPreference(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 245191, ~: 242849) +OrderBookAddOrderTest:testAddOrderRealHandleIOInputsReverts1(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 261570, ~: 259228) +OrderBookAddOrderTest:testAddOrderRealHandleIOInputsReverts2(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 263259, ~: 260917) +OrderBookAddOrderTest:testAddOrderRealNoHandleIOReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 173094, ~: 170752) OrderBookAddOrderTest:testAddOrderRealNoSourcesReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 176464, ~: 174474) -OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 725463, ~: 718929) -OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 718735, ~: 712201) +OrderBookAddOrderTest:testAddOrderRealOneStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 248580, ~: 246238) +OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 725429, ~: 718895) +OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 718723, ~: 712189) +OrderBookAddOrderTest:testAddOrderRealZeroStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 242660, ~: 240318) OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 637093) OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 619410) OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 619395) diff --git a/test/concrete/OrderBook.addOrder.t.sol b/test/concrete/OrderBook.addOrder.t.sol index 2185d265b..af1f22032 100644 --- a/test/concrete/OrderBook.addOrder.t.sol +++ b/test/concrete/OrderBook.addOrder.t.sol @@ -5,6 +5,11 @@ import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRea import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; import {OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; +import { + UnsupportedCalculateOutputs, + UnsupportedCalculateInputs, + UnsupportedHandleInputs +} from "src/concrete/OrderBook.sol"; /// @title OrderBookAddOrderTest /// @notice A test harness for testing the OrderBook addOrder function. @@ -29,28 +34,28 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { iOrderbook.addOrder(config); } - // /// A stack of 0 for calculate order reverts. - // function testAddOrderRealZeroStackCalculateReverts(address owner, OrderConfigV2 memory config) public { - // LibTestAddOrder.conformConfig(config, iDeployer); - // (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(":;:;"); - // config.evaluableConfig.constants = constants; - // config.evaluableConfig.bytecode = bytecode; - // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 0, 2)); - // vm.prank(owner); - // iOrderbook.addOrder(config); - // } + /// A stack of 0 for calculate order reverts. + function testAddOrderRealZeroStackCalculateReverts(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(":;:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateOutputs.selector, 0)); + vm.prank(owner); + iOrderbook.addOrder(config); + } - // /// A stack of 1 for calculate order reverts. - // function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfigV2 memory config) public { - // LibTestAddOrder.conformConfig(config, iDeployer); - // (bytes memory bytecode, uint256[] memory constants) = - // IParserV1(address(iParser)).parse("_:block-timestamp();:;"); - // config.evaluableConfig.constants = constants; - // config.evaluableConfig.bytecode = bytecode; - // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 1, 2)); - // vm.prank(owner); - // iOrderbook.addOrder(config); - // } + /// A stack of 1 for calculate order reverts. + function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = + IParserV1(address(iParser)).parse("_:block-timestamp();:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateOutputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } /// A stack of 2 for calculate order deploys. function testAddOrderRealTwoStackCalculateReverts(address owner, OrderConfigV2 memory config) public { @@ -73,4 +78,60 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { vm.prank(owner); iOrderbook.addOrder(config); } + + /// Inputs for calculate order errors. Tests one input. + function testAddOrderRealCalculateInputsReverts1(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("i:;:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateInputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for calculate order errors. Tests two inputs. + function testAddOrderRealCalculateInputsReverts2(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("i0 i1:;:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateInputs.selector, 2)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for calculate order errors. This takes precedent over the same + /// error in handle io. + function testAddOrderRealCalculateInputsRevertsPreference(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("i:;i:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateInputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for handle io errors. Tests one input. + function testAddOrderRealHandleIOInputsReverts1(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("_ _:1e18 1e18;i:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedHandleInputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for handle io errors. Tests two inputs. + function testAddOrderRealHandleIOInputsReverts2(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("_ _:1e18 1e18;i0 i1:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedHandleInputs.selector, 2)); + vm.prank(owner); + iOrderbook.addOrder(config); + } } From 1dd01dd6e6d2a5a1f808c011b811284ce3801530 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 24 Nov 2023 15:44:58 +0400 Subject: [PATCH 13/14] fmt --- script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol | 5 +---- script/DeployGenericPoolOrderBookV3FlashBorrower.sol | 5 +---- script/DeployOrderBook.sol | 5 +---- .../DeployRouteProcessorOrderBookV3ArbOrderTaker.sol | 5 +---- src/concrete/OrderBook.sol | 4 +--- test/util/abstract/OrderBookExternalRealTest.sol | 11 +++++------ 6 files changed, 10 insertions(+), 25 deletions(-) diff --git a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol index af41180bf..19cb51182 100644 --- a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol +++ b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol @@ -22,10 +22,7 @@ contract DeployGenericPoolOrderBookV3ArbOrderTaker is Script { vm.startBroadcast(deployerPrivateKey); GenericPoolOrderBookV3ArbOrderTaker deployed = - new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig ( - i9rDeployer, - meta - )); + new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol index 18860b0ca..505881af1 100644 --- a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol +++ b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol @@ -25,10 +25,7 @@ contract DeployGenericPoolOrderBookV3FlashBorrower is Script { vm.startBroadcast(deployerPrivateKey); GenericPoolOrderBookV3FlashBorrower deployed = - new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV3ConstructionConfig ( - i9rDeployer, - meta - )); + new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployOrderBook.sol b/script/DeployOrderBook.sol index 36ff5a195..202397715 100644 --- a/script/DeployOrderBook.sol +++ b/script/DeployOrderBook.sol @@ -15,10 +15,7 @@ contract DeployOrderBook is Script { console2.logBytes32(keccak256(meta)); vm.startBroadcast(deployerPrivateKey); - OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig ( - i9rDeployer, - meta - )); + OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol index 6672bf902..4372d40fb 100644 --- a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol +++ b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol @@ -22,10 +22,7 @@ contract DeployRouteProcessorOrderBookV3ArbOrderTaker is Script { vm.startBroadcast(deployerPrivateKey); RouteProcessorOrderBookV3ArbOrderTaker deployed = - new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig ( - i9rDeployer, - meta - )); + new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); (deployed); vm.stopBroadcast(); } diff --git a/src/concrete/OrderBook.sol b/src/concrete/OrderBook.sol index 7bf43f22c..36768c18e 100644 --- a/src/concrete/OrderBook.sol +++ b/src/concrete/OrderBook.sol @@ -701,9 +701,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookV3Flash uint256[][] memory context; { - uint256[][] memory callingContext = new uint256[][]( - CALLING_CONTEXT_COLUMNS - ); + uint256[][] memory callingContext = new uint256[][](CALLING_CONTEXT_COLUMNS); callingContext[CONTEXT_CALLING_CONTEXT_COLUMN - 1] = LibUint256Array.arrayFrom( uint256(orderHash), uint256(uint160(order.owner)), uint256(uint160(counterparty)) ); diff --git a/test/util/abstract/OrderBookExternalRealTest.sol b/test/util/abstract/OrderBookExternalRealTest.sol index deb2fed34..ac7486453 100644 --- a/test/util/abstract/OrderBookExternalRealTest.sol +++ b/test/util/abstract/OrderBookExternalRealTest.sol @@ -53,12 +53,11 @@ abstract contract OrderBookExternalRealTest is Test, IOrderBookV3Stub { console2.logBytes32(keccak256(deployerMeta)); iDeployer = IExpressionDeployerV3( address( - new RainterpreterExpressionDeployerNPE2(RainterpreterExpressionDeployerNPE2ConstructionConfig( - address(iInterpreter), - address(iStore), - address(iParser), - deployerMeta - )) + new RainterpreterExpressionDeployerNPE2( + RainterpreterExpressionDeployerNPE2ConstructionConfig( + address(iInterpreter), address(iStore), address(iParser), deployerMeta + ) + ) ) ); bytes memory orderbookMeta = vm.readFileBinary(ORDER_BOOK_META_PATH); From 3d805fd9d31ca661ed1d5c7c82ecfb1188d4ab2e Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 24 Nov 2023 15:58:01 +0400 Subject: [PATCH 14/14] fix deploy --- script/DeployConstants.sol | 6 ++++++ .../DeployGenericPoolOrderBookV3ArbOrderTaker.sol | 13 +++++++------ .../DeployGenericPoolOrderBookV3FlashBorrower.sol | 6 ++---- script/DeployOrderBook.sol | 6 ++---- ...DeployRouteProcessorOrderBookV3ArbOrderTaker.sol | 13 +++++++------ 5 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 script/DeployConstants.sol diff --git a/script/DeployConstants.sol b/script/DeployConstants.sol new file mode 100644 index 000000000..69c046a53 --- /dev/null +++ b/script/DeployConstants.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: CAL +pragma solidity ^0.8.19; + +// @todo pull this from subgraph. +// hardcoded from CI https://github.com/rainprotocol/rain.interpreter/actions/runs/6953107467/job/18917750124 +address constant I9R_DEPLOYER = 0xa5aDC3F2A7A8Cf7b5172D76d8b26c3d49272297B; diff --git a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol index 19cb51182..d4952a087 100644 --- a/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol +++ b/script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol @@ -1,8 +1,12 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "forge-std/Script.sol"; -import "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; +import {Script, console2} from "forge-std/Script.sol"; +import { + GenericPoolOrderBookV3ArbOrderTaker, + DeployerDiscoverableMetaV3ConstructionConfig +} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; +import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// @title DeployGenericPoolOrderBookV3ArbOrderTaker /// @notice A script that deploys a `GenericPoolOrderBookV3ArbOrderTaker`. This @@ -13,16 +17,13 @@ contract DeployGenericPoolOrderBookV3ArbOrderTaker is Script { /// provide the built metadata. On CI this is achieved by using the rain cli. function run(bytes memory meta) external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - // @todo pull this from subgraph. - // hardcoded from CI https://github.com/rainprotocol/rain.interpreter/actions/runs/6101787278/job/16558857505 - address i9rDeployer = 0xAb0A13cC2654CbaDABabC9952a090928F4ff569A; console2.log("GenericPoolOrderBookV3ArbOrderTaker meta hash:"); console2.logBytes32(keccak256(meta)); vm.startBroadcast(deployerPrivateKey); GenericPoolOrderBookV3ArbOrderTaker deployed = - new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); + new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol index 505881af1..5f18a1719 100644 --- a/script/DeployGenericPoolOrderBookV3FlashBorrower.sol +++ b/script/DeployGenericPoolOrderBookV3FlashBorrower.sol @@ -6,6 +6,7 @@ import { GenericPoolOrderBookV3FlashBorrower, DeployerDiscoverableMetaV3ConstructionConfig } from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; +import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// @title DeployGenericPoolOrderBookV3FlashBorrower /// @notice A script that deploys a `GenericPoolOrderBookV3FlashBorrower`. This @@ -16,16 +17,13 @@ contract DeployGenericPoolOrderBookV3FlashBorrower is Script { /// provide the built metadata. On CI this is achieved by using the rain cli. function run(bytes memory meta) external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - // @todo pull this from subgraph. - // hardcoded from CI https://github.com/rainprotocol/rain.interpreter/actions/runs/6101787278/job/16558857505 - address i9rDeployer = 0xAb0A13cC2654CbaDABabC9952a090928F4ff569A; console2.log("DeployGenericPoolOrderBookV3FlashBorrower meta hash:"); console2.logBytes32(keccak256(meta)); vm.startBroadcast(deployerPrivateKey); GenericPoolOrderBookV3FlashBorrower deployed = - new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); + new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployOrderBook.sol b/script/DeployOrderBook.sol index 202397715..f2af4a542 100644 --- a/script/DeployOrderBook.sol +++ b/script/DeployOrderBook.sol @@ -3,19 +3,17 @@ pragma solidity =0.8.19; import {Script, console2} from "forge-std/Script.sol"; import {OrderBook, DeployerDiscoverableMetaV3ConstructionConfig} from "src/concrete/OrderBook.sol"; +import {I9R_DEPLOYER} from "./DeployConstants.sol"; contract DeployOrderBook is Script { function run(bytes memory meta) external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - // @todo pull this from subgraph. - // hardcoded from CI https://github.com/rainprotocol/rain.interpreter/actions/runs/6953107467/job/18917750124 - address i9rDeployer = 0xa5aDC3F2A7A8Cf7b5172D76d8b26c3d49272297B; console2.log("DeployOrderBook meta hash:"); console2.logBytes32(keccak256(meta)); vm.startBroadcast(deployerPrivateKey); - OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); + OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); (deployed); vm.stopBroadcast(); } diff --git a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol index 4372d40fb..07fef9cf7 100644 --- a/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol +++ b/script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol @@ -1,8 +1,12 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "forge-std/Script.sol"; -import "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; +import {Script, console2} from "forge-std/Script.sol"; +import { + RouteProcessorOrderBookV3ArbOrderTaker, + DeployerDiscoverableMetaV3ConstructionConfig +} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol"; +import {I9R_DEPLOYER} from "./DeployConstants.sol"; /// @title DeployRouteProcessorOrderBookV3ArbOrderTaker /// @notice A script that deploys a `RouteProcessorOrderBookV3ArbOrderTaker`. This @@ -13,16 +17,13 @@ contract DeployRouteProcessorOrderBookV3ArbOrderTaker is Script { /// provide the built metadata. On CI this is achieved by using the rain cli. function run(bytes memory meta) external { uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY"); - // @todo pull this from subgraph. - // hardcoded from CI https://github.com/rainprotocol/rain.interpreter/actions/runs/6101787278/job/16558857505 - address i9rDeployer = 0xAb0A13cC2654CbaDABabC9952a090928F4ff569A; console2.log("RouteProcessorOrderBookV3ArbOrderTaker meta hash:"); console2.logBytes32(keccak256(meta)); vm.startBroadcast(deployerPrivateKey); RouteProcessorOrderBookV3ArbOrderTaker deployed = - new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(i9rDeployer, meta)); + new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta)); (deployed); vm.stopBroadcast(); }