Skip to content

Commit

Permalink
Fix computeBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobrunoah committed Dec 19, 2024
1 parent 1d90eaf commit aa0818b
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pkg/pool-gyro/contracts/Gyro2CLPPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,16 @@ contract Gyro2CLPPool is IGyro2CLPPool, BalancerPoolToken {
invariant = invariant.mulUp(invariantRatio);
uint256 squareNewInv = invariant * invariant;

// L / sqrt(beta), rounded down to maximize newBalance.
uint256 a = invariant.divDown(sqrtBeta);
// L * sqrt(alpha), rounded down to maximize newBalance (b is in the denominator).
uint256 b = invariant.mulDown(sqrtAlpha);

if (tokenInIndex == 0) {
// if newBalance = newX

// L / sqrt(beta), rounded down to minimize newBalance.
uint256 a = invariant.divDown(sqrtBeta);
// L * sqrt(alpha), rounded up to minimize newBalance (b is in the denominator).
uint256 b = invariant.mulUp(sqrtAlpha);

newBalance = squareNewInv.divUpRaw(b + balancesLiveScaled18[1]) - a;
} else {
// if newBalance = newY

// L / sqrt(beta), rounded up to minimize newBalance (a is in the denominator).
uint256 a = invariant.divUp(sqrtBeta);
// L * sqrt(alpha), rounded down to minimize newBalance.
uint256 b = invariant.mulDown(sqrtAlpha);

newBalance = squareNewInv.divUpRaw(a + balancesLiveScaled18[0]) - b;
}
}
Expand Down

0 comments on commit aa0818b

Please sign in to comment.