Conversation
Collaborator
jrhea
commented
Nov 9, 2023
Hyperdrive Gas Benchmark
This comment was automatically generated by workflow using github-action-benchmark. |
jalextowle
reviewed
Nov 9, 2023
jalextowle
reviewed
Nov 9, 2023
jalextowle
reviewed
Nov 9, 2023
jalextowle
reviewed
Nov 9, 2023
jalextowle
reviewed
Nov 9, 2023
Co-authored-by: Alex Towle <jalextowle@gmail.com>
jrhea
commented
Nov 9, 2023
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.
This PR is a followup to PR #594 and provides a better fix to issue #587 in that it allows for infinite netting within a checkpoint (the previous fix simply disregarded the shortDeposit when calculating exposure for
openShort()).Summary of the Problem and Fix:
Edge cases were found fuzz testing that caused longs to be insolvent in rare cases. What would happen is that after the shorts were closed in
_applyCheckpoint()it would underflow when trying to close out the longs. This would happen bc fuzzing found cases were a short would have a larger deposit than a long's fixed rate despite the short being for less bonds than the long (see issue #587). I determined that this was caused by numerical inaccuracies in fixed point math pow(). The fix was to round the short's base deposit part of the exposure calc down by the magnitude of the numerical error. This ensures that when LP's withdraw, the exposure is high enough to ensure there is enough left in the share reserves to allow longs to close at maturity.Notes:
New PoolConfig variable called precisionThreshold was added to make the fix configurable.
resolves Exposure Symmetry Tests #662 by adding checkpoint exposure check in IntraCheckpointNettingTest.open_close_long_short
In the process of implementing this fix, I audited OpenLong, CloseLong, OpenShort, and CloseShort for consistency.
OpenLong
CloseLong
OpenShort
of deposit bc slippage could make a larger than maxDeposit
potentially pass the check
CloseShort