Skip to content

Commit

Permalink
refactor BNBPartyFee
Browse files Browse the repository at this point in the history
  • Loading branch information
YouStillAlive committed Sep 23, 2024
1 parent 7083866 commit cce88a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
52 changes: 10 additions & 42 deletions contracts/BNBPartyFee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,6 @@ import "./interfaces/IUniswapV3Pool.sol";
/// @title BNBPartyFee
/// @notice This abstract contract provides internal functions for calculating fees in the BNB Party system.
abstract contract BNBPartyFee is BNBPartyState {
/// @notice Internal function to retrieve the fee growth inside the position from the last observation
/// @param pool Address of the Uniswap V3 pool
/// @return feeGrowthInside0LastX128 Fee growth inside for token0 from the last observation
/// @return feeGrowthInside1LastX128 Fee growth inside for token1 from the last observation
function _getFeeGrowthInsideLastX128(
IUniswapV3Pool pool
)
internal
view
returns (
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128
)
{
(feeGrowthInside0LastX128, feeGrowthInside1LastX128) = _getFeeGrowthInsideLastX128(
positionManager,
pool,
party.lpTicks
);
}

/// @notice Internal function to retrieve the fee growth inside the position from the last observation
/// @param pool Address of the Uniswap V3 pool
function _getPartyFeeGrowthInsideLastX128(
IUniswapV3Pool pool
)
internal
view
returns (
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128
)
{
(feeGrowthInside0LastX128, feeGrowthInside1LastX128) = _getFeeGrowthInsideLastX128(
BNBPositionManager,
pool,
party.partyTicks
);
}

/// @notice Internal function to retrieve the fee growth inside the position from the last observation
function _getFeeGrowthInsideLastX128(
INonfungiblePositionManager manager,
Expand Down Expand Up @@ -88,10 +48,18 @@ abstract contract BNBPartyFee is BNBPartyState {
IUniswapV3Pool pool
) internal view returns (uint256 feeGrowthGlobal) {
if (pool.token0() == address(WBNB)) {
(uint256 feeGrowthInside0LastX128 , ) = _getPartyFeeGrowthInsideLastX128(pool);
(uint256 feeGrowthInside0LastX128 , ) = _getFeeGrowthInsideLastX128(
BNBPositionManager,
pool,
party.partyTicks
);
feeGrowthGlobal = pool.feeGrowthGlobal0X128() -feeGrowthInside0LastX128;
} else {
( , uint256 feeGrowthInside1LastX128) = _getPartyFeeGrowthInsideLastX128(pool);
( , uint256 feeGrowthInside1LastX128) = _getFeeGrowthInsideLastX128(
BNBPositionManager,
pool,
party.partyTicks
);
feeGrowthGlobal = pool.feeGrowthGlobal1X128() - feeGrowthInside1LastX128;
}
}
Expand Down
11 changes: 10 additions & 1 deletion contracts/BNBPartyView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ abstract contract BNBPartyView is BNBPartyFee {
(
feeGrowthInside0LastX128,
feeGrowthInside1LastX128
) = manager == BNBPositionManager ? _getPartyFeeGrowthInsideLastX128(pool) : _getFeeGrowthInsideLastX128(pool);
) = manager == BNBPositionManager ? _getFeeGrowthInsideLastX128(
BNBPositionManager,
pool,
party.partyTicks
) :
_getFeeGrowthInsideLastX128(
positionManager,
pool,
party.lpTicks
);
}
}

0 comments on commit cce88a9

Please sign in to comment.