Skip to content

Commit

Permalink
use optimized abs
Browse files Browse the repository at this point in the history
  • Loading branch information
kinrezC committed Jul 25, 2024
1 parent d5c217b commit fa461b3
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/lib/RmmLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fa461b3

Please sign in to comment.