From ba4125da755ac8c391cf5cca13e30a7da722b5e5 Mon Sep 17 00:00:00 2001 From: Eric Zhong Date: Mon, 5 Aug 2024 11:40:49 -0400 Subject: [PATCH] feat: add priority order reactor deploy script and test (#265) * Add deploy script and test * Add salt * new salt * forge fmt --- script/DeployPriorityOrderReactor.s.sol | 42 +++++++++++++ test/script/DeployPriorityOrderReactor.t.sol | 64 ++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 script/DeployPriorityOrderReactor.s.sol create mode 100644 test/script/DeployPriorityOrderReactor.t.sol diff --git a/script/DeployPriorityOrderReactor.s.sol b/script/DeployPriorityOrderReactor.s.sol new file mode 100644 index 00000000..8c44fa84 --- /dev/null +++ b/script/DeployPriorityOrderReactor.s.sol @@ -0,0 +1,42 @@ +// 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 {PriorityOrderReactor} from "../src/reactors/PriorityOrderReactor.sol"; +import {OrderQuoter} from "../src/lens/OrderQuoter.sol"; +import {DeployPermit2} from "../test/util/DeployPermit2.sol"; + +struct PriorityOrderReactorDeployment { + IPermit2 permit2; + PriorityOrderReactor reactor; + OrderQuoter quoter; +} + +contract DeployPriorityOrderReactor is Script, DeployPermit2 { + address constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; + address constant UNI_TIMELOCK = 0x1a9C8182C09F50C8318d769245beA52c32BE35BC; + + function setUp() public {} + + function run() public returns (PriorityOrderReactorDeployment memory deployment) { + vm.startBroadcast(); + if (PERMIT2.code.length == 0) { + deployPermit2(); + } + + // will deploy to: 0x00000000e990A30496431710d6B58384a603b45c + PriorityOrderReactor reactor = new PriorityOrderReactor{ + salt: 0xee73c108815b7b841a11030c53600e3a1d8a5dd2d42966e386e5107a3da56e81 + }(IPermit2(PERMIT2), UNI_TIMELOCK); + console2.log("Reactor", address(reactor)); + + OrderQuoter quoter = new OrderQuoter{salt: 0x00}(); + console2.log("Quoter", address(quoter)); + + vm.stopBroadcast(); + + return PriorityOrderReactorDeployment(IPermit2(PERMIT2), reactor, quoter); + } +} diff --git a/test/script/DeployPriorityOrderReactor.t.sol b/test/script/DeployPriorityOrderReactor.t.sol new file mode 100644 index 00000000..101fa934 --- /dev/null +++ b/test/script/DeployPriorityOrderReactor.t.sol @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity ^0.8.19; + +import {Test} from "forge-std/Test.sol"; +import { + PriorityOrderReactorDeployment, DeployPriorityOrderReactor +} from "../../script/DeployPriorityOrderReactor.s.sol"; +import {PermitSignature} from "../util/PermitSignature.sol"; +import {OrderInfo, InputToken, ResolvedOrder} from "../../src/base/ReactorStructs.sol"; +import {OrderInfoBuilder} from "../util/OrderInfoBuilder.sol"; +import {PriorityOrderReactor} from "../../src/reactors/PriorityOrderReactor.sol"; +import {PriorityOrder, PriorityInput, PriorityOutput, PriorityCosignerData} from "../../src/lib/PriorityOrderLib.sol"; +import {MockERC20} from "../../test/util/mock/MockERC20.sol"; + +contract DeployPriorityOrderReactorTest is Test, PermitSignature { + using OrderInfoBuilder for OrderInfo; + + DeployPriorityOrderReactor deployer; + MockERC20 tokenIn; + MockERC20 tokenOut; + uint256 constant ONE = 10 ** 18; + + function setUp() public { + deployer = new DeployPriorityOrderReactor(); + tokenIn = new MockERC20{salt: 0x00}("Token A", "TA", 18); + tokenOut = new MockERC20{salt: 0x00}("Token B", "TB", 18); + } + + function testDeploy() public { + PriorityOrderReactorDeployment 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(PriorityOrderReactorDeployment memory deployment) public { + uint256 swapperPrivateKey = 0x12341234; + address swapper = vm.addr(swapperPrivateKey); + + tokenIn.mint(address(swapper), ONE); + tokenIn.forceApprove(swapper, address(deployment.permit2), ONE); + PriorityOutput[] memory priorityOutputs = new PriorityOutput[](1); + priorityOutputs[0] = PriorityOutput(address(tokenOut), ONE, 1, address(0)); + PriorityOrder memory order = PriorityOrder({ + info: OrderInfoBuilder.init(address(deployment.reactor)).withSwapper(address(swapper)), + cosigner: address(0), + auctionStartBlock: block.number, + baselinePriorityFeeWei: 0, + input: PriorityInput({token: tokenIn, amount: ONE, mpsPerPriorityFeeWei: 0}), + outputs: priorityOutputs, + cosignerData: PriorityCosignerData({auctionTargetBlock: block.number}), + cosignature: bytes("") + }); + 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); + } +}