Skip to content

Commit

Permalink
Revert "refactor!: remove VaultStatus::CommittedTheft and add migration"
Browse files Browse the repository at this point in the history
This reverts commit 78bdebb.

Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
  • Loading branch information
gregdhill committed Jul 22, 2022
1 parent 78bdebb commit 0c15911
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 256 deletions.
3 changes: 3 additions & 0 deletions crates/vault-registry/src/lib.rs
Expand Up @@ -601,6 +601,8 @@ 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,
/// Vault must be either liquidated or flagged for theft.
Expand Down Expand Up @@ -844,6 +846,7 @@ impl<T: Config> Pallet<T> {
match vault.status {
VaultStatus::Active(_) => Ok(vault),
VaultStatus::Liquidated => Err(Error::<T>::VaultLiquidated.into()),
VaultStatus::CommittedTheft => Err(Error::<T>::VaultCommittedTheft.into()),
}
}

Expand Down
36 changes: 9 additions & 27 deletions crates/vault-registry/src/types.rs
Expand Up @@ -190,28 +190,6 @@ pub mod liquidation_vault_fix {
pub mod v4 {
use super::*;

#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)]
pub enum VaultStatusV4 {
/// Vault is active - bool=true indicates that the vault accepts new issue requests
Active(bool),

/// Vault has been liquidated
Liquidated,

/// Vault theft has been reported
CommittedTheft,
}

impl Into<VaultStatus> for VaultStatusV4 {
fn into(self) -> VaultStatus {
match self {
VaultStatusV4::Active(accept_issue) => VaultStatus::Active(accept_issue),
VaultStatusV4::Liquidated => VaultStatus::Liquidated,
VaultStatusV4::CommittedTheft => VaultStatus::Liquidated,
}
}
}

#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct VaultV4<AccountId, BlockNumber, Balance, CurrencyId: Copy> {
Expand All @@ -220,7 +198,7 @@ pub mod v4 {
/// Bitcoin address of this Vault (P2PKH, P2SH, P2WPKH, P2WSH)
pub wallet: Wallet,
/// Current status of the vault
pub status: VaultStatusV4,
pub status: VaultStatus,
/// Block height until which this Vault is banned from being used for
/// Issue, Redeem (except during automatic liquidation) and Replace.
pub banned_until: Option<BlockNumber>,
Expand Down Expand Up @@ -268,7 +246,7 @@ pub mod v4 {
Some(Vault {
id: vault_v4.id,
wallet: vault_v4.wallet,
status: vault_v4.status.into(),
status: vault_v4.status,
banned_until: vault_v4.banned_until,
secure_collateral_threshold: None,
to_be_issued_tokens: vault_v4.to_be_issued_tokens,
Expand Down Expand Up @@ -315,7 +293,7 @@ pub mod v4 {
.into(),
},
banned_until: None,
status: VaultStatusV4::Active(true),
status: VaultStatus::Active(true),
issued_tokens: Default::default(),
liquidated_collateral: Default::default(),
replace_collateral: Default::default(),
Expand All @@ -338,7 +316,7 @@ pub mod v4 {
wallet: Wallet {
addresses: vault.wallet.addresses.clone(),
},
status: vault.status.into(),
status: vault.status.clone(),
banned_until: vault.banned_until,
secure_collateral_threshold: None,
to_be_issued_tokens: vault.to_be_issued_tokens,
Expand Down Expand Up @@ -392,6 +370,10 @@ pub enum VaultStatus {

/// Vault has been liquidated
Liquidated,

/// Vault theft has been reported
// TODO: remove this, requires migration
CommittedTheft,
}

impl Default for VaultStatus {
Expand Down Expand Up @@ -478,7 +460,7 @@ impl<
}

pub fn is_liquidated(&self) -> bool {
matches!(self.status, VaultStatus::Liquidated)
matches!(self.status, VaultStatus::Liquidated | VaultStatus::CommittedTheft)
}
}

Expand Down

0 comments on commit 0c15911

Please sign in to comment.