delvtech/hyperdrive-rs

Allow `calculate_max_long` and `calculate_max_short` to "cross-over" the optimal point

Opened this issue · 0 comments

There are TODO comments in calculate_max_long and calculate_max_short about how we should allow Newton's method to hop from one side of the optimal point to the other. We do this in Solidity's LPMath: https://github.com/delvtech/hyperdrive/blob/03b66f69da0d38ec1ef3f9a2f3461fc0c84f583a/contracts/src/libraries/LPMath.sol#L894. This would prevent these calculations from overflowing/underflowing in extreme circumstances.