1234567891011121314151617use cumulus_pallet_xcm;18use frame_support::{19 {match_types, parameter_types, weights::Weight},20 pallet_prelude::Get,21 traits::{Contains, Everything, fungibles},22};23use frame_system::EnsureRoot;24use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};25use pallet_xcm::XcmPassthrough;26use polkadot_parachain::primitives::Sibling;27use sp_runtime::traits::{AccountIdConversion, CheckedConversion, Convert, Zero};28use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};29use xcm::{30 latest::{MultiAsset, Xcm},31 prelude::{Concrete, Fungible as XcmFungible},32 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},33};34use xcm_builder::{35 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin,36 FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentAsSuperuser, ParentIsPreset,37 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,38 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,39 ConvertedConcreteAssetId,40};41use xcm_executor::{42 {Config, XcmExecutor},43 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible, ShouldExecute},44};4546use up_common::{47 constants::{MAXIMUM_BLOCK_WEIGHT, UNIQUE},48 types::{AccountId, Balance},49};5051use crate::{52 Balances, Call, DmpQueue, Event, ForeingAssets, Origin, ParachainInfo, ParachainSystem,53 PolkadotXcm, Runtime, XcmpQueue,54};55use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};56use crate::runtime_common::config::pallets::TreasuryAccountId;57use crate::runtime_common::config::xcm::*;58use crate::*;5960use pallet_foreing_assets::{61 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,62 TryAsForeing, ForeignAssetId,63};646566pub type Amount = i128;6768parameter_types! {69 pub const RelayLocation: MultiLocation = MultiLocation::parent();70 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;71 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();72 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();73 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));74}7576777879pub type XcmOriginToTransactDispatchOrigin = (80 81 82 83 SovereignSignedViaLocation<LocationToAccountId, Origin>,84 85 86 RelayChainAsNative<RelayOrigin, Origin>,87 88 89 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,90 91 92 ParentAsSuperuser<Origin>,93 94 95 SignedAccountId32AsNative<RelayNetwork, Origin>,96 97 XcmPassthrough<Origin>,98);99100parameter_types! {101 102 pub UnitWeightCost: Weight = 1_000_000;103 104 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);105 pub const MaxInstructions: u32 = 100;106 pub const MaxAuthorities: u32 = 100_000;107}108109match_types! {110 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {111 MultiLocation { parents: 1, interior: Here } |112 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }113 };114}115116117118119120121pub struct AllowAllDebug;122impl ShouldExecute for AllowAllDebug {123 fn should_execute<Call>(124 _origin: &MultiLocation,125 _message: &mut Xcm<Call>,126 max_weight: Weight,127 weight_credit: &mut Weight,128 ) -> Result<(), ()> {129 Ok(())130 }131}132133pub type Barrier = DenyThenTry<134 DenyTransact,135 (136 TakeWeightCredit,137 AllowTopLevelPaidExecutionFrom<Everything>,138 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,139 140 AllowAllDebug,141 )142>;143144pub struct AllAsset;145impl FilterAssetLocation for AllAsset {146 fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {147 true148 }149}150151pub struct CurrencyIdConvert;152impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {153 fn convert(id: AssetIds) -> Option<MultiLocation> {154 match id {155 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(156 1,157 X1(Parachain(ParachainInfo::get().into())),158 )),159 AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),160 AssetIds::ForeignAssetId(foreign_asset_id) => {161 XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)162 }163 }164 }165}166impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {167 fn convert(location: MultiLocation) -> Option<CurrencyId> {168 if location == MultiLocation::here()169 || location == MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())))170 {171 return Some(AssetIds::NativeAssetId(NativeCurrency::Here));172 }173174 if location == MultiLocation::parent() {175 return Some(AssetIds::NativeAssetId(NativeCurrency::Parent));176 }177178 if let Some(currency_id) =179 XcmForeignAssetIdMapping::<Runtime>::get_currency_id(location.clone())180 {181 return Some(currency_id);182 }183184 None185 }186}187188pub fn get_all_module_accounts() -> Vec<AccountId> {189 vec![TreasuryModuleId::get().into_account_truncating()]190}191192pub struct DustRemovalWhitelist;193impl Contains<AccountId> for DustRemovalWhitelist {194 fn contains(a: &AccountId) -> bool {195 get_all_module_accounts().contains(a)196 }197}198199parameter_type_with_key! {200 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {201 match currency_id {202 CurrencyId::NativeAssetId(symbol) => match symbol {203 NativeCurrency::Here => 0,204 NativeCurrency::Parent=> 0,205 },206 _ => 100_000207 }208 };209}210211impl orml_tokens::Config for Runtime {212 type Event = Event;213 type Balance = Balance;214 type Amount = Amount;215 type CurrencyId = CurrencyId;216 type WeightInfo = ();217 type ExistentialDeposits = ExistentialDeposits;218 type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;219 type MaxLocks = MaxLocks;220 type MaxReserves = MaxReserves;221 222 type DustRemovalWhitelist = DustRemovalWhitelist;223 224 type ReserveIdentifier = ();225 type OnNewTokenAccount = ();226 type OnKilledTokenAccount = ();227}228229parameter_types! {230 pub const BaseXcmWeight: Weight = 100_000_000; 231 pub const MaxAssetsForTransfer: usize = 2;232}233234parameter_type_with_key! {235 pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {236 Some(100_000_000_000)237 };238}239240pub struct AccountIdToMultiLocation;241impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {242 fn convert(account: AccountId) -> MultiLocation {243 X1(AccountId32 {244 network: NetworkId::Any,245 id: account.into(),246 })247 .into()248 }249}250251impl orml_xtokens::Config for Runtime {252 type Event = Event;253 type Balance = Balance;254 type CurrencyId = CurrencyId;255 type CurrencyIdConvert = CurrencyIdConvert;256 type AccountIdToMultiLocation = AccountIdToMultiLocation;257 type SelfLocation = SelfLocation;258 type XcmExecutor = XcmExecutor<XcmConfig<Self>>;259 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;260 type BaseXcmWeight = BaseXcmWeight;261 type LocationInverter = LocationInverter<Ancestry>;262 type MaxAssetsForTransfer = MaxAssetsForTransfer;263 type MinXcmFee = ParachainMinFee;264 type MultiLocationsFilter = Everything;265 type ReserveProvider = AbsoluteReserveProvider;266}