Skip to content

Commit

Permalink
fix: simplify replace branch in _request_redeem
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Sep 1, 2023
1 parent 5edbfcf commit dd0ac31
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions crates/redeem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,26 +614,13 @@ impl<T: Config> Pallet<T> {
ext::fee::get_redeem_fee::<T>(&amount_wrapped)?
};

// only allow requests of amount above above the minimum
ensure!(
// this is the amount the vault will send
amount_wrapped.ge(&Self::get_dust_value(vault_id.wrapped_currency()))?,
Error::<T>::AmountBelowDustAmount
);

// increased the to_be_redeem tokens by amount_wrapped - fee_wrapped
ext::vault_registry::try_increase_to_be_redeemed_tokens::<T>(
&vault_id,
&amount_wrapped.checked_sub(&fee_wrapped)?,
)?;

(
fee_wrapped,
// the inclusion fee is paid by old vault itself hence we can set it as zero
Amount::zero(vault_id.wrapped_currency()),
// the new vault (redeemer) should receive the whole amount without deduction of fees
// as fee handling is done by old vault itself
amount_wrapped,
amount_wrapped.clone(),
)
} else {
let redeemer_balance =
Expand All @@ -657,20 +644,24 @@ impl<T: Config> Pallet<T> {
.checked_sub(&inclusion_fee)
.map_err(|_| Error::<T>::AmountBelowDustAmount)?;

// only allow requests of amount above above the minimum
ensure!(
// this is the amount the vault will send (minus fee)
user_to_be_received_btc.ge(&Self::get_dust_value(vault_id.wrapped_currency()))?,
Error::<T>::AmountBelowDustAmount
);

// vault will get rid of the btc + btc_inclusion_fee
ext::vault_registry::try_increase_to_be_redeemed_tokens::<T>(&vault_id, &vault_to_be_burned_tokens)?;
amount_wrapped.lock_on(redeemer.get_account())?;

(fee_wrapped, inclusion_fee, user_to_be_received_btc)
};

// only allow requests of amount above above the minimum
ensure!(
// this is the amount the vault will send
user_to_be_received_btc.ge(&Self::get_dust_value(vault_id.wrapped_currency()))?,
Error::<T>::AmountBelowDustAmount
);

// increased the to_be_redeem tokens by amount_wrapped - fee_wrapped
ext::vault_registry::try_increase_to_be_redeemed_tokens::<T>(
&vault_id,
&amount_wrapped.checked_sub(&fee_wrapped)?,
)?;

let redeem_id = ext::security::get_secure_id::<T>(redeemer.get_account());

let below_premium_redeem = ext::vault_registry::is_vault_below_premium_threshold::<T>(&vault_id)?;
Expand Down

0 comments on commit dd0ac31

Please sign in to comment.