Fixed the issue with open short #1199
Merged
+39
−11
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.
Description
This PR fixes a minor issue with
openShort
that ensures that the amount of shares owned by the pool are always greater than the expected amount. This ensures that the system is always completely solvent. Despite the old pool design making it possible to have small amounts of insolvency, in practice this wasn't an issue because the magnitudes were so small. The following is an analysis of why this wasn't an issue.Insolvency Writeup
Sheng surfaced a failing fuzz test that indicates insolvency on the Morpho Blue wstETH/USDA Hyperdrive pool. After investigating this issue, I noticed that this issue will occur whenever shorts are opened because of the imprecision in converting from shares to base using the vault share price.
Since this pool already has a fairly large amount of liquidity in it ($10k), it would be annoying for all involved to have to redeploy the pool. DELV has already deployed ~$80 of USDA to the pool, so depending on the amount of insolvency, this will be covered by DELV's initial deposit.
Issue Analysis
To get a better understanding of the insolvency issue surfaced yesterday, it's useful to understand the magnitude of the insolvency. If the insolvency is small enough, it can be covered by the initial liquidity supplied to the pool.
On a short of
156.468005765553258496
bonds, we run into a small amount of insolvency immediately. Looking at the expected balance of vault shares versus the actual balance of vault shares measured in vault shares and base, we can see that the discrepancy is quite small:If the short amount is increased to the max short of
3231.05668405864919373
bonds, the insolvency amounts are:To get a better sense of what this looks like in an extreme case, we'll add lots of liquidity before opening the max short. When we add
6_000_000
USDA of liquidity and open a max short of2_011_395.096051101066013435
, the insolvency amounts are:Plotting an additional point on this line, we can see that insolvency scales with bonds with a slope of approximately
4e-14
base of insolvency per bond. Using this linear regression model, we can solve for the short volume that will result in an insolvency of $80:To make sure that this analysis isn't leaving anything off, I tried to see what the impact of closing shorts immediately would have on solvency. In the three examples we have the following results:
Doing the same linear regression on these points, the insolvency per bond that is bought and immediately sold is
~2e-15
. Solving for the amount of this volume that is required to achieve insolvency of $80 we get:Next, I'll plot similar points if we close the longs at maturity with the variable rate staying constant for the full term. As we can see from the points below, closing at maturity results in the pool becoming more solvent, so we can support an infinite amount of volume in this direction.
Verdict
Given the extremely small monetary value of the insolvency accrued on the short, the pool can support more volume than we'll ever need it to support. This pool would require more volume than is processed in mature treasury markets in a decade to be more than $80 insolvent, and the pool's solvency is improved when shorts are held to maturity.