Basin
Basin copied to clipboard
CalcReserve extreme values fix
calcReserveAtRatioSwap
and calcReserveAtRatioLiquidity
utilize a LUT to decrease the computation needed to estimate the reserves. When this function is called at extremely high or low values, the function can revert due to overflow or the function not converging.
This PR implements the following:
-
readjusts the max step size when
scaledReserve[j]
is updated. This ensures that maxStep size can never be larger than thej
reserve. -
In the case where newton's method overestimates, set high/low price to the new price, which guarantees convergence.