From 47d96e0192705d8d1c333564abb85ad942f6dc46 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Fri, 18 Nov 2022 10:51:45 +0100 Subject: [PATCH] make it almost compile --- parachains/common/src/xcm_config.rs | 19 +++++--- .../runtimes/assets/westmint/src/lib.rs | 46 ++++++++++--------- .../assets/westmint/src/xcm_config.rs | 24 +++++++--- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/parachains/common/src/xcm_config.rs b/parachains/common/src/xcm_config.rs index 9a9774ae94..49bd563387 100644 --- a/parachains/common/src/xcm_config.rs +++ b/parachains/common/src/xcm_config.rs @@ -82,24 +82,29 @@ pub struct AssetFeeAsExistentialDepositMultiplier cumulus_primitives_utility::ChargeWeightInFungibles< AccountIdOf, - pallet_assets::Pallet, + // todo: I don't understand why `frame_support` is the instance here??? but it compiles... + 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>>::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/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index a0c225c391..a8b2bd600c 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -228,8 +228,8 @@ pub type AssetsForceOrigin = EnsureRoot; // We should perhaps come up with a new name. "ReserveBackedAssets" collides with XCM terminology // and falsly implies that they are actually backed by some reserve. In reality, the user is // _trusting_ some `CreateOrigin` (AccountId) that the asset is what they claim. -type TrustBackedAssetClasses = pallet_assets::Instance1; -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; @@ -251,9 +251,11 @@ type ForeignAssetClasses = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = MultiLocationForAssetId; + // TODO: impl Copy for MultiLocation or relax AssetId to Clone? + // https://github.com/paritytech/substrate/pull/12731 + type AssetId = AssetId; // MultiLocationForAssetId; type Currency = Balances; - type CreateOrigin = ForeignCreators; + type CreateOrigin = AsEnsureOriginWithArg>; // ForeignCreators; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; @@ -339,6 +341,7 @@ impl Default for ProxyType { Self::Any } } +type TrustBackedAssetsCall = pallet_assets::Call; impl InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { @@ -366,12 +369,12 @@ impl InstanceFilter for ProxyType { }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetClasses::Call::create { .. }) | - RuntimeCall::Assets(TrustBackedAssetClasses::Call::destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetClasses::Call::transfer_ownership { .. }) | - RuntimeCall::Assets(TrustBackedAssetClasses::Call::set_team { .. }) | - RuntimeCall::Assets(TrustBackedAssetClasses::Call::set_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetClasses::Call::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::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 { .. }) | @@ -388,15 +391,13 @@ impl InstanceFilter for ProxyType { ), ProxyType::AssetManager => matches!( c, - RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::mint { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::burn { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::freeze { .. }) | - RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::thaw { .. }) | - RuntimeCall::TrustBackedAssets( - TrustBackedAssetClasses::Call::freeze_asset { .. } - ) | RuntimeCall::TrustBackedAssets( - TrustBackedAssetClasses::Call::thaw_asset { .. } - ) | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | + 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 { .. }) | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | @@ -536,14 +537,15 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; // TODO https://github.com/paritytech/substrate/issues/12724 - // This should be able to take assets from any pallet instance. + // 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< Balances, Runtime, ConvertInto, - pallet_assets::Instance1, + TrustBackedAssetsInstance, >, AssetsToBlockAuthor, >; @@ -661,7 +663,7 @@ 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, + (), //pallet_assets::migration::v1::MigrateToV1, >; #[cfg(feature = "runtime-benchmarks")] diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index 29ba8304b6..5adf40767a 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -18,14 +18,15 @@ use super::{ ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, AccountId, AssetId, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, WeightToFee, XcmpQueue, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssetsInstance, TrustBackedAssets, + WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, traits::{ConstU32, Everything, Nothing, PalletInfoAccess}, traits::{EnsureOriginWithArg, Everything, PalletInfoAccess}, }; -use pallet_xcm::XcmPassthrough; +use pallet_xcm::{EnsureXcm, XcmPassthrough}; use parachains_common::{ impls::ToStakingPot, xcm_config::{ @@ -43,7 +44,7 @@ use xcm_builder::{ SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds, }; -use xcm_executor::{traits::JustTry, XcmExecutor}; +use xcm_executor::{traits::{Convert, JustTry}, XcmExecutor}; parameter_types! { pub const WestendLocation: MultiLocation = MultiLocation::parent(); @@ -183,7 +184,12 @@ impl xcm_executor::Config for XcmConfig { AssetFeeAsExistentialDepositMultiplier< Runtime, WeightToFee, - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance< + Balances, + Runtime, + ConvertInto, + TrustBackedAssetsInstance, + >, >, ConvertedConcreteId< AssetId, @@ -274,8 +280,14 @@ impl EnsureOriginWithArg for ForeignCreators { o: RuntimeOrigin, a: &MultiLocation, ) -> sp_std::result::Result { - let origin_location = pallet_xcm::EnsureXcm::::try_origin(o.clone())?; - if !a.starts_with(&origin_location) { + let origin_location = EnsureXcm::try_origin(o.clone())?; + + // dirty hack, should port vvv into master and use `starts_with` + // https://github.com/paritytech/polkadot/commit/e640d826513c45a0452138c8908a699e19ac0143 + if a.parents != origin_location.parents || + a.interior.len() != origin_location.interior.len() || + !a.interior.iter().zip(origin_location.interior.iter()).all(|(l, r)| l == r) + { return Err(o) } SovereignAccountOf::convert(origin_location).map_err(|_| o)