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
40 FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative,40 FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentAsSuperuser,
41 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,41 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
42 SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, ParentIsPreset,42 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
43 ConvertedConcreteAssetId43 ParentIsPreset, ConvertedConcreteAssetId,
44};44};
45use xcm_executor::{Config, XcmExecutor, Assets};45use xcm_executor::{Config, XcmExecutor, Assets};
46use xcm_executor::traits::{Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation};46use xcm_executor::traits::{
47 Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation,
48};
47use pallet_foreing_assets::{49use pallet_foreing_assets::{
48 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,50 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,
49 UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,51 TryAsForeing, ForeignAssetId,
50};52};
51use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};53use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};
52use crate::{54use crate::{
53 Runtime, Call, Event, Origin, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,55 Runtime, Call, Event, Origin, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,
54 xcm_config::Barrier56 xcm_config::Barrier,
55};57};
56#[cfg(feature = "foreign-assets")]58#[cfg(feature = "foreign-assets")]
57use crate::ForeingAssets;59use crate::ForeingAssets;
83pub struct OnlySelfCurrency;85pub struct OnlySelfCurrency;
84impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {86impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {
85 fn matches_fungible(a: &MultiAsset) -> Option<B> {87 fn matches_fungible(a: &MultiAsset) -> Option<B> {
88 let paraid = Parachain(ParachainInfo::parachain_id().into());
86 match (&a.id, &a.fun) {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),
87 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),97 (
98 Concrete(MultiLocation {
99 parents: 0,
100 interior: Here,
101 }),
102 XcmFungible(ref amount),
103 ) => CheckedConversion::checked_from(*amount),
88 _ => None,104 _ => None,
89 }105 }
188 }204 }
189205
190 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {206 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)?;
194
195 // location to this parachain through relay chain
196 let option1: xcm::v1::AssetId = Concrete(MultiLocation {
197 parents: 1,
198 interior: X1(Parachain(ParachainInfo::parachain_id().into())),
199 });
200 // direct location
201 let option2: xcm::v1::AssetId = Concrete(MultiLocation {
202 parents: 0,
203 interior: Here,
204 });
205
206 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 };
213
214 let unused = payment
215 .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)207 Ok(payment)
220 }208 }
221
222 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 None
232 }
233 }
234}209}
235impl<210impl<
236 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,211 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,
377pub type IsReserve = NativeAsset;352pub type IsReserve = NativeAsset;
378353
379#[cfg(feature = "foreign-assets")]354#[cfg(feature = "foreign-assets")]
380type Trader<T> =355type Trader<T> = FreeForAll<
381 UsingAnyCurrencyComponents<
382 pallet_configuration::WeightToFee<T, Balance>,356 pallet_configuration::WeightToFee<T, Balance>,
383 RelayLocation, AccountId, Balances, ()>;357 RelayLocation,
358 AccountId,
359 Balances,
360 (),
361>;
384#[cfg(not(feature = "foreign-assets"))]362#[cfg(not(feature = "foreign-assets"))]
385type Trader<T> = UsingOnlySelfCurrencyComponents<363type Trader<T> = UsingOnlySelfCurrencyComponents<
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,