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.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,
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.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.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,