chore: rename _computePairAddress to _verifyPairAddress, add fake v2 pool in v2 test file
This commit is contained in:
@@ -11,6 +11,9 @@ error UniswapV2Executor__InvalidTarget();
|
||||
contract UniswapV2Executor is IExecutor {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
bytes32 internal constant POOL_INIT_CODE_HASH =
|
||||
0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
|
||||
|
||||
address private constant FACTORY =
|
||||
0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
|
||||
|
||||
@@ -27,9 +30,8 @@ contract UniswapV2Executor is IExecutor {
|
||||
|
||||
(tokenIn, target, receiver, zeroForOne) = _decodeData(data);
|
||||
|
||||
if (target != _computePairAddress(target)) {
|
||||
revert UniswapV2Executor__InvalidTarget();
|
||||
}
|
||||
_verifyPairAddress(target);
|
||||
|
||||
calculatedAmount = _getAmountOut(target, givenAmount, zeroForOne);
|
||||
tokenIn.safeTransfer(target, givenAmount);
|
||||
|
||||
@@ -83,27 +85,23 @@ contract UniswapV2Executor is IExecutor {
|
||||
amount = numerator / denominator;
|
||||
}
|
||||
|
||||
function _computePairAddress(address target)
|
||||
internal
|
||||
view
|
||||
returns (address pair)
|
||||
{
|
||||
function _verifyPairAddress(address target) internal view {
|
||||
address token0 = IUniswapV2Pair(target).token0();
|
||||
address token1 = IUniswapV2Pair(target).token1();
|
||||
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
|
||||
pair = address(
|
||||
address pair = address(
|
||||
uint160(
|
||||
uint256(
|
||||
keccak256(
|
||||
abi.encodePacked(
|
||||
hex"ff",
|
||||
FACTORY,
|
||||
salt,
|
||||
hex"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
|
||||
hex"ff", FACTORY, salt, POOL_INIT_CODE_HASH
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
if (pair != target) {
|
||||
revert UniswapV2Executor__InvalidTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ error UniswapV3Executor__InvalidTarget();
|
||||
contract UniswapV3Executor is IExecutor, ICallback {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
bytes32 internal constant POOL_INIT_CODE_HASH =
|
||||
0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
|
||||
uint160 private constant MIN_SQRT_RATIO = 4295128739;
|
||||
uint160 private constant MAX_SQRT_RATIO =
|
||||
1461446703485210103287273052203988822378723970342;
|
||||
@@ -44,9 +46,7 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
||||
bool zeroForOne
|
||||
) = _decodeData(data);
|
||||
|
||||
if (target != _computePairAddress(tokenIn, tokenOut, fee)) {
|
||||
revert UniswapV3Executor__InvalidTarget();
|
||||
}
|
||||
_verifyPairAddress(tokenIn, tokenOut, fee, target);
|
||||
|
||||
int256 amount0;
|
||||
int256 amount1;
|
||||
@@ -153,14 +153,15 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
||||
);
|
||||
}
|
||||
|
||||
function _computePairAddress(address tokenA, address tokenB, uint24 fee)
|
||||
internal
|
||||
view
|
||||
returns (address pool)
|
||||
{
|
||||
function _verifyPairAddress(
|
||||
address tokenA,
|
||||
address tokenB,
|
||||
uint24 fee,
|
||||
address target
|
||||
) internal view {
|
||||
(address token0, address token1) =
|
||||
tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
|
||||
pool = address(
|
||||
address pool = address(
|
||||
uint160(
|
||||
uint256(
|
||||
keccak256(
|
||||
@@ -168,11 +169,14 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
||||
hex"ff",
|
||||
factory,
|
||||
keccak256(abi.encode(token0, token1, fee)),
|
||||
hex"e34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54"
|
||||
POOL_INIT_CODE_HASH
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
if (pool != target) {
|
||||
revert UniswapV3Executor__InvalidTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user