Skip to content

Commit

Permalink
Move PoolKey struct to a separate .sol file and fix build errors. Fix…
Browse files Browse the repository at this point in the history
… lint.
  • Loading branch information
gnarlycow committed Mar 23, 2024
1 parent 76c9b5a commit afbb9b1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 23 deletions.
8 changes: 1 addition & 7 deletions src/PoolAddress.sol
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/PoolAddressPancakeSwapV3.sol
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/PoolKey.sol
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions src/test/PoolAddressPancakeSwapV3Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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 {
key := _key
}
}

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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/PoolAddressTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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 {
key := _key
}
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/interfaces/IPoolAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 2 additions & 10 deletions test/PoolAddress.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit afbb9b1

Please sign in to comment.