Skip to content

Commit

Permalink
forge fmt && fix a bug in veCakeMembership hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Jun 21, 2024
1 parent b9131f6 commit 3f462be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/pool-cl/VeCakeMembershipHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract VeCakeMembershipHook is CLBaseHook {
beforeDonate: false,
afterDonate: false,
beforeSwapReturnsDelta: false,
afterSwapReturnsDelta: true,
afterSwapReturnsDelta: true,
afterAddLiquidityReturnsDelta: false,
afterRemoveLiquidityReturnsDelta: false
})
Expand Down Expand Up @@ -85,17 +85,18 @@ 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);
}

/// @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
Expand Down
2 changes: 1 addition & 1 deletion src/pool-cl/VeCakeSwapDiscountHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/pool-cl/VeCakeMembershipHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 3f462be

Please sign in to comment.