1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pub use primitives::redeem::{RedeemRequest, RedeemRequestStatus};
use primitives::VaultId;
use scale_info::TypeInfo;
use sp_runtime::DispatchError;
use vault_registry::types::CurrencyId;
use crate::Config;
use codec::{Decode, Encode, MaxEncodedLen};
use currency::Amount;
use frame_system::pallet_prelude::BlockNumberFor;
#[derive(Encode, Decode, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub enum Version {
V0,
}
pub(crate) type BalanceOf<T> = <T as currency::Config>::Balance;
pub(crate) type DefaultVaultId<T> = VaultId<<T as frame_system::Config>::AccountId, CurrencyId<T>>;
pub type DefaultRedeemRequest<T> =
RedeemRequest<<T as frame_system::Config>::AccountId, BlockNumberFor<T>, BalanceOf<T>, CurrencyId<T>>;
pub trait RedeemRequestExt<T: Config> {
fn amount_btc(&self) -> Amount<T>;
fn fee(&self) -> Amount<T>;
fn premium(&self) -> Result<Amount<T>, DispatchError>;
fn transfer_fee_btc(&self) -> Amount<T>;
}
impl<T: Config> RedeemRequestExt<T> for RedeemRequest<T::AccountId, BlockNumberFor<T>, BalanceOf<T>, CurrencyId<T>> {
fn amount_btc(&self) -> Amount<T> {
Amount::new(self.amount_btc, self.vault.wrapped_currency())
}
fn fee(&self) -> Amount<T> {
Amount::new(self.fee, self.vault.wrapped_currency())
}
fn premium(&self) -> Result<Amount<T>, DispatchError> {
Ok(Amount::new(self.premium, self.vault.collateral_currency()))
}
fn transfer_fee_btc(&self) -> Amount<T> {
Amount::new(self.transfer_fee_btc, self.vault.wrapped_currency())
}
}