diff --git a/test/large/ReservoirPriceOracleLarge.t.sol b/test/large/ReservoirPriceOracleLarge.t.sol index f30898b..c6a28b7 100644 --- a/test/large/ReservoirPriceOracleLarge.t.sol +++ b/test/large/ReservoirPriceOracleLarge.t.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import { ReservoirPriceOracleTest, EnumerableSetLib, + FixedPointMathLib, MintableERC20, ReservoirPair, IERC20 @@ -11,6 +12,7 @@ import { contract ReservoirPriceOracleLargeTest is ReservoirPriceOracleTest { using EnumerableSetLib for EnumerableSetLib.AddressSet; + using FixedPointMathLib for uint256; function testGetQuote_RandomizeAllParam_3HopRoute( uint256 aPrice1, @@ -97,14 +99,14 @@ contract ReservoirPriceOracleLargeTest is ReservoirPriceOracleTest { // assert uint256 lExpectedAmtBOut = lTokenA < lTokenB - ? lAmtIn * 10 ** lTokenADecimal * lPrice1 * 10 ** lTokenBDecimal / 10 ** lTokenADecimal / WAD - : lAmtIn * 10 ** lTokenADecimal * WAD * 10 ** lTokenBDecimal / lPrice1 / 10 ** lTokenADecimal; + ? (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(lPrice1 * 10 ** lTokenBDecimal, 10 ** lTokenADecimal * WAD) + : (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(WAD * 10 ** lTokenBDecimal, lPrice1 * 10 ** lTokenADecimal); uint256 lExpectedAmtCOut = lTokenB < lTokenC - ? lExpectedAmtBOut * lPrice2 * 10 ** lTokenCDecimal / 10 ** lTokenBDecimal / WAD - : lExpectedAmtBOut * WAD * 10 ** lTokenCDecimal / lPrice2 / 10 ** lTokenBDecimal; + ? lExpectedAmtBOut.fullMulDiv(lPrice2 * 10 ** lTokenCDecimal, 10 ** lTokenBDecimal * WAD) + : lExpectedAmtBOut.fullMulDiv(WAD * 10 ** lTokenCDecimal, lPrice2 * 10 ** lTokenBDecimal); uint256 lExpectedAmtDOut = lTokenC < lTokenD - ? lExpectedAmtCOut * lPrice3 * 10 ** lTokenDDecimal / 10 ** lTokenCDecimal / WAD - : lExpectedAmtCOut * WAD * 10 ** lTokenDDecimal / lPrice3 / 10 ** lTokenCDecimal; + ? lExpectedAmtCOut.fullMulDiv(lPrice3 * 10 ** lTokenDDecimal, 10 ** lTokenCDecimal * WAD) + : lExpectedAmtCOut.fullMulDiv(WAD * 10 ** lTokenDDecimal, lPrice3 * 10 ** lTokenCDecimal); assertEq(lAmtDOut, lExpectedAmtDOut); } diff --git a/test/unit/ReservoirPriceOracle.t.sol b/test/unit/ReservoirPriceOracle.t.sol index 82331f0..f85e3dc 100644 --- a/test/unit/ReservoirPriceOracle.t.sol +++ b/test/unit/ReservoirPriceOracle.t.sol @@ -6,6 +6,7 @@ import { BaseTest, console2, ReservoirPair, MintableERC20 } from "test/__fixture import { Utils } from "src/libraries/Utils.sol"; import { Buffer, + FixedPointMathLib, PriceType, OracleErrors, OracleLatestQuery, @@ -27,6 +28,7 @@ contract ReservoirPriceOracleTest is BaseTest { using FlagsLib for *; using Bytes32Lib for *; using EnumerableSetLib for EnumerableSetLib.AddressSet; + using FixedPointMathLib for uint256; event DesignatePair(address token0, address token1, ReservoirPair pair); event Oracle(address newOracle); @@ -282,8 +284,8 @@ contract ReservoirPriceOracleTest is BaseTest { // assert uint256 lExpectedAmt = lTokenA < lTokenB - ? lAmtIn * 10 ** lTokenADecimal * lPrice * 10 ** lTokenBDecimal / 10 ** lTokenADecimal / WAD - : lAmtIn * 10 ** lTokenADecimal * WAD * 10 ** lTokenBDecimal / lPrice / 10 ** lTokenADecimal; + ? (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(lPrice * 10 ** lTokenBDecimal, 10 ** lTokenADecimal * WAD) + : (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(WAD * 10 ** lTokenBDecimal, lPrice * 10 ** lTokenADecimal); assertEq(lAmtBOut, lExpectedAmt); } @@ -349,11 +351,11 @@ contract ReservoirPriceOracleTest is BaseTest { // assert uint256 lExpectedAmtBOut = lTokenA < lTokenB - ? lAmtIn * 10 ** lTokenADecimal * lPrice1 * 10 ** lTokenBDecimal / 10 ** lTokenADecimal / WAD - : lAmtIn * 10 ** lTokenADecimal * WAD * 10 ** lTokenBDecimal / lPrice1 / 10 ** lTokenADecimal; + ? (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(lPrice1 * 10 ** lTokenBDecimal, 10 ** lTokenADecimal * WAD) + : (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(WAD * 10 ** lTokenBDecimal, lPrice1 * 10 ** lTokenADecimal); uint256 lExpectedAmtCOut = lTokenB < lTokenC - ? lExpectedAmtBOut * lPrice2 * 10 ** lTokenCDecimal / 10 ** lTokenBDecimal / WAD - : lExpectedAmtBOut * WAD * 10 ** lTokenCDecimal / lPrice2 / 10 ** lTokenBDecimal; + ? (lExpectedAmtBOut).fullMulDiv(lPrice2 * 10 ** lTokenCDecimal, 10 ** lTokenBDecimal * WAD) + : (lExpectedAmtBOut).fullMulDiv(WAD * 10 ** lTokenCDecimal, lPrice2 * 10 ** lTokenBDecimal); assertEq(lAmtCOut, lExpectedAmtCOut); }