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

Move chain specific definitions #440

Merged
11 changes: 11 additions & 0 deletions runtime/amplitude/src/definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

pub mod asset_hub {
use runtime_common::parachain_asset_location;

pub const PARA_ID: u32 = 1000;
pub const ASSET_PALLET_INDEX: u8 = 50;

parachain_asset_location!(USDC, 1337);
parachain_asset_location!(USDT, 1984);
parachain_asset_location!(PINK, 23);
gianfra-t marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions runtime/amplitude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod chain_ext;
mod weights;
pub mod xcm_config;
pub mod zenlink;
pub mod definitions;

use crate::zenlink::*;
use bifrost_farming as farming;
Expand Down
2 changes: 1 addition & 1 deletion runtime/amplitude/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use xcm_executor::{
XcmExecutor,
};

use runtime_common::{parachains::kusama::asset_hub, RelativeValue};
use runtime_common::{parachains::asset_hub, RelativeValue};
gianfra-t marked this conversation as resolved.
Show resolved Hide resolved

use cumulus_primitives_utility::{
ChargeWeightInFungibles, TakeFirstAssetTrader, XcmFeesTo32ByteAccount,
Expand Down
122 changes: 3 additions & 119 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub mod parachains {
}

/// Creates a location for the given asset in this format: `fn <asset_name>_location() -> MultiLocation`
#[macro_export]
macro_rules! parachain_asset_location {
// Also declares a constant variable <asset_name>_ASSET_ID with <asset_value>.
// This assumes that the following constant variables exist:
Expand Down Expand Up @@ -159,122 +160,16 @@ pub mod parachains {
}
};
}

pub mod polkadot {
pub mod asset_hub {
pub const PARA_ID: u32 = 1000;
pub const ASSET_PALLET_INDEX: u8 = 50;

parachain_asset_location!(USDC, 1337);
parachain_asset_location!(USDT, 1984);
parachain_asset_location!(PINK, 23);
}

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

parachain_asset_location!(EQ, 25_969);
parachain_asset_location!(EQD, 6_648_164);
}

pub mod moonbeam {
use xcm::latest::{
Junction::{AccountKey20, PalletInstance, Parachain},
Junctions::{X2, X3},
};

pub const PARA_ID: u32 = 2004;
pub const ASSET_PALLET_INDEX: u8 = 110;
pub const BALANCES_PALLET_INDEX: u8 = 10;

// The address of the BRZ token on Moonbeam `0x3225edCe8aD30Ae282e62fa32e7418E4b9cf197b` as byte array
pub const BRZ_ASSET_ACCOUNT_IN_BYTES: [u8; 20] = [
50, 37, 237, 206, 138, 211, 10, 226, 130, 230, 47, 163, 46, 116, 24, 228, 185, 207,
25, 123,
];

parachain_asset_location!(
BRZ,
X3(
Parachain(PARA_ID),
PalletInstance(ASSET_PALLET_INDEX),
AccountKey20 { network: None, key: BRZ_ASSET_ACCOUNT_IN_BYTES }
)
);

parachain_asset_location!(
GLMR,
X2(Parachain(PARA_ID), PalletInstance(BALANCES_PALLET_INDEX))
);
}

pub mod polkadex {
use xcm::latest::{Junction::Parachain, Junctions::X1};

pub const PARA_ID: u32 = 2040;

parachain_asset_location!(PDEX, X1(Parachain(PARA_ID)));
}
}

pub mod kusama {
/// values of kusama asset_hub is similar to polkadot's asset_hub
pub mod asset_hub {
pub use super::super::polkadot::asset_hub::*;
}
}

pub mod moonbase_alpha_relay {
pub mod moonbase_alpha {
use xcm::latest::{
Junction::{PalletInstance, Parachain},
Junctions::X2,
};

pub const PARA_ID: u32 = 1000;
pub const BALANCES_PALLET_INDEX: u8 = 3;

parachain_asset_location!(
DEV,
X2(Parachain(PARA_ID), PalletInstance(BALANCES_PALLET_INDEX))
);
}
}
}

