Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit event to track swap fees #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/pool-cl/NonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,23 @@ contract NonfungiblePositionManager is
/// that's won't cause any issue because existingLiquility = 0
/// unchecked is needed to avoid overflow error
unchecked {
nftPosition.tokensOwed0 += uint128(
uint128 tokensOwed0 = uint128(
FullMath.mulDiv(
poolManagerPositionInfo.feeGrowthInside0LastX128 - nftPosition.feeGrowthInside0LastX128,
existingLiquility,
FixedPoint128.Q128
)
);
nftPosition.tokensOwed1 += uint128(
uint128 tokensOwed1 = uint128(
FullMath.mulDiv(
poolManagerPositionInfo.feeGrowthInside1LastX128 - nftPosition.feeGrowthInside1LastX128,
existingLiquility,
FixedPoint128.Q128
)
);
emit TokensOwed(params.tokenId, tokensOwed0, tokensOwed1);
nftPosition.tokensOwed0 += tokensOwed0;
nftPosition.tokensOwed1 += tokensOwed1;
chef-omelette marked this conversation as resolved.
Show resolved Hide resolved
}

nftPosition.feeGrowthInside0LastX128 = poolManagerPositionInfo.feeGrowthInside0LastX128;
Expand Down Expand Up @@ -353,21 +356,23 @@ contract NonfungiblePositionManager is
/// that's won't cause any issue because existingLiquility = 0
/// unchecked is needed to avoid overflow error
unchecked {
nftPosition.tokensOwed0 += uint128(
uint128 tokensOwed0 = uint128(
FullMath.mulDiv(
poolManagerPositionInfo.feeGrowthInside0LastX128 - nftPosition.feeGrowthInside0LastX128,
liquidity,
FixedPoint128.Q128
)
);

nftPosition.tokensOwed1 += uint128(
uint128 tokensOwed1 = uint128(
FullMath.mulDiv(
poolManagerPositionInfo.feeGrowthInside1LastX128 - nftPosition.feeGrowthInside1LastX128,
liquidity,
FixedPoint128.Q128
)
);
emit TokensOwed(params.tokenId, tokensOwed0, tokensOwed1);
nftPosition.tokensOwed0 += tokensOwed0;
nftPosition.tokensOwed1 += tokensOwed1;
}

nftPosition.feeGrowthInside0LastX128 = poolManagerPositionInfo.feeGrowthInside0LastX128;
Expand Down Expand Up @@ -407,20 +412,23 @@ contract NonfungiblePositionManager is
/// that's won't cause any issue because existingLiquility = 0
/// unchecked is needed to avoid overflow error
unchecked {
tokensOwed0 += uint128(
uint128 to0 = uint128(
FullMath.mulDiv(
poolManagerPositionInfo.feeGrowthInside0LastX128 - nftPositionCache.feeGrowthInside0LastX128,
nftPositionCache.liquidity,
FixedPoint128.Q128
)
);
tokensOwed1 += uint128(
uint128 to1 = uint128(
FullMath.mulDiv(
poolManagerPositionInfo.feeGrowthInside1LastX128 - nftPositionCache.feeGrowthInside1LastX128,
nftPositionCache.liquidity,
FixedPoint128.Q128
)
);
emit TokensOwed(params.tokenId, to0, to1);
tokensOwed0 += to0;
tokensOwed1 += to1;
}

nftPosition.feeGrowthInside0LastX128 = poolManagerPositionInfo.feeGrowthInside0LastX128;
Expand Down
3 changes: 3 additions & 0 deletions src/pool-cl/interfaces/INonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ interface INonfungiblePositionManager is
/// @param amount1 The amount of token1 owed to the position that was collected
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

/// @dev To track swap fees of a position for off-chain farming
event TokensOwed(uint256 indexed tokenId, uint128 amount0, uint128 amount1);

/// @dev details about the pancake position
struct Position {
// the nonce for permits
Expand Down
Loading