Skip to content

Commit

Permalink
dry arb
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Sep 7, 2023
1 parent 3f0b6e1 commit b29e9fb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 40 deletions.
12 changes: 6 additions & 6 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GenericPoolOrderBookV3ArbOrderTakerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 2503121, ~: 2502124)
GenericPoolOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 2445228, ~: 2445722)
GenericPoolOrderBookV3FlashBorrowerTest:testMinimumOutput((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256,uint256,uint256) (runs: 5096, μ: 2778300, ~: 2777328)
GenericPoolOrderBookV3FlashBorrowerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 2701886, ~: 2702333)
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)
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)
Expand Down Expand Up @@ -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, μ: 2525859, ~: 2525280)
RouteProcessorOrderBookV3ArbOrderTakerTest:testTakeOrdersSender((address,bool,(address,address,address),(address,uint8,uint256)[],(address,uint8,uint256)[]),uint256,uint256) (runs: 5096, μ: 2468311, ~: 2468803)
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)
16 changes: 2 additions & 14 deletions test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ import "src/interface/unstable/IOrderBookV3.sol";

import "test/util/concrete/FlashLendingMockOrderBook.sol";

contract Mock0xProxy {
fallback() external {
Address.sendValue(payable(msg.sender), address(this).balance);
}
}

contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) {
(address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) =
Expand All @@ -34,7 +28,6 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1);

FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

GenericPoolOrderBookV3ArbOrderTaker arb = GenericPoolOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
arb.initialize(
Expand All @@ -52,9 +45,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
orders[0] = TakeOrderConfig(order, inputIOIndex, outputIOIndex, new SignedContextV1[](0));

arb.arb(
TakeOrdersConfigV2(
0, type(uint256).max, type(uint256).max, orders, abi.encode(address(proxy), address(proxy), "")
),
TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(iRefundoor, iRefundoor, "")),
0
);
}
Expand All @@ -73,7 +64,6 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {

vm.assume(minimumOutput > mintAmount);
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

GenericPoolOrderBookV3ArbOrderTaker arb = GenericPoolOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
arb.initialize(
Expand All @@ -94,9 +84,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {

vm.expectRevert(abi.encodeWithSelector(MinimumOutput.selector, minimumOutput, mintAmount));
arb.arb(
TakeOrdersConfigV2(
0, type(uint256).max, type(uint256).max, orders, abi.encode(address(proxy), address(proxy), "")
),
TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, abi.encode(iRefundoor, iRefundoor, "")),
minimumOutput
);
}
Expand Down
12 changes: 2 additions & 10 deletions test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import "test/util/concrete/FlashLendingMockOrderBook.sol";
import "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol";
import "src/interface/unstable/IOrderBookV3.sol";

contract Mock0xProxy {
fallback() external {
Address.sendValue(payable(msg.sender), address(this).balance);
}
}

contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) {
(address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) =
Expand All @@ -33,7 +27,6 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1);

FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

GenericPoolOrderBookV3FlashBorrower arb = GenericPoolOrderBookV3FlashBorrower(Clones.clone(iImplementation));
arb.initialize(
Expand All @@ -53,7 +46,7 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
arb.arb(
TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""),
0,
abi.encode(address(proxy), address(proxy), "")
abi.encode(iRefundoor, iRefundoor, "")
);
}

Expand All @@ -71,7 +64,6 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {

vm.assume(minimumOutput > mintAmount);
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

GenericPoolOrderBookV3FlashBorrower arb = GenericPoolOrderBookV3FlashBorrower(Clones.clone(iImplementation));
arb.initialize(
Expand All @@ -94,7 +86,7 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
arb.arb(
TakeOrdersConfigV2(0, type(uint256).max, type(uint256).max, orders, ""),
minimumOutput,
abi.encode(address(proxy), address(proxy), "")
abi.encode(iRefundoor, iRefundoor, "")
);
}
}
12 changes: 2 additions & 10 deletions test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ import "test/util/concrete/FlashLendingMockOrderBook.sol";
import "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol";
import "src/interface/unstable/IOrderBookV3.sol";

contract Mock0xProxy {
fallback() external {
Address.sendValue(payable(msg.sender), address(this).balance);
}
}

contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
function buildArbTestConstructorConfig() internal returns (ArbTestConstructorConfig memory) {
(address deployer, DeployerDiscoverableMetaV2ConstructionConfig memory config) =
Expand All @@ -34,7 +28,6 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
outputIOIndex = bound(outputIOIndex, 0, order.validOutputs.length - 1);

FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

RouteProcessorOrderBookV3ArbOrderTaker arb =
RouteProcessorOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
Expand All @@ -43,7 +36,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
OrderBookV3ArbOrderTakerConfigV1(
address(ob),
EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)),
abi.encode(address(proxy))
abi.encode(iRefundoor)
)
)
);
Expand Down Expand Up @@ -71,7 +64,6 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {

vm.assume(minimumOutput > mintAmount);
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

RouteProcessorOrderBookV3ArbOrderTaker arb =
RouteProcessorOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
Expand All @@ -80,7 +72,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
OrderBookV3ArbOrderTakerConfigV1(
address(ob),
EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)),
abi.encode(address(proxy))
abi.encode(iRefundoor)
)
)
);
Expand Down
3 changes: 3 additions & 0 deletions test/util/abstract/ArbTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {DeployerDiscoverableMetaV2ConstructionConfig} from
"rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol";
import {IExpressionDeployerV2} from "rain.interpreter/src/interface/unstable/IExpressionDeployerV2.sol";
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "test/util/concrete/Refundoor.sol";

contract Token is ERC20 {
constructor() ERC20("Token", "TKN") {}
Expand All @@ -27,12 +28,14 @@ abstract contract ArbTest is Test {
address immutable iImplementation;
Token immutable iTakerInput;
Token immutable iTakerOutput;
address immutable iRefundoor;

constructor(ArbTestConstructorConfig memory config) {
iDeployer = config.deployer;
iImplementation = config.implementation;
iTakerInput = new Token();
iTakerOutput = new Token();
iRefundoor = address(new Refundoor());
}

function buildConstructorConfig(string memory metaPath)
Expand Down
10 changes: 10 additions & 0 deletions test/util/concrete/Refundoor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import "openzeppelin-contracts/contracts/utils/Address.sol";

contract Refundoor {
fallback() external {
Address.sendValue(payable(msg.sender), address(this).balance);
}
}

0 comments on commit b29e9fb

Please sign in to comment.