Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

315 enable pendulum assets to be transferable via xcm #332

Merged
merged 20 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions runtime/amplitude/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use orml_traits::{
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use runtime_common::parachains::kusama::asset_hub;
use sp_runtime::traits::Convert;
use xcm::latest::{prelude::*, Weight as XCMWeight};
use xcm_builder::{
Expand All @@ -27,7 +28,6 @@ use xcm_executor::{
traits::{JustTry, ShouldExecute},
XcmExecutor,
};
use runtime_common::parachains::kusama::asset_hub;

const XCM_ASSET_RELAY_KSM: u8 = 0;
const XCM_ASSET_ASSETHUB_USDT: u8 = 1;
Expand Down Expand Up @@ -75,6 +75,10 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
)),
_ => None,
},
CurrencyId::Native => Some(MultiLocation::new(
1,
X2(Parachain(ParachainInfo::parachain_id().into()), PalletInstance(10)),
)),
_ => None,
}
}
Expand All @@ -83,16 +87,22 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
fn convert(location: MultiLocation) -> Option<CurrencyId> {
match location {
MultiLocation { parents: 1, interior: Here } => Some(CurrencyId::XCM(XCM_ASSET_RELAY_KSM)),
MultiLocation { parents: 1, interior: Here } =>
Some(CurrencyId::XCM(XCM_ASSET_RELAY_KSM)),
MultiLocation {
parents: 1,
interior:
X3(
Parachain(asset_hub::PARA_ID),
PalletInstance(asset_hub::ASSET_PALLET_ID),
GeneralIndex(asset_hub::USDT_ASSET_ID)
)
GeneralIndex(asset_hub::USDT_ASSET_ID),
),
} => Some(CurrencyId::XCM(XCM_ASSET_ASSETHUB_USDT)),
MultiLocation { parents: 1, interior: X2(Parachain(id), PalletInstance(10)) }
if id == u32::from(ParachainInfo::parachain_id()) =>
Some(CurrencyId::Native),
MultiLocation { parents: 0, interior: X1(PalletInstance(10)) } =>
Some(CurrencyId::Native),
_ => None,
}
}
Expand Down
9 changes: 9 additions & 0 deletions runtime/foucoco/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
0 => Some(MultiLocation::parent()),
_ => None,
},
CurrencyId::Native => Some(MultiLocation::new(
1,
X2(Parachain(ParachainInfo::parachain_id().into()), PalletInstance(10)),
)),
_ => None,
}
}
Expand All @@ -72,6 +76,11 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
fn convert(location: MultiLocation) -> Option<CurrencyId> {
match location {
MultiLocation { parents: 1, interior: Here } => Some(CurrencyId::XCM(0)),
MultiLocation { parents: 1, interior: X2(Parachain(id), PalletInstance(10)) }
if id == u32::from(ParachainInfo::parachain_id()) =>
Some(CurrencyId::Native),
MultiLocation { parents: 0, interior: X1(PalletInstance(10)) } =>
Some(CurrencyId::Native),
_ => None,
}
}
Expand Down
20 changes: 20 additions & 0 deletions runtime/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ version = "0.1.0"
codec = { package = "parity-scale-codec", version = "3.0.0" }
scale-info = { version = "2.1.2", features = ["derive"] }

# Spacewalk libraries
spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "58983d2695c309665c9c017a022436aaee088f3d"}

frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
Expand All @@ -17,6 +20,8 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sp-debug-derive = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }

xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" }
Expand All @@ -34,13 +39,28 @@ xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "bea35c

cumulus-pallet-dmp-queue = {git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40"}
cumulus-pallet-xcmp-queue = {git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40"}
cumulus-pallet-xcm = {git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40"}
cumulus-primitives-core = {git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40"}
cumulus-primitives-utility = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.40"}
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }

statemint-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }
statemine-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }

orml-xcm = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.40" }
orml-xcm-support = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.40" }
orml-traits = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.40" }
orml-tokens = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.40" }
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.40" }

# Local
runtime-common = {path = "../common", default-features = false}

pendulum-runtime = { path = "../pendulum" }
amplitude-runtime = {path = "../amplitude" }

[features]
default = ["std"]
std = [
"codec/std",
]
28 changes: 27 additions & 1 deletion runtime/integration-tests/src/amplitude_tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{
mock::{kusama_relay_ext, para_ext, ParachainType, USDT_ASSET_ID},
sibling,
test_macros::{
parachain1_transfer_asset_to_parachain2, parachain1_transfer_asset_to_parachain2_and_back,
parachain1_transfer_incorrect_asset_to_parachain2_should_fail,
transfer_10_relay_token_from_parachain_to_relay_chain,
transfer_20_relay_token_from_relay_chain_to_parachain,
transfer_native_token_from_parachain1_to_parachain2_and_back,
},
AMPLITUDE_ID, KUSAMA_ASSETHUB_ID,
AMPLITUDE_ID, KUSAMA_ASSETHUB_ID, SIBLING_ID,
};

use frame_support::assert_ok;
Expand Down Expand Up @@ -34,6 +36,16 @@ decl_test_parachain! {
}
}

decl_test_parachain! {
pub struct SiblingParachain {
Runtime = sibling::Runtime,
RuntimeOrigin = sibling::RuntimeOrigin,
XcmpMessageHandler = sibling::XcmpQueue,
DmpMessageHandler = sibling::DmpQueue,
new_ext = para_ext(ParachainType::Sibling),
}
}

