From 84de2e2a6c16b45622a86e756e34772761d23387 Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:13:10 +0800 Subject: [PATCH] feat: Add pause to BinPoolManager --- ...inHookTest#testDonateSucceedsWithHook.snap | 2 +- .../BinHookTest#testMintSucceedsWithHook.snap | 2 +- .../BinHookTest#testSwapSucceedsWithHook.snap | 2 +- .../BinPoolManagerTest#testGasDonate.snap | 2 +- ...nPoolManagerTest#testGasMintNneBins-1.snap | 2 +- ...nPoolManagerTest#testGasMintNneBins-2.snap | 2 +- ...inPoolManagerTest#testGasMintOneBin-1.snap | 2 +- ...inPoolManagerTest#testGasMintOneBin-2.snap | 2 +- ...olManagerTest#testGasSwapMultipleBins.snap | 2 +- ...nagerTest#testGasSwapOverBigBinIdGate.snap | 2 +- ...nPoolManagerTest#testGasSwapSingleBin.snap | 2 +- ...oolManagerTest#testMintNativeCurrency.snap | 2 +- ...BinPoolManagerTest#testNoOpGas_Donate.snap | 2 +- .../BinPoolManagerTest#testNoOpGas_Mint.snap | 2 +- .../BinPoolManagerTest#testNoOpGas_Swap.snap | 2 +- src/pool-bin/BinPoolManager.sol | 3 + test/pool-bin/BinPoolManager.t.sol | 83 +++++++++++++++++++ 17 files changed, 101 insertions(+), 15 deletions(-) diff --git a/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap index fcf5c059..9f091e53 100644 --- a/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap @@ -1 +1 @@ -134890 \ No newline at end of file +135032 \ No newline at end of file diff --git a/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap index dedd16e3..a06322b0 100644 --- a/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap @@ -1 +1 @@ -298927 \ No newline at end of file +301069 \ No newline at end of file diff --git a/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap index 7a7c6ab5..07f1a25b 100644 --- a/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap @@ -1 +1 @@ -141133 \ No newline at end of file +141275 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap b/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap index 2a54c995..ed1259c2 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap @@ -1 +1 @@ -53974 \ No newline at end of file +54221 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap index 66abbd6e..dee5f7eb 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap @@ -1 +1 @@ -968069 \ No newline at end of file +970211 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap index 1f192157..87abc625 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap @@ -1 +1 @@ -121583 \ No newline at end of file +121725 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap index 5bde9de4..1a6589a9 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap @@ -1 +1 @@ -337259 \ No newline at end of file +339401 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap index 612b90fc..0a9f433f 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap @@ -1 +1 @@ -56320 \ No newline at end of file +56462 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap index 18a4592a..fc933d28 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap @@ -1 +1 @@ -93084 \ No newline at end of file +93238 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap index e9bae811..4f7345a4 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap @@ -1 +1 @@ -95069 \ No newline at end of file +95223 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap index 70a7b26b..8d4f2e00 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap @@ -1 +1 @@ -74513 \ No newline at end of file +74667 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap b/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap index 26f291e2..839f2405 100644 --- a/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap +++ b/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap @@ -1 +1 @@ -318967 \ No newline at end of file +321109 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap index 976fd115..6f7169e0 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap @@ -1 +1 @@ -19515 \ No newline at end of file +19774 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap index 5dd23c23..dfa647e1 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap @@ -1 +1 @@ -37367 \ No newline at end of file +39509 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap index 158be14c..afc7e3e9 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap @@ -1 +1 @@ -22743 \ No newline at end of file +22897 \ No newline at end of file diff --git a/src/pool-bin/BinPoolManager.sol b/src/pool-bin/BinPoolManager.sol index 38c413d4..23b377d1 100644 --- a/src/pool-bin/BinPoolManager.sol +++ b/src/pool-bin/BinPoolManager.sol @@ -140,6 +140,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload { external override poolManagerMatch(address(key.poolManager)) + whenNotPaused returns (BalanceDelta delta) { PoolId id = key.toId(); @@ -241,6 +242,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload { external override poolManagerMatch(address(key.poolManager)) + whenNotPaused returns (BalanceDelta delta, BinPool.MintArrays memory mintArray) { PoolId id = key.toId(); @@ -329,6 +331,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload { external override poolManagerMatch(address(key.poolManager)) + whenNotPaused returns (BalanceDelta delta, uint24 binId) { PoolId id = key.toId(); diff --git a/test/pool-bin/BinPoolManager.t.sol b/test/pool-bin/BinPoolManager.t.sol index 15e3a6e4..1ae2737e 100644 --- a/test/pool-bin/BinPoolManager.t.sol +++ b/test/pool-bin/BinPoolManager.t.sol @@ -821,6 +821,89 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper { vm.stopPrank(); } + function testSwap_WhenPaused() public { + BinSwapHelper.TestSettings memory testSettings; + + // initialize the pool + poolManager.initialize(key, activeId, new bytes(0)); + + // mint + token0.mint(address(this), 10 ether); + token1.mint(address(this), 10 ether); + IBinPoolManager.MintParams memory mintParams = _getSingleBinMintParams(activeId, 10 ether, 10 ether); + binLiquidityHelper.mint(key, mintParams, ""); + + // pause + poolManager.pause(); + + // attempt swap + token0.mint(address(this), 1 ether); + vm.expectRevert("Pausable: paused"); + testSettings = BinSwapHelper.TestSettings({withdrawTokens: false, settleUsingTransfer: true}); + binSwapHelper.swap(key, true, 1 ether, testSettings, ""); + } + + function testMint_WhenPaused() public { + token0.mint(address(this), 1 ether); + token1.mint(address(this), 1 ether); + + poolManager.initialize(key, activeId, new bytes(0)); + IBinPoolManager.MintParams memory mintParams; + + // add 1 eth of tokenX and 1 eth of tokenY liquidity at activeId + mintParams = _getSingleBinMintParams(activeId, 1 ether, 1 ether); + + // pause + poolManager.pause(); + + vm.expectRevert("Pausable: paused"); + binLiquidityHelper.mint(key, mintParams, ""); + } + + // verify remove liquidity is fine when paused + function testBurn_WhenPaused() public { + // initialize + poolManager.initialize(key, activeId, new bytes(0)); + + // mint + token0.mint(address(this), 2 ether); + token1.mint(address(this), 2 ether); + IBinPoolManager.MintParams memory mintParams = _getSingleBinMintParams(activeId, 1 ether, 1 ether); + binLiquidityHelper.mint(key, mintParams, ""); + + // pause + poolManager.pause(); + + // burn + IBinPoolManager.BurnParams memory burnParams = + _getSingleBinBurnLiquidityParams(key, poolManager, activeId, address(binLiquidityHelper), 100); + + uint256[] memory ids = new uint256[](1); + bytes32[] memory amounts = new bytes32[](1); + ids[0] = activeId; + amounts[0] = uint128(1e18).encode(uint128(1e18)); + + // verify no issue even when pause + binLiquidityHelper.burn(key, burnParams, ""); + } + + function testDonate_WhenPaused() public { + poolManager.initialize(key, activeId, new bytes(0)); + + token0.mint(address(this), 11 ether); + token1.mint(address(this), 11 ether); + + // add 1 eth of tokenX and 1 eth of tokenY liquidity at activeId + IBinPoolManager.MintParams memory mintParams = _getSingleBinMintParams(activeId, 1 ether, 1 ether); + binLiquidityHelper.mint(key, mintParams, ""); + + // pause + poolManager.pause(); + + vm.expectRevert("Pausable: paused"); + binDonateHelper.donate(key, 10 ether, 10 ether, ""); + } + receive() external payable {} function supportsInterface(bytes4) external pure returns (bool) {