Skip to content

Commit

Permalink
dry arb test
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Sep 7, 2023
1 parent d8986ff commit 3f0b6e1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 71 deletions.
31 changes: 7 additions & 24 deletions test/concrete/GenericPoolOrderBookV3ArbOrderTaker.sender.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import "test/util/abstract/ArbTest.sol";
import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol";
import "openzeppelin-contracts/contracts/proxy/Clones.sol";
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

import "test/util/lib/LibTestConstants.sol";
import "test/util/lib/LibGenericPoolOrderBookV3ArbOrderTakerConstants.sol";
Expand All @@ -13,14 +12,6 @@ import "src/interface/unstable/IOrderBookV3.sol";

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

contract Token is ERC20 {
constructor() ERC20("Token", "TKN") {}

function mint(address receiver_, uint256 amount_) external {
_mint(receiver_, amount_);
}
}

contract Mock0xProxy {
fallback() external {
Address.sendValue(payable(msg.sender), address(this).balance);
Expand All @@ -34,9 +25,7 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
return ArbTestConstructorConfig(deployer, address(new GenericPoolOrderBookV3ArbOrderTaker(config)));
}

constructor()
ArbTest(buildArbTestConstructorConfig())
{}
constructor() ArbTest(buildArbTestConstructorConfig()) {}

function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public {
vm.assume(order.validInputs.length > 0);
Expand All @@ -47,9 +36,6 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

Token takerInput = new Token();
Token takerOutput = new Token();

GenericPoolOrderBookV3ArbOrderTaker arb = GenericPoolOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
arb.initialize(
abi.encode(
Expand All @@ -59,8 +45,8 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
)
);

order.validInputs[inputIOIndex].token = address(takerOutput);
order.validOutputs[outputIOIndex].token = address(takerInput);
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));
Expand Down Expand Up @@ -89,9 +75,6 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

Token takerInput = new Token();
Token takerOutput = new Token();

GenericPoolOrderBookV3ArbOrderTaker arb = GenericPoolOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
arb.initialize(
abi.encode(
Expand All @@ -101,10 +84,10 @@ contract GenericPoolOrderBookV3ArbOrderTakerTest is ArbTest {
)
);

takerOutput.mint(address(arb), mintAmount);
iTakerOutput.mint(address(arb), mintAmount);

order.validInputs[inputIOIndex].token = address(takerOutput);
order.validOutputs[outputIOIndex].token = address(takerInput);
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));
Expand Down
27 changes: 6 additions & 21 deletions test/concrete/GenericPoolOrderBookV3FlashBorrower.sender.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import "test/util/abstract/ArbTest.sol";
import {ArbTest, ArbTestConstructorConfig} from "test/util/abstract/ArbTest.sol";
import "lib/openzeppelin-contracts/contracts/proxy/Clones.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

import "test/util/lib/LibTestConstants.sol";
import "test/util/lib/LibGenericPoolOrderBookV3FlashBorrowerConstants.sol";
Expand All @@ -12,14 +11,6 @@ import "test/util/concrete/FlashLendingMockOrderBook.sol";
import "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol";
import "src/interface/unstable/IOrderBookV3.sol";

contract Token is ERC20 {
constructor() ERC20("Token", "TKN") {}

function mint(address receiver_, uint256 amount_) external {
_mint(receiver_, amount_);
}
}

contract Mock0xProxy {
fallback() external {
Address.sendValue(payable(msg.sender), address(this).balance);
Expand All @@ -44,9 +35,6 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

Token takerInput = new Token();
Token takerOutput = new Token();

GenericPoolOrderBookV3FlashBorrower arb = GenericPoolOrderBookV3FlashBorrower(Clones.clone(iImplementation));
arb.initialize(
abi.encode(
Expand All @@ -56,8 +44,8 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
)
);

order.validInputs[inputIOIndex].token = address(takerOutput);
order.validOutputs[outputIOIndex].token = address(takerInput);
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));
Expand Down Expand Up @@ -85,9 +73,6 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

Token takerInput = new Token();
Token takerOutput = new Token();

