Skip to content

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

@nakul1010

Description

@nakul1010

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    New 🆕

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions