feat: Support Pancakeswap v3 on ethereum
- Needed to take pool code init hash as input param for executors - Added tests for ethereum. Will test base on-chain. - Important note: Pancakeswap uses their deployer instead of their factory (this is a different address) for target verification.
This commit is contained in:
@@ -5,43 +5,62 @@ const hre = require("hardhat");
|
|||||||
// Comment out the executors you don't want to deploy
|
// Comment out the executors you don't want to deploy
|
||||||
const executors_to_deploy = {
|
const executors_to_deploy = {
|
||||||
"ethereum":[
|
"ethereum":[
|
||||||
// Factory, Pool Init Code Hash
|
// Args: Factory, Pool Init Code Hash
|
||||||
{exchange: "UniswapV2Executor", args: [
|
{exchange: "UniswapV2Executor", args: [
|
||||||
"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
|
"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
|
||||||
"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
|
"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
|
||||||
]},
|
]},
|
||||||
// Factory, Pool Init Code Hash
|
// Args: Factory, Pool Init Code Hash
|
||||||
{exchange: "SushiSwapV2Executor", args: [
|
{exchange: "SushiSwapV2Executor", args: [
|
||||||
"0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac",
|
"0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac",
|
||||||
"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303"
|
"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303"
|
||||||
]},
|
]},
|
||||||
// Factory, Pool Init Code Hash
|
// Args: Factory, Pool Init Code Hash
|
||||||
{exchange: "PancakeSwapV2Executor", args: [
|
{exchange: "PancakeSwapV2Executor", args: [
|
||||||
"0x1097053Fd2ea711dad45caCcc45EfF7548fCB362",
|
"0x1097053Fd2ea711dad45caCcc45EfF7548fCB362",
|
||||||
"0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d"
|
"0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d"
|
||||||
]},
|
]},
|
||||||
{exchange: "UniswapV3Executor", args: ["0x1F98431c8aD98523631AE4a59f267346ea31F984"]},
|
// Args: Factory, Pool Init Code Hash
|
||||||
|
{exchange: "UniswapV3Executor", args: [
|
||||||
|
"0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
||||||
|
"0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54"
|
||||||
|
]},
|
||||||
|
// Args: Deployer, Pool Init Code Hash
|
||||||
|
{exchange: "PancakeSwapV3Executor", args: [
|
||||||
|
"0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9 ",
|
||||||
|
"0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2"
|
||||||
|
]},
|
||||||
|
// Args: Pool manager
|
||||||
{exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
|
{exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
|
||||||
{exchange: "BalancerV2Executor", args: []},
|
{exchange: "BalancerV2Executor", args: []},
|
||||||
],
|
],
|
||||||
"base":[
|
"base":[
|
||||||
// Factory, Pool Init Code Hash
|
// Args: Factory, Pool Init Code Hash
|
||||||
{exchange: "UniswapV2Executor", args: [
|
{exchange: "UniswapV2Executor", args: [
|
||||||
"0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6",
|
"0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6",
|
||||||
"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
|
"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
|
||||||
]},
|
]},
|
||||||
// Factory, Pool Init Code Hash
|
// Args: Factory, Pool Init Code Hash
|
||||||
{exchange: "SushiSwapV2Executor", args: [
|
{exchange: "SushiSwapV2Executor", args: [
|
||||||
"0x71524B4f93c58fcbF659783284E38825f0622859",
|
"0x71524B4f93c58fcbF659783284E38825f0622859",
|
||||||
"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303"
|
"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303"
|
||||||
]},
|
]},
|
||||||
// Factory, Pool Init Code Hash
|
// Args: Factory, Pool Init Code Hash
|
||||||
{exchange: "PancakeSwapV2Executor", args: [
|
{exchange: "PancakeSwapV2Executor", args: [
|
||||||
"0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E",
|
"0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E",
|
||||||
"0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d"
|
"0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d"
|
||||||
]},
|
]},
|
||||||
// Factory, Pool Init Code Hash
|
// Args: Factory, Pool Init Code Hash
|
||||||
{exchange: "UniswapV3Executor", args: ["0x33128a8fC17869897dcE68Ed026d694621f6FDfD"]},
|
{exchange: "UniswapV3Executor", args: [
|
||||||
|
"0x33128a8fC17869897dcE68Ed026d694621f6FDfD",
|
||||||
|
"0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54"
|
||||||
|
]},
|
||||||
|
// Args: Deployer, Pool Init Code Hash
|
||||||
|
{exchange: "PancakeSwapV3Executor", args: [
|
||||||
|
"0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9 ",
|
||||||
|
"0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2"
|
||||||
|
]},
|
||||||
|
// Args: Pool manager
|
||||||
{exchange: "UniswapV4Executor", args: ["0x498581ff718922c3f8e6a244956af099b2652b2b"]},
|
{exchange: "UniswapV4Executor", args: ["0x498581ff718922c3f8e6a244956af099b2652b2b"]},
|
||||||
{exchange: "BalancerV2Executor", args: []},
|
{exchange: "BalancerV2Executor", args: []},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -14,18 +14,18 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
address public immutable factory;
|
address public immutable factory;
|
||||||
bytes32 public immutable init_code;
|
bytes32 public immutable initCode;
|
||||||
address private immutable self;
|
address private immutable self;
|
||||||
|
|
||||||
constructor(address _factory, bytes32 _init_code) {
|
constructor(address _factory, bytes32 _initCode) {
|
||||||
if (_factory == address(0)) {
|
if (_factory == address(0)) {
|
||||||
revert UniswapV2Executor__InvalidFactory();
|
revert UniswapV2Executor__InvalidFactory();
|
||||||
}
|
}
|
||||||
if (_init_code == bytes32(0)) {
|
if (_initCode == bytes32(0)) {
|
||||||
revert UniswapV2Executor__InvalidInitCode();
|
revert UniswapV2Executor__InvalidInitCode();
|
||||||
}
|
}
|
||||||
factory = _factory;
|
factory = _factory;
|
||||||
init_code = _init_code;
|
initCode = _initCode;
|
||||||
self = address(this);
|
self = address(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
uint160(
|
uint160(
|
||||||
uint256(
|
uint256(
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encodePacked(hex"ff", factory, salt, init_code)
|
abi.encodePacked(hex"ff", factory, salt, initCode)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,24 +10,28 @@ import "@interfaces/ICallback.sol";
|
|||||||
error UniswapV3Executor__InvalidDataLength();
|
error UniswapV3Executor__InvalidDataLength();
|
||||||
error UniswapV3Executor__InvalidFactory();
|
error UniswapV3Executor__InvalidFactory();
|
||||||
error UniswapV3Executor__InvalidTarget();
|
error UniswapV3Executor__InvalidTarget();
|
||||||
|
error UniswapV3Executor__InvalidInitCode();
|
||||||
|
|
||||||
contract UniswapV3Executor is IExecutor, ICallback {
|
contract UniswapV3Executor is IExecutor, ICallback {
|
||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
bytes32 internal constant POOL_INIT_CODE_HASH =
|
|
||||||
0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
|
|
||||||
uint160 private constant MIN_SQRT_RATIO = 4295128739;
|
uint160 private constant MIN_SQRT_RATIO = 4295128739;
|
||||||
uint160 private constant MAX_SQRT_RATIO =
|
uint160 private constant MAX_SQRT_RATIO =
|
||||||
1461446703485210103287273052203988822378723970342;
|
1461446703485210103287273052203988822378723970342;
|
||||||
|
|
||||||
address public immutable factory;
|
address public immutable factory;
|
||||||
|
bytes32 public immutable initCode;
|
||||||
address private immutable self;
|
address private immutable self;
|
||||||
|
|
||||||
constructor(address _factory) {
|
constructor(address _factory, bytes32 _initCode) {
|
||||||
if (_factory == address(0)) {
|
if (_factory == address(0)) {
|
||||||
revert UniswapV3Executor__InvalidFactory();
|
revert UniswapV3Executor__InvalidFactory();
|
||||||
}
|
}
|
||||||
|
if (_initCode == bytes32(0)) {
|
||||||
|
revert UniswapV3Executor__InvalidInitCode();
|
||||||
|
}
|
||||||
factory = _factory;
|
factory = _factory;
|
||||||
|
initCode = _initCode;
|
||||||
self = address(this);
|
self = address(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +171,7 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
|||||||
hex"ff",
|
hex"ff",
|
||||||
factory,
|
factory,
|
||||||
keccak256(abi.encode(token0, token1, fee)),
|
keccak256(abi.encode(token0, token1, fee)),
|
||||||
POOL_INIT_CODE_HASH
|
initCode
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -55,6 +55,15 @@ contract Constants is Test, BaseConstants {
|
|||||||
address PANCAKESWAP_WBTC_WETH_POOL =
|
address PANCAKESWAP_WBTC_WETH_POOL =
|
||||||
0x4AB6702B3Ed3877e9b1f203f90cbEF13d663B0e8;
|
0x4AB6702B3Ed3877e9b1f203f90cbEF13d663B0e8;
|
||||||
|
|
||||||
|
// Uniswap v3
|
||||||
|
address DAI_WETH_USV3 = 0xC2e9F25Be6257c210d7Adf0D4Cd6E3E881ba25f8;
|
||||||
|
address USDC_WETH_USV3 = 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640; // 0.05% fee
|
||||||
|
address USDC_WETH_USV3_2 = 0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8; // 0.3% fee
|
||||||
|
|
||||||
|
// Pancakeswap v3
|
||||||
|
address PANCAKESWAPV3_WETH_USDT_POOL =
|
||||||
|
0x6CA298D2983aB03Aa1dA7679389D955A4eFEE15C;
|
||||||
|
|
||||||
// Factories
|
// Factories
|
||||||
address USV3_FACTORY_ETHEREUM = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
|
address USV3_FACTORY_ETHEREUM = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
|
||||||
address USV2_FACTORY_ETHEREUM = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
|
address USV2_FACTORY_ETHEREUM = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
|
||||||
@@ -63,10 +72,9 @@ contract Constants is Test, BaseConstants {
|
|||||||
address PANCAKESWAPV2_FACTORY_ETHEREUM =
|
address PANCAKESWAPV2_FACTORY_ETHEREUM =
|
||||||
0x1097053Fd2ea711dad45caCcc45EfF7548fCB362;
|
0x1097053Fd2ea711dad45caCcc45EfF7548fCB362;
|
||||||
|
|
||||||
// Uniswap v3
|
// Pancakeswap uses their deployer instead of their factory for target verification
|
||||||
address DAI_WETH_USV3 = 0xC2e9F25Be6257c210d7Adf0D4Cd6E3E881ba25f8;
|
address PANCAKESWAPV3_DEPLOYER_ETHEREUM =
|
||||||
address USDC_WETH_USV3 = 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640; // 0.05% fee
|
0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9;
|
||||||
address USDC_WETH_USV3_2 = 0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8; // 0.3% fee
|
|
||||||
|
|
||||||
// Uniswap universal router
|
// Uniswap universal router
|
||||||
address UNIVERSAL_ROUTER = 0x66a9893cC07D91D95644AEDD05D03f95e1dBA8Af;
|
address UNIVERSAL_ROUTER = 0x66a9893cC07D91D95644AEDD05D03f95e1dBA8Af;
|
||||||
@@ -77,10 +85,14 @@ contract Constants is Test, BaseConstants {
|
|||||||
// Pool Code Init Hashes
|
// Pool Code Init Hashes
|
||||||
bytes32 USV2_POOL_CODE_INIT_HASH =
|
bytes32 USV2_POOL_CODE_INIT_HASH =
|
||||||
0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
|
0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
|
||||||
|
bytes32 USV3_POOL_CODE_INIT_HASH =
|
||||||
|
0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
|
||||||
bytes32 SUSHIV2_POOL_CODE_INIT_HASH =
|
bytes32 SUSHIV2_POOL_CODE_INIT_HASH =
|
||||||
0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303;
|
0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303;
|
||||||
bytes32 PANCAKEV2_POOL_CODE_INIT_HASH =
|
bytes32 PANCAKEV2_POOL_CODE_INIT_HASH =
|
||||||
0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d;
|
0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d;
|
||||||
|
bytes32 PANCAKEV3_POOL_CODE_INIT_HASH =
|
||||||
|
0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Deploys a dummy contract with non-empty bytecode
|
* @dev Deploys a dummy contract with non-empty bytecode
|
||||||
|
|||||||
@@ -44,9 +44,10 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||||
|
|
||||||
vm.startPrank(ADMIN);
|
vm.startPrank(ADMIN);
|
||||||
address factoryV3 = USV3_FACTORY_ETHEREUM;
|
|
||||||
address factoryV2 = USV2_FACTORY_ETHEREUM;
|
address factoryV2 = USV2_FACTORY_ETHEREUM;
|
||||||
|
address factoryV3 = USV3_FACTORY_ETHEREUM;
|
||||||
bytes32 initCodeV2 = USV2_POOL_CODE_INIT_HASH;
|
bytes32 initCodeV2 = USV2_POOL_CODE_INIT_HASH;
|
||||||
|
bytes32 initCodeV3 = USV3_POOL_CODE_INIT_HASH;
|
||||||
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
||||||
IPoolManager poolManager = IPoolManager(poolManagerAddress);
|
IPoolManager poolManager = IPoolManager(poolManagerAddress);
|
||||||
tychoRouter = new TychoRouterExposed(PERMIT2_ADDRESS, WETH_ADDR);
|
tychoRouter = new TychoRouterExposed(PERMIT2_ADDRESS, WETH_ADDR);
|
||||||
@@ -62,7 +63,7 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|
||||||
usv2Executor = new UniswapV2Executor(factoryV2, initCodeV2);
|
usv2Executor = new UniswapV2Executor(factoryV2, initCodeV2);
|
||||||
usv3Executor = new UniswapV3Executor(factoryV3);
|
usv3Executor = new UniswapV3Executor(factoryV3, initCodeV3);
|
||||||
usv4Executor = new UniswapV4Executor(poolManager);
|
usv4Executor = new UniswapV4Executor(poolManager);
|
||||||
vm.startPrank(EXECUTOR_SETTER);
|
vm.startPrank(EXECUTOR_SETTER);
|
||||||
address[] memory executors = new address[](3);
|
address[] memory executors = new address[](3);
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import {Test} from "../../lib/forge-std/src/Test.sol";
|
|||||||
import {Constants} from "../Constants.sol";
|
import {Constants} from "../Constants.sol";
|
||||||
|
|
||||||
contract UniswapV2ExecutorExposed is UniswapV2Executor {
|
contract UniswapV2ExecutorExposed is UniswapV2Executor {
|
||||||
constructor(address _factory, bytes32 _init_code)
|
constructor(address _factory, bytes32 _initCode)
|
||||||
UniswapV2Executor(_factory, _init_code)
|
UniswapV2Executor(_factory, _initCode)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
function decodeParams(bytes calldata data)
|
function decodeParams(bytes calldata data)
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import {Test} from "../../lib/forge-std/src/Test.sol";
|
|||||||
import {Constants} from "../Constants.sol";
|
import {Constants} from "../Constants.sol";
|
||||||
|
|
||||||
contract UniswapV3ExecutorExposed is UniswapV3Executor {
|
contract UniswapV3ExecutorExposed is UniswapV3Executor {
|
||||||
constructor(address _factory) UniswapV3Executor(_factory) {}
|
constructor(address _factory, bytes32 _initCode)
|
||||||
|
UniswapV3Executor(_factory, _initCode)
|
||||||
|
{}
|
||||||
|
|
||||||
function decodeData(bytes calldata data)
|
function decodeData(bytes calldata data)
|
||||||
external
|
external
|
||||||
@@ -37,6 +39,7 @@ contract UniswapV3ExecutorTest is Test, Constants {
|
|||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
UniswapV3ExecutorExposed uniswapV3Exposed;
|
UniswapV3ExecutorExposed uniswapV3Exposed;
|
||||||
|
UniswapV3ExecutorExposed pancakeV3Exposed;
|
||||||
IERC20 WETH = IERC20(WETH_ADDR);
|
IERC20 WETH = IERC20(WETH_ADDR);
|
||||||
IERC20 DAI = IERC20(DAI_ADDR);
|
IERC20 DAI = IERC20(DAI_ADDR);
|
||||||
|
|
||||||
@@ -44,7 +47,12 @@ contract UniswapV3ExecutorTest is Test, Constants {
|
|||||||
uint256 forkBlock = 17323404;
|
uint256 forkBlock = 17323404;
|
||||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||||
|
|
||||||
uniswapV3Exposed = new UniswapV3ExecutorExposed(USV3_FACTORY_ETHEREUM);
|
uniswapV3Exposed = new UniswapV3ExecutorExposed(
|
||||||
|
USV3_FACTORY_ETHEREUM, USV3_POOL_CODE_INIT_HASH
|
||||||
|
);
|
||||||
|
pancakeV3Exposed = new UniswapV3ExecutorExposed(
|
||||||
|
PANCAKESWAPV3_DEPLOYER_ETHEREUM, PANCAKEV3_POOL_CODE_INIT_HASH
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDecodeParams() public view {
|
function testDecodeParams() public view {
|
||||||
@@ -84,6 +92,12 @@ contract UniswapV3ExecutorTest is Test, Constants {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testVerifyPairAddressPancake() public view {
|
||||||
|
pancakeV3Exposed.verifyPairAddress(
|
||||||
|
WETH_ADDR, USDT_ADDR, 500, PANCAKESWAPV3_WETH_USDT_POOL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function testUSV3Callback() public {
|
function testUSV3Callback() public {
|
||||||
uint24 poolFee = 3000;
|
uint24 poolFee = 3000;
|
||||||
uint256 amountOwed = 1000000000000000000;
|
uint256 amountOwed = 1000000000000000000;
|
||||||
|
|||||||
Reference in New Issue
Block a user