Skip to content

Commit

Permalink
update burn
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds committed Jun 28, 2024
1 parent 2299f83 commit 9eaffcd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 5 additions & 2 deletions contracts/NonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,17 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit
isAuthorizedForToken(tokenId)
returns (BalanceDelta delta)
{
// TODO: Burn currently decreases and collects. However its done under different locks.
// Replace once we have the execute multicall.
// remove liquidity
TokenPosition storage tokenPosition = tokenPositions[tokenId];
LiquidityRangeId rangeId = tokenPosition.range.toId();
Position storage position = positions[msg.sender][rangeId];
if (0 < position.liquidity) {
if (position.liquidity > 0) {
(delta,) = decreaseLiquidity(tokenId, position.liquidity, hookData, claims);
(delta) = collect(tokenId, recipient, hookData, claims);
}

collect(tokenId, recipient, hookData, claims);
require(position.tokensOwed0 == 0 && position.tokensOwed1 == 0, "NOT_EMPTY");
delete positions[msg.sender][rangeId];
delete tokenPositions[tokenId];
Expand Down
20 changes: 11 additions & 9 deletions contracts/base/BaseLiquidityManagement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,20 @@ contract BaseLiquidityManagement is IBaseLiquidityManagement, SafeCallback {
internal
returns (BalanceDelta callerDelta, BalanceDelta thisDelta)
{
// Do not add or decrease liquidity, just trigger fee updates.
// TODO: Fails when position is empty
(BalanceDelta liquidityDelta, BalanceDelta totalFeesAccrued) = _modifyLiquidity(owner, range, 0, hookData);

Position storage position = positions[owner][range.toId()];

// Also updates the position's the feeGrowthInsideLast variables in storage.
(BalanceDelta callerFeesAccrued) = _updateFeeGrowth(range, position);
// Only call modify if there is still liquidty in this position.
if (position.liquidity != 0) {
// Do not add or decrease liquidity, just trigger fee updates.
(BalanceDelta liquidityDelta, BalanceDelta totalFeesAccrued) = _modifyLiquidity(owner, range, 0, hookData);

// Account for fees accrued to other users on the same range.
// TODO: Opt when liquidityDelta == 0
(callerDelta, thisDelta) = liquidityDelta.split(callerFeesAccrued, totalFeesAccrued);
// Also updates the position's the feeGrowthInsideLast variables in storage.
(BalanceDelta callerFeesAccrued) = _updateFeeGrowth(range, position);

// Account for fees accrued to other users on the same range.
// TODO: Opt when liquidityDelta == 0
(callerDelta, thisDelta) = liquidityDelta.split(callerFeesAccrued, totalFeesAccrued);
}

// Allow the caller to collect the tokens owed.
// Tokens owed that the caller collects is paid for by this contract.
Expand Down
2 changes: 2 additions & 0 deletions test/position-managers/FeeCollection.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ contract FeeCollectionTest is Test, Deployers, GasSnapshot, LiquidityFuzzers {

/// @dev Alice and bob create liquidity on the same range
/// when alice decreases liquidity, she should only collect her fees
/// TODO Add back fuzz test on liquidityDeltaBob
/// TODO Assert state changes for lpm balance, position state, and return values
function test_decreaseLiquidity_sameRange_exact() public {
// alice and bob create liquidity on the same range [-120, 120]
LiquidityRange memory range = LiquidityRange({poolKey: key, tickLower: -120, tickUpper: 120});
Expand Down

0 comments on commit 9eaffcd

Please sign in to comment.