diff --git a/xpallets/assets/src/lib.rs b/xpallets/assets/src/lib.rs index e422515f9..129d634ee 100644 --- a/xpallets/assets/src/lib.rs +++ b/xpallets/assets/src/lib.rs @@ -24,192 +24,112 @@ pub mod weights; use sp_std::{ collections::btree_map::BTreeMap, convert::{TryFrom, TryInto}, - prelude::*, }; use frame_support::{ - decl_error, decl_event, decl_module, decl_storage, dispatch::{DispatchError, DispatchResult}, ensure, + inherent::Vec, log::{debug, error, info}, traits::{Currency, Get, HandleLifetime, LockableCurrency, ReservableCurrency}, - Parameter, StorageDoubleMap, + Parameter, }; + use frame_system::{ensure_root, ensure_signed, AccountInfo}; use orml_traits::arithmetic::{Signed, SimpleArithmetic}; -use sp_runtime::traits::{ - CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Member, Saturating, StaticLookup, Zero, -}; +use sp_runtime::traits::{CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero}; +use self::trigger::AssetChangedTrigger; use chainx_primitives::AssetId; -pub use xpallet_assets_registrar::{AssetInfo, Chain}; use xpallet_support::traits::TreasuryAccount; pub use self::traits::{ChainT, OnAssetChanged}; -use self::trigger::AssetChangedTrigger; pub use self::types::{ AssetErr, AssetRestrictions, AssetType, BalanceLock, TotalAssetInfo, WithdrawalLimit, }; pub use self::weights::WeightInfo; +pub use xpallet_assets_registrar::{AssetInfo, Chain}; pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -/// The module's config trait. -/// -/// `frame_system::Config` should always be included in our implied traits. -pub trait Config: xpallet_assets_registrar::Config { - /// The overarching event type. - type Event: From> + Into<::Event>; - - /// The native currency. - type Currency: ReservableCurrency - + LockableCurrency; - - /// The amount type, should be signed version of `Balance` - type Amount: Parameter - + Member - + Default - + Copy - + MaybeSerializeDeserialize - + Signed - + SimpleArithmetic - + TryInto> - + TryFrom>; - - /// The treasury account. - type TreasuryAccount: TreasuryAccount; - - /// The hook for doing something on the event of creating an account. - type OnCreatedAccount: HandleLifetime; - - /// The hook triggered whenever the asset balance of an account is changed. - type OnAssetChanged: OnAssetChanged>; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; -} - -decl_error! { - /// Error for the Assets Module - pub enum Error for Module { - /// - InvalidAsset, - /// Got an overflow after adding - Overflow, - /// Balance too low to send value - InsufficientBalance, - /// Failed because liquidity restrictions due to locking - LiquidityRestrictions, - /// Cannot convert Amount into Balance type - AmountIntoBalanceFailed, - /// Got an overflow after adding - TotalAssetOverflow, - /// Balance too low to send value - TotalAssetInsufficientBalance, - /// Not Allow native asset, - DenyNativeAsset, - /// Action is not allowed. - ActionNotAllowed, - /// Account still has active reserved - StillHasActiveReserved - } -} - -decl_event!( - pub enum Event - where - ::AccountId, - Balance = BalanceOf, - { - /// Some balances of an asset was moved from one to another. [asset_id, from, from_type, to, to_type, amount] - Moved(AssetId, AccountId, AssetType, AccountId, AssetType, Balance), - /// New balances of an asset were issued. [asset_id, receiver, amount] - Issued(AssetId, AccountId, Balance), - /// Some balances of an asset were destoryed. [asset_id, who, amount] - Destroyed(AssetId, AccountId, Balance), - /// Set asset balance of an account by root. [asset_id, who, asset_type, amount] - BalanceSet(AssetId, AccountId, AssetType, Balance), - } -); - -decl_storage! { - trait Store for Module as XAssets { - /// asset extend limit properties, set asset "can do", example, `CanTransfer`, `CanDestroyWithdrawal` - /// notice if not set AssetRestriction, default is true for this limit - /// if want let limit make sense, must set false for the limit - pub AssetRestrictionsOf get(fn asset_restrictions_of): - map hasher(twox_64_concat) AssetId => AssetRestrictions; - - /// asset balance for user&asset_id, use btree_map to accept different asset type - pub AssetBalance get(fn asset_balance): - double_map hasher(blake2_128_concat) T::AccountId, hasher(twox_64_concat) AssetId - => BTreeMap>; - - /// Any liquidity locks of a token type under an account. - /// NOTE: Should only be accessed when setting, changing and freeing a lock. - pub Locks get(fn locks): - double_map hasher(blake2_128_concat) T::AccountId, hasher(twox_64_concat) AssetId - => Vec>>; - - /// asset balance for an asset_id, use btree_map to accept different asset type - pub TotalAssetBalance get(fn total_asset_balance): - map hasher(twox_64_concat) AssetId => BTreeMap>; - } - add_extra_genesis { - config(assets_restrictions): Vec<(AssetId, AssetRestrictions)>; - config(endowed): BTreeMap)>>; - build(|config| { - for (id, endowed) in &config.endowed { - if *id != T::NativeAssetId::get() { - for (accountid, value) in endowed.iter() { - Module::::issue(id, accountid, *value) - .expect("asset issuance during the genesis can not fail"); - } - } - } - for (id, restrictions) in &config.assets_restrictions { - if *id != T::NativeAssetId::get() { - Module::::set_asset_restrictions(*id, *restrictions) - .expect("should not fail in genesis, qed"); - } - } - }) - } -} - -decl_module! { - pub struct Module for enum Call where origin: T::Origin { - type Error = Error; - - fn deposit_event() = default; - - /// transfer between account - #[weight = 0] +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + /// The pallet's config trait. + /// + /// `frame_system::Config` should always be included in our implied traits. + #[pallet::config] + pub trait Config: frame_system::Config + xpallet_assets_registrar::Config { + /// The overarching event type. + type Event: From> + IsType<::Event>; + + /// The native currency. + type Currency: ReservableCurrency + + LockableCurrency; + + /// The amount type, should be signed version of `Balance` + type Amount: Parameter + + Member + + Default + + Copy + + MaybeSerializeDeserialize + + Signed + + SimpleArithmetic + + TryInto> + + TryFrom>; + + /// The treasury account. + type TreasuryAccount: TreasuryAccount; + + /// The hook for doing something on the event of creating an account. + type OnCreatedAccount: HandleLifetime; + + /// The hook triggered whenever the asset balance of an account is changed. + type OnAssetChanged: OnAssetChanged>; + + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; + } + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(PhantomData); + + #[pallet::call] + impl Pallet { + /// transfer between two accounts + #[pallet::weight(0)] pub fn transfer( - origin, + origin: OriginFor, dest: ::Source, - #[compact] id: AssetId, - #[compact] value: BalanceOf + #[pallet::compact] id: AssetId, + #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let transactor = ensure_signed(origin)?; let dest = T::Lookup::lookup(dest)?; debug!(target: "runtime::assets", "[transfer] from:{:?}, to:{:?}, id:{}, value:{:?}", transactor, dest, id, value); Self::can_transfer(&id)?; - Self::move_usable_balance(&id, &transactor, &dest, value).map_err::, _>(Into::into)?; + Self::move_usable_balance(&id, &transactor, &dest, value) + .map_err::, _>(Into::into)?; Ok(()) } - /// for transfer by root - #[weight = 0] + /// transfer method reserved for root(sudo) + #[pallet::weight(0)] pub fn force_transfer( - origin, + origin: OriginFor, transactor: ::Source, dest: ::Source, - #[compact] id: AssetId, - #[compact] value: BalanceOf + #[pallet::compact] id: AssetId, + #[pallet::compact] value: BalanceOf, ) -> DispatchResult { ensure_root(origin)?; @@ -217,17 +137,18 @@ decl_module! { let dest = T::Lookup::lookup(dest)?; debug!(target: "runtime::assets", "[force_transfer] from:{:?}, to:{:?}, id:{}, value:{:?}", transactor, dest, id, value); Self::can_transfer(&id)?; - Self::move_usable_balance(&id, &transactor, &dest, value).map_err::, _>(Into::into)?; + Self::move_usable_balance(&id, &transactor, &dest, value) + .map_err::, _>(Into::into)?; Ok(()) } /// set free token for an account - #[weight = 0] + #[pallet::weight(0)] pub fn set_balance( - origin, + origin: OriginFor, who: ::Source, - #[compact] id: AssetId, - balances: BTreeMap> + #[pallet::compact] id: AssetId, + balances: BTreeMap>, ) -> DispatchResult { ensure_root(origin)?; @@ -237,27 +158,156 @@ decl_module! { Ok(()) } - #[weight = ::WeightInfo::set_asset_limit()] - pub fn set_asset_limit(origin, #[compact] id: AssetId, restrictions: AssetRestrictions) -> DispatchResult { + /// asset restriction method reserved for root + #[pallet::weight(::WeightInfo::set_asset_limit())] + pub fn set_asset_limit( + origin: OriginFor, + #[pallet::compact] id: AssetId, + restrictions: AssetRestrictions, + ) -> DispatchResult { ensure_root(origin)?; Self::set_asset_restrictions(id, restrictions) } } + + /// Event for the Assets Pallet + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + #[pallet::metadata(T::AccountId = "AccountId", BalanceOf = "Balance")] + pub enum Event { + /// Some balances of an asset was moved from one to another. [asset_id, from, from_type, to, to_type, amount] + Moved( + AssetId, + T::AccountId, + AssetType, + T::AccountId, + AssetType, + BalanceOf, + ), + /// New balances of an asset were issued. [asset_id, receiver, amount] + Issued(AssetId, T::AccountId, BalanceOf), + /// Some balances of an asset were destoryed. [asset_id, who, amount] + Destroyed(AssetId, T::AccountId, BalanceOf), + /// Set asset balance of an account by root. [asset_id, who, asset_type, amount] + BalanceSet(AssetId, T::AccountId, AssetType, BalanceOf), + } + + /// Error for the Assets Pallet + #[pallet::error] + pub enum Error { + /// Got and Invalid Asset + InvalidAsset, + /// Got an overflow after adding + Overflow, + /// Balance too low to send value + InsufficientBalance, + /// Failed because liquidity restrictions due to locking + LiquidityRestrictions, + /// Cannot convert Amount into Balance type + AmountIntoBalanceFailed, + /// Got an overflow after adding + TotalAssetOverflow, + /// Balance too low to send value + TotalAssetInsufficientBalance, + /// Not Allow native asset, + DenyNativeAsset, + /// Action is not allowed. + ActionNotAllowed, + /// Account still has active reserved + StillHasActiveReserved, + } + + /// asset extend limit properties, set asset "can do", example, `CanTransfer`, `CanDestroyWithdrawal` + /// notice if not set AssetRestriction, default is true for this limit + /// if want let limit make sense, must set false for the limit + #[pallet::storage] + #[pallet::getter(fn asset_restrictions_of)] + pub type AssetRestrictionsOf = + StorageMap<_, Twox64Concat, AssetId, AssetRestrictions, ValueQuery>; + + /// asset balance for user&asset_id, use btree_map to accept different asset type + #[pallet::storage] + #[pallet::getter(fn asset_balance)] + pub type AssetBalance = StorageDoubleMap< + _, + Blake2_128Concat, + T::AccountId, + Twox64Concat, + AssetId, + BTreeMap>, + ValueQuery, + >; + + /// Any liquidity locks of a token type under an account. + /// NOTE: Should only be accessed when setting, changing and freeing a lock. + #[pallet::storage] + #[pallet::getter(fn locks)] + pub type Locks = StorageDoubleMap< + _, + Blake2_128Concat, + T::AccountId, + Twox64Concat, + AssetId, + Vec>>, + ValueQuery, + >; + + /// asset balance for an asset_id, use btree_map to accept different asset type + #[pallet::storage] + #[pallet::getter(fn total_asset_balance)] + pub type TotalAssetBalance = + StorageMap<_, Twox64Concat, AssetId, BTreeMap>, ValueQuery>; + + #[pallet::genesis_config] + pub struct GenesisConfig { + pub assets_restrictions: Vec<(AssetId, AssetRestrictions)>, + pub endowed: BTreeMap)>>, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self { + assets_restrictions: Default::default(), + endowed: Default::default(), + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + let extra_genesis_builder: fn(&Self) = |config| { + for (id, endowed) in &config.endowed { + if *id != T::NativeAssetId::get() { + for (accountid, value) in endowed.iter() { + Pallet::::issue(id, accountid, *value) + .expect("asset issuance during the genesis can not fail"); + } + } + } + for (id, restrictions) in &config.assets_restrictions { + if *id != T::NativeAssetId::get() { + Pallet::::set_asset_restrictions(*id, *restrictions) + .expect("should not fail in genesis, qed"); + } + } + }; + extra_genesis_builder(self); + } + } } -// others -impl Module { +impl Pallet { fn set_asset_restrictions( asset_id: AssetId, restrictions: AssetRestrictions, ) -> DispatchResult { - xpallet_assets_registrar::Module::::ensure_asset_exists(&asset_id)?; - AssetRestrictionsOf::insert(asset_id, restrictions); + xpallet_assets_registrar::Pallet::::ensure_asset_exists(&asset_id)?; + AssetRestrictionsOf::::insert(asset_id, restrictions); Ok(()) } -} -impl Module { pub fn ensure_not_native_asset(asset_id: &AssetId) -> DispatchResult { ensure!( *asset_id != T::NativeAssetId::get(), @@ -265,13 +315,11 @@ impl Module { ); Ok(()) } -} -// asset related -impl Module { + // Asset related /// Returns a map of all registered assets by far. pub fn total_asset_infos() -> BTreeMap>> { - xpallet_assets_registrar::Module::::asset_infos() + xpallet_assets_registrar::Pallet::::asset_infos() .filter_map(|(id, info)| { if id == T::NativeAssetId::get() { // ignore native asset @@ -282,7 +330,7 @@ impl Module { TotalAssetInfo { info, balance: Self::total_asset_balance(id), - is_online: xpallet_assets_registrar::Module::::is_online(&id), + is_online: xpallet_assets_registrar::Pallet::::is_online(&id), restrictions: Self::asset_restrictions_of(id), }, ); @@ -292,17 +340,16 @@ impl Module { .collect() } - /// Retutrns the invalid asset info of `who`. + /// Returns the invalid asset info of `who`. pub fn valid_assets_of( who: &T::AccountId, ) -> BTreeMap>> { - use frame_support::IterableStorageDoubleMap; AssetBalance::::iter_prefix(who) - .filter(|(id, _)| xpallet_assets_registrar::Module::::asset_online(id)) + .filter(|(id, _)| xpallet_assets_registrar::Pallet::::asset_online(id)) .collect() } - /// Retutrns whether `restriction` is applied for given asset `id`. + /// Returns whether `restriction` is applied for given asset `id`. pub fn can_do(id: &AssetId, restriction: AssetRestrictions) -> bool { !Self::asset_restrictions_of(id).contains(restriction) } @@ -343,10 +390,8 @@ impl Module { } Ok(()) } -} -// Public read functions. -impl Module { + // Public read functions. /// Returns the total issuance of asset `id` by far. pub fn total_issuance(id: &AssetId) -> BalanceOf { let map = Self::total_asset_balance(id); @@ -389,10 +434,7 @@ impl Module { balance_for(Reserved) + balance_for(ReservedWithdrawal) + balance_for(ReservedDexSpot) } -} -// Public write functions. -impl Module { /// Sets the free balance of `who` without sanity checks and triggering the asset changed hook. #[cfg(feature = "std")] pub fn force_set_free_balance(id: &AssetId, who: &T::AccountId, value: BalanceOf) { @@ -402,7 +444,7 @@ impl Module { /// Increases the Usable balance of `who` given the asset `id` by this `value`. pub fn issue(id: &AssetId, who: &T::AccountId, value: BalanceOf) -> DispatchResult { Self::ensure_not_native_asset(id)?; - xpallet_assets_registrar::Module::::ensure_asset_is_valid(id)?; + xpallet_assets_registrar::Pallet::::ensure_asset_is_valid(id)?; let _imbalance = Self::inner_issue(id, who, AssetType::Usable, value)?; Ok(()) @@ -414,7 +456,7 @@ impl Module { value: BalanceOf, ) -> DispatchResult { Self::ensure_not_native_asset(id)?; - xpallet_assets_registrar::Module::::ensure_asset_is_valid(id)?; + xpallet_assets_registrar::Pallet::::ensure_asset_is_valid(id)?; Self::can_destroy_withdrawal(id)?; Self::inner_destroy(id, who, AssetType::ReservedWithdrawal, value)?; @@ -423,7 +465,7 @@ impl Module { pub fn destroy_usable(id: &AssetId, who: &T::AccountId, value: BalanceOf) -> DispatchResult { Self::ensure_not_native_asset(id)?; - xpallet_assets_registrar::Module::::ensure_asset_is_valid(id)?; + xpallet_assets_registrar::Pallet::::ensure_asset_is_valid(id)?; Self::can_destroy_usable(id)?; Self::inner_destroy(id, who, AssetType::Usable, value)?; @@ -439,7 +481,7 @@ impl Module { value: BalanceOf, ) -> Result<(), AssetErr> { Self::ensure_not_native_asset(id).map_err(|_| AssetErr::InvalidAsset)?; - xpallet_assets_registrar::Module::::ensure_asset_is_valid(id) + xpallet_assets_registrar::Pallet::::ensure_asset_is_valid(id) .map_err(|_| AssetErr::InvalidAsset)?; Self::can_move(id).map_err(|_| AssetErr::NotAllow)?; @@ -510,10 +552,7 @@ impl Module { } Ok(()) } -} -/// token issue destroy reserve/unreserve, it's core function -impl Module { /// Returns the balance of `who` given `asset_id` and `ty`. fn asset_typed_balance(who: &T::AccountId, asset_id: &AssetId, ty: AssetType) -> BalanceOf { Self::asset_balance(who, asset_id) diff --git a/xpallets/assets/src/mock.rs b/xpallets/assets/src/mock.rs index 538cbff95..06311f7b9 100644 --- a/xpallets/assets/src/mock.rs +++ b/xpallets/assets/src/mock.rs @@ -8,7 +8,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; -use frame_support::{parameter_types, sp_io}; +use frame_support::{parameter_types, sp_io, traits::GenesisBuild}; use chainx_primitives::AssetId; pub use xp_protocol::X_BTC; diff --git a/xpallets/assets/src/multicurrency.rs b/xpallets/assets/src/multicurrency.rs index 7ec0c549f..f8a2f890f 100644 --- a/xpallets/assets/src/multicurrency.rs +++ b/xpallets/assets/src/multicurrency.rs @@ -10,7 +10,7 @@ use frame_support::{ ensure, log::error, traits::{BalanceStatus, LockIdentifier}, - transactional, IterableStorageDoubleMap, + transactional, }; use orml_traits::{ @@ -22,9 +22,9 @@ use chainx_primitives::AssetId; use xpallet_support::traits::TreasuryAccount; use crate::types::{AssetType, BalanceLock}; -use crate::{AssetBalance, BalanceOf, Config, Error, Module}; +use crate::{AssetBalance, BalanceOf, Config, Error, Pallet}; -impl MultiCurrency for Module { +impl MultiCurrency for Pallet { type CurrencyId = AssetId; type Balance = BalanceOf; @@ -173,7 +173,7 @@ impl MultiCurrency for Module { } } -impl MultiCurrencyExtended for Module { +impl MultiCurrencyExtended for Pallet { type Amount = T::Amount; fn update_balance( @@ -195,7 +195,7 @@ impl MultiCurrencyExtended for Module { } } -impl MultiReservableCurrency for Module { +impl MultiReservableCurrency for Pallet { fn can_reserve( currency_id: Self::CurrencyId, who: &T::AccountId, @@ -326,7 +326,7 @@ impl MultiReservableCurrency for Module { } } -impl MultiLockableCurrency for Module { +impl MultiLockableCurrency for Pallet { type Moment = T::BlockNumber; fn set_lock( @@ -404,7 +404,7 @@ impl MultiLockableCurrency for Module { } } -impl MergeAccount for Module { +impl MergeAccount for Pallet { #[transactional] fn merge_account(source: &T::AccountId, dest: &T::AccountId) -> DispatchResult { AssetBalance::::iter_prefix(source).try_for_each( diff --git a/xpallets/assets/src/trigger.rs b/xpallets/assets/src/trigger.rs index 4b4a12a8c..b457926e8 100644 --- a/xpallets/assets/src/trigger.rs +++ b/xpallets/assets/src/trigger.rs @@ -6,7 +6,7 @@ use chainx_primitives::AssetId; use crate::traits::OnAssetChanged; use crate::types::{AssetErr, AssetType}; -use crate::{BalanceOf, Config, Event, Module}; +use crate::{BalanceOf, Config, Event, Pallet}; impl OnAssetChanged for () {} @@ -32,7 +32,7 @@ impl AssetChangedTrigger { to_type: AssetType, value: BalanceOf, ) -> Result<(), AssetErr> { - Module::::deposit_event(Event::::Moved( + Pallet::::deposit_event(Event::::Moved( *id, from.clone(), from_type, @@ -49,7 +49,7 @@ impl AssetChangedTrigger { } pub fn on_issue_post(id: &AssetId, who: &T::AccountId, value: BalanceOf) -> DispatchResult { - Module::::deposit_event(Event::::Issued(*id, who.clone(), value)); + Pallet::::deposit_event(Event::::Issued(*id, who.clone(), value)); T::OnAssetChanged::on_issue_post(id, who, value)?; Ok(()) } @@ -63,7 +63,7 @@ impl AssetChangedTrigger { who: &T::AccountId, value: BalanceOf, ) -> DispatchResult { - Module::::deposit_event(Event::::Destroyed(*id, who.clone(), value)); + Pallet::::deposit_event(Event::::Destroyed(*id, who.clone(), value)); T::OnAssetChanged::on_destroy_post(id, who, value)?; Ok(()) } @@ -74,7 +74,7 @@ impl AssetChangedTrigger { type_: AssetType, value: BalanceOf, ) -> DispatchResult { - Module::::deposit_event(Event::::BalanceSet(*id, who.clone(), type_, value)); + Pallet::::deposit_event(Event::::BalanceSet(*id, who.clone(), type_, value)); T::OnAssetChanged::on_set_balance(id, who, type_, value)?; Ok(()) } diff --git a/xpallets/assets/src/weights.rs b/xpallets/assets/src/weights.rs index 7a26cd8af..4cdd06dab 100644 --- a/xpallets/assets/src/weights.rs +++ b/xpallets/assets/src/weights.rs @@ -32,7 +32,7 @@ use sp_std::marker::PhantomData; pub trait WeightInfo { fn transfer() -> Weight; fn force_transfer() -> Weight; - fn set_balance(n: u32) -> Weight; + fn set_balance() -> Weight; fn set_asset_limit() -> Weight; } @@ -49,7 +49,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } - fn set_balance(_n: u32) -> Weight { + fn set_balance() -> Weight { (218_742_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) @@ -73,7 +73,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } - fn set_balance(_n: u32) -> Weight { + fn set_balance() -> Weight { (218_742_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) diff --git a/xpallets/dex/spot/src/mock.rs b/xpallets/dex/spot/src/mock.rs index 2d85711ce..c68376518 100644 --- a/xpallets/dex/spot/src/mock.rs +++ b/xpallets/dex/spot/src/mock.rs @@ -5,7 +5,11 @@ use std::{ collections::{BTreeMap, HashSet}, }; -use frame_support::{parameter_types, traits::Get, weights::Weight}; +use frame_support::{ + parameter_types, + traits::{GenesisBuild, Get}, + weights::Weight, +}; use sp_core::H256; use sp_runtime::{ testing::Header, diff --git a/xpallets/gateway/common/src/mock.rs b/xpallets/gateway/common/src/mock.rs index 19f6cf702..150baccce 100644 --- a/xpallets/gateway/common/src/mock.rs +++ b/xpallets/gateway/common/src/mock.rs @@ -3,8 +3,10 @@ use std::{cell::RefCell, convert::TryFrom, time::Duration}; use codec::{Decode, Encode}; -use frame_support::traits::UnixTime; -use frame_support::{parameter_types, sp_io}; +use frame_support::{ + parameter_types, sp_io, + traits::{GenesisBuild, UnixTime}, +}; use frame_system::EnsureSignedBy; use sp_core::{crypto::UncheckedInto, H256}; use sp_io::hashing::blake2_256; diff --git a/xpallets/gateway/records/src/mock.rs b/xpallets/gateway/records/src/mock.rs index 5c8a319e0..e804be402 100644 --- a/xpallets/gateway/records/src/mock.rs +++ b/xpallets/gateway/records/src/mock.rs @@ -1,6 +1,6 @@ // Copyright 2019-2020 ChainX Project Authors. Licensed under GPL-3.0. -use frame_support::{parameter_types, sp_io}; +use frame_support::{parameter_types, sp_io, traits::GenesisBuild}; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -8,10 +8,11 @@ use sp_runtime::{ }; use chainx_primitives::AssetId; -pub use xp_protocol::{X_BTC, X_ETH}; use xpallet_assets::AssetRestrictions; use xpallet_assets_registrar::AssetInfo; +pub use xp_protocol::{X_BTC, X_ETH}; + use crate::{self as xpallet_gateway_records, *}; /// The AccountId alias in this test module.