#[cfg(test)]
mod tests {
gianfra-t marked this conversation as resolved.
Show resolved Hide resolved
use super::parachains::polkadot::*;
use crate::parachains::asset_hub;
use xcm::{
latest::prelude::{AccountKey20, PalletInstance, Parachain},
latest::prelude::{PalletInstance, Parachain},
prelude::GeneralIndex,
};

#[test]
fn test_BRZ() {
let brz_loc = moonbeam::BRZ_location();
let mut junctions = brz_loc.interior().into_iter();

assert_eq!(junctions.next(), Some(&Parachain(moonbeam::PARA_ID)));
assert_eq!(junctions.next(), Some(&PalletInstance(moonbeam::ASSET_PALLET_INDEX)));
assert_eq!(
junctions.next(),
Some(&AccountKey20 { network: None, key: moonbeam::BRZ_ASSET_ACCOUNT_IN_BYTES })
);
assert_eq!(junctions.next(), None);
}

#[test]
fn test_GLMR() {
let glmr_loc = moonbeam::GLMR_location();
let mut junctions = glmr_loc.interior().into_iter();

assert_eq!(junctions.next(), Some(&Parachain(moonbeam::PARA_ID)));
assert_eq!(junctions.next(), Some(&PalletInstance(moonbeam::BALANCES_PALLET_INDEX)));
assert_eq!(junctions.next(), None);
}

#[test]
fn test_PINK() {
let pink_loc = asset_hub::PINK_location();
Expand All @@ -288,17 +183,6 @@ mod tests {

#[test]
fn test_constants() {
let expected_EQ_value = 25_969;
assert_eq!(equilibrium::EQ_ASSET_ID, expected_EQ_value);

let eq_interior = equilibrium::EQ_location().interior;
let mut junctions = eq_interior.into_iter();

assert_eq!(junctions.next(), Some(Parachain(equilibrium::PARA_ID)));
assert_eq!(junctions.next(), Some(PalletInstance(equilibrium::ASSET_PALLET_INDEX)));
assert_eq!(junctions.next(), Some(GeneralIndex(equilibrium::EQ_ASSET_ID)));
assert_eq!(junctions.next(), None);

let expected_USDT_value = 1984;
assert_eq!(asset_hub::USDT_ASSET_ID, expected_USDT_value);
}
Expand Down
18 changes: 18 additions & 0 deletions runtime/foucoco/src/definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

pub mod moonbase_alpha_relay {
pub mod moonbase_alpha {
use runtime_common::parachain_asset_location;
use xcm::latest::{
Junction::{PalletInstance, Parachain},
Junctions::X2,
};

pub const PARA_ID: u32 = 1000;
pub const BALANCES_PALLET_INDEX: u8 = 3;

parachain_asset_location!(
DEV,
X2(Parachain(PARA_ID), PalletInstance(BALANCES_PALLET_INDEX))
);
}
}
1 change: 1 addition & 0 deletions runtime/foucoco/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod chain_ext;
mod weights;
pub mod xcm_config;
pub mod zenlink;
pub mod definitions;

use crate::zenlink::*;
use xcm::v3::MultiLocation;
Expand Down
7 changes: 4 additions & 3 deletions runtime/foucoco/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ use xcm_builder::{
};
use xcm_executor::{traits::ShouldExecute, XcmExecutor};

use runtime_common::parachains::moonbase_alpha_relay::moonbase_alpha;

use crate::assets::{
use crate::{
definitions::moonbase_alpha_relay::moonbase_alpha,
assets::{
native_locations::{native_location_external_pov, native_location_local_pov},
xcm_assets,
},
};

use super::{
Expand Down
2 changes: 1 addition & 1 deletion runtime/integration-tests/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sp_io::TestExternalities;
use sp_runtime::traits::AccountIdConversion;
use xcm_emulator::Weight;

use runtime_common::parachains::polkadot::moonbeam::PARA_ID as MOONBEAM_PARA_ID;
use pendulum_runtime::definitions::moonbeam::PARA_ID as MOONBEAM_PARA_ID;
use statemine_runtime as kusama_asset_hub_runtime;
use statemint_runtime as polkadot_asset_hub_runtime;

Expand Down
2 changes: 1 addition & 1 deletion runtime/integration-tests/src/pendulum_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};

use frame_support::assert_ok;
use runtime_common::parachains::polkadot::moonbeam::PARA_ID as MOONBEAM_PARA_ID;
use pendulum_runtime::definitions::moonbeam::PARA_ID as MOONBEAM_PARA_ID;
use statemint_runtime as polkadot_asset_hub_runtime;
use xcm::latest::NetworkId;
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt};
Expand Down
4 changes: 2 additions & 2 deletions runtime/integration-tests/src/sibling.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::MAXIMUM_BLOCK_WEIGHT;
use runtime_common::parachains::polkadot::asset_hub;
use runtime_common::parachains::asset_hub;
gianfra-t marked this conversation as resolved.
Show resolved Hide resolved
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::H256;
Expand Down Expand Up @@ -45,7 +45,7 @@ use xcm_builder::{

use crate::{AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID};

use runtime_common::parachains::polkadot::moonbeam::BRZ_location;
use pendulum_runtime::definitions::moonbeam::BRZ_location;

const XCM_ASSET_RELAY_DOT: u8 = 0;
const XCM_ASSET_ASSETHUB_USDT: u8 = 1;
Expand Down
112 changes: 112 additions & 0 deletions runtime/pendulum/src/definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

pub mod asset_hub {
use runtime_common::parachain_asset_location;

pub const PARA_ID: u32 = 1000;
pub const ASSET_PALLET_INDEX: u8 = 50;

parachain_asset_location!(USDC, 1337);
parachain_asset_location!(USDT, 1984);
parachain_asset_location!(PINK, 23);
}


pub mod equilibrium {

use runtime_common::parachain_asset_location;
pub const PARA_ID: u32 = 2011;
pub const ASSET_PALLET_INDEX: u8 = 11;

parachain_asset_location!(EQ, 25_969);
parachain_asset_location!(EQD, 6_648_164);
}

pub mod moonbeam {
use runtime_common::parachain_asset_location;
use xcm::latest::{
Junction::{AccountKey20, PalletInstance, Parachain},
Junctions::{X2, X3},
};

pub const PARA_ID: u32 = 2004;
pub const ASSET_PALLET_INDEX: u8 = 110;
pub const BALANCES_PALLET_INDEX: u8 = 10;

// The address of the BRZ token on Moonbeam `0x3225edCe8aD30Ae282e62fa32e7418E4b9cf197b` as byte array
pub const BRZ_ASSET_ACCOUNT_IN_BYTES: [u8; 20] = [
50, 37, 237, 206, 138, 211, 10, 226, 130, 230, 47, 163, 46, 116, 24, 228, 185, 207, 25, 123
];

parachain_asset_location!(
BRZ,
X3(
Parachain(PARA_ID),
PalletInstance(ASSET_PALLET_INDEX),
AccountKey20 { network: None, key: BRZ_ASSET_ACCOUNT_IN_BYTES }
)
);

parachain_asset_location!(
GLMR,
X2(Parachain(PARA_ID), PalletInstance(BALANCES_PALLET_INDEX))
);
}

pub mod polkadex {
use runtime_common::parachain_asset_location;
use xcm::latest::{Junction::Parachain, Junctions::X1};

pub const PARA_ID: u32 = 2040;

parachain_asset_location!(PDEX, X1(Parachain(PARA_ID)));
}

#[cfg(test)]
mod tests {
use super::{polkadex, equilibrium, moonbeam};
use xcm::{
latest::prelude::{AccountKey20, PalletInstance, Parachain},
prelude::GeneralIndex,
};

#[test]
fn test_BRZ() {
let brz_loc = moonbeam::BRZ_location();
let mut junctions = brz_loc.interior().into_iter();

assert_eq!(junctions.next(), Some(&Parachain(moonbeam::PARA_ID)));
assert_eq!(junctions.next(), Some(&PalletInstance(moonbeam::ASSET_PALLET_INDEX)));
assert_eq!(
junctions.next(),
Some(&AccountKey20 { network: None, key: moonbeam::BRZ_ASSET_ACCOUNT_IN_BYTES })
);
assert_eq!(junctions.next(), None);
}

#[test]
fn test_GLMR() {
let glmr_loc = moonbeam::GLMR_location();
let mut junctions = glmr_loc.interior().into_iter();

assert_eq!(junctions.next(), Some(&Parachain(moonbeam::PARA_ID)));
assert_eq!(junctions.next(), Some(&PalletInstance(moonbeam::BALANCES_PALLET_INDEX)));
assert_eq!(junctions.next(), None);
}



#[test]
fn test_constants() {
let expected_EQ_value = 25_969;
assert_eq!(equilibrium::EQ_ASSET_ID, expected_EQ_value);

let eq_interior = equilibrium::EQ_location().interior;
let mut junctions = eq_interior.into_iter();

assert_eq!(junctions.next(), Some(Parachain(equilibrium::PARA_ID)));
assert_eq!(junctions.next(), Some(PalletInstance(equilibrium::ASSET_PALLET_INDEX)));
assert_eq!(junctions.next(), Some(GeneralIndex(equilibrium::EQ_ASSET_ID)));
assert_eq!(junctions.next(), None);

}
}
1 change: 1 addition & 0 deletions runtime/pendulum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod chain_ext;
mod weights;
pub mod xcm_config;
pub mod zenlink;
pub mod definitions;

use crate::zenlink::*;
use xcm::v3::MultiLocation;
Expand Down
3 changes: 2 additions & 1 deletion runtime/pendulum/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use xcm_executor::{

use runtime_common::{
custom_transactor::{AssetData, AutomationPalletConfig, CustomTransactorInterceptor},
parachains::polkadot::{asset_hub, equilibrium, moonbeam, polkadex},

RelativeValue,
};

Expand All @@ -50,6 +50,7 @@ use crate::{
xcm_assets,
},
ConstU32,
definitions::{asset_hub, equilibrium, moonbeam, polkadex}
};

use super::{
Expand Down
Loading