git.delta.rocks / unique-network / refs/commits / 9b72a3a55cc6

difftreelog

Weight trader removed

Dev2022-08-29parent: #6fb8930.patch.diff
in: master

8 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -65,7 +65,6 @@
 	Unknown(String),
 }
 
-
 #[cfg(not(feature = "unique-runtime"))]
 /// PARA_ID for Opal/Quartz
 const PARA_ID: u32 = 2095;
modifiedpallets/foreing-assets/src/lib.rsdiffbeforeafterboth
--- a/pallets/foreing-assets/src/lib.rs
+++ b/pallets/foreing-assets/src/lib.rs
@@ -458,7 +458,7 @@
 
 use xcm::latest::{Fungibility::Fungible as XcmFungible};
 
-pub struct UsingAnyCurrencyComponents<
+pub struct FreeForAll<
 	WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,
 	AssetId: Get<MultiLocation>,
 	AccountId,
@@ -476,8 +476,7 @@
 		AccountId,
 		Currency: CurrencyT<AccountId>,
 		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,
-	> WeightTrader
-	for UsingAnyCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>
+	> WeightTrader for FreeForAll<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>
 {
 	fn new() -> Self {
 		Self(0, Zero::zero(), PhantomData)
@@ -485,46 +484,7 @@
 
 	fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {
 		log::trace!(target: "fassets::weight", "buy_weight weight: {:?}, payment: {:?}", weight, payment);
-
-		let amount: Currency::Balance = (0 as u32).into();
-		let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;
-
-		let asset_id = payment
-			.fungible
-			.iter()
-			.next()
-			.map_or(Err(XcmError::TooExpensive), |v| Ok(v.0))?;
-
-		// First fungible pays fee
-		let required = MultiAsset {
-			id: asset_id.clone(),
-			fun: XcmFungible(u128_amount),
-		};
-
-		log::trace!(
-			target: "fassets::weight", "buy_weight payment: {:?}, required: {:?}",
-			payment, required,
-		);
-
-		let unused = payment
-			.checked_sub(required)
-			.map_err(|_| XcmError::TooExpensive)?;
-		self.0 = self.0.saturating_add(weight);
-		self.1 = self.1.saturating_add(amount);
-		Ok(unused)
-	}
-
-	fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {
-		let weight = weight.min(self.0);
-		let amount = WeightToFee::weight_to_fee(&weight);
-		self.0 -= weight;
-		self.1 = self.1.saturating_sub(amount);
-		let amount: u128 = amount.saturated_into();
-		if amount > 0 {
-			Some((AssetId::get(), amount).into())
-		} else {
-			None
-		}
+		Ok(payment)
 	}
 }
 impl<
@@ -533,7 +493,7 @@
 		AccountId,
 		Currency: CurrencyT<AccountId>,
 		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,
-	> Drop for UsingAnyCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>
+	> Drop for FreeForAll<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>
 {
 	fn drop(&mut self) {
 		OnUnbalanced::on_unbalanced(Currency::issue(self.1));
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -171,10 +171,9 @@
 	/// Foreign collection flag
 	#[pallet::storage]
 	pub type ForeignCollection<T: Config> =
-	StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = bool, QueryKind = ValueQuery>;
+		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = bool, QueryKind = ValueQuery>;
 }
 
-
 /// Wrapper around untyped collection handle, asserting inner collection is of fungible type.
 /// Required for interaction with Fungible collections, type safety and implementation [`solidity_interface`][`evm_coder::solidity_interface`].
 pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);
@@ -340,7 +339,7 @@
 				to: H160::default(),
 				value: amount.into(),
 			}
-				.to_log(collection_id_to_address(collection.id)),
+			.to_log(collection_id_to_address(collection.id)),
 		);
 		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
 			collection.id,
@@ -560,7 +559,7 @@
 					to: *user.as_eth(),
 					value: amount.into(),
 				}
-					.to_log(collection_id_to_address(collection.id)),
+				.to_log(collection_id_to_address(collection.id)),
 			);
 			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(
 				collection.id,
modifiedruntime/common/config/pallets/foreign_asset.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/foreign_asset.rs
+++ b/runtime/common/config/pallets/foreign_asset.rs
@@ -2,8 +2,8 @@
 use up_common::types::AccountId;
 
 impl pallet_foreing_assets::Config for Runtime {
-    type Event = Event;
-    type Currency = Balances;
-    type RegisterOrigin = frame_system::EnsureRoot<AccountId>;
-    type WeightInfo = ();
+	type Event = Event;
+	type Currency = Balances;
+	type RegisterOrigin = frame_system::EnsureRoot<AccountId>;
+	type WeightInfo = ();
 }
modifiedruntime/common/config/xcm.rsdiffbeforeafterboth
before · runtime/common/config/xcm.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	traits::{19		Contains, tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get, Everything,20		fungibles,21	},22	weights::{Weight, WeightToFeePolynomial, WeightToFee},23	parameter_types, match_types,24};25use frame_system::EnsureRoot;26use sp_runtime::{27	traits::{Saturating, CheckedConversion, Zero},28	SaturatedConversion,29};30use pallet_xcm::XcmPassthrough;31use polkadot_parachain::primitives::Sibling;32use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};33use xcm::latest::{34	AssetId::{Concrete},35	Fungibility::Fungible as XcmFungible,36	MultiAsset, Error as XcmError,37};38use xcm_builder::{39	AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,40	FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative,41	SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,42	SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, ParentIsPreset,43	ConvertedConcreteAssetId44};45use xcm_executor::{Config, XcmExecutor, Assets};46use xcm_executor::traits::{Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation};47use pallet_foreing_assets::{48	AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,49	UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,50};51use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};52use crate::{53	Runtime, Call, Event, Origin, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,54	xcm_config::Barrier55};56#[cfg(feature = "foreign-assets")]57use crate::ForeingAssets;5859use up_common::{60	types::{AccountId, Balance},61	constants::*,62};6364parameter_types! {65	pub const RelayLocation: MultiLocation = MultiLocation::parent();66	pub const RelayNetwork: NetworkId = NetworkId::Polkadot;67	pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();68	pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();69}7071/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used72/// when determining ownership of accounts for asset transacting and when attempting to use XCM73/// `Transact` in order to determine the dispatch Origin.74pub type LocationToAccountId = (75	// The parent (Relay-chain) origin converts to the default `AccountId`.76	ParentIsPreset<AccountId>,77	// Sibling parachain origins convert to AccountId via the `ParaId::into`.78	SiblingParachainConvertsVia<Sibling, AccountId>,79	// Straight up local `AccountId32` origins just alias directly to `AccountId`.80	AccountId32Aliases<RelayNetwork, AccountId>,81);8283pub struct OnlySelfCurrency;84impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {85	fn matches_fungible(a: &MultiAsset) -> Option<B> {86		match (&a.id, &a.fun) {87			(Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),88			_ => None,89		}90	}91}9293/// Means for transacting assets on this chain.94pub type LocalAssetTransactor = CurrencyAdapter<95	// Use this currency:96	Balances,97	// Use this currency when it is a fungible asset matching the given location or name:98	OnlySelfCurrency,99	// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:100	LocationToAccountId,101	// Our chain's account ID type (we can't get away without mentioning it explicitly):102	AccountId,103	// We don't track any teleports.104	(),105>;106107/// No local origins on this chain are allowed to dispatch XCM sends/executions.108pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);109110/// The means for routing XCM messages which are not for local execution into the right message111/// queues.112pub type XcmRouter = (113	// Two routers - use UMP to communicate with the relay chain:114	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,115	// ..and XCMP to communicate with the sibling chains.116	XcmpQueue,117);118119/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,120/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can121/// biases the kind of local `Origin` it will become.122pub type XcmOriginToTransactDispatchOrigin = (123	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location124	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for125	// foreign chains who want to have a local sovereign account on this chain which they control.126	SovereignSignedViaLocation<LocationToAccountId, Origin>,127	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when128	// recognised.129	RelayChainAsNative<RelayOrigin, Origin>,130	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when131	// recognised.132	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,133	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a134	// transaction from the Root origin.135	ParentAsSuperuser<Origin>,136	// Native signed account converter; this just converts an `AccountId32` origin into a normal137	// `Origin::Signed` origin of the same 32-byte value.138	SignedAccountId32AsNative<RelayNetwork, Origin>,139	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.140	XcmPassthrough<Origin>,141);142143parameter_types! {144	// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.145	pub UnitWeightCost: Weight = 1_000_000;146	// 1200 UNIQUEs buy 1 second of weight.147	pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);148	pub const MaxInstructions: u32 = 100;149}150151match_types! {152	pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {153		MultiLocation { parents: 1, interior: Here } |154		MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }155	};156}157158/*159pub type Barrier = (160	TakeWeightCredit,161	AllowTopLevelPaidExecutionFrom<Everything>,162	// ^^^ Parent & its unit plurality gets free execution163);164 */165166pub struct UsingOnlySelfCurrencyComponents<167	WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,168	AssetId: Get<MultiLocation>,169	AccountId,170	Currency: CurrencyT<AccountId>,171	OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,172>(173	Weight,174	Currency::Balance,175	PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,176);177impl<178		WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,179		AssetId: Get<MultiLocation>,180		AccountId,181		Currency: CurrencyT<AccountId>,182		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,183	> WeightTrader184	for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>185{186	fn new() -> Self {187		Self(0, Zero::zero(), PhantomData)188	}189190	fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {191		let amount: Currency::Balance = (0 as u32).into();192		//let amount = WeightToFee::weight_to_fee(&weight);193		let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;194195		// location to this parachain through relay chain196		let option1: xcm::v1::AssetId = Concrete(MultiLocation {197			parents: 1,198			interior: X1(Parachain(ParachainInfo::parachain_id().into())),199		});200		// direct location201		let option2: xcm::v1::AssetId = Concrete(MultiLocation {202			parents: 0,203			interior: Here,204		});205206		let required = if payment.fungible.contains_key(&option1) {207			(option1, u128_amount).into()208		} else if payment.fungible.contains_key(&option2) {209			(option2, u128_amount).into()210		} else {211			(Concrete(MultiLocation::default()), u128_amount).into()212		};213214		let unused = payment215			.checked_sub(required)216			.map_err(|_| XcmError::TooExpensive)?;217		self.0 = self.0.saturating_add(weight);218		self.1 = self.1.saturating_add(amount);219		Ok(unused)220	}221222	fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {223		let weight = weight.min(self.0);224		let amount = WeightToFee::weight_to_fee(&weight);225		self.0 -= weight;226		self.1 = self.1.saturating_sub(amount);227		let amount: u128 = amount.saturated_into();228		if amount > 0 {229			Some((AssetId::get(), amount).into())230		} else {231			None232		}233	}234}235impl<236		WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,237		AssetId: Get<MultiLocation>,238		AccountId,239		Currency: CurrencyT<AccountId>,240		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,241	> Drop242	for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>243{244	fn drop(&mut self) {245		OnUnbalanced::on_unbalanced(Currency::issue(self.1));246	}247}248249parameter_types! {250	pub CheckingAccount: AccountId = PolkadotXcm::check_account();251}252/// Allow checking in assets that have issuance > 0.253#[cfg(feature = "foreign-assets")]254pub struct NonZeroIssuance<AccountId, ForeingAssets>(PhantomData<(AccountId, ForeingAssets)>);255256#[cfg(feature = "foreign-assets")]257impl<AccountId, ForeingAssets> Contains<<ForeingAssets as fungibles::Inspect<AccountId>>::AssetId>258for NonZeroIssuance<AccountId, ForeingAssets>259	where260		ForeingAssets: fungibles::Inspect<AccountId>,261{262	fn contains(id: &<ForeingAssets as fungibles::Inspect<AccountId>>::AssetId) -> bool {263		!ForeingAssets::total_issuance(*id).is_zero()264	}265}266267#[cfg(feature = "foreign-assets")]268pub struct AsInnerId<AssetId, ConvertAssetId>(PhantomData<(AssetId, ConvertAssetId)>);269#[cfg(feature = "foreign-assets")]270impl<AssetId: Clone + PartialEq, ConvertAssetId: ConvertXcm<AssetId, AssetId>>271ConvertXcm<MultiLocation, AssetId> for AsInnerId<AssetId, ConvertAssetId>272	where273		AssetId: Borrow<AssetId>,274		AssetId: TryAsForeing<AssetId, ForeignAssetId>,275		AssetIds: Borrow<AssetId>,276{277	fn convert_ref(id: impl Borrow<MultiLocation>) -> Result<AssetId, ()> {278		let id = id.borrow();279280		log::trace!(281			target: "xcm::AsInnerId::Convert",282			"AsInnerId {:?}",283			id284		);285286		let parent = MultiLocation::parent();287		let here = MultiLocation::here();288		let self_location = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));289290		if *id == parent {291			return ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Parent));292		}293294		if *id == here || *id == self_location {295			return ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Here));296		}297298		match XcmForeignAssetIdMapping::<Runtime>::get_currency_id(id.clone()) {299			Some(AssetIds::ForeignAssetId(foreign_asset_id)) => {300				ConvertAssetId::convert_ref(AssetIds::ForeignAssetId(foreign_asset_id))301			}302			_ => ConvertAssetId::convert_ref(AssetIds::ForeignAssetId(0)),303		}304	}305306	fn reverse_ref(what: impl Borrow<AssetId>) -> Result<MultiLocation, ()> {307		log::trace!(308			target: "xcm::AsInnerId::Reverse",309			"AsInnerId",310		);311312		let asset_id = what.borrow();313314		let parent_id =315			ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Parent)).unwrap();316		let here_id =317			ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Here)).unwrap();318319		if asset_id.clone() == parent_id {320			return Ok(MultiLocation::parent());321		}322323		if asset_id.clone() == here_id {324			return Ok(MultiLocation::new(325				1,326				X1(Parachain(ParachainInfo::get().into())),327			));328		}329330		match <AssetId as TryAsForeing<AssetId, ForeignAssetId>>::try_as_foreing(asset_id.clone()) {331			Some(fid) => match XcmForeignAssetIdMapping::<Runtime>::get_multi_location(fid) {332				Some(location) => Ok(location),333				None => Err(()),334			},335			None => Err(()),336		}337	}338}339340/// Means for transacting assets besides the native currency on this chain.341#[cfg(feature = "foreign-assets")]342pub type FungiblesTransactor = FungiblesAdapter<343	// Use this fungibles implementation:344	ForeingAssets,345	// Use this currency when it is a fungible asset matching the given location or name:346	ConvertedConcreteAssetId<AssetIds, Balance, AsInnerId<AssetIds, JustTry>, JustTry>,347	// Convert an XCM MultiLocation into a local account id:348	LocationToAccountId,349	// Our chain's account ID type (we can't get away without mentioning it explicitly):350	AccountId,351	// We only want to allow teleports of known assets. We use non-zero issuance as an indication352	// that this asset is known.353	NonZeroIssuance<AccountId, ForeingAssets>,354	// The account to use for tracking teleports.355	CheckingAccount,356>;357358/// Means for transacting assets on this chain.359#[cfg(feature = "foreign-assets")]360pub type AssetTransactors = FungiblesTransactor;361362#[cfg(not(feature = "foreign-assets"))]363pub type AssetTransactors = LocalAssetTransactor;364365#[cfg(feature = "foreign-assets")]366pub struct AllAsset;367#[cfg(feature = "foreign-assets")]368impl FilterAssetLocation for AllAsset {369	fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {370		true371	}372}373374#[cfg(feature = "foreign-assets")]375pub type IsReserve = AllAsset;376#[cfg(not(feature = "foreign-assets"))]377pub type IsReserve = NativeAsset;378379#[cfg(feature = "foreign-assets")]380type Trader<T> =381	UsingAnyCurrencyComponents<382		pallet_configuration::WeightToFee<T, Balance>,383		RelayLocation, AccountId, Balances, ()>;384#[cfg(not(feature = "foreign-assets"))]385type Trader<T> = UsingOnlySelfCurrencyComponents<386	pallet_configuration::WeightToFee<T, Balance>,387	RelayLocation,388	AccountId,389	Balances,390	(),391>;392393pub struct XcmConfig<T>(PhantomData<T>);394impl<T> Config for XcmConfig<T>395where396	T: pallet_configuration::Config,397{398	type Call = Call;399	type XcmSender = XcmRouter;400	// How to withdraw and deposit an asset.401	type AssetTransactor = AssetTransactors;402	type OriginConverter = XcmOriginToTransactDispatchOrigin;403	type IsReserve = IsReserve;404	type IsTeleporter = (); // Teleportation is disabled405	type LocationInverter = LocationInverter<Ancestry>;406	type Barrier = Barrier;407	type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;408	type Trader = Trader<T>;409	type ResponseHandler = (); // Don't handle responses for now.410	type SubscriptionService = PolkadotXcm;411412	type AssetTrap = PolkadotXcm;413	type AssetClaims = PolkadotXcm;414}415416impl pallet_xcm::Config for Runtime {417	type Event = Event;418	type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;419	type XcmRouter = XcmRouter;420	type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;421	type XcmExecuteFilter = Everything;422	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;423	type XcmTeleportFilter = Everything;424	type XcmReserveTransferFilter = Everything;425	type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;426	type LocationInverter = LocationInverter<Ancestry>;427	type Origin = Origin;428	type Call = Call;429	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;430	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;431}432433impl cumulus_pallet_xcm::Config for Runtime {434	type Event = Event;435	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;436}437438impl cumulus_pallet_xcmp_queue::Config for Runtime {439	type WeightInfo = ();440	type Event = Event;441	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;442	type ChannelInfo = ParachainSystem;443	type VersionWrapper = ();444	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;445	type ControllerOrigin = EnsureRoot<AccountId>;446	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;447}448449impl cumulus_pallet_dmp_queue::Config for Runtime {450	type Event = Event;451	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;452	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;453}454
after · runtime/common/config/xcm.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	traits::{19		Contains, tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get,20		Everything, fungibles,21	},22	weights::{Weight, WeightToFeePolynomial, WeightToFee},23	parameter_types, match_types,24};25use frame_system::EnsureRoot;26use sp_runtime::{27	traits::{Saturating, CheckedConversion, Zero},28	SaturatedConversion,29};30use pallet_xcm::XcmPassthrough;31use polkadot_parachain::primitives::Sibling;32use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};33use xcm::latest::{34	AssetId::{Concrete},35	Fungibility::Fungible as XcmFungible,36	MultiAsset, Error as XcmError,37};38use xcm_builder::{39	AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,40	FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentAsSuperuser,41	RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,42	SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,43	ParentIsPreset, ConvertedConcreteAssetId,44};45use xcm_executor::{Config, XcmExecutor, Assets};46use xcm_executor::traits::{47	Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation,48};49use pallet_foreing_assets::{50	AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,51	TryAsForeing, ForeignAssetId,52};53use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};54use crate::{55	Runtime, Call, Event, Origin, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,56	xcm_config::Barrier,57};58#[cfg(feature = "foreign-assets")]59use crate::ForeingAssets;6061use up_common::{62	types::{AccountId, Balance},63	constants::*,64};6566parameter_types! {67	pub const RelayLocation: MultiLocation = MultiLocation::parent();68	pub const RelayNetwork: NetworkId = NetworkId::Polkadot;69	pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();70	pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();71}7273/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used74/// when determining ownership of accounts for asset transacting and when attempting to use XCM75/// `Transact` in order to determine the dispatch Origin.76pub type LocationToAccountId = (77	// The parent (Relay-chain) origin converts to the default `AccountId`.78	ParentIsPreset<AccountId>,79	// Sibling parachain origins convert to AccountId via the `ParaId::into`.80	SiblingParachainConvertsVia<Sibling, AccountId>,81	// Straight up local `AccountId32` origins just alias directly to `AccountId`.82	AccountId32Aliases<RelayNetwork, AccountId>,83);8485pub struct OnlySelfCurrency;86impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {87	fn matches_fungible(a: &MultiAsset) -> Option<B> {88		let paraid = Parachain(ParachainInfo::parachain_id().into());89		match (&a.id, &a.fun) {90			(91				Concrete(MultiLocation {92					parents: 1,93					interior: X1(loc),94				}),95				XcmFungible(ref amount),96			) if paraid == *loc => CheckedConversion::checked_from(*amount),97			(98				Concrete(MultiLocation {99					parents: 0,100					interior: Here,101				}),102				XcmFungible(ref amount),103			) => CheckedConversion::checked_from(*amount),104			_ => None,105		}106	}107}108109/// Means for transacting assets on this chain.110pub type LocalAssetTransactor = CurrencyAdapter<111	// Use this currency:112	Balances,113	// Use this currency when it is a fungible asset matching the given location or name:114	OnlySelfCurrency,115	// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:116	LocationToAccountId,117	// Our chain's account ID type (we can't get away without mentioning it explicitly):118	AccountId,119	// We don't track any teleports.120	(),121>;122123/// No local origins on this chain are allowed to dispatch XCM sends/executions.124pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);125126/// The means for routing XCM messages which are not for local execution into the right message127/// queues.128pub type XcmRouter = (129	// Two routers - use UMP to communicate with the relay chain:130	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,131	// ..and XCMP to communicate with the sibling chains.132	XcmpQueue,133);134135/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,136/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can137/// biases the kind of local `Origin` it will become.138pub type XcmOriginToTransactDispatchOrigin = (139	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location140	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for141	// foreign chains who want to have a local sovereign account on this chain which they control.142	SovereignSignedViaLocation<LocationToAccountId, Origin>,143	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when144	// recognised.145	RelayChainAsNative<RelayOrigin, Origin>,146	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when147	// recognised.148	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,149	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a150	// transaction from the Root origin.151	ParentAsSuperuser<Origin>,152	// Native signed account converter; this just converts an `AccountId32` origin into a normal153	// `Origin::Signed` origin of the same 32-byte value.154	SignedAccountId32AsNative<RelayNetwork, Origin>,155	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.156	XcmPassthrough<Origin>,157);158159parameter_types! {160	// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.161	pub UnitWeightCost: Weight = 1_000_000;162	// 1200 UNIQUEs buy 1 second of weight.163	pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);164	pub const MaxInstructions: u32 = 100;165}166167match_types! {168	pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {169		MultiLocation { parents: 1, interior: Here } |170		MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }171	};172}173174/*175pub type Barrier = (176	TakeWeightCredit,177	AllowTopLevelPaidExecutionFrom<Everything>,178	// ^^^ Parent & its unit plurality gets free execution179);180 */181182pub struct UsingOnlySelfCurrencyComponents<183	WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,184	AssetId: Get<MultiLocation>,185	AccountId,186	Currency: CurrencyT<AccountId>,187	OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,188>(189	Weight,190	Currency::Balance,191	PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,192);193impl<194		WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,195		AssetId: Get<MultiLocation>,196		AccountId,197		Currency: CurrencyT<AccountId>,198		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,199	> WeightTrader200	for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>201{202	fn new() -> Self {203		Self(0, Zero::zero(), PhantomData)204	}205206	fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {207		Ok(payment)208	}209}210impl<211		WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,212		AssetId: Get<MultiLocation>,213		AccountId,214		Currency: CurrencyT<AccountId>,215		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,216	> Drop217	for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>218{219	fn drop(&mut self) {220		OnUnbalanced::on_unbalanced(Currency::issue(self.1));221	}222}223224parameter_types! {225	pub CheckingAccount: AccountId = PolkadotXcm::check_account();226}227/// Allow checking in assets that have issuance > 0.228#[cfg(feature = "foreign-assets")]229pub struct NonZeroIssuance<AccountId, ForeingAssets>(PhantomData<(AccountId, ForeingAssets)>);230231#[cfg(feature = "foreign-assets")]232impl<AccountId, ForeingAssets> Contains<<ForeingAssets as fungibles::Inspect<AccountId>>::AssetId>233	for NonZeroIssuance<AccountId, ForeingAssets>234where235	ForeingAssets: fungibles::Inspect<AccountId>,236{237	fn contains(id: &<ForeingAssets as fungibles::Inspect<AccountId>>::AssetId) -> bool {238		!ForeingAssets::total_issuance(*id).is_zero()239	}240}241242#[cfg(feature = "foreign-assets")]243pub struct AsInnerId<AssetId, ConvertAssetId>(PhantomData<(AssetId, ConvertAssetId)>);244#[cfg(feature = "foreign-assets")]245impl<AssetId: Clone + PartialEq, ConvertAssetId: ConvertXcm<AssetId, AssetId>>246	ConvertXcm<MultiLocation, AssetId> for AsInnerId<AssetId, ConvertAssetId>247where248	AssetId: Borrow<AssetId>,249	AssetId: TryAsForeing<AssetId, ForeignAssetId>,250	AssetIds: Borrow<AssetId>,251{252	fn convert_ref(id: impl Borrow<MultiLocation>) -> Result<AssetId, ()> {253		let id = id.borrow();254255		log::trace!(256			target: "xcm::AsInnerId::Convert",257			"AsInnerId {:?}",258			id259		);260261		let parent = MultiLocation::parent();262		let here = MultiLocation::here();263		let self_location = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));264265		if *id == parent {266			return ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Parent));267		}268269		if *id == here || *id == self_location {270			return ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Here));271		}272273		match XcmForeignAssetIdMapping::<Runtime>::get_currency_id(id.clone()) {274			Some(AssetIds::ForeignAssetId(foreign_asset_id)) => {275				ConvertAssetId::convert_ref(AssetIds::ForeignAssetId(foreign_asset_id))276			}277			_ => ConvertAssetId::convert_ref(AssetIds::ForeignAssetId(0)),278		}279	}280281	fn reverse_ref(what: impl Borrow<AssetId>) -> Result<MultiLocation, ()> {282		log::trace!(283			target: "xcm::AsInnerId::Reverse",284			"AsInnerId",285		);286287		let asset_id = what.borrow();288289		let parent_id =290			ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Parent)).unwrap();291		let here_id =292			ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Here)).unwrap();293294		if asset_id.clone() == parent_id {295			return Ok(MultiLocation::parent());296		}297298		if asset_id.clone() == here_id {299			return Ok(MultiLocation::new(300				1,301				X1(Parachain(ParachainInfo::get().into())),302			));303		}304305		match <AssetId as TryAsForeing<AssetId, ForeignAssetId>>::try_as_foreing(asset_id.clone()) {306			Some(fid) => match XcmForeignAssetIdMapping::<Runtime>::get_multi_location(fid) {307				Some(location) => Ok(location),308				None => Err(()),309			},310			None => Err(()),311		}312	}313}314315/// Means for transacting assets besides the native currency on this chain.316#[cfg(feature = "foreign-assets")]317pub type FungiblesTransactor = FungiblesAdapter<318	// Use this fungibles implementation:319	ForeingAssets,320	// Use this currency when it is a fungible asset matching the given location or name:321	ConvertedConcreteAssetId<AssetIds, Balance, AsInnerId<AssetIds, JustTry>, JustTry>,322	// Convert an XCM MultiLocation into a local account id:323	LocationToAccountId,324	// Our chain's account ID type (we can't get away without mentioning it explicitly):325	AccountId,326	// We only want to allow teleports of known assets. We use non-zero issuance as an indication327	// that this asset is known.328	NonZeroIssuance<AccountId, ForeingAssets>,329	// The account to use for tracking teleports.330	CheckingAccount,331>;332333/// Means for transacting assets on this chain.334#[cfg(feature = "foreign-assets")]335pub type AssetTransactors = FungiblesTransactor;336337#[cfg(not(feature = "foreign-assets"))]338pub type AssetTransactors = LocalAssetTransactor;339340#[cfg(feature = "foreign-assets")]341pub struct AllAsset;342#[cfg(feature = "foreign-assets")]343impl FilterAssetLocation for AllAsset {344	fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {345		true346	}347}348349#[cfg(feature = "foreign-assets")]350pub type IsReserve = AllAsset;351#[cfg(not(feature = "foreign-assets"))]352pub type IsReserve = NativeAsset;353354#[cfg(feature = "foreign-assets")]355type Trader<T> = FreeForAll<356	pallet_configuration::WeightToFee<T, Balance>,357	RelayLocation,358	AccountId,359	Balances,360	(),361>;362#[cfg(not(feature = "foreign-assets"))]363type Trader<T> = UsingOnlySelfCurrencyComponents<364	pallet_configuration::WeightToFee<T, Balance>,365	RelayLocation,366	AccountId,367	Balances,368	(),369>;370371pub struct XcmConfig<T>(PhantomData<T>);372impl<T> Config for XcmConfig<T>373where374	T: pallet_configuration::Config,375{376	type Call = Call;377	type XcmSender = XcmRouter;378	// How to withdraw and deposit an asset.379	type AssetTransactor = AssetTransactors;380	type OriginConverter = XcmOriginToTransactDispatchOrigin;381	type IsReserve = IsReserve;382	type IsTeleporter = (); // Teleportation is disabled383	type LocationInverter = LocationInverter<Ancestry>;384	type Barrier = Barrier;385	type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;386	type Trader = Trader<T>;387	type ResponseHandler = (); // Don't handle responses for now.388	type SubscriptionService = PolkadotXcm;389390	type AssetTrap = PolkadotXcm;391	type AssetClaims = PolkadotXcm;392}393394impl pallet_xcm::Config for Runtime {395	type Event = Event;396	type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;397	type XcmRouter = XcmRouter;398	type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;399	type XcmExecuteFilter = Everything;400	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;401	type XcmTeleportFilter = Everything;402	type XcmReserveTransferFilter = Everything;403	type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;404	type LocationInverter = LocationInverter<Ancestry>;405	type Origin = Origin;406	type Call = Call;407	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;408	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;409}410411impl cumulus_pallet_xcm::Config for Runtime {412	type Event = Event;413	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;414}415416impl cumulus_pallet_xcmp_queue::Config for Runtime {417	type WeightInfo = ();418	type Event = Event;419	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;420	type ChannelInfo = ParachainSystem;421	type VersionWrapper = ();422	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;423	type ControllerOrigin = EnsureRoot<AccountId>;424	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;425}426427impl cumulus_pallet_dmp_queue::Config for Runtime {428	type Event = Event;429	type XcmExecutor = XcmExecutor<XcmConfig<Self>>;430	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;431}
modifiedruntime/opal/src/xcm_config.rsdiffbeforeafterboth
--- a/runtime/opal/src/xcm_config.rs
+++ b/runtime/opal/src/xcm_config.rs
@@ -32,9 +32,9 @@
 	v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},
 };
 use xcm_builder::{
-	AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
-	EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentAsSuperuser,
-	ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
+	AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin,
+	FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentAsSuperuser, ParentIsPreset,
+	RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
 	SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
 	ConvertedConcreteAssetId,
 };
