diff --git a/Cargo.lock b/Cargo.lock index 765932da..c1cc5ae8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1900,7 +1900,7 @@ dependencies = [ [[package]] name = "dev-runtime" -version = "3.1.0" +version = "3.2.0" dependencies = [ "frame-benchmarking", "frame-executive", @@ -3016,7 +3016,7 @@ dependencies = [ [[package]] name = "generic-runtime" -version = "3.1.0" +version = "3.2.0" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -3888,9 +3888,6 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin 0.9.8", -] [[package]] name = "lazycell" @@ -4574,7 +4571,6 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "hex-literal 0.3.4", - "lazy_static", "pallet-assets", "pallet-balances", "pallet-collective", @@ -4590,6 +4586,7 @@ dependencies = [ "pallet-robonomics-lighthouse", "pallet-robonomics-rws", "pallet-scheduler", + "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", @@ -4597,6 +4594,7 @@ dependencies = [ "pallet-utility", "pallet-vesting", "pallet-xcm", + "pallet-xcm-info", "parachain-info", "parity-scale-codec", "polkadot-parachain", @@ -5847,7 +5845,7 @@ dependencies = [ [[package]] name = "pallet-xcm" -version = "3.1.0" +version = "3.2.0" dependencies = [ "bounded-collections", "frame-benchmarking", @@ -5869,6 +5867,19 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "pallet-xcm-info" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", + "xcm", +] + [[package]] name = "parachain-info" version = "0.1.0" @@ -7867,7 +7878,7 @@ dependencies = [ [[package]] name = "robonomics" -version = "3.1.0" +version = "3.2.0" dependencies = [ "color-eyre", "robonomics-node", @@ -7876,7 +7887,7 @@ dependencies = [ [[package]] name = "robonomics-node" -version = "3.1.0" +version = "3.2.0" dependencies = [ "clap", "color-print", @@ -7904,7 +7915,7 @@ dependencies = [ [[package]] name = "robonomics-primitives" -version = "3.1.0" +version = "3.2.0" dependencies = [ "hex-literal 0.3.4", "sp-core", @@ -7913,7 +7924,7 @@ dependencies = [ [[package]] name = "robonomics-rpc-core" -version = "3.1.0" +version = "3.2.0" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc", @@ -7929,7 +7940,7 @@ dependencies = [ [[package]] name = "robonomics-service" -version = "3.1.0" +version = "3.2.0" dependencies = [ "cumulus-client-cli", "cumulus-client-consensus-common", diff --git a/Cargo.toml b/Cargo.toml index 3f9053bd..053fb2a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ homepage.workspace = true repository.workspace = true [workspace.package] -version = "3.1.0" +version = "3.2.0" edition = "2021" authors = ["Airalab "] license = "Apache-2.0" @@ -51,6 +51,7 @@ members = [ "frame/liability", "frame/lighthouse", "frame/digital-twin", + "frame/xcm-info", "primitives", "runtime/dev", "runtime/main", @@ -70,9 +71,6 @@ scale-info = { version = "2.5.0", default-features = false, features = [ "derive", ] } smallvec = { version = "1.11", default-features = false } -lazy_static = { version = "1.4", default-features = false, features = [ - "spin_no_std", -] } log = { version = "0.4.19", default-features = false } # (native) diff --git a/frame/xcm-info/Cargo.toml b/frame/xcm-info/Cargo.toml new file mode 100644 index 00000000..98adfafb --- /dev/null +++ b/frame/xcm-info/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "pallet-xcm-info" +description = "XCM setup & information pallet" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +frame-support = { workspace = true } +frame-system = { workspace = true } +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } +xcm = { workspace = true } + +[features] +default = ["std"] +std = [ + "frame-support/std", + "frame-system/std", + "parity-scale-codec/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", + "xcm/std", +] diff --git a/frame/xcm-info/src/lib.rs b/frame/xcm-info/src/lib.rs new file mode 100644 index 00000000..a3a406d3 --- /dev/null +++ b/frame/xcm-info/src/lib.rs @@ -0,0 +1,109 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2018-2024 Robonomics Network +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/////////////////////////////////////////////////////////////////////////////// +//! On-chain XCM setup & information. +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::pallet_prelude::*; + use frame_system::{ensure_root, pallet_prelude::*}; + use sp_runtime::traits::MaybeEquivalence; + use xcm::latest::prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + /// AssetId type for asset<>location linkage setup. + type AssetId: Parameter + Copy + Default + MaxEncodedLen; + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::error] + pub enum Error {} + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// Updated Relay XCM identifier. + RelayNetworkChanged(NetworkId), + /// Added new asset XCM location. + AssetLinkAdded(T::AssetId, MultiLocation), + } + + #[pallet::pallet] + pub struct Pallet(PhantomData); + + /// Relay network identifier. + #[pallet::storage] + #[pallet::getter(fn relay_network)] + pub(super) type RelayNetwork = StorageValue<_, NetworkId>; + + /// AssetId to location mapping. + #[pallet::storage] + #[pallet::getter(fn location_of)] + pub(super) type LocationOf = + StorageMap<_, Blake2_128Concat, T::AssetId, MultiLocation>; + + /// Location to AssetId mapping. + #[pallet::storage] + #[pallet::getter(fn assetid_of)] + pub(super) type AssetIdOf = + StorageMap<_, Blake2_128Concat, MultiLocation, T::AssetId>; + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(10_000)] + pub fn set_relay_network(origin: OriginFor, network_id: NetworkId) -> DispatchResult { + ensure_root(origin)?; + + >::put(network_id); + Self::deposit_event(Event::::RelayNetworkChanged(network_id)); + + Ok(()) + } + + #[pallet::call_index(1)] + #[pallet::weight(10_000)] + pub fn set_asset_link( + origin: OriginFor, + asset_id: T::AssetId, + location: MultiLocation, + ) -> DispatchResult { + ensure_root(origin)?; + + >::insert(asset_id, location); + >::insert(location, asset_id); + Self::deposit_event(Event::::AssetLinkAdded(asset_id, location)); + + Ok(()) + } + } + + impl MaybeEquivalence for Pallet { + fn convert(id: &MultiLocation) -> Option { + >::get(id) + } + fn convert_back(what: &T::AssetId) -> Option { + >::get(what) + } + } +} diff --git a/runtime/main/Cargo.toml b/runtime/main/Cargo.toml index 0c8acdd1..73022766 100644 --- a/runtime/main/Cargo.toml +++ b/runtime/main/Cargo.toml @@ -10,7 +10,6 @@ build = "build.rs" parity-scale-codec = { workspace = true } smallvec = { workspace = true } scale-info = { workspace = true } -lazy_static = { workspace = true } hex-literal = { workspace = true, optional = true } # primitives @@ -49,6 +48,7 @@ pallet-vesting = { workspace = true } pallet-timestamp = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } +pallet-sudo = { workspace = true } # robonomics dependencies pallet-robonomics-datalog = { path = "../../frame/datalog", default-features = false } @@ -73,6 +73,7 @@ xcm = { workspace = true } xcm-builder = { workspace = true } xcm-executor = { workspace = true } pallet-xcm = { path = "../../vendor/pallet-xcm", default-features = false } +pallet-xcm-info = { path = "../../frame/xcm-info", default-features = false } polkadot-parachain = { workspace = true } polkadot-primitives = { workspace = true } @@ -82,7 +83,6 @@ substrate-wasm-builder = { workspace = true } [features] default = ["std"] with-tracing = ["frame-executive/with-tracing"] -polkadot = [] std = [ "parity-scale-codec/std", "robonomics-primitives/std", @@ -122,6 +122,7 @@ std = [ "pallet-robonomics-liability/std", "pallet-robonomics-lighthouse/std", "pallet-robonomics-rws/std", + "pallet-sudo/std", "cumulus-pallet-parachain-system/std", "cumulus-primitives-core/std", "cumulus-primitives-utility/std", @@ -133,6 +134,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "pallet-xcm/std", + "pallet-xcm-info/std", "polkadot-parachain/std", "polkadot-primitives/std", "parachain-info/std", diff --git a/runtime/main/src/kusama_xcm.rs b/runtime/main/src/kusama_xcm.rs deleted file mode 100644 index b38071e2..00000000 --- a/runtime/main/src/kusama_xcm.rs +++ /dev/null @@ -1,340 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2018-2024 Robonomics Network -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -/////////////////////////////////////////////////////////////////////////////// -use super::{ - AccountId, AllPalletsWithSystem, AssetId, Assets, Balance, Balances, DealWithFees, - ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - WeightToFee, XcmpQueue, -}; -use frame_support::{ - match_types, - pallet_prelude::Get, - parameter_types, - traits::{Contains, ContainsPair, Everything, Nothing, PalletInfoAccess}, - weights::Weight, -}; -use sp_runtime::traits::{Bounded, ConstU32, MaybeEquivalence}; -use sp_std::{marker::PhantomData, prelude::*}; - -// Polkadot imports -use xcm::latest::prelude::*; -use xcm_builder::{ - Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteId, CurrencyAdapter, - EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungiblesAdapter, IsConcrete, - NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, -}; -use xcm_executor::{ - traits::{JustTry, WithOriginFilter}, - Config, XcmExecutor, -}; - -parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub RelayNetwork: NetworkId = NetworkId::Kusama; - pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub UniversalLocation: InteriorMultiLocation = - X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); - pub Local: MultiLocation = Here.into_location(); - pub AssetsPalletLocation: MultiLocation = - PalletInstance(::index() as u8).into(); - pub DummyCheckingAccount: AccountId = PolkadotXcm::check_account(); -} - -/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used -/// when determining ownership of accounts for asset transacting and when attempting to use XCM -/// `Transact` in order to determine the dispatch Origin. -pub type LocationToAccountId = ( - // The parent (Relay-chain) origin converts to the default `AccountId`. - ParentIsPreset, - // Sibling parachain origins convert to AccountId via the `ParaId::into`. - SiblingParachainConvertsVia, - // Straight up local `AccountId32` origins just alias directly to `AccountId`. - AccountId32Aliases, - // Derives a private `Account32` by hashing `("multiloc", received multilocation)` - Account32Hash, -); - -/// Means for transacting the native currency on this chain. -pub type CurrencyTransactor = CurrencyAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // Convert an XCM MultiLocation into a local account id: - LocationToAccountId, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // We don't track any teleports of `Balances`. - (), ->; - -lazy_static::lazy_static! { - static ref ASSET_TO_LOCATION: [(AssetId, MultiLocation); 2] = - // KSM - [ (AssetId::max_value(), MultiLocation::parent()) - // CSM - , (AssetId::max_value() - 4, MultiLocation::new(1, X1(Parachain(2012)))) - ]; -} - -pub struct AssetIdConvertion(PhantomData); -impl MaybeEquivalence for AssetIdConvertion -where - AssetId: Clone + Eq + Bounded + From, -{ - fn convert(id: &MultiLocation) -> Option { - if let Some((asset_id, _)) = ASSET_TO_LOCATION.iter().find(|&(_, v)| id.eq(v)) { - Some((*asset_id).into()) - } else { - None - } - } - fn convert_back(what: &AssetId) -> Option { - if let Some((_, location)) = ASSET_TO_LOCATION - .iter() - .find(|&(k, _)| what.eq(&AssetId::from(*k))) - { - Some(location.clone()) - } else { - None - } - } -} - -/// Means for transacting assets besides the native currency on this chain. -pub type FungiblesTransactor = FungiblesAdapter< - // Use this fungibles implementation: - Assets, - // Use this currency when it is a fungible asset matching the given location or name: - ConvertedConcreteId, JustTry>, - // Convert an XCM MultiLocation into a local account id: - LocationToAccountId, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // We don't track any teleports of `Assets`. - NoChecking, - // We don't track any teleports of `Assets`. - DummyCheckingAccount, ->; - -/// Means for transacting assets on this chain. -pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor); - -/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, -/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can -/// biases the kind of local `Origin` it will become. -pub type XcmOriginToTransactDispatchOrigin = ( - // Sovereign account converter; this attempts to derive an `AccountId` from the origin location - // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for - // foreign chains who want to have a local sovereign account on this chain which they control. - SovereignSignedViaLocation, - // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when - // recognised. - RelayChainAsNative, - // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when - // recognised. - SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, - // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. - pallet_xcm::XcmPassthrough, - // Native signed account converter; this just converts an `AccountId32` origin into a normal - // `Origin::Signed` origin of the same 32-byte value. - SignedAccountId32AsNative, -); - -parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024); - pub const MaxInstructions: u32 = 100; - pub KsmPerSecond: (cumulus_primitives_core::AssetId, u128, u128) = - (MultiLocation::parent().into(), 1_000_000_000, 1_000_000_000); -} - -match_types! { - pub type ParentOrParentsPlurality: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(Plurality { .. }) } - }; -} - -pub type XcmBarrier = ( - TakeWeightCredit, - AllowTopLevelPaidExecutionFrom, - // Parent and its plurality get free execution - AllowUnpaidExecutionFrom, - // Expected responses are OK. - AllowKnownQueryResponses, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, -); - -/// Asset filter that allows all assets from a certain location. -pub struct AssetsFrom(PhantomData); -impl> ContainsPair for AssetsFrom { - fn contains(_a: &MultiAsset, b: &MultiLocation) -> bool { - b.eq(&T::get()) - } -} - -/// A call filter for the XCM Transact instruction. -pub struct SafeCallFilter; -impl SafeCallFilter { - pub fn allow_base_call(_call: &RuntimeCall) -> bool { - // Allow almost base calls by default - true - } - pub fn allow_composite_call(call: &RuntimeCall) -> bool { - match call { - /* - RuntimeCall::Proxy(pallet_proxy::Call::proxy { call, .. }) => { - Self::allow_base_call(call) - } - RuntimeCall::Proxy(pallet_proxy::Call::proxy_announced { call, .. }) => { - Self::allow_base_call(call) - } - */ - RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => { - calls.iter().all(|call| Self::allow_base_call(call)) - } - RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => { - calls.iter().all(|call| Self::allow_base_call(call)) - } - RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => { - Self::allow_base_call(call) - } - RuntimeCall::Multisig(pallet_multisig::Call::as_multi_threshold_1 { call, .. }) => { - Self::allow_base_call(call) - } - RuntimeCall::Multisig(pallet_multisig::Call::as_multi { call, .. }) => { - Self::allow_base_call(call) - } - _ => false, - } - } -} - -impl Contains for SafeCallFilter { - fn contains(call: &RuntimeCall) -> bool { - Self::allow_base_call(call) || Self::allow_composite_call(call) - } -} - -pub struct XcmConfig; -impl Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - type AssetTransactor = AssetTransactors; - type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = AssetsFrom; - type IsTeleporter = (); - type UniversalLocation = UniversalLocation; - type Barrier = XcmBarrier; - type Weigher = FixedWeightBounds; - type Trader = ( - FixedRateOfFungible, - UsingComponents, - ); - type ResponseHandler = PolkadotXcm; - type AssetTrap = PolkadotXcm; - type AssetClaims = PolkadotXcm; - type SubscriptionService = PolkadotXcm; - type PalletInstancesInfo = AllPalletsWithSystem; - type MaxAssetsIntoHolding = ConstU32<64>; - type AssetLocker = (); - type AssetExchanger = (); - type FeeManager = (); - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = WithOriginFilter; - type SafeCallFilter = SafeCallFilter; - type Aliasers = Nothing; -} - -/// Local origins on this chain are allowed to dispatch XCM sends/executions. -pub type LocalOriginToLocation = SignedToAccountId32; - -/// The means for routing XCM messages which are not for local execution into the right message -/// queues. -pub type XcmRouter = ( - // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, - // ..and XCMP to communicate with the sibling chains. - XcmpQueue, -); - -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - -impl pallet_xcm::Config for Runtime { - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = EnsureXcmOrigin; - type XcmRouter = XcmRouter; - type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Nothing; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Nothing; - type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; - type UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; - - type Currency = Balances; - type CurrencyMatcher = (); - type TrustedLockers = (); - type SovereignAccountOf = LocationToAccountId; - type MaxLockers = ConstU32<0>; - type WeightInfo = pallet_xcm::TestWeightInfo; // TODO: fix weights - type MaxRemoteLockConsumers = ConstU32<0>; - type RemoteLockConsumerIdentifier = (); - type AdminOrigin = frame_system::EnsureRoot; - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; -} - -impl cumulus_pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; -} - -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ParachainSystem; - type VersionWrapper = PolkadotXcm; - type ExecuteOverweightOrigin = frame_system::EnsureRoot; - type ControllerOrigin = frame_system::EnsureRoot; - type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; - type PriceForSiblingDelivery = (); - type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight; -} - -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = frame_system::EnsureRoot; -} diff --git a/runtime/main/src/lib.rs b/runtime/main/src/lib.rs index ae16d4b2..87fe9648 100644 --- a/runtime/main/src/lib.rs +++ b/runtime/main/src/lib.rs @@ -77,13 +77,7 @@ use sp_version::RuntimeVersion; use constants::{currency::*, time::*}; -// Kusama XCM configuration & types -#[cfg(not(feature = "polkadot"))] -mod kusama_xcm; - -// Polkadot XCM configuration & types -#[cfg(feature = "polkadot")] -mod polkadot_xcm; +mod xcm_config; /// Standalone runtime version. #[sp_version::runtime_version] @@ -91,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("robonomics"), impl_name: create_runtime_str!("robonomics-airalab"), authoring_version: 1, - spec_version: 33, + spec_version: 34, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -669,13 +663,15 @@ construct_runtime! { RWS: pallet_robonomics_rws = 55, Liability: pallet_robonomics_liability = 56, + // Block authoring gadget. Lighthouse: pallet_robonomics_lighthouse = 60, - // XCM helpers. + // XCM support. XcmpQueue: cumulus_pallet_xcmp_queue = 70, PolkadotXcm: pallet_xcm = 71, CumulusXcm: cumulus_pallet_xcm = 72, DmpQueue: cumulus_pallet_dmp_queue = 73, + XcmInfo: pallet_xcm_info = 74, } } diff --git a/runtime/main/src/polkadot_xcm.rs b/runtime/main/src/xcm_config.rs similarity index 92% rename from runtime/main/src/polkadot_xcm.rs rename to runtime/main/src/xcm_config.rs index 54ef93f3..6fcca0b2 100644 --- a/runtime/main/src/polkadot_xcm.rs +++ b/runtime/main/src/xcm_config.rs @@ -18,7 +18,7 @@ use super::{ AccountId, AllPalletsWithSystem, AssetId, Assets, Balance, Balances, DealWithFees, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - WeightToFee, XcmpQueue, + WeightToFee, XcmInfo, XcmpQueue, }; use frame_support::{ match_types, @@ -27,7 +27,7 @@ use frame_support::{ traits::{Contains, ContainsPair, Everything, Nothing, PalletInfoAccess}, weights::Weight, }; -use sp_runtime::traits::{Bounded, ConstU32, MaybeEquivalence}; +use sp_runtime::traits::ConstU32; use sp_std::{marker::PhantomData, prelude::*}; // Polkadot imports @@ -46,8 +46,8 @@ use xcm_executor::{ }; parameter_types! { + pub RelayNetwork: NetworkId = XcmInfo::relay_network().unwrap_or(NetworkId::Kusama); pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub RelayNetwork: NetworkId = NetworkId::Polkadot; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); @@ -85,43 +85,12 @@ pub type CurrencyTransactor = CurrencyAdapter< (), >; -lazy_static::lazy_static! { - static ref ASSET_TO_LOCATION: [(AssetId, MultiLocation); 1] = - // DOT - [ (AssetId::max_value(), MultiLocation::parent()) - ]; -} - -pub struct AssetIdConvertion(PhantomData); -impl MaybeEquivalence for AssetIdConvertion -where - AssetId: Clone + Eq + Bounded + From, -{ - fn convert(id: &MultiLocation) -> Option { - if let Some((asset_id, _)) = ASSET_TO_LOCATION.iter().find(|&(_, v)| id.eq(v)) { - Some((*asset_id).into()) - } else { - None - } - } - fn convert_back(what: &AssetId) -> Option { - if let Some((_, location)) = ASSET_TO_LOCATION - .iter() - .find(|&(k, _)| what.eq(&AssetId::from(*k))) - { - Some(location.clone()) - } else { - None - } - } -} - /// Means for transacting assets besides the native currency on this chain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: Assets, // Use this currency when it is a fungible asset matching the given location or name: - ConvertedConcreteId, JustTry>, + ConvertedConcreteId, // Convert an XCM MultiLocation into a local account id: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -336,3 +305,8 @@ impl cumulus_pallet_dmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = frame_system::EnsureRoot; } + +impl pallet_xcm_info::Config for Runtime { + type AssetId = AssetId; + type RuntimeEvent = RuntimeEvent; +}