Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
7 changed files
with
114 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
158211 | ||
138311 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Base-LimitOrderReactor-BaseExecuteSingleWithFee.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
154360 | ||
123620 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Base-LimitOrderReactor-ExecuteSingleNativeOutput.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
103419 | ||
123319 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |