Skip to content

Commit

Permalink
Merge pull request #554 from sander2/fix/vault-error
Browse files Browse the repository at this point in the history
refactor!: more explicit error when vault is liquidated
  • Loading branch information
sander2 committed Mar 28, 2022
2 parents 41b0ff3 + becf0d9 commit 2df5c5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions crates/vault-registry/src/lib.rs
Expand Up @@ -563,6 +563,10 @@ pub mod pallet {
MaxNominationRatioViolation,
/// The collateral ceiling would be exceeded for the vault's currency
CurrencyCeilingExceeded,
/// Vault is no longer usable as it was liquidated due to theft
VaultCommittedTheft,
/// Vault is no longer usable as it was liquidated due to undercollateralization
VaultLiquidated,

// Errors used exclusively in RPC functions
/// Collateralization is infinite if no tokens are issued
Expand Down Expand Up @@ -764,11 +768,11 @@ impl<T: Config> Pallet<T> {
/// Like get_vault_from_id, but additionally checks that the vault is active
pub fn get_active_vault_from_id(vault_id: &DefaultVaultId<T>) -> Result<DefaultVault<T>, DispatchError> {
let vault = Self::get_vault_from_id(vault_id)?;
ensure!(
matches!(vault.status, VaultStatus::Active(_)),
Error::<T>::VaultNotFound
);
Ok(vault)
match vault.status {
VaultStatus::Active(_) => Ok(vault),
VaultStatus::Liquidated => Err(Error::<T>::VaultLiquidated.into()),
VaultStatus::CommittedTheft => Err(Error::<T>::VaultCommittedTheft.into()),
}
}

/// Deposit an `amount` of collateral to be used for collateral tokens
Expand Down
2 changes: 1 addition & 1 deletion standalone/runtime/tests/test_redeem.rs
Expand Up @@ -267,7 +267,7 @@ mod spec_based_tests {
vault_id: vault_id.clone(),
})
.dispatch(origin_of(account_of(ALICE))),
VaultRegistryError::VaultNotFound,
VaultRegistryError::VaultLiquidated,
);
});
}
Expand Down

0 comments on commit 2df5c5a

Please sign in to comment.