feat: Pancakeswap V3 support

This commit is contained in:
TAMARA LIPOWSKI
2025-03-21 11:26:41 -04:00
parent 59a5a558f5
commit d582543057
7 changed files with 82 additions and 12 deletions

View File

@@ -18,12 +18,14 @@ library CallbackValidationV2 {
address factory,
address tokenA,
address tokenB,
uint24 fee
uint24 fee,
bytes32 initCode
) internal view returns (IUniswapV3Pool pool) {
return
verifyCallback(
factory,
PoolAddressV2.getPoolKey(tokenA, tokenB, fee)
PoolAddressV2.getPoolKey(tokenA, tokenB, fee),
initCode
);
}
@@ -33,9 +35,10 @@ library CallbackValidationV2 {
/// @return pool The V3 pool contract address
function verifyCallback(
address factory,
PoolAddressV2.PoolKey memory poolKey
PoolAddressV2.PoolKey memory poolKey,
bytes32 initCode
) internal view returns (IUniswapV3Pool pool) {
pool = IUniswapV3Pool(PoolAddressV2.computeAddress(factory, poolKey));
pool = IUniswapV3Pool(PoolAddressV2.computeAddress(factory, poolKey, initCode));
require(msg.sender == address(pool), "CV");
}
}

View File

@@ -5,8 +5,6 @@ pragma solidity >=0.5.0;
/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddressV2 {
bytes32 internal constant POOL_INIT_CODE_HASH =
0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
/// @notice The identifying key of the pool
struct PoolKey {
@@ -33,7 +31,7 @@ library PoolAddressV2 {
/// @param factory The Uniswap V3 factory contract address
/// @param key The PoolKey
/// @return pool The contract address of the V3 pool
function computeAddress(address factory, PoolKey memory key)
function computeAddress(address factory, PoolKey memory key, bytes32 initCode)
internal
pure
returns (address pool)
@@ -49,7 +47,7 @@ library PoolAddressV2 {
keccak256(
abi.encode(key.token0, key.token1, key.fee)
),
POOL_INIT_CODE_HASH
initCode
)
)
)