Skip to content

Commit 7e8fc22

Browse files
committed
fix: g3m fee adjustment
1 parent 1d389b4 commit 7e8fc22

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/solvers/G3M/G3MSolver.sol

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,9 @@ contract G3MSolver {
161161
{
162162
if (swapXIn) {
163163
uint256 fees = amountIn.mulWadUp(poolParams.swapFee);
164-
uint256 weightedPrice = uint256(
165-
int256(startReserves.ry.divWadUp(startReserves.rx)).powWad(
166-
int256(poolParams.wY)
167-
)
164+
uint256 deltaL = (ONE.divWadDown(2 * ONE)).mulWadUp(
165+
fees.mulWadUp(startComputedL).divWadUp(startReserves.rx)
168166
);
169-
uint256 deltaL = fees.mulWadUp(weightedPrice);
170-
deltaL += 1;
171167

172168
endReserves.rx = startReserves.rx + amountIn;
173169
endReserves.L = startComputedL + deltaL;
@@ -183,13 +179,9 @@ contract G3MSolver {
183179
amountOut = startReserves.ry - endReserves.ry;
184180
} else {
185181
uint256 fees = amountIn.mulWadUp(poolParams.swapFee);
186-
uint256 weightedPrice = uint256(
187-
int256(startReserves.rx.divWadUp(startReserves.ry)).powWad(
188-
int256(poolParams.wX)
189-
)
182+
uint256 deltaL = (ONE.divWadDown(2 * ONE)).mulWadUp(
183+
fees.mulWadUp(startComputedL).divWadUp(startReserves.rx)
190184
);
191-
uint256 deltaL = fees.mulWadUp(weightedPrice);
192-
deltaL += 1;
193185

194186
endReserves.ry = startReserves.ry + amountIn;
195187
endReserves.L = startComputedL + deltaL;
@@ -209,7 +201,6 @@ contract G3MSolver {
209201
bytes memory swapData =
210202
abi.encode(endReserves.rx, endReserves.ry, endReserves.L);
211203

212-
uint256 poolId = poolId;
213204
(bool valid,,,,,) =
214205
IStrategy(strategy).validateSwap(address(this), poolId, swapData);
215206
return (

src/strategies/G3M/G3M.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,19 @@ contract G3M is IStrategy {
168168
if (nextRx > startRx) {
169169
amountIn = nextRx - startRx;
170170
fees = amountIn.mulWadUp(params.swapFee);
171-
minLiquidityDelta += fees.mulWadUp(startL).divWadUp(startRx);
171+
minLiquidityDelta += (ONE.divWadDown(2 * ONE)).mulWadUp(
172+
fees.mulWadUp(startL).divWadUp(startRx)
173+
);
172174
} else if (nextRy > startRy) {
173175
amountIn = nextRy - startRy;
174176
fees = amountIn.mulWadUp(params.swapFee);
175-
minLiquidityDelta += fees.mulWadUp(startL).divWadUp(startRy);
177+
minLiquidityDelta += (ONE.divWadDown(2 * ONE)).mulWadUp(
178+
fees.mulWadUp(startL).divWadUp(startRy)
179+
);
176180
} else {
177181
revert("invalid swap: inputs x and y have the same sign!");
178182
}
179183

180-
uint256 poolId = poolId;
181-
182184
liquidityDelta = int256(nextL)
183185
- int256(
184186
G3MLib.computeNextLiquidity(

0 commit comments

Comments
 (0)