test: add permit2 tests for simple swaps in TychoRouter and GasTest
This commit is contained in:
@@ -30,8 +30,8 @@ contract GasTest is Commands, Test, Constants {
|
||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||
}
|
||||
|
||||
// Gas usage: 248717
|
||||
// TychoRouter:testSwapSimple costs 255123
|
||||
// Gas usage: 248511
|
||||
// TychoRouter:testSwapSimple costs 113647
|
||||
function testUniversalRouterUniswapV2() public {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
|
||||
@@ -49,8 +49,34 @@ contract GasTest is Commands, Test, Constants {
|
||||
universalRouter.execute(commands, inputs, block.timestamp + 1000);
|
||||
}
|
||||
|
||||
// Gas usage: 251900
|
||||
// TychoRouter:testSwapSingleUSV3 costs 264195
|
||||
// Gas usage: 296248
|
||||
// TychoRouter:testSwapSimplePermit2 costs 184993
|
||||
function testUniversalRouterUniswapV2Permit2() public {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
|
||||
bytes memory commands =
|
||||
abi.encodePacked(uint8(Commands.V2_SWAP_EXACT_IN));
|
||||
|
||||
address[] memory path = new address[](2);
|
||||
path[0] = WETH_ADDR;
|
||||
path[1] = DAI_ADDR;
|
||||
|
||||
bytes[] memory inputs = new bytes[](1);
|
||||
inputs[0] = abi.encode(BOB, amountIn, uint256(0), path, true);
|
||||
|
||||
deal(WETH_ADDR, address(this), amountIn);
|
||||
IERC20(WETH_ADDR).approve(PERMIT2_ADDRESS, amountIn);
|
||||
permit2.approve(
|
||||
WETH_ADDR,
|
||||
address(universalRouter),
|
||||
uint160(amountIn),
|
||||
uint48(block.timestamp + 1000)
|
||||
);
|
||||
universalRouter.execute(commands, inputs, block.timestamp + 1000);
|
||||
}
|
||||
|
||||
// Gas usage: 252003
|
||||
// TychoRouter:testSwapSingleUSV3 costs 126181
|
||||
function testUniversalRouterUniswapV3() public {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
|
||||
@@ -67,9 +93,34 @@ contract GasTest is Commands, Test, Constants {
|
||||
universalRouter.execute(commands, inputs, block.timestamp + 1000);
|
||||
}
|
||||
|
||||
// Gas usage: 299427
|
||||
// TychoRouter:testSwapSingleUSV4Callback costs 286025
|
||||
function testUniversalRouterUniswapV4() public {
|
||||
// Gas usage: 299036
|
||||
// TychoRouter:testSwapSingleUSV3Permit2 costs 192780
|
||||
function testUniversalRouterUniswapV3Permit2() public {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
|
||||
bytes memory commands =
|
||||
abi.encodePacked(uint8(Commands.V3_SWAP_EXACT_IN));
|
||||
|
||||
uint24 poolFee = 3000;
|
||||
bytes memory path = abi.encodePacked(WETH_ADDR, poolFee, DAI_ADDR);
|
||||
|
||||
bytes[] memory inputs = new bytes[](1);
|
||||
inputs[0] = abi.encode(BOB, amountIn, uint256(0), path, true);
|
||||
|
||||
deal(WETH_ADDR, address(this), amountIn);
|
||||
IERC20(WETH_ADDR).approve(PERMIT2_ADDRESS, amountIn);
|
||||
permit2.approve(
|
||||
WETH_ADDR,
|
||||
address(universalRouter),
|
||||
uint160(amountIn),
|
||||
uint48(block.timestamp + 1000)
|
||||
);
|
||||
universalRouter.execute(commands, inputs, block.timestamp + 1000);
|
||||
}
|
||||
|
||||
// Gas usage: 299523
|
||||
// TychoRouter:testSwapSingleUSV4CallbackPermit2 costs 217751
|
||||
function testUniversalRouterUniswapV4Permit2() public {
|
||||
uint128 amountIn = uint128(100 ether);
|
||||
uint128 amountOutMinimum = uint128(0);
|
||||
uint256 deadline = block.timestamp + 1000;
|
||||
|
||||
Reference in New Issue
Block a user