GenericPoolOrderBookV3FlashBorrower arb = GenericPoolOrderBookV3FlashBorrower(Clones.clone(iImplementation));
arb.initialize(
abi.encode(
Expand All @@ -97,10 +82,10 @@ contract GenericPoolOrderBookV3FlashBorrowerTest is ArbTest {
)
);

takerOutput.mint(address(arb), mintAmount);
iTakerOutput.mint(address(arb), mintAmount);

order.validInputs[inputIOIndex].token = address(takerOutput);
order.validOutputs[outputIOIndex].token = address(takerInput);
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));
Expand Down
31 changes: 7 additions & 24 deletions test/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
pragma solidity =0.8.19;

import "openzeppelin-contracts/contracts/proxy/Clones.sol";
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

import "test/util/lib/LibTestConstants.sol";
import "test/util/lib/LibRouteProcessorOrderBookV3ArbOrderTakerConstants.sol";

import "test/util/abstract/ArbTest.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";

contract Token is ERC20 {
constructor() ERC20("Token", "TKN") {}

function mint(address receiver_, uint256 amount_) external {
_mint(receiver_, amount_);
}
}

contract Mock0xProxy {
fallback() external {
Address.sendValue(payable(msg.sender), address(this).balance);
Expand All @@ -34,9 +25,7 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
return ArbTestConstructorConfig(deployer, address(new RouteProcessorOrderBookV3ArbOrderTaker(config)));
}

constructor()
ArbTest(buildArbTestConstructorConfig())
{}
constructor() ArbTest(buildArbTestConstructorConfig()) {}

function testTakeOrdersSender(Order memory order, uint256 inputIOIndex, uint256 outputIOIndex) public {
vm.assume(order.validInputs.length > 0);
Expand All @@ -47,9 +36,6 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

Token takerInput = new Token();
Token takerOutput = new Token();

RouteProcessorOrderBookV3ArbOrderTaker arb =
RouteProcessorOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
arb.initialize(
Expand All @@ -62,8 +48,8 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
)
);

order.validInputs[inputIOIndex].token = address(takerOutput);
order.validOutputs[outputIOIndex].token = address(takerInput);
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));
Expand All @@ -87,9 +73,6 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
FlashLendingMockOrderBook ob = new FlashLendingMockOrderBook();
Mock0xProxy proxy = new Mock0xProxy();

Token takerInput = new Token();
Token takerOutput = new Token();

RouteProcessorOrderBookV3ArbOrderTaker arb =
RouteProcessorOrderBookV3ArbOrderTaker(Clones.clone(iImplementation));
arb.initialize(
Expand All @@ -102,10 +85,10 @@ contract RouteProcessorOrderBookV3ArbOrderTakerTest is ArbTest {
)
);

takerOutput.mint(address(arb), mintAmount);
iTakerOutput.mint(address(arb), mintAmount);

order.validInputs[inputIOIndex].token = address(takerOutput);
order.validOutputs[outputIOIndex].token = address(takerInput);
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));
Expand Down
13 changes: 13 additions & 0 deletions test/util/abstract/ArbTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ 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 "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {
constructor() ERC20("Token", "TKN") {}

function mint(address receiver, uint256 amount) external {
_mint(receiver, amount);
}
}

struct ArbTestConstructorConfig {
address deployer;
Expand All @@ -16,10 +25,14 @@ struct ArbTestConstructorConfig {
abstract contract ArbTest is Test {
address immutable iDeployer;
address immutable iImplementation;
Token immutable iTakerInput;
Token immutable iTakerOutput;

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

function buildConstructorConfig(string memory metaPath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;

string constant GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH = "meta/GenericPoolOrderBookV3ArbOrderTaker.rain.meta";
string constant GENERIC_POOL_ORDER_BOOK_V3_ARB_ORDER_TAKER_META_PATH =
"meta/GenericPoolOrderBookV3ArbOrderTaker.rain.meta";
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;

string constant GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_META_PATH = "meta/GenericPoolOrderBookV3FlashBorrower.rain.meta";
string constant GENERIC_POOL_ORDER_BOOK_V3_FLASH_BORROWER_META_PATH =
"meta/GenericPoolOrderBookV3FlashBorrower.rain.meta";

0 comments on commit 3f0b6e1

Please sign in to comment.