Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Jun 20, 2024
1 parent d622a56 commit 23642f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pool-cl/VeCakeMembershipHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ contract VeCakeMembershipHook is CLBaseHook {

constructor(ICLPoolManager _poolManager, address _veCake) CLBaseHook(_poolManager) {
veCake = IVeCake(_veCake);
promoEndDate = block.timestamp + 1 hours;
}

function getHooksRegistrationBitmap() external pure override returns (uint16) {
Expand Down Expand Up @@ -64,6 +63,7 @@ contract VeCakeMembershipHook is CLBaseHook {
(uint24 lpFee) = abi.decode(hookData, (uint24));
poolIdToLpFee[key.toId()] = lpFee;

promoEndDate = block.timestamp + 1 hours;
return this.afterInitialize.selector;
}

Expand Down
19 changes: 16 additions & 3 deletions src/pool-cl/VeCakeSwapDiscountHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ interface IVeCake {
}

/// @notice VeCakeSwapDiscountHook provides 50% swap fee discount for veCake holder
/// Idea: 1. PancakeSwap has veCake (vote-escrowed Cake), user obtain veCake by locking cake
/// 2. If the swapper holds veCake, provide 50% swap fee discount
/// Idea:
/// 1. PancakeSwap has veCake (vote-escrowed Cake), user obtain veCake by locking cake
/// 2. If the swapper holds veCake, provide 50% swap fee discount
/// Implementation:
/// 1. When pool is initialized, at `afterInitialize` we store what is the intended swap fee for the pool
// 2. During `beforeSwap` callback, the hook checks if users is veCake holder and provide discount accordingly
contract VeCakeSwapDiscountHook is CLBaseHook {
using PoolIdLibrary for PoolKey;
using LPFeeLibrary for uint24;
Expand Down Expand Up @@ -47,18 +51,27 @@ contract VeCakeSwapDiscountHook is CLBaseHook {
);
}

/// @dev Get the intended lpFee for this pool and store in mapping
/// @notice The hook called after the state of a pool is initialized
/// @return bytes4 The function selector for the hook
function afterInitialize(address, PoolKey calldata key, uint160, int24, bytes calldata hookData)
external
override
returns (bytes4)
{
// Get the intended lpFee for this pool and store in mapping
uint24 lpFee = abi.decode(hookData, (uint24));
poolIdToLpFee[key.toId()] = lpFee;

return this.afterInitialize.selector;
}

/// @notice The hook called before a swap
/// @return bytes4 The function selector for the hook
/// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies.
/// @return uint24 Optionally override the lp fee, only used if three conditions are met:
/// 1) the Pool has a dynamic fee,
/// 2) the value's override flag is set to 1 i.e. vaule & OVERRIDE_FEE_FLAG = 0x400000 != 0
/// 3) the value is less than or equal to the maximum fee (1 million)
function beforeSwap(address, PoolKey calldata key, ICLPoolManager.SwapParams calldata, bytes calldata)
external
override
Expand Down
2 changes: 1 addition & 1 deletion test/pool-cl/VeCakeSwapDiscountHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract VeCakeSwapDiscountHookTest is Test, CLTestUtils {
parameters: bytes32(uint256(hook.getHooksRegistrationBitmap())).setTickSpacing(10)
});

// initialize pool at 1:1 price point and set 3000 as initial lp fee, lpFee is stored in the hook
// initialize pool at 1:1 price point and set 3000 (0.3%) as lp fee, lpFee is stored in the hook
poolManager.initialize(key, Constants.SQRT_RATIO_1_1, abi.encode(uint24(3000)));

// add liquidity so that swap can happen
Expand Down

0 comments on commit 23642f2

Please sign in to comment.