From 26f2f8c475a2a3d6bbad5f669e674b38e6359091 Mon Sep 17 00:00:00 2001 From: clemlak Date: Fri, 29 Mar 2024 16:43:19 +0400 Subject: [PATCH 1/2] fix: use mulDiv for most operations in StrategyLib --- src/lib/StrategyLib.sol | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lib/StrategyLib.sol b/src/lib/StrategyLib.sol index d1d60387..51d21fc1 100644 --- a/src/lib/StrategyLib.sol +++ b/src/lib/StrategyLib.sol @@ -19,8 +19,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; } @@ -31,8 +30,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; } @@ -42,7 +40,7 @@ function computeDeltaLGivenDeltaX( uint256 liquidity, uint256 reserveX ) pure returns (uint256 deltaL) { - return liquidity.mulWadDown(deltaX.divWadDown(reserveX)); + return liquidity.mulDivDown(deltaX, reserveX); } function computeDeltaLGivenDeltaY( @@ -50,7 +48,7 @@ function computeDeltaLGivenDeltaY( uint256 liquidity, uint256 reserveY ) pure returns (uint256 deltaL) { - return liquidity.mulWadDown(deltaY.divWadDown(reserveY)); + return liquidity.mulDivDown(deltaY, reserveY); } function computeDeltaYGivenDeltaX( @@ -58,7 +56,7 @@ function computeDeltaYGivenDeltaX( uint256 reserveX, uint256 reserveY ) pure returns (uint256 deltaY) { - return reserveY.mulWadDown(deltaX.divWadUp(reserveX)); + return reserveY.mulDivUp(deltaX, reserveX); } function computeDeltaXGivenDeltaL( @@ -66,7 +64,7 @@ function computeDeltaXGivenDeltaL( uint256 liquidity, uint256 reserveX ) pure returns (uint256 deltaX) { - return reserveX.mulWadUp(deltaL.divWadUp(liquidity)); + return reserveX.mulDivUp(deltaL, liquidity); } function computeDeltaYGivenDeltaL( @@ -74,5 +72,5 @@ function computeDeltaYGivenDeltaL( uint256 liquidity, uint256 reserveY ) pure returns (uint256 deltaX) { - return reserveY.mulWadUp(deltaL.divWadUp(liquidity)); + return reserveY.mulDivUp(deltaL, liquidity); } From aa9e127eb9670296cdd24fa3cb803cd74a103d1a Mon Sep 17 00:00:00 2001 From: clemlak Date: Mon, 1 Apr 2024 18:24:38 +0400 Subject: [PATCH 2/2] test: increase default X reserve for LogNormal pools --- test/LogNormal/unit/SetUp.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/LogNormal/unit/SetUp.sol b/test/LogNormal/unit/SetUp.sol index 2866eb4e..733fcabd 100644 --- a/test/LogNormal/unit/SetUp.sol +++ b/test/LogNormal/unit/SetUp.sol @@ -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;