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

Currency pegs #304

Merged
merged 8 commits into from
Jun 20, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 103 additions & 79 deletions Cargo.lock

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions lib-serml/currencies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub mod module {
AmountIntoBalanceFailed,
/// Balance is too low.
BalanceTooLow,
/// Invalid Currency Type.
InvalidCurrencyType,
}

#[pallet::event]
Expand Down Expand Up @@ -124,9 +126,14 @@ pub mod module {
dest: <T::Lookup as StaticLookup>::Source,
currency_id: CurrencyIdOf<T>,
#[pallet::compact] amount: BalanceOf<T>,
// TODO: Add `claim_cashdrop: bool`, and if yes then call clain_cashdrop(origin, currency_id, amount) to claim cashdrop.
) -> DispatchResultWithPostInfo {
let from = ensure_signed(origin)?;
let to = T::Lookup::lookup(dest)?;
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
<Self as MultiCurrency<T::AccountId>>::transfer(currency_id, &from, &to, amount)?;
Ok(().into())
}
Expand Down Expand Up @@ -161,6 +168,10 @@ pub mod module {
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let dest = T::Lookup::lookup(who)?;
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
<Self as MultiCurrencyExtended<T::AccountId>>::update_balance(currency_id, &dest, amount)?;
Ok(().into())
}
Expand All @@ -175,6 +186,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::minimum_balance()
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::minimum_balance(currency_id)
}
}
Expand All @@ -183,6 +198,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::total_issuance()
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::total_issuance(currency_id)
}
}
Expand All @@ -191,6 +210,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::total_balance(who)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::total_balance(currency_id, who)
}
}
Expand All @@ -199,6 +222,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::free_balance(who)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::free_balance(currency_id, who)
}
}
Expand All @@ -207,6 +234,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::ensure_can_withdraw(who, amount)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::ensure_can_withdraw(currency_id, who, amount)
}
}
Expand All @@ -223,6 +254,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::transfer(from, to, amount)?;
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::transfer(currency_id, from, to, amount)?;
}
Self::deposit_event(Event::Transferred(currency_id, from.clone(), to.clone(), amount));
Expand All @@ -236,6 +271,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::deposit(who, amount)?;
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::deposit(currency_id, who, amount)?;
}
Self::deposit_event(Event::Deposited(currency_id, who.clone(), amount));
Expand All @@ -249,6 +288,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::withdraw(who, amount)?;
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::withdraw(currency_id, who, amount)?;
}
Self::deposit_event(Event::Withdrawn(currency_id, who.clone(), amount));
Expand All @@ -259,6 +302,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::can_slash(who, amount)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::can_slash(currency_id, who, amount)
}
}
Expand All @@ -267,6 +314,10 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::slash(who, amount)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::slash(currency_id, who, amount)
}
}
Expand All @@ -279,6 +330,10 @@ impl<T: Config> MultiCurrencyExtended<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::update_balance(who, by_amount)?;
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::update_balance(currency_id, who, by_amount)?;
}
Self::deposit_event(Event::BalanceUpdated(currency_id, who.clone(), by_amount));
Expand All @@ -298,6 +353,10 @@ impl<T: Config> MultiLockableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::set_lock(lock_id, who, amount)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::set_lock(lock_id, currency_id, who, amount)
}
}
Expand All @@ -311,6 +370,10 @@ impl<T: Config> MultiLockableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::extend_lock(lock_id, who, amount)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::extend_lock(lock_id, currency_id, who, amount)
}
}
Expand All @@ -319,6 +382,10 @@ impl<T: Config> MultiLockableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::remove_lock(lock_id, who)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::remove_lock(lock_id, currency_id, who)
}
}
Expand All @@ -329,6 +396,10 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::can_reserve(who, value)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::can_reserve(currency_id, who, value)
}
}
Expand All @@ -337,6 +408,10 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::slash_reserved(who, value)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::slash_reserved(currency_id, who, value)
}
}
Expand All @@ -345,6 +420,10 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::reserved_balance(who)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::reserved_balance(currency_id, who)
}
}
Expand All @@ -353,6 +432,10 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::reserve(who, value)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::reserve(currency_id, who, value)
}
}
Expand All @@ -361,6 +444,10 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::unreserve(who, value)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::unreserve(currency_id, who, value)
}
}
Expand All @@ -375,6 +462,10 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::repatriate_reserved(slashed, beneficiary, value, status)
} else {
ensure!(
!T::FiatCurrencyIds::get().contains(&currency_id),
Error::<T>::InvalidCurrencyType,
);
T::MultiCurrency::repatriate_reserved(currency_id, slashed, beneficiary, value, status)
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib-serml/incentives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ frame-system = { default-features = false, version = '3.0.0', git = 'https://git
sp-std = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05' }

# orml dependencies
orml-traits = { path = "../../lib-orml/traits", default-features = false }
orml-rewards = { path = "../../lib-orml/rewards", default-features = false }
orml-traits = { path = "../../lib-openrml/traits", default-features = false }
orml-rewards = { path = "../../lib-openrml/rewards", default-features = false }

# local dependencies
support = { package = "setheum-support", path = "../support", default-features = false }
Expand All @@ -27,8 +27,8 @@ primitives = { package = "setheum-primitives", path = "../../primitives", defaul
sp-core = { version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'}
sp-io = { version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'}
pallet-balances = { version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'}
orml-tokens = { path = "../../lib-orml/tokens" }
orml-rewards = { path = "../../lib-orml/rewards" }
orml-tokens = { path = "../../lib-openrml/tokens" }
orml-rewards = { path = "../../lib-openrml/rewards" }

[features]
default = ["std"]
Expand Down
Loading