Skip to content

Commit

Permalink
posm takes as 6909; remove legacy deadcode
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Jul 1, 2024
1 parent 2637b6e commit c87b0ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 52 deletions.
4 changes: 2 additions & 2 deletions contracts/NonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit
// close the deltas
int128[] memory returnData = new int128[](currencies.length);
for (uint256 i; i < currencies.length; i++) {
returnData[i] = currencies[i].close(manager, msgSender);
currencies[i].close(manager, address(this));
returnData[i] = currencies[i].close(manager, msgSender, false); // TODO: support claims
currencies[i].close(manager, address(this), true); // position manager always takes 6909
}

// Should just be returning the netted amount that was settled on behalf of the caller (msgSender)
Expand Down
39 changes: 1 addition & 38 deletions contracts/base/BaseLiquidityManagement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,6 @@ abstract contract BaseLiquidityManagement is IBaseLiquidityManagement, SafeCallb

function _msgSenderInternal() internal virtual returns (address);

function _closeCallerDeltas(
BalanceDelta callerDeltas,
Currency currency0,
Currency currency1,
address owner,
bool claims
) internal {
int128 callerDelta0 = callerDeltas.amount0();
int128 callerDelta1 = callerDeltas.amount1();
// On liquidity increase, the deltas should never be > 0.
// We always 0 out a caller positive delta because it is instead accounted for in position.tokensOwed.

if (callerDelta0 < 0) currency0.settle(manager, owner, uint256(int256(-callerDelta0)), claims);
else if (callerDelta0 > 0) currency0.take(manager, owner, uint128(callerDelta0), claims);

if (callerDelta1 < 0) currency1.settle(manager, owner, uint256(int256(-callerDelta1)), claims);
else if (callerDelta1 > 0) currency1.take(manager, owner, uint128(callerDelta1), claims);

owner.close(currency0, currency1);
}

function _modifyLiquidity(address owner, LiquidityRange memory range, int256 liquidityChange, bytes memory hookData)
internal
returns (BalanceDelta liquidityDelta, BalanceDelta totalFeesAccrued)
Expand Down Expand Up @@ -131,22 +110,6 @@ abstract contract BaseLiquidityManagement is IBaseLiquidityManagement, SafeCallb
position.addLiquidity(liquidityToAdd);
}

// When chaining many actions, this should be called at the very end to close out any open deltas owed to or by this contract for other users on the same range.
// This is safe because any amounts the caller should not pay or take have already been accounted for in closeCallerDeltas.
function _closeThisDeltas(BalanceDelta delta, Currency currency0, Currency currency1) internal {
int128 delta0 = delta.amount0();
int128 delta1 = delta.amount1();

// Mint a receipt for the tokens owed to this address.
if (delta0 > 0) currency0.take(manager, address(this), uint128(delta0), true);
if (delta1 > 0) currency1.take(manager, address(this), uint128(delta1), true);
// Burn the receipt for tokens owed to this address.
if (delta0 < 0) currency0.settle(manager, address(this), uint256(int256(-delta0)), true);
if (delta1 < 0) currency1.settle(manager, address(this), uint256(int256(-delta1)), true);

address(this).close(currency0, currency1);
}

function _moveCallerDeltaToTokensOwed(
bool useAmount0,
BalanceDelta tokensOwed,
Expand Down Expand Up @@ -236,7 +199,7 @@ abstract contract BaseLiquidityManagement is IBaseLiquidityManagement, SafeCallb
if (recipient == _msgSenderInternal()) {
callerDelta.flush(recipient, range.poolKey.currency0, range.poolKey.currency1);
} else {
callerDelta.closeDelta(manager, recipient, range.poolKey.currency0, range.poolKey.currency1);
callerDelta.closeDelta(manager, recipient, range.poolKey.currency0, range.poolKey.currency1, false); // TODO: allow recipient to receive claims, and add test!
}
thisDelta.flush(address(this), range.poolKey.currency0, range.poolKey.currency1);

Expand Down
22 changes: 10 additions & 12 deletions contracts/libraries/TransientLiquidityDelta.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ library TransientLiquidityDelta {
}
}

function close(address holder, Currency currency0, Currency currency1) internal {
setDelta(currency0, holder, 0);
setDelta(currency1, holder, 0);
}

/// @notice Flush a BalanceDelta into transient storage for a given holder
function flush(BalanceDelta delta, address holder, Currency currency0, Currency currency1) internal {
addDelta(currency0, holder, delta.amount0());
Expand All @@ -54,18 +49,20 @@ library TransientLiquidityDelta {
}
}

function close(Currency currency, IPoolManager manager, address holder) internal returns (int128 delta) {
function close(Currency currency, IPoolManager manager, address holder, bool claims)
internal
returns (int128 delta)
{
// getDelta(currency, holder);
bytes32 hashSlot = _computeSlot(holder, currency);
assembly {
delta := tload(hashSlot)
}

// TODO support claims field
if (delta < 0) {
currency.settle(manager, holder, uint256(-int256(delta)), false);
currency.settle(manager, holder, uint256(-int256(delta)), claims);
} else {
currency.take(manager, holder, uint256(int256(delta)), false);
currency.take(manager, holder, uint256(int256(delta)), claims);
}

// setDelta(0);
Expand All @@ -79,10 +76,11 @@ library TransientLiquidityDelta {
IPoolManager manager,
address holder,
Currency currency0,
Currency currency1
Currency currency1,
bool claims
) internal {
close(currency0, manager, holder);
close(currency1, manager, holder);
close(currency0, manager, holder, claims);
close(currency1, manager, holder, claims);
}

function getBalanceDelta(address holder, Currency currency0, Currency currency1)
Expand Down

0 comments on commit c87b0ad

Please sign in to comment.