Skip to content

Commit

Permalink
Merge pull request #9 from pancakeswap/refactor/fit-periphery
Browse files Browse the repository at this point in the history
Refactor/fit periphery
  • Loading branch information
chefburger authored Aug 28, 2024
2 parents ddf50fb + d0ca89d commit 75f5bbd
Show file tree
Hide file tree
Showing 31 changed files with 834 additions and 452 deletions.
12 changes: 6 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/pancake-v4-core"]
path = lib/pancake-v4-core
url = https://github.com/pancakeswap/pancake-v4-core
[submodule "lib/pancake-v4-periphery"]
path = lib/pancake-v4-periphery
url = https://github.com/pancakeswap/pancake-v4-periphery
[submodule "lib/forge-gas-snapshot"]
path = lib/forge-gas-snapshot
url = https://github.com/marktoda/forge-gas-snapshot
[submodule "lib/pancake-v4-universal-router"]
path = lib/pancake-v4-universal-router
url = https://github.com/pancakeswap/pancake-v4-universal-router
7 changes: 1 addition & 6 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ optimizer_runs = 1000
via_ir = true
evm_version = 'cancun'
ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}]
remappings = [
"@pancakeswap/v4-core/=lib/pancake-v4-core/",
"@pancakeswap/v4-periphery/=lib/pancake-v4-periphery/",
"@openzeppelin/=lib/pancake-v4-periphery/lib/openzeppelin-contracts/"
]
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/" }]

[profile.default.fuzz]
runs = 1000
Expand Down
1 change: 1 addition & 0 deletions lib/forge-gas-snapshot
Submodule forge-gas-snapshot added at 9fc447
2 changes: 1 addition & 1 deletion lib/forge-std
1 change: 0 additions & 1 deletion lib/pancake-v4-core
Submodule pancake-v4-core deleted from 52b216
1 change: 0 additions & 1 deletion lib/pancake-v4-periphery
Submodule pancake-v4-periphery deleted from 035570
1 change: 1 addition & 0 deletions lib/pancake-v4-universal-router
11 changes: 8 additions & 3 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@pancakeswap/v4-core/=lib/pancake-v4-core/
@pancakeswap/v4-periphery/=lib/pancake-v4-periphery/
@openzeppelin/=lib/pancake-v4-periphery/lib/openzeppelin-contracts/
forge-std/=lib/forge-std/src/
ds-test/=lib/forge-std/lib/ds-test/src/
openzeppelin-contracts/=lib/pancake-v4-universal-router/lib/pancake-v4-periphery/lib/pancake-v4-core/lib/openzeppelin-contracts/
solmate/=lib/pancake-v4-universal-router/lib/pancake-v4-periphery/lib/pancake-v4-core/lib/solmate/
pancake-v4-core/=lib/pancake-v4-universal-router/lib/pancake-v4-periphery/lib/pancake-v4-core/
pancake-v4-periphery/=lib/pancake-v4-universal-router/lib/pancake-v4-periphery/
pancake-v4-universal-router/=lib/pancake-v4-universal-router/
permit2/=lib/pancake-v4-universal-router/lib/pancake-v4-periphery/lib/permit2/
20 changes: 10 additions & 10 deletions src/pool-bin/BinBaseHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import {
HOOKS_AFTER_SWAP_RETURNS_DELTA_OFFSET,
HOOKS_AFTER_MINT_RETURNS_DELTA_OFFSET,
HOOKS_AFTER_BURN_RETURNS_DELTA_OFFSET
} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {BalanceDelta} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol";
import {IHooks} from "@pancakeswap/v4-core/src/interfaces/IHooks.sol";
import {IVault} from "@pancakeswap/v4-core/src/interfaces/IVault.sol";
import {IBinHooks} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {IBinPoolManager} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";
import {BinPoolManager} from "@pancakeswap/v4-core/src/pool-bin/BinPoolManager.sol";
} from "pancake-v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {BalanceDelta} from "pancake-v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta} from "pancake-v4-core/src/types/BeforeSwapDelta.sol";
import {IHooks} from "pancake-v4-core/src/interfaces/IHooks.sol";
import {IVault} from "pancake-v4-core/src/interfaces/IVault.sol";
import {IBinHooks} from "pancake-v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {IBinPoolManager} from "pancake-v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";
import {BinPoolManager} from "pancake-v4-core/src/pool-bin/BinPoolManager.sol";

