Merge pull request #93 from propeller-heads/router/tnl/configurable-usv2-factory
fix: make USV2 factory configurable in Executor
This commit is contained in:
@@ -12,7 +12,10 @@
|
|||||||
"vm:balancer_v2": "0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"
|
"vm:balancer_v2": "0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"
|
||||||
},
|
},
|
||||||
"base": {
|
"base": {
|
||||||
"uniswap_v2": "0x2DaE954eCF457276F90B68Cee68981C0aA07f2ef"
|
"uniswap_v2": "0xa2D6c55676D0d2A1D090e3157aCC9a41bB53BE3B",
|
||||||
|
"uniswap_v3": "0x374fFd7224422dF5dE83B43C7Fa8379F9CAA826a",
|
||||||
|
"uniswap_v4": "0xf1531642018C9Ab6a1B07666755d975eae16a01b",
|
||||||
|
"vm:balancer_v2": "0x6920209CaAF45872006eC507f2f18595af030418"
|
||||||
},
|
},
|
||||||
"tenderly_base": {
|
"tenderly_base": {
|
||||||
"uniswap_v3": "0x7c7E06d7317e620a185078e236879D2a87fC8d22"
|
"uniswap_v3": "0x7c7E06d7317e620a185078e236879D2a87fC8d22"
|
||||||
|
|||||||
@@ -3,12 +3,21 @@ const {ethers} = require("hardhat");
|
|||||||
const hre = require("hardhat");
|
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 = {
|
||||||
{exchange: "UniswapV2Executor", args: []},
|
"ethereum":[
|
||||||
|
{exchange: "UniswapV2Executor", args: ["0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"]},
|
||||||
{exchange: "UniswapV3Executor", args: ["0x1F98431c8aD98523631AE4a59f267346ea31F984"]},
|
{exchange: "UniswapV3Executor", args: ["0x1F98431c8aD98523631AE4a59f267346ea31F984"]},
|
||||||
{exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
|
{exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
|
||||||
{exchange: "BalancerV2Executor", args: []},
|
{exchange: "BalancerV2Executor", args: []},
|
||||||
]
|
],
|
||||||
|
"base":[
|
||||||
|
{exchange: "UniswapV2Executor", args: ["0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6"]},
|
||||||
|
{exchange: "UniswapV3Executor", args: ["0x33128a8fC17869897dcE68Ed026d694621f6FDfD"]},
|
||||||
|
{exchange: "UniswapV4Executor", args: ["0x498581ff718922c3f8e6a244956af099b2652b2b"]},
|
||||||
|
{exchange: "BalancerV2Executor", args: []},
|
||||||
|
],
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const network = hre.network.name;
|
const network = hre.network.name;
|
||||||
@@ -18,7 +27,7 @@ async function main() {
|
|||||||
console.log(`Deploying with account: ${deployer.address}`);
|
console.log(`Deploying with account: ${deployer.address}`);
|
||||||
console.log(`Account balance: ${ethers.utils.formatEther(await deployer.getBalance())} ETH`);
|
console.log(`Account balance: ${ethers.utils.formatEther(await deployer.getBalance())} ETH`);
|
||||||
|
|
||||||
for (const executor of executors_to_deploy) {
|
for (const executor of executors_to_deploy[network]) {
|
||||||
const {exchange, args} = executor;
|
const {exchange, args} = executor;
|
||||||
const Executor = await ethers.getContractFactory(exchange);
|
const Executor = await ethers.getContractFactory(exchange);
|
||||||
const deployedExecutor = await Executor.deploy(...args);
|
const deployedExecutor = await Executor.deploy(...args);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import "@uniswap-v2/contracts/interfaces/IUniswapV2Pair.sol";
|
|||||||
|
|
||||||
error UniswapV2Executor__InvalidDataLength();
|
error UniswapV2Executor__InvalidDataLength();
|
||||||
error UniswapV2Executor__InvalidTarget();
|
error UniswapV2Executor__InvalidTarget();
|
||||||
|
error UniswapV2Executor__InvalidFactory();
|
||||||
|
|
||||||
contract UniswapV2Executor is IExecutor {
|
contract UniswapV2Executor is IExecutor {
|
||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
@@ -14,8 +15,16 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
bytes32 internal constant POOL_INIT_CODE_HASH =
|
bytes32 internal constant POOL_INIT_CODE_HASH =
|
||||||
0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
|
0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
|
||||||
|
|
||||||
address private constant FACTORY =
|
address public immutable factory;
|
||||||
0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
|
address private immutable self;
|
||||||
|
|
||||||
|
constructor(address _factory) {
|
||||||
|
if (_factory == address(0)) {
|
||||||
|
revert UniswapV2Executor__InvalidFactory();
|
||||||
|
}
|
||||||
|
factory = _factory;
|
||||||
|
self = address(this);
|
||||||
|
}
|
||||||
|
|
||||||
// slither-disable-next-line locked-ether
|
// slither-disable-next-line locked-ether
|
||||||
function swap(uint256 givenAmount, bytes calldata data)
|
function swap(uint256 givenAmount, bytes calldata data)
|
||||||
@@ -94,7 +103,7 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
uint256(
|
uint256(
|
||||||
keccak256(
|
keccak256(
|
||||||
abi.encodePacked(
|
abi.encodePacked(
|
||||||
hex"ff", FACTORY, salt, POOL_INIT_CODE_HASH
|
hex"ff", factory, salt, POOL_INIT_CODE_HASH
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ contract Constants is Test, BaseConstants {
|
|||||||
address USDC_WBTC_POOL = 0x004375Dff511095CC5A197A54140a24eFEF3A416;
|
address USDC_WBTC_POOL = 0x004375Dff511095CC5A197A54140a24eFEF3A416;
|
||||||
|
|
||||||
// uniswap v3
|
// uniswap v3
|
||||||
address USV3_FACTORY = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
|
address USV3_FACTORY_ETHEREUM = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
|
||||||
|
address USV2_FACTORY_ETHEREUM = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
|
||||||
address DAI_WETH_USV3 = 0xC2e9F25Be6257c210d7Adf0D4Cd6E3E881ba25f8;
|
address DAI_WETH_USV3 = 0xC2e9F25Be6257c210d7Adf0D4Cd6E3E881ba25f8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ 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;
|
address factoryV3 = USV3_FACTORY_ETHEREUM;
|
||||||
|
address factoryV2 = USV2_FACTORY_ETHEREUM;
|
||||||
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
||||||
IPoolManager poolManager = IPoolManager(poolManagerAddress);
|
IPoolManager poolManager = IPoolManager(poolManagerAddress);
|
||||||
tychoRouter = new TychoRouterExposed(permit2Address, WETH_ADDR);
|
tychoRouter = new TychoRouterExposed(permit2Address, WETH_ADDR);
|
||||||
@@ -60,7 +61,7 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
deployDummyContract();
|
deployDummyContract();
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|
||||||
usv2Executor = new UniswapV2Executor();
|
usv2Executor = new UniswapV2Executor(factoryV2);
|
||||||
usv3Executor = new UniswapV3Executor(factoryV3);
|
usv3Executor = new UniswapV3Executor(factoryV3);
|
||||||
usv4Executor = new UniswapV4Executor(poolManager);
|
usv4Executor = new UniswapV4Executor(poolManager);
|
||||||
vm.startPrank(EXECUTOR_SETTER);
|
vm.startPrank(EXECUTOR_SETTER);
|
||||||
|
|||||||
@@ -6,6 +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) UniswapV2Executor(_factory) {}
|
||||||
|
|
||||||
function decodeParams(bytes calldata data)
|
function decodeParams(bytes calldata data)
|
||||||
external
|
external
|
||||||
pure
|
pure
|
||||||
@@ -42,7 +44,7 @@ contract FakeUniswapV2Pool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
|
contract UniswapV2ExecutorTest is Test, Constants {
|
||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
UniswapV2ExecutorExposed uniswapV2Exposed;
|
UniswapV2ExecutorExposed uniswapV2Exposed;
|
||||||
@@ -52,7 +54,7 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
|
|||||||
function setUp() public {
|
function setUp() public {
|
||||||
uint256 forkBlock = 17323404;
|
uint256 forkBlock = 17323404;
|
||||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||||
uniswapV2Exposed = new UniswapV2ExecutorExposed();
|
uniswapV2Exposed = new UniswapV2ExecutorExposed(USV2_FACTORY_ETHEREUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDecodeParams() public view {
|
function testDecodeParams() public view {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ 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);
|
uniswapV3Exposed = new UniswapV3ExecutorExposed(USV3_FACTORY_ETHEREUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDecodeParams() public view {
|
function testDecodeParams() public view {
|
||||||
|
|||||||
Reference in New Issue
Block a user