@@ -49,8 +49,8 @@
 };
 
 use crate::{
-	Balances, Call, DmpQueue, Event, ForeingAssets, Origin, ParachainInfo,
-	ParachainSystem, PolkadotXcm, Runtime, XcmpQueue,
+	Balances, Call, DmpQueue, Event, ForeingAssets, Origin, ParachainInfo, ParachainSystem,
+	PolkadotXcm, Runtime, XcmpQueue,
 };
 use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};
 use crate::runtime_common::config::pallets::TreasuryAccountId;
@@ -58,8 +58,8 @@
 use crate::*;
 
 use pallet_foreing_assets::{
-	AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
-	UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,
+	AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,
+	TryAsForeing, ForeignAssetId,
 };
 
 // Signed version of balance
@@ -330,7 +330,7 @@
 	type Barrier = Barrier;
 	type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
 	type Trader =
-		UsingAnyCurrencyComponents<LinearFee<Balance>, RelayLocation, AccountId, Balances, ()>;
+		FreeForAll<LinearFee<Balance>, RelayLocation, AccountId, Balances, ()>;
 	type ResponseHandler = (); // Don't handle responses for now.
 	type SubscriptionService = PolkadotXcm;
 	type AssetTrap = PolkadotXcm;
modifiedruntime/quartz/src/xcm_config.rsdiffbeforeafterboth
--- a/runtime/quartz/src/xcm_config.rs
+++ b/runtime/quartz/src/xcm_config.rs
@@ -50,7 +50,7 @@
 };
 use pallet_foreing_assets::{
     AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
-    UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,
+    FreeForAll, TryAsForeing, ForeignAssetId,
 };
 use crate::{
     Balances, Call, DmpQueue, Event, Origin, ParachainInfo,
modifiedruntime/unique/src/xcm_config.rsdiffbeforeafterboth
--- a/runtime/unique/src/xcm_config.rs
+++ b/runtime/unique/src/xcm_config.rs
@@ -50,7 +50,7 @@
 };
 use pallet_foreing_assets::{
     AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
-    UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,
+    FreeForAll, TryAsForeing, ForeignAssetId,
 };
 use crate::{
     Balances, Call, DmpQueue, Event, Origin, ParachainInfo,