From f89b5bcefec5f00a2ee60204abda9f03bfd0fd42 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 23 Nov 2022 21:10:14 +0100 Subject: [PATCH 01/10] instantiate all assets pallets --- parachains/common/src/impls.rs | 11 +-- parachains/common/src/lib.rs | 2 +- parachains/common/src/xcm_config.rs | 20 +++-- .../runtimes/assets/statemine/src/lib.rs | 73 ++++++++++++------- .../assets/statemine/src/xcm_config.rs | 30 +++++--- .../runtimes/assets/statemine/tests/tests.rs | 38 +++++----- .../runtimes/assets/statemint/src/lib.rs | 72 +++++++++++------- .../assets/statemint/src/xcm_config.rs | 16 ++-- .../runtimes/assets/statemint/tests/tests.rs | 10 +-- .../runtimes/assets/westmint/src/lib.rs | 73 ++++++++++++------- .../assets/westmint/src/xcm_config.rs | 30 +++++--- .../runtimes/assets/westmint/tests/tests.rs | 38 +++++----- .../testing/rococo-parachain/src/lib.rs | 8 +- 13 files changed, 251 insertions(+), 170 deletions(-) diff --git a/parachains/common/src/impls.rs b/parachains/common/src/impls.rs index 80c3015b47a..9768acef6da 100644 --- a/parachains/common/src/impls.rs +++ b/parachains/common/src/impls.rs @@ -71,17 +71,18 @@ where /// A `HandleCredit` implementation that naively transfers the fees to the block author. /// Will drop and burn the assets in case the transfer fails. -pub struct AssetsToBlockAuthor(PhantomData); -impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor +pub struct AssetsToBlockAuthor(PhantomData<(R, I)>); +impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor where - R: pallet_authorship::Config + pallet_assets::Config, + I: 'static, + R: pallet_authorship::Config + pallet_assets::Config, AccountIdOf: From + Into, { - fn handle_credit(credit: CreditOf, pallet_assets::Pallet>) { + fn handle_credit(credit: CreditOf, pallet_assets::Pallet>) { if let Some(author) = pallet_authorship::Pallet::::author() { // In case of error: Will drop the result triggering the `OnDrop` of the imbalance. - let _ = pallet_assets::Pallet::::resolve(&author, credit); + let _ = pallet_assets::Pallet::::resolve(&author, credit); } } } diff --git a/parachains/common/src/lib.rs b/parachains/common/src/lib.rs index c192d6e2a7e..067babc3a0b 100644 --- a/parachains/common/src/lib.rs +++ b/parachains/common/src/lib.rs @@ -62,7 +62,7 @@ mod types { pub type StatemintAuraId = sp_consensus_aura::ed25519::AuthorityId; // Id used for identifying assets. - pub type AssetId = u32; + pub type AssetIdForTrustBackedAssets = u32; } /// Common constants of parachains. diff --git a/parachains/common/src/xcm_config.rs b/parachains/common/src/xcm_config.rs index b9ae5ef87ce..34ab67e5f53 100644 --- a/parachains/common/src/xcm_config.rs +++ b/parachains/common/src/xcm_config.rs @@ -82,24 +82,30 @@ pub struct AssetFeeAsExistentialDepositMultiplier cumulus_primitives_utility::ChargeWeightInFungibles< AccountIdOf, - pallet_assets::Pallet, + pallet_assets::Pallet, > for AssetFeeAsExistentialDepositMultiplier where - Runtime: pallet_assets::Config, + Runtime: pallet_assets::Config, WeightToFee: WeightToFeePolynomial, BalanceConverter: BalanceConversion< CurrencyBalance, - ::AssetId, - ::Balance, + >::AssetId, + >::Balance, >, AccountIdOf: From + Into, { fn charge_weight_in_fungibles( - asset_id: as Inspect>>::AssetId, + asset_id: as Inspect< + AccountIdOf, + >>::AssetId, weight: Weight, - ) -> Result< as Inspect>>::Balance, XcmError> - { + ) -> Result< + as Inspect< + AccountIdOf, + >>::Balance, + XcmError, + > { let amount = WeightToFee::weight_to_fee(&weight); // If the amount gotten is not at least the ED, then make it be the ED of the asset // This is to avoid burning assets and decreasing the supply diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 9b754fcbf1e..69681e28601 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -60,8 +60,9 @@ use frame_system::{ pub use parachains_common as common; use parachains_common::{ impls::{AssetsToBlockAuthor, DealWithFees}, - opaque, AccountId, AssetId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature, - AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, + opaque, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, + Index, Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, + NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; use xcm_config::{KsmLocation, XcmConfig}; @@ -242,10 +243,12 @@ parameter_types! { pub type AssetsForceOrigin = EitherOfDiverse, EnsureXcm>>; -impl pallet_assets::Config for Runtime { +pub type TrustBackedAssetsInstance = pallet_assets::Instance1; +type TrustBackedAssetsCall = pallet_assets::Call; +impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = AssetId; + type AssetId = AssetIdForTrustBackedAssets; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = AssetsForceOrigin; @@ -340,7 +343,7 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!( c, RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( @@ -352,7 +355,7 @@ impl InstanceFilter for ProxyType { ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::Uniques { .. } @@ -360,15 +363,17 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(pallet_assets::Call::create { .. }) | - RuntimeCall::Assets(pallet_assets::Call::start_destroy { .. }) | - RuntimeCall::Assets(pallet_assets::Call::destroy_accounts { .. }) | - RuntimeCall::Assets(pallet_assets::Call::destroy_approvals { .. }) | - RuntimeCall::Assets(pallet_assets::Call::finish_destroy { .. }) | - RuntimeCall::Assets(pallet_assets::Call::transfer_ownership { .. }) | - RuntimeCall::Assets(pallet_assets::Call::set_team { .. }) | - RuntimeCall::Assets(pallet_assets::Call::set_metadata { .. }) | - RuntimeCall::Assets(pallet_assets::Call::clear_metadata { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::TrustBackedAssets( + TrustBackedAssetsCall::destroy_accounts { .. } + ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::TrustBackedAssets( + TrustBackedAssetsCall::transfer_ownership { .. } + ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::clear_metadata { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | @@ -385,12 +390,12 @@ impl InstanceFilter for ProxyType { ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(pallet_assets::Call::mint { .. }) | - RuntimeCall::Assets(pallet_assets::Call::burn { .. }) | - RuntimeCall::Assets(pallet_assets::Call::freeze { .. }) | - RuntimeCall::Assets(pallet_assets::Call::thaw { .. }) | - RuntimeCall::Assets(pallet_assets::Call::freeze_asset { .. }) | - RuntimeCall::Assets(pallet_assets::Call::thaw_asset { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw_asset { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | @@ -534,9 +539,14 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = Assets; + type Fungibles = TrustBackedAssets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, AssetsToBlockAuthor, >; } @@ -613,7 +623,7 @@ construct_runtime!( Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 42, // The main stage. - Assets: pallet_assets::{Pallet, Call, Storage, Event} = 50, + TrustBackedAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 51, #[cfg(feature = "state-trie-version-1")] @@ -652,9 +662,20 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - pallet_assets::migration::v1::MigrateToV1, + // Note: Removed v1 storage migration. Assume this has been applied in some upgrade. + // Do not release until verified! + MigrateAssetsPallet, >; +pub struct MigrateAssetsPallet; +impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet { + fn on_runtime_upgrade() -> Weight { + use frame_support::storage::migration; + migration::move_pallet(b"Assets", b"TrustBackedAssets"); + ::DbWeight::get().writes(1) + } +} + #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; @@ -663,7 +684,7 @@ extern crate frame_benchmarking; mod benches { define_benchmarks!( [frame_system, SystemBench::] - [pallet_assets, Assets] + [pallet_assets, TrustBackedAssets] [pallet_balances, Balances] [pallet_multisig, Multisig] [pallet_proxy, Proxy] diff --git a/parachains/runtimes/assets/statemine/src/xcm_config.rs b/parachains/runtimes/assets/statemine/src/xcm_config.rs index e4b8fd99fa0..77097ed55fa 100644 --- a/parachains/runtimes/assets/statemine/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemine/src/xcm_config.rs @@ -14,8 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetId, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, + TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -48,8 +49,8 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const Local: MultiLocation = Here.into(); - pub AssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); + pub TrustBackedAssetsPalletLocation: MultiLocation = + PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } @@ -82,12 +83,12 @@ pub type CurrencyTransactor = CurrencyAdapter< /// Means for transacting assets besides the native currency on this chain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: - Assets, + TrustBackedAssets, // Use this currency when it is a fungible asset matching the given location or name: ConvertedConcreteAssetId< - AssetId, + AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, // Convert an XCM MultiLocation into a local account id: @@ -96,7 +97,7 @@ pub type FungiblesTransactor = FungiblesAdapter< AccountId, // We only want to allow teleports of known assets. We use non-zero issuance as an indication // that this asset is known. - parachains_common::impls::NonZeroIssuance, + parachains_common::impls::NonZeroIssuance, // The account to use for tracking teleports. CheckingAccount, >; @@ -182,15 +183,20 @@ impl xcm_executor::Config for XcmConfig { AssetFeeAsExistentialDepositMultiplier< Runtime, WeightToFee, - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, >, ConvertedConcreteAssetId< - AssetId, + AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, - Assets, + TrustBackedAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< FungiblesTransactor, AccountId, diff --git a/parachains/runtimes/assets/statemine/tests/tests.rs b/parachains/runtimes/assets/statemine/tests/tests.rs index 974f89ec1ee..d39da4c9706 100644 --- a/parachains/runtimes/assets/statemine/tests/tests.rs +++ b/parachains/runtimes/assets/statemine/tests/tests.rs @@ -6,7 +6,7 @@ use frame_support::{ }; use parachains_common::{AccountId, AuraId}; pub use statemine_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit, + constants::fee::WeightToFee, xcm_config::XcmConfig, TrustBackedAssets, Balances, ExistentialDeposit, Runtime, SessionKeys, System, }; use xcm::latest::prelude::*; @@ -26,7 +26,7 @@ fn test_asset_xcm_trader() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -35,7 +35,7 @@ fn test_asset_xcm_trader() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1, AccountId::from(ALICE).into(), @@ -57,7 +57,7 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -74,12 +74,12 @@ fn test_asset_xcm_trader() { // Make sure author(Alice) has received the amount assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + amount_needed ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + amount_needed); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + amount_needed); }); } @@ -96,7 +96,7 @@ fn test_asset_xcm_trader_with_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -105,7 +105,7 @@ fn test_asset_xcm_trader_with_refund() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1, AccountId::from(ALICE).into(), @@ -124,7 +124,7 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -161,12 +161,12 @@ fn test_asset_xcm_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight_used)); assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + fees_paid); }); } @@ -183,7 +183,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -203,7 +203,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -223,10 +223,10 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(Assets::total_supply(1), 0); + assert_eq!(TrustBackedAssets::total_supply(1), 0); }); } @@ -243,7 +243,7 @@ fn test_that_buying_ed_refund_does_not_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -263,7 +263,7 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -296,9 +296,9 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); }); } diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 1b215b61564..a515eeaa3f3 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -89,8 +89,8 @@ use frame_system::{ pub use parachains_common as common; use parachains_common::{ impls::{AssetsToBlockAuthor, DealWithFees}, - opaque, AccountId, AssetId, Balance, BlockNumber, Hash, Header, Index, Signature, - StatemintAuraId as AuraId, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, + opaque, AccountId, AssetIdForTrustBackedAssets, Balance, BlockNumber, Hash, Header, Index, + Signature, StatemintAuraId as AuraId, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; use xcm_config::{DotLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}; @@ -258,10 +258,12 @@ parameter_types! { pub type AssetsForceOrigin = EitherOfDiverse, EnsureXcm>>; -impl pallet_assets::Config for Runtime { +pub type TrustBackedAssetsInstance = pallet_assets::Instance1; +type TrustBackedAssetsCall = pallet_assets::Call; +impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = AssetId; + type AssetId = AssetIdForTrustBackedAssets; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = AssetsForceOrigin; @@ -356,7 +358,7 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!( c, RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( @@ -368,7 +370,7 @@ impl InstanceFilter for ProxyType { ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::Uniques { .. } @@ -376,15 +378,17 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(pallet_assets::Call::create { .. }) | - RuntimeCall::Assets(pallet_assets::Call::start_destroy { .. }) | - RuntimeCall::Assets(pallet_assets::Call::destroy_accounts { .. }) | - RuntimeCall::Assets(pallet_assets::Call::destroy_approvals { .. }) | - RuntimeCall::Assets(pallet_assets::Call::finish_destroy { .. }) | - RuntimeCall::Assets(pallet_assets::Call::transfer_ownership { .. }) | - RuntimeCall::Assets(pallet_assets::Call::set_team { .. }) | - RuntimeCall::Assets(pallet_assets::Call::set_metadata { .. }) | - RuntimeCall::Assets(pallet_assets::Call::clear_metadata { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::TrustBackedAssets( + TrustBackedAssetsCall::destroy_accounts { .. } + ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::TrustBackedAssets( + TrustBackedAssetsCall::transfer_ownership { .. } + ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::clear_metadata { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | @@ -401,12 +405,12 @@ impl InstanceFilter for ProxyType { ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(pallet_assets::Call::mint { .. }) | - RuntimeCall::Assets(pallet_assets::Call::burn { .. }) | - RuntimeCall::Assets(pallet_assets::Call::freeze { .. }) | - RuntimeCall::Assets(pallet_assets::Call::thaw { .. }) | - RuntimeCall::Assets(pallet_assets::Call::freeze_asset { .. }) | - RuntimeCall::Assets(pallet_assets::Call::thaw_asset { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw_asset { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | @@ -550,9 +554,14 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = Assets; + type Fungibles = TrustBackedAssets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, AssetsToBlockAuthor, >; } @@ -629,7 +638,7 @@ construct_runtime!( Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 42, // The main stage. - Assets: pallet_assets::{Pallet, Call, Storage, Event} = 50, + TrustBackedAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 51, } ); @@ -665,9 +674,20 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - pallet_assets::migration::v1::MigrateToV1, + // Note: Removed v1 storage migration. Assume this has been applied in some upgrade. + // Do not release until verified! + MigrateAssetsPallet, >; +pub struct MigrateAssetsPallet; +impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet { + fn on_runtime_upgrade() -> Weight { + use frame_support::storage::migration; + migration::move_pallet(b"Assets", b"TrustBackedAssets"); + ::DbWeight::get().writes(1) + } +} + #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; @@ -676,7 +696,7 @@ extern crate frame_benchmarking; mod benches { define_benchmarks!( [frame_system, SystemBench::] - [pallet_assets, Assets] + [pallet_assets, TrustBackedAssets] [pallet_balances, Balances] [pallet_multisig, Multisig] [pallet_proxy, Proxy] diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index eaaa04f2f67..3b455a9b25b 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -14,8 +14,8 @@ // limitations under the License. use super::{ - AccountId, AssetId, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -45,8 +45,8 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const Local: MultiLocation = Here.into(); - pub AssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); + pub TrustBackedAssetsPalletLocation: MultiLocation = + PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } @@ -79,12 +79,12 @@ pub type CurrencyTransactor = CurrencyAdapter< /// Means for transacting assets besides the native currency on this chain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: - Assets, + TrustBackedAssets, // Use this currency when it is a fungible asset matching the given location or name: ConvertedConcreteAssetId< - AssetId, + AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, // Convert an XCM MultiLocation into a local account id: @@ -93,7 +93,7 @@ pub type FungiblesTransactor = FungiblesAdapter< AccountId, // We only want to allow teleports of known assets. We use non-zero issuance as an indication // that this asset is known. - parachains_common::impls::NonZeroIssuance, + parachains_common::impls::NonZeroIssuance, // The account to use for tracking teleports. CheckingAccount, >; diff --git a/parachains/runtimes/assets/statemint/tests/tests.rs b/parachains/runtimes/assets/statemint/tests/tests.rs index 77cb45c1cc5..98e351f63b3 100644 --- a/parachains/runtimes/assets/statemint/tests/tests.rs +++ b/parachains/runtimes/assets/statemint/tests/tests.rs @@ -6,7 +6,7 @@ use frame_support::{ }; use parachains_common::{AccountId, StatemintAuraId as AuraId}; pub use statemint_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit, + constants::fee::WeightToFee, xcm_config::XcmConfig, TrustBackedAssets, Balances, ExistentialDeposit, Runtime, SessionKeys, System, }; use xcm::latest::prelude::*; @@ -26,7 +26,7 @@ fn test_asset_xcm_trader_does_not_work_in_statemine() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -52,7 +52,7 @@ fn test_asset_xcm_trader_does_not_work_in_statemine() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -65,9 +65,9 @@ fn test_asset_xcm_trader_does_not_work_in_statemine() { assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(Assets::total_supply(1), 0); + assert_eq!(TrustBackedAssets::total_supply(1), 0); }); } diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index 4661266a1ff..167a403533d 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -60,8 +60,9 @@ use frame_system::{ pub use parachains_common as common; use parachains_common::{ impls::{AssetsToBlockAuthor, DealWithFees}, - opaque, AccountId, AssetId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature, - AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, + opaque, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, + Index, Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, + NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; @@ -223,10 +224,12 @@ parameter_types! { pub type AssetsForceOrigin = EnsureRoot; -impl pallet_assets::Config for Runtime { +pub type TrustBackedAssetsInstance = pallet_assets::Instance1; +type TrustBackedAssetsCall = pallet_assets::Call; +impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = AssetId; + type AssetId = AssetIdForTrustBackedAssets; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = AssetsForceOrigin; @@ -321,7 +324,7 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!( c, RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( @@ -333,7 +336,7 @@ impl InstanceFilter for ProxyType { ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::Uniques { .. } @@ -341,15 +344,17 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(pallet_assets::Call::create { .. }) | - RuntimeCall::Assets(pallet_assets::Call::start_destroy { .. }) | - RuntimeCall::Assets(pallet_assets::Call::destroy_accounts { .. }) | - RuntimeCall::Assets(pallet_assets::Call::destroy_approvals { .. }) | - RuntimeCall::Assets(pallet_assets::Call::finish_destroy { .. }) | - RuntimeCall::Assets(pallet_assets::Call::transfer_ownership { .. }) | - RuntimeCall::Assets(pallet_assets::Call::set_team { .. }) | - RuntimeCall::Assets(pallet_assets::Call::set_metadata { .. }) | - RuntimeCall::Assets(pallet_assets::Call::clear_metadata { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::TrustBackedAssets( + TrustBackedAssetsCall::destroy_accounts { .. } + ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::TrustBackedAssets( + TrustBackedAssetsCall::transfer_ownership { .. } + ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::clear_metadata { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | @@ -366,12 +371,12 @@ impl InstanceFilter for ProxyType { ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(pallet_assets::Call::mint { .. }) | - RuntimeCall::Assets(pallet_assets::Call::burn { .. }) | - RuntimeCall::Assets(pallet_assets::Call::freeze { .. }) | - RuntimeCall::Assets(pallet_assets::Call::thaw { .. }) | - RuntimeCall::Assets(pallet_assets::Call::freeze_asset { .. }) | - RuntimeCall::Assets(pallet_assets::Call::thaw_asset { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw_asset { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | @@ -510,9 +515,14 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = Assets; + type Fungibles = TrustBackedAssets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, AssetsToBlockAuthor, >; } @@ -589,7 +599,7 @@ construct_runtime!( Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 42, // The main stage. - Assets: pallet_assets::{Pallet, Call, Storage, Event} = 50, + TrustBackedAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 51, } ); @@ -625,9 +635,20 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - pallet_assets::migration::v1::MigrateToV1, + // Note: Removed v1 storage migration. Assume this has been applied in some upgrade. + // Do not release until verified! + MigrateAssetsPallet, >; +pub struct MigrateAssetsPallet; +impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet { + fn on_runtime_upgrade() -> Weight { + use frame_support::storage::migration; + migration::move_pallet(b"Assets", b"TrustBackedAssets"); + ::DbWeight::get().writes(1) + } +} + #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; @@ -636,7 +657,7 @@ extern crate frame_benchmarking; mod benches { define_benchmarks!( [frame_system, SystemBench::] - [pallet_assets, Assets] + [pallet_assets, TrustBackedAssets] [pallet_balances, Balances] [pallet_multisig, Multisig] [pallet_proxy, Proxy] diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index 6b36b797207..77ff1c6fb7c 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -14,8 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetId, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, + TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -49,8 +50,8 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const Local: MultiLocation = Here.into(); - pub AssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); + pub TrustBackedAssetsPalletLocation: MultiLocation = + PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } @@ -83,12 +84,12 @@ pub type CurrencyTransactor = CurrencyAdapter< /// Means for transacting assets besides the native currency on this chain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: - Assets, + TrustBackedAssets, // Use this currency when it is a fungible asset matching the given location or name: ConvertedConcreteAssetId< - AssetId, + AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, // Convert an XCM MultiLocation into a local account id: @@ -97,7 +98,7 @@ pub type FungiblesTransactor = FungiblesAdapter< AccountId, // We only want to allow teleports of known assets. We use non-zero issuance as an indication // that this asset is known. - parachains_common::impls::NonZeroIssuance, + parachains_common::impls::NonZeroIssuance, // The account to use for tracking teleports. CheckingAccount, >; @@ -179,15 +180,20 @@ impl xcm_executor::Config for XcmConfig { AssetFeeAsExistentialDepositMultiplier< Runtime, WeightToFee, - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, >, ConvertedConcreteAssetId< - AssetId, + AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, - Assets, + TrustBackedAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< FungiblesTransactor, AccountId, diff --git a/parachains/runtimes/assets/westmint/tests/tests.rs b/parachains/runtimes/assets/westmint/tests/tests.rs index 1bd8f7c5ec8..842d6c0dafa 100644 --- a/parachains/runtimes/assets/westmint/tests/tests.rs +++ b/parachains/runtimes/assets/westmint/tests/tests.rs @@ -6,7 +6,7 @@ use frame_support::{ }; use parachains_common::{AccountId, AuraId}; pub use westmint_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit, + constants::fee::WeightToFee, xcm_config::XcmConfig, TrustBackedAssets, Balances, ExistentialDeposit, Runtime, SessionKeys, System, }; use xcm::latest::prelude::*; @@ -27,7 +27,7 @@ fn test_asset_xcm_trader() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -36,7 +36,7 @@ fn test_asset_xcm_trader() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1, AccountId::from(ALICE).into(), @@ -58,7 +58,7 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -75,12 +75,12 @@ fn test_asset_xcm_trader() { // Make sure author(Alice) has received the amount assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + amount_needed ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + amount_needed); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + amount_needed); }); } @@ -97,7 +97,7 @@ fn test_asset_xcm_trader_with_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -106,7 +106,7 @@ fn test_asset_xcm_trader_with_refund() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1, AccountId::from(ALICE).into(), @@ -124,7 +124,7 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -161,12 +161,12 @@ fn test_asset_xcm_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight_used)); assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + fees_paid); }); } @@ -183,7 +183,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -203,7 +203,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -223,10 +223,10 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(Assets::total_supply(1), 0); + assert_eq!(TrustBackedAssets::total_supply(1), 0); }); } @@ -243,7 +243,7 @@ fn test_that_buying_ed_refund_does_not_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1, AccountId::from(ALICE).into(), @@ -262,7 +262,7 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -295,9 +295,9 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); }); } diff --git a/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/parachains/runtimes/testing/rococo-parachain/src/lib.rs index f6ae5c1fb67..0216fb9dc9e 100644 --- a/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -61,7 +61,7 @@ pub use sp_runtime::{Perbill, Permill}; use parachains_common::{ impls::{AssetsFrom, NonZeroIssuance}, - AccountId, AssetId, Signature, + AccountId, AssetIdForTrustBackedAssets, Signature, }; use xcm_builder::{ AllowKnownQueryResponses, AllowSubscriptionsFrom, AsPrefixedGeneralIndex, @@ -318,9 +318,9 @@ pub type FungiblesTransactor = FungiblesAdapter< Assets, // Use this currency when it is a fungible asset matching the given location or name: ConvertedConcreteAssetId< - AssetId, + AssetIdForTrustBackedAssets, u64, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, // Convert an XCM MultiLocation into a local account id: @@ -495,7 +495,7 @@ pub type AdminOrigin = impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = u64; - type AssetId = AssetId; + type AssetId = AssetIdForTrustBackedAssets; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = AdminOrigin; From 88d6744ec1cc549de7131eac9d1d8e1e40dc2782 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 23 Nov 2022 21:27:08 +0100 Subject: [PATCH 02/10] assets instance --- parachains/runtimes/assets/statemine/src/lib.rs | 2 +- parachains/runtimes/assets/statemint/src/lib.rs | 2 +- parachains/runtimes/assets/westmint/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 69681e28601..66eb06daef9 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -244,7 +244,7 @@ pub type AssetsForceOrigin = EitherOfDiverse, EnsureXcm>>; pub type TrustBackedAssetsInstance = pallet_assets::Instance1; -type TrustBackedAssetsCall = pallet_assets::Call; +type TrustBackedAssetsCall = pallet_assets::Call; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index a515eeaa3f3..85bbca50768 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -259,7 +259,7 @@ pub type AssetsForceOrigin = EitherOfDiverse, EnsureXcm>>; pub type TrustBackedAssetsInstance = pallet_assets::Instance1; -type TrustBackedAssetsCall = pallet_assets::Call; +type TrustBackedAssetsCall = pallet_assets::Call; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index 167a403533d..bf77f6edfe8 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -225,7 +225,7 @@ parameter_types! { pub type AssetsForceOrigin = EnsureRoot; pub type TrustBackedAssetsInstance = pallet_assets::Instance1; -type TrustBackedAssetsCall = pallet_assets::Call; +type TrustBackedAssetsCall = pallet_assets::Call; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; From cc751f03ae5adce1aca074a75825e81448bcf571 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 23 Nov 2022 21:27:22 +0100 Subject: [PATCH 03/10] fmt --- .../assets/statemine/src/xcm_config.rs | 18 +++++++---- .../runtimes/assets/statemine/tests/tests.rs | 30 +++++++++++-------- .../assets/statemint/src/xcm_config.rs | 11 +++++-- .../runtimes/assets/statemint/tests/tests.rs | 8 ++--- .../assets/westmint/src/xcm_config.rs | 18 +++++++---- .../runtimes/assets/westmint/tests/tests.rs | 30 +++++++++++-------- 6 files changed, 74 insertions(+), 41 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/xcm_config.rs b/parachains/runtimes/assets/statemine/src/xcm_config.rs index 77097ed55fa..fd1cf76d01e 100644 --- a/parachains/runtimes/assets/statemine/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemine/src/xcm_config.rs @@ -14,9 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, - TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, + ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -88,7 +88,11 @@ pub type FungiblesTransactor = FungiblesAdapter< ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex< + TrustBackedAssetsPalletLocation, + AssetIdForTrustBackedAssets, + JustTry, + >, JustTry, >, // Convert an XCM MultiLocation into a local account id: @@ -193,7 +197,11 @@ impl xcm_executor::Config for XcmConfig { ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex< + TrustBackedAssetsPalletLocation, + AssetIdForTrustBackedAssets, + JustTry, + >, JustTry, >, TrustBackedAssets, diff --git a/parachains/runtimes/assets/statemine/tests/tests.rs b/parachains/runtimes/assets/statemine/tests/tests.rs index d39da4c9706..812950b0859 100644 --- a/parachains/runtimes/assets/statemine/tests/tests.rs +++ b/parachains/runtimes/assets/statemine/tests/tests.rs @@ -6,8 +6,8 @@ use frame_support::{ }; use parachains_common::{AccountId, AuraId}; pub use statemine_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, TrustBackedAssets, Balances, ExistentialDeposit, - Runtime, SessionKeys, System, + constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit, Runtime, + SessionKeys, System, TrustBackedAssets, }; use xcm::latest::prelude::*; use xcm_executor::traits::WeightTrader; @@ -57,8 +57,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -79,7 +79,10 @@ fn test_asset_xcm_trader() { ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + amount_needed); + assert_eq!( + TrustBackedAssets::total_supply(1), + ExistentialDeposit::get() + amount_needed + ); }); } @@ -124,8 +127,8 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -203,8 +206,8 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -263,8 +266,8 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -296,7 +299,10 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!( + TrustBackedAssets::balance(1, AccountId::from(ALICE)), + ExistentialDeposit::get() + ); // We also need to ensure the total supply increased assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index 3b455a9b25b..544a7ee2634 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -14,8 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, WeightToFee, XcmpQueue, + AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, + ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + TrustBackedAssets, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -84,7 +85,11 @@ pub type FungiblesTransactor = FungiblesAdapter< ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex< + TrustBackedAssetsPalletLocation, + AssetIdForTrustBackedAssets, + JustTry, + >, JustTry, >, // Convert an XCM MultiLocation into a local account id: diff --git a/parachains/runtimes/assets/statemint/tests/tests.rs b/parachains/runtimes/assets/statemint/tests/tests.rs index 98e351f63b3..fcdebc8a88a 100644 --- a/parachains/runtimes/assets/statemint/tests/tests.rs +++ b/parachains/runtimes/assets/statemint/tests/tests.rs @@ -6,8 +6,8 @@ use frame_support::{ }; use parachains_common::{AccountId, StatemintAuraId as AuraId}; pub use statemint_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, TrustBackedAssets, Balances, ExistentialDeposit, - Runtime, SessionKeys, System, + constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit, Runtime, + SessionKeys, System, TrustBackedAssets, }; use xcm::latest::prelude::*; use xcm_executor::traits::WeightTrader; @@ -52,8 +52,8 @@ fn test_asset_xcm_trader_does_not_work_in_statemine() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index 77ff1c6fb7c..88943fd97b7 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -14,9 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, - TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, + ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -89,7 +89,11 @@ pub type FungiblesTransactor = FungiblesAdapter< ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex< + TrustBackedAssetsPalletLocation, + AssetIdForTrustBackedAssets, + JustTry, + >, JustTry, >, // Convert an XCM MultiLocation into a local account id: @@ -190,7 +194,11 @@ impl xcm_executor::Config for XcmConfig { ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex< + TrustBackedAssetsPalletLocation, + AssetIdForTrustBackedAssets, + JustTry, + >, JustTry, >, TrustBackedAssets, diff --git a/parachains/runtimes/assets/westmint/tests/tests.rs b/parachains/runtimes/assets/westmint/tests/tests.rs index 842d6c0dafa..49fadcfe610 100644 --- a/parachains/runtimes/assets/westmint/tests/tests.rs +++ b/parachains/runtimes/assets/westmint/tests/tests.rs @@ -6,8 +6,8 @@ use frame_support::{ }; use parachains_common::{AccountId, AuraId}; pub use westmint_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, TrustBackedAssets, Balances, ExistentialDeposit, - Runtime, SessionKeys, System, + constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit, Runtime, + SessionKeys, System, TrustBackedAssets, }; use xcm::latest::prelude::*; use xcm_executor::traits::WeightTrader; @@ -58,8 +58,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -80,7 +80,10 @@ fn test_asset_xcm_trader() { ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + amount_needed); + assert_eq!( + TrustBackedAssets::total_supply(1), + ExistentialDeposit::get() + amount_needed + ); }); } @@ -124,8 +127,8 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -203,8 +206,8 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -262,8 +265,8 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -295,7 +298,10 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!( + TrustBackedAssets::balance(1, AccountId::from(ALICE)), + ExistentialDeposit::get() + ); // We also need to ensure the total supply increased assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); From b0d80fbe537ea1cc921c2c78703f202a1ded7ba9 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Tue, 29 Nov 2022 16:34:53 +0100 Subject: [PATCH 04/10] fix merge errors --- .../assets/statemine/src/xcm_config.rs | 2 +- .../runtimes/assets/statemine/tests/tests.rs | 16 ++++---- .../assets/statemint/src/xcm_config.rs | 10 ++--- .../runtimes/assets/statemint/tests/tests.rs | 38 +++++++++---------- .../assets/westmint/src/xcm_config.rs | 2 +- .../runtimes/assets/westmint/tests/tests.rs | 18 ++++----- .../testing/rococo-parachain/src/lib.rs | 2 +- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/xcm_config.rs b/parachains/runtimes/assets/statemine/src/xcm_config.rs index ea6da02f142..03faba20909 100644 --- a/parachains/runtimes/assets/statemine/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemine/src/xcm_config.rs @@ -165,7 +165,7 @@ pub type Barrier = DenyThenTry< pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentialDepositMultiplier< Runtime, WeightToFee, - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance, >; pub struct XcmConfig; diff --git a/parachains/runtimes/assets/statemine/tests/tests.rs b/parachains/runtimes/assets/statemine/tests/tests.rs index 43c858659e3..88514462f17 100644 --- a/parachains/runtimes/assets/statemine/tests/tests.rs +++ b/parachains/runtimes/assets/statemine/tests/tests.rs @@ -51,7 +51,7 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(local_asset_id.into()), @@ -99,7 +99,7 @@ fn test_asset_xcm_trader() { ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance + asset_amount_needed); + assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance + asset_amount_needed); }); } @@ -322,7 +322,7 @@ fn test_that_buying_ed_refund_does_not_refund() { ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); }); } @@ -339,7 +339,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { .execute_with(|| { // Create a non-sufficient asset with specific existential deposit let minimum_asset_balance = 1_000_000_u128; - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -348,7 +348,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -370,7 +370,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -386,9 +386,9 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance); + assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); }); } diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index 3030f824fde..14fa90e9b41 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -16,7 +16,7 @@ use super::{ AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - TrustBackedAssets, WeightToFee, XcmpQueue, + TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -165,7 +165,7 @@ pub type Barrier = DenyThenTry< pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentialDepositMultiplier< Runtime, WeightToFee, - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance, >; pub struct XcmConfig; @@ -192,12 +192,12 @@ impl xcm_executor::Config for XcmConfig { AccountId, AssetFeeAsExistentialDepositMultiplierFeeCharger, ConvertedConcreteAssetId< - AssetId, + AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, - Assets, + TrustBackedAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< FungiblesTransactor, AccountId, diff --git a/parachains/runtimes/assets/statemint/tests/tests.rs b/parachains/runtimes/assets/statemint/tests/tests.rs index 2109f12fab5..868c6c9b20b 100644 --- a/parachains/runtimes/assets/statemint/tests/tests.rs +++ b/parachains/runtimes/assets/statemint/tests/tests.rs @@ -30,7 +30,7 @@ fn test_asset_xcm_trader() { // We need root origin to create a sufficient asset let minimum_asset_balance = 333333333_u128; let local_asset_id = 1; - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -39,7 +39,7 @@ fn test_asset_xcm_trader() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -51,7 +51,7 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(local_asset_id.into()), @@ -97,12 +97,12 @@ fn test_asset_xcm_trader() { // Make sure author(Alice) has received the amount assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance + asset_amount_needed); + assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance + asset_amount_needed); }); } @@ -128,7 +128,7 @@ fn test_asset_xcm_trader_with_refund() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -150,7 +150,7 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -187,12 +187,12 @@ fn test_asset_xcm_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight_used)); assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + fees_paid); }); } @@ -209,7 +209,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -272,7 +272,7 @@ fn test_that_buying_ed_refund_does_not_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -292,7 +292,7 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -325,10 +325,10 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); }); } @@ -345,7 +345,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { .execute_with(|| { // Create a non-sufficient asset let minimum_asset_balance = 1_000_000_u128; - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -354,7 +354,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -379,7 +379,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -395,9 +395,9 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance); + assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); }); } diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index 5d085fc0405..ad52c577a6c 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -162,7 +162,7 @@ pub type Barrier = DenyThenTry< pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentialDepositMultiplier< Runtime, WeightToFee, - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance, >; pub struct XcmConfig; diff --git a/parachains/runtimes/assets/westmint/tests/tests.rs b/parachains/runtimes/assets/westmint/tests/tests.rs index 671f62d63c8..8c76a92ca89 100644 --- a/parachains/runtimes/assets/westmint/tests/tests.rs +++ b/parachains/runtimes/assets/westmint/tests/tests.rs @@ -51,7 +51,7 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(local_asset_id.into()), @@ -94,12 +94,12 @@ fn test_asset_xcm_trader() { // Make sure author(Alice) has received the amount assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), + TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance + asset_amount_needed); + assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance + asset_amount_needed); }); } @@ -320,7 +320,7 @@ fn test_that_buying_ed_refund_does_not_refund() { ); // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); }); } @@ -337,7 +337,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { .execute_with(|| { // Create a non-sufficient asset with specific existential deposit let minimum_asset_balance = 1_000_000_u128; - assert_ok!(Assets::force_create( + assert_ok!(TrustBackedAssets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -346,7 +346,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( + assert_ok!(TrustBackedAssets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -368,7 +368,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() + ::PalletInfo::index::().unwrap() as u8, ), GeneralIndex(1), @@ -384,9 +384,9 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance); + assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); }); } diff --git a/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/parachains/runtimes/testing/rococo-parachain/src/lib.rs index ffcb0439b9a..25f8dc37e9c 100644 --- a/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -496,7 +496,7 @@ impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = u64; type AssetId = AssetIdForTrustBackedAssets; - type AssetIdParameter = codec::Compact; + type AssetIdParameter = codec::Compact; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = AdminOrigin; From 5185939696804e76ff6cd48ba05c458077c94f8a Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Tue, 29 Nov 2022 16:41:18 +0100 Subject: [PATCH 05/10] fmt --- .../runtimes/assets/statemine/tests/tests.rs | 18 +++++++---- .../assets/statemint/src/xcm_config.rs | 6 +++- .../runtimes/assets/statemint/tests/tests.rs | 31 ++++++++++++------- .../runtimes/assets/westmint/tests/tests.rs | 18 +++++++---- 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/parachains/runtimes/assets/statemine/tests/tests.rs b/parachains/runtimes/assets/statemine/tests/tests.rs index 88514462f17..4e68ee3c0e9 100644 --- a/parachains/runtimes/assets/statemine/tests/tests.rs +++ b/parachains/runtimes/assets/statemine/tests/tests.rs @@ -51,8 +51,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(local_asset_id.into()), ), @@ -99,7 +99,10 @@ fn test_asset_xcm_trader() { ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance + asset_amount_needed); + assert_eq!( + TrustBackedAssets::total_supply(1), + minimum_asset_balance + asset_amount_needed + ); }); } @@ -370,8 +373,8 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -386,7 +389,10 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!( + TrustBackedAssets::balance(1, AccountId::from(ALICE)), + minimum_asset_balance + ); // We also need to ensure the total supply NOT increased assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index 14fa90e9b41..a4834667b2f 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -194,7 +194,11 @@ impl xcm_executor::Config for XcmConfig { ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex< + TrustBackedAssetsPalletLocation, + AssetIdForTrustBackedAssets, + JustTry, + >, JustTry, >, TrustBackedAssets, diff --git a/parachains/runtimes/assets/statemint/tests/tests.rs b/parachains/runtimes/assets/statemint/tests/tests.rs index 868c6c9b20b..8427f3af4dd 100644 --- a/parachains/runtimes/assets/statemint/tests/tests.rs +++ b/parachains/runtimes/assets/statemint/tests/tests.rs @@ -51,8 +51,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(local_asset_id.into()), ), @@ -102,7 +102,10 @@ fn test_asset_xcm_trader() { ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance + asset_amount_needed); + assert_eq!( + TrustBackedAssets::total_supply(1), + minimum_asset_balance + asset_amount_needed + ); }); } @@ -150,8 +153,8 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -292,8 +295,8 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -325,7 +328,10 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); + assert_eq!( + TrustBackedAssets::balance(1, AccountId::from(ALICE)), + ExistentialDeposit::get() + ); // We also need to ensure the total supply increased assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); @@ -379,8 +385,8 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -395,7 +401,10 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!( + TrustBackedAssets::balance(1, AccountId::from(ALICE)), + minimum_asset_balance + ); // We also need to ensure the total supply NOT increased assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); diff --git a/parachains/runtimes/assets/westmint/tests/tests.rs b/parachains/runtimes/assets/westmint/tests/tests.rs index 8c76a92ca89..9e489e1c363 100644 --- a/parachains/runtimes/assets/westmint/tests/tests.rs +++ b/parachains/runtimes/assets/westmint/tests/tests.rs @@ -51,8 +51,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(local_asset_id.into()), ), @@ -99,7 +99,10 @@ fn test_asset_xcm_trader() { ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance + asset_amount_needed); + assert_eq!( + TrustBackedAssets::total_supply(1), + minimum_asset_balance + asset_amount_needed + ); }); } @@ -368,8 +371,8 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::().unwrap() - as u8, + ::PalletInfo::index::() + .unwrap() as u8, ), GeneralIndex(1), ), @@ -384,7 +387,10 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); + assert_eq!( + TrustBackedAssets::balance(1, AccountId::from(ALICE)), + minimum_asset_balance + ); // We also need to ensure the total supply NOT increased assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); From 460ff7ec9ac74335dd1520f63513a06bed526071 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Tue, 29 Nov 2022 17:02:24 +0100 Subject: [PATCH 06/10] no default instance --- parachains/common/src/impls.rs | 4 ++-- parachains/runtimes/assets/statemine/src/lib.rs | 2 +- parachains/runtimes/assets/statemint/src/lib.rs | 2 +- parachains/runtimes/assets/westmint/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/parachains/common/src/impls.rs b/parachains/common/src/impls.rs index 9768acef6da..8e4b2cf4b8f 100644 --- a/parachains/common/src/impls.rs +++ b/parachains/common/src/impls.rs @@ -71,8 +71,8 @@ where /// A `HandleCredit` implementation that naively transfers the fees to the block author. /// Will drop and burn the assets in case the transfer fails. -pub struct AssetsToBlockAuthor(PhantomData<(R, I)>); -impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor +pub struct AssetsToBlockAuthor(PhantomData<(R, I)>); +impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor where I: 'static, R: pallet_authorship::Config + pallet_assets::Config, diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 5245c7e35ed..adb09b1c5e6 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -550,7 +550,7 @@ impl pallet_asset_tx_payment::Config for Runtime { ConvertInto, TrustBackedAssetsInstance, >, - AssetsToBlockAuthor, + AssetsToBlockAuthor, >; } diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 64faa7a4a31..535d28da92c 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -565,7 +565,7 @@ impl pallet_asset_tx_payment::Config for Runtime { ConvertInto, TrustBackedAssetsInstance, >, - AssetsToBlockAuthor, + AssetsToBlockAuthor, >; } diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index a8e730f7a3a..d5a282bef4d 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -526,7 +526,7 @@ impl pallet_asset_tx_payment::Config for Runtime { ConvertInto, TrustBackedAssetsInstance, >, - AssetsToBlockAuthor, + AssetsToBlockAuthor, >; } From 3c811c97602c59455d8aa1d923b3b1ddaf9360ae Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 30 Nov 2022 11:26:21 +0000 Subject: [PATCH 07/10] Generic AssetFeeAsExistentialDepositMultiplier Signed-off-by: Oliver Tale-Yazdi --- parachains/common/src/xcm_config.rs | 27 ++++++++++--------- .../assets/statemine/src/xcm_config.rs | 1 + .../assets/statemint/src/xcm_config.rs | 1 + .../assets/westmint/src/xcm_config.rs | 1 + 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/parachains/common/src/xcm_config.rs b/parachains/common/src/xcm_config.rs index 67ffd731d4a..4796baa10ce 100644 --- a/parachains/common/src/xcm_config.rs +++ b/parachains/common/src/xcm_config.rs @@ -76,34 +76,35 @@ impl ShouldExecute for DenyReserveTransferToRelayChain { /// A `ChargeFeeInFungibles` implementation that converts the output of /// a given WeightToFee implementation an amount charged in /// a particular assetId from pallet-assets -pub struct AssetFeeAsExistentialDepositMultiplier( - PhantomData<(Runtime, WeightToFee, BalanceConverter)>, -); -impl +pub struct AssetFeeAsExistentialDepositMultiplier< + Runtime, + WeightToFee, + BalanceConverter, + AssetInstance: 'static, +>(PhantomData<(Runtime, WeightToFee, BalanceConverter, AssetInstance)>); +impl cumulus_primitives_utility::ChargeWeightInFungibles< AccountIdOf, - pallet_assets::Pallet, - > for AssetFeeAsExistentialDepositMultiplier + pallet_assets::Pallet, + > for AssetFeeAsExistentialDepositMultiplier where - Runtime: pallet_assets::Config, + Runtime: pallet_assets::Config, WeightToFee: WeightToFeePolynomial, BalanceConverter: BalanceConversion< CurrencyBalance, - >::AssetId, - >::Balance, + >::AssetId, + >::Balance, >, AccountIdOf: From + Into, { fn charge_weight_in_fungibles( - asset_id: as Inspect< + asset_id: as Inspect< AccountIdOf, >>::AssetId, weight: Weight, ) -> Result< - as Inspect< - AccountIdOf, - >>::Balance, + as Inspect>>::Balance, XcmError, > { let amount = WeightToFee::weight_to_fee(&weight); diff --git a/parachains/runtimes/assets/statemine/src/xcm_config.rs b/parachains/runtimes/assets/statemine/src/xcm_config.rs index 03faba20909..019c9dfd9b5 100644 --- a/parachains/runtimes/assets/statemine/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemine/src/xcm_config.rs @@ -166,6 +166,7 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia Runtime, WeightToFee, pallet_assets::BalanceToAssetBalance, + TrustBackedAssetsInstance, >; pub struct XcmConfig; diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index a4834667b2f..da26aea8aaa 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -166,6 +166,7 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia Runtime, WeightToFee, pallet_assets::BalanceToAssetBalance, + TrustBackedAssetsInstance, >; pub struct XcmConfig; diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index ad52c577a6c..6066960980c 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -163,6 +163,7 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia Runtime, WeightToFee, pallet_assets::BalanceToAssetBalance, + TrustBackedAssetsInstance, >; pub struct XcmConfig; From 13c89913825fafb070550899d5034e1c4bc7ca22 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 11 Jan 2023 14:25:44 +0100 Subject: [PATCH 08/10] remove old import --- parachains/runtimes/assets/westmint/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index d6166209ac1..faf1daf7eaf 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -61,8 +61,8 @@ use pallet_nfts::PalletFeatures; pub use parachains_common as common; use parachains_common::{ impls::{AssetsToBlockAuthor, DealWithFees}, - opaque, AccountId, AssetId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, - Header, Index, Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, + opaque, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, + Index, Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; From 7f5a83cf10bb36cc12b0624da7864c67baa89b53 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 11 Jan 2023 16:21:31 +0100 Subject: [PATCH 09/10] don't rename pallet in runtime --- .../runtimes/assets/statemine/src/lib.rs | 60 +++++++--------- .../assets/statemine/src/xcm_config.rs | 12 ++-- .../runtimes/assets/statemine/tests/tests.rs | 69 ++++++++----------- .../runtimes/assets/statemint/src/lib.rs | 60 +++++++--------- .../assets/statemint/src/xcm_config.rs | 12 ++-- .../runtimes/assets/statemint/tests/tests.rs | 69 ++++++++----------- .../runtimes/assets/westmint/src/lib.rs | 60 +++++++--------- .../assets/westmint/src/xcm_config.rs | 12 ++-- .../runtimes/assets/westmint/tests/tests.rs | 69 ++++++++----------- 9 files changed, 186 insertions(+), 237 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 2f69ac662b4..2256586308d 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -232,6 +232,9 @@ parameter_types! { pub type AssetsForceOrigin = EitherOfDiverse, EnsureXcm>>; +// Called "Trust Backed" assets because these are generally registered by some account, and users of +// the asset assume it has some claimed backing. The pallet is called `Assets` in +// `construct_runtime` to avoid breaking changes on storage reads. pub type TrustBackedAssetsInstance = pallet_assets::Instance1; type TrustBackedAssetsCall = pallet_assets::Call; impl pallet_assets::Config for Runtime { @@ -336,7 +339,7 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!( c, RuntimeCall::Balances { .. } | - RuntimeCall::TrustBackedAssets { .. } | + RuntimeCall::Assets { .. } | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( @@ -348,7 +351,7 @@ impl InstanceFilter for ProxyType { ProxyType::Assets => { matches!( c, - RuntimeCall::TrustBackedAssets { .. } | + RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::Uniques { .. } @@ -356,17 +359,15 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::TrustBackedAssets( - TrustBackedAssetsCall::destroy_accounts { .. } - ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::TrustBackedAssets( - TrustBackedAssetsCall::transfer_ownership { .. } - ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | @@ -383,12 +384,12 @@ impl InstanceFilter for ProxyType { ), ProxyType::AssetManager => matches!( c, - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | @@ -546,7 +547,7 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = TrustBackedAssets; + type Fungibles = Assets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< pallet_assets::BalanceToAssetBalance< Balances, @@ -630,7 +631,7 @@ construct_runtime!( Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 42, // The main stage. - TrustBackedAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, + Assets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 51, #[cfg(feature = "state-trie-version-1")] @@ -662,6 +663,8 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; +/// Migrations to apply on runtime upgrade. +pub type Migrations = (); /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< @@ -670,20 +673,9 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - // Note: Removed v1 storage migration. Assume this has been applied in some upgrade. - // Do not release until verified! - MigrateAssetsPallet, + Migrations, >; -pub struct MigrateAssetsPallet; -impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet { - fn on_runtime_upgrade() -> Weight { - use frame_support::storage::migration; - migration::move_pallet(b"Assets", b"TrustBackedAssets"); - ::DbWeight::get().writes(1) - } -} - #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; @@ -692,7 +684,7 @@ extern crate frame_benchmarking; mod benches { define_benchmarks!( [frame_system, SystemBench::] - [pallet_assets, TrustBackedAssets] + [pallet_assets, Assets] [pallet_balances, Balances] [pallet_multisig, Multisig] [pallet_proxy, Proxy] diff --git a/parachains/runtimes/assets/statemine/src/xcm_config.rs b/parachains/runtimes/assets/statemine/src/xcm_config.rs index 019c9dfd9b5..3f910190122 100644 --- a/parachains/runtimes/assets/statemine/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemine/src/xcm_config.rs @@ -14,9 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, + AccountId, AssetIdForTrustBackedAssets, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -50,7 +50,7 @@ parameter_types! { pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const Local: MultiLocation = Here.into(); pub TrustBackedAssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); + PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } @@ -83,7 +83,7 @@ pub type CurrencyTransactor = CurrencyAdapter< /// Means for transacting assets besides the native currency on this chain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: - TrustBackedAssets, + Assets, // Use this currency when it is a fungible asset matching the given location or name: ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, @@ -101,7 +101,7 @@ pub type FungiblesTransactor = FungiblesAdapter< AccountId, // We only want to allow teleports of known assets. We use non-zero issuance as an indication // that this asset is known. - parachains_common::impls::NonZeroIssuance, + parachains_common::impls::NonZeroIssuance, // The account to use for tracking teleports. CheckingAccount, >; @@ -202,7 +202,7 @@ impl xcm_executor::Config for XcmConfig { >, JustTry, >, - TrustBackedAssets, + Assets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< FungiblesTransactor, AccountId, diff --git a/parachains/runtimes/assets/statemine/tests/tests.rs b/parachains/runtimes/assets/statemine/tests/tests.rs index 4e68ee3c0e9..18caaaf3f7e 100644 --- a/parachains/runtimes/assets/statemine/tests/tests.rs +++ b/parachains/runtimes/assets/statemine/tests/tests.rs @@ -8,8 +8,8 @@ use frame_support::{ use parachains_common::{AccountId, AuraId}; use statemine_runtime::xcm_config::AssetFeeAsExistentialDepositMultiplierFeeCharger; pub use statemine_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit, Runtime, - SessionKeys, System, TrustBackedAssets, + constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit, + Runtime, SessionKeys, System, }; use xcm::latest::prelude::*; use xcm_executor::traits::WeightTrader; @@ -30,7 +30,7 @@ fn test_asset_xcm_trader() { // We need root origin to create a sufficient asset let minimum_asset_balance = 3333333_u128; let local_asset_id = 1; - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -39,7 +39,7 @@ fn test_asset_xcm_trader() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -51,8 +51,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(local_asset_id.into()), ), @@ -94,15 +94,12 @@ fn test_asset_xcm_trader() { // Make sure author(Alice) has received the amount assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), + Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased - assert_eq!( - TrustBackedAssets::total_supply(1), - minimum_asset_balance + asset_amount_needed - ); + assert_eq!(Assets::total_supply(1), minimum_asset_balance + asset_amount_needed); }); } @@ -119,7 +116,7 @@ fn test_asset_xcm_trader_with_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -128,7 +125,7 @@ fn test_asset_xcm_trader_with_refund() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -147,8 +144,8 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -184,12 +181,12 @@ fn test_asset_xcm_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight_used)); assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), + Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); }); } @@ -206,7 +203,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -226,8 +223,8 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -246,10 +243,10 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(TrustBackedAssets::total_supply(1), 0); + assert_eq!(Assets::total_supply(1), 0); }); } @@ -266,7 +263,7 @@ fn test_that_buying_ed_refund_does_not_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -286,8 +283,8 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -319,13 +316,10 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), - ExistentialDeposit::get() - ); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); }); } @@ -342,7 +336,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { .execute_with(|| { // Create a non-sufficient asset with specific existential deposit let minimum_asset_balance = 1_000_000_u128; - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -351,7 +345,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -373,8 +367,8 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -389,12 +383,9 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), - minimum_asset_balance - ); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); + assert_eq!(Assets::total_supply(1), minimum_asset_balance); }); } diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index b5f454df6a3..14a35816780 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -247,6 +247,9 @@ parameter_types! { pub type AssetsForceOrigin = EitherOfDiverse, EnsureXcm>>; +// Called "Trust Backed" assets because these are generally registered by some account, and users of +// the asset assume it has some claimed backing. The pallet is called `Assets` in +// `construct_runtime` to avoid breaking changes on storage reads. pub type TrustBackedAssetsInstance = pallet_assets::Instance1; type TrustBackedAssetsCall = pallet_assets::Call; impl pallet_assets::Config for Runtime { @@ -351,7 +354,7 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!( c, RuntimeCall::Balances { .. } | - RuntimeCall::TrustBackedAssets { .. } | + RuntimeCall::Assets { .. } | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( @@ -363,7 +366,7 @@ impl InstanceFilter for ProxyType { ProxyType::Assets => { matches!( c, - RuntimeCall::TrustBackedAssets { .. } | + RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::Uniques { .. } @@ -371,17 +374,15 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::TrustBackedAssets( - TrustBackedAssetsCall::destroy_accounts { .. } - ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::TrustBackedAssets( - TrustBackedAssetsCall::transfer_ownership { .. } - ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | @@ -398,12 +399,12 @@ impl InstanceFilter for ProxyType { ), ProxyType::AssetManager => matches!( c, - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | @@ -546,7 +547,7 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = TrustBackedAssets; + type Fungibles = Assets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< pallet_assets::BalanceToAssetBalance< Balances, @@ -630,7 +631,7 @@ construct_runtime!( Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 42, // The main stage. - TrustBackedAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, + Assets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 51, } ); @@ -659,6 +660,8 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; +/// Migrations to apply on runtime upgrade. +pub type Migrations = (); /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< @@ -667,20 +670,9 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - // Note: Removed v1 storage migration. Assume this has been applied in some upgrade. - // Do not release until verified! - MigrateAssetsPallet, + Migrations, >; -pub struct MigrateAssetsPallet; -impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet { - fn on_runtime_upgrade() -> Weight { - use frame_support::storage::migration; - migration::move_pallet(b"Assets", b"TrustBackedAssets"); - ::DbWeight::get().writes(1) - } -} - #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; @@ -689,7 +681,7 @@ extern crate frame_benchmarking; mod benches { define_benchmarks!( [frame_system, SystemBench::] - [pallet_assets, TrustBackedAssets] + [pallet_assets, Assets] [pallet_balances, Balances] [pallet_multisig, Multisig] [pallet_proxy, Proxy] diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index da26aea8aaa..c8613777b02 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -14,9 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, + AccountId, AssetIdForTrustBackedAssets, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -50,7 +50,7 @@ parameter_types! { pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const Local: MultiLocation = Here.into(); pub TrustBackedAssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); + PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } @@ -83,7 +83,7 @@ pub type CurrencyTransactor = CurrencyAdapter< /// Means for transacting assets besides the native currency on this chain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: - TrustBackedAssets, + Assets, // Use this currency when it is a fungible asset matching the given location or name: ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, @@ -101,7 +101,7 @@ pub type FungiblesTransactor = FungiblesAdapter< AccountId, // We only want to allow teleports of known assets. We use non-zero issuance as an indication // that this asset is known. - parachains_common::impls::NonZeroIssuance, + parachains_common::impls::NonZeroIssuance, // The account to use for tracking teleports. CheckingAccount, >; @@ -202,7 +202,7 @@ impl xcm_executor::Config for XcmConfig { >, JustTry, >, - TrustBackedAssets, + Assets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< FungiblesTransactor, AccountId, diff --git a/parachains/runtimes/assets/statemint/tests/tests.rs b/parachains/runtimes/assets/statemint/tests/tests.rs index 8427f3af4dd..50c0f904eb1 100644 --- a/parachains/runtimes/assets/statemint/tests/tests.rs +++ b/parachains/runtimes/assets/statemint/tests/tests.rs @@ -8,8 +8,8 @@ use frame_support::{ use parachains_common::{AccountId, StatemintAuraId as AuraId}; use statemint_runtime::xcm_config::AssetFeeAsExistentialDepositMultiplierFeeCharger; pub use statemint_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit, Runtime, - SessionKeys, System, TrustBackedAssets, + constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit, + Runtime, SessionKeys, System, }; use xcm::latest::prelude::*; use xcm_executor::traits::WeightTrader; @@ -30,7 +30,7 @@ fn test_asset_xcm_trader() { // We need root origin to create a sufficient asset let minimum_asset_balance = 333333333_u128; let local_asset_id = 1; - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -39,7 +39,7 @@ fn test_asset_xcm_trader() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -51,8 +51,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(local_asset_id.into()), ), @@ -97,15 +97,12 @@ fn test_asset_xcm_trader() { // Make sure author(Alice) has received the amount assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), + Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased - assert_eq!( - TrustBackedAssets::total_supply(1), - minimum_asset_balance + asset_amount_needed - ); + assert_eq!(Assets::total_supply(1), minimum_asset_balance + asset_amount_needed); }); } @@ -122,7 +119,7 @@ fn test_asset_xcm_trader_with_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -131,7 +128,7 @@ fn test_asset_xcm_trader_with_refund() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -153,8 +150,8 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -190,12 +187,12 @@ fn test_asset_xcm_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight_used)); assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), + Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); }); } @@ -212,7 +209,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -235,8 +232,8 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -255,10 +252,10 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(TrustBackedAssets::total_supply(1), 0); + assert_eq!(Assets::total_supply(1), 0); }); } @@ -275,7 +272,7 @@ fn test_that_buying_ed_refund_does_not_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -295,8 +292,8 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -328,13 +325,10 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), - ExistentialDeposit::get() - ); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); }); } @@ -351,7 +345,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { .execute_with(|| { // Create a non-sufficient asset let minimum_asset_balance = 1_000_000_u128; - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -360,7 +354,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -385,8 +379,8 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -401,12 +395,9 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), - minimum_asset_balance - ); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); + assert_eq!(Assets::total_supply(1), minimum_asset_balance); }); } diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index faf1daf7eaf..d72f552fd55 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -214,6 +214,9 @@ parameter_types! { pub type AssetsForceOrigin = EnsureRoot; +// Called "Trust Backed" assets because these are generally registered by some account, and users of +// the asset assume it has some claimed backing. The pallet is called `Assets` in +// `construct_runtime` to avoid breaking changes on storage reads. pub type TrustBackedAssetsInstance = pallet_assets::Instance1; type TrustBackedAssetsCall = pallet_assets::Call; impl pallet_assets::Config for Runtime { @@ -318,7 +321,7 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!( c, RuntimeCall::Balances { .. } | - RuntimeCall::TrustBackedAssets { .. } | + RuntimeCall::Assets { .. } | RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ), @@ -331,7 +334,7 @@ impl InstanceFilter for ProxyType { ProxyType::Assets => { matches!( c, - RuntimeCall::TrustBackedAssets { .. } | + RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } @@ -339,17 +342,15 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::TrustBackedAssets( - TrustBackedAssetsCall::destroy_accounts { .. } - ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::TrustBackedAssets( - TrustBackedAssetsCall::transfer_ownership { .. } - ) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | @@ -377,12 +378,12 @@ impl InstanceFilter for ProxyType { ), ProxyType::AssetManager => matches!( c, - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | RuntimeCall::Nfts(pallet_nfts::Call::burn { .. }) | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | @@ -525,7 +526,7 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = TrustBackedAssets; + type Fungibles = Assets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< pallet_assets::BalanceToAssetBalance< Balances, @@ -640,7 +641,7 @@ construct_runtime!( Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 42, // The main stage. - TrustBackedAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, + Assets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 51, Nfts: pallet_nfts::{Pallet, Call, Storage, Event} = 52, } @@ -670,6 +671,8 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; +/// Migrations to apply on runtime upgrade. +pub type Migrations = (); /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< @@ -678,20 +681,9 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - // Note: Removed v1 storage migration. Assume this has been applied in some upgrade. - // Do not release until verified! - MigrateAssetsPallet, + Migrations, >; -pub struct MigrateAssetsPallet; -impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet { - fn on_runtime_upgrade() -> Weight { - use frame_support::storage::migration; - migration::move_pallet(b"Assets", b"TrustBackedAssets"); - ::DbWeight::get().writes(1) - } -} - #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; @@ -700,7 +692,7 @@ extern crate frame_benchmarking; mod benches { define_benchmarks!( [frame_system, SystemBench::] - [pallet_assets, TrustBackedAssets] + [pallet_assets, Assets] [pallet_balances, Balances] [pallet_multisig, Multisig] [pallet_nfts, Nfts] diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index 6066960980c..3eaa3a82dc6 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -14,9 +14,9 @@ // limitations under the License. use super::{ - AccountId, AssetIdForTrustBackedAssets, Authorship, Balance, Balances, ParachainInfo, + AccountId, AssetIdForTrustBackedAssets, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -51,7 +51,7 @@ parameter_types! { pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const Local: MultiLocation = Here.into(); pub TrustBackedAssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); + PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } @@ -84,7 +84,7 @@ pub type CurrencyTransactor = CurrencyAdapter< /// Means for transacting assets besides the native currency on this chain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: - TrustBackedAssets, + Assets, // Use this currency when it is a fungible asset matching the given location or name: ConvertedConcreteAssetId< AssetIdForTrustBackedAssets, @@ -102,7 +102,7 @@ pub type FungiblesTransactor = FungiblesAdapter< AccountId, // We only want to allow teleports of known assets. We use non-zero issuance as an indication // that this asset is known. - parachains_common::impls::NonZeroIssuance, + parachains_common::impls::NonZeroIssuance, // The account to use for tracking teleports. CheckingAccount, >; @@ -199,7 +199,7 @@ impl xcm_executor::Config for XcmConfig { >, JustTry, >, - TrustBackedAssets, + Assets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< FungiblesTransactor, AccountId, diff --git a/parachains/runtimes/assets/westmint/tests/tests.rs b/parachains/runtimes/assets/westmint/tests/tests.rs index 9e489e1c363..a7b846d49ec 100644 --- a/parachains/runtimes/assets/westmint/tests/tests.rs +++ b/parachains/runtimes/assets/westmint/tests/tests.rs @@ -8,8 +8,8 @@ use frame_support::{ use parachains_common::{AccountId, AuraId}; use westmint_runtime::xcm_config::AssetFeeAsExistentialDepositMultiplierFeeCharger; pub use westmint_runtime::{ - constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit, Runtime, - SessionKeys, System, TrustBackedAssets, + constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit, + Runtime, SessionKeys, System, }; use xcm::latest::prelude::*; use xcm_executor::traits::WeightTrader; @@ -30,7 +30,7 @@ fn test_asset_xcm_trader() { // We need root origin to create a sufficient asset let minimum_asset_balance = 3333333_u128; let local_asset_id = 1; - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -39,7 +39,7 @@ fn test_asset_xcm_trader() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), local_asset_id.into(), AccountId::from(ALICE).into(), @@ -51,8 +51,8 @@ fn test_asset_xcm_trader() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(local_asset_id.into()), ), @@ -94,15 +94,12 @@ fn test_asset_xcm_trader() { // Make sure author(Alice) has received the amount assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), + Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); // We also need to ensure the total supply increased - assert_eq!( - TrustBackedAssets::total_supply(1), - minimum_asset_balance + asset_amount_needed - ); + assert_eq!(Assets::total_supply(1), minimum_asset_balance + asset_amount_needed); }); } @@ -119,7 +116,7 @@ fn test_asset_xcm_trader_with_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -128,7 +125,7 @@ fn test_asset_xcm_trader_with_refund() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -146,8 +143,8 @@ fn test_asset_xcm_trader_with_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -183,12 +180,12 @@ fn test_asset_xcm_trader_with_refund() { let fees_paid = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight_used)); assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), + Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get() + fees_paid ); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get() + fees_paid); + assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); }); } @@ -205,7 +202,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -225,8 +222,8 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -245,10 +242,10 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive); // not credited since the ED is higher than this value - assert_eq!(TrustBackedAssets::balance(1, AccountId::from(ALICE)), 0); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); // We also need to ensure the total supply did not increase - assert_eq!(TrustBackedAssets::total_supply(1), 0); + assert_eq!(Assets::total_supply(1), 0); }); } @@ -265,7 +262,7 @@ fn test_that_buying_ed_refund_does_not_refund() { .execute_with(|| { // We need root origin to create a sufficient asset // We set existential deposit to be identical to the one for Balances first - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -284,8 +281,8 @@ fn test_that_buying_ed_refund_does_not_refund() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -317,13 +314,10 @@ fn test_that_buying_ed_refund_does_not_refund() { drop(trader); // Make sure author(Alice) has received the amount - assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), - ExistentialDeposit::get() - ); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); // We also need to ensure the total supply increased - assert_eq!(TrustBackedAssets::total_supply(1), ExistentialDeposit::get()); + assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); }); } @@ -340,7 +334,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { .execute_with(|| { // Create a non-sufficient asset with specific existential deposit let minimum_asset_balance = 1_000_000_u128; - assert_ok!(TrustBackedAssets::force_create( + assert_ok!(Assets::force_create( RuntimeHelper::::root_origin(), 1.into(), AccountId::from(ALICE).into(), @@ -349,7 +343,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { )); // We first mint enough asset for the account to exist for assets - assert_ok!(TrustBackedAssets::mint( + assert_ok!(Assets::mint( RuntimeHelper::::origin_of(AccountId::from(ALICE)), 1.into(), AccountId::from(ALICE).into(), @@ -371,8 +365,8 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { 0, X2( PalletInstance( - ::PalletInfo::index::() - .unwrap() as u8, + ::PalletInfo::index::().unwrap() + as u8, ), GeneralIndex(1), ), @@ -387,12 +381,9 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { drop(trader); // Make sure author(Alice) has NOT received the amount - assert_eq!( - TrustBackedAssets::balance(1, AccountId::from(ALICE)), - minimum_asset_balance - ); + assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); // We also need to ensure the total supply NOT increased - assert_eq!(TrustBackedAssets::total_supply(1), minimum_asset_balance); + assert_eq!(Assets::total_supply(1), minimum_asset_balance); }); } From d5f8b29ec533568b151e96bc5572ab18cfaa2f36 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Wed, 11 Jan 2023 19:37:00 +0100 Subject: [PATCH 10/10] fix merge --- parachains/runtimes/assets/statemine/src/lib.rs | 2 -- parachains/runtimes/assets/statemint/src/lib.rs | 2 -- parachains/runtimes/assets/westmint/src/lib.rs | 2 -- 3 files changed, 6 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 88238e4aae9..2256586308d 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -666,8 +666,6 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic