Skip to content
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

InsufficientVaultCollateralAmount error when trying to withdraw an amount takes the vault below MinimumCollateral #1203

Open
1 task
nakul1010 opened this issue Oct 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@nakul1010
Copy link
Member

nakul1010 commented Oct 13, 2023

Describe the bug
The issue with is_allowed_to_withdraw_collateral helper method is, that it passes out an error InsufficientVaultCollateralAmount when trying to withdraw an amount that falls below MinimumCollateral but in some cases it is not ideal

Corner case 1:

When a vault accepts a replace, it doesn't seem to check whether the vault's is below the minimum_collateral_vault threshold.This will cause issues when the vault tries to cancelReplace since, the extrinsic will only allow to cancel if vault is above minimum_collateral_vault threshold.

Steps to reproduce the behavior:

  • Set minimum_collateral_vault to amount x.

  • Set vault stake to amount y. Where y < x.

  • Send an acceptReplace request to vault

  • Try to cancelReplace should pass out an error InsufficientVaultCollateralAmount

  • In cancelReplace if collateral amount is 0 then don't call force_withdraw_collateral hence making the is_allowed_to_withdraw_collateral redundant which is causing the issue.

  • Only do the collateral calculation if the amount is greater than 0

Corner case 2:
There can be a scenario where the vault is trying to exit and has no issue token to back. The vault is trying to withdraw_collateral amount but after withdrawing the collateral will be less than MinimumCollateralVault hence the call will emit out InsufficientVaultCollateralAmount error. In such cases, the withdraw shouldn't fail.

ToDos

  • Find other methods where is_allowed_to_withdraw_collateral is used and can lead to corner cases.
@nakul1010 nakul1010 added the bug Something isn't working label Oct 13, 2023
@nakul1010
Copy link
Member Author

nakul1010 commented Jan 5, 2024

The corner case may arise for different method that use the helper function is_allowed_to_withdraw_collateral because of the following check.
Example: vault trying to withdraw_collateral amount but after withdraw the collateral will be less than MinimumCollateralVault hence the call will emit out InsufficientVaultCollateralAmount error.

@nakul1010 nakul1010 changed the title Allow acceptReplace only if vault is above minimum collateral InsufficientVaultCollateralAmount error when trying to withdraw an amount takes the vault below MinimumCollateral Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: New 🆕
Development

No branches or pull requests

1 participant