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

refactor: AssetPairAccountId trait #237

Merged
merged 3 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 3 additions & 12 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ pub fn testnet_parachain_config(para_id: ParaId) -> Result<ChainSpec, String> {
vec![hex!["30035c21ba9eda780130f2029a80c3e962f56588bc04c36be95a225cb536fb55"].into()],
hex!["30035c21ba9eda780130f2029a80c3e962f56588bc04c36be95a225cb536fb55"].into(), // SAME AS ROOT
vec![],
vec![
(b"KSM".to_vec(), 1_000u128),
(b"KUSD".to_vec(), 1_000u128),
],
vec![(b"KSM".to_vec(), 1_000u128), (b"KUSD".to_vec(), 1_000u128)],
vec![(1, Price::from_float(0.0000212)), (2, Price::from_float(0.000806))],
)
},
Expand Down Expand Up @@ -315,10 +312,7 @@ pub fn parachain_development_config(para_id: ParaId) -> Result<ChainSpec, String
],
get_account_id_from_seed::<sr25519::Public>("Alice"), // SAME AS ROOT
get_vesting_config_for_test(),
vec![
(b"KSM".to_vec(), 1_000u128),
(b"KUSD".to_vec(), 1_000u128),
],
vec![(b"KSM".to_vec(), 1_000u128), (b"KUSD".to_vec(), 1_000u128)],
vec![(1, Price::from_float(0.0000212)), (2, Price::from_float(0.000806))],
)
},
Expand Down Expand Up @@ -464,10 +458,7 @@ pub fn local_parachain_config(para_id: ParaId) -> Result<ChainSpec, String> {
],
get_account_id_from_seed::<sr25519::Public>("Alice"), // SAME AS ROOT
get_vesting_config_for_test(),
vec![
(b"KSM".to_vec(), 1_000u128),
(b"KUSD".to_vec(), 1_000u128),
],
vec![(b"KSM".to_vec(), 1_000u128), (b"KUSD".to_vec(), 1_000u128)],
vec![(1, Price::from_float(0.0000212)), (2, Price::from_float(0.000806))],
)
},
Expand Down
12 changes: 3 additions & 9 deletions node/src/testing_chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![allow(clippy::too_many_arguments)]

