difftreelog
Weight trader removed
in: master
8 files changed
node/cli/src/chain_spec.rsdiffbeforeafterbothno syntactic changes
pallets/foreing-assets/src/lib.rsdiffbeforeafterboth458458459use xcm::latest::{Fungibility::Fungible as XcmFungible};459use xcm::latest::{Fungibility::Fungible as XcmFungible};460460461pub struct UsingAnyCurrencyComponents<461pub struct FreeForAll<462 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,462 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,463 AssetId: Get<MultiLocation>,463 AssetId: Get<MultiLocation>,464 AccountId,464 AccountId,476 AccountId,476 AccountId,477 Currency: CurrencyT<AccountId>,477 Currency: CurrencyT<AccountId>,478 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,478 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,479 > WeightTrader479 > WeightTrader for FreeForAll<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>480 for UsingAnyCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>481{480{482 fn new() -> Self {481 fn new() -> Self {483 Self(0, Zero::zero(), PhantomData)482 Self(0, Zero::zero(), PhantomData)486 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {485 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {487 log::trace!(target: "fassets::weight", "buy_weight weight: {:?}, payment: {:?}", weight, payment);486 log::trace!(target: "fassets::weight", "buy_weight weight: {:?}, payment: {:?}", weight, payment);488489 let amount: Currency::Balance = (0 as u32).into();490 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;491492 let asset_id = payment493 .fungible494 .iter()495 .next()496 .map_or(Err(XcmError::TooExpensive), |v| Ok(v.0))?;497498 // First fungible pays fee499 let required = MultiAsset {500 id: asset_id.clone(),501 fun: XcmFungible(u128_amount),502 };503504 log::trace!(505 target: "fassets::weight", "buy_weight payment: {:?}, required: {:?}",506 payment, required,507 );508509 let unused = payment510 .checked_sub(required)511 .map_err(|_| XcmError::TooExpensive)?;512 self.0 = self.0.saturating_add(weight);513 self.1 = self.1.saturating_add(amount);514 Ok(unused)487 Ok(payment)515 }488 }516517 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {518 let weight = weight.min(self.0);519 let amount = WeightToFee::weight_to_fee(&weight);520 self.0 -= weight;521 self.1 = self.1.saturating_sub(amount);522 let amount: u128 = amount.saturated_into();523 if amount > 0 {524 Some((AssetId::get(), amount).into())525 } else {526 None527 }528 }529}489}530impl<490impl<531 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,491 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,532 AssetId: Get<MultiLocation>,492 AssetId: Get<MultiLocation>,533 AccountId,493 AccountId,534 Currency: CurrencyT<AccountId>,494 Currency: CurrencyT<AccountId>,535 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,495 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,536 > Drop for UsingAnyCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>496 > Drop for FreeForAll<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>537{497{538 fn drop(&mut self) {498 fn drop(&mut self) {539 OnUnbalanced::on_unbalanced(Currency::issue(self.1));499 OnUnbalanced::on_unbalanced(Currency::issue(self.1));pallets/fungible/src/lib.rsdiffbeforeafterbothno syntactic changes
runtime/common/config/pallets/foreign_asset.rsdiffbeforeafterbothno syntactic changes
runtime/common/config/xcm.rsdiffbeforeafterboth40 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 }189205190 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)?;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)207 Ok(payment)220 }208 }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}209}235impl<210impl<236 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,211 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,377pub type IsReserve = NativeAsset;352pub type IsReserve = NativeAsset;378353379#[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<runtime/opal/src/xcm_config.rsdiffbeforeafterboth58use crate::*;58use crate::*;595960use pallet_foreing_assets::{60use pallet_foreing_assets::{61 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,61 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,62 UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,62 TryAsForeing, ForeignAssetId,63};63};646465// Signed version of balance65// Signed version of balance316 }316 }317}317}318318319/* /// CHANGEME!!!319/* /// CHANGEME!!!320pub struct XcmConfig;320pub struct XcmConfig;321impl Config for XcmConfig {321impl Config for XcmConfig {322 type Call = Call;322 type Call = Call;323 type XcmSender = XcmRouter;323 type XcmSender = XcmRouter;324 // How to withdraw and deposit an asset.324 // How to withdraw and deposit an asset.325 type AssetTransactor = AssetTransactors;325 type AssetTransactor = AssetTransactors;326 type OriginConverter = XcmOriginToTransactDispatchOrigin;326 type OriginConverter = XcmOriginToTransactDispatchOrigin;327 type IsReserve = AllAsset; //NativeAsset;327 type IsReserve = AllAsset; //NativeAsset;328 type IsTeleporter = (); // Teleportation is disabled328 type IsTeleporter = (); // Teleportation is disabled329 type LocationInverter = LocationInverter<Ancestry>;329 type LocationInverter = LocationInverter<Ancestry>;330 type Barrier = Barrier;330 type Barrier = Barrier;331 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;331 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;332 type Trader =332 type Trader =333 UsingAnyCurrencyComponents<LinearFee<Balance>, RelayLocation, AccountId, Balances, ()>;333 FreeForAll<LinearFee<Balance>, RelayLocation, AccountId, Balances, ()>;334 type ResponseHandler = (); // Don't handle responses for now.334 type ResponseHandler = (); // Don't handle responses for now.335 type SubscriptionService = PolkadotXcm;335 type SubscriptionService = PolkadotXcm;336 type AssetTrap = PolkadotXcm;336 type AssetTrap = PolkadotXcm;337 type AssetClaims = PolkadotXcm;337 type AssetClaims = PolkadotXcm;338}338}339 */339 */340340341/*341/*342/// No local origins on this chain are allowed to dispatch XCM sends/executions.342/// No local origins on this chain are allowed to dispatch XCM sends/executions.runtime/quartz/src/xcm_config.rsdiffbeforeafterboth50};50};51use pallet_foreing_assets::{51use pallet_foreing_assets::{52 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,52 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,53 UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,53 FreeForAll, TryAsForeing, ForeignAssetId,54};54};55use crate::{55use crate::{56 Balances, Call, DmpQueue, Event, Origin, ParachainInfo,56 Balances, Call, DmpQueue, Event, Origin, ParachainInfo,runtime/unique/src/xcm_config.rsdiffbeforeafterboth50};50};51use pallet_foreing_assets::{51use pallet_foreing_assets::{52 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,52 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,53 UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,53 FreeForAll, TryAsForeing, ForeignAssetId,54};54};55use crate::{55use crate::{56 Balances, Call, DmpQueue, Event, Origin, ParachainInfo,56 Balances, Call, DmpQueue, Event, Origin, ParachainInfo,