Skip to content

Commit

Permalink
first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
b-yap committed Nov 8, 2023
1 parent 4a9bc57 commit 0214193
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
18 changes: 18 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ pub mod parachains {
pub const USDC_ASSET_ID: u128 = 1337;
pub const USDT_ASSET_ID: u128 = 1984;
}

pub mod equilibrium {
pub const PARA_ID: u32 = 2011;
pub const ASSET_PALLET_ID: u8 = 11;

pub const EQ_ASSET_ID: u128 = 25_969;
pub const EQD_ASSET_ID: u128 = 6_648_164;
}

pub mod moonbeam {
pub const PARA_ID: u32 = 2004;
pub const ASSET_PALLET_ID: u8 = 104;
}

pub mod polkadex {
pub const PARA_ID: u32 = 2040;
pub const ASSET_PALLET_ID: u8 = 25;
}
}

pub mod kusama {
Expand Down
51 changes: 33 additions & 18 deletions runtime/pendulum/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use orml_traits::{
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use runtime_common::parachains::polkadot::asset_hub;
use runtime_common::parachains::polkadot::{asset_hub, equilibrium};
use sp_runtime::traits::Convert;
use xcm::latest::{prelude::*, Weight as XCMWeight};
use xcm_builder::{
Expand All @@ -31,6 +31,9 @@ use xcm_executor::{

const XCM_ASSET_RELAY_DOT: u8 = 0;
const XCM_ASSET_ASSETHUB_USDT: u8 = 1;
const XCM_ASSET_ASSETHUB_USDC: u8 = 2;
const XCM_ASSET_EQUILIBRIUM_EQD: u8 = 3;
const XCM_ASSET_EQUILIBRIUM_EQ: u8 = 4;

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Expand All @@ -42,6 +45,19 @@ parameter_types! {

}

macro_rules! parachain_asset_loc {
($module:ident, $asset_id:path) => {
MultiLocation {
parents: 1,
interior: X3(
Parachain($module::PARA_ID),
PalletInstance($module::ASSET_PALLET_ID),
GeneralIndex($asset_id),
),
}
};
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
/// `Transact` in order to determine the dispatch Origin.
Expand All @@ -66,14 +82,14 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
// CurrencyId::KSM => Some(MultiLocation::parent()),
CurrencyId::XCM(f) => match f {
XCM_ASSET_RELAY_DOT => Some(MultiLocation::parent()),
XCM_ASSET_ASSETHUB_USDT => Some(MultiLocation::new(
1,
X3(
Parachain(asset_hub::PARA_ID),
PalletInstance(asset_hub::ASSET_PALLET_ID),
GeneralIndex(asset_hub::USDT_ASSET_ID),
),
)),
XCM_ASSET_ASSETHUB_USDT =>
Some(parachain_asset_loc!(asset_hub, asset_hub::USDT_ASSET_ID)),
XCM_ASSET_ASSETHUB_USDC =>
Some(parachain_asset_loc!(asset_hub, asset_hub::USDC_ASSET_ID)),
XCM_ASSET_EQUILIBRIUM_EQD =>
Some(parachain_asset_loc!(equilibrium, equilibrium::EQD_ASSET_ID)),
XCM_ASSET_EQUILIBRIUM_EQ =>
Some(parachain_asset_loc!(equilibrium, equilibrium::EQ_ASSET_ID)),
_ => None,
},
CurrencyId::Native => Some(MultiLocation::new(
Expand All @@ -90,15 +106,14 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
match location {
MultiLocation { parents: 1, interior: Here } =>
Some(CurrencyId::XCM(XCM_ASSET_RELAY_DOT)),
MultiLocation {
parents: 1,
interior:
X3(
Parachain(asset_hub::PARA_ID),
PalletInstance(asset_hub::ASSET_PALLET_ID),
GeneralIndex(asset_hub::USDT_ASSET_ID),
),
} => Some(CurrencyId::XCM(XCM_ASSET_ASSETHUB_USDT)),
parachain_asset_loc!(asset_hub, asset_hub::USDT_ASSET_ID) =>
Some(CurrencyId::XCM(XCM_ASSET_ASSETHUB_USDT)),
parachain_asset_loc!(asset_hub, asset_hub::USDC_ASSET_ID) =>
Some(CurrencyId::XCM(XCM_ASSET_ASSETHUB_USDC)),
parachain_asset_loc!(equilibrium, equilibrium::EQD_ASSET_ID) =>
Some(CurrencyId::XCM(XCM_ASSET_EQUILIBRIUM_EQD)),
parachain_asset_loc!(equilibrium, equilibrium::EQ_ASSET_ID) =>
Some(CurrencyId::XCM(XCM_ASSET_EQUILIBRIUM_EQ)),
// Our native currency location without re-anchoring
MultiLocation { parents: 1, interior: X2(Parachain(id), PalletInstance(10)) }
if id == u32::from(ParachainInfo::parachain_id()) =>
Expand Down

0 comments on commit 0214193

Please sign in to comment.