Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 *****************
123 changes: 75 additions & 48 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = <T as frame_system::Config>::AccountId;
Expand Down Expand Up @@ -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::*;

Expand Down Expand Up @@ -192,6 +208,9 @@ pub mod pallet {

#[pallet::constant]
type TransactType: Get<ParachainTransactType>;

#[pallet::constant]
type RelayNetwork: Get<NetworkId>;
}

#[pallet::pallet]
Expand Down Expand Up @@ -1148,60 +1167,68 @@ pub mod pallet {
value: BalanceOf<T>,
nonce: Nonce,
) -> Result<MessageId, XcmError> {
let contribute_call =
RelaychainCall::Crowdloan::<BalanceOf<T>, AccountIdOf<T>, BlockNumberFor<T>>(
ContributeCall::Contribute(Contribution { index, value, signature: None }),
use_relay!({
let contribute_call =
RelaychainCall::Crowdloan::<BalanceOf<T>, AccountIdOf<T>, BlockNumberFor<T>>(
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<T>) -> Result<MessageId, XcmError> {
let call = RelaychainCall::Proxy::<BalanceOf<T>, AccountIdOf<T>, BlockNumberFor<T>>(
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::<BalanceOf<T>, AccountIdOf<T>, BlockNumberFor<T>>(
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<T>) -> Result<MessageId, XcmError> {
let call = RelaychainCall::Proxy::<BalanceOf<T>, AccountIdOf<T>, BlockNumberFor<T>>(
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::<BalanceOf<T>, AccountIdOf<T>, BlockNumberFor<T>>(
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<T>, amount: BalanceOf<T>) -> DispatchResult {
Expand Down
2 changes: 2 additions & 0 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -296,6 +297,7 @@ impl salp::Config for Test {
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
type TransactProxyType = SalpTransactProxyType;
type TransactType = SalpTransactType;
type RelayNetwork = RelayNetwork;
}

pub struct SalpWeightInfo;
Expand Down
6 changes: 4 additions & 2 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<RelayLocation>,
IsConcrete<KsmLocation>,
// 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):
Expand Down Expand Up @@ -1217,6 +1218,7 @@ impl bifrost_salp::Config for Runtime {
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
type TransactProxyType = SalpProxyType;
type TransactType = SalpTransactType;
type RelayNetwork = RelayNetwork;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ impl bifrost_salp::Config for Runtime {
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
type TransactProxyType = SalpProxyType;
type TransactType = SalpTransactType;
type RelayNetwork = RelayNetwork;
}

parameter_types! {
Expand Down
6 changes: 4 additions & 2 deletions runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<RelayLocation>,
IsConcrete<KsmLocation>,
// 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):
Expand Down Expand Up @@ -1116,6 +1117,7 @@ impl bifrost_salp::Config for Runtime {
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
type TransactProxyType = SalpTransactProxyType;
type TransactType = SalpTransactType;
type RelayNetwork = RelayNetwork;
}

parameter_types! {
Expand Down
29 changes: 28 additions & 1 deletion xcm-support/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

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<RelayChainCall> {
#[codec(index = 1)]
AsDerivative(u16, RelayChainCall),
#[codec(index = 2)]
BatchAll(Vec<RelayChainCall>),
}

#[derive(Encode, Decode, RuntimeDebug)]
pub enum StakingCall {
#[codec(index = 3)]
WithdrawUnbonded(u32),
}

pub mod kusama {

pub use crate::calls::*;
Expand All @@ -34,6 +48,19 @@ pub mod kusama {
}
}

pub mod polkadot {

pub use crate::calls::*;

#[derive(Encode, Decode, RuntimeDebug)]
pub enum RelaychainCall<BalanceOf, AccountIdOf, BlockNumberOf> {
#[codec(index = 73)]
Crowdloan(ContributeCall<BalanceOf, AccountIdOf>),
#[codec(index = 29)]
Proxy(ProxyCall<AccountIdOf, BlockNumberOf>),
}
}

#[derive(Encode, Decode, RuntimeDebug)]
pub enum ContributeCall<BalanceOf, AccountIdOf> {
#[codec(index = 1)]
Expand Down