diff --git a/Cargo.lock b/Cargo.lock index b9473ae83..6872aacdf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -954,6 +954,7 @@ name = "bifrost-salp" version = "0.8.0" dependencies = [ "bifrost-asset-registry", + "cumulus-primitives-core", "frame-benchmarking", "frame-support", "frame-system", diff --git a/integration-tests/src/flexible_fee.rs b/integration-tests/src/flexible_fee.rs index b563cab55..49d63125a 100644 --- a/integration-tests/src/flexible_fee.rs +++ b/integration-tests/src/flexible_fee.rs @@ -25,6 +25,7 @@ use frame_support::{ weights::{GetDispatchInfo, Pays, PostDispatchInfo}, }; use frame_system::pallet_prelude::BlockNumberFor; +use node_primitives::TryConvertFrom; use pallet_transaction_payment::OnChargeTransaction; use sp_runtime::testing::TestXt; use xcm_emulator::TestExt; @@ -172,11 +173,17 @@ fn basic_setup() { )); // create DEX pair - let asset_0_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_0).unwrap(); - let asset_1_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_1).unwrap(); - let asset_2_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_2).unwrap(); - let asset_3_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_3).unwrap(); - let asset_4_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_4).unwrap(); + let parachain_id: u32 = 2001; + let asset_0_currency_id: AssetId = + AssetId::try_convert_from(CURRENCY_ID_0, parachain_id).unwrap(); + let asset_1_currency_id: AssetId = + AssetId::try_convert_from(CURRENCY_ID_1, parachain_id).unwrap(); + let asset_2_currency_id: AssetId = + AssetId::try_convert_from(CURRENCY_ID_2, parachain_id).unwrap(); + let asset_3_currency_id: AssetId = + AssetId::try_convert_from(CURRENCY_ID_3, parachain_id).unwrap(); + let asset_4_currency_id: AssetId = + AssetId::try_convert_from(CURRENCY_ID_4, parachain_id).unwrap(); assert_ok!(ZenlinkProtocol::create_pair( Origin::root(), diff --git a/integration-tests/src/slp.rs b/integration-tests/src/slp.rs index 66fed9c2f..0a7767981 100644 --- a/integration-tests/src/slp.rs +++ b/integration-tests/src/slp.rs @@ -94,6 +94,27 @@ fn register_subaccount_index_0() { Delays { unlock_delay: TimeUnit::Era(10), leave_delegators_delay: Default::default() }; assert_ok!(Slp::set_currency_delays(Origin::root(), RelayCurrencyId::get(), Some(delay))); + let mins_and_maxs = MinimumsMaximums { + delegator_bonded_minimum: 100_000_000_000, + bond_extra_minimum: 0, + unbond_minimum: 0, + rebond_minimum: 0, + unbond_record_maximum: 32, + validators_back_maximum: 36, + delegator_active_staking_maximum: 200_000_000_000_000, + validators_reward_maximum: 0, + delegation_amount_minimum: 0, + delegators_maximum: 100, + validators_maximum: 300, + }; + + // Set minimums and maximums + assert_ok!(Slp::set_minimums_and_maximums( + Origin::root(), + RelayCurrencyId::get(), + Some(mins_and_maxs) + )); + // First to setup index-multilocation relationship of subaccount_0 assert_ok!(Slp::add_delegator( Origin::root(), @@ -172,27 +193,6 @@ fn register_subaccount_index_0() { XcmOperation::TransferBack, Some((20_000_000_000, 10_000_000_000)), )); - - let mins_and_maxs = MinimumsMaximums { - delegator_bonded_minimum: 100_000_000_000, - bond_extra_minimum: 0, - unbond_minimum: 0, - rebond_minimum: 0, - unbond_record_maximum: 32, - validators_back_maximum: 36, - delegator_active_staking_maximum: 200_000_000_000_000, - validators_reward_maximum: 0, - delegation_amount_minimum: 0, - delegators_maximum: 100, - validators_maximum: 300, - }; - - // Set minimums and maximums - assert_ok!(Slp::set_minimums_and_maximums( - Origin::root(), - RelayCurrencyId::get(), - Some(mins_and_maxs) - )); }); } @@ -242,6 +242,27 @@ fn register_validators() { let multi_hash_0 = ::Hashing::hash(&validator_0_location.encode()); + let mins_and_maxs = MinimumsMaximums { + delegator_bonded_minimum: 100_000_000_000, + bond_extra_minimum: 0, + unbond_minimum: 0, + rebond_minimum: 0, + unbond_record_maximum: 32, + validators_back_maximum: 36, + delegator_active_staking_maximum: 200_000_000_000_000, + validators_reward_maximum: 0, + delegation_amount_minimum: 0, + delegators_maximum: 100, + validators_maximum: 300, + }; + + // Set minimums and maximums + assert_ok!(Slp::set_minimums_and_maximums( + Origin::root(), + RelayCurrencyId::get(), + Some(mins_and_maxs) + )); + // Set delegator ledger assert_ok!(Slp::add_validator( Origin::root(), @@ -641,9 +662,9 @@ fn rebond_works() { #[test] fn delegate_works() { // bond 1 ksm for sub-account index 0 - register_validators(); locally_bond_subaccount_0_1ksm_in_kusama(); register_subaccount_index_0(); + register_validators(); register_delegator_ledger(); let subaccount_0 = subaccount_0(); diff --git a/integration-tests/src/treasury.rs b/integration-tests/src/treasury.rs index ed530c2a1..bf396ed2c 100644 --- a/integration-tests/src/treasury.rs +++ b/integration-tests/src/treasury.rs @@ -21,6 +21,7 @@ use frame_support::assert_ok; use xcm_emulator::TestExt; // use node_primitives::*; // use zenlink_protocol::LIQUIDITY; +use node_primitives::TryConvertFrom; use sp_runtime::AccountId32; // use bifrost_polkadot_runtime::Permill; @@ -40,6 +41,7 @@ fn kusama_treasury_propose_spend() { #[test] fn bifrost_treasury_operations() { + let para_id = 2001u32; let treasury_account: AccountId32 = bifrost_kusama_runtime::TreasuryPalletId::get().into_account_truncating(); Bifrost::execute_with(|| { @@ -68,14 +70,14 @@ fn bifrost_treasury_operations() { assert_ok!(bifrost_kusama_runtime::ZenlinkProtocol::create_pair( bifrost_kusama_runtime::Origin::root(), - zenlink_protocol::AssetId::try_from(KSM).unwrap(), - zenlink_protocol::AssetId::try_from(VKSM).unwrap(), + zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), + zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), )); assert_ok!(bifrost_kusama_runtime::ZenlinkProtocol::add_liquidity( bifrost_kusama_runtime::Origin::signed(treasury_account.clone()), - zenlink_protocol::AssetId::try_from(KSM).unwrap(), - zenlink_protocol::AssetId::try_from(VKSM).unwrap(), + zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), + zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), 25_000_000_000_000_000, 25_000_000_000_000_000, 0, @@ -84,8 +86,8 @@ fn bifrost_treasury_operations() { )); let lp_asset_id = bifrost_kusama_runtime::ZenlinkProtocol::lp_asset_id( - &zenlink_protocol::AssetId::try_from(KSM).unwrap(), - &zenlink_protocol::AssetId::try_from(VKSM).unwrap(), + &zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), + &zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), ); let lp = bifrost_kusama_runtime::ZenlinkProtocol::foreign_balance_of( @@ -95,8 +97,8 @@ fn bifrost_treasury_operations() { assert_ok!(bifrost_kusama_runtime::ZenlinkProtocol::remove_liquidity( bifrost_kusama_runtime::Origin::signed(treasury_account.clone()), - zenlink_protocol::AssetId::try_from(KSM).unwrap(), - zenlink_protocol::AssetId::try_from(VKSM).unwrap(), + zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), + zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), lp, 0, 0, diff --git a/node/primitives/Cargo.toml b/node/primitives/Cargo.toml index 4719236ba..ea10ed1cf 100644 --- a/node/primitives/Cargo.toml +++ b/node/primitives/Cargo.toml @@ -6,8 +6,12 @@ edition = "2021" [dependencies] bstringify = "0.1.2" -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [ + "derive", +] } +scale-info = { version = "2.1.2", default-features = false, features = [ + "derive", +] } serde = { version = "1.0.143", optional = true, features = ["derive"] } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } @@ -29,3 +33,11 @@ std = [ "sp-std/std", "zenlink-protocol/std", ] + +with-bifrost-runtime = [ + "with-bifrost-kusama-runtime", + "with-bifrost-polkadot-runtime", +] +with-bifrost-kusama-runtime = [] +with-bifrost-polkadot-runtime = [] +with-all-runtime = ["with-bifrost-runtime"] diff --git a/node/primitives/src/currency.rs b/node/primitives/src/currency.rs index 8ae6b2f65..f1007d424 100644 --- a/node/primitives/src/currency.rs +++ b/node/primitives/src/currency.rs @@ -32,9 +32,9 @@ use zenlink_protocol::{AssetId, LOCAL, NATIVE}; use crate::{ traits::{CurrencyIdExt, TokenInfo}, - LeasePeriod, ParaId, + LeasePeriod, ParaId, TryConvertFrom, }; -pub const BIFROST_PARACHAIN_ID: u32 = 2001; // bifrost parachain id + pub const DOT_TOKEN_ID: u8 = 0u8; pub const DOT: CurrencyId = CurrencyId::Token2(DOT_TOKEN_ID); pub const GLMR_TOKEN_ID: u8 = 1u8; @@ -71,14 +71,14 @@ macro_rules! create_currency_id { } } - impl TryFrom for AssetId { + impl TryConvertFrom for AssetId { // DATA LAYOUT // // Empty: 2bytes // Currency Discriminant: 1byte // TokenSymbol Index: 1byte type Error = (); - fn try_from(id: CurrencyId) -> Result { + fn try_convert_from(id: CurrencyId, para_id: u32) -> Result { let _index = match id { $(CurrencyId::Native(TokenSymbol::$symbol) => Ok((0_u64, TokenSymbol::$symbol as u64)),)* $(CurrencyId::VToken(TokenSymbol::$symbol) => Ok((1_u64, TokenSymbol::$symbol as u64)),)* @@ -100,10 +100,10 @@ macro_rules! create_currency_id { }; let asset_index = ((_index?.0 << 8) & 0x0000_ff00) + (_index?.1 & 0x0000_00ff); if id.is_native() { - Ok(AssetId { chain_id: BIFROST_PARACHAIN_ID, asset_type: NATIVE, asset_index: 0 }) + Ok(AssetId { chain_id: para_id, asset_type: NATIVE, asset_index: 0 }) } else { Ok(AssetId { - chain_id: BIFROST_PARACHAIN_ID, + chain_id: para_id, asset_type: LOCAL, asset_index: asset_index as u64, }) diff --git a/node/primitives/src/traits.rs b/node/primitives/src/traits.rs index 3be1e3e4d..e3ab8e3d5 100644 --- a/node/primitives/src/traits.rs +++ b/node/primitives/src/traits.rs @@ -207,3 +207,10 @@ pub trait VtokenMintingInterface { fn vtoken_id(token_id: CurrencyId) -> Option; fn token_id(vtoken_id: CurrencyId) -> Option; } + +pub trait TryConvertFrom { + type Error; + fn try_convert_from(currency_id: CurrencyId, para_id: u32) -> Result + where + Self: Sized; +} diff --git a/pallets/flexible-fee/Cargo.toml b/pallets/flexible-fee/Cargo.toml index fb9bec3b3..3ef9b1432 100644 --- a/pallets/flexible-fee/Cargo.toml +++ b/pallets/flexible-fee/Cargo.toml @@ -5,8 +5,12 @@ authors = ["Herry Ho "] edition = "2021" [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [ + "derive", +] } +scale-info = { version = "2.1.2", default-features = false, features = [ + "derive", +] } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } @@ -18,6 +22,8 @@ node-primitives = { path = "../../node/primitives", default-features = false } zenlink-protocol = { version = "*", default-features = false } orml-traits = { version = "0.4.1-dev", default-features = false } impl-trait-for-tuples = "0.2.1" +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.26", default-features = false } +bifrost-asset-registry = { path = "../../pallets/asset-registry", default-features = false } [dev-dependencies] orml-tokens = "0.4.1-dev" @@ -31,7 +37,7 @@ bifrost-salp = { path = "../salp" } bifrost-asset-registry = { path = "../asset-registry" } bifrost-kusama-runtime = { path = "../../runtime/bifrost-kusama" } bifrost-runtime-common = { path = "../../runtime/common" } -xcm-interface = { path = "../xcm-interface"} +xcm-interface = { path = "../xcm-interface" } [features] default = ["std"] @@ -46,6 +52,7 @@ std = [ "pallet-transaction-payment/std", "zenlink-protocol/std", "sp-arithmetic/std", + "cumulus-primitives-core/std", "bifrost-asset-registry/std", ] diff --git a/pallets/flexible-fee/src/lib.rs b/pallets/flexible-fee/src/lib.rs index 1f94b984a..484a775ce 100644 --- a/pallets/flexible-fee/src/lib.rs +++ b/pallets/flexible-fee/src/lib.rs @@ -19,8 +19,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(deprecated)] // TODO: clear transaction -use core::convert::{Into, TryFrom}; +use core::convert::Into; +use cumulus_primitives_core::ParaId; use frame_support::{ pallet_prelude::*, traits::{ @@ -30,7 +31,7 @@ use frame_support::{ transactional, }; use frame_system::pallet_prelude::*; -use node_primitives::{CurrencyId, ExtraFeeName, TokenSymbol}; +use node_primitives::{CurrencyId, ExtraFeeName, TokenSymbol, TryConvertFrom}; use orml_traits::MultiCurrency; pub use pallet::*; use pallet_transaction_payment::OnChargeTransaction; @@ -103,6 +104,8 @@ pub mod pallet { /// Alternative Fee currency exchange rate: ?x Fee currency: ?y Native currency #[pallet::constant] type AltFeeCurrencyExchangeRate: Get<(u32, u32)>; + + type ParachainId: Get; } pub type AccountIdOf = ::AccountId; @@ -326,10 +329,14 @@ impl FeeDealer, CurrencyIdOf> for if let Some((currency_id, amount_in, amount_out)) = result_option { if currency_id != T::NativeCurrencyId::get() { - let native_asset_id: AssetId = AssetId::try_from(T::NativeCurrencyId::get()) - .map_err(|_| DispatchError::Other("Conversion Error."))?; - let asset_id: AssetId = AssetId::try_from(currency_id) - .map_err(|_| DispatchError::Other("Conversion Error."))?; + let native_asset_id: AssetId = AssetId::try_convert_from( + T::NativeCurrencyId::get(), + T::ParachainId::get().into(), + ) + .map_err(|_| DispatchError::Other("Conversion Error."))?; + let asset_id: AssetId = + AssetId::try_convert_from(currency_id, T::ParachainId::get().into()) + .map_err(|_| DispatchError::Other("Conversion Error."))?; let path = vec![asset_id, native_asset_id]; T::DexOperator::inner_swap_assets_for_exact_assets( @@ -399,8 +406,11 @@ impl Pallet { // If it is other assets // If native token balance is below existential deposit requirement, // go exchange fee + existential deposit. Else to exchange fee amount. - let native_asset_id: AssetId = AssetId::try_from(T::NativeCurrencyId::get()) - .map_err(|_| Error::::ConversionError)?; + let native_asset_id: AssetId = AssetId::try_convert_from( + T::NativeCurrencyId::get(), + T::ParachainId::get().into(), + ) + .map_err(|_| Error::::ConversionError)?; let amount_out: AssetBalance = { if native_balance > existential_deposit { @@ -411,7 +421,8 @@ impl Pallet { }; let asset_id: AssetId = - AssetId::try_from(currency_id).map_err(|_| Error::::ConversionError)?; + AssetId::try_convert_from(currency_id, T::ParachainId::get().into()) + .map_err(|_| Error::::ConversionError)?; let path = vec![asset_id, native_asset_id]; // see if path exists, if not, continue. diff --git a/pallets/flexible-fee/src/mock.rs b/pallets/flexible-fee/src/mock.rs index f9973d5e8..68b4eb9fc 100644 --- a/pallets/flexible-fee/src/mock.rs +++ b/pallets/flexible-fee/src/mock.rs @@ -18,6 +18,7 @@ #![cfg(test)] +use cumulus_primitives_core::ParaId as Pid; use std::convert::TryInto; use bifrost_asset_registry::AssetIdMaps; @@ -27,7 +28,7 @@ use frame_support::{ ord_parameter_types, parameter_types, sp_runtime::{DispatchError, DispatchResult}, sp_std::marker::PhantomData, - traits::{Contains, Nothing}, + traits::{Contains, Get, Nothing}, weights::{ConstantMultiplier, IdentityFee}, PalletId, }; @@ -79,10 +80,20 @@ frame_support::construct_runtime!( ZenlinkProtocol: zenlink_protocol::{Pallet, Call, Storage, Event}, Currencies: orml_currencies::{Pallet, Call, Storage}, Salp: bifrost_salp::{Pallet, Call, Storage, Event}, - AssetRegistry: bifrost_asset_registry::{Pallet, Call, Event, Storage}, + AssetRegistry: bifrost_asset_registry::{Pallet, Call, Storage, Event}, } ); +ord_parameter_types! { + pub const One: AccountId = ALICE; +} + +impl bifrost_asset_registry::Config for Test { + type Event = Event; + type Currency = Balances; + type RegisterOrigin = EnsureSignedBy; +} + parameter_types! { pub const BlockHashCount: u32 = 250; } @@ -230,6 +241,14 @@ impl crate::Config for Test { type ExtraFeeMatcher = ExtraFeeMatcher; type MiscFeeHandler = MiscFeeHandler; + type ParachainId = ParaInfo; +} + +pub struct ParaInfo; +impl Get for ParaInfo { + fn get() -> Pid { + Pid::from(2001) + } } parameter_types! { @@ -437,15 +456,7 @@ impl bifrost_salp::Config for Test { type BuybackPalletId = BuybackPalletId; type DexOperator = ZenlinkProtocol; type CurrencyIdConversion = AssetIdMaps; -} - -ord_parameter_types! { - pub const CouncilAccount: AccountId = AccountId::from([1u8; 32]); -} -impl bifrost_asset_registry::Config for Test { - type Event = Event; - type Currency = Balances; - type RegisterOrigin = EnsureSignedBy; + type ParachainId = ParaInfo; } //************** Salp mock end ***************** diff --git a/pallets/flexible-fee/src/tests.rs b/pallets/flexible-fee/src/tests.rs index 88f306093..452d5e660 100644 --- a/pallets/flexible-fee/src/tests.rs +++ b/pallets/flexible-fee/src/tests.rs @@ -20,7 +20,7 @@ #![cfg(test)] -use std::convert::TryFrom; +use node_primitives::TryConvertFrom; // use balances::Call as BalancesCall; use frame_support::{ @@ -78,11 +78,12 @@ fn basic_setup() { assert_ok!(Currencies::deposit(CURRENCY_ID_4, &DICK, 100000)); // create DEX pair - let asset_0_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_0).unwrap(); - let asset_1_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_1).unwrap(); - let asset_2_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_2).unwrap(); - let asset_3_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_3).unwrap(); - let asset_4_currency_id: AssetId = AssetId::try_from(CURRENCY_ID_4).unwrap(); + let para_id: u32 = 2001; + let asset_0_currency_id: AssetId = AssetId::try_convert_from(CURRENCY_ID_0, para_id).unwrap(); + let asset_1_currency_id: AssetId = AssetId::try_convert_from(CURRENCY_ID_1, para_id).unwrap(); + let asset_2_currency_id: AssetId = AssetId::try_convert_from(CURRENCY_ID_2, para_id).unwrap(); + let asset_3_currency_id: AssetId = AssetId::try_convert_from(CURRENCY_ID_3, para_id).unwrap(); + let asset_4_currency_id: AssetId = AssetId::try_convert_from(CURRENCY_ID_4, para_id).unwrap(); assert_ok!(ZenlinkProtocol::create_pair( Origin::root(), diff --git a/pallets/salp/Cargo.toml b/pallets/salp/Cargo.toml index 995fb300a..789ff159e 100644 --- a/pallets/salp/Cargo.toml +++ b/pallets/salp/Cargo.toml @@ -1,28 +1,33 @@ [package] name = "bifrost-salp" version = "0.8.0" -authors = ["Edwin Wang ","Ron yang"] +authors = ["Edwin Wang ", "Ron yang"] edition = "2021" [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [ + "derive", +] } +scale-info = { version = "2.1.2", default-features = false, features = [ + "derive", +] } log = { version = "0.4.17", default-features = false } node-primitives = { path = "../../node/primitives", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true } sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false } orml-traits = { version = "0.4.1-dev", default-features = false } xcm-interface = { path = "../xcm-interface", default-features = false } zenlink-protocol = { version = "*", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.26", default-features = false } [dev-dependencies] -pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26"} -pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26"} +pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" } +pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" } pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" } smallvec = "1.9.0" sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" } @@ -50,6 +55,7 @@ std = [ "xcm-interface/std", "zenlink-protocol/std", "bifrost-asset-registry/std", + "cumulus-primitives-core/std", ] runtime-benchmarks = [ diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index ff4fceda4..1be1f8131 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -37,7 +37,7 @@ pub use weights::WeightInfo; // Re-export pallet items so that they can be accessed from the crate namespace. use frame_support::{pallet_prelude::*, sp_runtime::SaturatedConversion, transactional}; -use node_primitives::{ContributionStatus, CurrencyIdConversion, TrieIndex}; +use node_primitives::{ContributionStatus, CurrencyIdConversion, TrieIndex, TryConvertFrom}; use orml_traits::MultiCurrency; pub use pallet::*; use scale_info::TypeInfo; @@ -172,6 +172,8 @@ pub mod pallet { type DexOperator: ExportZenlink; type CurrencyIdConversion: CurrencyIdConversion; + + type ParachainId: Get; } #[pallet::pallet] @@ -1011,10 +1013,12 @@ pub mod pallet { let relay_currency_id = T::RelayChainToken::get(); let relay_vstoken_id = T::CurrencyIdConversion::convert_to_vstoken(relay_currency_id) .map_err(|_| Error::::NotSupportTokenType)?; - let relay_asset_id: AssetId = AssetId::try_from(relay_currency_id) - .map_err(|_| DispatchError::Other("Conversion Error."))?; - let relay_vstoken_asset_id: AssetId = AssetId::try_from(relay_vstoken_id) - .map_err(|_| DispatchError::Other("Conversion Error."))?; + let relay_asset_id: AssetId = + AssetId::try_convert_from(relay_currency_id, T::ParachainId::get().into()) + .map_err(|_| DispatchError::Other("Conversion Error."))?; + let relay_vstoken_asset_id: AssetId = + AssetId::try_convert_from(relay_vstoken_id, T::ParachainId::get().into()) + .map_err(|_| DispatchError::Other("Conversion Error."))?; let path = vec![relay_asset_id, relay_vstoken_asset_id]; T::DexOperator::inner_swap_exact_assets_for_assets( diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index ae76caca2..ef13195ae 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -21,11 +21,12 @@ #![cfg(test)] use bifrost_asset_registry::AssetIdMaps; +use cumulus_primitives_core::ParaId as Pid; use frame_support::{ construct_runtime, ord_parameter_types, parameter_types, sp_runtime::{DispatchError, DispatchResult, SaturatedConversion}, sp_std::marker::PhantomData, - traits::{EnsureOrigin, GenesisBuild, Nothing}, + traits::{EnsureOrigin, GenesisBuild, Get, Nothing}, weights::Weight, PalletId, }; @@ -349,6 +350,14 @@ impl salp::Config for Test { type BuybackPalletId = BuybackPalletId; type DexOperator = ZenlinkProtocol; type CurrencyIdConversion = AssetIdMaps; + type ParachainId = ParaInfo; +} + +pub struct ParaInfo; +impl Get for ParaInfo { + fn get() -> Pid { + Pid::from(2001) + } } pub struct SalpWeightInfo; diff --git a/pallets/salp/src/tests.rs b/pallets/salp/src/tests.rs index 76d8f4f8f..9b7308345 100644 --- a/pallets/salp/src/tests.rs +++ b/pallets/salp/src/tests.rs @@ -1399,9 +1399,11 @@ fn refund_meanwhile_issue_should_work() { assert_eq!(Tokens::accounts(buyback_account, RelayCurrencyId::get()).free, 75); assert_noop!(Salp::redeem(Some(BRUCE).into(), 3_000, 50), Error::::InvalidParaId); - let asset_0_currency_id: AssetId = AssetId::try_from(RelayCurrencyId::get()).unwrap(); + let para_id = 2001u32; + let asset_0_currency_id: AssetId = + AssetId::try_convert_from(RelayCurrencyId::get(), para_id).unwrap(); let asset_1_currency_id: AssetId = - AssetId::try_from(CurrencyId::VSToken(TokenSymbol::KSM)).unwrap(); + AssetId::try_convert_from(CurrencyId::VSToken(TokenSymbol::KSM), para_id).unwrap(); assert_ok!(ZenlinkProtocol::create_pair( Origin::root(), asset_0_currency_id, diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index ffc261162..5bc1b88b5 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -44,6 +44,8 @@ pub use frame_support::{ PalletId, RuntimeDebug, StorageValue, }; use frame_system::limits::{BlockLength, BlockWeights}; +#[cfg(feature = "try-runtime")] +use node_primitives::TokenInfo; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; use pallet_xcm::QueryStatus; @@ -1547,6 +1549,7 @@ impl bifrost_flexible_fee::Config for Runtime { type WeightInfo = bifrost_flexible_fee::weights::BifrostWeight; type ExtraFeeMatcher = ExtraFeeMatcher; type MiscFeeHandler = MiscFeeHandlers; + type ParachainId = ParachainInfo; } parameter_types! { @@ -1623,6 +1626,7 @@ impl bifrost_salp::Config for Runtime { type BuybackPalletId = BuybackPalletId; type DexOperator = ZenlinkProtocol; type CurrencyIdConversion = AssetIdMaps; + type ParachainId = ParachainInfo; } parameter_types! { diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index 0037aa913..9151d6052 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -1319,6 +1319,7 @@ impl bifrost_flexible_fee::Config for Runtime { type WeightInfo = (); type ExtraFeeMatcher = ExtraFeeMatcher; type MiscFeeHandler = MiscFeeHandlers; + type ParachainId = ParachainInfo; } parameter_types! { @@ -1395,6 +1396,7 @@ impl bifrost_salp::Config for Runtime { type BuybackPalletId = BuybackPalletId; type DexOperator = ZenlinkProtocol; type CurrencyIdConversion = AssetIdMaps; + type ParachainId = ParachainInfo; } impl bifrost_call_switchgear::Config for Runtime {