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.
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
fix: withdraw limits #178
fix: withdraw limits #178
Changes from all commits
44a16e6
9c8e360
3799b70
1632228
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 believe you should be able to remove this block if you do:
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.
it also solves the case where max_withdraw < strategy_limit, where withdrawer would take 100% of the losses (and I don't think it should be this way anyway)
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.
Since .maxWithdraw(self) will already have accounted for the losses we cannot pass that value into the _assess_share_of_unrealised_losses. Otherwise our unrealised_losses will be reduced twice.
EX:
strategy_debt = 100
current_value = 90
unrealised_loss = 10
So if a user is trying to withdraw the full 100 the unrealised_loss should be 10.
needed = 100
strategy.maxWithdraw(vault) = 90
_assess_share_of_unrealised_losses(strategy, 90) = .1 * 90 = 9
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 believe that returning max_assets including losses can lead to issues, as smart contracts would expect to receive the losses too.
also, it doesn't comply with erc4626
max received assets should be the output (i.e. do not include losses)
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.
So this was an issue i was unsure how to handle. But I believe we have to count it as "withdrawable" since it is unrealized in order to comply with the standard.
I wrote the reasoning in the comments. https://github.com/Schlagonia/yearn-vaults-v3/blob/limits/contracts/VaultV3.vy#L566-L572
Basically the conversion rates the vault uses don't yet know about that loss, so the amounts shouldn't adjust for it.
The maxRedeem would also be screwed up if we didnt account for the unrealized loss as withdrawable.
Its not an ideal way to do it but im pretty sure it has to be done this way to comply to the standard.
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.
do we want to allow max_loss = 100%?
nobody should use it but probably better to allow 100% losses
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.
Its the default value used in "redeem" calls if one is not given.
It shouldnt be used. But dont think there is another option we should enforce as a default on every vault
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.
Why is 99.999999999% a valid value, but not 100%?
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.
100% is a valid value and is used by default for redeems. But if its 100% then we have no need to waste the gas to check the loss is within the range
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.
Another option is to do this check (is loss >= max_loss?) every time we have a loss and return the max_assets at that point, returning the max amount of withdrawable assets before hitting a certain max_loss?
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.
added here abb73b6
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.
This is underestimates the max_assets available in cases where partially iterating through the withdraw queue would have had tolerable losses.
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.
abb73b6
Added to the other branch with the modules.
I Did not account for a scenario in which partial would revert but the full queue would not. Think that we shouldnt return a value that has amounts less than it that would revert. Could break things.
Perhaps that could be something to add to a preivewWithdraw/redeem