Skip to content

Commit

Permalink
Merge pull request #108 from primitivefinance/fix/g3m-math
Browse files Browse the repository at this point in the history
fix: remove computeLGivenY in G3MMath
  • Loading branch information
clemlak authored Apr 2, 2024
2 parents bf3c7bf + 1b9e6ed commit a2f111e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 41 deletions.
34 changes: 1 addition & 33 deletions src/GeometricMean/G3MMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,11 @@ function computeLGivenX(
uint256 S,
GeometricMeanParams memory params
) pure returns (uint256) {
int256 a = int256(params.wY.divWadUp(params.wX).mulWadUp(S));
int256 a = int256(params.wY.mulDivUp(S, params.wX));
int256 b = a.powWad(int256(params.wY));
return x.mulWadUp(uint256(b));
}

function computeLGivenY(
uint256 y,
uint256 S,
GeometricMeanParams memory params
) pure returns (uint256) {
return y.mulWadUp(params.wX).divWadUp(params.wY.mulWadUp(S));
}

function computeXGivenL(
uint256 L,
uint256 S,
GeometricMeanParams memory params
) pure returns (uint256) {
return params.wX.mulWadUp(L).divWadUp(params.wY.mulWadUp(S));
}

function computeYGivenL(
uint256 L,
uint256 S,
GeometricMeanParams memory params
) pure returns (uint256) {
return params.wY.mulWadUp(L).divWadUp(params.wX.mulWadUp(S));
}

function computeAllocationGivenDeltaX(
uint256 deltaX,
uint256 rX,
Expand Down Expand Up @@ -123,14 +99,6 @@ function computeY(
return params.wY.divWadDown(params.wX).mulWadDown(S).mulWadDown(x);
}

function computeX(
uint256 y,
uint256 S,
GeometricMeanParams memory params
) pure returns (uint256) {
return params.wX.divWadDown(params.wY.mulWadDown(S)).mulWadDown(y);
}

function computeL(
uint256 x,
uint256 y,
Expand Down
10 changes: 2 additions & 8 deletions src/GeometricMean/GeometricMeanSolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ import {
} from "./G3MUtils.sol";
import {
computeInitialPoolData,
computeL,
computePrice,
computeLGivenX,
computeY,
computeX,
computeLGivenY,
computeNextLiquidity,
computeNextRx,
computeNextRy,
computeTradingFunction,
computeAllocationGivenDeltaX,
computeAllocationGivenDeltaY,
computeDeallocationGivenDeltaX,
computeDeallocationGivenDeltaY
computeDeallocationGivenDeltaY,
computePrice
} from "./G3MMath.sol";

contract GeometricMeanSolver {
Expand Down

0 comments on commit a2f111e

Please sign in to comment.