Improve VolatilityOracle accuracy and manipulation resistance #219
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.
Addresses
Fix for 45
FEE_GROWTH_AVG_WINDOW
from 6 hours to 72 hours, making it cost 12x more to manipulate. This measurement isn't precise enough to pick up intra-day variance in the first place (was just noise before), so the increase doesn't hurt anything.IV_CHANGE_PER_SECOND
by a factor of 4Borrower
s a heads up as to where IV is headed. In case of manipulation, this forces the attacker to wait and hope thatBorrower
s don't respond. It also helps in normal operation, asBorrower
s are less likely to become liquidatable all at once, reducing congestion and price impact.Fix for 38
The issue is not as bad as the report would have one believe:
nSigma
between 4 and 8 (from a default of 5), so it should be relatively easy to compensate for any systematic error.That said, there's one simple improvement that I've implemented here -- an exponential moving average for IV, where the upwards gain is 5x larger than the downwards gain. This smooths out changes (similar to the linear interpolation described above) and empirically causes it to match the "true" IV more closely.
Note
One post-facto explanation for this is that when the price moves rapidly, sophisticated actors are the first to update their Uniswap positions, making our measurement more accurate for a brief period. Once the dumber capital catches up and creates passive positions in the new trading range, IV becomes artificially depressed again.