diff --git a/node/primitives/src/currency.rs b/node/primitives/src/currency.rs index d99db46ac7..64b97cddbe 100644 --- a/node/primitives/src/currency.rs +++ b/node/primitives/src/currency.rs @@ -22,7 +22,7 @@ use bstringify::bstringify; use codec::{Decode, Encode}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; -use sp_runtime::{RuntimeDebug, SaturatedConversion}; +use sp_runtime::RuntimeDebug; use sp_std::{ convert::{Into, TryFrom, TryInto}, prelude::*, @@ -75,11 +75,18 @@ macro_rules! create_currency_id { type Error = (); fn try_from(id: CurrencyId) -> Result { let _index = match id { - $(CurrencyId::Native(TokenSymbol::$symbol) => Ok((0_u32, TokenSymbol::$symbol as u32)),)* - $(CurrencyId::VToken(TokenSymbol::$symbol) => Ok((1_u32, TokenSymbol::$symbol as u32)),)* - $(CurrencyId::Token(TokenSymbol::$symbol) => Ok((2_u32, TokenSymbol::$symbol as u32)),)* - $(CurrencyId::Stable(TokenSymbol::$symbol) => Ok((3_u32, TokenSymbol::$symbol as u32)),)* - $(CurrencyId::VSToken(TokenSymbol::$symbol) => Ok((4_u32, TokenSymbol::$symbol as u32)),)* + $(CurrencyId::Native(TokenSymbol::$symbol) => Ok((0_u64, TokenSymbol::$symbol as u64)),)* + $(CurrencyId::VToken(TokenSymbol::$symbol) => Ok((1_u64, TokenSymbol::$symbol as u64)),)* + $(CurrencyId::Token(TokenSymbol::$symbol) => Ok((2_u64, TokenSymbol::$symbol as u64)),)* + $(CurrencyId::Stable(TokenSymbol::$symbol) => Ok((3_u64, TokenSymbol::$symbol as u64)),)* + $(CurrencyId::VSToken(TokenSymbol::$symbol) => Ok((4_u64, TokenSymbol::$symbol as u64)),)* + CurrencyId::LPToken(symbol0, index0, symbol1, index1) => { + let currency_index0 = + (((((index0 as u64) << 8) & 0x0000_ff00) + (symbol0 as u64 & 0x0000_00ff)) as u64) << 16; + let currency_index1 = + (((((index1 as u64) << 8) & 0x0000_ff00) + (symbol1 as u64 & 0x0000_00ff)) as u64) << 32; + Ok((6 as u64, currency_index0 + currency_index1)) + } _ => Err(()), }; let asset_index = ((_index?.0 << 8) & 0x0000_ff00) + (_index?.1 & 0x0000_00ff); @@ -103,25 +110,17 @@ macro_rules! create_currency_id { // TokenSymbol Index: 1byte type Error = (); fn try_into(self) -> Result { - let id: u32 = self.asset_index.saturated_into(); - let c_discr = (id >> 8) as u32; - let _index = (0x0000_00ff & id) as u32; - let token_symbol = match _index { - $(x if x == TokenSymbol::$symbol as u32 => Ok(TokenSymbol::$symbol),)* - _ => Err(()), - }; + let id = self.asset_index; + let c_discr = ((id & 0x0000_0000_0000_ff00) >> 8) as u32; + let _index = (0x0000_00ff & id) as u8; + match c_discr { - 0 => { - if (_index == 0) { - Ok(CurrencyId::Native(TokenSymbol::ASG)) - } else { - Ok(CurrencyId::Native(TokenSymbol::BNC)) - } - }, - 1 => Ok(CurrencyId::VToken(token_symbol?)), - 2 => Ok(CurrencyId::Token(token_symbol?)), - 3 => Ok(CurrencyId::Stable(token_symbol?)), - 4 => Ok(CurrencyId::VSToken(token_symbol?)), + 0 => Ok(CurrencyId::Native(TokenSymbol::try_from(_index)?)), + 1 => Ok(CurrencyId::VToken(TokenSymbol::try_from(_index)?)), + 2 => Ok(CurrencyId::Token(TokenSymbol::try_from(_index)?)), + 3 => Ok(CurrencyId::Stable(TokenSymbol::try_from(_index)?)), + 4 => Ok(CurrencyId::VSToken(TokenSymbol::try_from(_index)?)), + 6 => Ok(CurrencyId::try_from(id)?), _ => Err(()), } } diff --git a/pallets/flexible-fee/src/mock.rs b/pallets/flexible-fee/src/mock.rs index 59314f629b..42f49893ba 100644 --- a/pallets/flexible-fee/src/mock.rs +++ b/pallets/flexible-fee/src/mock.rs @@ -215,14 +215,14 @@ parameter_types! { } impl zenlink_protocol::Config for Test { - type Conversion = (); type Event = Event; - type GetExchangeFee = GetExchangeFee; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; type SelfParaId = SelfParaId; + type TargetChains = (); type XcmExecutor = (); + type Conversion = (); } type MultiAssets = ZenlinkMultiAssets>; diff --git a/pallets/flexible-fee/src/tests.rs b/pallets/flexible-fee/src/tests.rs index df636595a8..2889b07641 100644 --- a/pallets/flexible-fee/src/tests.rs +++ b/pallets/flexible-fee/src/tests.rs @@ -82,12 +82,6 @@ fn basic_setup() { 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(); - assert_ok!(ZenlinkProtocol::create_pair( - Origin::signed(ALICE), - asset_0_currency_id, - asset_1_currency_id - )); - let mut deadline: BlockNumberFor = >::block_number() + ::BlockNumber::from(100u32); assert_ok!(ZenlinkProtocol::add_liquidity( @@ -101,17 +95,6 @@ fn basic_setup() { deadline )); - assert_ok!(ZenlinkProtocol::create_pair( - Origin::signed(ALICE), - asset_0_currency_id, - asset_2_currency_id - )); // asset 0 and 2 - - let pool_0_2_account = ZenlinkProtocol::lp_metadata((asset_0_currency_id, asset_2_currency_id)) - .unwrap() - .0; - println!("pool_0_2_account: {:?}", pool_0_2_account); - // pool 0 2 deadline = >::block_number() + ::BlockNumber::from(100u32); @@ -199,27 +182,6 @@ fn ensure_can_charge_fee_should_work() { Some(asset_order_list_vec.clone()), ); - let native_asset_id: AssetId = AssetId::try_from(CURRENCY_ID_0).unwrap(); - let asset_id: AssetId = AssetId::try_from(CURRENCY_ID_1).unwrap(); - - let path = vec![asset_id, native_asset_id]; - let pool_0_1_account = ZenlinkProtocol::lp_metadata((native_asset_id, asset_id)).unwrap().0; - - println!("pool_0_1_account: {:?}", pool_0_1_account); - - let pool_0_1_price = ZenlinkProtocol::get_amount_in_by_path(100, &path); - let pool_0_1_account = ZenlinkProtocol::lp_metadata((native_asset_id, asset_id)).unwrap().0; - - println!("pool_0_1_price: {:?}", pool_0_1_price); - println!( - "crrency 0 total balance of pool_0_1: {:?}", - Currencies::total_balance(CURRENCY_ID_0, &pool_0_1_account) - ); - println!( - "crrency 1 total balance of pool_0_1: {:?}", - Currencies::total_balance(CURRENCY_ID_1, &pool_0_1_account) - ); - assert_ok!(::FeeDealer::ensure_can_charge_fee( &ALICE, 100, diff --git a/pallets/minter-reward/src/mock.rs b/pallets/minter-reward/src/mock.rs index 5350b6cdb0..b1d7a6b4f6 100644 --- a/pallets/minter-reward/src/mock.rs +++ b/pallets/minter-reward/src/mock.rs @@ -168,7 +168,6 @@ parameter_types! { impl zenlink_protocol::Config for Runtime { type Conversion = (); type Event = Event; - type GetExchangeFee = GetExchangeFee; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; // type SelfParaId = SelfParaId; diff --git a/pallets/minter-reward/src/tests.rs b/pallets/minter-reward/src/tests.rs index 73eb8acc71..0754c0ee39 100644 --- a/pallets/minter-reward/src/tests.rs +++ b/pallets/minter-reward/src/tests.rs @@ -73,27 +73,6 @@ fn minter_reward_should_work() { let vksm_asset_id: AssetId = AssetId::try_from(CurrencyId::VToken(TokenSymbol::KSM)).unwrap(); - assert_ok!(ZenlinkProtocol::create_pair( - Origin::signed(ALICE), - ausd_asset_id, - dot_asset_id - )); - assert_ok!(ZenlinkProtocol::create_pair( - Origin::signed(ALICE), - ausd_asset_id, - vdot_asset_id - )); - assert_ok!(ZenlinkProtocol::create_pair( - Origin::signed(ALICE), - ausd_asset_id, - ksm_asset_id - )); - assert_ok!(ZenlinkProtocol::create_pair( - Origin::signed(ALICE), - ausd_asset_id, - vksm_asset_id - )); - let deadline: BlockNumberFor = >::block_number() + ::BlockNumber::from(100u32); assert_ok!(ZenlinkProtocol::add_liquidity( diff --git a/pallets/vtoken-mint/src/mock.rs b/pallets/vtoken-mint/src/mock.rs index 128a362309..0a0035f8df 100644 --- a/pallets/vtoken-mint/src/mock.rs +++ b/pallets/vtoken-mint/src/mock.rs @@ -189,7 +189,6 @@ parameter_types! { impl zenlink_protocol::Config for Runtime { type Conversion = (); type Event = Event; - type GetExchangeFee = GetExchangeFee; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; type SelfParaId = ();