Skip to content

Commit

Permalink
feat: add priority order reactor deploy script and test (#265)
Browse files Browse the repository at this point in the history
* Add deploy script and test

* Add salt

* new salt

* forge fmt
  • Loading branch information
zhongeric authored Aug 5, 2024
1 parent 9fefbea commit ba4125d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
42 changes: 42 additions & 0 deletions script/DeployPriorityOrderReactor.s.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
64 changes: 64 additions & 0 deletions test/script/DeployPriorityOrderReactor.t.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit ba4125d

Please sign in to comment.