git.delta.rocks / unique-network / refs/commits / 25b276d53c18

difftreelog

source

runtime/opal/src/xcm_config.rs6.1 KiBsourcehistory
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	{match_types, parameter_types, weights::Weight},19	pallet_prelude::Get,20	traits::{Contains, Everything},21};22use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};23use sp_runtime::traits::{AccountIdConversion, Convert};24use sp_std::{vec, vec::Vec};25use xcm::{26	latest::Xcm,27	v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},28};29use xcm_builder::{30	AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter,31	TakeWeightCredit,32};33use xcm_executor::{XcmExecutor, traits::ShouldExecute};3435use up_common::types::{AccountId, Balance};36use crate::{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;5152match_types! {53	pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {54		MultiLocation { parents: 1, interior: Here } |55		MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }56	};57}5859/// Execution barrier that just takes `max_weight` from `weight_credit`.60///61/// Useful to allow XCM execution by local chain users via extrinsics.62/// E.g. `pallet_xcm::reserve_asset_transfer` to transfer a reserve asset63/// out of the local chain to another one.64pub struct AllowAllDebug;65impl ShouldExecute for AllowAllDebug {66	fn should_execute<Call>(67		_origin: &MultiLocation,68		_message: &mut Xcm<Call>,69		_max_weight: Weight,70		_weight_credit: &mut Weight,71	) -> Result<(), ()> {72		Ok(())73	}74}7576pub type Barrier = DenyThenTry<77	DenyTransact,78	(79		TakeWeightCredit,80		AllowTopLevelPaidExecutionFrom<Everything>,81		AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,82		// ^^^ Parent & its unit plurality gets free execution83		AllowAllDebug,84	),85>;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}