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 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
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
Loading