Closed dpaiton closed 8 months ago
High 1: There is a proposal from the Spearbit audit to re-work the fees, which I may address next week, but the drift we'd be most worried about is a drift in price. If you look at other AMM protocols (Uni V2 is the simplest to look into for this), you'll see that they also experience drifts in k.
High 2: I don't think it's an extra term. It could definitely be documented better, but what it is doing is basically accounting for the fact that the checkpoint may have negative margin that can eaten through because of netting. For example, let's say the checkpoint exposure is -100 and the exposure is 1000. If we open 100 longs, the checkpoint exposure will be 0 and the exposure will still be 1000 since exposure is calculated as:
$$ e = \sum_c{\max(e_c, 0)} $$
On first glance, the code looks weird because it's negating $\min(e_c, 0)$, but it does this because exposure is subtracted in $s_0$, so it actually has an additive effect.
Low 2: There was definitely some mad science going on in this estimate. The exponent and scaling factor seemed like they would work, and after testing, this hypothesis was shown to work most of the time. After working on the LP optimization problems, I'm skeptical that picking a guess in this way is really needed. It feels like it's doing what Newton's method should be able to do better. That said, it dramatically improved the convergence in testing, so something weird is going on here.
Low 1: You're welcome to take a crack at this. It's not always easy to see where the documentation you wrote falls short.
https://github.com/delvtech/hyperdrive/pull/830 addresses comment issues low 2; medium 1; medium 2; high 2.
Alex's response resolves high 1 in the sense that we know it's a problem and do not see a need to address it at this time.
I have resolved discrepancies in the doc, aside from a lingering one with the base update equation. I will leave that unresolved unless it is marked as a priority by the protocol team.
Closing this issue until unresolved items are deemed worth addressing.
I did a deep dive into the math and algorithms underlying calculateMaxLong, which computes an input amount for the maximum possible long trade in a given pool. The calculateMaxLong function is auxiliary to the core Hyperdrive smart contracts, but is heavily used by the front-end, simulation, and bot frameworks. Additionally, calculating the maximum and targeted long requires an understanding of the openLong accounting, which at its core is a fundamental component of the Hyperdrive system.
The full writeup is available via this overleaf document, and a summary follows in the form of a pseudo "audit report".
I ranked the issues into "low", "medium", and "high" based on my perceived impact. The issues all stem from my own confusions or misunderstandings, and hopefully can be resolved via explanations and not actual code change requirements. I identified 2 low level issues, 3 medium level issues, and 2 high level issues. You can refer to the full writeup for more detailed descriptions that are in-context and with links.
Low
overloading “delta” variable
unclear how to derive initial long guess
Medium
“yieldspace price” vs “hyperdrive price”
curve fee doc equation error
error in share reserves after opening a long
High
fees might cause curve drift
extra checkpoint exposure term in initial max long guess
Since this issue contains a multitude of sub-issues, I will set tasks here that are resolved with an explanation here or a new issue.