delvtech / hyperdrive-rs

Rust SDK for the Hyperdrive AMM.
https://docs.rs/crate/hyperdrive-math/latest
Apache License 2.0
2 stars 0 forks source link

add guardrails to open long & short preventing double max #126

Open dpaiton opened 8 months ago

dpaiton commented 8 months ago

in our fuzz tests we should prevent allowing two max longs/shorts in row

lets put a check in the interface before calling rust funcs; if bond & share are at certain levels (e.g. close to equal for max long) then we directly return FixedPoint(0) without bothering with the rust func. Similar for max short

we should also catch neg interest in crash reporting and see if it's because max long was too big (calc_max has noise, this results from two max trades in a row)

wakamex commented 8 months ago

we discussed this a bit, and the most robust solution would be to add guardrails to the rust sdk. that may still be something we want to do, but it's a bigger task, since the logic needs to be mirrored in solidity. we have a lot more flexibility in addressing this issue in python, like running a mock trade at the end.

dpaiton commented 4 months ago

A shortcut was added to max long in https://github.com/delvtech/hyperdrive-rs/pull/5 A similar one should be added to max short.