Skip to content

Commit

Permalink
Merge pull request #100 from primitivefinance/fix/strategy-lib-muldiv
Browse files Browse the repository at this point in the history
Fix/strategy lib muldiv
  • Loading branch information
clemlak authored Apr 1, 2024
2 parents 8bff684 + aa9e127 commit 32a5572
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/lib/StrategyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ function computeAllocationGivenX(
uint256 rx,
uint256 L
) pure returns (uint256 nextRx, uint256 nextL) {
uint256 liquidityPerRx = L.divWadUp(rx);
uint256 deltaL = amountX.mulWadUp(liquidityPerRx);
uint256 deltaL = amountX.mulDivDown(L, rx);
nextRx = add ? rx + amountX : rx - amountX;
nextL = add ? L + deltaL : L - deltaL;
}
Expand All @@ -29,8 +28,7 @@ function computeAllocationGivenY(
uint256 ry,
uint256 L
) pure returns (uint256 nextRy, uint256 nextL) {
uint256 liquidityPerRy = L.divWadUp(ry);
uint256 deltaL = amountY.mulWadUp(liquidityPerRy);
uint256 deltaL = amountY.mulDivDown(L, ry);
nextRy = add ? ry + amountY : ry - amountY;
nextL = add ? L + deltaL : L - deltaL;
}
Expand All @@ -40,37 +38,37 @@ function computeDeltaLGivenDeltaX(
uint256 liquidity,
uint256 reserveX
) pure returns (uint256 deltaL) {
return liquidity.mulWadDown(deltaX.divWadDown(reserveX));
return liquidity.mulDivDown(deltaX, reserveX);
}

function computeDeltaLGivenDeltaY(
uint256 deltaY,
uint256 liquidity,
uint256 reserveY
) pure returns (uint256 deltaL) {
return liquidity.mulWadDown(deltaY.divWadDown(reserveY));
return liquidity.mulDivDown(deltaY, reserveY);
}

function computeDeltaYGivenDeltaX(
uint256 deltaX,
uint256 reserveX,
uint256 reserveY
) pure returns (uint256 deltaY) {
return reserveY.mulWadDown(deltaX.divWadUp(reserveX));
return reserveY.mulDivUp(deltaX, reserveX);
}

function computeDeltaXGivenDeltaL(
uint256 deltaL,
uint256 liquidity,
uint256 reserveX
) pure returns (uint256 deltaX) {
return reserveX.mulWadUp(deltaL.divWadUp(liquidity));
return reserveX.mulDivUp(deltaL, liquidity);
}

function computeDeltaYGivenDeltaL(
uint256 deltaL,
uint256 liquidity,
uint256 reserveY
) pure returns (uint256 deltaX) {
return reserveY.mulWadUp(deltaL.divWadUp(liquidity));
return reserveY.mulDivUp(deltaL, liquidity);
}
2 changes: 1 addition & 1 deletion test/LogNormal/unit/SetUp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract LogNormalSetUp is SetUp {
controller: address(this)
});

uint256 defaultReserveX = ONE;
uint256 defaultReserveX = 100 ether;
uint256 defaultReserveXDeep = ONE * 10_000_000;

uint256 defaultPrice = ONE;
Expand Down

0 comments on commit 32a5572

Please sign in to comment.