Basin icon indicating copy to clipboard operation
Basin copied to clipboard

CalcReserve extreme values fix

Open Brean0 opened this issue 6 months ago • 0 comments

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 the j reserve.

  • In the case where newton's method overestimates, set high/low price to the new price, which guarantees convergence.

Brean0 avatar Aug 13 '24 15:08 Brean0