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.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/nativeassets.rs
+++ b/runtime/common/config/xcm/nativeassets.rs
@@ -18,7 +18,7 @@
traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},
weights::{Weight, WeightToFeePolynomial},
};
-use sp_runtime::traits::{CheckedConversion, Zero};
+use sp_runtime::traits::{CheckedConversion, Zero, Convert};
use xcm::v1::{Junction::*, MultiLocation, Junctions::*};
use xcm::latest::{
AssetId::{Concrete},
@@ -30,6 +30,7 @@
Assets,
traits::{MatchesFungible, WeightTrader},
};
+use pallet_foreing_assets::{AssetIds, NativeCurrency};
use sp_std::marker::PhantomData;
use crate::{Balances, ParachainInfo};
use super::{LocationToAccountId, RelayLocation};
@@ -127,3 +128,16 @@
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())),
+ )),
+ _ => None,
+ }
+ }
+}
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.rsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617use frame_support::{17use frame_support::{18 {match_types, parameter_types, weights::Weight},18 match_types, parameter_types,19 pallet_prelude::Get,20 traits::{Contains, Everything},19 traits::{Everything, Get},21};20};22use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};23use sp_runtime::traits::{AccountIdConversion, Convert};24use sp_std::{vec, vec::Vec};21use sp_std::{vec, vec::Vec};25use xcm::{22use xcm::v1::{BodyId, Junction::*, Junctions::*, MultiLocation};26 latest::Xcm,27 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},28};29use xcm_builder::{23use xcm_builder::{30 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,24 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,31 AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, TakeWeightCredit,25 AllowUnpaidExecutionFrom, TakeWeightCredit,32};26};33use xcm_executor::XcmExecutor;273435use up_common::types::{AccountId, Balance};36use pallet_foreing_assets::{AssetIds, CurrencyId, NativeCurrency};37use crate::{Call, Event, ParachainInfo, PolkadotXcm, Runtime};38use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};28use crate::{39use crate::runtime_common::config::pallets::TreasuryAccountId;29 ParachainInfo, PolkadotXcm,40use crate::runtime_common::config::xcm::*;30 runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation},41use xcm::opaque::latest::prelude::{DepositReserveAsset, TransferReserveAsset};31};4243// Signed version of balance44pub type Amount = i128;453246match_types! {33match_types! {47 pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {34 pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {54 };41 };55}42}564357pub type Barrier = DenyThenTry<44parameter_types! {58 (DenyTransact, DenyExchangeWithUnknownLocation),59 (60 TakeWeightCredit,61 AllowTopLevelPaidExecutionFrom<Everything>,62 // Parent and its exec plurality get free execution63 AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,64 // Expected responses are OK.65 AllowKnownQueryResponses<PolkadotXcm>,66 // Subscriptions for version tracking are OK.67 AllowSubscriptionsFrom<ParentOrSiblings>,68 ),69>;7071pub fn get_allowed_locations() -> Vec<MultiLocation> {45 pub UniqueAllowedLocations: Vec<MultiLocation> = vec![72 vec![73 // Self location46 // Self location74 MultiLocation {47 MultiLocation {95 parents: 1,68 parents: 1,96 interior: X1(Parachain(ParachainInfo::get().into())),69 interior: X1(Parachain(ParachainInfo::get().into())),97 },70 },98 ]71 ];99}72}10073101// Allow xcm exchange only with locations in list102pub struct DenyExchangeWithUnknownLocation;74pub type Barrier = DenyThenTry<103impl TryPass for DenyExchangeWithUnknownLocation {75 (104 fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()> {105 // Check if deposit or transfer belongs to allowed parachains106 let mut allowed = get_allowed_locations().contains(origin);107108 message.0.iter().for_each(|inst| match inst {109 DepositReserveAsset { dest: dst, .. } => {110 allowed |= get_allowed_locations().contains(dst);111 }112 TransferReserveAsset { dest: dst, .. } => {113 allowed |= get_allowed_locations().contains(dst);114 }115 _ => {}116 });117118 if allowed {119 return Ok(());120 }121122 log::warn!(123 target: "xcm::barrier",124 "Unexpected deposit or transfer location"125 );126 // Deny127 Err(())128 }129}130131impl orml_tokens::Config for Runtime {132 type Event = Event;133 type Balance = Balance;134 type Amount = Amount;135 type CurrencyId = CurrencyId;136 type WeightInfo = ();137 type ExistentialDeposits = ExistentialDeposits;138 type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;139 type MaxLocks = MaxLocks;140 type MaxReserves = MaxReserves;141 // TODO: Add all module accounts142 type DustRemovalWhitelist = DustRemovalWhitelist;143 /// The id type for named reserves.144 type ReserveIdentifier = ();145 type OnNewTokenAccount = ();146 type OnKilledTokenAccount = ();147}148149impl orml_xtokens::Config for Runtime {150 type Event = Event;151 type Balance = Balance;152 type CurrencyId = CurrencyId;153 type CurrencyIdConvert = CurrencyIdConvert;154 type AccountIdToMultiLocation = AccountIdToMultiLocation;155 type SelfLocation = SelfLocation;156 type XcmExecutor = XcmExecutor<XcmConfig<Self>>;157 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;158 type BaseXcmWeight = BaseXcmWeight;159 type LocationInverter = LocationInverter<Ancestry>;160 type MaxAssetsForTransfer = MaxAssetsForTransfer;161 type MinXcmFee = ParachainMinFee;162 type MultiLocationsFilter = Everything;163 type ReserveProvider = AbsoluteReserveProvider;164}165166parameter_type_with_key! {167 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {168 match currency_id {169 CurrencyId::NativeAssetId(symbol) => match symbol {170 NativeCurrency::Here => 0,171 NativeCurrency::Parent=> 0,172 },76 DenyTransact,173 _ => 100_000174 }175 };176}177178pub struct DustRemovalWhitelist;179impl Contains<AccountId> for DustRemovalWhitelist {77 DenyExchangeWithUnknownLocation<UniqueAllowedLocations>,180 fn contains(a: &AccountId) -> bool {181 get_all_module_accounts().contains(a)182 }183}184185pub struct CurrencyIdConvert;186impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {78 ),79 (80 TakeWeightCredit,81 AllowTopLevelPaidExecutionFrom<Everything>,82 // Parent and its exec plurality get free execution187 fn convert(id: AssetIds) -> Option<MultiLocation> {83 AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,188 match id {84 // Expected responses are OK.189 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(190 1,191 X1(Parachain(ParachainInfo::get().into())),192 )),193 _ => None,194 }195 }196}197198parameter_types! {199 pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this200 pub const MaxAssetsForTransfer: usize = 2;201202 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();203 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));204}205206parameter_type_with_key! {207 pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {208 Some(100_000_000)209 };210}211212pub fn get_all_module_accounts() -> Vec<AccountId> {85 AllowKnownQueryResponses<PolkadotXcm>,213 vec![TreasuryModuleId::get().into_account_truncating()]86 // Subscriptions for version tracking are OK.214}215216pub struct AccountIdToMultiLocation;217impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {87 AllowSubscriptionsFrom<ParentOrSiblings>,218 fn convert(account: AccountId) -> MultiLocation {219 X1(AccountId32 {220 network: NetworkId::Any,221 id: account.into(),88 ),222 })89>;223 .into()224 }225}22690