From f07524108354f04fa1fd95845843c7529fbdfd97 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Thu, 22 Aug 2024 13:51:23 +0530 Subject: [PATCH 1/5] Bump ob dep --- lib/rain.orderbook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rain.orderbook b/lib/rain.orderbook index 794bb26..be02225 160000 --- a/lib/rain.orderbook +++ b/lib/rain.orderbook @@ -1 +1 @@ -Subproject commit 794bb26f9ca0de3835aa10821b4e7f34f104485e +Subproject commit be02225be02c6264d7088de6ddf61b9d9ada1499 From 0d4ac23bff20c4b3c947b46d88d3a606203b5e02 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Thu, 22 Aug 2024 16:44:41 +0530 Subject: [PATCH 2/5] update lib --- src/StrategyTests.sol | 68 ++++++++++++++---------- src/lib/LibComposeOrder.sol | 86 ++++++++++++++++++++++++++++--- src/lib/LibStrategyDeployment.sol | 5 +- test/DeployedStrategyTest.t.sol | 54 ++++--------------- test/strategies/base-order.rain | 25 +-------- test/strategies/base-settings.yml | 20 +++++++ 6 files changed, 152 insertions(+), 106 deletions(-) create mode 100644 test/strategies/base-settings.yml diff --git a/src/StrategyTests.sol b/src/StrategyTests.sol index f788975..dc02ca3 100644 --- a/src/StrategyTests.sol +++ b/src/StrategyTests.sol @@ -16,16 +16,39 @@ contract StrategyTests is OrderBookStrategyTest { internal returns (OrderV3 memory order) { + { + bytes memory orderBook = LibComposeOrders.getOrderOrderBook( + vm, strategy.strategyFile, strategy.settingsFile, strategy.deploymentKey, strategy.buildPath, strategy.manifestPath + ); + iOrderBook = IOrderBookV4(address(uint160(bytes20(orderBook)))); + } + + bytes memory addOrderCallData; + { + addOrderCallData = LibComposeOrders.getOrderCalldata( + vm, strategy.strategyFile, strategy.settingsFile, strategy.deploymentKey, strategy.buildPath, strategy.manifestPath + ); + } + + vm.startPrank(ORDER_OWNER); + vm.recordLogs(); + (, bytes memory result) = address(iOrderBook).call(addOrderCallData); + (bool stateChanged) = abi.decode(result, (bool)); + assertEq(stateChanged, true); + Vm.Log[] memory entries = vm.getRecordedLogs(); + (,, order) = abi.decode(entries[0].data, (address, bytes32, OrderV3)); + assertEq(order.owner, ORDER_OWNER); + address inputToken; address outputToken; uint256 inputTokenVaultId; uint256 outputTokenVaultId; { - inputToken = strategy.inputVaults[strategy.inputTokenIndex].token; - outputToken = strategy.outputVaults[strategy.outputTokenIndex].token; - inputTokenVaultId = strategy.inputVaults[strategy.inputTokenIndex].vaultId; - outputTokenVaultId = strategy.outputVaults[strategy.outputTokenIndex].vaultId; + inputToken = order.validInputs[strategy.inputTokenIndex].token; + outputToken = order.validOutputs[strategy.outputTokenIndex].token; + inputTokenVaultId = order.validInputs[strategy.inputTokenIndex].vaultId; + outputTokenVaultId = order.validOutputs[strategy.outputTokenIndex].vaultId; deal(address(inputToken), EXTERNAL_EOA, 1e30); deal(address(outputToken), EXTERNAL_EOA, 1e30); deal(address(inputToken), APPROVED_EOA, 1e30); @@ -36,26 +59,6 @@ contract StrategyTests is OrderBookStrategyTest { { depositTokens(ORDER_OWNER, outputToken, outputTokenVaultId, strategy.takerAmount, new TaskV1[](0)); } - { - TaskV1[] memory postAddOrderTasks; - { - bytes memory postOrderCompose = iParser.parse2( - LibComposeOrders.getComposedPostAddOrder( - vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath - ) - ); - EvaluableV3 memory postOrderEvaluable = EvaluableV3(iInterpreter, iStore, postOrderCompose); - TaskV1 memory postOrderAction = TaskV1(postOrderEvaluable,strategy.postAddOrderTaskSignedContext); - postAddOrderTasks = new TaskV1[](1); - postAddOrderTasks[0] = postOrderAction; - } - bytes memory bytecode = iParser.parse2( - LibComposeOrders.getComposedOrder( - vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath - ) - ); - order = placeOrder(ORDER_OWNER, bytecode, strategy.inputVaults, strategy.outputVaults, postAddOrderTasks); - } } // Function to assert OrderBook calculations context by calling 'takeOrders' function @@ -84,8 +87,8 @@ contract StrategyTests is OrderBookStrategyTest { // Move external pool price in opposite direction that of the order { moveExternalPrice( - strategy.inputVaults[strategy.inputTokenIndex].token, - strategy.outputVaults[strategy.outputTokenIndex].token, + order.validInputs[strategy.inputTokenIndex].token, + order.validOutputs[strategy.outputTokenIndex].token, strategy.makerAmount, strategy.makerRoute ); @@ -114,7 +117,7 @@ contract StrategyTests is OrderBookStrategyTest { ) internal { bytes memory bytecode = iParser.parse2( LibComposeOrders.getComposedOrder( - vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath + vm, strategy.strategyFile, strategy.settingsFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath ) ); @@ -132,6 +135,15 @@ contract StrategyTests is OrderBookStrategyTest { } } + function toAddress(bytes memory b) internal pure returns (address) { + require(b.length >= 20, "Insufficient length"); + address addr; + assembly { + addr := mload(add(b, 0x14)) // Load 20 bytes starting from the 20th byte + } + return addr; + } + function getBounty(Vm.Log[] memory entries) public view @@ -153,5 +165,5 @@ contract StrategyTests is OrderBookStrategyTest { } } return (bounties[0], bounties[1]); - } + } } diff --git a/src/lib/LibComposeOrder.sol b/src/lib/LibComposeOrder.sol index ea2fbfa..b9bb304 100644 --- a/src/lib/LibComposeOrder.sol +++ b/src/lib/LibComposeOrder.sol @@ -11,11 +11,12 @@ library LibComposeOrders { function getComposedOrder( Vm vm, string memory filePath, + string memory settingsPath, string memory scenario, string memory buildPath, string memory manifestPath ) internal returns (bytes memory composedOrder) { - string[] memory ffi = new string[](16); + string[] memory ffi = new string[](18); ffi[0] = "nix"; ffi[1] = "develop"; ffi[2] = buildPath; @@ -30,8 +31,10 @@ library LibComposeOrders { ffi[11] = "compose"; ffi[12] = "-f"; ffi[13] = filePath; - ffi[14] = "-s"; - ffi[15] = scenario; + ffi[14] = "-c"; + ffi[15] = settingsPath; + ffi[16] = "-s"; + ffi[17] = scenario; composedOrder = vm.ffi(ffi); } @@ -39,11 +42,12 @@ library LibComposeOrders { function getComposedPostAddOrder( Vm vm, string memory filePath, + string memory settingsPath, string memory scenario, string memory buildPath, string memory manifestPath ) internal returns (bytes memory composedSource) { - string[] memory ffi = new string[](17); + string[] memory ffi = new string[](19); ffi[0] = "nix"; ffi[1] = "develop"; ffi[2] = buildPath; @@ -58,9 +62,77 @@ library LibComposeOrders { ffi[11] = "compose"; ffi[12] = "-f"; ffi[13] = filePath; - ffi[14] = "-s"; - ffi[15] = scenario; - ffi[16] = "-p"; + ffi[14] = "-c"; + ffi[15] = settingsPath; + ffi[16] = "-s"; + ffi[17] = scenario; + ffi[18] = "-p"; + + composedSource = vm.ffi(ffi); + } + + function getOrderCalldata( + Vm vm, + string memory filePath, + string memory settingsPath, + string memory deploymentKey, + string memory buildPath, + string memory manifestPath + ) internal returns (bytes memory composedOrder) { + string[] memory ffi = new string[](20); + ffi[0] = "nix"; + ffi[1] = "develop"; + ffi[2] = buildPath; + ffi[3] = "--command"; + ffi[4] = "cargo"; + ffi[5] = "run"; + ffi[6] = "--manifest-path"; + ffi[7] = manifestPath; + ffi[8] = "--package"; + ffi[9] = "rain_orderbook_cli"; + ffi[10] = "order"; + ffi[11] = "calldata"; + ffi[12] = "-f"; + ffi[13] = filePath; + ffi[14] = "-c"; + ffi[15] = settingsPath; + ffi[16] = "-e"; + ffi[17] = deploymentKey; + ffi[18] = "-o"; + ffi[19] = "hex"; + + composedOrder = vm.ffi(ffi); + } + + function getOrderOrderBook( + Vm vm, + string memory filePath, + string memory settingsPath, + string memory deploymentKey, + string memory buildPath, + string memory manifestPath + ) internal returns (bytes memory composedSource) { + string[] memory ffi = new string[](20); + ffi[0] = "nix"; + ffi[1] = "develop"; + ffi[2] = buildPath; + ffi[3] = "--command"; + ffi[4] = "cargo"; + ffi[5] = "run"; + ffi[6] = "--manifest-path"; + ffi[7] = manifestPath; + ffi[8] = "--package"; + ffi[9] = "rain_orderbook_cli"; + ffi[10] = "order"; + ffi[11] = "ob"; + ffi[12] = "-f"; + ffi[13] = filePath; + ffi[14] = "-c"; + ffi[15] = settingsPath; + ffi[16] = "-e"; + ffi[17] = deploymentKey; + ffi[18] = "-o"; + ffi[19] = "hex"; composedSource = vm.ffi(ffi); } diff --git a/src/lib/LibStrategyDeployment.sol b/src/lib/LibStrategyDeployment.sol index 47ed4c8..b28360e 100644 --- a/src/lib/LibStrategyDeployment.sol +++ b/src/lib/LibStrategyDeployment.sol @@ -16,11 +16,10 @@ library LibStrategyDeployment { uint256 expectedRatio; uint256 expectedAmount; string strategyFile; + string settingsFile; string strategyScenario; + string deploymentKey; string buildPath; string manifestPath; - IO[] inputVaults; - IO[] outputVaults; - SignedContextV1[] postAddOrderTaskSignedContext; } } diff --git a/test/DeployedStrategyTest.t.sol b/test/DeployedStrategyTest.t.sol index a26337b..76ff33b 100644 --- a/test/DeployedStrategyTest.t.sol +++ b/test/DeployedStrategyTest.t.sol @@ -13,12 +13,6 @@ contract DeployedStrategyTest is StrategyTests { // Inheriting contract defines the fork block number. uint256 constant FORK_BLOCK_NUMBER = 18690236; - // https://basescan.org/address/0x222789334d44bb5b2364939477e15a6c981ca165 - address constant RED_TOKEN = address(0x222789334D44bB5b2364939477E15A6c981Ca165); - - // https://basescan.org/address/0x6d3abb80c3cbae0f60ba274f36137298d8571fbe - address constant BLUE_TOKEN = address(0x6d3AbB80c3CBAe0f60ba274F36137298D8571Fbe); - // Inheriting contract defines fork selection. function selectFork() internal { uint256 fork = vm.createFork(vm.envString("RPC_URL_BASE")); @@ -30,33 +24,16 @@ contract DeployedStrategyTest is StrategyTests { function setUp() public { selectFork(); - iParser = IParserV2(0x56394785a22b3BE25470a0e03eD9E0a939C47b9b); - iStore = IInterpreterStoreV2(0x6E4b01603edBDa617002A077420E98C86595748E); - iInterpreter = IInterpreterV3(0x379b966DC6B117dD47b5Fc5308534256a4Ab1BCC); - iExpressionDeployer = IExpressionDeployerV3(0x56394785a22b3BE25470a0e03eD9E0a939C47b9b); - - iOrderBook = IOrderBookV4(0x80DE00e3cA96AE0569426A1bb1Ae22CD4181dE6F); iArbInstance = IOrderBookV4ArbOrderTakerV2(0x40D44abeC30288BFcd400200BA65FBD05daA5321); iRouteProcessor = IRouteProcessor(address(0x0389879e0156033202C44BF784ac18fC02edeE4f)); EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427); APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88); ORDER_OWNER = address(0x5e01e44aE1969e16B9160d903B6F2aa991a37B21); - } - + // Inheriting contract tests OrderBook strategy with test suite. function testDeployedStrategy() public { - // Input vaults - IO[] memory inputVaults = new IO[](1); - IO memory inputVault = IO(BLUE_TOKEN, 18, 1); - inputVaults[0] = inputVault; - - // Output vaults - IO[] memory outputVaults = new IO[](1); - IO memory outputVault = IO(RED_TOKEN, 18, 1); - outputVaults[0] = outputVault; - // Expected calculations context uint256 expectedRatio = 0.001e18; uint256 expectedAmountOutputMax = 0.0000000000000001e18; @@ -72,12 +49,11 @@ contract DeployedStrategyTest is StrategyTests { expectedRatio, expectedAmountOutputMax, "test/strategies/base-order.rain", - "base-order-simulations", + "test/strategies/base-settings.yml", + "", + "buy-order", "./lib/rain.orderbook", - "./lib/rain.orderbook/Cargo.toml", - inputVaults, - outputVaults, - new SignedContextV1[](0) + "./lib/rain.orderbook/Cargo.toml" ); // Assert strategy calculations by executing order by directly calling 'takeOrder' function @@ -87,16 +63,6 @@ contract DeployedStrategyTest is StrategyTests { // Inheriting contract tests OrderBook strategy with test suite. function testDeployedStrategyArbOrder() public { - // Input vaults - IO[] memory inputVaults = new IO[](1); - IO memory inputVault = IO(BLUE_TOKEN, 18, 1); - inputVaults[0] = inputVault; - - // Output vaults - IO[] memory outputVaults = new IO[](1); - IO memory outputVault = IO(RED_TOKEN, 18, 1); - outputVaults[0] = outputVault; - // Expected calculations context uint256 expectedRatio = 0.001e18; uint256 expectedAmountOutputMax = 0.0000000000000001e18; @@ -112,17 +78,15 @@ contract DeployedStrategyTest is StrategyTests { expectedRatio, expectedAmountOutputMax, "test/strategies/base-order.rain", - "base-order-simulations", + "test/strategies/base-settings.yml", + "", + "buy-order", "./lib/rain.orderbook", - "./lib/rain.orderbook/Cargo.toml", - inputVaults, - outputVaults, - new SignedContextV1[](0) + "./lib/rain.orderbook/Cargo.toml" ); // Assert strategy calculations by executing order by calling 'arb' function // on the OrderBookV3ArbOrderTaker contract. - // checkStrategyCalculationsArbOrder(strategy); OrderV3 memory order = addOrderDepositOutputTokens(strategy); { diff --git a/test/strategies/base-order.rain b/test/strategies/base-order.rain index a8b4f26..907a7d8 100644 --- a/test/strategies/base-order.rain +++ b/test/strategies/base-order.rain @@ -1,24 +1,3 @@ -networks: - base-test: - rpc: https://mainnet.base.org - chain-id: 8453 - network-id: 8453 - currency: ETH - -subgraphs: - base-test: https://api.goldsky.com/api/public/project_clv14x04y9kzi01saerx7bxpg/subgraphs/ob4-base/0.3/gn - -orderbooks: - base-test: - address: 0x80DE00e3cA96AE0569426A1bb1Ae22CD4181dE6F - network: base-test - subgraph: base-test - -deployers: - base-test: - address: 0x56394785a22b3BE25470a0e03eD9E0a939C47b9b - network: base-test - tokens: base-red: network: base-test @@ -31,10 +10,10 @@ tokens: orders: base-order: inputs: - - token: base-red + - token: base-blue vault-id: 0x58f0bb181e38b0bfecbf503744e46ee3fe517425c56655288f640ad008930ca5 outputs: - - token: base-blue + - token: base-red vault-id: 0x58f0bb181e38b0bfecbf503744e46ee3fe517425c56655288f640ad008930ca5 scenarios: diff --git a/test/strategies/base-settings.yml b/test/strategies/base-settings.yml new file mode 100644 index 0000000..d7c3202 --- /dev/null +++ b/test/strategies/base-settings.yml @@ -0,0 +1,20 @@ +networks: + base-test: + rpc: https://mainnet.base.org + chain-id: 8453 + network-id: 8453 + currency: ETH + +subgraphs: + base-test: https://api.goldsky.com/api/public/project_clv14x04y9kzi01saerx7bxpg/subgraphs/ob4-base/0.3/gn + +orderbooks: + base-test: + address: 0x80DE00e3cA96AE0569426A1bb1Ae22CD4181dE6F + network: base-test + subgraph: base-test + +deployers: + base-test: + address: 0x56394785a22b3BE25470a0e03eD9E0a939C47b9b + network: base-test From ab13712b3e8148499f590c71daea0716e5aa4121 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Thu, 22 Aug 2024 17:14:30 +0530 Subject: [PATCH 3/5] update --- src/StrategyTests.sol | 7 ------- test/DeployedStrategyTest.t.sol | 12 +++++++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/StrategyTests.sol b/src/StrategyTests.sol index dc02ca3..a94cfe3 100644 --- a/src/StrategyTests.sol +++ b/src/StrategyTests.sol @@ -16,13 +16,6 @@ contract StrategyTests is OrderBookStrategyTest { internal returns (OrderV3 memory order) { - { - bytes memory orderBook = LibComposeOrders.getOrderOrderBook( - vm, strategy.strategyFile, strategy.settingsFile, strategy.deploymentKey, strategy.buildPath, strategy.manifestPath - ); - iOrderBook = IOrderBookV4(address(uint160(bytes20(orderBook)))); - } - bytes memory addOrderCallData; { addOrderCallData = LibComposeOrders.getOrderCalldata( diff --git a/test/DeployedStrategyTest.t.sol b/test/DeployedStrategyTest.t.sol index 76ff33b..b543bfe 100644 --- a/test/DeployedStrategyTest.t.sol +++ b/test/DeployedStrategyTest.t.sol @@ -29,7 +29,17 @@ contract DeployedStrategyTest is StrategyTests { EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427); APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88); - ORDER_OWNER = address(0x5e01e44aE1969e16B9160d903B6F2aa991a37B21); + ORDER_OWNER = address(0x5e01e44aE1969e16B9160d903B6F2aa991a37B21); + + bytes memory orderBook = LibComposeOrders.getOrderOrderBook( + vm, + "test/strategies/base-order.rain", + "test/strategies/base-settings.yml", + "buy-order", + "./lib/rain.orderbook", + "./lib/rain.orderbook/Cargo.toml" + ); + iOrderBook = IOrderBookV4(address(uint160(bytes20(orderBook)))); } // Inheriting contract tests OrderBook strategy with test suite. From 2976ce1ea2b4fbfb91eda57a2e87ab5c31603333 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Fri, 23 Aug 2024 14:12:50 +0530 Subject: [PATCH 4/5] bump ob dep --- lib/rain.orderbook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rain.orderbook b/lib/rain.orderbook index be02225..8f76973 160000 --- a/lib/rain.orderbook +++ b/lib/rain.orderbook @@ -1 +1 @@ -Subproject commit be02225be02c6264d7088de6ddf61b9d9ada1499 +Subproject commit 8f76973e0af461620a385f008d689377b7f5af22 From 9ed1580be066b4b63631e90bad832650df7a30b5 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Fri, 23 Aug 2024 14:32:38 +0530 Subject: [PATCH 5/5] update ob address command --- src/lib/LibComposeOrder.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/LibComposeOrder.sol b/src/lib/LibComposeOrder.sol index b9bb304..d604333 100644 --- a/src/lib/LibComposeOrder.sol +++ b/src/lib/LibComposeOrder.sol @@ -124,7 +124,7 @@ library LibComposeOrders { ffi[8] = "--package"; ffi[9] = "rain_orderbook_cli"; ffi[10] = "order"; - ffi[11] = "ob"; + ffi[11] = "ob-addr"; ffi[12] = "-f"; ffi[13] = filePath; ffi[14] = "-c";