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
Describe the bug
The issue with
is_allowed_to_withdraw_collateralhelper method is, that it passes out an errorInsufficientVaultCollateralAmountwhen trying to withdraw an amount that falls belowMinimumCollateralbut in some cases it is not idealCorner case 1:
When a vault accepts a replace, it doesn't seem to check whether the vault's is below the
minimum_collateral_vaultthreshold.This will cause issues when the vault tries tocancelReplacesince, the extrinsic will only allow to cancel if vault is aboveminimum_collateral_vaultthreshold.Steps to reproduce the behavior:
Set
minimum_collateral_vaultto amount x.Set vault stake to amount y. Where y < x.
Send an
acceptReplacerequest to vaultTry to
cancelReplaceshould pass out an errorInsufficientVaultCollateralAmountIn
cancelReplaceifcollateralamount is0then don't callforce_withdraw_collateralhence making theis_allowed_to_withdraw_collateralredundant which is causing the issue.Only do the collateral calculation if the amount is greater than
0Corner 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_collateralamount but after withdrawing the collateral will be less thanMinimumCollateralVaulthence the call will emit outInsufficientVaultCollateralAmounterror. In such cases, the withdraw shouldn't fail.ToDos
is_allowed_to_withdraw_collateralis used and can lead to corner cases.