Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions node/primitives/src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -75,11 +75,18 @@ macro_rules! create_currency_id {
type Error = ();
fn try_from(id: CurrencyId) -> Result<AssetId, ()> {
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);
Expand All @@ -103,25 +110,17 @@ macro_rules! create_currency_id {
// TokenSymbol Index: 1byte
type Error = ();
fn try_into(self) -> Result<CurrencyId, Self::Error> {
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(()),
}
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZenlinkProtocol, Balances, LocalAssetAdaptor<Currencies>>;
Expand Down
38 changes: 0 additions & 38 deletions pallets/flexible-fee/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test> = <frame_system::Pallet<Test>>::block_number() +
<Test as frame_system::Config>::BlockNumber::from(100u32);
assert_ok!(ZenlinkProtocol::add_liquidity(
Expand All @@ -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 = <frame_system::Pallet<Test>>::block_number() +
<Test as frame_system::Config>::BlockNumber::from(100u32);
Expand Down Expand Up @@ -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!(<Test as crate::Config>::FeeDealer::ensure_can_charge_fee(
&ALICE,
100,
Expand Down
1 change: 0 additions & 1 deletion pallets/minter-reward/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 0 additions & 21 deletions pallets/minter-reward/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime> = <frame_system::Pallet<Runtime>>::block_number() +
<Runtime as frame_system::Config>::BlockNumber::from(100u32);
assert_ok!(ZenlinkProtocol::add_liquidity(
Expand Down
1 change: 0 additions & 1 deletion pallets/vtoken-mint/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
Expand Down