diff --git a/foundry.toml b/foundry.toml index aa6f1ae..96d0bb0 100644 --- a/foundry.toml +++ b/foundry.toml @@ -4,3 +4,4 @@ out = 'foundry-out' solc_version = '0.8.24' libs = ["lib"] evm_version = 'cancun' +via_ir = true diff --git a/lib/pancake-v4-core b/lib/pancake-v4-core index a3cf6ea..fec703e 160000 --- a/lib/pancake-v4-core +++ b/lib/pancake-v4-core @@ -1 +1 @@ -Subproject commit a3cf6ea800536e8103cb3e6e2c52cb47d323a497 +Subproject commit fec703e6e9aa6c69e735069824a13507bf0e90d5 diff --git a/lib/pancake-v4-periphery b/lib/pancake-v4-periphery index 92d8948..38006c8 160000 --- a/lib/pancake-v4-periphery +++ b/lib/pancake-v4-periphery @@ -1 +1 @@ -Subproject commit 92d894854db7f8a17840083840e6f9dde0eee377 +Subproject commit 38006c89a52b2993d3d66564fd7e2b85a2168085 diff --git a/src/pool-bin/BinBaseHook.sol b/src/pool-bin/BinBaseHook.sol index 82828d1..9120353 100644 --- a/src/pool-bin/BinBaseHook.sol +++ b/src/pool-bin/BinBaseHook.sol @@ -12,9 +12,13 @@ import { HOOKS_AFTER_SWAP_OFFSET, HOOKS_BEFORE_DONATE_OFFSET, HOOKS_AFTER_DONATE_OFFSET, - HOOKS_NO_OP_OFFSET + HOOKS_BEFORE_SWAP_RETURNS_DELTA_OFFSET, + 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 {BeforeSwapDelta} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol"; import {BalanceDelta} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol"; import {IHooks} from "@pancakeswap/v4-core/src/interfaces/IHooks.sol"; import {IVault} from "@pancakeswap/v4-core/src/interfaces/IVault.sol"; @@ -41,7 +45,10 @@ abstract contract BinBaseHook is IBinHooks { bool afterSwap; bool beforeDonate; bool afterDonate; - bool noOp; + bool beforeSwapReturnsDelta; + bool afterSwapReturnsDelta; + bool afterMintReturnsDelta; + bool afterBurnReturnsDelta; } /// @notice The address of the pool manager @@ -111,7 +118,7 @@ abstract contract BinBaseHook is IBinHooks { function afterMint(address, PoolKey calldata, IBinPoolManager.MintParams calldata, BalanceDelta, bytes calldata) external virtual - returns (bytes4) + returns (bytes4, BalanceDelta) { revert HookNotImplemented(); } @@ -127,19 +134,23 @@ abstract contract BinBaseHook is IBinHooks { function afterBurn(address, PoolKey calldata, IBinPoolManager.BurnParams calldata, BalanceDelta, bytes calldata) external virtual - returns (bytes4) + returns (bytes4, BalanceDelta) { revert HookNotImplemented(); } - function beforeSwap(address, PoolKey calldata, bool, uint128, bytes calldata) external virtual returns (bytes4) { + function beforeSwap(address, PoolKey calldata, bool, int128, bytes calldata) + external + virtual + returns (bytes4, BeforeSwapDelta, uint24) + { revert HookNotImplemented(); } - function afterSwap(address, PoolKey calldata, bool, uint128, BalanceDelta, bytes calldata) + function afterSwap(address, PoolKey calldata, bool, int128, BalanceDelta, bytes calldata) external virtual - returns (bytes4) + returns (bytes4, int128) { revert HookNotImplemented(); } @@ -172,7 +183,10 @@ abstract contract BinBaseHook is IBinHooks { | (permissions.afterSwap ? 1 << HOOKS_AFTER_SWAP_OFFSET : 0) | (permissions.beforeDonate ? 1 << HOOKS_BEFORE_DONATE_OFFSET : 0) | (permissions.afterDonate ? 1 << HOOKS_AFTER_DONATE_OFFSET : 0) - | (permissions.noOp ? 1 << HOOKS_NO_OP_OFFSET : 0) + | (permissions.beforeSwapReturnsDelta ? 1 << HOOKS_BEFORE_SWAP_RETURNS_DELTA_OFFSET : 0) + | (permissions.afterSwapReturnsDelta ? 1 << HOOKS_AFTER_SWAP_RETURNS_DELTA_OFFSET : 0) + | (permissions.afterMintReturnsDelta ? 1 << HOOKS_AFTER_MINT_RETURNS_DELTA_OFFSET : 0) + | (permissions.afterBurnReturnsDelta ? 1 << HOOKS_AFTER_BURN_RETURNS_DELTA_OFFSET : 0) ); } } diff --git a/src/pool-bin/BinCounterHook.sol b/src/pool-bin/BinCounterHook.sol index a249b97..244463b 100644 --- a/src/pool-bin/BinCounterHook.sol +++ b/src/pool-bin/BinCounterHook.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.24; import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol"; -import {BalanceDelta} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol"; +import {BalanceDelta, BalanceDeltaLibrary} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol"; +import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol"; import {PoolId, PoolIdLibrary} from "@pancakeswap/v4-core/src/types/PoolId.sol"; import {IBinPoolManager} from "@pancakeswap/v4-core/src/pool-bin/interfaces/IBinPoolManager.sol"; import {BinBaseHook} from "./BinBaseHook.sol"; @@ -32,7 +33,10 @@ contract BinCounterHook is BinBaseHook { afterSwap: true, beforeDonate: false, afterDonate: false, - noOp: false + beforeSwapReturnsDelta: false, + afterSwapReturnsDelta: false, + afterMintReturnsDelta: false, + afterBurnReturnsDelta: false }) ); } @@ -51,29 +55,29 @@ contract BinCounterHook is BinBaseHook { external override poolManagerOnly - returns (bytes4) + returns (bytes4, BalanceDelta) { afterMintCount[key.toId()]++; - return this.afterMint.selector; + return (this.afterMint.selector, BalanceDeltaLibrary.ZERO_DELTA); } - function beforeSwap(address, PoolKey calldata key, bool, uint128, bytes calldata) + function beforeSwap(address, PoolKey calldata key, bool, int128, bytes calldata) external override poolManagerOnly - returns (bytes4) + returns (bytes4, BeforeSwapDelta, uint24) { beforeSwapCount[key.toId()]++; - return this.beforeSwap.selector; + return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0); } - function afterSwap(address, PoolKey calldata key, bool, uint128, BalanceDelta, bytes calldata) + function afterSwap(address, PoolKey calldata key, bool, int128, BalanceDelta, bytes calldata) external override poolManagerOnly - returns (bytes4) + returns (bytes4, int128) { afterSwapCount[key.toId()]++; - return this.afterSwap.selector; + return (this.afterSwap.selector, 0); } } diff --git a/src/pool-cl/CLBaseHook.sol b/src/pool-cl/CLBaseHook.sol index 86e5d04..7046132 100644 --- a/src/pool-cl/CLBaseHook.sol +++ b/src/pool-cl/CLBaseHook.sol @@ -12,10 +12,14 @@ import { HOOKS_AFTER_SWAP_OFFSET, HOOKS_BEFORE_DONATE_OFFSET, HOOKS_AFTER_DONATE_OFFSET, - HOOKS_NO_OP_OFFSET + HOOKS_BEFORE_SWAP_RETURNS_DELTA_OFFSET, + 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"; @@ -41,7 +45,10 @@ abstract contract CLBaseHook is ICLHooks { bool afterSwap; bool beforeDonate; bool afterDonate; - bool noOp; + bool beforeSwapReturnsDelta; + bool afterSwapReturnsDelta; + bool afterAddLiquidityReturnsDelta; + bool afterRemoveLiquidityReturnsDelta; } /// @notice The address of the pool manager @@ -119,7 +126,7 @@ abstract contract CLBaseHook is ICLHooks { ICLPoolManager.ModifyLiquidityParams calldata, BalanceDelta, bytes calldata - ) external virtual returns (bytes4) { + ) external virtual returns (bytes4, BalanceDelta) { revert HookNotImplemented(); } @@ -138,14 +145,14 @@ abstract contract CLBaseHook is ICLHooks { ICLPoolManager.ModifyLiquidityParams calldata, BalanceDelta, bytes calldata - ) external virtual returns (bytes4) { + ) external virtual returns (bytes4, BalanceDelta) { revert HookNotImplemented(); } function beforeSwap(address, PoolKey calldata, ICLPoolManager.SwapParams calldata, bytes calldata) external virtual - returns (bytes4) + returns (bytes4, BeforeSwapDelta, uint24) { revert HookNotImplemented(); } @@ -153,7 +160,7 @@ abstract contract CLBaseHook is ICLHooks { function afterSwap(address, PoolKey calldata, ICLPoolManager.SwapParams calldata, BalanceDelta, bytes calldata) external virtual - returns (bytes4) + returns (bytes4, int128) { revert HookNotImplemented(); } @@ -186,7 +193,10 @@ abstract contract CLBaseHook is ICLHooks { | (permissions.afterSwap ? 1 << HOOKS_AFTER_SWAP_OFFSET : 0) | (permissions.beforeDonate ? 1 << HOOKS_BEFORE_DONATE_OFFSET : 0) | (permissions.afterDonate ? 1 << HOOKS_AFTER_DONATE_OFFSET : 0) - | (permissions.noOp ? 1 << HOOKS_NO_OP_OFFSET : 0) + | (permissions.beforeSwapReturnsDelta ? 1 << HOOKS_BEFORE_SWAP_RETURNS_DELTA_OFFSET : 0) + | (permissions.afterSwapReturnsDelta ? 1 << HOOKS_AFTER_SWAP_RETURNS_DELTA_OFFSET : 0) + | (permissions.afterAddLiquidityReturnsDelta ? 1 << HOOKS_AFTER_ADD_LIQUIDIY_RETURNS_DELTA_OFFSET : 0) + | (permissions.afterRemoveLiquidityReturnsDelta ? 1 << HOOKS_AFTER_REMOVE_LIQUIDIY_RETURNS_DELTA_OFFSET : 0) ); } } diff --git a/src/pool-cl/CLCounterHook.sol b/src/pool-cl/CLCounterHook.sol index 920ef86..88e9531 100644 --- a/src/pool-cl/CLCounterHook.sol +++ b/src/pool-cl/CLCounterHook.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.24; import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol"; -import {BalanceDelta} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol"; +import {BalanceDelta, BalanceDeltaLibrary} from "@pancakeswap/v4-core/src/types/BalanceDelta.sol"; +import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@pancakeswap/v4-core/src/types/BeforeSwapDelta.sol"; import {PoolId, PoolIdLibrary} from "@pancakeswap/v4-core/src/types/PoolId.sol"; import {ICLPoolManager} from "@pancakeswap/v4-core/src/pool-cl/interfaces/ICLPoolManager.sol"; import {CLBaseHook} from "./CLBaseHook.sol"; @@ -32,7 +33,10 @@ contract CLCounterHook is CLBaseHook { afterSwap: true, beforeDonate: false, afterDonate: false, - noOp: false + beforeSwapReturnsDelta: false, + afterSwapReturnsDelta: false, + afterAddLiquidityReturnsDelta: false, + afterRemoveLiquidityReturnsDelta: false }) ); } @@ -53,28 +57,28 @@ contract CLCounterHook is CLBaseHook { ICLPoolManager.ModifyLiquidityParams calldata, BalanceDelta, bytes calldata - ) external override poolManagerOnly returns (bytes4) { + ) external override poolManagerOnly returns (bytes4, BalanceDelta) { afterAddLiquidityCount[key.toId()]++; - return this.afterAddLiquidity.selector; + return (this.afterAddLiquidity.selector, BalanceDeltaLibrary.ZERO_DELTA); } function beforeSwap(address, PoolKey calldata key, ICLPoolManager.SwapParams calldata, bytes calldata) external override poolManagerOnly - returns (bytes4) + returns (bytes4, BeforeSwapDelta, uint24) { beforeSwapCount[key.toId()]++; - return this.beforeSwap.selector; + return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0); } function afterSwap(address, PoolKey calldata key, ICLPoolManager.SwapParams calldata, BalanceDelta, bytes calldata) external override poolManagerOnly - returns (bytes4) + returns (bytes4, int128) { afterSwapCount[key.toId()]++; - return this.afterSwap.selector; + return (this.afterSwap.selector, 0); } } diff --git a/test/pool-bin/utils/BinTestUtils.sol b/test/pool-bin/utils/BinTestUtils.sol index dfa567b..f9f577f 100644 --- a/test/pool-bin/utils/BinTestUtils.sol +++ b/test/pool-bin/utils/BinTestUtils.sol @@ -25,7 +25,7 @@ contract BinTestUtils { function deployContractsWithTokens() internal returns (Currency, Currency) { vault = new Vault(); poolManager = new BinPoolManager(vault, 500000); - vault.registerPoolManager(address(poolManager)); + vault.registerApp(address(poolManager)); positionManager = new BinFungiblePositionManager(vault, poolManager, address(0)); swapRouter = new BinSwapRouter(vault, poolManager, address(0)); diff --git a/test/pool-cl/utils/CLTestUtils.sol b/test/pool-cl/utils/CLTestUtils.sol index b7a2f57..a3fa2ee 100644 --- a/test/pool-cl/utils/CLTestUtils.sol +++ b/test/pool-cl/utils/CLTestUtils.sol @@ -22,7 +22,7 @@ contract CLTestUtils { function deployContractsWithTokens() internal returns (Currency, Currency) { vault = new Vault(); poolManager = new CLPoolManager(vault, 500000); - vault.registerPoolManager(address(poolManager)); + vault.registerApp(address(poolManager)); nfp = new NonfungiblePositionManager(vault, poolManager, address(0), address(0)); swapRouter = new CLSwapRouter(vault, poolManager, address(0)); @@ -46,6 +46,7 @@ contract CLTestUtils { poolKey: key, tickLower: tickLower, tickUpper: tickUpper, + salt: bytes32(0), amount0Desired: amount0, amount1Desired: amount1, amount0Min: 0,