From afbb9b1448896018d1e6adda4efa47311c57d62c Mon Sep 17 00:00:00 2001 From: Peiqian Li Date: Sat, 23 Mar 2024 12:00:31 -0700 Subject: [PATCH] Move PoolKey struct to a separate .sol file and fix build errors. Fix lint. --- src/PoolAddress.sol | 8 +------- src/PoolAddressPancakeSwapV3.sol | 2 +- src/PoolKey.sol | 9 +++++++++ src/test/PoolAddressPancakeSwapV3Test.sol | 4 ++-- src/test/PoolAddressTest.sol | 4 ++-- src/test/interfaces/IPoolAddress.sol | 2 +- test/PoolAddress.t.sol | 12 ++---------- 7 files changed, 18 insertions(+), 23 deletions(-) create mode 100644 src/PoolKey.sol diff --git a/src/PoolAddress.sol b/src/PoolAddress.sol index 3e35d2c..e5e0e01 100644 --- a/src/PoolAddress.sol +++ b/src/PoolAddress.sol @@ -1,15 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; +import "./PoolKey.sol"; import "./TernaryLib.sol"; -/// @notice The identifying key of the pool -struct PoolKey { - address token0; - address token1; - uint24 fee; -} - /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee /// @author Aperture Finance /// @author Modified from Uniswap (https://github.com/uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol) diff --git a/src/PoolAddressPancakeSwapV3.sol b/src/PoolAddressPancakeSwapV3.sol index 3047c19..ad7cb3f 100644 --- a/src/PoolAddressPancakeSwapV3.sol +++ b/src/PoolAddressPancakeSwapV3.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; -import "./PoolAddress.sol"; +import "./PoolKey.sol"; import "./TernaryLib.sol"; /// @title Provides functions for deriving a pool address from the deployer, tokens, and the fee diff --git a/src/PoolKey.sol b/src/PoolKey.sol new file mode 100644 index 0000000..47f92e9 --- /dev/null +++ b/src/PoolKey.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity >=0.5.0; + +/// @notice The identifying key of a liquidity pool +struct PoolKey { + address token0; + address token1; + uint24 fee; +} diff --git a/src/test/PoolAddressPancakeSwapV3Test.sol b/src/test/PoolAddressPancakeSwapV3Test.sol index 48ae5c9..9de6bab 100644 --- a/src/test/PoolAddressPancakeSwapV3Test.sol +++ b/src/test/PoolAddressPancakeSwapV3Test.sol @@ -11,7 +11,7 @@ contract PoolAddressPancakeSwapV3Test is IPoolAddress { address tokenA, address tokenB, uint24 fee - ) external pure override returns (IPoolKey memory key) { + ) external pure override returns (PoolKey memory key) { PoolAddress.PoolKey memory _key = PoolAddress.getPoolKey(tokenA, tokenB, fee); /// @solidity memory-safe-assembly assembly { @@ -19,7 +19,7 @@ contract PoolAddressPancakeSwapV3Test is IPoolAddress { } } - function computeAddress(address deployer, IPoolKey memory key) external pure override returns (address pool) { + function computeAddress(address deployer, PoolKey memory key) external pure override returns (address pool) { PoolAddress.PoolKey memory _key; /// @solidity memory-safe-assembly assembly { diff --git a/src/test/PoolAddressTest.sol b/src/test/PoolAddressTest.sol index 0759aa4..7872bf2 100644 --- a/src/test/PoolAddressTest.sol +++ b/src/test/PoolAddressTest.sol @@ -11,7 +11,7 @@ contract PoolAddressTest is IPoolAddress { address tokenA, address tokenB, uint24 fee - ) external pure override returns (IPoolKey memory key) { + ) external pure override returns (PoolKey memory key) { PoolAddress.PoolKey memory _key = PoolAddress.getPoolKey(tokenA, tokenB, fee); /// @solidity memory-safe-assembly assembly { @@ -19,7 +19,7 @@ contract PoolAddressTest is IPoolAddress { } } - function computeAddress(address factory, IPoolKey memory key) external pure override returns (address pool) { + function computeAddress(address factory, PoolKey memory key) external pure override returns (address pool) { PoolAddress.PoolKey memory _key; /// @solidity memory-safe-assembly assembly { diff --git a/src/test/interfaces/IPoolAddress.sol b/src/test/interfaces/IPoolAddress.sol index 5a6d387..b9c39cc 100644 --- a/src/test/interfaces/IPoolAddress.sol +++ b/src/test/interfaces/IPoolAddress.sol @@ -2,7 +2,7 @@ pragma solidity >=0.5.0; pragma abicoder v2; -import "../../PoolAddress.sol"; +import "../../PoolKey.sol"; interface IPoolAddress { function getPoolKey(address tokenA, address tokenB, uint24 fee) external pure returns (PoolKey memory); diff --git a/test/PoolAddress.t.sol b/test/PoolAddress.t.sol index 6472b58..4dc4b5f 100644 --- a/test/PoolAddress.t.sol +++ b/test/PoolAddress.t.sol @@ -32,11 +32,7 @@ interface IPoolAddressWrapper is IPoolAddress { /// @dev Expose internal functions to test the PoolAddress library. contract PoolAddressWrapper is IPoolAddressWrapper { - function getPoolKey( - address tokenA, - address tokenB, - uint24 fee - ) external pure returns (PoolKey memory key) { + function getPoolKey(address tokenA, address tokenB, uint24 fee) external pure returns (PoolKey memory key) { key = PoolAddress.getPoolKey(tokenA, tokenB, fee); } @@ -77,11 +73,7 @@ contract PoolAddressWrapper is IPoolAddressWrapper { /// @dev Expose internal functions to test the PoolAddressPancakeSwapV3 library. contract PoolAddressPancakeSwapV3Wrapper is IPoolAddressWrapper { - function getPoolKey( - address tokenA, - address tokenB, - uint24 fee - ) external pure returns (PoolKey memory key) { + function getPoolKey(address tokenA, address tokenB, uint24 fee) external pure returns (PoolKey memory key) { key = PoolAddressPancakeSwapV3.getPoolKey(tokenA, tokenB, fee); }