-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swap limit bug fix #221
Swap limit bug fix #221
Conversation
Swap limit bug fix
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
e8377bb
to
23de243
Compare
23de243
to
547840f
Compare
_enforceUnderlyingBalAfterSwap(underlying_, s.vaultTVL); | ||
// Revert if swap reduces vault's available liquidity. | ||
uint256 underlyingBalPost = underlying_.balanceOf(address(this)); | ||
if (underlyingBalPost <= underlyingBalPre) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (underlyingBalPost <= underlyingBalPre) { | |
if (underlyingBalPost < underlyingBalPre) { |
Should be ok if it remains unchanged?
_enforceUnderlyingBalAfterSwap(underlying_, s.vaultTVL); | ||
// - Absolute balance is strictly greater than `minUnderlyingBal`. | ||
// - Ratio of the balance to the vault's TVL is strictly greater than `minUnderlyingPerc`. | ||
uint256 underlyingBal = underlying_.balanceOf(address(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there's a weird corner case where underlying balance could go up (or maybe just remain constant?) after an underlying->perp swap.
e.g. If the vault was sitting on a bunch of As, and the new Zs free those up.
In that case I think we'd want to allow that to go through.
Perhaps the most generalized logic would be:
If underlying bal increases or stays the same, continue
else, execute the check logic you have here.
That situation would be exceptionally rare, though. Worth it? It would be one extra var and a conditional, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool. So basically if the underlying balances goes down, we then ensure that it doesn't go down too much. If it stays the same or increases its fine..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Skipping liquidity check when swapping from perps to underlying.
Swapping from perps to underlying should almost always increase the vault's liquidity, so we only check if underlying balance doesn't decrease.