use super::{
parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, FellowshipAdmin,
GeneralAdmin, ParaId, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin,
TransactionByteFee, Treasury, WeightToFee, XcmPallet,
};
use crate::governance::pallet_custom_origins::Treasurer;
use frame_support::{
parameter_types,
traits::{Contains, Equals, Everything, Nothing},
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use polkadot_runtime_common::{
xcm_sender::{ChildParachainRouter, ExponentialPrice},
ToAuthor,
};
use sp_core::ConstU32;
use westend_runtime_constants::{
currency::CENTS, system_parachain::*, xcm::body::FELLOWSHIP_ADMIN_INDEX,
};
use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
use xcm_builder::{
AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
ChildParachainAsNative, ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily,
FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsChildSystemParachain,
IsConcrete, MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
XcmFeeManagerFromComponents,
};
use xcm_executor::XcmExecutor;
parameter_types! {
pub const TokenLocation: Location = Here.into_location();
pub const RootLocation: Location = Location::here();
pub const ThisNetwork: NetworkId = ByGenesis(WESTEND_GENESIS_HASH);
pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetwork::get())].into();
pub CheckAccount: AccountId = XcmPallet::check_account();
pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
pub TreasuryAccount: AccountId = Treasury::account_id();
pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
}
pub type LocationConverter = (
ChildParachainConvertsVia<ParaId, AccountId>,
AccountId32Aliases<ThisNetwork, AccountId>,
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
);
pub type LocalAssetTransactor = FungibleAdapter<
Balances,
IsConcrete<TokenLocation>,
LocationConverter,
AccountId,
LocalCheckAccount,
>;
type LocalOriginConverter = (
SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
XcmPassthrough<RuntimeOrigin>,
);
pub type PriceForChildParachainDelivery =
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
pub type XcmRouter = WithUniqueTopic<
ChildParachainRouter<Runtime, XcmPallet, PriceForChildParachainDelivery>,
>;
parameter_types! {
pub AssetHub: Location = Parachain(ASSET_HUB_ID).into_location();
pub Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
pub People: Location = Parachain(PEOPLE_ID).into_location();
pub Broker: Location = Parachain(BROKER_ID).into_location();
pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
pub WndForEncointer: (AssetFilter, Location) = (Wnd::get(), Encointer::get());
pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
pub MaxInstructions: u32 = 100;
pub MaxAssetsIntoHolding: u32 = 64;
}
pub type TrustedTeleporters = (
xcm_builder::Case<WndForAssetHub>,
xcm_builder::Case<WndForCollectives>,
xcm_builder::Case<WndForBridgeHub>,
xcm_builder::Case<WndForEncointer>,
xcm_builder::Case<WndForPeople>,
xcm_builder::Case<WndForBroker>,
);
pub struct OnlyParachains;
impl Contains<Location> for OnlyParachains {
fn contains(location: &Location) -> bool {
matches!(location.unpack(), (0, [Parachain(_)]))
}
}
pub struct Fellows;
impl Contains<Location> for Fellows {
fn contains(location: &Location) -> bool {
matches!(
location.unpack(),
(0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
)
}
}
pub struct LocalPlurality;
impl Contains<Location> for LocalPlurality {
fn contains(loc: &Location) -> bool {
matches!(loc.unpack(), (0, [Plurality { .. }]))
}
}
pub type Barrier = TrailingSetTopicAsId<(
TakeWeightCredit,
AllowKnownQueryResponses<XcmPallet>,
WithComputedOrigin<
(
AllowTopLevelPaidExecutionFrom<Everything>,
AllowSubscriptionsFrom<OnlyParachains>,
AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain<ParaId>, Fellows)>,
),
UniversalLocation,
ConstU32<8>,
>,
)>;
pub type WaivedLocations = (SystemParachains, Equals<RootLocation>, LocalPlurality);
pub type Aliasers = AliasChildLocation;
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::WestendXcmWeight<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 = XcmFeeManagerFromComponents<
WaivedLocations,
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Aliasers;
type TransactionalProcessor = FrameTransactionalProcessor;
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = XcmPallet;
}
parameter_types! {
pub const GeneralAdminBodyId: BodyId = BodyId::Administration;
pub const StakingAdminBodyId: BodyId = BodyId::Defense;
pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
pub const TreasurerBodyId: BodyId = BodyId::Treasury;
}
pub type GeneralAdminToPlurality =
OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
pub type LocalOriginToLocation = (
GeneralAdminToPlurality,
SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
);
pub type StakingAdminToPlurality =
OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
pub type FellowshipAdminToPlurality =
OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
pub type LocalPalletOriginToLocation = (
GeneralAdminToPlurality,
StakingAdminToPlurality,
FellowshipAdminToPlurality,
TreasurerToPlurality,
);
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 = WeightInfoBounds<
crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
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>;
type AdminOrigin = EnsureRoot<AccountId>;
}