From fa461b352bd49519e7c4e4c3f5038a7c3cbd3593 Mon Sep 17 00:00:00 2001 From: kinrezc Date: Thu, 25 Jul 2024 16:49:22 -0400 Subject: [PATCH] use optimized abs --- src/lib/RmmLib.sol | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/lib/RmmLib.sol b/src/lib/RmmLib.sol index 560d8f1..9c79200 100644 --- a/src/lib/RmmLib.sol +++ b/src/lib/RmmLib.sol @@ -284,7 +284,7 @@ function findRootNewX(bytes memory args, uint256 initialGuess, uint256 maxIterat reserveX_next = int256(reserveX_) - fx * 1e18 / dfx; - if (abs(int256(reserveX_) - reserveX_next) <= int256(tolerance) || abs(fx) <= int256(tolerance)) { + if (FixedPointMathLib.abs(int256(reserveX_) - reserveX_next) <= tolerance || FixedPointMathLib.abs(fx) <= tolerance) { reserveX_ = uint256(reserveX_next); break; } @@ -310,7 +310,7 @@ function findRootNewY(bytes memory args, uint256 initialGuess, uint256 maxIterat reserveY_next = int256(reserveY_) - fx * 1e18 / dfx; - if (abs(int256(reserveY_) - reserveY_next) <= int256(tolerance) || abs(fx) <= int256(tolerance)) { + if (FixedPointMathLib.abs(int256(reserveY_) - reserveY_next) <= tolerance || FixedPointMathLib.abs(fx) <= tolerance) { reserveY_ = uint256(reserveY_next); break; } @@ -479,14 +479,6 @@ function toUint(int256 x) pure returns (uint256) { return uint256(x); } -function abs(int256 x) pure returns (int256) { - if (x < 0) { - return -x; - } else { - return x; - } -} - /// @dev Computes the scalar to multiply to convert between WAD and native units. function scalar(address token) view returns (uint256) { uint256 decimals = ERC20(token).decimals();