diff --git a/pallets/flexible-fee/src/mock.rs b/pallets/flexible-fee/src/mock.rs index 47d2c77913..e669f02954 100644 --- a/pallets/flexible-fee/src/mock.rs +++ b/pallets/flexible-fee/src/mock.rs @@ -473,6 +473,7 @@ parameter_types! { pub SalpTransactProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived; pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm; pub const RelayCurrencyId: CurrencyId = CurrencyId::Token(TokenSymbol::KSM); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; } pub const XCM_WEIGHT: u64 = 1_000_000_000; @@ -544,6 +545,7 @@ impl bifrost_salp::Config for Test { type SovereignSubAccountLocation = RelaychainSovereignSubAccount; type TransactProxyType = SalpTransactProxyType; type TransactType = SalpTransactType; + type RelayNetwork = RelayNetwork; } //************** Salp mock end ***************** diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index 8fc0e69998..7ac1714af9 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -38,6 +38,23 @@ use node_primitives::{ContributionStatus, TokenInfo, TokenSymbol, TrieIndex}; use orml_traits::MultiCurrency; pub use pallet::*; use sp_std::convert::TryFrom; +use xcm_support::*; + +macro_rules! use_relay { + ({ $( $code:tt )* }) => { + if T::RelayNetwork::get() == NetworkId::Polkadot { + use polkadot::RelaychainCall; + + $( $code )* + } else if T::RelayNetwork::get() == NetworkId::Kusama { + use kusama::RelaychainCall; + + $( $code )* + } else { + unreachable!() + } + } +} #[allow(type_alias_bounds)] pub type AccountIdOf = ::AccountId; @@ -105,7 +122,6 @@ pub mod pallet { use sp_arithmetic::Percent; use sp_std::prelude::*; use xcm::latest::prelude::*; - use xcm_support::{kusama::RelaychainCall, *}; use super::*; @@ -192,6 +208,9 @@ pub mod pallet { #[pallet::constant] type TransactType: Get; + + #[pallet::constant] + type RelayNetwork: Get; } #[pallet::pallet] @@ -1148,60 +1167,68 @@ pub mod pallet { value: BalanceOf, nonce: Nonce, ) -> Result { - let contribute_call = - RelaychainCall::Crowdloan::, AccountIdOf, BlockNumberFor>( - ContributeCall::Contribute(Contribution { index, value, signature: None }), + use_relay!({ + let contribute_call = + RelaychainCall::Crowdloan::, AccountIdOf, BlockNumberFor>( + ContributeCall::Contribute(Contribution { index, value, signature: None }), + ) + .encode() + .into(); + + T::BifrostXcmExecutor::ump_transact( + MultiLocation::here(), + contribute_call, + T::ContributionWeight::get(), + false, + nonce, ) - .encode() - .into(); - - T::BifrostXcmExecutor::ump_transact( - MultiLocation::here(), - contribute_call, - T::ContributionWeight::get(), - false, - nonce, - ) + }) } fn xcm_ump_add_proxy(delegate: AccountIdOf) -> Result { - let call = RelaychainCall::Proxy::, AccountIdOf, BlockNumberFor>( - ProxyCall::Add(AddProxy { - delegate, - proxy_type: ProxyType::Any, - delay: T::BlockNumber::zero(), - }), - ) - .encode() - .into(); - - T::BifrostXcmExecutor::ump_transact( - MultiLocation::here(), - call, - T::AddProxyWeight::get(), - false, - 0, - ) + use_relay!({ + let call = + RelaychainCall::Proxy::, AccountIdOf, BlockNumberFor>( + ProxyCall::Add(AddProxy { + delegate, + proxy_type: ProxyType::Any, + delay: T::BlockNumber::zero(), + }), + ) + .encode() + .into(); + + T::BifrostXcmExecutor::ump_transact( + MultiLocation::here(), + call, + T::AddProxyWeight::get(), + false, + 0, + ) + }) } fn xcm_ump_remove_proxy(delegate: AccountIdOf) -> Result { - let call = RelaychainCall::Proxy::, AccountIdOf, BlockNumberFor>( - ProxyCall::Remove(RemoveProxy { - delegate, - proxy_type: ProxyType::Any, - delay: T::BlockNumber::zero(), - }), - ) - .encode() - .into(); - - T::BifrostXcmExecutor::ump_transact( - MultiLocation::here(), - call, - T::AddProxyWeight::get(), - false, - 0, - ) + use_relay!({ + let call = + RelaychainCall::Proxy::, AccountIdOf, BlockNumberFor>( + ProxyCall::Remove(RemoveProxy { + delegate, + proxy_type: ProxyType::Any, + delay: T::BlockNumber::zero(), + }), + ) + .encode() + .into(); + + T::BifrostXcmExecutor::ump_transact( + MultiLocation::here(), + call, + T::AddProxyWeight::get(), + false, + 0, + ) + }) } fn xcm_ump_transfer(who: AccountIdOf, amount: BalanceOf) -> DispatchResult { diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index 88b15d73be..11b48dbc2b 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -205,6 +205,7 @@ parameter_types! { pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(0); pub SalpTransactProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived; pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm; + pub const RelayNetwork: NetworkId = NetworkId::Kusama; } parameter_types! { @@ -296,6 +297,7 @@ impl salp::Config for Test { type SovereignSubAccountLocation = RelaychainSovereignSubAccount; type TransactProxyType = SalpTransactProxyType; type TransactType = SalpTransactType; + type RelayNetwork = RelayNetwork; } pub struct SalpWeightInfo; diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index dcf30cf760..2d900e826a 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -690,7 +690,8 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} impl pallet_randomness_collective_flip::Config for Runtime {} parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); + pub const KsmLocation: MultiLocation = MultiLocation::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); pub SelfParaChainId: CumulusParaId = ParachainInfo::parachain_id(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); @@ -713,7 +714,7 @@ pub type LocalAssetTransactor = CurrencyAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + IsConcrete, // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -1217,6 +1218,7 @@ impl bifrost_salp::Config for Runtime { type SovereignSubAccountLocation = RelaychainSovereignSubAccount; type TransactProxyType = SalpProxyType; type TransactType = SalpTransactType; + type RelayNetwork = RelayNetwork; } parameter_types! { diff --git a/runtime/bifrost/Cargo.toml b/runtime/bifrost/Cargo.toml index c2780343f0..c015bb2d91 100644 --- a/runtime/bifrost/Cargo.toml +++ b/runtime/bifrost/Cargo.toml @@ -172,6 +172,7 @@ std = [ "bifrost-token-issuer/std", "zenlink-protocol/std", "zenlink-protocol-runtime-api/std", + "xcm-support/std" ] with-tracing = ["frame-executive/with-tracing"] diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index e6a4859df1..342baeb1a3 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -1140,6 +1140,7 @@ impl bifrost_salp::Config for Runtime { type SovereignSubAccountLocation = RelaychainSovereignSubAccount; type TransactProxyType = SalpProxyType; type TransactType = SalpTransactType; + type RelayNetwork = RelayNetwork; } parameter_types! { diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 30453f4758..0110bae84d 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -680,7 +680,8 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} impl pallet_randomness_collective_flip::Config for Runtime {} parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); + pub const KsmLocation: MultiLocation = MultiLocation::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); pub SelfParaChainId: CumulusParaId = ParachainInfo::parachain_id(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); @@ -703,7 +704,7 @@ pub type LocalAssetTransactor = CurrencyAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + IsConcrete, // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -1116,6 +1117,7 @@ impl bifrost_salp::Config for Runtime { type SovereignSubAccountLocation = RelaychainSovereignSubAccount; type TransactProxyType = SalpTransactProxyType; type TransactType = SalpTransactType; + type RelayNetwork = RelayNetwork; } parameter_types! { diff --git a/xcm-support/src/calls.rs b/xcm-support/src/calls.rs index f238c93c07..1eea7be969 100644 --- a/xcm-support/src/calls.rs +++ b/xcm-support/src/calls.rs @@ -17,10 +17,24 @@ // along with this program. If not, see . use codec::{Decode, Encode}; +use frame_support::{sp_runtime::MultiSignature, RuntimeDebug}; use node_primitives::ParaId; -use sp_runtime::{MultiSignature, RuntimeDebug}; use sp_std::vec::Vec; +#[derive(Encode, Decode, RuntimeDebug)] +pub enum UtilityCall { + #[codec(index = 1)] + AsDerivative(u16, RelayChainCall), + #[codec(index = 2)] + BatchAll(Vec), +} + +#[derive(Encode, Decode, RuntimeDebug)] +pub enum StakingCall { + #[codec(index = 3)] + WithdrawUnbonded(u32), +} + pub mod kusama { pub use crate::calls::*; @@ -34,6 +48,19 @@ pub mod kusama { } } +pub mod polkadot { + + pub use crate::calls::*; + + #[derive(Encode, Decode, RuntimeDebug)] + pub enum RelaychainCall { + #[codec(index = 73)] + Crowdloan(ContributeCall), + #[codec(index = 29)] + Proxy(ProxyCall), + } +} + #[derive(Encode, Decode, RuntimeDebug)] pub enum ContributeCall { #[codec(index = 1)]