From 1172d2b50e0cf74b3a8d5c9fb85559ffef4a2538 Mon Sep 17 00:00:00 2001 From: Chef Snoopy <91462681+ChefSnoopy@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:37:21 +0800 Subject: [PATCH] Feat/update v4 lib and fix conflicts (#14) * feat: Update lib * feat: Update codes to adapt to latest v4 codes --- lib/forge-gas-snapshot | 2 +- lib/forge-std | 2 +- lib/pancake-v4-universal-router | 2 +- src/pool-cl/CLBaseHook.sol | 2 + test/pool-bin/helpers/Deployers.sol | 2 +- test/pool-cl/CLFullRangeHook.t.sol | 1 - test/pool-cl/CLGeomeanOracle.t.sol | 46 ++++++------------- test/pool-cl/CLLimitOrder.t.sol | 8 ++-- test/pool-cl/CLVeCakeExclusiveHook.t.sol | 8 ++-- .../pool-cl/helpers/MockCLPositionManager.sol | 23 +++++----- 10 files changed, 39 insertions(+), 57 deletions(-) diff --git a/lib/forge-gas-snapshot b/lib/forge-gas-snapshot index 9fc447c..03b10b1 160000 --- a/lib/forge-gas-snapshot +++ b/lib/forge-gas-snapshot @@ -1 +1 @@ -Subproject commit 9fc447c732c89b6dd6352c096042d8d82b44faed +Subproject commit 03b10b10574e069081f6b84f5e1244e42041511d diff --git a/lib/forge-std b/lib/forge-std index 1714bee..beb836e 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 1714bee72e286e73f76e320d110e0eaf5c4e649d +Subproject commit beb836e33f9a207f4927abb7cd09ad0afe4b3f9f diff --git a/lib/pancake-v4-universal-router b/lib/pancake-v4-universal-router index 8cefacb..e655693 160000 --- a/lib/pancake-v4-universal-router +++ b/lib/pancake-v4-universal-router @@ -1 +1 @@ -Subproject commit 8cefacb472e8fdecdb7b0391527d42b6310b817d +Subproject commit e6556937a9e7cd1ccbb8a0ce958e99e32108e47c diff --git a/src/pool-cl/CLBaseHook.sol b/src/pool-cl/CLBaseHook.sol index 348f263..4579e80 100644 --- a/src/pool-cl/CLBaseHook.sol +++ b/src/pool-cl/CLBaseHook.sol @@ -140,6 +140,7 @@ abstract contract CLBaseHook is ICLHooks { PoolKey calldata, ICLPoolManager.ModifyLiquidityParams calldata, BalanceDelta, + BalanceDelta, bytes calldata ) external virtual returns (bytes4, BalanceDelta) { revert HookNotImplemented(); @@ -161,6 +162,7 @@ abstract contract CLBaseHook is ICLHooks { PoolKey calldata, ICLPoolManager.ModifyLiquidityParams calldata, BalanceDelta, + BalanceDelta, bytes calldata ) external virtual returns (bytes4, BalanceDelta) { revert HookNotImplemented(); diff --git a/test/pool-bin/helpers/Deployers.sol b/test/pool-bin/helpers/Deployers.sol index 8de2813..0a84106 100644 --- a/test/pool-bin/helpers/Deployers.sol +++ b/test/pool-bin/helpers/Deployers.sol @@ -65,7 +65,7 @@ contract Deployers { function createFreshManager() internal returns (IVault vault, BinPoolManager manager) { vault = new Vault(); - manager = new BinPoolManager(vault, 500000); + manager = new BinPoolManager(vault); vault.registerApp(address(manager)); } } diff --git a/test/pool-cl/CLFullRangeHook.t.sol b/test/pool-cl/CLFullRangeHook.t.sol index 9856d06..1d19a66 100644 --- a/test/pool-cl/CLFullRangeHook.t.sol +++ b/test/pool-cl/CLFullRangeHook.t.sol @@ -23,7 +23,6 @@ import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol" import {MockCLSwapRouter} from "./helpers/MockCLSwapRouter.sol"; import {MockCLPositionManager} from "./helpers/MockCLPositionManager.sol"; -import {PositionConfig} from "pancake-v4-periphery/src/pool-cl/libraries/PositionConfig.sol"; import {CLFullRange} from "../../src/pool-cl/full-range/CLFullRange.sol"; import {PancakeV4ERC20} from "../../src/pool-cl/full-range/libraries/PancakeV4ERC20.sol"; diff --git a/test/pool-cl/CLGeomeanOracle.t.sol b/test/pool-cl/CLGeomeanOracle.t.sol index ac26441..a22056e 100644 --- a/test/pool-cl/CLGeomeanOracle.t.sol +++ b/test/pool-cl/CLGeomeanOracle.t.sol @@ -24,8 +24,6 @@ import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol" import {MockCLSwapRouter} from "./helpers/MockCLSwapRouter.sol"; import {MockCLPositionManager} from "./helpers/MockCLPositionManager.sol"; -import {PositionConfig} from "pancake-v4-periphery/src/pool-cl/libraries/PositionConfig.sol"; - import {CLGeomeanOracle} from "../../src/pool-cl/geomean-oracle/CLGeomeanOracle.sol"; import {Oracle} from "../../src/pool-cl/geomean-oracle/libraries/Oracle.sol"; @@ -157,14 +155,10 @@ contract CLGeomeanOracleHookTest is Test, Deployers, DeployPermit2 { function testBeforeModifyPositionNoObservations() public { poolManager.initialize(key, Constants.SQRT_RATIO_2_1, ZERO_BYTES); - PositionConfig memory config = PositionConfig({ - poolKey: key, - tickLower: TickMath.minUsableTick(MAX_TICK_SPACING), - tickUpper: TickMath.maxUsableTick(MAX_TICK_SPACING) - }); - cpm.mint( - config, + key, + TickMath.minUsableTick(MAX_TICK_SPACING), + TickMath.maxUsableTick(MAX_TICK_SPACING), // liquidity: 10e18, // amount0Max: @@ -193,14 +187,10 @@ contract CLGeomeanOracleHookTest is Test, Deployers, DeployPermit2 { poolManager.initialize(key, Constants.SQRT_RATIO_2_1, ZERO_BYTES); vm.warp(3); // advance 2 seconds - PositionConfig memory config = PositionConfig({ - poolKey: key, - tickLower: TickMath.minUsableTick(MAX_TICK_SPACING), - tickUpper: TickMath.maxUsableTick(MAX_TICK_SPACING) - }); - cpm.mint( - config, + key, + TickMath.minUsableTick(MAX_TICK_SPACING), + TickMath.maxUsableTick(MAX_TICK_SPACING), // liquidity: 10e18, // amount0Max: @@ -234,14 +224,10 @@ contract CLGeomeanOracleHookTest is Test, Deployers, DeployPermit2 { assertEq(observationState.cardinality, 1); assertEq(observationState.cardinalityNext, 2); - PositionConfig memory config = PositionConfig({ - poolKey: key, - tickLower: TickMath.minUsableTick(MAX_TICK_SPACING), - tickUpper: TickMath.maxUsableTick(MAX_TICK_SPACING) - }); - cpm.mint( - config, + key, + TickMath.minUsableTick(MAX_TICK_SPACING), + TickMath.maxUsableTick(MAX_TICK_SPACING), // liquidity: 10e18, // amount0Max: @@ -279,14 +265,10 @@ contract CLGeomeanOracleHookTest is Test, Deployers, DeployPermit2 { poolManager.initialize(key, Constants.SQRT_RATIO_2_1, ZERO_BYTES); vm.warp(3); // advance 2 seconds - PositionConfig memory config = PositionConfig({ - poolKey: key, - tickLower: TickMath.minUsableTick(MAX_TICK_SPACING), - tickUpper: TickMath.maxUsableTick(MAX_TICK_SPACING) - }); - (uint256 tokenId, uint128 liquidity) = cpm.mint( - config, + key, + TickMath.minUsableTick(MAX_TICK_SPACING), + TickMath.maxUsableTick(MAX_TICK_SPACING), // liquidity: 10e18, // amount0Max: @@ -309,8 +291,8 @@ contract CLGeomeanOracleHookTest is Test, Deployers, DeployPermit2 { cpm.decreaseLiquidity( // tokenId: tokenId, - // config: - config, + // poolKey: + key, // liquidity: liquidity, // amount0Min: diff --git a/test/pool-cl/CLLimitOrder.t.sol b/test/pool-cl/CLLimitOrder.t.sol index 07e3f3f..1535f7b 100644 --- a/test/pool-cl/CLLimitOrder.t.sol +++ b/test/pool-cl/CLLimitOrder.t.sol @@ -23,8 +23,6 @@ import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol" import {MockCLSwapRouter} from "./helpers/MockCLSwapRouter.sol"; import {MockCLPositionManager} from "./helpers/MockCLPositionManager.sol"; -import {PositionConfig} from "pancake-v4-periphery/src/pool-cl/libraries/PositionConfig.sol"; - import {CLLimitOrder, Epoch, EpochLibrary} from "../../src/pool-cl/limit-order/CLLimitOrder.sol"; contract CLLimitOrderHookTest is Test, Deployers, DeployPermit2 { @@ -81,10 +79,10 @@ contract CLLimitOrderHookTest is Test, Deployers, DeployPermit2 { poolManager.initialize(key, SQRT_RATIO_1_1, ZERO_BYTES); - PositionConfig memory config = PositionConfig({poolKey: key, tickLower: -120, tickUpper: 120}); - cpm.mint( - config, + key, + -120, + 120, // liquidity: 10e18, // amount0Max: diff --git a/test/pool-cl/CLVeCakeExclusiveHook.t.sol b/test/pool-cl/CLVeCakeExclusiveHook.t.sol index 1eccacd..0210e25 100644 --- a/test/pool-cl/CLVeCakeExclusiveHook.t.sol +++ b/test/pool-cl/CLVeCakeExclusiveHook.t.sol @@ -22,7 +22,6 @@ import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol" import {MockCLSwapRouter} from "./helpers/MockCLSwapRouter.sol"; import {MockCLPositionManager} from "./helpers/MockCLPositionManager.sol"; -import {PositionConfig} from "pancake-v4-periphery/src/pool-cl/libraries/PositionConfig.sol"; import {CLVeCakeExclusiveHook} from "../../src/pool-cl/vecake-exclusive/CLVeCakeExclusiveHook.sol"; contract CLVeCakeExclusiveHookTest is Test, Deployers, DeployPermit2 { @@ -45,7 +44,6 @@ contract CLVeCakeExclusiveHookTest is Test, Deployers, DeployPermit2 { Currency currency1; PoolKey key; PoolId id; - PositionConfig config; MockERC20 veCake; address nonHolder = address(0x1); @@ -80,13 +78,15 @@ contract CLVeCakeExclusiveHookTest is Test, Deployers, DeployPermit2 { fee: 3000, parameters: bytes32(uint256(veCakeExclusiveHook.getHooksRegistrationBitmap())).setTickSpacing(60) }); - config = PositionConfig({poolKey: key, tickLower: -120, tickUpper: 120}); + id = key.toId(); poolManager.initialize(key, SQRT_RATIO_1_1, ZERO_BYTES); cpm.mint( - config, + key, + -120, + 120, // liquidity: 10e18, // amount0Max: diff --git a/test/pool-cl/helpers/MockCLPositionManager.sol b/test/pool-cl/helpers/MockCLPositionManager.sol index 65bc4e9..c724c52 100644 --- a/test/pool-cl/helpers/MockCLPositionManager.sol +++ b/test/pool-cl/helpers/MockCLPositionManager.sol @@ -11,17 +11,19 @@ import {CLPositionManager} from "pancake-v4-periphery/src/pool-cl/CLPositionMana import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol"; import {Planner, Plan} from "pancake-v4-periphery/src/libraries/Planner.sol"; import {Actions} from "pancake-v4-periphery/src/libraries/Actions.sol"; -import {PositionConfig} from "pancake-v4-periphery/src/pool-cl/libraries/PositionConfig.sol"; +import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol"; contract MockCLPositionManager is CLPositionManager, CommonBase { using Planner for Plan; constructor(IVault _vault, ICLPoolManager _clPoolManager, IAllowanceTransfer _permit2) - CLPositionManager(_vault, _clPoolManager, _permit2) + CLPositionManager(_vault, _clPoolManager, _permit2, 500000) {} function mint( - PositionConfig calldata config, + PoolKey calldata poolKey, + int24 tickLower, + int24 tickUpper, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, @@ -29,32 +31,31 @@ contract MockCLPositionManager is CLPositionManager, CommonBase { bytes calldata hookData ) external payable returns (uint256 tokenId, uint128 liquidityMinted) { Plan memory planner = Planner.init().add( - Actions.CL_MINT_POSITION, abi.encode(config, liquidity, amount0Max, amount1Max, owner, hookData) + Actions.CL_MINT_POSITION, + abi.encode(poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, hookData) ); - bytes memory data = planner.finalizeModifyLiquidityWithClose(config.poolKey); - - // vm.recordLogs(); + bytes memory data = planner.finalizeModifyLiquidityWithClose(poolKey); tokenId = nextTokenId; vm.prank(msg.sender); this.modifyLiquidities(data, block.timestamp); - liquidityMinted = getPositionLiquidity(tokenId, config); + liquidityMinted = _getLiquidity(tokenId, poolKey, tickLower, tickUpper); } function decreaseLiquidity( uint256 tokenId, - PositionConfig calldata config, + PoolKey calldata poolKey, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData ) external payable { Plan memory planner = Planner.init().add( - Actions.CL_DECREASE_LIQUIDITY, abi.encode(tokenId, config, liquidity, amount0Min, amount1Min, hookData) + Actions.CL_DECREASE_LIQUIDITY, abi.encode(tokenId, liquidity, amount0Min, amount1Min, hookData) ); - bytes memory data = planner.finalizeModifyLiquidityWithClose(config.poolKey); + bytes memory data = planner.finalizeModifyLiquidityWithClose(poolKey); vm.prank(msg.sender); this.modifyLiquidities(data, block.timestamp);