difftreelog
refactor move common xcm parts to common
in: master
7 files changed
runtime/common/config/orml.rsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// 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::parameter_types;17use frame_support::{18 parameter_types,19 traits::{Contains, Everything},20 weights::Weight,21};18use frame_system::EnsureSigned;22use frame_system::EnsureSigned;23use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};24use sp_runtime::traits::Convert;25use xcm::v1::{Junction::*, Junctions::*, MultiLocation, NetworkId};26use xcm_builder::LocationInverter;27use xcm_executor::XcmExecutor;28use sp_std::{vec, vec::Vec};29use pallet_foreing_assets::{CurrencyId, NativeCurrency};19use crate::{Runtime, Event, RelayChainBlockNumberProvider};30use crate::{31 Runtime, Event, RelayChainBlockNumberProvider,32 runtime_common::config::{33 xcm::{34 SelfLocation, Weigher, XcmConfig, Ancestry,35 xcm_assets::{CurrencyIdConvert},36 },37 pallets::TreasuryAccountId,38 substrate::{MaxLocks, MaxReserves},39 },40};4120use up_common::{42use up_common::{21 types::{AccountId, Balance},43 types::{AccountId, Balance},22 constants::*,44 constants::*,23};45};4647// Signed version of balance48pub type Amount = i128;244925parameter_types! {50parameter_types! {26 pub const MinVestedTransfer: Balance = 10 * UNIQUE;51 pub const MinVestedTransfer: Balance = 10 * UNIQUE;27 pub const MaxVestingSchedules: u32 = 28;52 pub const MaxVestingSchedules: u32 = 28;5354 pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this55 pub const MaxAssetsForTransfer: usize = 2;28}56}5758parameter_type_with_key! {59 pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {60 Some(100_000_000_000)61 };62}6364parameter_type_with_key! {65 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {66 match currency_id {67 CurrencyId::NativeAssetId(symbol) => match symbol {68 NativeCurrency::Here => 0,69 NativeCurrency::Parent=> 0,70 },71 _ => 100_00072 }73 };74}7576pub fn get_all_module_accounts() -> Vec<AccountId> {77 vec![TreasuryAccountId::get()]78}7980pub struct DustRemovalWhitelist;81impl Contains<AccountId> for DustRemovalWhitelist {82 fn contains(a: &AccountId) -> bool {83 get_all_module_accounts().contains(a)84 }85}8687pub struct AccountIdToMultiLocation;88impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {89 fn convert(account: AccountId) -> MultiLocation {90 X1(AccountId32 {91 network: NetworkId::Any,92 id: account.into(),93 })94 .into()95 }96}299730impl orml_vesting::Config for Runtime {98impl orml_vesting::Config for Runtime {31 type Event = Event;99 type Event = Event;37 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;105 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;38}106}107108impl orml_tokens::Config for Runtime {109 type Event = Event;110 type Balance = Balance;111 type Amount = Amount;112 type CurrencyId = CurrencyId;113 type WeightInfo = ();114 type ExistentialDeposits = ExistentialDeposits;115 type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;116 type MaxLocks = MaxLocks;117 type MaxReserves = MaxReserves;118 // TODO: Add all module accounts119 type DustRemovalWhitelist = DustRemovalWhitelist;120 /// The id type for named reserves.121 type ReserveIdentifier = ();122 type OnNewTokenAccount = ();123 type OnKilledTokenAccount = ();124}125126impl orml_xtokens::Config for Runtime {127 type Event = Event;128 type Balance = Balance;129 type CurrencyId = CurrencyId;130 type CurrencyIdConvert = CurrencyIdConvert;131 type AccountIdToMultiLocation = AccountIdToMultiLocation;132 type SelfLocation = SelfLocation;133 type XcmExecutor = XcmExecutor<XcmConfig<Self>>;134 type Weigher = Weigher;135 type BaseXcmWeight = BaseXcmWeight;136 type LocationInverter = LocationInverter<Ancestry>;137 type MaxAssetsForTransfer = MaxAssetsForTransfer;138 type MinXcmFee = ParachainMinFee;139 type MultiLocationsFilter = Everything;140 type ReserveProvider = AbsoluteReserveProvider;141}39142runtime/common/config/xcm/foreignassets.rsdiffbeforeafterboth18 traits::{Contains, Get, fungibles},18 traits::{Contains, Get, fungibles},19 parameter_types,19 parameter_types,20};20};21use sp_runtime::traits::Zero;21use sp_runtime::traits::{Zero, Convert};22use xcm::v1::{Junction::*, MultiLocation, Junctions::*};22use xcm::v1::{Junction::*, MultiLocation, Junctions::*};23use xcm::latest::MultiAsset;23use xcm::latest::MultiAsset;24use xcm_builder::{FungiblesAdapter, ConvertedConcreteAssetId};24use xcm_builder::{FungiblesAdapter, ConvertedConcreteAssetId};25use xcm_executor::traits::{Convert as ConvertXcm, JustTry, FilterAssetLocation};25use xcm_executor::traits::{Convert as ConvertXcm, JustTry, FilterAssetLocation};26use pallet_foreing_assets::{26use pallet_foreing_assets::{27 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, NativeCurrency, FreeForAll, TryAsForeing,27 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, NativeCurrency, FreeForAll, TryAsForeing,28 ForeignAssetId,28 ForeignAssetId, CurrencyId,29};29};30use sp_std::{borrow::Borrow, marker::PhantomData};30use sp_std::{borrow::Borrow, marker::PhantomData};31use crate::{Runtime, Balances, ParachainInfo, PolkadotXcm, ForeingAssets};31use crate::{Runtime, Balances, ParachainInfo, PolkadotXcm, ForeingAssets};159 (),159 (),160>;160>;161162pub struct CurrencyIdConvert;163impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {164 fn convert(id: AssetIds) -> Option<MultiLocation> {165 match id {166 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(167 1,168 X1(Parachain(ParachainInfo::get().into())),169 )),170 AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),171 AssetIds::ForeignAssetId(foreign_asset_id) => {172 XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)173 }174 }175 }176}177178impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {179 fn convert(location: MultiLocation) -> Option<CurrencyId> {180 if location == MultiLocation::here()181 || location == MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())))182 {183 return Some(AssetIds::NativeAssetId(NativeCurrency::Here));184 }185186 if location == MultiLocation::parent() {187 return Some(AssetIds::NativeAssetId(NativeCurrency::Parent));188 }189190 if let Some(currency_id) =191 XcmForeignAssetIdMapping::<Runtime>::get_currency_id(location.clone())192 {193 return Some(currency_id);194 }195196 None197 }198}161199runtime/common/config/xcm/mod.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::{traits::Everything, weights::Weight, parameter_types};17use frame_support::{18 traits::{Everything, Get},19 weights::Weight,20 parameter_types,21};18use frame_system::EnsureRoot;22use frame_system::EnsureRoot;19use pallet_xcm::XcmPassthrough;23use pallet_xcm::XcmPassthrough;20use polkadot_parachain::primitives::Sibling;24use polkadot_parachain::primitives::Sibling;21use xcm::v1::{Junction::*, MultiLocation, NetworkId};25use xcm::v1::{Junction::*, MultiLocation, NetworkId};22use xcm::latest::{Instruction, Xcm};26use xcm::latest::prelude::*;23use xcm_builder::{27use xcm_builder::{24 AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, ParentAsSuperuser,28 AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, ParentAsSuperuser,25 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,29 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,26 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,30 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,27};31};28use xcm_executor::{Config, XcmExecutor, traits::ShouldExecute};32use xcm_executor::{Config, XcmExecutor, traits::ShouldExecute};29use sp_std::marker::PhantomData;33use sp_std::{marker::PhantomData, vec::Vec};30use crate::{34use crate::{31 Runtime, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,35 Runtime, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,32 xcm_config::Barrier,36 xcm_config::Barrier,35use up_common::types::AccountId;39use up_common::types::AccountId;364037#[cfg(feature = "foreign-assets")]41#[cfg(feature = "foreign-assets")]38mod foreignassets;42pub mod foreignassets;394340#[cfg(not(feature = "foreign-assets"))]44#[cfg(not(feature = "foreign-assets"))]41mod nativeassets;45pub mod nativeassets;424643#[cfg(feature = "foreign-assets")]47#[cfg(feature = "foreign-assets")]44use foreignassets as xcm_assets;48pub use foreignassets as xcm_assets;454946#[cfg(not(feature = "foreign-assets"))]50#[cfg(not(feature = "foreign-assets"))]47use nativeassets as xcm_assets;51pub use nativeassets as xcm_assets;485249use xcm_assets::{AssetTransactors, IsReserve, Trader};53use xcm_assets::{AssetTransactors, IsReserve, Trader};505453 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;57 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;54 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();58 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();55 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();59 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();60 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));6162 // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.63 pub UnitWeightCost: Weight = 1_000_000;64 pub const MaxInstructions: u32 = 100;56}65}576658/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used67/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used103 XcmPassthrough<Origin>,112 XcmPassthrough<Origin>,104);113);105106parameter_types! {107 // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.108 pub UnitWeightCost: Weight = 1_000_000;109 pub const MaxInstructions: u32 = 100;110}111114112pub trait TryPass {115pub trait TryPass {113 fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()>;116 fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()>;169 }172 }170}173}174175// Allow xcm exchange only with locations in list176pub struct DenyExchangeWithUnknownLocation<T>(PhantomData<T>);177impl<T: Get<Vec<MultiLocation>>> TryPass for DenyExchangeWithUnknownLocation<T> {178 fn try_pass<Call>(origin: &MultiLocation, message: &mut Xcm<Call>) -> Result<(), ()> {179 let allowed_locations = T::get();180181 // Check if deposit or transfer belongs to allowed parachains182 let mut allowed = allowed_locations.contains(origin);183184 message.0.iter().for_each(|inst| match inst {185 DepositReserveAsset { dest: dst, .. } => {186 allowed |= allowed_locations.contains(dst);187 }188 TransferReserveAsset { dest: dst, .. } => {189 allowed |= allowed_locations.contains(dst);190 }191 _ => {}192 });193194 if allowed {195 return Ok(());196 }197198 log::warn!(199 target: "xcm::barrier",200 "Unexpected deposit or transfer location"201 );202 // Deny203 Err(())204 }205}206207pub type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;171208172pub struct XcmConfig<T>(PhantomData<T>);209pub struct XcmConfig<T>(PhantomData<T>);173impl<T> Config for XcmConfig<T>210impl<T> Config for XcmConfig<T>183 type IsTeleporter = (); // Teleportation is disabled220 type IsTeleporter = (); // Teleportation is disabled184 type LocationInverter = LocationInverter<Ancestry>;221 type LocationInverter = LocationInverter<Ancestry>;185 type Barrier = Barrier;222 type Barrier = Barrier;186 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;223 type Weigher = Weigher;187 type Trader = Trader<T>;224 type Trader = Trader<T>;188 type ResponseHandler = (); // Don't handle responses for now.225 type ResponseHandler = (); // Don't handle responses for now.189 type SubscriptionService = PolkadotXcm;226 type SubscriptionService = PolkadotXcm;runtime/common/config/xcm/nativeassets.rsdiffbeforeafterboth18 traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},18 traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},19 weights::{Weight, WeightToFeePolynomial},19 weights::{Weight, WeightToFeePolynomial},20};20};21use sp_runtime::traits::{CheckedConversion, Zero};21use sp_runtime::traits::{CheckedConversion, Zero, Convert};22use xcm::v1::{Junction::*, MultiLocation, Junctions::*};22use xcm::v1::{Junction::*, MultiLocation, Junctions::*};23use xcm::latest::{23use xcm::latest::{24 AssetId::{Concrete},24 AssetId::{Concrete},30 Assets,30 Assets,31 traits::{MatchesFungible, WeightTrader},31 traits::{MatchesFungible, WeightTrader},32};32};33use pallet_foreing_assets::{AssetIds, NativeCurrency};33use sp_std::marker::PhantomData;34use sp_std::marker::PhantomData;34use crate::{Balances, ParachainInfo};35use crate::{Balances, ParachainInfo};35use super::{LocationToAccountId, RelayLocation};36use super::{LocationToAccountId, RelayLocation};128 (),129 (),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}130144runtime/opal/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, weights::Weight},19 pallet_prelude::Get,20 traits::{Contains, Everything},19 traits::Everything,21};20};22use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};23use sp_runtime::traits::{AccountIdConversion, Convert};24use sp_std::{vec, vec::Vec};25use xcm::{21use xcm::{26 latest::Xcm,22 latest::Xcm,27 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},23 v1::{BodyId, Junction::*, Junctions::*, MultiLocation},28};24};29use xcm_builder::{25use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit};30 AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter,31 TakeWeightCredit,32};33use xcm_executor::{XcmExecutor, traits::ShouldExecute};26use xcm_executor::traits::ShouldExecute;342735use up_common::types::{AccountId, Balance};36use crate::{28use crate::runtime_common::config::xcm::{DenyThenTry, DenyTransact};37 Call, Event, ParachainInfo, Runtime,38 runtime_common::config::{39 substrate::{TreasuryModuleId, MaxLocks, MaxReserves},40 pallets::TreasuryAccountId,41 xcm::*,42 },43};4445use pallet_foreing_assets::{46 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,47};4849// Signed version of balance50pub type Amount = i128;512952match_types! {30match_types! {53 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {31 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {84 ),62 ),85>;63>;8687impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {88 fn convert(location: MultiLocation) -> Option<CurrencyId> {89 if location == MultiLocation::here()90 || location == MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())))91 {92 return Some(AssetIds::NativeAssetId(NativeCurrency::Here));93 }9495 if location == MultiLocation::parent() {96 return Some(AssetIds::NativeAssetId(NativeCurrency::Parent));97 }9899 if let Some(currency_id) =100 XcmForeignAssetIdMapping::<Runtime>::get_currency_id(location.clone())101 {102 return Some(currency_id);103 }104105 None106 }107}108109impl orml_tokens::Config for Runtime {110 type Event = Event;111 type Balance = Balance;112 type Amount = Amount;113 type CurrencyId = CurrencyId;114 type WeightInfo = ();115 type ExistentialDeposits = ExistentialDeposits;116 type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;117 type MaxLocks = MaxLocks;118 type MaxReserves = MaxReserves;119 // TODO: Add all module accounts120 type DustRemovalWhitelist = DustRemovalWhitelist;121 /// The id type for named reserves.122 type ReserveIdentifier = ();123 type OnNewTokenAccount = ();124 type OnKilledTokenAccount = ();125}126127impl orml_xtokens::Config for Runtime {128 type Event = Event;129 type Balance = Balance;130 type CurrencyId = CurrencyId;131 type CurrencyIdConvert = CurrencyIdConvert;132 type AccountIdToMultiLocation = AccountIdToMultiLocation;133 type SelfLocation = SelfLocation;134 type XcmExecutor = XcmExecutor<XcmConfig<Self>>;135 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;136 type BaseXcmWeight = BaseXcmWeight;137 type LocationInverter = LocationInverter<Ancestry>;138 type MaxAssetsForTransfer = MaxAssetsForTransfer;139 type MinXcmFee = ParachainMinFee;140 type MultiLocationsFilter = Everything;141 type ReserveProvider = AbsoluteReserveProvider;142}143144parameter_type_with_key! {145 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {146 match currency_id {147 CurrencyId::NativeAssetId(symbol) => match symbol {148 NativeCurrency::Here => 0,149 NativeCurrency::Parent=> 0,150 },151 _ => 100_000152 }153 };154}155156pub struct DustRemovalWhitelist;157impl Contains<AccountId> for DustRemovalWhitelist {158 fn contains(a: &AccountId) -> bool {159 get_all_module_accounts().contains(a)160 }161}162163pub struct CurrencyIdConvert;164impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {165 fn convert(id: AssetIds) -> Option<MultiLocation> {166 match id {167 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(168 1,169 X1(Parachain(ParachainInfo::get().into())),170 )),171 AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),172 AssetIds::ForeignAssetId(foreign_asset_id) => {173 XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)174 }175 }176 }177}178179parameter_types! {180 pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this181 pub const MaxAssetsForTransfer: usize = 2;182183 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();184 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));185}186187parameter_type_with_key! {188 pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {189 Some(100_000_000_000)190 };191}192193pub fn get_all_module_accounts() -> Vec<AccountId> {194 vec![TreasuryModuleId::get().into_account_truncating()]195}196pub struct AccountIdToMultiLocation;197impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {198 fn convert(account: AccountId) -> MultiLocation {199 X1(AccountId32 {200 network: NetworkId::Any,201 id: account.into(),202 })203 .into()204 }205}20664runtime/quartz/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 QuartzAllowedLocations: 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<QuartzAllowedLocations>,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}22690runtime/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