Skip to content

Commit

Permalink
feat: updated v4-core / v4-periphery (#3)
Browse files Browse the repository at this point in the history
* feat: updated v4-core / v4-periphery

* refactor: line break for foundry.tml
  • Loading branch information
ChefMist authored Jun 18, 2024
1 parent a597fdd commit b56ae5b
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 37 deletions.
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ out = 'foundry-out'
solc_version = '0.8.24'
libs = ["lib"]
evm_version = 'cancun'
via_ir = true
2 changes: 1 addition & 1 deletion lib/pancake-v4-core
Submodule pancake-v4-core updated 248 files
2 changes: 1 addition & 1 deletion lib/pancake-v4-periphery
30 changes: 22 additions & 8 deletions src/pool-bin/BinBaseHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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)
);
}
}
24 changes: 14 additions & 10 deletions src/pool-bin/BinCounterHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -32,7 +33,10 @@ contract BinCounterHook is BinBaseHook {
afterSwap: true,
beforeDonate: false,
afterDonate: false,
noOp: false
beforeSwapReturnsDelta: false,
afterSwapReturnsDelta: false,
afterMintReturnsDelta: false,
afterBurnReturnsDelta: false
})
);
}
Expand All @@ -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);
}
}
24 changes: 17 additions & 7 deletions src/pool-cl/CLBaseHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down Expand Up @@ -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();
}

Expand All @@ -138,22 +145,22 @@ 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();
}

function afterSwap(address, PoolKey calldata, ICLPoolManager.SwapParams calldata, BalanceDelta, bytes calldata)
external
virtual
returns (bytes4)
returns (bytes4, int128)
{
revert HookNotImplemented();
}
Expand Down Expand Up @@ -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)
);
}
}
20 changes: 12 additions & 8 deletions src/pool-cl/CLCounterHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -32,7 +33,10 @@ contract CLCounterHook is CLBaseHook {
afterSwap: true,
beforeDonate: false,
afterDonate: false,
noOp: false
beforeSwapReturnsDelta: false,
afterSwapReturnsDelta: false,
afterAddLiquidityReturnsDelta: false,
afterRemoveLiquidityReturnsDelta: false
})
);
}
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion test/pool-bin/utils/BinTestUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion test/pool-cl/utils/CLTestUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -46,6 +46,7 @@ contract CLTestUtils {
poolKey: key,
tickLower: tickLower,
tickUpper: tickUpper,
salt: bytes32(0),
amount0Desired: amount0,
amount1Desired: amount1,
amount0Min: 0,
Expand Down

0 comments on commit b56ae5b

Please sign in to comment.