use super::{
parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, ParaId, Runtime,
RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmPallet,
};
use frame_support::{
match_types, parameter_types,
traits::{Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use rococo_runtime_constants::currency::CENTS;
use runtime_common::{
xcm_sender::{ChildParachainRouter, ExponentialPrice},
ToAuthor,
};
use sp_core::ConstU32;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, DescribeBodyTerminal,
DescribeFamily, FixedWeightBounds, HashedDescription, IsChildSystemParachain, IsConcrete,
MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin,
WithUniqueTopic,
};
use xcm_executor::XcmExecutor;
parameter_types! {
pub const TokenLocation: MultiLocation = Here.into_location();
pub const ThisNetwork: NetworkId = NetworkId::Rococo;
pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into();
pub CheckAccount: AccountId = XcmPallet::check_account();
pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
}
pub type LocationConverter = (
ChildParachainConvertsVia<ParaId, AccountId>,
AccountId32Aliases<ThisNetwork, AccountId>,
HashedDescription<AccountId, DescribeFamily<DescribeBodyTerminal>>,
);
pub type LocalAssetTransactor = XcmCurrencyAdapter<
Balances,
IsConcrete<TokenLocation>,
LocationConverter,
AccountId,
LocalCheckAccount,
>;
type LocalOriginConverter = (
SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
);
parameter_types! {
pub const BaseXcmWeight: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
pub FeeAssetId: AssetId = Concrete(TokenLocation::get());
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
}
pub type XcmRouter = WithUniqueTopic<(
ChildParachainRouter<
Runtime,
XcmPallet,
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>,
>,
)>;
parameter_types! {
pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub const Rockmine: MultiLocation = Parachain(1000).into_location();
pub const Contracts: MultiLocation = Parachain(1002).into_location();
pub const Encointer: MultiLocation = Parachain(1003).into_location();
pub const Tick: MultiLocation = Parachain(100).into_location();
pub const Trick: MultiLocation = Parachain(110).into_location();
pub const Track: MultiLocation = Parachain(120).into_location();
pub const RocForTick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Tick::get());
pub const RocForTrick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Trick::get());
pub const RocForTrack: (MultiAssetFilter, MultiLocation) = (Roc::get(), Track::get());
pub const RocForRockmine: (MultiAssetFilter, MultiLocation) = (Roc::get(), Rockmine::get());
pub const RocForContracts: (MultiAssetFilter, MultiLocation) = (Roc::get(), Contracts::get());
pub const RocForEncointer: (MultiAssetFilter, MultiLocation) = (Roc::get(), Encointer::get());
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
}
pub type TrustedTeleporters = (
xcm_builder::Case<RocForTick>,
xcm_builder::Case<RocForTrick>,
xcm_builder::Case<RocForTrack>,
xcm_builder::Case<RocForRockmine>,
xcm_builder::Case<RocForContracts>,
xcm_builder::Case<RocForEncointer>,
);
match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};
}
pub type Barrier = TrailingSetTopicAsId<(
TakeWeightCredit,
AllowKnownQueryResponses<XcmPallet>,
WithComputedOrigin<
(
AllowTopLevelPaidExecutionFrom<Everything>,
AllowExplicitUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>,
AllowSubscriptionsFrom<OnlyParachains>,
),
UniversalLocation,
ConstU32<8>,
>,
)>;
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
type IsTeleporter = TrustedTeleporters;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = WeightInfoBounds<
crate::weights::xcm::RococoXcmWeight<RuntimeCall>,
RuntimeCall,
MaxInstructions,
>;
type Trader =
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
}
#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parachain(1000).into());
}
pub type LocalOriginToLocation = (
SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
);
impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Everything;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = IsConcrete<TokenLocation>;
type TrustedLockers = ();
type SovereignAccountOf = LocationConverter;
type MaxLockers = ConstU32<8>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}