use cumulus_primitives_core::ParaId;
use primitives::{BlockNumber, Price, AssetId};
use primitives::{AssetId, BlockNumber, Price};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -142,10 +142,7 @@ pub fn parachain_development_config(para_id: ParaId) -> Result<ChainSpec, String
],
get_account_id_from_seed::<sr25519::Public>("Alice"), // SAME AS ROOT
get_vesting_config_for_test(),
vec![
(b"KSM".to_vec(), 1_000u128),
(b"KUSD".to_vec(), 1_000u128),
],
vec![(b"KSM".to_vec(), 1_000u128), (b"KUSD".to_vec(), 1_000u128)],
vec![(1, Price::from_float(0.0000212)), (2, Price::from_float(0.000806))],
)
},
Expand Down Expand Up @@ -221,10 +218,7 @@ pub fn local_parachain_config(para_id: ParaId) -> Result<ChainSpec, String> {
],
get_account_id_from_seed::<sr25519::Public>("Alice"), // SAME AS ROOT
get_vesting_config_for_test(),
vec![
(b"KSM".to_vec(), 1_000u128),
(b"KUSD".to_vec(), 1_000u128),
],
vec![(b"KSM".to_vec(), 1_000u128), (b"KUSD".to_vec(), 1_000u128)],
vec![(1, Price::from_float(0.0000212)), (2, Price::from_float(0.000806))],
)
},
Expand Down
6 changes: 1 addition & 5 deletions pallets/duster/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ pub mod pallet {
///
/// Caller is rewarded with chosen reward in native currency.
#[pallet::weight((<T as Config>::WeightInfo::dust_account(), DispatchClass::Normal, Pays::Yes))]
pub fn dust_account(
origin: OriginFor<T>,
account: T::AccountId,
currency_id: T::CurrencyId,
) -> DispatchResult {
pub fn dust_account(origin: OriginFor<T>, account: T::AccountId, currency_id: T::CurrencyId) -> DispatchResult {
let who = ensure_signed(origin)?;

ensure!(Self::blacklisted(&account).is_none(), Error::<T>::AccountBlacklisted);
Expand Down
7 changes: 4 additions & 3 deletions pallets/exchange/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ use sp_runtime::{
};

use frame_system::EnsureSigned;
use pallet_xyk::AssetPairAccountIdFor;
use primitives::{
constants::chain::{MAX_IN_RATIO, MAX_OUT_RATIO, MIN_POOL_LIQUIDITY, MIN_TRADING_LIMIT},
fee, AssetId, Balance,
fee,
traits::AssetPairAccountIdFor,
AssetId, Balance,
};

pub type Amount = i128;
Expand Down Expand Up @@ -121,7 +122,7 @@ impl orml_tokens::Config for Test {
pub struct AssetPairAccountIdTest();

impl AssetPairAccountIdFor<AssetId, u64> for AssetPairAccountIdTest {
fn from_assets(asset_a: AssetId, asset_b: AssetId) -> u64 {
fn from_assets(asset_a: AssetId, asset_b: AssetId, _: &str) -> u64 {
let mut a = asset_a as u128;
let mut b = asset_b as u128;
if a > b {
Expand Down
144 changes: 72 additions & 72 deletions pallets/exchange/src/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,36 @@ impl<'a, T: Config> DirectTradeData<'a, T> {
match (&self.intention_a.sell_or_buy, &self.intention_b.sell_or_buy) {
(IntentionType::SELL, IntentionType::SELL) => {
if !Self::reserve_if_can(
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a,
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a,
) {
return false;
return false;
}

if !Self::reserve_if_can(
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b,
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b,
) {
return false;
return false;
}

let transfer = Transfer::<T> {
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a - transfer_a_fee,
fee_transfer: false,
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a - transfer_a_fee,
fee_transfer: false,
};
self.transfers.push(transfer);

let transfer = Transfer::<T> {
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b - transfer_b_fee,
fee_transfer: false,
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b - transfer_b_fee,
fee_transfer: false,
};
self.transfers.push(transfer);

Expand All @@ -134,36 +134,36 @@ impl<'a, T: Config> DirectTradeData<'a, T> {
}
(IntentionType::BUY, IntentionType::BUY) => {
if !Self::reserve_if_can(
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a + transfer_a_fee,
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a + transfer_a_fee,
) {
return false;
return false;
}

if !Self::reserve_if_can(
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b + transfer_b_fee,
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b + transfer_b_fee,
) {
return false;
return false;
}

let transfer = Transfer::<T> {
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a,
fee_transfer: false,
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a,
fee_transfer: false,
};
self.transfers.push(transfer);

let transfer = Transfer::<T> {
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b,
fee_transfer: false,
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b,
fee_transfer: false,
};
self.transfers.push(transfer);

Expand All @@ -187,36 +187,36 @@ impl<'a, T: Config> DirectTradeData<'a, T> {
}
(IntentionType::BUY, IntentionType::SELL) => {
if !Self::reserve_if_can(
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a + transfer_a_fee,
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a + transfer_a_fee,
) {
return false;
return false;
}

if !Self::reserve_if_can(
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b,
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b,
) {
return false;
return false;
}

let transfer = Transfer::<T> {
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a - transfer_a_fee,
fee_transfer: false,
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a - transfer_a_fee,
fee_transfer: false,
};
self.transfers.push(transfer);

let transfer = Transfer::<T> {
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b,
fee_transfer: false,
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b,
fee_transfer: false,
};
self.transfers.push(transfer);

Expand All @@ -231,36 +231,36 @@ impl<'a, T: Config> DirectTradeData<'a, T> {
}
(IntentionType::SELL, IntentionType::BUY) => {
if !Self::reserve_if_can(
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a,
self.intention_a.assets.asset_in,
&self.intention_a.who,
self.amount_from_a,
) {
return false;
return false;
}

if !Self::reserve_if_can(
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b + transfer_b_fee,
self.intention_a.assets.asset_out,
&self.intention_b.who,
self.amount_from_b + transfer_b_fee,
) {
return false;
return false;
}

let transfer = Transfer::<T> {
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a,
fee_transfer: false,
from: &self.intention_a.who,
to: &self.intention_b.who,
asset: self.intention_a.assets.asset_in,
amount: self.amount_from_a,
fee_transfer: false,
};
self.transfers.push(transfer);

let transfer = Transfer::<T> {
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b - transfer_b_fee,
fee_transfer: false,
from: &self.intention_b.who,
to: &self.intention_a.who,
asset: self.intention_a.assets.asset_out,
amount: self.amount_from_b - transfer_b_fee,
fee_transfer: false,
};
self.transfers.push(transfer);

Expand Down
4 changes: 2 additions & 2 deletions pallets/exchange/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type IntentionId<T> = <T as system::Config>::Hash;
pub type Intention<T> = ExchangeIntention<<T as system::Config>::AccountId, Balance, IntentionId<T>>;

// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;
use frame_support::pallet_prelude::*;
pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -195,7 +195,7 @@ pub mod pallet {
MinimumTradeLimitNotReached,

/// Overflow
IntentionCountOverflow
IntentionCountOverflow,
}

/// Intention count for current block
Expand Down
7 changes: 4 additions & 3 deletions pallets/exchange/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ use pallet_xyk as xyk;

use frame_support::traits::{Everything, GenesisBuild, Get};
use frame_system::EnsureSigned;
use pallet_xyk::AssetPairAccountIdFor;
use primitives::{
constants::chain::{MAX_IN_RATIO, MAX_OUT_RATIO, MIN_POOL_LIQUIDITY, MIN_TRADING_LIMIT},
fee, AssetId, Balance,
fee,
traits::AssetPairAccountIdFor,
AssetId, Balance,
};
use std::cell::RefCell;

Expand Down Expand Up @@ -138,7 +139,7 @@ impl orml_tokens::Config for Test {
pub struct AssetPairAccountIdTest();

impl AssetPairAccountIdFor<AssetId, u64> for AssetPairAccountIdTest {
fn from_assets(asset_a: AssetId, asset_b: AssetId) -> u64 {
fn from_assets(asset_a: AssetId, asset_b: AssetId, _: &str) -> u64 {
let mut a = asset_a as u128;
let mut b = asset_b as u128;
if a > b {
Expand Down
Loading