Skip to content

Commit ae9424a

Browse files
kulkarohanclaude[bot]oveddan
authored
feat(coins): check fee growth inside lps before collecting (#1385)
* feat(coins): check fee growth inside lps before collecting * chore: add changeset * chore: lint * fix: add missing package specification to changeset Co-authored-by: Dan Oved <[email protected]> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Dan Oved <[email protected]>
1 parent 7ec6134 commit ae9424a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.changeset/many-cows-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zoralabs/coins": patch
3+
---
4+
5+
Ignore collecting from liquidity positions with empty fee growth

packages/coins/src/libs/V4Liquidity.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ library V4Liquidity {
167167
continue;
168168
}
169169

170+
// skip lps with no fees to collect
171+
(uint256 feeGrowthInside0DeltaX128, uint256 feeGrowthInside1DeltaX128) = getFeeGrowth(poolManager, poolKey, positions[i]);
172+
if (feeGrowthInside0DeltaX128 == 0 && feeGrowthInside1DeltaX128 == 0) {
173+
continue;
174+
}
175+
170176
params = ModifyLiquidityParams({
171177
tickLower: positions[i].tickLower,
172178
tickUpper: positions[i].tickUpper,
@@ -221,6 +227,30 @@ library V4Liquidity {
221227
liquidity = StateLibrary.getPositionLiquidity(poolManager, poolKey.toId(), positionId);
222228
}
223229

230+
function getFeeGrowth(
231+
IPoolManager poolManager,
232+
PoolKey memory poolKey,
233+
LpPosition memory position
234+
) private view returns (uint256 feeGrowthInside0DeltaX128, uint256 feeGrowthInside1DeltaX128) {
235+
(, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128) = StateLibrary.getPositionInfo(
236+
poolManager,
237+
poolKey.toId(),
238+
address(this),
239+
position.tickLower,
240+
position.tickUpper,
241+
bytes32(0)
242+
);
243+
(uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = StateLibrary.getFeeGrowthInside(
244+
poolManager,
245+
poolKey.toId(),
246+
position.tickLower,
247+
position.tickUpper
248+
);
249+
250+
feeGrowthInside0DeltaX128 = feeGrowthInside0X128 - feeGrowthInside0LastX128;
251+
feeGrowthInside1DeltaX128 = feeGrowthInside1X128 - feeGrowthInside1LastX128;
252+
}
253+
224254
function mintPositions(IPoolManager poolManager, PoolKey memory poolKey, LpPosition[] memory positions) internal returns (int128 amount0, int128 amount1) {
225255
ModifyLiquidityParams memory params;
226256
uint256 numPositions = positions.length;

0 commit comments

Comments
 (0)