Open dpaiton opened 6 months ago
We also wrap calc_max_long
and calc_max_short
in the random bot policy in agent0 with a try/catch because the calc_max functions fail without clear messaging or in a situation that could be easily avoided with knowledge of the pool state. We're seeing failures in the hyperdrive experiment flow as well as fuzz testing.
The calc_max process is approximate, and has a high error rate when the network is close to an extreme state where the max would be close to zero. This is easily reproducible by calling calcmax[long/short], executing the trade, and then calling it again. We want to catch this situation and return a max of zero at the rust level, so that the value returned is safe to pass directly to the smart contracts.
Related issues with crash report for this are https://github.com/delvtech/hyperdrive/issues/687 and https://github.com/delvtech/hyperdrive/issues/686
Solving open long issue in this pr: https://github.com/delvtech/hyperdrive/pull/754
Upper bound (max) errors on close long & short require checkpointing ( https://github.com/delvtech/hyperdrive-rs/issues/23 ), so we are blocked on that for now.
I'm moving this to High
priority, removing the deadline, and removing @slundqui 's assignment.
He achieved all that was possible in delvtech/hyperdrive#916 . We are blocked on checkpointing & a MockHyperdrive
test utility; so the full resolution of this issue will need to be delayed.
Tasks:
Another issue (https://github.com/delvtech/hyperdrive-rs/issues/45) will address these:
When these functions are added (https://github.com/delvtech/hyperdrive/issues/873 https://github.com/delvtech/hyperdrive-rs/issues/24 https://github.com/delvtech/hyperdrive-rs/issues/22) we should ensure they also have matching errors:
Details:
The Solidity code includes error handling which the Rust SDK lacks. For instance, in Solidity, openLong reverts with a NegativeInterest error, while in Rust it incorrectly returns a valid FixedPoint number. This discrepancy can lead to issues where users might pay gas for transactions that are destined to fail. It also can introduce bugs in Python bot logic that relies on these outputs for choosing subsequent trades.
Here is a python script to reproduce the given example: