Enforce z - zeta >= z_min (except for LPs)#726
Merged
jalextowle merged 6 commits intomainfrom Jan 19, 2024
Merged
Conversation
z - zeta >= z_min (except for LPs)
Hyperdrive Gas Benchmark
This comment was automatically generated by workflow using github-action-benchmark. |
Collaborator
jrhea
reviewed
Jan 18, 2024
jrhea
reviewed
Jan 18, 2024
jrhea
reviewed
Jan 18, 2024
jrhea
reviewed
Jan 18, 2024
jrhea
reviewed
Jan 18, 2024
jrhea
reviewed
Jan 18, 2024
Co-authored-by: Jonny Rhea <5555162+jrhea@users.noreply.github.com>
Co-authored-by: Jonny Rhea <5555162+jrhea@users.noreply.github.com>
jrhea
reviewed
Jan 18, 2024
…eater-than-minimum-share-reserves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #583, #677.
This PR enforces$z - \zeta \geq z_{min}$ for trading operations but continues to allow LP operations like
removeLiquidityand the system level_distributeExcessIdleto bring the effective share reserves below the minimum share reserves.As discussed theoretically in #583 and practically in #677, it is quite dangerous for the system's liveness to allow traders to manipulate the effective share reserves to be very small. A sane cutoff for this manipulation is the$z - \zeta \geq z_{min}$ in
minimumShareReservessince this was selected to be a sane minimum for the share reserves which is subject to similar constraints. Enforcing this check is straightforward incloseLongandopenShort. Since the LP operations can violate the invariant, we only enforcecloseLongwhen the effective share reserves are decreasing to allow checkpoints to be minted regardless of the current effective share reserves.The idea of enforcing$z - \zeta \geq z_{min}$ seems reasonable on its face, but it prevents LPs from being able to remove all of the shares from system even if there are no outstanding positions. Attempting to enforce this check would complicate the logic in $\zeta > 0$ and $\tfrac{z}{z - \zeta} = 50$ . If we enforced $z - \zeta \geq z_{min}$ , then $z - \zeta = z_{min}$ after removing the liquidity but $z = 50 \cdot z_{min}$ . This is untenable as the ratio increases. With all of this in mind, this PR doesn't enforce the constraint for LPs and instead adds a test demonstrating that liveness is not compromised by LPs removing all of their liquidity even in extreme trading conditions.
LPMath.calculateDistributeExcessIdleand would also create situations in which LPs wouldn't be able to remove non-trivial amounts of liquidity. For example, assume thatIn order for the$z - \zeta \geq z_{min}$ constraint, I needed to update the rounding behavior. I also took the opportunity to simplify $\max(z_{min}, z_{min} + \zeta)$ to $z_{min} + \max(\zeta, 0)$ .
calculateMaxShortmachinery to respect the