Skip to content

Commit

Permalink
315 enable pendulum assets to be transferable via xcm (#332)
Browse files Browse the repository at this point in the history
* Add PEN token to MultiLocation (and viceversa) conversions in XCM config

* Add test for transferring PEN to AssetHub through XCM

* fmt

* fmt

* Add conversions for Amplitude and Foucoco - tests still in progress

* Add 'sibling' runtime

* Add dependencies

* Try to get sibling to compile for the minimal configuration - failed

* Almost fix sibling runtime

* Add `std` feature

* Fix sibling runtime, integration tests and update xcm configs for all runtimes with the correct multilocations

* Add xcm config updates for all runtimes

* Cargo lock

* Remove unused dependencies and sibling cleanup

* Address change request

* fmt

* Add comment in test macro

* Remove unused import

* Support XCM transfers for AssetHub USDT and relay dot on sibling runtime

* Add comments

---------

Co-authored-by: Marcel Ebert <[email protected]>
  • Loading branch information
bogdanS98 and ebma authored Nov 7, 2023
1 parent d8626d4 commit cb328d3
Show file tree
Hide file tree
Showing 11 changed files with 976 additions and 23 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

21 changes: 17 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,25 @@ 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)),
// Our native currency location without re-anchoring
MultiLocation { parents: 1, interior: X2(Parachain(id), PalletInstance(10)) }
if id == u32::from(ParachainInfo::parachain_id()) =>
Some(CurrencyId::Native),
// Our native currency location with re-anchoring
// The XCM pallet will try to re-anchor the location before it reaches here
MultiLocation { parents: 0, interior: X1(PalletInstance(10)) } =>
Some(CurrencyId::Native),
_ => None,
}
}
Expand Down
12 changes: 12 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,14 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
fn convert(location: MultiLocation) -> Option<CurrencyId> {
match location {
MultiLocation { parents: 1, interior: Here } => Some(CurrencyId::XCM(0)),
// Our native currency location without re-anchoring
MultiLocation { parents: 1, interior: X2(Parachain(id), PalletInstance(10)) }
if id == u32::from(ParachainInfo::parachain_id()) =>
Some(CurrencyId::Native),
// Our native currency location with re-anchoring
// The XCM pallet will try to re-anchor the location before it reaches here
MultiLocation { parents: 0, interior: X1(PalletInstance(10)) } =>
Some(CurrencyId::Native),
_ => None,
}
}
Expand Down
21 changes: 21 additions & 0 deletions runtime/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ version = "0.1.0"
[dev-dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0" }
scale-info = { version = "2.1.2", features = ["derive"] }
serde = { version = "1.0.144", 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" }
Expand All @@ -17,6 +21,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 +40,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",
]
30 changes: 28 additions & 2 deletions 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, 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 @@ -108,11 +121,24 @@ fn assethub_transfer_asset_to_amplitude_and_back() {
parachain1_transfer_asset_to_parachain2_and_back!(
kusama_asset_hub_runtime,
AssetHubParachain,
KUSAMA_ASSETHUB_ID,
ASSETHUB_ID,
USDT_ASSET_ID,
amplitude_runtime,
AmplitudeParachain,
AMPLITUDE_ID,
network_id
);
}

#[test]
fn transfer_native_token_from_amplitude_to_sibling_parachain_and_back() {
transfer_native_token_from_parachain1_to_parachain2_and_back!(
KusamaMockNet,
amplitude_runtime,
AmplitudeParachain,
sibling,
SiblingParachain,
AMPLITUDE_ID,
SIBLING_ID
);
}
8 changes: 5 additions & 3 deletions runtime/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ mod amplitude_tests;
#[cfg(test)]
mod test_macros;

pub const PENDULUM_ID: u32 = 2094;
pub const POLKADOT_ASSETHUB_ID: u32 = 1000;
#[cfg(test)]
mod sibling;

pub const PENDULUM_ID: u32 = 2094;
pub const AMPLITUDE_ID: u32 = 2124;
pub const KUSAMA_ASSETHUB_ID: u32 = 1000;
pub const ASSETHUB_ID: u32 = 1000;
pub const SIBLING_ID: u32 = 9999;
Loading

0 comments on commit cb328d3

Please sign in to comment.