difftreelog
refactor move common xcm parts to common
in: master
7 files changed
runtime/common/config/orml.rsdiffbeforeafterboth--- a/runtime/common/config/orml.rs
+++ b/runtime/common/config/orml.rs
@@ -14,19 +14,87 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::parameter_types;
+use frame_support::{
+ parameter_types,
+ traits::{Contains, Everything},
+ weights::Weight,
+};
use frame_system::EnsureSigned;
-use crate::{Runtime, Event, RelayChainBlockNumberProvider};
+use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
+use sp_runtime::traits::Convert;
+use xcm::v1::{Junction::*, Junctions::*, MultiLocation, NetworkId};
+use xcm_builder::LocationInverter;
+use xcm_executor::XcmExecutor;
+use sp_std::{vec, vec::Vec};
+use pallet_foreing_assets::{CurrencyId, NativeCurrency};
+use crate::{
+ Runtime, Event, RelayChainBlockNumberProvider,
+ runtime_common::config::{
+ xcm::{
+ SelfLocation, Weigher, XcmConfig, Ancestry,
+ xcm_assets::{CurrencyIdConvert},
+ },
+ pallets::TreasuryAccountId,
+ substrate::{MaxLocks, MaxReserves},
+ },
+};
+
use up_common::{
types::{AccountId, Balance},
constants::*,
};
+// Signed version of balance
+pub type Amount = i128;
+
parameter_types! {
pub const MinVestedTransfer: Balance = 10 * UNIQUE;
pub const MaxVestingSchedules: u32 = 28;
+
+ pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this
+ pub const MaxAssetsForTransfer: usize = 2;
+}
+
+parameter_type_with_key! {
+ pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {
+ Some(100_000_000_000)
+ };
+}
+
+parameter_type_with_key! {
+ pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
+ match currency_id {
+ CurrencyId::NativeAssetId(symbol) => match symbol {
+ NativeCurrency::Here => 0,
+ NativeCurrency::Parent=> 0,
+ },
+ _ => 100_000
+ }
+ };
+}
+
+pub fn get_all_module_accounts() -> Vec<AccountId> {
+ vec![TreasuryAccountId::get()]
}
+pub struct DustRemovalWhitelist;
+impl Contains<AccountId> for DustRemovalWhitelist {
+ fn contains(a: &AccountId) -> bool {
+ get_all_module_accounts().contains(a)
+ }
+}
+
+pub struct AccountIdToMultiLocation;
+impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
+ fn convert(account: AccountId) -> MultiLocation {
+ X1(AccountId32 {
+ network: NetworkId::Any,
+ id: account.into(),
+ })
+ .into()
+ }
+}
+
impl orml_vesting::Config for Runtime {
type Event = Event;
type Currency = pallet_balances::Pallet<Runtime>;
@@ -36,3 +104,38 @@
type MaxVestingSchedules = MaxVestingSchedules;
type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
}
+
+impl orml_tokens::Config for Runtime {
+ type Event = Event;
+ type Balance = Balance;
+ type Amount = Amount;
+ type CurrencyId = CurrencyId;
+ type WeightInfo = ();
+ type ExistentialDeposits = ExistentialDeposits;
+ type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;
+ type MaxLocks = MaxLocks;
+ type MaxReserves = MaxReserves;
+ // TODO: Add all module accounts
+ type DustRemovalWhitelist = DustRemovalWhitelist;
+ /// The id type for named reserves.
+ type ReserveIdentifier = ();
+ type OnNewTokenAccount = ();
+ type OnKilledTokenAccount = ();
+}
+
+impl orml_xtokens::Config for Runtime {
+ type Event = Event;
+ type Balance = Balance;
+ type CurrencyId = CurrencyId;
+ type CurrencyIdConvert = CurrencyIdConvert;
+ type AccountIdToMultiLocation = AccountIdToMultiLocation;
+ type SelfLocation = SelfLocation;
+ type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
+ type Weigher = Weigher;
+ type BaseXcmWeight = BaseXcmWeight;
+ type LocationInverter = LocationInverter<Ancestry>;
+ type MaxAssetsForTransfer = MaxAssetsForTransfer;
+ type MinXcmFee = ParachainMinFee;
+ type MultiLocationsFilter = Everything;
+ type ReserveProvider = AbsoluteReserveProvider;
+}
runtime/common/config/xcm/foreignassets.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/foreignassets.rs
+++ b/runtime/common/config/xcm/foreignassets.rs
@@ -18,14 +18,14 @@
traits::{Contains, Get, fungibles},
parameter_types,
};
-use sp_runtime::traits::Zero;
+use sp_runtime::traits::{Zero, Convert};
use xcm::v1::{Junction::*, MultiLocation, Junctions::*};
use xcm::latest::MultiAsset;
use xcm_builder::{FungiblesAdapter, ConvertedConcreteAssetId};
use xcm_executor::traits::{Convert as ConvertXcm, JustTry, FilterAssetLocation};
use pallet_foreing_assets::{
AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, NativeCurrency, FreeForAll, TryAsForeing,
- ForeignAssetId,
+ ForeignAssetId, CurrencyId,
};
use sp_std::{borrow::Borrow, marker::PhantomData};
use crate::{Runtime, Balances, ParachainInfo, PolkadotXcm, ForeingAssets};
@@ -158,3 +158,41 @@
Balances,
(),
>;
+
+pub struct CurrencyIdConvert;
+impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
+ fn convert(id: AssetIds) -> Option<MultiLocation> {
+ match id {
+ AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(
+ 1,
+ X1(Parachain(ParachainInfo::get().into())),
+ )),
+ AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),
+ AssetIds::ForeignAssetId(foreign_asset_id) => {
+ XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)
+ }
+ }
+ }
+}
+
+impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
+ fn convert(location: MultiLocation) -> Option<CurrencyId> {
+ if location == MultiLocation::here()
+ || location == MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())))
+ {
+ return Some(AssetIds::NativeAssetId(NativeCurrency::Here));
+ }
+
+ if location == MultiLocation::parent() {
+ return Some(AssetIds::NativeAssetId(NativeCurrency::Parent));
+ }
+
+ if let Some(currency_id) =
+ XcmForeignAssetIdMapping::<Runtime>::get_currency_id(location.clone())
+ {
+ return Some(currency_id);
+ }
+
+ None
+ }
+}
runtime/common/config/xcm/mod.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/mod.rs
+++ b/runtime/common/config/xcm/mod.rs
@@ -14,19 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{traits::Everything, weights::Weight, parameter_types};
+use frame_support::{
+ traits::{Everything, Get},
+ weights::Weight,
+ parameter_types,
+};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use xcm::v1::{Junction::*, MultiLocation, NetworkId};
-use xcm::latest::{Instruction, Xcm};
+use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, ParentAsSuperuser,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,
};
use xcm_executor::{Config, XcmExecutor, traits::ShouldExecute};
-use sp_std::marker::PhantomData;
+use sp_std::{marker::PhantomData, vec::Vec};
use crate::{
Runtime, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,
xcm_config::Barrier,
@@ -35,16 +39,16 @@
use up_common::types::AccountId;
#[cfg(feature = "foreign-assets")]
-mod foreignassets;
+pub mod foreignassets;
#[cfg(not(feature = "foreign-assets"))]
-mod nativeassets;
+pub mod nativeassets;
#[cfg(feature = "foreign-assets")]
-use foreignassets as xcm_assets;
+pub use foreignassets as xcm_assets;
#[cfg(not(feature = "foreign-assets"))]
-use nativeassets as xcm_assets;
+pub use nativeassets as xcm_assets;
use xcm_assets::{AssetTransactors, IsReserve, Trader};
@@ -53,6 +57,11 @@
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
+ pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
+
+ // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.
+ pub UnitWeightCost: Weight = 1_000_000;
+ pub const MaxInstructions: u32 = 100;
}
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
@@ -102,12 +111,6 @@
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<Origin>,
);
-
-parameter_types! {
- // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.
- pub UnitWeightCost: Weight = 1_000_000;
- pub const MaxInstructions: u32 = 100;
-}
pub trait TryPass {
fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()>;
@@ -169,6 +172,40 @@
}
}
+// Allow xcm exchange only with locations in list
+pub struct DenyExchangeWithUnknownLocation<T>(PhantomData<T>);
+impl<T: Get<Vec<MultiLocation>>> TryPass for DenyExchangeWithUnknownLocation<T> {
+ fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()> {
+ let allowed_locations = T::get();
+
+ // Check if deposit or transfer belongs to allowed parachains
+ let mut allowed = allowed_locations.contains(origin);
+
+ message.0.iter().for_each(|inst| match inst {
+ DepositReserveAsset { dest: dst, .. } => {
+ allowed |= allowed_locations.contains(dst);
+ }
+ TransferReserveAsset { dest: dst, .. } => {
+ allowed |= allowed_locations.contains(dst);
+ }
+ _ => {}
+ });
+
+ if allowed {
+ return Ok(());
+ }
+
+ log::warn!(
+ target: "xcm::barrier",
+ "Unexpected deposit or transfer location"
+ );
+ // Deny
+ Err(())
+ }
+}
+
+pub type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
+
pub struct XcmConfig<T>(PhantomData<T>);
impl<T> Config for XcmConfig<T>
where
@@ -183,7 +220,7 @@
type IsTeleporter = (); // Teleportation is disabled
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
- type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
+ type Weigher = Weigher;
type Trader = Trader<T>;
type ResponseHandler = (); // Don't handle responses for now.
type SubscriptionService = PolkadotXcm;
runtime/common/config/xcm/nativeassets.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/>.1617use frame_support::{18 traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},19 weights::{Weight, WeightToFeePolynomial},20};21use sp_runtime::traits::{CheckedConversion, Zero};22use xcm::v1::{Junction::*, MultiLocation, Junctions::*};23use xcm::latest::{24 AssetId::{Concrete},25 Fungibility::Fungible as XcmFungible,26 MultiAsset, Error as XcmError,27};28use xcm_builder::{CurrencyAdapter, NativeAsset};29use xcm_executor::{30 Assets,31 traits::{MatchesFungible, WeightTrader},32};33use sp_std::marker::PhantomData;34use crate::{Balances, ParachainInfo};35use super::{LocationToAccountId, RelayLocation};3637use up_common::types::{AccountId, Balance};3839pub struct OnlySelfCurrency;40impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {41 fn matches_fungible(a: &MultiAsset) -> Option<B> {42 let paraid = Parachain(ParachainInfo::parachain_id().into());43 match (&a.id, &a.fun) {44 (45 Concrete(MultiLocation {46 parents: 1,47 interior: X1(loc),48 }),49 XcmFungible(ref amount),50 ) if paraid == *loc => CheckedConversion::checked_from(*amount),51 (52 Concrete(MultiLocation {53 parents: 0,54 interior: Here,55 }),56 XcmFungible(ref amount),57 ) => CheckedConversion::checked_from(*amount),58 _ => None,59 }60 }61}6263/// Means for transacting assets on this chain.64pub type LocalAssetTransactor = CurrencyAdapter<65 // Use this currency:66 Balances,67 // Use this currency when it is a fungible asset matching the given location or name:68 OnlySelfCurrency,69 // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:70 LocationToAccountId,71 // Our chain's account ID type (we can't get away without mentioning it explicitly):72 AccountId,73 // We don't track any teleports.74 (),75>;7677pub type AssetTransactors = LocalAssetTransactor;7879pub type IsReserve = NativeAsset;8081pub struct UsingOnlySelfCurrencyComponents<82 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,83 AssetId: Get<MultiLocation>,84 AccountId,85 Currency: CurrencyT<AccountId>,86 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,87>(88 Weight,89 Currency::Balance,90 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,91);92impl<93 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,94 AssetId: Get<MultiLocation>,95 AccountId,96 Currency: CurrencyT<AccountId>,97 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,98 > WeightTrader99 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>100{101 fn new() -> Self {102 Self(0, Zero::zero(), PhantomData)103 }104105 fn buy_weight(&mut self, _weight: Weight, payment: Assets) -> Result<Assets, XcmError> {106 Ok(payment)107 }108}109impl<110 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,111 AssetId: Get<MultiLocation>,112 AccountId,113 Currency: CurrencyT<AccountId>,114 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,115 > Drop116 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>117{118 fn drop(&mut self) {119 OnUnbalanced::on_unbalanced(Currency::issue(self.1));120 }121}122123pub type Trader<T> = UsingOnlySelfCurrencyComponents<124 pallet_configuration::WeightToFee<T, Balance>,125 RelayLocation,126 AccountId,127 Balances,128 (),129>;1// 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/>.1617use frame_support::{18 traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},19 weights::{Weight, WeightToFeePolynomial},20};21use sp_runtime::traits::{CheckedConversion, Zero, Convert};22use xcm::v1::{Junction::*, MultiLocation, Junctions::*};23use xcm::latest::{24 AssetId::{Concrete},25 Fungibility::Fungible as XcmFungible,26 MultiAsset, Error as XcmError,27};28use xcm_builder::{CurrencyAdapter, NativeAsset};29use xcm_executor::{30 Assets,31 traits::{MatchesFungible, WeightTrader},32};33use pallet_foreing_assets::{AssetIds, NativeCurrency};34use sp_std::marker::PhantomData;35use crate::{Balances, ParachainInfo};36use super::{LocationToAccountId, RelayLocation};3738use up_common::types::{AccountId, Balance};3940pub struct OnlySelfCurrency;41impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {42 fn matches_fungible(a: &MultiAsset) -> Option<B> {43 let paraid = Parachain(ParachainInfo::parachain_id().into());44 match (&a.id, &a.fun) {45 (46 Concrete(MultiLocation {47 parents: 1,48 interior: X1(loc),49 }),50 XcmFungible(ref amount),51 ) if paraid == *loc => CheckedConversion::checked_from(*amount),52 (53 Concrete(MultiLocation {54 parents: 0,55 interior: Here,56 }),57 XcmFungible(ref amount),58 ) => CheckedConversion::checked_from(*amount),59 _ => None,60 }61 }62}6364/// Means for transacting assets on this chain.65pub type LocalAssetTransactor = CurrencyAdapter<66 // Use this currency:67 Balances,68 // Use this currency when it is a fungible asset matching the given location or name:69 OnlySelfCurrency,70 // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:71 LocationToAccountId,72 // Our chain's account ID type (we can't get away without mentioning it explicitly):73 AccountId,74 // We don't track any teleports.75 (),76>;7778pub type AssetTransactors = LocalAssetTransactor;7980pub type IsReserve = NativeAsset;8182pub struct UsingOnlySelfCurrencyComponents<83 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,84 AssetId: Get<MultiLocation>,85 AccountId,86 Currency: CurrencyT<AccountId>,87 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,88>(89 Weight,90 Currency::Balance,91 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,92);93impl<94 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,95 AssetId: Get<MultiLocation>,96 AccountId,97 Currency: CurrencyT<AccountId>,98 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,99 > WeightTrader100 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>101{102 fn new() -> Self {103 Self(0, Zero::zero(), PhantomData)104 }105106 fn buy_weight(&mut self, _weight: Weight, payment: Assets) -> Result<Assets, XcmError> {107 Ok(payment)108 }109}110impl<111 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,112 AssetId: Get<MultiLocation>,113 AccountId,114 Currency: CurrencyT<AccountId>,115 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,116 > Drop117 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>118{119 fn drop(&mut self) {120 OnUnbalanced::on_unbalanced(Currency::issue(self.1));121 }122}123124pub type Trader<T> = UsingOnlySelfCurrencyComponents<125 pallet_configuration::WeightToFee<T, Balance>,126 RelayLocation,127 AccountId,128 Balances,129 (),130>;131132pub struct CurrencyIdConvert;133impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {134 fn convert(id: AssetIds) -> Option<MultiLocation> {135 match id {136 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(137 1,138 X1(Parachain(ParachainInfo::get().into())),139 )),140 _ => None,141 }142 }143}runtime/opal/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/opal/src/xcm_config.rs
+++ b/runtime/opal/src/xcm_config.rs
@@ -15,39 +15,17 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- {match_types, parameter_types, weights::Weight},
- pallet_prelude::Get,
- traits::{Contains, Everything},
+ {match_types, weights::Weight},
+ traits::Everything,
};
-use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
-use sp_runtime::traits::{AccountIdConversion, Convert};
-use sp_std::{vec, vec::Vec};
use xcm::{
latest::Xcm,
- v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},
-};
-use xcm_builder::{
- AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter,
- TakeWeightCredit,
-};
-use xcm_executor::{XcmExecutor, traits::ShouldExecute};
-
-use up_common::types::{AccountId, Balance};
-use crate::{
- Call, Event, ParachainInfo, Runtime,
- runtime_common::config::{
- substrate::{TreasuryModuleId, MaxLocks, MaxReserves},
- pallets::TreasuryAccountId,
- xcm::*,
- },
+ v1::{BodyId, Junction::*, Junctions::*, MultiLocation},
};
-
-use pallet_foreing_assets::{
- AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
-};
+use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit};
+use xcm_executor::traits::ShouldExecute;
-// Signed version of balance
-pub type Amount = i128;
+use crate::runtime_common::config::xcm::{DenyThenTry, DenyTransact};
match_types! {
pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {
@@ -83,123 +61,3 @@
AllowAllDebug,
),
>;
-
-impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
- fn convert(location: MultiLocation) -> Option<CurrencyId> {
- if location == MultiLocation::here()
- || location == MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())))
- {
- return Some(AssetIds::NativeAssetId(NativeCurrency::Here));
- }
-
- if location == MultiLocation::parent() {
- return Some(AssetIds::NativeAssetId(NativeCurrency::Parent));
- }
-
- if let Some(currency_id) =
- XcmForeignAssetIdMapping::<Runtime>::get_currency_id(location.clone())
- {
- return Some(currency_id);
- }
-
- None
- }
-}
-
-impl orml_tokens::Config for Runtime {
- type Event = Event;
- type Balance = Balance;
- type Amount = Amount;
- type CurrencyId = CurrencyId;
- type WeightInfo = ();
- type ExistentialDeposits = ExistentialDeposits;
- type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;
- type MaxLocks = MaxLocks;
- type MaxReserves = MaxReserves;
- // TODO: Add all module accounts
- type DustRemovalWhitelist = DustRemovalWhitelist;
- /// The id type for named reserves.
- type ReserveIdentifier = ();
- type OnNewTokenAccount = ();
- type OnKilledTokenAccount = ();
-}
-
-impl orml_xtokens::Config for Runtime {
- type Event = Event;
- type Balance = Balance;
- type CurrencyId = CurrencyId;
- type CurrencyIdConvert = CurrencyIdConvert;
- type AccountIdToMultiLocation = AccountIdToMultiLocation;
- type SelfLocation = SelfLocation;
- type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
- type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
- type BaseXcmWeight = BaseXcmWeight;
- type LocationInverter = LocationInverter<Ancestry>;
- type MaxAssetsForTransfer = MaxAssetsForTransfer;
- type MinXcmFee = ParachainMinFee;
- type MultiLocationsFilter = Everything;
- type ReserveProvider = AbsoluteReserveProvider;
-}
-
-parameter_type_with_key! {
- pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
- match currency_id {
- CurrencyId::NativeAssetId(symbol) => match symbol {
- NativeCurrency::Here => 0,
- NativeCurrency::Parent=> 0,
- },
- _ => 100_000
- }
- };
-}
-
-pub struct DustRemovalWhitelist;
-impl Contains<AccountId> for DustRemovalWhitelist {
- fn contains(a: &AccountId) -> bool {
- get_all_module_accounts().contains(a)
- }
-}
-
-pub struct CurrencyIdConvert;
-impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
- fn convert(id: AssetIds) -> Option<MultiLocation> {
- match id {
- AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(
- 1,
- X1(Parachain(ParachainInfo::get().into())),
- )),
- AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),
- AssetIds::ForeignAssetId(foreign_asset_id) => {
- XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)
- }
- }
- }
-}
-
-parameter_types! {
- pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this
- pub const MaxAssetsForTransfer: usize = 2;
-
- pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
- pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
-}
-
-parameter_type_with_key! {
- pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {
- Some(100_000_000_000)
- };
-}
-
-pub fn get_all_module_accounts() -> Vec<AccountId> {
- vec![TreasuryModuleId::get().into_account_truncating()]
-}
-pub struct AccountIdToMultiLocation;
-impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
- fn convert(account: AccountId) -> MultiLocation {
- X1(AccountId32 {
- network: NetworkId::Any,
- id: account.into(),
- })
- .into()
- }
-}
runtime/quartz/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/quartz/src/xcm_config.rs
+++ b/runtime/quartz/src/xcm_config.rs
@@ -15,33 +15,20 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- {match_types, parameter_types, weights::Weight},
- pallet_prelude::Get,
- traits::{Contains, Everything},
+ match_types, parameter_types,
+ traits::{Everything, Get},
};
-use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
-use sp_runtime::traits::{AccountIdConversion, Convert};
use sp_std::{vec, vec::Vec};
-use xcm::{
- latest::Xcm,
- v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},
-};
+use xcm::v1::{BodyId, Junction::*, Junctions::*, MultiLocation};
use xcm_builder::{
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
- AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, TakeWeightCredit,
+ AllowUnpaidExecutionFrom, TakeWeightCredit,
};
-use xcm_executor::XcmExecutor;
-use up_common::types::{AccountId, Balance};
-use pallet_foreing_assets::{AssetIds, CurrencyId, NativeCurrency};
-use crate::{Call, Event, ParachainInfo, PolkadotXcm, Runtime};
-use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};
-use crate::runtime_common::config::pallets::TreasuryAccountId;
-use crate::runtime_common::config::xcm::*;
-use xcm::opaque::latest::prelude::{DepositReserveAsset, TransferReserveAsset};
-
-// Signed version of balance
-pub type Amount = i128;
+use crate::{
+ ParachainInfo, PolkadotXcm,
+ runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation},
+};
match_types! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
@@ -54,22 +41,8 @@
};
}
-pub type Barrier = DenyThenTry<
- (DenyTransact, DenyExchangeWithUnknownLocation),
- (
- TakeWeightCredit,
- AllowTopLevelPaidExecutionFrom<Everything>,
- // Parent and its exec plurality get free execution
- AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
- // Expected responses are OK.
- AllowKnownQueryResponses<PolkadotXcm>,
- // Subscriptions for version tracking are OK.
- AllowSubscriptionsFrom<ParentOrSiblings>,
- ),
->;
-
-pub fn get_allowed_locations() -> Vec<MultiLocation> {
- vec![
+parameter_types! {
+ pub QuartzAllowedLocations: Vec<MultiLocation> = vec![
// Self location
MultiLocation {
parents: 0,
@@ -95,131 +68,22 @@
parents: 1,
interior: X1(Parachain(ParachainInfo::get().into())),
},
- ]
-}
-
-// Allow xcm exchange only with locations in list
-pub struct DenyExchangeWithUnknownLocation;
-impl TryPass for DenyExchangeWithUnknownLocation {
- fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()> {
- // Check if deposit or transfer belongs to allowed parachains
- let mut allowed = get_allowed_locations().contains(origin);
-
- message.0.iter().for_each(|inst| match inst {
- DepositReserveAsset { dest: dst, .. } => {
- allowed |= get_allowed_locations().contains(dst);
- }
- TransferReserveAsset { dest: dst, .. } => {
- allowed |= get_allowed_locations().contains(dst);
- }
- _ => {}
- });
-
- if allowed {
- return Ok(());
- }
-
- log::warn!(
- target: "xcm::barrier",
- "Unexpected deposit or transfer location"
- );
- // Deny
- Err(())
- }
+ ];
}
-impl orml_tokens::Config for Runtime {
- type Event = Event;
- type Balance = Balance;
- type Amount = Amount;
- type CurrencyId = CurrencyId;
- type WeightInfo = ();
- type ExistentialDeposits = ExistentialDeposits;
- type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;
- type MaxLocks = MaxLocks;
- type MaxReserves = MaxReserves;
- // TODO: Add all module accounts
- type DustRemovalWhitelist = DustRemovalWhitelist;
- /// The id type for named reserves.
- type ReserveIdentifier = ();
- type OnNewTokenAccount = ();
- type OnKilledTokenAccount = ();
-}
-
-impl orml_xtokens::Config for Runtime {
- type Event = Event;
- type Balance = Balance;
- type CurrencyId = CurrencyId;
- type CurrencyIdConvert = CurrencyIdConvert;
- type AccountIdToMultiLocation = AccountIdToMultiLocation;
- type SelfLocation = SelfLocation;
- type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
- type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
- type BaseXcmWeight = BaseXcmWeight;
- type LocationInverter = LocationInverter<Ancestry>;
- type MaxAssetsForTransfer = MaxAssetsForTransfer;
- type MinXcmFee = ParachainMinFee;
- type MultiLocationsFilter = Everything;
- type ReserveProvider = AbsoluteReserveProvider;
-}
-
-parameter_type_with_key! {
- pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
- match currency_id {
- CurrencyId::NativeAssetId(symbol) => match symbol {
- NativeCurrency::Here => 0,
- NativeCurrency::Parent=> 0,
- },
- _ => 100_000
- }
- };
-}
-
-pub struct DustRemovalWhitelist;
-impl Contains<AccountId> for DustRemovalWhitelist {
- fn contains(a: &AccountId) -> bool {
- get_all_module_accounts().contains(a)
- }
-}
-
-pub struct CurrencyIdConvert;
-impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
- fn convert(id: AssetIds) -> Option<MultiLocation> {
- match id {
- AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(
- 1,
- X1(Parachain(ParachainInfo::get().into())),
- )),
- _ => None,
- }
- }
-}
-
-parameter_types! {
- pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this
- pub const MaxAssetsForTransfer: usize = 2;
-
- pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
- pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
-}
-
-parameter_type_with_key! {
- pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {
- Some(100_000_000)
- };
-}
-
-pub fn get_all_module_accounts() -> Vec<AccountId> {
- vec![TreasuryModuleId::get().into_account_truncating()]
-}
-
-pub struct AccountIdToMultiLocation;
-impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
- fn convert(account: AccountId) -> MultiLocation {
- X1(AccountId32 {
- network: NetworkId::Any,
- id: account.into(),
- })
- .into()
- }
-}
+pub type Barrier = DenyThenTry<
+ (
+ DenyTransact,
+ DenyExchangeWithUnknownLocation<QuartzAllowedLocations>,
+ ),
+ (
+ TakeWeightCredit,
+ AllowTopLevelPaidExecutionFrom<Everything>,
+ // Parent and its exec plurality get free execution
+ AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
+ // Expected responses are OK.
+ AllowKnownQueryResponses<PolkadotXcm>,
+ // Subscriptions for version tracking are OK.
+ AllowSubscriptionsFrom<ParentOrSiblings>,
+ ),
+>;
runtime/unique/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/unique/src/xcm_config.rs
+++ b/runtime/unique/src/xcm_config.rs
@@ -15,33 +15,20 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- {match_types, parameter_types, weights::Weight},
- pallet_prelude::Get,
- traits::{Contains, Everything},
+ match_types, parameter_types,
+ traits::{Everything, Get},
};
-use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
-use sp_runtime::traits::{AccountIdConversion, Convert};
use sp_std::{vec, vec::Vec};
-use xcm::{
- latest::Xcm,
- v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},
-};
+use xcm::v1::{BodyId, Junction::*, Junctions::*, MultiLocation};
use xcm_builder::{
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
- AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, TakeWeightCredit,
+ AllowUnpaidExecutionFrom, TakeWeightCredit,
};
-use xcm_executor::XcmExecutor;
-use up_common::types::{AccountId, Balance};
-use pallet_foreing_assets::{AssetIds, CurrencyId, NativeCurrency};
-use crate::{Call, Event, ParachainInfo, PolkadotXcm, Runtime};
-use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};
-use crate::runtime_common::config::pallets::TreasuryAccountId;
-use crate::runtime_common::config::xcm::*;
-use xcm::opaque::latest::prelude::{DepositReserveAsset, TransferReserveAsset};
-
-// Signed version of balance
-pub type Amount = i128;
+use crate::{
+ ParachainInfo, PolkadotXcm,
+ runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation},
+};
match_types! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
@@ -54,22 +41,8 @@
};
}
-pub type Barrier = DenyThenTry<
- (DenyTransact, DenyExchangeWithUnknownLocation),
- (
- TakeWeightCredit,
- AllowTopLevelPaidExecutionFrom<Everything>,
- // Parent and its exec plurality get free execution
- AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
- // Expected responses are OK.
- AllowKnownQueryResponses<PolkadotXcm>,
- // Subscriptions for version tracking are OK.
- AllowSubscriptionsFrom<ParentOrSiblings>,
- ),
->;
-
-pub fn get_allowed_locations() -> Vec<MultiLocation> {
- vec![
+parameter_types! {
+ pub UniqueAllowedLocations: Vec<MultiLocation> = vec![
// Self location
MultiLocation {
parents: 0,
@@ -95,131 +68,22 @@
parents: 1,
interior: X1(Parachain(ParachainInfo::get().into())),
},
- ]
-}
-
-// Allow xcm exchange only with locations in list
-pub struct DenyExchangeWithUnknownLocation;
-impl TryPass for DenyExchangeWithUnknownLocation {
- fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()> {
- // Check if deposit or transfer belongs to allowed parachains
- let mut allowed = get_allowed_locations().contains(origin);
-
- message.0.iter().for_each(|inst| match inst {
- DepositReserveAsset { dest: dst, .. } => {
- allowed |= get_allowed_locations().contains(dst);
- }
- TransferReserveAsset { dest: dst, .. } => {
- allowed |= get_allowed_locations().contains(dst);
- }
- _ => {}
- });
-
- if allowed {
- return Ok(());
- }
-
- log::warn!(
- target: "xcm::barrier",
- "Unexpected deposit or transfer location"
- );
- // Deny
- Err(())
- }
+ ];
}
-impl orml_tokens::Config for Runtime {
- type Event = Event;
- type Balance = Balance;
- type Amount = Amount;
- type CurrencyId = CurrencyId;
- type WeightInfo = ();
- type ExistentialDeposits = ExistentialDeposits;
- type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;
- type MaxLocks = MaxLocks;
- type MaxReserves = MaxReserves;
- // TODO: Add all module accounts
- type DustRemovalWhitelist = DustRemovalWhitelist;
- /// The id type for named reserves.
- type ReserveIdentifier = ();
- type OnNewTokenAccount = ();
- type OnKilledTokenAccount = ();
-}
-
-impl orml_xtokens::Config for Runtime {
- type Event = Event;
- type Balance = Balance;
- type CurrencyId = CurrencyId;
- type CurrencyIdConvert = CurrencyIdConvert;
- type AccountIdToMultiLocation = AccountIdToMultiLocation;
- type SelfLocation = SelfLocation;
- type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
- type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
- type BaseXcmWeight = BaseXcmWeight;
- type LocationInverter = LocationInverter<Ancestry>;
- type MaxAssetsForTransfer = MaxAssetsForTransfer;
- type MinXcmFee = ParachainMinFee;
- type MultiLocationsFilter = Everything;
- type ReserveProvider = AbsoluteReserveProvider;
-}
-
-parameter_type_with_key! {
- pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
- match currency_id {
- CurrencyId::NativeAssetId(symbol) => match symbol {
- NativeCurrency::Here => 0,
- NativeCurrency::Parent=> 0,
- },
- _ => 100_000
- }
- };
-}
-
-pub struct DustRemovalWhitelist;
-impl Contains<AccountId> for DustRemovalWhitelist {
- fn contains(a: &AccountId) -> bool {
- get_all_module_accounts().contains(a)
- }
-}
-
-pub struct CurrencyIdConvert;
-impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
- fn convert(id: AssetIds) -> Option<MultiLocation> {
- match id {
- AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(
- 1,
- X1(Parachain(ParachainInfo::get().into())),
- )),
- _ => None,
- }
- }
-}
-
-parameter_types! {
- pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this
- pub const MaxAssetsForTransfer: usize = 2;
-
- pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
- pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
-}
-
-parameter_type_with_key! {
- pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {
- Some(100_000_000)
- };
-}
-
-pub fn get_all_module_accounts() -> Vec<AccountId> {
- vec![TreasuryModuleId::get().into_account_truncating()]
-}
-
-pub struct AccountIdToMultiLocation;
-impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
- fn convert(account: AccountId) -> MultiLocation {
- X1(AccountId32 {
- network: NetworkId::Any,
- id: account.into(),
- })
- .into()
- }
-}
+pub type Barrier = DenyThenTry<
+ (
+ DenyTransact,
+ DenyExchangeWithUnknownLocation<UniqueAllowedLocations>,
+ ),
+ (
+ TakeWeightCredit,
+ AllowTopLevelPaidExecutionFrom<Everything>,
+ // Parent and its exec plurality get free execution
+ AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
+ // Expected responses are OK.
+ AllowKnownQueryResponses<PolkadotXcm>,
+ // Subscriptions for version tracking are OK.
+ AllowSubscriptionsFrom<ParentOrSiblings>,
+ ),
+>;