Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/strategy lib muldiv #100

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading