diff --git a/.gas-snapshot b/.gas-snapshot index 580b9f645..7762704be 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,7 +1,7 @@ -GenericPoolOrderBookV3ArbOrderTakerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 1118510, ~: 1118456) -GenericPoolOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 1062543, ~: 1063098) -GenericPoolOrderBookV3FlashBorrowerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 1394297, ~: 1393645) -GenericPoolOrderBookV3FlashBorrowerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 1319200, ~: 1319647) +GenericPoolOrderBookV3ArbOrderTakerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 1009609, ~: 1008341) +GenericPoolOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 953258, ~: 953814) +GenericPoolOrderBookV3FlashBorrowerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 1290560, ~: 1288607) +GenericPoolOrderBookV3FlashBorrowerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 1212419, ~: 1212863) LibOrderTest:testHashEqual((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[])) (runs: 5096, μ: 194389, ~: 191140) 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, μ: 298734, ~: 298554) 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, μ: 2771808, ~: 2761475) @@ -51,5 +51,5 @@ OrderBookWithdrawTest:testWithdrawMany((bool,address,address,uint256,uint248)[]) OrderBookWithdrawTest:testWithdrawPartialVault(address,uint256,uint256,uint256) (runs: 5096, μ: 51929, ~: 51929) OrderBookWithdrawTest:testWithdrawReentrant(address,uint256,uint256,address,address,uint256) (runs: 5096, μ: 506228, ~: 507997) 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, μ: 1140756, ~: 1140707) -RouteProcessorOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 1085625, ~: 1086117) \ No newline at end of file +RouteProcessorOrderBookV3ArbOrderTakerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 1033065, ~: 1032882) +RouteProcessorOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 976343, ~: 976833) \ No newline at end of file diff --git a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol index 596996b54..ae56837c3 100644 --- a/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol @@ -10,8 +10,6 @@ import "test/util/lib/LibGenericPoolOrderBookV3ArbOrderTakerConstants.sol"; import "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol"; import "src/interface/unstable/IOrderBookV3.sol"; -import "test/util/concrete/FlashLendingMockOrderBook.sol"; - contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) { (address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) = @@ -19,7 +17,15 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3ArbOrderTaker(config))); } - constructor() ArbTest(buildArbTestConstructorConfig()) {} + constructor() ArbTest(buildArbTestConstructorConfig()) { + ICloneableV2(iArb).initialize( + abi.encode( + OrderBookV3ArbOrderTakerConfigV1( + address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" + ) + ) + ); + } function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { vm.assume(order.validInputs.length > 0); @@ -27,24 +33,13 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { vm.assume(order.validOutputs.length > 0); outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1); - FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook(); - - GenericPoolOrderBookV3ArbOrderTaker arb = GenericPoolOrderBookV3ArbOrderTaker(Clones.clone(iImplementation)); - arb.initialize( - abi.encode( - OrderBookV3ArbOrderTakerConfigV1( - address(ob), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" - ) - ) - ); - 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)); - arb.arb( + GenericPoolOrderBookV3ArbOrderTaker(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(iRefundoor, iRefundoor, "")), 0 ); @@ -63,18 +58,8 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1); vm.assume(minimumOutput > mintAmount); - FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook(); - - GenericPoolOrderBookV3ArbOrderTaker arb = GenericPoolOrderBookV3ArbOrderTaker(Clones.clone(iImplementation)); - arb.initialize( - abi.encode( - OrderBookV3ArbOrderTakerConfigV1( - address(ob), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" - ) - ) - ); - iTakerOutput.mint(address(arb), mintAmount); + iTakerOutput.mint(iArb, mintAmount); order.validInputs[inputIOIndex].token = address(iTakerOutput); order.validOutputs[outputIOIndex].token = address(iTakerInput); @@ -83,7 +68,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest { orders[0] = TakeOrderConfig(order, inputIOIndex, outputIOIndex, new SignedContextV1[](0)); vm.expectRevert(abi.encodeWithSelector(MinimumOutput.selector, minimumOutput, mintAmount)); - arb.arb( + GenericPoolOrderBookV3ArbOrderTaker(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(iRefundoor, iRefundoor, "")), minimumOutput ); diff --git a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol index 76f5ccffe..eb911800b 100644 --- a/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol +++ b/test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol @@ -6,7 +6,6 @@ import "lib/openzeppelin-contracts/contracts/proxy/Clones.sol"; import "test/util/lib/LibTestConstants.sol"; import "test/util/lib/LibGenericPoolOrderBookV3FlashBorrowerConstants.sol"; -import "test/util/concrete/FlashLendingMockOrderBook.sol"; import "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol"; import "src/interface/unstable/IOrderBookV3.sol"; @@ -18,7 +17,15 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3FlashBorrower(config))); } - constructor() ArbTest(buildArbTestConstructorConfig()) {} + constructor() ArbTest(buildArbTestConstructorConfig()) { + ICloneableV2(iArb).initialize( + abi.encode( + OrderBookV3FlashBorrowerConfigV2( + address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" + ) + ) + ); + } function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { vm.assume(order.validInputs.length > 0); @@ -26,24 +33,13 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { vm.assume(order.validOutputs.length > 0); outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1); - FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook(); - - GenericPoolOrderBookV3FlashBorrower arb = GenericPoolOrderBookV3FlashBorrower(Clones.clone(iImplementation)); - arb.initialize( - abi.encode( - OrderBookV3FlashBorrowerConfigV2( - address(ob), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" - ) - ) - ); - 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)); - arb.arb( + GenericPoolOrderBookV3FlashBorrower(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""), 0, abi.encode(iRefundoor, iRefundoor, "") @@ -63,18 +59,8 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1); vm.assume(minimumOutput > mintAmount); - FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook(); - - GenericPoolOrderBookV3FlashBorrower arb = GenericPoolOrderBookV3FlashBorrower(Clones.clone(iImplementation)); - arb.initialize( - abi.encode( - OrderBookV3FlashBorrowerConfigV2( - address(ob), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), "" - ) - ) - ); - iTakerOutput.mint(address(arb), mintAmount); + iTakerOutput.mint(iArb, mintAmount); order.validInputs[inputIOIndex].token = address(iTakerOutput); order.validOutputs[outputIOIndex].token = address(iTakerInput); @@ -83,7 +69,7 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest { orders[0] = TakeOrderConfig(order, inputIOIndex, outputIOIndex, new SignedContextV1[](0)); vm.expectRevert(abi.encodeWithSelector(MinimumOutput.selector, minimumOutput, mintAmount)); - arb.arb( + GenericPoolOrderBookV3FlashBorrower(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""), minimumOutput, abi.encode(iRefundoor, iRefundoor, "") diff --git a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol index cb0863182..280336a68 100644 --- a/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol +++ b/test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol @@ -1,17 +1,16 @@ // SPDX-License-Identifier: CAL pragma solidity =0.8.19; -import "openzeppelin-contracts/contracts/proxy/Clones.sol"; - import "test/util/lib/LibTestConstants.sol"; import "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol"; import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol"; -import "test/util/concrete/FlashLendingMockOrderBook.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, DeployerDiscoverableMetaV2ConstructionConfig memory config) = @@ -19,27 +18,23 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config))); } - constructor() ArbTest(buildArbTestConstructorConfig()) {} - - function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { - vm.assume(order.validInputs.length > 0); - inputIOIndex = bound(inputIOIndex, 0, order.validInputs.length - 1); - vm.assume(order.validOutputs.length > 0); - outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1); - - FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook(); - - RouteProcessorOrderBookV3ArbOrderTaker arb = - RouteProcessorOrderBookV3ArbOrderTaker(Clones.clone(iImplementation)); - arb.initialize( + constructor() ArbTest(buildArbTestConstructorConfig()) { + ICloneableV2(iArb).initialize( abi.encode( OrderBookV3ArbOrderTakerConfigV1( - address(ob), + address(iOrderBook), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), abi.encode(iRefundoor) ) ) ); + } + + function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public { + vm.assume(order.validInputs.length > 0); + inputIOIndex = bound(inputIOIndex, 0, order.validInputs.length - 1); + vm.assume(order.validOutputs.length > 0); + outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1); order.validInputs[inputIOIndex].token = address(iTakerOutput); order.validOutputs[outputIOIndex].token = address(iTakerInput); @@ -47,7 +42,9 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { TakeOrderConfig[] memory orders = new TakeOrderConfig[](1); orders[0] = TakeOrderConfig(order, inputIOIndex, outputIOIndex, new SignedContextV1[](0)); - arb.arb(TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(bytes("0x00"))), 0); + RouteProcessorOrderBookV3ArbOrderTaker(iArb).arb( + TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(bytes("0x00"))), 0 + ); } function testMinimumOutput( @@ -63,21 +60,8 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1); vm.assume(minimumOutput > mintAmount); - FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook(); - - RouteProcessorOrderBookV3ArbOrderTaker arb = - RouteProcessorOrderBookV3ArbOrderTaker(Clones.clone(iImplementation)); - arb.initialize( - abi.encode( - OrderBookV3ArbOrderTakerConfigV1( - address(ob), - EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), - abi.encode(iRefundoor) - ) - ) - ); - iTakerOutput.mint(address(arb), mintAmount); + iTakerOutput.mint(iArb, mintAmount); order.validInputs[inputIOIndex].token = address(iTakerOutput); order.validOutputs[outputIOIndex].token = address(iTakerInput); @@ -86,7 +70,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest { orders[0] = TakeOrderConfig(order, inputIOIndex, outputIOIndex, new SignedContextV1[](0)); vm.expectRevert(abi.encodeWithSelector(MinimumOutput.selector, minimumOutput, mintAmount)); - arb.arb( + RouteProcessorOrderBookV3ArbOrderTaker(iArb).arb( TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(bytes("0x00"))), minimumOutput ); diff --git a/test/util/abstract/ArbTest.sol b/test/util/abstract/ArbTest.sol index 8d3e2b7ed..4e69babbc 100644 --- a/test/util/abstract/ArbTest.sol +++ b/test/util/abstract/ArbTest.sol @@ -2,6 +2,7 @@ pragma solidity =0.8.19; import "forge-std/Test.sol"; +import "openzeppelin-contracts/contracts/proxy/Clones.sol"; import "test/util/lib/LibTestConstants.sol"; import {DeployerDiscoverableMetaV2ConstructionConfig} from @@ -9,6 +10,7 @@ import {DeployerDiscoverableMetaV2ConstructionConfig} from import {IExpressionDeployerV2} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV2.sol"; import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; import "test/util/concrete/Refundoor.sol"; +import "test/util/concrete/FlashLendingMockOrderBook.sol"; contract Token is ERC20 { constructor() ERC20("Token", "TKN") {} @@ -29,13 +31,17 @@ abstract contract ArbTest is Test { Token immutable iTakerInput; Token immutable iTakerOutput; address immutable iRefundoor; + FlashLendingMockOrderBook immutable iOrderBook; + address iArb; constructor(ArbTestConstructorConfig memory config) { iDeployer = config.deployer; iImplementation = config.implementation; + iArb = Clones.clone(iImplementation); iTakerInput = new Token(); iTakerOutput = new Token(); iRefundoor = address(new Refundoor()); + iOrderBook = new FlashLendingMockOrderBook(); } function buildConstructorConfig(string memory metaPath)