feat: Pancakeswap V3 support
This commit is contained in:
@@ -753,6 +753,39 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
assertGe(finalBalance, expAmountOut);
|
||||
}
|
||||
|
||||
function testSwapSinglePancakeV3() public {
|
||||
// Trade 1 WETH for USDT with 1 swap on Pancakeswap V3
|
||||
// 1 WETH -> USDT
|
||||
// (PancakeV3)
|
||||
uint256 amountIn = 10 ** 18;
|
||||
deal(WETH_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
uint256 expAmountOut = 2659_567519; //Swap 1 WETH for 1205.12 DAI
|
||||
bool zeroForOne = true;
|
||||
bytes memory protocolData = encodeUniswapV3Swap(
|
||||
WETH_ADDR,
|
||||
USDT_ADDR,
|
||||
tychoRouterAddr,
|
||||
PANCAKESWAPV3_WETH_USDT_POOL,
|
||||
zeroForOne
|
||||
);
|
||||
bytes memory swap = encodeSwap(
|
||||
uint8(0),
|
||||
uint8(1),
|
||||
uint24(0),
|
||||
address(pancakev3Executor),
|
||||
protocolData
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](1);
|
||||
swaps[0] = swap;
|
||||
|
||||
tychoRouter.exposedSwap(amountIn, 2, pleEncode(swaps));
|
||||
|
||||
uint256 finalBalance = IERC20(USDT_ADDR).balanceOf(tychoRouterAddr);
|
||||
assertGe(finalBalance, expAmountOut);
|
||||
}
|
||||
|
||||
function testSwapSingleUSV3Permit2() public {
|
||||
// Trade 1 WETH for DAI with 1 swap on Uniswap V3 using Permit2
|
||||
// 1 WETH -> DAI
|
||||
|
||||
@@ -36,6 +36,7 @@ contract TychoRouterTestSetup is Test, Constants {
|
||||
address tychoRouterAddr;
|
||||
UniswapV2Executor public usv2Executor;
|
||||
UniswapV3Executor public usv3Executor;
|
||||
UniswapV3Executor public pancakev3Executor;
|
||||
UniswapV4Executor public usv4Executor;
|
||||
MockERC20[] tokens;
|
||||
|
||||
@@ -46,8 +47,10 @@ contract TychoRouterTestSetup is Test, Constants {
|
||||
vm.startPrank(ADMIN);
|
||||
address factoryV2 = USV2_FACTORY_ETHEREUM;
|
||||
address factoryV3 = USV3_FACTORY_ETHEREUM;
|
||||
address factoryPancakeV3 = PANCAKESWAPV3_DEPLOYER_ETHEREUM;
|
||||
bytes32 initCodeV2 = USV2_POOL_CODE_INIT_HASH;
|
||||
bytes32 initCodeV3 = USV3_POOL_CODE_INIT_HASH;
|
||||
bytes32 initCodePancakeV3 = PANCAKEV3_POOL_CODE_INIT_HASH;
|
||||
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
||||
IPoolManager poolManager = IPoolManager(poolManagerAddress);
|
||||
tychoRouter = new TychoRouterExposed(PERMIT2_ADDRESS, WETH_ADDR);
|
||||
@@ -65,11 +68,14 @@ contract TychoRouterTestSetup is Test, Constants {
|
||||
usv2Executor = new UniswapV2Executor(factoryV2, initCodeV2);
|
||||
usv3Executor = new UniswapV3Executor(factoryV3, initCodeV3);
|
||||
usv4Executor = new UniswapV4Executor(poolManager);
|
||||
pancakev3Executor =
|
||||
new UniswapV3Executor(factoryPancakeV3, initCodePancakeV3);
|
||||
vm.startPrank(EXECUTOR_SETTER);
|
||||
address[] memory executors = new address[](3);
|
||||
address[] memory executors = new address[](4);
|
||||
executors[0] = address(usv2Executor);
|
||||
executors[1] = address(usv3Executor);
|
||||
executors[2] = address(usv4Executor);
|
||||
executors[2] = address(pancakev3Executor);
|
||||
executors[3] = address(usv4Executor);
|
||||
tychoRouter.setExecutors(executors);
|
||||
vm.stopPrank();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user