@@ -21,6 +21,7 @@ abstract contract BNBPartyFee is BNBPartyModifiers {
21
21
uint256 feeGrowthInside1LastX128
22
22
)
23
23
{
24
+ Ticks memory ticks = _getTicks (pool.token0 (), party.lpTicks);
24
25
(
25
26
feeGrowthInside0LastX128,
26
27
feeGrowthInside1LastX128
@@ -29,8 +30,8 @@ abstract contract BNBPartyFee is BNBPartyModifiers {
29
30
keccak256 (
30
31
abi.encodePacked (
31
32
address (positionManager),
32
- party.lpTicks .tickLower,
33
- party.lpTicks .tickUpper
33
+ ticks .tickLower,
34
+ ticks .tickUpper
34
35
)
35
36
)
36
37
);
@@ -48,6 +49,7 @@ abstract contract BNBPartyFee is BNBPartyModifiers {
48
49
uint256 feeGrowthInside1LastX128
49
50
)
50
51
{
52
+ Ticks memory ticks = _getTicks (pool.token0 (), party.partyTicks);
51
53
(
52
54
feeGrowthInside0LastX128,
53
55
feeGrowthInside1LastX128
@@ -56,8 +58,8 @@ abstract contract BNBPartyFee is BNBPartyModifiers {
56
58
keccak256 (
57
59
abi.encodePacked (
58
60
address (BNBPositionManager),
59
- party.partyTicks .tickLower,
60
- party.partyTicks .tickUpper
61
+ ticks .tickLower,
62
+ ticks .tickUpper
61
63
)
62
64
)
63
65
);
@@ -81,13 +83,46 @@ abstract contract BNBPartyFee is BNBPartyModifiers {
81
83
82
84
/// @notice Internal function to calculate the global fee growth
83
85
/// @param pool Address of the Uniswap V3 pool
84
- function _calculateFeeGrowthGlobal (IUniswapV3Pool pool ) internal view returns (uint256 feeGrowthGlobal ) {
86
+ function _calculateFeeGrowthGlobal (
87
+ IUniswapV3Pool pool
88
+ ) internal view returns (uint256 feeGrowthGlobal ) {
85
89
if (pool.token0 () == address (WBNB)) {
86
- (uint256 feeGrowthInside0LastX128 , ) = _getPartyFeeGrowthInsideLastX128 (pool);
87
- feeGrowthGlobal = pool.feeGrowthGlobal0X128 () - feeGrowthInside0LastX128;
90
+ (uint256 feeGrowthInside0LastX128 , ) = _getPartyFeeGrowthInsideLastX128 (pool);
91
+ feeGrowthGlobal = pool.feeGrowthGlobal0X128 () - feeGrowthInside0LastX128;
88
92
} else {
89
- (, uint256 feeGrowthInside1LastX128 ) = _getPartyFeeGrowthInsideLastX128 (pool);
93
+ ( , uint256 feeGrowthInside1LastX128 ) = _getPartyFeeGrowthInsideLastX128 (pool);
90
94
feeGrowthGlobal = pool.feeGrowthGlobal1X128 () - feeGrowthInside1LastX128;
91
95
}
92
96
}
97
+
98
+ /// @notice Invert the ticks
99
+ /// @param tickLower Lower tick
100
+ /// @param tickUpper Upper tick
101
+ /// @return ticks struct with inverted ticks
102
+ function _invertTicks (
103
+ int24 tickLower ,
104
+ int24 tickUpper
105
+ ) internal pure returns (Ticks memory ticks ) {
106
+ ticks.tickLower = - tickUpper;
107
+ ticks.tickUpper = - tickLower;
108
+ }
109
+
110
+ /// @notice Internal function to retrieve the Ticks based on the token address
111
+ /// @param token0 Address of the token0
112
+ /// @param ticks The Ticks struct with lower and upper ticks
113
+ /// @return adjustedTicks The Ticks struct adjusted based on token address
114
+ function _getTicks (
115
+ address token0 ,
116
+ Ticks memory ticks
117
+ )
118
+ internal
119
+ view
120
+ returns (Ticks memory adjustedTicks )
121
+ {
122
+ if (address (WBNB) == token0) {
123
+ adjustedTicks = _invertTicks (ticks.tickLower, ticks.tickUpper);
124
+ } else {
125
+ adjustedTicks = ticks;
126
+ }
127
+ }
93
128
}
0 commit comments