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

refactor!: more explicit error when vault is liquidated #554

Merged
merged 1 commit into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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