/// @notice BaseHook abstract contract for Bin pool hooks to inherit
abstract contract BinBaseHook is IBinHooks {
Expand Down Expand Up @@ -124,7 +124,7 @@ abstract contract BinBaseHook is IBinHooks {
function beforeMint(address, PoolKey calldata, IBinPoolManager.MintParams calldata, bytes calldata)
external
virtual
returns (bytes4)
returns (bytes4, uint24)
{
revert HookNotImplemented();
}
Expand Down
20 changes: 10 additions & 10 deletions src/pool-bin/geomean-oracle/BinGeomeanOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.19;

import {IBinPoolManager} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";
import {IBinPoolManager} from "pancake-v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";
import {
HOOKS_BEFORE_INITIALIZE_OFFSET,
HOOKS_AFTER_INITIALIZE_OFFSET,
Expand All @@ -14,13 +14,13 @@ import {
HOOKS_AFTER_SWAP_OFFSET,
HOOKS_BEFORE_DONATE_OFFSET,
HOOKS_AFTER_DONATE_OFFSET
} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {IPoolManager} from "@pancakeswap/v4-core/src/interfaces/IPoolManager.sol";
import {PoolId, PoolIdLibrary} from "@pancakeswap/v4-core/src/types/PoolId.sol";
import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {BalanceDelta, BalanceDeltaLibrary} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol";
import {Hooks} from "@pancakeswap/v4-core/src/libraries/Hooks.sol";
} from "pancake-v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {IPoolManager} from "pancake-v4-core/src/interfaces/IPoolManager.sol";
import {PoolId, PoolIdLibrary} from "pancake-v4-core/src/types/PoolId.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {BalanceDelta, BalanceDeltaLibrary} from "pancake-v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "pancake-v4-core/src/types/BeforeSwapDelta.sol";
import {Hooks} from "pancake-v4-core/src/libraries/Hooks.sol";

import {BinBaseHook} from "../BinBaseHook.sol";
import {OracleHelper} from "./libraries/OracleHelper.sol";
Expand Down Expand Up @@ -92,9 +92,9 @@ contract BinGeomeanOracle is BinBaseHook {
PoolKey calldata key,
IBinPoolManager.MintParams calldata params,
bytes calldata hookData
) external override poolManagerOnly returns (bytes4) {
) external override poolManagerOnly returns (bytes4, uint24) {
_updatePool(key);
return this.beforeMint.selector;
return (this.beforeMint.selector, 0);
}

function beforeBurn(
Expand Down
40 changes: 20 additions & 20 deletions src/pool-bin/limit-order/BinLimitOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.19;

import {IBinPoolManager} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";
import {IBinPoolManager} from "pancake-v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";
import {
HOOKS_BEFORE_INITIALIZE_OFFSET,
HOOKS_AFTER_INITIALIZE_OFFSET,
Expand All @@ -14,23 +14,23 @@ import {
HOOKS_AFTER_SWAP_OFFSET,
HOOKS_BEFORE_DONATE_OFFSET,
HOOKS_AFTER_DONATE_OFFSET
} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {FullMath} from "@pancakeswap/v4-core/src/pool-cl/libraries/FullMath.sol";
import {SafeCast} from "@pancakeswap/v4-core/src/libraries/SafeCast.sol";
import {BinPoolParametersHelper} from "@pancakeswap/v4-core/src/pool-bin/libraries/BinPoolParametersHelper.sol";
import {IPoolManager} from "@pancakeswap/v4-core/src/interfaces/IPoolManager.sol";
import {IVault} from "@pancakeswap/v4-core/src/interfaces/IVault.sol";
import {PoolId, PoolIdLibrary} from "@pancakeswap/v4-core/src/types/PoolId.sol";
import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {Currency, CurrencyLibrary} from "@pancakeswap/v4-core/src/types/Currency.sol";
import {BalanceDelta} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol";
import {Hooks} from "@pancakeswap/v4-core/src/libraries/Hooks.sol";
import {BinPoolManager} from "@pancakeswap/v4-core/src/pool-bin/BinPoolManager.sol";
import {LiquidityConfigurations} from "@pancakeswap/v4-core/src/pool-bin/libraries/math/LiquidityConfigurations.sol";
import {PackedUint128Math} from "@pancakeswap/v4-core/src/pool-bin/libraries/math/PackedUint128Math.sol";
import {BinPool} from "@pancakeswap/v4-core/src/pool-bin/libraries/BinPool.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
} from "pancake-v4-core/src/pool-bin/interfaces/IBinHooks.sol";
import {FullMath} from "pancake-v4-core/src/pool-cl/libraries/FullMath.sol";
import {SafeCast} from "pancake-v4-core/src/libraries/SafeCast.sol";
import {BinPoolParametersHelper} from "pancake-v4-core/src/pool-bin/libraries/BinPoolParametersHelper.sol";
import {IPoolManager} from "pancake-v4-core/src/interfaces/IPoolManager.sol";
import {IVault} from "pancake-v4-core/src/interfaces/IVault.sol";
import {PoolId, PoolIdLibrary} from "pancake-v4-core/src/types/PoolId.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {Currency, CurrencyLibrary} from "pancake-v4-core/src/types/Currency.sol";
import {BalanceDelta} from "pancake-v4-core/src/types/BalanceDelta.sol";
import {Hooks} from "pancake-v4-core/src/libraries/Hooks.sol";
import {BinPoolManager} from "pancake-v4-core/src/pool-bin/BinPoolManager.sol";
import {LiquidityConfigurations} from "pancake-v4-core/src/pool-bin/libraries/math/LiquidityConfigurations.sol";
import {PackedUint128Math} from "pancake-v4-core/src/pool-bin/libraries/math/PackedUint128Math.sol";
import {BinPool} from "pancake-v4-core/src/pool-bin/libraries/BinPool.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

import {BinBaseHook} from "../BinBaseHook.sol";

Expand Down Expand Up @@ -315,13 +315,13 @@ contract BinLimitOrder is BinBaseHook {
IERC20(Currency.unwrap(key.currency0)).safeTransferFrom(
owner, address(vault), uint256(uint128(-delta.amount0()))
);
vault.settle(key.currency0);
vault.settle();
} else {
vault.sync(key.currency1);
IERC20(Currency.unwrap(key.currency1)).safeTransferFrom(
owner, address(vault), uint256(uint128(-delta.amount1()))
);
vault.settle(key.currency1);
vault.settle();
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/pool-bin/vecake-exclusive/BinVeCakeExclusiveHook.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "@pancakeswap/v4-core/src/types/PoolId.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol";
import {IBinPoolManager} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "pancake-v4-core/src/types/PoolId.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "pancake-v4-core/src/types/BeforeSwapDelta.sol";
import {IBinPoolManager} from "pancake-v4-core/src/pool-bin/interfaces/IBinPoolManager.sol";

import {BinBaseHook} from "../BinBaseHook.sol";

Expand Down
18 changes: 9 additions & 9 deletions src/pool-cl/CLBaseHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import {
HOOKS_AFTER_SWAP_RETURNS_DELTA_OFFSET,
HOOKS_AFTER_ADD_LIQUIDIY_RETURNS_DELTA_OFFSET,
HOOKS_AFTER_REMOVE_LIQUIDIY_RETURNS_DELTA_OFFSET
} from "@pancakeswap/v4-core/src/pool-cl/interfaces/ICLHooks.sol";
import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {BalanceDelta} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol";
import {IHooks} from "@pancakeswap/v4-core/src/interfaces/IHooks.sol";
import {IVault} from "@pancakeswap/v4-core/src/interfaces/IVault.sol";
import {ICLHooks} from "@pancakeswap/v4-core/src/pool-cl/interfaces/ICLHooks.sol";
import {ICLPoolManager} from "@pancakeswap/v4-core/src/pool-cl/interfaces/ICLPoolManager.sol";
import {CLPoolManager} from "@pancakeswap/v4-core/src/pool-cl/CLPoolManager.sol";
} from "pancake-v4-core/src/pool-cl/interfaces/ICLHooks.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {BalanceDelta} from "pancake-v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta} from "pancake-v4-core/src/types/BeforeSwapDelta.sol";
import {IHooks} from "pancake-v4-core/src/interfaces/IHooks.sol";
import {IVault} from "pancake-v4-core/src/interfaces/IVault.sol";
import {ICLHooks} from "pancake-v4-core/src/pool-cl/interfaces/ICLHooks.sol";
import {ICLPoolManager} from "pancake-v4-core/src/pool-cl/interfaces/ICLPoolManager.sol";
import {CLPoolManager} from "pancake-v4-core/src/pool-cl/CLPoolManager.sol";

/// @notice BaseHook abstract contract for CL pool hooks to inherit
abstract contract CLBaseHook is ICLHooks {
Expand Down
48 changes: 24 additions & 24 deletions src/pool-cl/full-range/CLFullRange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

pragma solidity ^0.8.19;

import {ICLPoolManager} from "@pancakeswap/v4-core/src/pool-cl/interfaces/ICLPoolManager.sol";
import {TickMath} from "@pancakeswap/v4-core/src/pool-cl/libraries/TickMath.sol";
import {TickBitmap} from "@pancakeswap/v4-core/src/pool-cl/libraries/TickBitmap.sol";
import {SqrtPriceMath} from "@pancakeswap/v4-core/src/pool-cl/libraries/SqrtPriceMath.sol";
import {FixedPoint96} from "@pancakeswap/v4-core/src/pool-cl/libraries/FixedPoint96.sol";
import {CLPoolParametersHelper} from "@pancakeswap/v4-core/src/pool-cl/libraries/CLPoolParametersHelper.sol";
import {IPoolManager} from "@pancakeswap/v4-core/src/interfaces/IPoolManager.sol";
import {IVault} from "@pancakeswap/v4-core/src/interfaces/IVault.sol";
import {PoolId, PoolIdLibrary} from "@pancakeswap/v4-core/src/types/PoolId.sol";
import {Currency, CurrencyLibrary} from "@pancakeswap/v4-core/src/types/Currency.sol";
import {BalanceDelta} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol";
import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {Hooks} from "@pancakeswap/v4-core/src/libraries/Hooks.sol";
import {SafeCast} from "@pancakeswap/v4-core/src/libraries/SafeCast.sol";
import {FullMath} from "@pancakeswap/v4-core/src/pool-cl/libraries/FullMath.sol";
import {CLPoolManager} from "@pancakeswap/v4-core/src/pool-cl/CLPoolManager.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ICLPoolManager} from "pancake-v4-core/src/pool-cl/interfaces/ICLPoolManager.sol";
import {TickMath} from "pancake-v4-core/src/pool-cl/libraries/TickMath.sol";
import {TickBitmap} from "pancake-v4-core/src/pool-cl/libraries/TickBitmap.sol";
import {SqrtPriceMath} from "pancake-v4-core/src/pool-cl/libraries/SqrtPriceMath.sol";
import {FixedPoint96} from "pancake-v4-core/src/pool-cl/libraries/FixedPoint96.sol";
import {CLPoolParametersHelper} from "pancake-v4-core/src/pool-cl/libraries/CLPoolParametersHelper.sol";
import {IPoolManager} from "pancake-v4-core/src/interfaces/IPoolManager.sol";
import {IVault} from "pancake-v4-core/src/interfaces/IVault.sol";
import {PoolId, PoolIdLibrary} from "pancake-v4-core/src/types/PoolId.sol";
import {Currency, CurrencyLibrary} from "pancake-v4-core/src/types/Currency.sol";
import {BalanceDelta} from "pancake-v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "pancake-v4-core/src/types/BeforeSwapDelta.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {Hooks} from "pancake-v4-core/src/libraries/Hooks.sol";
import {SafeCast} from "pancake-v4-core/src/libraries/SafeCast.sol";
import {FullMath} from "pancake-v4-core/src/pool-cl/libraries/FullMath.sol";
import {CLPoolManager} from "pancake-v4-core/src/pool-cl/CLPoolManager.sol";
import {FixedPointMathLib} from "solmate/src/utils/FixedPointMathLib.sol";
import {IERC20Metadata} from "openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

import {CLBaseHook} from "../CLBaseHook.sol";
import {LiquidityAmounts} from "./libraries/LiquidityAmounts.sol";
Expand Down Expand Up @@ -331,15 +331,15 @@ contract CLFullRange is CLBaseHook {

function _settleDelta(address sender, Currency currency, uint128 amount) internal {
if (currency.isNative()) {
vault.settle{value: amount}(currency);
vault.settle{value: amount}();
} else {
vault.sync(currency);
if (sender == address(this)) {
IERC20(Currency.unwrap(currency)).safeTransfer(address(vault), amount);
} else {
IERC20(Currency.unwrap(currency)).safeTransferFrom(sender, address(vault), amount);
}
vault.settle(currency);
vault.settle();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pool-cl/full-range/libraries/LiquidityAmounts.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;

import "@pancakeswap/v4-core/src/pool-cl/libraries/FullMath.sol";
import "@pancakeswap/v4-core/src/pool-cl/libraries/FixedPoint96.sol";
import "pancake-v4-core/src/pool-cl/libraries/FullMath.sol";
import "pancake-v4-core/src/pool-cl/libraries/FixedPoint96.sol";

/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
Expand Down
4 changes: 2 additions & 2 deletions src/pool-cl/full-range/libraries/PancakeV4ERC20.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.8.19;

import {ERC20} from "solmate/tokens/ERC20.sol";
import {Owned} from "solmate/auth/Owned.sol";
import {ERC20} from "solmate/src/tokens/ERC20.sol";
import {Owned} from "solmate/src/auth/Owned.sol";

contract PancakeV4ERC20 is ERC20, Owned {
constructor(string memory name, string memory symbol) ERC20(name, symbol, 18) Owned(msg.sender) {}
Expand Down
Loading

0 comments on commit 75f5bbd

Please sign in to comment.