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.rsdiffbeforeafterboth1// 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/>.1617//! # Foreing assets18//!19//! - [`Config`]20//! - [`Call`]21//! - [`Pallet`]22//!23//! ## Overview24//!25//! The foreing assests pallet provides functions for:26//!27//! - Local and foreign assets management. The foreign assets can be updated without runtime upgrade.28//! - Bounds between asset and target collection for cross chain transfer and inner transfers.29//!30//! ## Overview31//!32//! Under construction3334#![cfg_attr(not(feature = "std"), no_std)]35#![allow(clippy::unused_unit)]3637use frame_support::{38 dispatch::DispatchResult,39 ensure,40 pallet_prelude::*,41 traits::{fungible, fungibles, Currency, EnsureOrigin},42 transactional, RuntimeDebug,43};44use frame_system::pallet_prelude::*;45use up_data_structs::{CollectionMode};46use pallet_fungible::{Pallet as PalletFungible};47use scale_info::{TypeInfo};48use sp_runtime::{49 traits::{One, Zero},50 ArithmeticError,51};52use sp_std::{boxed::Box, vec::Vec};53use up_data_structs::{CollectionId, TokenId, CreateCollectionData};5455// NOTE:v1::MultiLocation is used in storages, we would need to do migration if upgrade the56// MultiLocation in the future.57use xcm::opaque::latest::{prelude::XcmError, MultiAsset};58use xcm::{v1::MultiLocation, VersionedMultiLocation};59use xcm_executor::{traits::WeightTrader, Assets};6061use pallet_common::erc::CrossAccountId;6263#[cfg(feature = "std")]64use serde::{Deserialize, Serialize};6566// TODO: Move to primitives67// Id of native currency.68// 0 - QTZ\UNQ69// 1 - KSM\DOT70#[derive(71 Clone,72 Copy,73 Eq,74 PartialEq,75 PartialOrd,76 Ord,77 MaxEncodedLen,78 RuntimeDebug,79 Encode,80 Decode,81 TypeInfo,82)]83#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]84pub enum NativeCurrency {85 Here = 0,86 Parent = 1,87}8889#[derive(90 Clone,91 Copy,92 Eq,93 PartialEq,94 PartialOrd,95 Ord,96 MaxEncodedLen,97 RuntimeDebug,98 Encode,99 Decode,100 TypeInfo,101)]102#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]103pub enum AssetIds {104 ForeignAssetId(ForeignAssetId),105 NativeAssetId(NativeCurrency),106}107108pub trait TryAsForeing<T, F> {109 fn try_as_foreing(asset: T) -> Option<F>;110}111112impl TryAsForeing<AssetIds, ForeignAssetId> for AssetIds {113 fn try_as_foreing(asset: AssetIds) -> Option<ForeignAssetId> {114 match asset {115 AssetIds::ForeignAssetId(id) => Some(id),116 _ => None,117 }118 }119}120121pub type ForeignAssetId = u32;122pub type CurrencyId = AssetIds;123124mod impl_fungibles;125mod weights;126127pub use module::*;128pub use weights::WeightInfo;129130/// Type alias for currency balance.131pub type BalanceOf<T> =132 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;133134/// A mapping between ForeignAssetId and AssetMetadata.135pub trait AssetIdMapping<ForeignAssetId, MultiLocation, AssetMetadata> {136 /// Returns the AssetMetadata associated with a given ForeignAssetId.137 fn get_asset_metadata(foreign_asset_id: ForeignAssetId) -> Option<AssetMetadata>;138 /// Returns the MultiLocation associated with a given ForeignAssetId.139 fn get_multi_location(foreign_asset_id: ForeignAssetId) -> Option<MultiLocation>;140 /// Returns the CurrencyId associated with a given MultiLocation.141 fn get_currency_id(multi_location: MultiLocation) -> Option<CurrencyId>;142}143144pub struct XcmForeignAssetIdMapping<T>(sp_std::marker::PhantomData<T>);145146impl<T: Config> AssetIdMapping<ForeignAssetId, MultiLocation, AssetMetadata<BalanceOf<T>>>147 for XcmForeignAssetIdMapping<T>148{149 fn get_asset_metadata(foreign_asset_id: ForeignAssetId) -> Option<AssetMetadata<BalanceOf<T>>> {150 log::trace!(target: "fassets::asset_metadatas", "call");151 Pallet::<T>::asset_metadatas(AssetIds::ForeignAssetId(foreign_asset_id))152 }153154 fn get_multi_location(foreign_asset_id: ForeignAssetId) -> Option<MultiLocation> {155 log::trace!(target: "fassets::get_multi_location", "call");156 Pallet::<T>::foreign_asset_locations(foreign_asset_id)157 }158159 fn get_currency_id(multi_location: MultiLocation) -> Option<CurrencyId> {160 log::trace!(target: "fassets::get_currency_id", "call");161 Some(AssetIds::ForeignAssetId(162 Pallet::<T>::location_to_currency_ids(multi_location).unwrap_or(0),163 ))164 }165}166167#[frame_support::pallet]168pub mod module {169 use super::*;170171 #[pallet::config]172 pub trait Config:173 frame_system::Config174 + pallet_common::Config175 + pallet_fungible::Config176 + orml_tokens::Config177 + pallet_balances::Config178 {179 /// The overarching event type.180 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;181182 /// Currency type for withdraw and balance storage.183 type Currency: Currency<Self::AccountId>;184185 /// Required origin for registering asset.186 type RegisterOrigin: EnsureOrigin<Self::Origin>;187188 /// Weight information for the extrinsics in this module.189 type WeightInfo: WeightInfo;190 }191192 #[derive(Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, TypeInfo)]193 pub struct AssetMetadata<Balance> {194 pub name: Vec<u8>,195 pub symbol: Vec<u8>,196 pub decimals: u8,197 pub minimal_balance: Balance,198 }199200 #[pallet::error]201 pub enum Error<T> {202 /// The given location could not be used (e.g. because it cannot be expressed in the203 /// desired version of XCM).204 BadLocation,205 /// MultiLocation existed206 MultiLocationExisted,207 /// AssetId not exists208 AssetIdNotExists,209 /// AssetId exists210 AssetIdExisted,211 }212213 #[pallet::event]214 #[pallet::generate_deposit(fn deposit_event)]215 pub enum Event<T: Config> {216 /// The foreign asset registered.217 ForeignAssetRegistered {218 asset_id: ForeignAssetId,219 asset_address: MultiLocation,220 metadata: AssetMetadata<BalanceOf<T>>,221 },222 /// The foreign asset updated.223 ForeignAssetUpdated {224 asset_id: ForeignAssetId,225 asset_address: MultiLocation,226 metadata: AssetMetadata<BalanceOf<T>>,227 },228 /// The asset registered.229 AssetRegistered {230 asset_id: AssetIds,231 metadata: AssetMetadata<BalanceOf<T>>,232 },233 /// The asset updated.234 AssetUpdated {235 asset_id: AssetIds,236 metadata: AssetMetadata<BalanceOf<T>>,237 },238 }239240 /// Next available Foreign AssetId ID.241 ///242 /// NextForeignAssetId: ForeignAssetId243 #[pallet::storage]244 #[pallet::getter(fn next_foreign_asset_id)]245 pub type NextForeignAssetId<T: Config> = StorageValue<_, ForeignAssetId, ValueQuery>;246 /// The storages for MultiLocations.247 ///248 /// ForeignAssetLocations: map ForeignAssetId => Option<MultiLocation>249 #[pallet::storage]250 #[pallet::getter(fn foreign_asset_locations)]251 pub type ForeignAssetLocations<T: Config> =252 StorageMap<_, Twox64Concat, ForeignAssetId, MultiLocation, OptionQuery>;253254 /// The storages for CurrencyIds.255 ///256 /// LocationToCurrencyIds: map MultiLocation => Option<ForeignAssetId>257 #[pallet::storage]258 #[pallet::getter(fn location_to_currency_ids)]259 pub type LocationToCurrencyIds<T: Config> =260 StorageMap<_, Twox64Concat, MultiLocation, ForeignAssetId, OptionQuery>;261262 /// The storages for AssetMetadatas.263 ///264 /// AssetMetadatas: map AssetIds => Option<AssetMetadata>265 #[pallet::storage]266 #[pallet::getter(fn asset_metadatas)]267 pub type AssetMetadatas<T: Config> =268 StorageMap<_, Twox64Concat, AssetIds, AssetMetadata<BalanceOf<T>>, OptionQuery>;269270 /// The storages for assets to fungible collection binding271 ///272 #[pallet::storage]273 #[pallet::getter(fn asset_binding)]274 pub type AssetBinding<T: Config> =275 StorageMap<_, Twox64Concat, ForeignAssetId, CollectionId, OptionQuery>;276277 #[pallet::pallet]278 #[pallet::without_storage_info]279 pub struct Pallet<T>(_);280281 #[pallet::call]282 impl<T: Config> Pallet<T> {283 #[pallet::weight(<T as Config>::WeightInfo::register_foreign_asset())]284 #[transactional]285 pub fn register_foreign_asset(286 origin: OriginFor<T>,287 owner: T::AccountId,288 location: Box<VersionedMultiLocation>,289 metadata: Box<AssetMetadata<BalanceOf<T>>>,290 ) -> DispatchResult {291 T::RegisterOrigin::ensure_origin(origin.clone())?;292293 let location: MultiLocation = (*location)294 .try_into()295 .map_err(|()| Error::<T>::BadLocation)?;296297 let md = metadata.clone();298 let name: Vec<u16> = md.name.into_iter().map(|x| x as u16).collect::<Vec<u16>>();299 let mut description: Vec<u16> = "Foreing assets collection for "300 .encode_utf16()301 .collect::<Vec<u16>>();302 description.append(&mut name.clone());303304 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {305 name: name.try_into().unwrap(),306 description: description.try_into().unwrap(),307 mode: CollectionMode::Fungible(18),308 ..Default::default()309 };310311 let bounded_collection_id = <PalletFungible<T>>::init_foreign_collection(312 CrossAccountId::from_sub(owner),313 data,314 )?;315 let foreign_asset_id =316 Self::do_register_foreign_asset(&location, &metadata, bounded_collection_id)?;317318 Self::deposit_event(Event::<T>::ForeignAssetRegistered {319 asset_id: foreign_asset_id,320 asset_address: location,321 metadata: *metadata,322 });323 Ok(())324 }325326 #[pallet::weight(<T as Config>::WeightInfo::update_foreign_asset())]327 #[transactional]328 pub fn update_foreign_asset(329 origin: OriginFor<T>,330 foreign_asset_id: ForeignAssetId,331 location: Box<VersionedMultiLocation>,332 metadata: Box<AssetMetadata<BalanceOf<T>>>,333 ) -> DispatchResult {334 T::RegisterOrigin::ensure_origin(origin)?;335336 let location: MultiLocation = (*location)337 .try_into()338 .map_err(|()| Error::<T>::BadLocation)?;339 Self::do_update_foreign_asset(foreign_asset_id, &location, &metadata)?;340341 Self::deposit_event(Event::<T>::ForeignAssetUpdated {342 asset_id: foreign_asset_id,343 asset_address: location,344 metadata: *metadata,345 });346 Ok(())347 }348 }349}350351impl<T: Config> Pallet<T> {352 fn get_next_foreign_asset_id() -> Result<ForeignAssetId, DispatchError> {353 NextForeignAssetId::<T>::try_mutate(|current| -> Result<ForeignAssetId, DispatchError> {354 let id = *current;355 *current = current356 .checked_add(One::one())357 .ok_or(ArithmeticError::Overflow)?;358 Ok(id)359 })360 }361362 fn do_register_foreign_asset(363 location: &MultiLocation,364 metadata: &AssetMetadata<BalanceOf<T>>,365 bounded_collection_id: CollectionId,366 ) -> Result<ForeignAssetId, DispatchError> {367 let foreign_asset_id = Self::get_next_foreign_asset_id()?;368 LocationToCurrencyIds::<T>::try_mutate(location, |maybe_currency_ids| -> DispatchResult {369 ensure!(370 maybe_currency_ids.is_none(),371 Error::<T>::MultiLocationExisted372 );373 *maybe_currency_ids = Some(foreign_asset_id);374 // *maybe_currency_ids = Some(CurrencyId::ForeignAsset(foreign_asset_id));375376 ForeignAssetLocations::<T>::try_mutate(377 foreign_asset_id,378 |maybe_location| -> DispatchResult {379 ensure!(maybe_location.is_none(), Error::<T>::MultiLocationExisted);380 *maybe_location = Some(location.clone());381382 AssetMetadatas::<T>::try_mutate(383 AssetIds::ForeignAssetId(foreign_asset_id),384 |maybe_asset_metadatas| -> DispatchResult {385 ensure!(maybe_asset_metadatas.is_none(), Error::<T>::AssetIdExisted);386 *maybe_asset_metadatas = Some(metadata.clone());387 Ok(())388 },389 )390 },391 )?;392393 AssetBinding::<T>::try_mutate(foreign_asset_id, |collection_id| -> DispatchResult {394 *collection_id = Some(bounded_collection_id);395 Ok(())396 })397 })?;398399 Ok(foreign_asset_id)400 }401402 fn do_update_foreign_asset(403 foreign_asset_id: ForeignAssetId,404 location: &MultiLocation,405 metadata: &AssetMetadata<BalanceOf<T>>,406 ) -> DispatchResult {407 ForeignAssetLocations::<T>::try_mutate(408 foreign_asset_id,409 |maybe_multi_locations| -> DispatchResult {410 let old_multi_locations = maybe_multi_locations411 .as_mut()412 .ok_or(Error::<T>::AssetIdNotExists)?;413414 AssetMetadatas::<T>::try_mutate(415 AssetIds::ForeignAssetId(foreign_asset_id),416 |maybe_asset_metadatas| -> DispatchResult {417 ensure!(418 maybe_asset_metadatas.is_some(),419 Error::<T>::AssetIdNotExists420 );421422 // modify location423 if location != old_multi_locations {424 LocationToCurrencyIds::<T>::remove(old_multi_locations.clone());425 LocationToCurrencyIds::<T>::try_mutate(426 location,427 |maybe_currency_ids| -> DispatchResult {428 ensure!(429 maybe_currency_ids.is_none(),430 Error::<T>::MultiLocationExisted431 );432 // *maybe_currency_ids = Some(CurrencyId::ForeignAsset(foreign_asset_id));433 *maybe_currency_ids = Some(foreign_asset_id);434 Ok(())435 },436 )?;437 }438 *maybe_asset_metadatas = Some(metadata.clone());439 *old_multi_locations = location.clone();440 Ok(())441 },442 )443 },444 )445 }446}447448use sp_runtime::SaturatedConversion;449use sp_runtime::traits::Saturating;450pub use frame_support::{451 traits::{452 fungibles::{Balanced, CreditOf},453 tokens::currency::Currency as CurrencyT,454 OnUnbalanced as OnUnbalancedT,455 },456 weights::{WeightToFeePolynomial, WeightToFee},457};458459use xcm::latest::{Fungibility::Fungible as XcmFungible};460461pub struct UsingAnyCurrencyComponents<462 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,463 AssetId: Get<MultiLocation>,464 AccountId,465 Currency: CurrencyT<AccountId>,466 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,467>(468 Weight,469 Currency::Balance,470 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,471);472473impl<474 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,475 AssetId: Get<MultiLocation>,476 AccountId,477 Currency: CurrencyT<AccountId>,478 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,479 > WeightTrader480 for UsingAnyCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>481{482 fn new() -> Self {483 Self(0, Zero::zero(), PhantomData)484 }485486 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {487 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)515 }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}530impl<531 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,532 AssetId: Get<MultiLocation>,533 AccountId,534 Currency: CurrencyT<AccountId>,535 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,536 > Drop for UsingAnyCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>537{538 fn drop(&mut self) {539 OnUnbalanced::on_unbalanced(Currency::issue(self.1));540 }541}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.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,