diff --git a/Cargo.lock b/Cargo.lock index dd692ac80..8bd0e6266 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10415,6 +10415,7 @@ dependencies = [ "pallet-xcm", "parachain-info", "parity-scale-codec", + "paste", "pendulum-runtime", "polkadot-core-primitives", "polkadot-parachain", diff --git a/runtime/amplitude/src/assets.rs b/runtime/amplitude/src/assets.rs deleted file mode 100644 index 05b5ab718..000000000 --- a/runtime/amplitude/src/assets.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![allow(non_snake_case)] - -pub mod xcm_assets { - use runtime_common::create_xcm_id; - - create_xcm_id!(RELAY_KSM, 0); - create_xcm_id!(ASSETHUB_USDT, 1); -} - -/// Locations for native currency and all natively issued tokens -pub mod native_locations { - use crate::ParachainInfo; - use frame_support::traits::PalletInfoAccess; - use xcm::latest::{ - Junction::{PalletInstance, Parachain}, - Junctions::{X1, X2}, - MultiLocation, - }; - - fn balances_pallet_id() -> u8 { - crate::Balances::index() as u8 - } - - /// location of the native currency from the point of view of Amplitude parachain - pub fn native_location_local_pov() -> MultiLocation { - MultiLocation { parents: 0, interior: X1(PalletInstance(balances_pallet_id())) } - } - - /// location of the native currency from the point of view of other parachains(external) - pub fn native_location_external_pov() -> MultiLocation { - MultiLocation { - parents: 1, - interior: X2( - Parachain(ParachainInfo::parachain_id().into()), - PalletInstance(balances_pallet_id()), - ), - } - } -} diff --git a/runtime/amplitude/src/definitions.rs b/runtime/amplitude/src/definitions.rs new file mode 100644 index 000000000..e69de29bb diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 99dd3fad5..264631a73 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -6,11 +6,11 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -mod assets; mod chain_ext; mod weights; pub mod xcm_config; pub mod zenlink; +pub mod definitions; use crate::zenlink::*; use bifrost_farming as farming; diff --git a/runtime/common/src/chain_ext.rs b/runtime/common/src/chain_ext.rs deleted file mode 100644 index d16183699..000000000 --- a/runtime/common/src/chain_ext.rs +++ /dev/null @@ -1,300 +0,0 @@ -use crate::*; -use dia_oracle::dia; -use scale_info::prelude::vec::Vec; -use sp_core::{Decode, Encode, MaxEncodedLen}; -use sp_runtime::{codec, ArithmeticError, TokenError}; - -pub use spacewalk_primitives::{Asset, CurrencyId}; - -/// Address is a type alias for easier readability of address (accountId) communicated between contract and chain extension. -pub type Address = [u8; 32]; -/// Amount is a type alias for easier readability of amount communicated between contract and chain extension. -pub type Amount = u128; -/// Blockchain is a type alias for easier readability of dia blockchain name communicated between contract and chain extension. -pub type Blockchain = [u8; 32]; -/// Symbol is a type alias for easier readability of dia blockchain symbol communicated between contract and chain extension. -pub type Symbol = [u8; 32]; - -/// ChainExtensionOutcome is almost the same as DispatchError, but with some modifications to make it compatible with being communicated between contract and chain extension. It implements the necessary From conversions with DispatchError and other nested errors. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum ChainExtensionOutcome { - /// Chain extension function executed correctly - Success, - /// Some error occurred. - Other, - /// Failed to lookup some data. - CannotLookup, - /// A bad origin. - BadOrigin, - /// A custom error in a module. - Module, - /// At least one consumer is remaining so the account cannot be destroyed. - ConsumerRemaining, - /// There are no providers so the account cannot be created. - NoProviders, - /// There are too many consumers so the account cannot be created. - TooManyConsumers, - /// Cannot decode - DecodingError, - /// Failed to save some data - WriteError, - /// Function id not implemented for chain extension - UnimplementedFuncId, - /// An error to do with tokens. - Token(ChainExtensionTokenError), - /// An arithmetic error. - Arithmetic(ChainExtensionArithmeticError), - /// Unknown error - Unknown, -} - -/// ChainExtensionTokenError is a nested error in ChainExtensionOutcome, similar to DispatchError's TokenError. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum ChainExtensionTokenError { - /// Account cannot exist with the funds that would be given. - BelowMinimum, - /// Account cannot be created. - CannotCreate, - /// The asset in question is unknown. - UnknownAsset, - /// Funds exist but are frozen. - Frozen, - /// Operation is not supported by the asset. - Unsupported, - /// Unknown error - Unknown, - /// Funds are unavailable. - FundsUnavailable, - /// Some part of the balance gives the only provider reference to the account and thus cannot - /// be (re)moved. - OnlyProvider, - /// Account cannot be created for a held balance. - CannotCreateHold, - /// Withdrawal would cause unwanted loss of account. - NotExpendable, -} - -/// ChainExtensionArithmeticError is a nested error in ChainExtensionOutcome, similar to DispatchError's ArithmeticError. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum ChainExtensionArithmeticError { - /// Underflow. - Underflow, - /// Overflow. - Overflow, - /// Division by zero. - DivisionByZero, - /// Unknown error - Unknown, -} - -impl From for ChainExtensionOutcome { - fn from(e: DispatchError) -> Self { - match e { - DispatchError::Other(_) => ChainExtensionOutcome::Other, - DispatchError::CannotLookup => ChainExtensionOutcome::CannotLookup, - DispatchError::BadOrigin => ChainExtensionOutcome::BadOrigin, - DispatchError::Module(_) => ChainExtensionOutcome::Module, - DispatchError::ConsumerRemaining => ChainExtensionOutcome::ConsumerRemaining, - DispatchError::NoProviders => ChainExtensionOutcome::NoProviders, - DispatchError::TooManyConsumers => ChainExtensionOutcome::TooManyConsumers, - DispatchError::Token(token_err) => - ChainExtensionOutcome::Token(ChainExtensionTokenError::from(token_err)), - DispatchError::Arithmetic(arithmetic_error) => ChainExtensionOutcome::Arithmetic( - ChainExtensionArithmeticError::from(arithmetic_error), - ), - _ => ChainExtensionOutcome::Unknown, - } - } -} - -impl From for ChainExtensionTokenError { - fn from(e: TokenError) -> Self { - match e { - TokenError::BelowMinimum => ChainExtensionTokenError::BelowMinimum, - TokenError::CannotCreate => ChainExtensionTokenError::CannotCreate, - TokenError::UnknownAsset => ChainExtensionTokenError::UnknownAsset, - TokenError::Frozen => ChainExtensionTokenError::Frozen, - TokenError::Unsupported => ChainExtensionTokenError::Unsupported, - TokenError::FundsUnavailable => ChainExtensionTokenError::FundsUnavailable, - TokenError::OnlyProvider => ChainExtensionTokenError::OnlyProvider, - TokenError::CannotCreateHold => ChainExtensionTokenError::CannotCreateHold, - TokenError::NotExpendable => ChainExtensionTokenError::NotExpendable, - } - } -} - -impl From for ChainExtensionArithmeticError { - fn from(e: ArithmeticError) -> Self { - match e { - ArithmeticError::Underflow => ChainExtensionArithmeticError::Underflow, - ArithmeticError::Overflow => ChainExtensionArithmeticError::Overflow, - ArithmeticError::DivisionByZero => ChainExtensionArithmeticError::DivisionByZero, - } - } -} - -/// ToTrimmedVec is a trait implemented for [u8; 32] to allow both types Blockchain and Symbol (which are [u8; 32]) to have the trim_trailing_zeros function. -pub trait ToTrimmedVec { - fn to_trimmed_vec(&self) -> Vec; -} -impl ToTrimmedVec for [u8; 32] { - fn to_trimmed_vec(&self) -> Vec { - trim_trailing_zeros(self).to_vec() - } -} - -/// trim_trailing_zeros takes an input slice and returns it without the trailing zeros. -fn trim_trailing_zeros(slice: &[u8]) -> &[u8] { - let mut trim_amount = 0; - for el in slice.iter().rev() { - if *el == 0 { - trim_amount += 1; - } else { - break - } - } - &slice[..slice.len() - trim_amount] -} - -/// CoinInfo is almost the same as Dia's CoinInfo, but with Encode, Decode, and TypeInfo which are necessary for contract to chain extension communication. Implements From to make conversion. -#[derive(Debug, Clone, PartialEq, Eq, codec::Encode, codec::Decode)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub struct CoinInfo { - pub symbol: Vec, - pub name: Vec, - pub blockchain: Vec, - pub supply: u128, - pub last_update_timestamp: u64, - pub price: u128, -} -impl From for CoinInfo { - fn from(coin_info: dia::CoinInfo) -> Self { - Self { - symbol: coin_info.symbol, - name: coin_info.name, - blockchain: coin_info.blockchain, - supply: coin_info.supply, - last_update_timestamp: coin_info.last_update_timestamp, - price: coin_info.price, - } - } -} - -/// decode gets the slice from a Vec to decode it into its scale encoded type. -pub fn decode(input: Vec) -> Result { - let mut input = input.as_slice(); - T::decode(&mut input) -} - -impl ChainExtensionOutcome { - pub fn as_u32(&self) -> u32 { - match self { - ChainExtensionOutcome::Success => 0, - ChainExtensionOutcome::Other => 1, - ChainExtensionOutcome::CannotLookup => 2, - ChainExtensionOutcome::BadOrigin => 3, - ChainExtensionOutcome::Module => 4, - ChainExtensionOutcome::ConsumerRemaining => 5, - ChainExtensionOutcome::NoProviders => 6, - ChainExtensionOutcome::TooManyConsumers => 7, - ChainExtensionOutcome::DecodingError => 8, - ChainExtensionOutcome::WriteError => 9, - ChainExtensionOutcome::UnimplementedFuncId => 10, - ChainExtensionOutcome::Token(token_error) => 1000 + token_error.as_u32(), - ChainExtensionOutcome::Arithmetic(arithmetic_error) => 2000 + arithmetic_error.as_u32(), - ChainExtensionOutcome::Unknown => 999, - } - } -} - -impl ChainExtensionTokenError { - pub fn as_u32(&self) -> u32 { - match self { - ChainExtensionTokenError::FundsUnavailable => 0, - ChainExtensionTokenError::NotExpendable => 1, - ChainExtensionTokenError::BelowMinimum => 2, - ChainExtensionTokenError::CannotCreate => 3, - ChainExtensionTokenError::UnknownAsset => 4, - ChainExtensionTokenError::Frozen => 5, - ChainExtensionTokenError::Unsupported => 6, - ChainExtensionTokenError::OnlyProvider => 7, - ChainExtensionTokenError::CannotCreateHold => 8, - ChainExtensionTokenError::Unknown => 999, - } - } -} - -impl ChainExtensionArithmeticError { - pub fn as_u32(&self) -> u32 { - match self { - ChainExtensionArithmeticError::Underflow => 0, - ChainExtensionArithmeticError::Overflow => 1, - ChainExtensionArithmeticError::DivisionByZero => 2, - ChainExtensionArithmeticError::Unknown => 999, - } - } -} - -impl TryFrom for ChainExtensionOutcome { - type Error = DispatchError; - - fn try_from(value: u32) -> Result { - match value { - 0 => Ok(ChainExtensionOutcome::Success), - 1 => Ok(ChainExtensionOutcome::Other), - 2 => Ok(ChainExtensionOutcome::CannotLookup), - 3 => Ok(ChainExtensionOutcome::BadOrigin), - 4 => Ok(ChainExtensionOutcome::Module), - 5 => Ok(ChainExtensionOutcome::ConsumerRemaining), - 6 => Ok(ChainExtensionOutcome::NoProviders), - 7 => Ok(ChainExtensionOutcome::TooManyConsumers), - 8 => Ok(ChainExtensionOutcome::DecodingError), - 9 => Ok(ChainExtensionOutcome::WriteError), - 10 => Ok(ChainExtensionOutcome::UnimplementedFuncId), - 999 => Ok(ChainExtensionOutcome::Unknown), - 1000..=1999 => - Ok(ChainExtensionOutcome::Token(ChainExtensionTokenError::try_from(value - 1000)?)), - 2000..=2999 => Ok(ChainExtensionOutcome::Arithmetic( - ChainExtensionArithmeticError::try_from(value - 2000)?, - )), - _ => Err(DispatchError::Other("Invalid ChainExtensionOutcome value")), - } - } -} - -impl TryFrom for ChainExtensionTokenError { - type Error = DispatchError; - - fn try_from(value: u32) -> Result { - match value { - 0 => Ok(ChainExtensionTokenError::FundsUnavailable), - 1 => Ok(ChainExtensionTokenError::NotExpendable), - 2 => Ok(ChainExtensionTokenError::BelowMinimum), - 3 => Ok(ChainExtensionTokenError::CannotCreate), - 4 => Ok(ChainExtensionTokenError::UnknownAsset), - 5 => Ok(ChainExtensionTokenError::Frozen), - 6 => Ok(ChainExtensionTokenError::Unsupported), - 7 => Ok(ChainExtensionTokenError::OnlyProvider), - 8 => Ok(ChainExtensionTokenError::CannotCreateHold), - 999 => Ok(ChainExtensionTokenError::Unknown), - _ => Err(DispatchError::Other("Invalid ChainExtensionTokenError value")), - } - } -} - -impl TryFrom for ChainExtensionArithmeticError { - type Error = DispatchError; - - fn try_from(value: u32) -> Result { - match value { - 0 => Ok(ChainExtensionArithmeticError::Underflow), - 1 => Ok(ChainExtensionArithmeticError::Overflow), - 2 => Ok(ChainExtensionArithmeticError::DivisionByZero), - 999 => Ok(ChainExtensionArithmeticError::Unknown), - _ => Err(DispatchError::Other("Invalid ChainExtensionArithmeticError value")), - } - } -} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 323070fd2..bbe5cbc17 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -11,7 +11,6 @@ use orml_traits::asset_registry::Inspect; use asset_registry::CustomMetadata; pub mod asset_registry; -pub mod chain_ext; pub mod custom_transactor; mod proxy_type; pub mod stellar; @@ -106,6 +105,7 @@ pub mod parachains { } /// Creates a location for the given asset in this format: `fn _location() -> MultiLocation` + #[macro_export] macro_rules! parachain_asset_location { // Also declares a constant variable _ASSET_ID with . // This assumes that the following constant variables exist: @@ -142,88 +142,6 @@ 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)) - ); - } - } } /// CurrencyIdConvert @@ -266,65 +184,3 @@ impl u8 { - crate::Balances::index() as u8 - } - - /// location of the native currency from the point of view of Foucoco parachain - pub fn native_location_local_pov() -> MultiLocation { - MultiLocation { parents: 0, interior: X1(PalletInstance(balances_pallet_id())) } - } - - /// location of the native currency from the point of view of other parachains(external) - pub fn native_location_external_pov() -> MultiLocation { - MultiLocation { - parents: 1, - interior: X2( - Parachain(ParachainInfo::parachain_id().into()), - PalletInstance(balances_pallet_id()), - ), - } - } -} diff --git a/runtime/foucoco/src/definitions.rs b/runtime/foucoco/src/definitions.rs new file mode 100644 index 000000000..e69de29bb diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index bfbb5bc59..ba7bfdd10 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -6,11 +6,11 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -mod assets; mod chain_ext; mod weights; pub mod xcm_config; pub mod zenlink; +pub mod definitions; use crate::zenlink::*; use xcm::v3::MultiLocation; diff --git a/runtime/foucoco/src/xcm_config.rs b/runtime/foucoco/src/xcm_config.rs index 393eff381..7979cdab7 100644 --- a/runtime/foucoco/src/xcm_config.rs +++ b/runtime/foucoco/src/xcm_config.rs @@ -4,7 +4,7 @@ use frame_support::{ log, match_types, parameter_types, traits::{ConstU32, ContainsPair, Everything, Nothing, ProcessMessageError}, }; -use orml_asset_registry::{AssetRegistryTrader, FixedRateAssetRegistryTrader, AssetMetadata}; +use orml_asset_registry::{AssetRegistryTrader, FixedRateAssetRegistryTrader}; use orml_traits::{ location::{RelativeReserveProvider, Reserve}, parameter_type_with_key, @@ -21,13 +21,7 @@ use xcm_builder::{ }; use xcm_executor::{traits::ShouldExecute, XcmExecutor}; use cumulus_primitives_utility::XcmFeesTo32ByteAccount; - -use runtime_common::{asset_registry::FixedConversionRateProvider, CurrencyIdConvert, - asset_registry::CustomMetadata}; - -use crate::assets::{ - native_locations::{native_location_external_pov, native_location_local_pov}, -}; +use runtime_common::{CurrencyIdConvert, asset_registry::{ FixedConversionRateProvider}}; use super::{ AccountId, AssetRegistry, Balance, Balances, Currencies, CurrencyId, FoucocoTreasuryAccount, ParachainInfo, diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 1be4874f5..24c6ee3a8 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -9,6 +9,7 @@ version = "0.1.0" codec = { package = "parity-scale-codec", version = "3.0.0" } scale-info = { version = "2.1.2", features = ["derive"] } serde = { version = "1.0.144", features = ["derive"] } +paste = "1.0.14" # Spacewalk libraries spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "3c03e759a6f600ea72d636d4f9cc4b05d633201c" } diff --git a/runtime/integration-tests/src/definitions.rs b/runtime/integration-tests/src/definitions.rs new file mode 100644 index 000000000..aa9225ee2 --- /dev/null +++ b/runtime/integration-tests/src/definitions.rs @@ -0,0 +1,16 @@ + +pub mod xcm_assets { + use runtime_common::create_xcm_id; + create_xcm_id!(MOONBEAM_BRZ, 4); +} + +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!(USDT, 1984); + +} + diff --git a/runtime/integration-tests/src/lib.rs b/runtime/integration-tests/src/lib.rs index 9c48c76e8..39c762950 100644 --- a/runtime/integration-tests/src/lib.rs +++ b/runtime/integration-tests/src/lib.rs @@ -13,6 +13,9 @@ mod test_macros; #[cfg(test)] mod sibling; +#[cfg(test)] +mod definitions; + pub const PENDULUM_ID: u32 = 2094; pub const AMPLITUDE_ID: u32 = 2124; pub const ASSETHUB_ID: u32 = 1000; diff --git a/runtime/integration-tests/src/mock.rs b/runtime/integration-tests/src/mock.rs index 47adf9ce9..115a8e5e0 100644 --- a/runtime/integration-tests/src/mock.rs +++ b/runtime/integration-tests/src/mock.rs @@ -1,4 +1,5 @@ -use crate::{sibling, AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID, SIBLING_ID}; +use crate::{sibling, AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID, SIBLING_ID, + definitions::asset_hub}; use amplitude_runtime::CurrencyId as AmplitudeCurrencyId; use frame_support::traits::GenesisBuild; use pendulum_runtime::CurrencyId as PendulumCurrencyId; @@ -20,9 +21,7 @@ use xcm::{ VersionedMultiLocation, }; -use runtime_common::parachains::polkadot::{ - asset_hub, moonbeam, moonbeam::PARA_ID as MOONBEAM_PARA_ID, -}; +use pendulum_runtime::definitions::{moonbeam::PARA_ID as MOONBEAM_PARA_ID, moonbeam}; use statemine_runtime as kusama_asset_hub_runtime; use statemint_runtime as polkadot_asset_hub_runtime; diff --git a/runtime/integration-tests/src/pendulum_tests.rs b/runtime/integration-tests/src/pendulum_tests.rs index 80df82ece..384008fcc 100644 --- a/runtime/integration-tests/src/pendulum_tests.rs +++ b/runtime/integration-tests/src/pendulum_tests.rs @@ -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}; diff --git a/runtime/integration-tests/src/sibling.rs b/runtime/integration-tests/src/sibling.rs index 4b5cebd91..c228e5098 100644 --- a/runtime/integration-tests/src/sibling.rs +++ b/runtime/integration-tests/src/sibling.rs @@ -15,7 +15,6 @@ 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 scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use sp_core::H256; @@ -43,9 +42,9 @@ use xcm_builder::{ SignedToAccountId32, SovereignSignedViaLocation, }; -use crate::{AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID}; +use crate::{AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID, definitions::asset_hub}; -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; diff --git a/runtime/integration-tests/src/test_macros.rs b/runtime/integration-tests/src/test_macros.rs index 68e0298eb..88a2e3aa3 100644 --- a/runtime/integration-tests/src/test_macros.rs +++ b/runtime/integration-tests/src/test_macros.rs @@ -656,12 +656,13 @@ macro_rules! moonbeam_transfers_token_and_handle_automation { $parachain2_id:ident, $expected_fee:ident ) => {{ - use crate::mock::{units, ALICE}; + use crate::{mock::{units, ALICE}, definitions::xcm_assets}; + use polkadot_core_primitives::Balance; use xcm::latest::{ Junction, Junction::{ GeneralKey, PalletInstance}, Junctions::{X3}, MultiLocation, WeightLimit, }; - use pendulum_runtime::assets::xcm_assets; + use orml_traits::MultiCurrency; use $parachain1_runtime::CurrencyId as Parachain1CurrencyId; diff --git a/runtime/pendulum/src/assets.rs b/runtime/pendulum/src/assets.rs deleted file mode 100644 index a08a6e303..000000000 --- a/runtime/pendulum/src/assets.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![allow(non_snake_case)] - -pub mod xcm_assets { - use runtime_common::create_xcm_id; - - create_xcm_id!(RELAY_DOT, 0); - create_xcm_id!(ASSETHUB_USDT, 1); - create_xcm_id!(ASSETHUB_USDC, 2); - create_xcm_id!(EQUILIBRIUM_EQD, 3); - create_xcm_id!(MOONBEAM_BRZ, 4); - create_xcm_id!(POLKADEX_PDEX, 5); - create_xcm_id!(MOONBEAM_GLMR, 6); - create_xcm_id!(ASSETHUB_PINK, 7); -} - -/// Locations for native currency and all natively issued tokens -pub mod native_locations { - use crate::ParachainInfo; - use frame_support::traits::PalletInfoAccess; - use xcm::latest::{ - Junction::{GeneralIndex, PalletInstance, Parachain}, - Junctions::{X1, X2, X3, X4}, - MultiLocation, - }; - - const TOKEN_IN_CURRENCY_ID: u128 = 4; - - fn tokens_pallet_id() -> u8 { - crate::Tokens::index() as u8 - } - - fn balances_pallet_id() -> u8 { - crate::Balances::index() as u8 - } - - /// location of the native currency from the point of view of Pendulum parachain - pub fn native_location_local_pov() -> MultiLocation { - MultiLocation { parents: 0, interior: X1(PalletInstance(balances_pallet_id())) } - } - - /// location of the native currency from the point of view of other parachains(external) - pub fn native_location_external_pov() -> MultiLocation { - MultiLocation { - parents: 1, - interior: X2( - Parachain(ParachainInfo::parachain_id().into()), - PalletInstance(balances_pallet_id()), - ), - } - } - - /// EURC location from the point of view of Pendulum parachain - pub fn EURC_location_local_pov() -> MultiLocation { - MultiLocation { - parents: 0, - interior: X3( - PalletInstance(tokens_pallet_id()), - GeneralIndex(TOKEN_IN_CURRENCY_ID), // index of the Token variant of CurrencyId enum - GeneralIndex(super::tokens::EURC_TOKEN_INDEX as u128), - ), - } - } - - /// EURC location from the point of view of other parachains(external) - pub fn EURC_location_external_pov() -> MultiLocation { - MultiLocation { - parents: 1, - interior: X4( - Parachain(ParachainInfo::parachain_id().into()), - PalletInstance(tokens_pallet_id()), - GeneralIndex(TOKEN_IN_CURRENCY_ID), - GeneralIndex(super::tokens::EURC_TOKEN_INDEX as u128), - ), - } - } -} - -/// Tokens issued by Pendulum -pub mod tokens { - use spacewalk_primitives::CurrencyId; - - // The index of EURC in the token variant of CurrencyId - pub const EURC_TOKEN_INDEX: u64 = 0; - - pub const EURC_ID: CurrencyId = CurrencyId::Token(EURC_TOKEN_INDEX); -} diff --git a/runtime/pendulum/src/definitions.rs b/runtime/pendulum/src/definitions.rs new file mode 100644 index 000000000..c0a4d4303 --- /dev/null +++ b/runtime/pendulum/src/definitions.rs @@ -0,0 +1,50 @@ + +pub mod moonbeam { + use runtime_common::{parachain_asset_location}; + use xcm::latest::{ + Junction::{AccountKey20, PalletInstance, Parachain}, + Junctions::{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 } + ) + ); + +} + +#[cfg(test)] +mod tests { + use super::{moonbeam}; + use xcm::{ + latest::prelude::{AccountKey20, PalletInstance, Parachain}, + }; + + #[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); + } + +} \ No newline at end of file diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index 78d52335a..6729f47de 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -6,11 +6,11 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -pub mod assets; mod chain_ext; mod weights; pub mod xcm_config; pub mod zenlink; +pub mod definitions; use crate::zenlink::*; use xcm::v3::MultiLocation; diff --git a/runtime/pendulum/src/xcm_config.rs b/runtime/pendulum/src/xcm_config.rs index 9c82d63b2..c39fe5e7f 100644 --- a/runtime/pendulum/src/xcm_config.rs +++ b/runtime/pendulum/src/xcm_config.rs @@ -26,11 +26,12 @@ use xcm_executor::{traits::ShouldExecute, XcmExecutor}; use runtime_common::{ custom_transactor::{AssetData, AutomationPalletConfig, CustomTransactorInterceptor}, - parachains::polkadot::{moonbeam}, asset_registry::{ FixedConversionRateProvider}, CurrencyIdConvert, }; +use crate::definitions::moonbeam; + use crate::ConstU32; use super::{