Skip to content

Commit

Permalink
Feat/update v4 lib and fix conflicts (#14)
Browse files Browse the repository at this point in the history
* feat: Update lib

* feat: Update codes to adapt to latest v4 codes
  • Loading branch information
ChefSnoopy authored Sep 19, 2024
1 parent 2b85e16 commit 1172d2b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 57 deletions.
2 changes: 1 addition & 1 deletion lib/pancake-v4-universal-router
Submodule pancake-v4-universal-router updated 47 files
+1 −1 .forge-snapshots/BinNativePancakeSwapV4Test#test_v4BinSwap_ExactInSingle_NativeIn.snap
+1 −1 .forge-snapshots/BinNativePancakeSwapV4Test#test_v4BinSwap_ExactInSingle_NativeOut_RouterRecipient.snap
+1 −1 .forge-snapshots/BinPancakeSwapV4Test#test_v4BinSwap_ExactInSingle.snap
+1 −1 .forge-snapshots/BinPancakeSwapV4Test#test_v4BinSwap_ExactIn_MultiHop.snap
+1 −1 .forge-snapshots/BinPancakeSwapV4Test#test_v4BinSwap_ExactIn_SingleHop.snap
+1 −1 .forge-snapshots/BinPancakeSwapV4Test#test_v4BinSwap_ExactOut_MultiHop.snap
+1 −1 .forge-snapshots/BinPancakeSwapV4Test#test_v4BinSwap_ExactOut_SingleHop.snap
+1 −1 .forge-snapshots/BinPancakeSwapV4Test#test_v4ClSwap_ExactOutSingle.snap
+1 −1 .forge-snapshots/CLNativePancakeSwapV4Test#test_v4ClSwap_ExactInSingle_NativeIn.snap
+1 −1 .forge-snapshots/CLNativePancakeSwapV4Test#test_v4ClSwap_ExactInSingle_NativeOut.snap
+1 −1 .forge-snapshots/CLPancakeSwapV4Test#test_v4ClSwap_ExactInSingle.snap
+1 −1 .forge-snapshots/CLPancakeSwapV4Test#test_v4ClSwap_ExactIn_MultiHop.snap
+1 −1 .forge-snapshots/CLPancakeSwapV4Test#test_v4ClSwap_ExactIn_SingleHop.snap
+1 −1 .forge-snapshots/CLPancakeSwapV4Test#test_v4ClSwap_ExactOutSingle.snap
+1 −1 .forge-snapshots/CLPancakeSwapV4Test#test_v4ClSwap_ExactOut_MultiHop.snap
+1 −1 .forge-snapshots/CLPancakeSwapV4Test#test_v4ClSwap_ExactOut_SingleHop.snap
+1 −1 .forge-snapshots/PancakeSwapV2Test#test_v2Swap_exactInput0For1.snap
+1 −1 .forge-snapshots/PancakeSwapV2Test#test_v2Swap_exactOutput0For1.snap
+1 −1 .forge-snapshots/PancakeSwapV3Test#test_v3Swap_ExactInput0For1.snap
+1 −1 .forge-snapshots/PancakeSwapV3Test#test_v3Swap_exactOutput0For1.snap
+1 −1 .forge-snapshots/StableSwapTest#test_stableSwap_ExactInput0For1.snap
+1 −1 .forge-snapshots/StableSwapTest#test_stableSwap_ExactInput1For0.snap
+1 −1 .forge-snapshots/UniversalRouterBytecodeSize.snap
+1 −1 .forge-snapshots/UniversalRouterTest#test_sweep_token.snap
+1 −1 .forge-snapshots/V3ToV4MigrationNativeTest#test_v4CLPositionmanager_Mint_Native.snap
+1 −1 .forge-snapshots/V3ToV4MigrationTest#test_v3PositionManager_burn.snap
+1 −1 .forge-snapshots/V3ToV4MigrationTest#test_v4BinPositionmanager_BinAddLiquidity.snap
+1 −1 .forge-snapshots/V3ToV4MigrationTest#test_v4BinPositionmanager_BinAddLiquidity_Native.snap
+1 −1 .forge-snapshots/V3ToV4MigrationTest#test_v4CLPositionmanager_Mint.snap
+1 −1 lib/pancake-v4-periphery
+11 −15 src/UniversalRouter.sol
+0 −13 src/base/Callbacks.sol
+66 −33 src/base/Dispatcher.sol
+4 −0 src/base/Lock.sol
+21 −34 src/libraries/BytesLib.sol
+8 −21 src/libraries/Commands.sol
+0 −1 src/modules/Payments.sol
+1 −0 src/modules/Permit2Payments.sol
+4 −0 src/modules/V3ToV4Migrator.sol
+2 −0 src/modules/pancakeswap/v3/V3SwapRouter.sol
+205 −10 test/UniversalRouter.t.sol
+4 −6 test/V3ToV4Migration.t.sol
+4 −6 test/V3ToV4MigrationNative.t.sol
+1 −1 test/v4/BinNativePancakeSwapV4.t.sol
+1 −1 test/v4/BinPancakeSwapV4.t.sol
+4 −6 test/v4/CLNativePancakeSwapV4.t.sol
+4 −6 test/v4/CLPancakeSwapV4.t.sol
2 changes: 2 additions & 0 deletions src/pool-cl/CLBaseHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/pool-bin/helpers/Deployers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
1 change: 0 additions & 1 deletion test/pool-cl/CLFullRangeHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
46 changes: 14 additions & 32 deletions test/pool-cl/CLGeomeanOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -309,8 +291,8 @@ contract CLGeomeanOracleHookTest is Test, Deployers, DeployPermit2 {
cpm.decreaseLiquidity(
// tokenId:
tokenId,
// config:
config,
// poolKey:
key,
// liquidity:
liquidity,
// amount0Min:
Expand Down
8 changes: 3 additions & 5 deletions test/pool-cl/CLLimitOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions test/pool-cl/CLVeCakeExclusiveHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -45,7 +44,6 @@ contract CLVeCakeExclusiveHookTest is Test, Deployers, DeployPermit2 {
Currency currency1;
PoolKey key;
PoolId id;
PositionConfig config;

MockERC20 veCake;
address nonHolder = address(0x1);
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 12 additions & 11 deletions test/pool-cl/helpers/MockCLPositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,51 @@ 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,
address owner,
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);
Expand Down

0 comments on commit 1172d2b

Please sign in to comment.