diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index a30fb2e327..4e1b20bb82 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -228,11 +228,13 @@ parameter_types! { pub type AssetsForceOrigin = EitherOfDiverse, EnsureXcm>>; -impl pallet_assets::Config for Runtime { +pub type TrustBackedAssetsInstance = pallet_assets::Instance1; +impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; type AssetId = AssetId; type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; @@ -243,6 +245,8 @@ impl pallet_assets::Config for Runtime { type Extra = (); type WeightInfo = weights::pallet_assets::WeightInfo; type AssetAccountDeposit = AssetAccountDeposit; + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); } parameter_types! { @@ -317,6 +321,7 @@ impl Default for ProxyType { Self::Any } } +type TrustBackedAssetsCall = pallet_assets::Call; impl InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { @@ -324,7 +329,7 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => !matches!( c, RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Uniques { .. } ), ProxyType::CancelProxy => matches!( @@ -336,7 +341,7 @@ impl InstanceFilter for ProxyType { ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } | + RuntimeCall::TrustBackedAssets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::Uniques { .. } @@ -344,12 +349,13 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(pallet_assets::Call::create { .. }) | - RuntimeCall::Assets(pallet_assets::Call::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::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 +372,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 { .. }) | @@ -516,9 +522,17 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = Assets; + // TODO https://github.com/paritytech/substrate/issues/12724 + // This should be able to take assets from any pallet instance. For now we only allow + // sufficient, trust backed assets to pay for transaction fees. + type Fungibles = TrustBackedAssets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, AssetsToBlockAuthor, >; } @@ -595,7 +609,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, } ); @@ -631,9 +645,18 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (), + 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; @@ -642,7 +665,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 4841ee7c51..6ee9044d8f 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, AllPalletsWithSystem, AssetId, Assets, Authorship, Balance, Balances, ParachainInfo, - ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, - XcmpQueue, + AccountId, AllPalletsWithSystem, AssetId, Authorship, Balance, Balances, ParachainInfo, + ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -48,8 +48,8 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = X1(Parachain(ParachainInfo::parachain_id().into())); pub const Local: MultiLocation = Here.into_location(); - pub AssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); + pub TrustBackedAssetsPalletLocation: MultiLocation = + PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } @@ -82,12 +82,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: ConvertedConcreteId< AssetId, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, // Convert an XCM MultiLocation into a local account id: @@ -96,7 +96,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, >; @@ -183,15 +183,20 @@ impl xcm_executor::Config for XcmConfig { AssetFeeAsExistentialDepositMultiplier< Runtime, WeightToFee, - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, >, ConvertedConcreteId< AssetId, Balance, - AsPrefixedGeneralIndex, + AsPrefixedGeneralIndex, JustTry, >, - Assets, + TrustBackedAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< FungiblesTransactor, AccountId, diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 8c96c4268f..c2683aaab8 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -263,6 +263,7 @@ impl pallet_assets::Config for Runtime { type Balance = Balance; type AssetId = AssetId; type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; @@ -273,6 +274,8 @@ impl pallet_assets::Config for Runtime { type Extra = (); type WeightInfo = weights::pallet_assets::WeightInfo; type AssetAccountDeposit = AssetAccountDeposit; + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); } parameter_types! { diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index b58baf3077..0f1f7c17a5 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -245,6 +245,8 @@ impl pallet_assets::Config for Runtime { type Extra = (); type WeightInfo = weights::pallet_assets::WeightInfo; type AssetAccountDeposit = AssetAccountDeposit; + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); } /// Assets managed by some foreign location. @@ -252,7 +254,6 @@ type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - // TODO: need HasCompact for MultiLocation type AssetId = AssetId; // MultiLocationForAssetId; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; // ForeignCreators; @@ -266,6 +267,8 @@ impl pallet_assets::Config for Runtime { type Extra = (); type WeightInfo = weights::pallet_assets::WeightInfo; type AssetAccountDeposit = AssetAccountDeposit; + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); } parameter_types! { @@ -663,9 +666,18 @@ pub type Executive = frame_executive::Executive< // TODO // 1. Move this instance https://substrate.stackexchange.com/questions/4343/how-to-migrate-storage-from-a-default-pallet-instance-to-an-actual-one // 2. Make sure this migration applies to the old instance - (), //pallet_assets::migration::v1::MigrateToV1, + MigrateAssetsPallet, //pallet_assets::migration::v1::MigrateToV1, >; +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;