From 6fcee3ab3046a39fb2596233fe56efac4c9d36f5 Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Thu, 20 Jun 2024 23:14:32 +0800 Subject: [PATCH] refactor: remove VeCakeWhitelistHook --- src/pool-cl/VeCakeWhitelistHook.sol | 68 ------------------ test/pool-cl/VeCakeWhitelistHook.t.sol | 96 -------------------------- 2 files changed, 164 deletions(-) delete mode 100644 src/pool-cl/VeCakeWhitelistHook.sol delete mode 100644 test/pool-cl/VeCakeWhitelistHook.t.sol diff --git a/src/pool-cl/VeCakeWhitelistHook.sol b/src/pool-cl/VeCakeWhitelistHook.sol deleted file mode 100644 index b32c019..0000000 --- a/src/pool-cl/VeCakeWhitelistHook.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.24; - -import {PoolKey} from "@pancakeswap/v4-core/src/types/PoolKey.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"; - -import {console2} from "forge-std/console2.sol"; - -interface IVeCake { - function balanceOf(address account) external view returns (uint256 balance); -} - -/// @notice VeCakeWhitelistHook allows only veCake holder to trade with the pool within the first hour -/// Idea: 1. A PCS partner protocol launch a new protocol by adding liquidity XX-ETH -/// 2. Only veCake holder can buy the token in the first hour and public access will be granted after. -contract VeCakeWhitelistHook is CLBaseHook { - using PoolIdLibrary for PoolKey; - - error PoolNotOpenForPublicTradeYet(); - - IVeCake veCake; - - // The time when public trade starts, before this, only veCake holder can trade - uint256 public publicTradeStartTime; - - constructor(ICLPoolManager _poolManager, address _veCake) CLBaseHook(_poolManager) { - veCake = IVeCake(_veCake); - publicTradeStartTime = block.timestamp + 1 hours; - } - - function getHooksRegistrationBitmap() external pure override returns (uint16) { - return _hooksRegistrationBitmapFrom( - Permissions({ - beforeInitialize: false, - afterInitialize: false, - beforeAddLiquidity: false, - afterAddLiquidity: false, - beforeRemoveLiquidity: false, - afterRemoveLiquidity: false, - beforeSwap: true, - afterSwap: false, - beforeDonate: false, - afterDonate: false, - beforeSwapReturnsDelta: false, - afterSwapReturnsDelta: false, - afterAddLiquidityReturnsDelta: false, - afterRemoveLiquidityReturnsDelta: false - }) - ); - } - - function beforeSwap(address, PoolKey calldata key, ICLPoolManager.SwapParams calldata, bytes calldata) - external - override - poolManagerOnly - returns (bytes4, BeforeSwapDelta, uint24) - { - /// Only allow non veCake holder to trade after publicTradeStartTime - if (block.timestamp < publicTradeStartTime && veCake.balanceOf(tx.origin) < 1 ether) { - revert PoolNotOpenForPublicTradeYet(); - } - - return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0); - } -} diff --git a/test/pool-cl/VeCakeWhitelistHook.t.sol b/test/pool-cl/VeCakeWhitelistHook.t.sol deleted file mode 100644 index b359676..0000000 --- a/test/pool-cl/VeCakeWhitelistHook.t.sol +++ /dev/null @@ -1,96 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.24; - -import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; -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 {CLPoolParametersHelper} from "@pancakeswap/v4-core/src/pool-cl/libraries/CLPoolParametersHelper.sol"; -import {LPFeeLibrary} from "@pancakeswap/v4-core/src/libraries/LPFeeLibrary.sol"; -import {VeCakeWhitelistHook} from "../../src/pool-cl/VeCakeWhitelistHook.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"; - -contract VeCakeWhitelistHookTest is Test, CLTestUtils { - using PoolIdLibrary for PoolKey; - using CLPoolParametersHelper for bytes32; - - VeCakeWhitelistHook hook; - Currency currency0; - Currency currency1; - PoolKey key; - MockERC20 veCake = new MockERC20("veCake", "veCake", 18); - address alice = makeAddr("alice"); - - function setUp() public { - (currency0, currency1) = deployContractsWithTokens(); - hook = new VeCakeWhitelistHook(poolManager, address(veCake)); - - // create the pool key - key = PoolKey({ - currency0: currency0, - currency1: currency1, - hooks: hook, - poolManager: poolManager, - fee: uint24(3000), - parameters: bytes32(uint256(hook.getHooksRegistrationBitmap())).setTickSpacing(10) - }); - - // initialize pool at 1:1 price point - poolManager.initialize(key, Constants.SQRT_RATIO_1_1, new bytes(0)); - - // add liquidity so that swap can happen - MockERC20(Currency.unwrap(currency0)).mint(address(this), 100 ether); - MockERC20(Currency.unwrap(currency1)).mint(address(this), 100 ether); - addLiquidity(key, 100 ether, 100 ether, -60, 60); - - // approve from alice for swap in the test cases below - vm.startPrank(alice); - MockERC20(Currency.unwrap(currency0)).approve(address(swapRouter), type(uint256).max); - MockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max); - vm.stopPrank(); - - // mint alice token for trade later - MockERC20(Currency.unwrap(currency0)).mint(address(alice), 100 ether); - } - - function testNonVeCakeHolder_beforePublicTradeStartTime() public { - vm.expectRevert(VeCakeWhitelistHook.PoolNotOpenForPublicTradeYet.selector); - _swap(); - } - - function testNonVeCakeHolder_afterPublicTradeStartTime() public { - /// proceed to public trade start time - vm.warp(hook.publicTradeStartTime()); - - _swap(); - } - - function testVeCakeHolder() public { - // mint alice veCake - veCake.mint(address(alice), 1 ether); - - _swap(); - } - - function _swap() internal returns (uint256 amtOut) { - // set alice as tx.origin - vm.prank(address(alice), address(alice)); - - amtOut = swapRouter.exactInputSingle( - ICLSwapRouterBase.V4CLExactInputSingleParams({ - poolKey: key, - zeroForOne: true, - recipient: address(alice), - amountIn: 1 ether, - amountOutMinimum: 0, - sqrtPriceLimitX96: 0, - hookData: new bytes(0) - }), - block.timestamp - ); - } -}