Skip to content

Commit

Permalink
clean up unused imports etc..
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Jun 21, 2024
1 parent 3f462be commit 7113492
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
38 changes: 19 additions & 19 deletions src/pool-cl/VeCakeMembershipHook.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {LPFeeLibrary} from "@pancakeswap/v4-core/src/libraries/LPFeeLibrary.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 {Currency} from "@pancakeswap/v4-core/src/types/Currency.sol";
import {CurrencySettlement} from "@pancakeswap/v4-core/test/helpers/CurrencySettlement.sol";
import {ICLPoolManager} from "@pancakeswap/v4-core/src/pool-cl/interfaces/ICLPoolManager.sol";
import {CLBaseHook} from "./CLBaseHook.sol";

import {LPFeeLibrary} from "@pancakeswap/v4-core/src/libraries/LPFeeLibrary.sol";
import {Currency} from "@pancakeswap/v4-core/src/types/Currency.sol";
import {CurrencySettlement} from "@pancakeswap/v4-core/test/helpers/CurrencySettlement.sol";

interface IVeCake {
function balanceOf(address account) external view returns (uint256 balance);
}
Expand All @@ -21,11 +22,10 @@ interface IVeCake {
contract VeCakeMembershipHook is CLBaseHook {
using CurrencySettlement for Currency;
using PoolIdLibrary for PoolKey;
using LPFeeLibrary for uint24;

IVeCake public veCake;
uint256 public promoEndDate;
mapping(PoolId => uint24) public poolIdToLpFee;
uint256 public promoEndDate;

constructor(ICLPoolManager _poolManager, address _veCake) CLBaseHook(_poolManager) {
veCake = IVeCake(_veCake);
Expand All @@ -52,14 +52,13 @@ contract VeCakeMembershipHook is CLBaseHook {
);
}

/// @dev Get the intended lpFee for this pool and store in mapping
function afterInitialize(address, PoolKey calldata key, uint160, int24, bytes calldata hookData)
external
override
returns (bytes4)
{
(uint24 lpFee) = abi.decode(hookData, (uint24));
poolIdToLpFee[key.toId()] = lpFee;
uint24 swapFee = abi.decode(hookData, (uint24));
poolIdToLpFee[key.toId()] = swapFee;

promoEndDate = block.timestamp + 1 hours;
return this.afterInitialize.selector;
Expand All @@ -71,10 +70,16 @@ contract VeCakeMembershipHook is CLBaseHook {
poolManagerOnly
returns (bytes4, BeforeSwapDelta, uint24)
{
/// If within promo endDate and veCake holder, lpFee is 0
uint24 lpFee =
block.timestamp < promoEndDate && veCake.balanceOf(tx.origin) >= 1 ether ? 0 : poolIdToLpFee[key.toId()];
// return early if promo has ended
if (block.timestamp > promoEndDate) {
return (
this.beforeSwap.selector,
BeforeSwapDeltaLibrary.ZERO_DELTA,
poolIdToLpFee[key.toId()] | LPFeeLibrary.OVERRIDE_FEE_FLAG
);
}

uint24 lpFee = veCake.balanceOf(tx.origin) >= 1 ether ? 0 : poolIdToLpFee[key.toId()];
return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, lpFee | LPFeeLibrary.OVERRIDE_FEE_FLAG);
}

Expand All @@ -84,17 +89,12 @@ contract VeCakeMembershipHook is CLBaseHook {
ICLPoolManager.SwapParams calldata param,
BalanceDelta delta,
bytes calldata
) external override returns (bytes4, int128) {
) external override poolManagerOnly 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.
/// 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;
Expand Down
14 changes: 7 additions & 7 deletions test/pool-cl/VeCakeMembershipHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {Test} from "forge-std/Test.sol";
import {Constants} from "@pancakeswap/v4-core/test/pool-cl/helpers/Constants.sol";
import {Currency} from "@pancakeswap/v4-core/src/types/Currency.sol";
import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.sol";
import {LPFeeLibrary} from "@pancakeswap/v4-core/src/libraries/LPFeeLibrary.sol";
import {CLPoolParametersHelper} from "@pancakeswap/v4-core/src/pool-cl/libraries/CLPoolParametersHelper.sol";
import {VeCakeMembershipHook} from "../../src/pool-cl/VeCakeMembershipHook.sol";
import {CLTestUtils} from "./utils/CLTestUtils.sol";
import {CLPoolParametersHelper} from "@pancakeswap/v4-core/src/pool-cl/libraries/CLPoolParametersHelper.sol";
import {PoolIdLibrary} from "@pancakeswap/v4-core/src/types/PoolId.sol";
import {ICLSwapRouterBase} from "pancake-v4-periphery/src/pool-cl/interfaces/ICLSwapRouterBase.sol";
import {ICLSwapRouterBase} from "@pancakeswap/v4-periphery/src/pool-cl/interfaces/ICLSwapRouterBase.sol";

import {console2} from "forge-std/console2.sol";
import {VeCakeMembershipHook} from "../../src/pool-cl/VeCakeMembershipHook.sol";
import {LPFeeLibrary} from "@pancakeswap/v4-core/src/libraries/LPFeeLibrary.sol";

contract VeCakeMembershipHookTest is Test, CLTestUtils {
using PoolIdLibrary for PoolKey;
Expand Down Expand Up @@ -80,14 +80,14 @@ contract VeCakeMembershipHookTest is Test, CLTestUtils {
assertLe(amtOut, 0.997 ether);
}

function testVeCakeHolderX() public {
function testVeCakeHolder() public {
// mint alice veCake
veCake.mint(address(alice), 1 ether);

uint256 amtOut = _swap();

// amount out is more than amtIn to indicate hook has given some extra tokenOut
assertGt(amtOut, 1 ether);
// amount out is almost 1.05 due to the 5% subsidy from hook and 0% swap fee
assertGt(amtOut, 1.04 ether);
}

function _swap() internal returns (uint256 amtOut) {
Expand Down

0 comments on commit 7113492

Please sign in to comment.