Skip to content

Commit

Permalink
feat: example of option 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Nov 11, 2024
1 parent 15b5220 commit a761527
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178130
178365
2 changes: 1 addition & 1 deletion .forge-snapshots/BinMintBurnFeeHookTest#test_Burn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170145
170380
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerBytecodeSize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23287
23381
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133892
134080
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142717
142975
Original file line number Diff line number Diff line change
@@ -1 +1 @@
289683
291375
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
127065
127253
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149710
149698
9 changes: 9 additions & 0 deletions src/pool-bin/libraries/BinPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ library BinPool {
error BinPool__NoLiquidityToReceiveFees();
/// @dev if swap exactIn, x for y, unspecifiedToken = token y. if swap x for exact out y, unspecified token is x
error BinPool__InsufficientAmountUnSpecified();
error BinPool__BelowMinimumShareInBurn(uint256 balanceShare);

/// @dev The state of a pool
struct State {
Expand All @@ -66,6 +67,9 @@ library BinPool {
mapping(bytes32 => bytes32) level2;
}

/// @dev when liquidity is removed, ensure there is either greater than min_share or 0 liquidity left
uint256 constant MINIMUM_SHARE = 1e3;

function initialize(State storage self, uint24 activeId, uint24 protocolFee, uint24 lpFee) internal {
/// An initialized pool will not have activeId: 0
if (self.slot0.activeId() != 0) revert PoolAlreadyInitialized();
Expand Down Expand Up @@ -464,6 +468,11 @@ library BinPool {
function _subShare(State storage self, address owner, uint24 binId, bytes32 salt, uint256 shares) internal {
self.positions.get(owner, binId, salt).subShare(shares);
self.shareOfBin[binId] -= shares;

uint256 balanceShare = self.shareOfBin[binId];
if (balanceShare > 0 && balanceShare < MINIMUM_SHARE) {
revert BinPool__BelowMinimumShareInBurn(balanceShare);
}
}

/// @notice Add share to user's position and update total share supply of bin
Expand Down
5 changes: 3 additions & 2 deletions test/pool-bin/libraries/BinPoolDonate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ contract BinPoolDonateTest is BinTestHelper {
poolManager.initialize(key, activeId);
addLiquidityToBin(key, poolManager, alice, activeId, 1e18, 1e18, 1e18, 1e18, "");

// Remove all share leaving less than MIN_LIQUIDITY_BEFORE_DONATE shares
remainingShare = bound(remainingShare, 1, poolManager.minBinShareForDonate() - 1);
/// @dev Remove all share leaving between 1e3 and minShareForDinate
/// if its less than 1e3, it will throw BinPool__BelowMinimumShareInBurn error
remainingShare = bound(remainingShare, 1e3, poolManager.minBinShareForDonate() - 1);
uint256 aliceShare = poolManager.getPosition(poolId, alice, activeId, 0).share;
removeLiquidityFromBin(key, poolManager, alice, activeId, aliceShare - remainingShare, "");

Expand Down

0 comments on commit a761527

Please sign in to comment.