diff --git a/primitives/src/traits.rs b/primitives/src/traits.rs index 36cbbf00b..f3650674d 100644 --- a/primitives/src/traits.rs +++ b/primitives/src/traits.rs @@ -28,7 +28,6 @@ mod market_transition_api; mod swaps; mod weights; mod zeitgeist_asset; -mod zeitgeist_multi_reservable_currency; pub use complete_set_operations_api::CompleteSetOperationsApi; pub use deploy_pool_api::DeployPoolApi; @@ -42,4 +41,3 @@ pub use market_transition_api::MarketTransitionApi; pub use swaps::Swaps; pub use weights::CheckedDivPerComponent; pub use zeitgeist_asset::*; -pub use zeitgeist_multi_reservable_currency::ZeitgeistAssetManager; diff --git a/primitives/src/traits/zeitgeist_multi_reservable_currency.rs b/primitives/src/traits/zeitgeist_multi_reservable_currency.rs deleted file mode 100644 index 11db3909e..000000000 --- a/primitives/src/traits/zeitgeist_multi_reservable_currency.rs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2023 Forecasting Technologies LTD. -// Copyright 2021-2022 Zeitgeist PM LLC. -// -// This file is part of Zeitgeist. -// -// Zeitgeist is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. -// -// Zeitgeist is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Zeitgeist. If not, see . - -#![allow(clippy::type_complexity)] -use alloc::vec::Vec; -use orml_tokens::{AccountData, Accounts, TotalIssuance}; -use orml_traits::currency::NamedMultiReservableCurrency; -use sp_runtime::{traits::Get, DispatchError}; - -/// Custom `NamedMultiReservableCurrency` trait. -pub trait ZeitgeistAssetManager: NamedMultiReservableCurrency { - /// Return the total number of accounts that hold _any_ asset (first value) and all accounts - /// that hold assets of a given `currency_id` (second value). - /// If the `currency_id` is the native currency, then return None. - fn accounts_by_currency_id( - currency_id: Self::CurrencyId, - ) -> Result<(usize, Vec<(AccountId, AccountData)>), DispatchError>; - - /// Destroy all assets of a `currency_id` for the given `accounts`. - /// If the `currency_id` is the native currency, then return false. - fn destroy_all(currency_id: Self::CurrencyId, accounts: I) -> Result<(), DispatchError> - where - I: Iterator)>; -} - -impl ZeitgeistAssetManager for orml_tokens::Pallet -where - T: orml_tokens::Config, -{ - fn accounts_by_currency_id( - currency_id: Self::CurrencyId, - ) -> Result<(usize, Vec<(T::AccountId, AccountData)>), DispatchError> { - let mut total = 0; - #[allow( - // Iterator will never yield more than `usize::MAX` elements - clippy::arithmetic_side_effects - )] - let accounts = >::iter() - .filter_map(|(k0, k1, v)| { - total += 1; - if k1 == currency_id { Some((k0, v)) } else { None } - }) - .collect(); - Ok((total, accounts)) - } - - fn destroy_all(currency_id: Self::CurrencyId, accounts: I) -> Result<(), DispatchError> - where - I: Iterator)>, - { - for (k0, _) in accounts { - >::remove(k0, currency_id); - } - >::remove(currency_id); - Ok(()) - } -} - -// This implementation will only affect the `MultiCurrency` part, i.e., it won't touch -// the native currency -impl ZeitgeistAssetManager for orml_currencies::Pallet -where - T: orml_currencies::Config, - T::MultiCurrency: ZeitgeistAssetManager, -{ - fn accounts_by_currency_id( - currency_id: Self::CurrencyId, - ) -> Result<(usize, Vec<(T::AccountId, AccountData)>), DispatchError> { - if currency_id == T::GetNativeCurrencyId::get() { - Err(DispatchError::Other("NotForNativeCurrency")) - } else { - T::MultiCurrency::accounts_by_currency_id(currency_id) - } - } - - fn destroy_all(currency_id: Self::CurrencyId, accounts: I) -> Result<(), DispatchError> - where - I: Iterator)>, - { - if currency_id == T::GetNativeCurrencyId::get() { - Err(DispatchError::Other("NotForNativeCurrency")) - } else { - T::MultiCurrency::destroy_all(currency_id, accounts) - } - } -}