decl_test_parachain! {
pub struct AssetHubParachain {
Runtime = kusama_asset_hub_runtime::Runtime,
Expand All @@ -50,6 +62,7 @@ decl_test_network! {
parachains = vec![
(1000, AssetHubParachain),
(2124, AmplitudeParachain),
(9999, SiblingParachain),
],
}
}
Expand Down Expand Up @@ -116,3 +129,16 @@ fn assethub_transfer_asset_to_amplitude_and_back() {
network_id
);
}

#[test]
fn transfer_native_token_to_sibling_parachain_and_back() {
bogdanS98 marked this conversation as resolved.
Show resolved Hide resolved
transfer_native_token_from_parachain1_to_parachain2_and_back!(
KusamaMockNet,
amplitude_runtime,
AmplitudeParachain,
sibling,
SiblingParachain,
AMPLITUDE_ID,
SIBLING_ID
);
}
5 changes: 5 additions & 0 deletions runtime/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ mod amplitude_tests;
#[cfg(test)]
mod test_macros;

#[cfg(test)]
mod sibling;

pub const PENDULUM_ID: u32 = 2094;
pub const POLKADOT_ASSETHUB_ID: u32 = 1000;

pub const AMPLITUDE_ID: u32 = 2124;
pub const KUSAMA_ASSETHUB_ID: u32 = 1000;

pub const SIBLING_ID: u32 = 9999;
33 changes: 30 additions & 3 deletions runtime/integration-tests/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{AMPLITUDE_ID, PENDULUM_ID, KUSAMA_ASSETHUB_ID, POLKADOT_ASSETHUB_ID};
use crate::{
sibling, AMPLITUDE_ID, KUSAMA_ASSETHUB_ID, PENDULUM_ID, POLKADOT_ASSETHUB_ID, SIBLING_ID,
};
use frame_support::traits::GenesisBuild;
use pendulum_runtime::CurrencyId;
use polkadot_core_primitives::{AccountId, Balance, BlockNumber};
Expand All @@ -7,10 +9,11 @@ use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_runtime_parachains::configuration::HostConfiguration;
use sp_io::TestExternalities;
use sp_runtime::traits::AccountIdConversion;
use sp_tracing;
use xcm_emulator::Weight;

use statemint_runtime as polkadot_asset_hub_runtime;
use statemine_runtime as kusama_asset_hub_runtime;
use statemint_runtime as polkadot_asset_hub_runtime;

pub const ALICE: [u8; 32] = [4u8; 32];
pub const BOB: [u8; 32] = [5u8; 32];
Expand Down Expand Up @@ -61,6 +64,8 @@ macro_rules! build_relaychain {

macro_rules! build_parachain_with_orml {
($self:ident, $runtime:ty, $system:tt, $balance:tt, $orml_balance:tt) => {{
sp_tracing::try_init_simple();

let mut t = frame_system::GenesisConfig::default().build_storage::<$runtime>().unwrap();
pallet_balances::GenesisConfig::<$runtime> {
balances: vec![(AccountId::from(ALICE), $balance), (AccountId::from(BOB), $balance)],
Expand All @@ -69,7 +74,12 @@ macro_rules! build_parachain_with_orml {
.unwrap();

orml_tokens::GenesisConfig::<$runtime> {
balances: vec![(AccountId::from(BOB), CurrencyId::XCM(0), units($orml_balance))],
balances: vec![
(AccountId::from(BOB), CurrencyId::XCM(0), units($orml_balance)),
(AccountId::from(ALICE), CurrencyId::XCM(0), units($orml_balance)),
(AccountId::from(BOB), CurrencyId::Native, units($orml_balance)),
(AccountId::from(ALICE), CurrencyId::Native, units($orml_balance)),
],
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down Expand Up @@ -110,6 +120,7 @@ pub enum ParachainType {
KusamaAssetHub,
Pendulum,
Amplitude,
Sibling,
}

pub struct ExtBuilderParachain<Currency> {
Expand Down Expand Up @@ -182,6 +193,7 @@ pub fn para_ext(chain: ParachainType) -> sp_io::TestExternalities {
ParachainType::Pendulum => ExtBuilderParachain::pendulum_default().balances(vec![]).build(),
ParachainType::Amplitude =>
ExtBuilderParachain::amplitude_default().balances(vec![]).build(),
ParachainType::Sibling => ExtBuilderParachain::sibling_default().balances(vec![]).build(),
}
}

Expand All @@ -191,6 +203,7 @@ impl<Currency> ExtBuilderParachain<Currency> {
ParachainType::PolkadotAssetHub => POLKADOT_ASSETHUB_ID,
ParachainType::KusamaAssetHub => KUSAMA_ASSETHUB_ID,
ParachainType::Pendulum => PENDULUM_ID,
ParachainType::Sibling => SIBLING_ID,
ParachainType::Amplitude => AMPLITUDE_ID,
}
}
Expand All @@ -205,6 +218,10 @@ impl ExtBuilderParachain<CurrencyId> {
pub fn amplitude_default() -> Self {
Self { balances: vec![], chain: ParachainType::Amplitude }
}

pub fn sibling_default() -> Self {
Self { balances: vec![], chain: ParachainType::Sibling }
}
}

impl Builder<CurrencyId> for ExtBuilderParachain<CurrencyId> {
Expand Down Expand Up @@ -235,6 +252,16 @@ impl Builder<CurrencyId> for ExtBuilderParachain<CurrencyId> {
ORML_INITIAL_BALANCE
)
},
ParachainType::Sibling => {
use sibling::{Runtime, System};
build_parachain_with_orml!(
self,
Runtime,
System,
INITIAL_BALANCE,
ORML_INITIAL_BALANCE
)
},
_ => panic!("cannot use this chain to build"),
}
}
Expand Down
Loading
Loading