diff --git a/polkadot/xcm/pallet-xcm/Cargo.toml b/polkadot/xcm/pallet-xcm/Cargo.toml index ed4b441d7c33..420fe2180bf6 100644 --- a/polkadot/xcm/pallet-xcm/Cargo.toml +++ b/polkadot/xcm/pallet-xcm/Cargo.toml @@ -55,6 +55,7 @@ std = [ "xcm-executor/std", "xcm-runtime-apis/std", "xcm/std", + "xcm-builder/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/xcm/pallet-xcm/src/lib.rs b/polkadot/xcm/pallet-xcm/src/lib.rs index 6451901279b1..6120f9f1f17c 100644 --- a/polkadot/xcm/pallet-xcm/src/lib.rs +++ b/polkadot/xcm/pallet-xcm/src/lib.rs @@ -210,34 +210,40 @@ pub mod pallet { pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; - #[pallet::config] + #[pallet::config(with_default)] /// The module configuration trait. pub trait Config: frame_system::Config { - /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// A lockable currency. // TODO: We should really use a trait which can handle multiple currencies. + #[pallet::no_default] + /// A lockable currency. type Currency: LockableCurrency>; /// The `Asset` matcher for `Currency`. + #[pallet::no_default_bounds] type CurrencyMatcher: MatchesFungible>; + // TODO: Would love to add a default for this, but I need access to `RuntimeOrigin` + // from the derive_impl + #[pallet::no_default_bounds] /// Required origin for sending XCM messages. If successful, it resolves to `Location` /// which exists as an interior location within this chain's XCM context. type SendXcmOrigin: EnsureOrigin<::RuntimeOrigin, Success = Location>; + #[pallet::no_default] /// The type used to actually dispatch an XCM to its destination. type XcmRouter: SendXcm; + #[pallet::no_default] /// Required origin for executing XCM messages, including the teleport functionality. If /// successful, then it resolves to `Location` which exists as an interior location /// within this chain's XCM context. type ExecuteXcmOrigin: EnsureOrigin<::RuntimeOrigin, Success = Location>; + #[pallet::no_default_bounds] /// Our XCM filter which messages to be executed using `XcmExecutor` must pass. type XcmExecuteFilter: Contains<(Location, Xcm<::RuntimeCall>)>; + #[pallet::no_default] /// Something to execute an XCM message. type XcmExecutor: ExecuteXcm<::RuntimeCall> + XcmAssetTransfers; @@ -248,29 +254,21 @@ pub mod pallet { /// must pass. type XcmReserveTransferFilter: Contains<(Location, Vec)>; + #[pallet::no_default] /// Means of measuring the weight consumed by an XCM message locally. type Weigher: WeightBounds<::RuntimeCall>; + #[pallet::no_default] /// This chain's Universal Location. type UniversalLocation: Get; - /// The runtime `Origin` type. - type RuntimeOrigin: From + From<::RuntimeOrigin>; - - /// The runtime `Call` type. - type RuntimeCall: Parameter - + GetDispatchInfo - + Dispatchable< - RuntimeOrigin = ::RuntimeOrigin, - PostInfo = PostDispatchInfo, - >; - const VERSION_DISCOVERY_QUEUE_SIZE: u32; - /// The latest supported version that we advertise. Generally just set it to - /// `pallet_xcm::CurrentXcmVersion`. + /// The latest supported version that we advertise. + /// Its default is `pallet_xcm::CurrentXcmVersion`. type AdvertisedXcmVersion: Get; + #[pallet::no_default] /// The origin that is allowed to call privileged operations on the XCM pallet type AdminOrigin: EnsureOrigin<::RuntimeOrigin>; @@ -278,6 +276,7 @@ pub mod pallet { /// lock. type TrustedLockers: ContainsPair; + #[pallet::no_default] /// How to get an `AccountId` value from a `Location`, useful for handling asset locks. type SovereignAccountOf: ConvertLocation; @@ -292,6 +291,92 @@ pub mod pallet { /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; + + /// The overarching event type. + #[pallet::no_default_bounds] + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + /// The runtime `Origin` type. + #[pallet::no_default_bounds] + type RuntimeOrigin: From + From<::RuntimeOrigin>; + + /// The runtime `Call` type. + #[pallet::no_default_bounds] + type RuntimeCall: Parameter + + GetDispatchInfo + + Dispatchable< + RuntimeOrigin = ::RuntimeOrigin, + PostInfo = PostDispatchInfo, + >; + } + + /// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`] + pub mod config_preludes { + use super::*; + use frame_support::{ + derive_impl, register_default_impl, + traits::{Everything, ConstU32, Equals}, + }; + use xcm_builder::{ + IsConcrete, + LocationWithAssetFilters, + }; + + pub struct TestDefaultConfig(core::marker::PhantomData<(RuntimeOrigin, AccountId)>); + + #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)] + impl frame_system::DefaultConfig for TestDefaultConfig {} + + // TODO: These make sense for an actual runtime, not for a test one maybe + parameter_types! { + /// We hold a native token locally, in `Here` + pub TokenLocation: Location = Here.into_location(); + /// We don't allow any assets to be teleported + pub AllowedAssetsToTeleport: Vec = vec![]; + /// We only allow reserve asset depositing the native token + pub AllowedAssetsToReserveTransfer: Vec = vec![ + Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) }), + ]; + pub AnyNetwork: Option = None; + } + + #[register_default_impl(TestDefaultConfig)] + impl DefaultConfig for TestDefaultConfig { + // This default config only handles the native token + type CurrencyMatcher = IsConcrete; + + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin>; + + // We don't filter any specific message + type XcmExecuteFilter = Everything; + + type XcmTeleportFilter = LocationWithAssetFilters< + Equals, + AllowedAssetsToTeleport, + >; + type XcmReserveTransferFilter = LocationWithAssetFilters< + Equals, + AllowedAssetsToReserveTransfer, + >; + + // Use latest version by default + type AdvertisedXcmVersion = CurrentXcmVersion; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + + type TrustedLockers = (); + type MaxLockers = ConstU32<0>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + + type WeightInfo = TestWeightInfo; + + #[inject_runtime_type] + type RuntimeEvent = (); + #[inject_runtime_type] + type RuntimeOrigin = (); + #[inject_runtime_type] + type RuntimeCall = (); + } } impl ExecuteControllerWeightInfo for Pallet { diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index 8d0476b0e70d..c40a6a134cfd 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -532,30 +532,18 @@ impl Contains<(Location, Vec)> for XcmTeleportFiltered { } } +#[derive_impl(pallet_xcm::config_preludes::TestDefaultConfig as pallet_xcm::DefaultConfig)] impl pallet_xcm::Config for Test { - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; type XcmRouter = XcmRouter; type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmExecuteFilter = Everything; type XcmExecutor = XcmExecutor; type XcmTeleportFilter = EverythingBut; type XcmReserveTransferFilter = Everything; type Weigher = FixedWeightBounds; type UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = AdvertisedXcmVersion; type AdminOrigin = EnsureRoot; - type TrustedLockers = (); type SovereignAccountOf = AccountId32Aliases<(), AccountId32>; type Currency = Balances; - type CurrencyMatcher = IsConcrete; - type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; - type RemoteLockConsumerIdentifier = (); - type WeightInfo = TestWeightInfo; } impl origin::Config for Test {}