difftreelog
Weight trader removed
in: master
8 files changed
node/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;
pallets/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));
pallets/fungible/src/lib.rsdiffbeforeafterbothno syntactic changes
runtime/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 = ();
}
runtime/common/config/xcm.rsdiffbeforeafterboth--- a/runtime/common/config/xcm.rs
+++ b/runtime/common/config/xcm.rs
@@ -16,8 +16,8 @@
use frame_support::{
traits::{
- Contains, tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get, Everything,
- fungibles,
+ Contains, tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get,
+ Everything, fungibles,
},
weights::{Weight, WeightToFeePolynomial, WeightToFee},
parameter_types, match_types,
@@ -37,21 +37,23 @@
};
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,
- FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative,
- SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
- SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, ParentIsPreset,
- ConvertedConcreteAssetId
+ FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentAsSuperuser,
+ RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
+ SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
+ ParentIsPreset, ConvertedConcreteAssetId,
};
use xcm_executor::{Config, XcmExecutor, Assets};
-use xcm_executor::traits::{Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation};
+use xcm_executor::traits::{
+ Convert as ConvertXcm, JustTry, MatchesFungible, WeightTrader, FilterAssetLocation,
+};
use pallet_foreing_assets::{
- AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
- UsingAnyCurrencyComponents, TryAsForeing, ForeignAssetId,
+ AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,
+ TryAsForeing, ForeignAssetId,
};
use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};
use crate::{
Runtime, Call, Event, Origin, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,
- xcm_config::Barrier
+ xcm_config::Barrier,
};
#[cfg(feature = "foreign-assets")]
use crate::ForeingAssets;
@@ -83,8 +85,22 @@
pub struct OnlySelfCurrency;
impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {
fn matches_fungible(a: &MultiAsset) -> Option<B> {
+ let paraid = Parachain(ParachainInfo::parachain_id().into());
match (&a.id, &a.fun) {
- (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),
+ (
+ Concrete(MultiLocation {
+ parents: 1,
+ interior: X1(loc),
+ }),
+ XcmFungible(ref amount),
+ ) if paraid == *loc => CheckedConversion::checked_from(*amount),
+ (
+ Concrete(MultiLocation {
+ parents: 0,
+ interior: Here,
+ }),
+ XcmFungible(ref amount),
+ ) => CheckedConversion::checked_from(*amount),
_ => None,
}
}
@@ -188,48 +204,7 @@
}
fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {
- let amount: Currency::Balance = (0 as u32).into();
- //let amount = WeightToFee::weight_to_fee(&weight);
- let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;
-
- // location to this parachain through relay chain
- let option1: xcm::v1::AssetId = Concrete(MultiLocation {
- parents: 1,
- interior: X1(Parachain(ParachainInfo::parachain_id().into())),
- });
- // direct location
- let option2: xcm::v1::AssetId = Concrete(MultiLocation {
- parents: 0,
- interior: Here,
- });
-
- let required = if payment.fungible.contains_key(&option1) {
- (option1, u128_amount).into()
- } else if payment.fungible.contains_key(&option2) {
- (option2, u128_amount).into()
- } else {
- (Concrete(MultiLocation::default()), u128_amount).into()
- };
-
- 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<
@@ -255,9 +230,9 @@
#[cfg(feature = "foreign-assets")]
impl<AccountId, ForeingAssets> Contains<<ForeingAssets as fungibles::Inspect<AccountId>>::AssetId>
-for NonZeroIssuance<AccountId, ForeingAssets>
- where
- ForeingAssets: fungibles::Inspect<AccountId>,
+ for NonZeroIssuance<AccountId, ForeingAssets>
+where
+ ForeingAssets: fungibles::Inspect<AccountId>,
{
fn contains(id: &<ForeingAssets as fungibles::Inspect<AccountId>>::AssetId) -> bool {
!ForeingAssets::total_issuance(*id).is_zero()
@@ -268,11 +243,11 @@
pub struct AsInnerId<AssetId, ConvertAssetId>(PhantomData<(AssetId, ConvertAssetId)>);
#[cfg(feature = "foreign-assets")]
impl<AssetId: Clone + PartialEq, ConvertAssetId: ConvertXcm<AssetId, AssetId>>
-ConvertXcm<MultiLocation, AssetId> for AsInnerId<AssetId, ConvertAssetId>
- where
- AssetId: Borrow<AssetId>,
- AssetId: TryAsForeing<AssetId, ForeignAssetId>,
- AssetIds: Borrow<AssetId>,
+ ConvertXcm<MultiLocation, AssetId> for AsInnerId<AssetId, ConvertAssetId>
+where
+ AssetId: Borrow<AssetId>,
+ AssetId: TryAsForeing<AssetId, ForeignAssetId>,
+ AssetIds: Borrow<AssetId>,
{
fn convert_ref(id: impl Borrow<MultiLocation>) -> Result<AssetId, ()> {
let id = id.borrow();
@@ -377,10 +352,13 @@
pub type IsReserve = NativeAsset;
#[cfg(feature = "foreign-assets")]
-type Trader<T> =
- UsingAnyCurrencyComponents<
- pallet_configuration::WeightToFee<T, Balance>,
- RelayLocation, AccountId, Balances, ()>;
+type Trader<T> = FreeForAll<
+ pallet_configuration::WeightToFee<T, Balance>,
+ RelayLocation,
+ AccountId,
+ Balances,
+ (),
+>;
#[cfg(not(feature = "foreign-assets"))]
type Trader<T> = UsingOnlySelfCurrencyComponents<
pallet_configuration::WeightToFee<T, Balance>,
@@ -451,4 +429,3 @@
type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;
}
-
runtime/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;
runtime/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,
runtime/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,