Skip to content

Commit

Permalink
Deploy exclusive reactor 2 (#161)
Browse files Browse the repository at this point in the history
* write DeployExclusiveDutchLimit.s.sol

Signed-off-by: Allen Lin <allenlin1992@hotmail.com>

* write test

Signed-off-by: Allen Lin <allenlin1992@hotmail.com>

* fix some typing

Signed-off-by: Allen Lin <allenlin1992@hotmail.com>

* update snapshots

Signed-off-by: Allen Lin <allenlin1992@hotmail.com>

* renaming and interface change

Signed-off-by: Allen Lin <allenlin1992@hotmail.com>

* move the mock tokens out of the deploy scripts

Signed-off-by: Allen Lin <allenlin1992@hotmail.com>

---------

Signed-off-by: Allen Lin <allenlin1992@hotmail.com>
  • Loading branch information
azflin committed Jun 23, 2023
1 parent b29bcf2 commit 597cf61
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 17 deletions.
@@ -1 +1 @@
158211
138311
@@ -1 +1 @@
154360
123620
@@ -1 +1 @@
103419
123319
9 changes: 1 addition & 8 deletions script/DeployDutch.s.sol
Expand Up @@ -13,8 +13,6 @@ struct DutchDeployment {
IPermit2 permit2;
DutchOrderReactor reactor;
OrderQuoter quoter;
MockERC20 tokenIn;
MockERC20 tokenOut;
}

contract DeployDutch is Script, DeployPermit2 {
Expand All @@ -35,13 +33,8 @@ contract DeployDutch is Script, DeployPermit2 {
OrderQuoter quoter = new OrderQuoter{salt: 0x00}();
console2.log("Quoter", address(quoter));

MockERC20 tokenIn = new MockERC20{salt: 0x00}("Token A", "TA", 18);
console2.log("tokenA", address(tokenIn));
MockERC20 tokenOut = new MockERC20{salt: 0x00}("Token B", "TB", 18);
console2.log("tokenB", address(tokenOut));

vm.stopBroadcast();

return DutchDeployment(PERMIT2, reactor, quoter, tokenIn, tokenOut);
return DutchDeployment(PERMIT2, reactor, quoter);
}
}
39 changes: 39 additions & 0 deletions script/DeployExclusiveDutch.s.sol
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.13;

import "forge-std/console2.sol";
import "forge-std/Script.sol";
import {IPermit2} from "permit2/src/interfaces/IPermit2.sol";
import {ExclusiveDutchOrderReactor} from "../src/reactors/ExclusiveDutchOrderReactor.sol";
import {OrderQuoter} from "../src/lens/OrderQuoter.sol";
import {DeployPermit2} from "../test/util/DeployPermit2.sol";

struct ExclusiveDutchDeployment {
IPermit2 permit2;
ExclusiveDutchOrderReactor reactor;
OrderQuoter quoter;
}

contract DeployExclusiveDutch is Script, DeployPermit2 {
address constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
address constant UNI_TIMELOCK = 0x1a9C8182C09F50C8318d769245beA52c32BE35BC;

function setUp() public {}

function run() public returns (ExclusiveDutchDeployment memory deployment) {
vm.startBroadcast();
if (PERMIT2.code.length == 0) {
deployPermit2();
}

ExclusiveDutchOrderReactor reactor = new ExclusiveDutchOrderReactor{salt: 0x00}(IPermit2(PERMIT2), UNI_TIMELOCK);
console2.log("Reactor", address(reactor));

OrderQuoter quoter = new OrderQuoter{salt: 0x00}();
console2.log("Quoter", address(quoter));

vm.stopBroadcast();

return ExclusiveDutchDeployment(IPermit2(PERMIT2), reactor, quoter);
}
}
Expand Up @@ -7,15 +7,20 @@ import {PermitSignature} from "../util/PermitSignature.sol";
import {OrderInfo, InputToken, ResolvedOrder} from "../../src/base/ReactorStructs.sol";
import {OrderInfoBuilder} from "../util/OrderInfoBuilder.sol";
import {DutchOrder, DutchOutput, DutchInput} from "../../src/reactors/DutchOrderReactor.sol";
import {MockERC20} from "../../test/util/mock/MockERC20.sol";

contract DeployDutchTest is Test, PermitSignature {
using OrderInfoBuilder for OrderInfo;

DeployDutch deployer;
MockERC20 tokenIn;
MockERC20 tokenOut;
uint256 constant ONE = 10 ** 18;

function setUp() public {
deployer = new DeployDutch();
tokenIn = new MockERC20{salt: 0x00}("Token A", "TA", 18);
tokenOut = new MockERC20{salt: 0x00}("Token B", "TB", 18);
}

function testDeploy() public {
Expand All @@ -31,23 +36,23 @@ contract DeployDutchTest is Test, PermitSignature {
uint256 swapperPrivateKey = 0x12341234;
address swapper = vm.addr(swapperPrivateKey);

deployment.tokenIn.mint(address(swapper), ONE);
deployment.tokenIn.forceApprove(swapper, address(deployment.permit2), ONE);
tokenIn.mint(address(swapper), ONE);
tokenIn.forceApprove(swapper, address(deployment.permit2), ONE);
DutchOutput[] memory dutchOutputs = new DutchOutput[](1);
dutchOutputs[0] = DutchOutput(address(deployment.tokenOut), ONE, ONE * 9 / 10, address(0));
dutchOutputs[0] = DutchOutput(address(tokenOut), ONE, ONE * 9 / 10, address(0));
DutchOrder memory order = DutchOrder({
info: OrderInfoBuilder.init(address(deployment.reactor)).withSwapper(address(swapper)),
decayStartTime: block.timestamp,
decayEndTime: block.timestamp + 100,
input: DutchInput(deployment.tokenIn, ONE, ONE),
input: DutchInput(tokenIn, ONE, ONE),
outputs: dutchOutputs
});
bytes memory sig = signOrder(swapperPrivateKey, address(deployment.permit2), order);
ResolvedOrder memory quote = deployment.quoter.quote(abi.encode(order), sig);

assertEq(address(quote.input.token), address(deployment.tokenIn));
assertEq(address(quote.input.token), address(tokenIn));
assertEq(quote.input.amount, ONE);
assertEq(quote.outputs[0].token, address(deployment.tokenOut));
assertEq(quote.outputs[0].token, address(tokenOut));
assertEq(quote.outputs[0].amount, ONE);
}
}
60 changes: 60 additions & 0 deletions test/script/DeployExclusiveDutch.t.sol
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;

import {Test} from "forge-std/Test.sol";
import {ExclusiveDutchDeployment, DeployExclusiveDutch} from "../../script/DeployExclusiveDutch.s.sol";
import {PermitSignature} from "../util/PermitSignature.sol";
import {OrderInfo, InputToken, ResolvedOrder} from "../../src/base/ReactorStructs.sol";
import {OrderInfoBuilder} from "../util/OrderInfoBuilder.sol";
import {ExclusiveDutchOrder, DutchOutput, DutchInput} from "../../src/reactors/ExclusiveDutchOrderReactor.sol";
import {MockERC20} from "../../test/util/mock/MockERC20.sol";

contract DeployExclusiveDutchTest is Test, PermitSignature {
using OrderInfoBuilder for OrderInfo;

DeployExclusiveDutch deployer;
MockERC20 tokenIn;
MockERC20 tokenOut;
uint256 constant ONE = 10 ** 18;

function setUp() public {
deployer = new DeployExclusiveDutch();
tokenIn = new MockERC20{salt: 0x00}("Token A", "TA", 18);
tokenOut = new MockERC20{salt: 0x00}("Token B", "TB", 18);
}

function testDeploy() public {
ExclusiveDutchDeployment memory deployment = deployer.run();

assertEq(address(deployment.reactor.permit2()), address(deployment.permit2));
quoteTest(deployment);
}

// running this against the deployment since it's a pretty good end-to-end test
// ensuring all of the contracts are properly set up and integrated with each other
function quoteTest(ExclusiveDutchDeployment memory deployment) public {
uint256 swapperPrivateKey = 0x12341234;
address swapper = vm.addr(swapperPrivateKey);

tokenIn.mint(address(swapper), ONE);
tokenIn.forceApprove(swapper, address(deployment.permit2), ONE);
DutchOutput[] memory dutchOutputs = new DutchOutput[](1);
dutchOutputs[0] = DutchOutput(address(tokenOut), ONE, ONE * 9 / 10, address(0));
ExclusiveDutchOrder memory order = ExclusiveDutchOrder({
info: OrderInfoBuilder.init(address(deployment.reactor)).withSwapper(address(swapper)),
decayStartTime: block.timestamp,
decayEndTime: block.timestamp + 100,
exclusiveFiller: address(0),
exclusivityOverrideBps: 0,
input: DutchInput(tokenIn, ONE, ONE),
outputs: dutchOutputs
});
bytes memory sig = signOrder(swapperPrivateKey, address(deployment.permit2), order);
ResolvedOrder memory quote = deployment.quoter.quote(abi.encode(order), sig);

assertEq(address(quote.input.token), address(tokenIn));
assertEq(quote.input.amount, ONE);
assertEq(quote.outputs[0].token, address(tokenOut));
assertEq(quote.outputs[0].amount, ONE);
}
}

0 comments on commit 597cf61

Please sign in to comment.