Skip to content

Commit

Permalink
feat: Add pause to BinPoolManager
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Apr 8, 2024
1 parent 09f70b7 commit 84de2e2
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134890
135032
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
298927
301069
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141133
141275
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53974
54221
Original file line number Diff line number Diff line change
@@ -1 +1 @@
968069
970211
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121583
121725
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337259
339401
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56320
56462
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93084
93238
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95069
95223
Original file line number Diff line number Diff line change
@@ -1 +1 @@
74513
74667
Original file line number Diff line number Diff line change
@@ -1 +1 @@
318967
321109
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19515
19774
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37367
39509
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22743
22897
3 changes: 3 additions & 0 deletions src/pool-bin/BinPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
external
override
poolManagerMatch(address(key.poolManager))
whenNotPaused
returns (BalanceDelta delta)
{
PoolId id = key.toId();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
83 changes: 83 additions & 0 deletions test/pool-bin/BinPoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 84de2e2

Please sign in to comment.