feat: Support sushiswap v2 and pancakeswap v2 on ethereum

- Needed to take pool code init hash as input param for executors
- Added tests for ethereum. Will test base on-chain.
This commit is contained in:
TAMARA LIPOWSKI
2025-03-19 14:27:34 -04:00
parent 5a6433caf1
commit 0a8a34be03
5 changed files with 86 additions and 13 deletions

View File

@@ -5,13 +5,42 @@ const hre = require("hardhat");
// Comment out the executors you don't want to deploy
const executors_to_deploy = {
"ethereum":[
{exchange: "UniswapV2Executor", args: ["0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"]},
// Factory, Pool Init Code Hash
{exchange: "UniswapV2Executor", args: [
"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
]},
// Factory, Pool Init Code Hash
{exchange: "SushiSwapV2Executor", args: [
"0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac",
"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303"
]},
// Factory, Pool Init Code Hash
{exchange: "PancakeSwapV2Executor", args: [
"0x1097053Fd2ea711dad45caCcc45EfF7548fCB362",
"0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d"
]},
{exchange: "UniswapV3Executor", args: ["0x1F98431c8aD98523631AE4a59f267346ea31F984"]},
{exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
{exchange: "BalancerV2Executor", args: []},
],
"base":[
{exchange: "UniswapV2Executor", args: ["0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6"]},
// Factory, Pool Init Code Hash
{exchange: "UniswapV2Executor", args: [
"0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6",
"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
]},
// Factory, Pool Init Code Hash
{exchange: "SushiSwapV2Executor", args: [
"0x71524B4f93c58fcbF659783284E38825f0622859",
"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303"
]},
// Factory, Pool Init Code Hash
{exchange: "PancakeSwapV2Executor", args: [
"0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E",
"0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d"
]},
// Factory, Pool Init Code Hash
{exchange: "UniswapV3Executor", args: ["0x33128a8fC17869897dcE68Ed026d694621f6FDfD"]},
{exchange: "UniswapV4Executor", args: ["0x498581ff718922c3f8e6a244956af099b2652b2b"]},
{exchange: "BalancerV2Executor", args: []},

View File

@@ -8,21 +8,24 @@ import "@uniswap-v2/contracts/interfaces/IUniswapV2Pair.sol";
error UniswapV2Executor__InvalidDataLength();
error UniswapV2Executor__InvalidTarget();
error UniswapV2Executor__InvalidFactory();
error UniswapV2Executor__InvalidInitCode();
contract UniswapV2Executor is IExecutor {
using SafeERC20 for IERC20;
bytes32 internal constant POOL_INIT_CODE_HASH =
0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
address public immutable factory;
bytes32 public immutable init_code;
address private immutable self;
constructor(address _factory) {
constructor(address _factory, bytes32 _init_code) {
if (_factory == address(0)) {
revert UniswapV2Executor__InvalidFactory();
}
if (_init_code == bytes32(0)) {
revert UniswapV2Executor__InvalidInitCode();
}
factory = _factory;
init_code = _init_code;
self = address(this);
}
@@ -102,9 +105,7 @@ contract UniswapV2Executor is IExecutor {
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff", factory, salt, POOL_INIT_CODE_HASH
)
abi.encodePacked(hex"ff", factory, salt, init_code)
)
)
)

View File

@@ -47,9 +47,23 @@ contract Constants is Test, BaseConstants {
address USDC_WBTC_POOL = 0x004375Dff511095CC5A197A54140a24eFEF3A416;
address USDC_WETH_USV2 = 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc;
// Uniswap v3
// Sushiswap v2
address SUSHISWAP_WBTC_WETH_POOL =
0xCEfF51756c56CeFFCA006cD410B03FFC46dd3a58;
// Pancakeswap v2
address PANCAKESWAP_WBTC_WETH_POOL =
0x4AB6702B3Ed3877e9b1f203f90cbEF13d663B0e8;
// Factories
address USV3_FACTORY_ETHEREUM = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
address USV2_FACTORY_ETHEREUM = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
address SUSHISWAPV2_FACTORY_ETHEREUM =
0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac;
address PANCAKESWAPV2_FACTORY_ETHEREUM =
0x1097053Fd2ea711dad45caCcc45EfF7548fCB362;
// Uniswap v3
address DAI_WETH_USV3 = 0xC2e9F25Be6257c210d7Adf0D4Cd6E3E881ba25f8;
address USDC_WETH_USV3 = 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640; // 0.05% fee
address USDC_WETH_USV3_2 = 0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8; // 0.3% fee
@@ -60,6 +74,14 @@ contract Constants is Test, BaseConstants {
// Permit2
address PERMIT2_ADDRESS = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
// Pool Code Init Hashes
bytes32 USV2_POOL_CODE_INIT_HASH =
0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
bytes32 SUSHIV2_POOL_CODE_INIT_HASH =
0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303;
bytes32 PANCAKEV2_POOL_CODE_INIT_HASH =
0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d;
/**
* @dev Deploys a dummy contract with non-empty bytecode
*/

View File

@@ -46,6 +46,7 @@ contract TychoRouterTestSetup is Test, Constants {
vm.startPrank(ADMIN);
address factoryV3 = USV3_FACTORY_ETHEREUM;
address factoryV2 = USV2_FACTORY_ETHEREUM;
bytes32 initCodeV2 = USV2_POOL_CODE_INIT_HASH;
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
IPoolManager poolManager = IPoolManager(poolManagerAddress);
tychoRouter = new TychoRouterExposed(PERMIT2_ADDRESS, WETH_ADDR);
@@ -60,7 +61,7 @@ contract TychoRouterTestSetup is Test, Constants {
deployDummyContract();
vm.stopPrank();
usv2Executor = new UniswapV2Executor(factoryV2);
usv2Executor = new UniswapV2Executor(factoryV2, initCodeV2);
usv3Executor = new UniswapV3Executor(factoryV3);
usv4Executor = new UniswapV4Executor(poolManager);
vm.startPrank(EXECUTOR_SETTER);

View File

@@ -6,7 +6,9 @@ import {Test} from "../../lib/forge-std/src/Test.sol";
import {Constants} from "../Constants.sol";
contract UniswapV2ExecutorExposed is UniswapV2Executor {
constructor(address _factory) UniswapV2Executor(_factory) {}
constructor(address _factory, bytes32 _init_code)
UniswapV2Executor(_factory, _init_code)
{}
function decodeParams(bytes calldata data)
external
@@ -48,13 +50,23 @@ contract UniswapV2ExecutorTest is Test, Constants {
using SafeERC20 for IERC20;
UniswapV2ExecutorExposed uniswapV2Exposed;
UniswapV2ExecutorExposed sushiswapV2Exposed;
UniswapV2ExecutorExposed pancakeswapV2Exposed;
IERC20 WETH = IERC20(WETH_ADDR);
IERC20 DAI = IERC20(DAI_ADDR);
function setUp() public {
uint256 forkBlock = 17323404;
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
uniswapV2Exposed = new UniswapV2ExecutorExposed(USV2_FACTORY_ETHEREUM);
uniswapV2Exposed = new UniswapV2ExecutorExposed(
USV2_FACTORY_ETHEREUM, USV2_POOL_CODE_INIT_HASH
);
sushiswapV2Exposed = new UniswapV2ExecutorExposed(
SUSHISWAPV2_FACTORY_ETHEREUM, SUSHIV2_POOL_CODE_INIT_HASH
);
pancakeswapV2Exposed = new UniswapV2ExecutorExposed(
PANCAKESWAPV2_FACTORY_ETHEREUM, PANCAKEV2_POOL_CODE_INIT_HASH
);
}
function testDecodeParams() public view {
@@ -82,6 +94,14 @@ contract UniswapV2ExecutorTest is Test, Constants {
uniswapV2Exposed.verifyPairAddress(WETH_DAI_POOL);
}
function testVerifyPairAddressSushi() public view {
sushiswapV2Exposed.verifyPairAddress(SUSHISWAP_WBTC_WETH_POOL);
}
function testVerifyPairAddressPancake() public view {
pancakeswapV2Exposed.verifyPairAddress(PANCAKESWAP_WBTC_WETH_POOL);
}
function testInvalidTarget() public {
address fakePool = address(new FakeUniswapV2Pool(WETH_ADDR, DAI_ADDR));
vm.expectRevert(UniswapV2Executor__InvalidTarget.selector);