From 3f462beab5651b32db310f7972227ad79f2c5612 Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:54:26 +0800 Subject: [PATCH] forge fmt && fix a bug in veCakeMembership hook --- src/pool-cl/VeCakeMembershipHook.sol | 11 ++++++----- src/pool-cl/VeCakeSwapDiscountHook.sol | 2 +- test/pool-cl/VeCakeMembershipHook.t.sol | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pool-cl/VeCakeMembershipHook.sol b/src/pool-cl/VeCakeMembershipHook.sol index 21b7634..474bddb 100644 --- a/src/pool-cl/VeCakeMembershipHook.sol +++ b/src/pool-cl/VeCakeMembershipHook.sol @@ -45,7 +45,7 @@ contract VeCakeMembershipHook is CLBaseHook { beforeDonate: false, afterDonate: false, beforeSwapReturnsDelta: false, - afterSwapReturnsDelta: true, + afterSwapReturnsDelta: true, afterAddLiquidityReturnsDelta: false, afterRemoveLiquidityReturnsDelta: false }) @@ -85,7 +85,6 @@ contract VeCakeMembershipHook is CLBaseHook { BalanceDelta delta, bytes calldata ) external override returns (bytes4, int128) { - // return early if promo has ended if (block.timestamp > promoEndDate) { return (this.afterSwap.selector, 0); @@ -93,9 +92,11 @@ contract VeCakeMembershipHook is CLBaseHook { /// @dev this is POC code, do not use for production, this is only for POC. /// Assumption: currency1 is subsidised currency and if veCake user swap token0 for token1, give 5% more token1. - if (param.zeroForOne && veCake.balanceOf(tx.origin) >= 1 ether) { - - // delta.amount1 is positive as zeroForOne + /// zeroForOne: swap token0 for token1 + /// amountSpecified < 0: indicate exactIn token0 for token1. so unspecified token is token1 + /// veCake.balanceOf(tx.origin) >= 1 ether: only veCake holder + if (param.zeroForOne && param.amountSpecified < 0 && veCake.balanceOf(tx.origin) >= 1 ether) { + // delta.amount1 is positive as zeroForOne int128 extraToken = delta.amount1() * 5 / 100; // settle and return negative value to indicate that hook is giving token diff --git a/src/pool-cl/VeCakeSwapDiscountHook.sol b/src/pool-cl/VeCakeSwapDiscountHook.sol index 97e3ef5..a0356a8 100644 --- a/src/pool-cl/VeCakeSwapDiscountHook.sol +++ b/src/pool-cl/VeCakeSwapDiscountHook.sol @@ -13,7 +13,7 @@ interface IVeCake { } /// @notice VeCakeSwapDiscountHook provides 50% swap fee discount for veCake holder -/// Idea: +/// 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: diff --git a/test/pool-cl/VeCakeMembershipHook.t.sol b/test/pool-cl/VeCakeMembershipHook.t.sol index dd58c88..2f5ace7 100644 --- a/test/pool-cl/VeCakeMembershipHook.t.sol +++ b/test/pool-cl/VeCakeMembershipHook.t.sol @@ -57,7 +57,7 @@ contract VeCakeMembershipHookTest is Test, CLTestUtils { // mint alice token for trade later MockERC20(Currency.unwrap(currency0)).mint(address(alice), 100 ether); - // mint currency 1 for hook to give out + // mint currency 1 for hook to give out MockERC20(Currency.unwrap(currency1)).mint(address(hook), 100 ether); }