Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
remove IsTradingPairEnabled and RegisterPair traits
  • Loading branch information
TheLedgerOfJoudi committed Oct 24, 2023
commit c596bbaf452d2954c707b456f8bc6daf2f039d8c
52 changes: 29 additions & 23 deletions common/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ pub trait TradingPairSourceManager<DEXId, AssetId> {
target_asset_id: &AssetId,
source_type: LiquiditySourceType,
) -> DispatchResult;

fn is_trading_pair_enabled(
dex_id: &DEXId,
base_asset_id: &AssetId,
target_asset_id: &AssetId,
) -> Result<bool, DispatchError>;

fn register_pair(
dex_id: DEXId,
base_asset_id: AssetId,
target_asset_id: AssetId,
) -> Result<(), DispatchError>;
}

impl<DEXId, AssetId> TradingPairSourceManager<DEXId, AssetId> for () {
Expand Down Expand Up @@ -157,6 +169,22 @@ impl<DEXId, AssetId> TradingPairSourceManager<DEXId, AssetId> for () {
) -> DispatchResult {
Err(DispatchError::CannotLookup)
}

fn is_trading_pair_enabled(
_dex_id: &DEXId,
_base_asset_id: &AssetId,
_target_asset_id: &AssetId,
) -> Result<bool, DispatchError> {
Err(DispatchError::CannotLookup)
}

fn register_pair(
_dex_id: DEXId,
_base_asset_id: AssetId,
_target_asset_id: AssetId,
) -> Result<(), DispatchError> {
Err(DispatchError::CannotLookup)
}
}

/// Indicates that particular object can be used to perform exchanges.
Expand Down Expand Up @@ -223,7 +251,7 @@ pub trait LockedLiquiditySourcesManager<LiquiditySourceType> {
fn append(liquidity_source_type: LiquiditySourceType) -> ();
}

/// Implements trading pair EnabledSources stroage
/// Implements trading pair EnabledSources storage
pub trait EnabledSourcesManager<DEXId, AssetId> {
fn mutate_remove(dex_id: &DEXId, base_asset_id: &AssetId, target_asset_id: &AssetId) -> ();
}
Expand All @@ -233,9 +261,6 @@ impl<DEXId, AssetId> EnabledSourcesManager<DEXId, AssetId> for () {
todo!()
}
}

/// Implements trading pair register

pub trait RegisterManager<DEXId, AssetId, Origin> {
fn register(
origin: Origin,
Expand All @@ -245,25 +270,6 @@ pub trait RegisterManager<DEXId, AssetId, Origin> {
) -> DispatchResultWithPostInfo;
}

/// Implements trading pair is_trading_pair_enabled
pub trait IsTradingPairEnabled<DEXId, AssetId> {
fn is_trading_pair_enabled(
dex_id: &DEXId,
base_asset_id: &AssetId,
target_asset_id: &AssetId,
) -> Result<bool, DispatchError>;
}

/// Implements trading pair register_pair
pub trait RegisterPair<DEXId, AssetId> {
fn register_pair(
dex_id: DEXId,
base_asset_id: AssetId,
target_asset_id: AssetId,
) -> Result<(), DispatchError>;
}

// pub trait RegisterManager
/// *Hook*-like trait for oracles to capture newly relayed symbols.
///
/// A struct implementing this trait can be specified in oracle pallet *Config*
Expand Down
2 changes: 0 additions & 2 deletions pallets/pool-xyk/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ impl xst::Config for Runtime {
type Symbol = SymbolName;
type GetSyntheticBaseBuySellLimit = GetSyntheticBaseBuySellLimit;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type IsTradingPairEnabled = trading_pair::Pallet<Runtime>;
type RegisterPair = trading_pair::Pallet<Runtime>;
}

parameter_type_with_key! {
Expand Down
41 changes: 18 additions & 23 deletions pallets/trading-pair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ extern crate alloc;

use common::{
AssetInfoProvider, DexInfoProvider, EnabledSourcesManager, EnsureDEXManager,
EnsureTradingPairExists, IsTradingPairEnabled, LiquiditySourceType,
LockedLiquiditySourcesManager, ManagementMode, RegisterManager, RegisterPair,
TradingPairSourceManager,
EnsureTradingPairExists, LiquiditySourceType, LockedLiquiditySourcesManager, ManagementMode,
RegisterManager, TradingPairSourceManager,
};
use frame_support::dispatch::{DispatchError, DispatchResult};
use frame_support::ensure;
Expand Down Expand Up @@ -78,26 +77,6 @@ impl<T: Config> EnsureTradingPairExists<T::DEXId, T::AssetId, DispatchError> for
}
}

impl<T: Config> IsTradingPairEnabled<T::DEXId, T::AssetId> for Pallet<T> {
fn is_trading_pair_enabled(
dex_id: &T::DEXId,
base_asset_id: &T::AssetId,
target_asset_id: &T::AssetId,
) -> Result<bool, DispatchError> {
Self::is_trading_pair_enabled(dex_id, base_asset_id, target_asset_id)
}
}

impl<T: Config> RegisterPair<T::DEXId, T::AssetId> for Pallet<T> {
fn register_pair(
dex_id: T::DEXId,
base_asset_id: T::AssetId,
target_asset_id: T::AssetId,
) -> Result<(), DispatchError> {
Self::register_pair(dex_id, base_asset_id, target_asset_id)
}
}

impl<T: Config> LockedLiquiditySourcesManager<LiquiditySourceType> for Pallet<T> {
fn get() -> Vec<LiquiditySourceType> {
LockedLiquiditySources::<T>::get()
Expand Down Expand Up @@ -209,6 +188,22 @@ impl<T: Config> TradingPairSourceManager<T::DEXId, T::AssetId> for Pallet<T> {
});
Ok(())
}

fn is_trading_pair_enabled(
dex_id: &T::DEXId,
base_asset_id: &T::AssetId,
target_asset_id: &T::AssetId,
) -> Result<bool, DispatchError> {
Self::is_trading_pair_enabled(dex_id, base_asset_id, target_asset_id)
}

fn register_pair(
dex_id: T::DEXId,
base_asset_id: T::AssetId,
target_asset_id: T::AssetId,
) -> Result<(), DispatchError> {
Self::register_pair(dex_id, base_asset_id, target_asset_id)
}
}

impl<T: Config> Pallet<T> {
Expand Down
2 changes: 0 additions & 2 deletions pallets/xst/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ impl xst::Config for Runtime {
type GetXSTPoolPermissionedTechAccountId = GetXSTPoolPermissionedTechAccountId;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type PriceToolsPallet = price_tools::Pallet<Runtime>;
type IsTradingPairEnabled = trading_pair::Pallet<Runtime>;
type RegisterPair = trading_pair::Pallet<Runtime>;
type Oracle = OracleProxy;
type Symbol = <Runtime as band::Config>::Symbol;
type GetSyntheticBaseBuySellLimit = GetSyntheticBaseBuySellLimit;
Expand Down
12 changes: 4 additions & 8 deletions pallets/xst/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ use common::prelude::{
};
use common::{
balance, fixed, fixed_wrapper, AssetId32, AssetInfoProvider, AssetName, AssetSymbol, DEXId,
DataFeed, GetMarketInfo, IsTradingPairEnabled, LiquiditySource, LiquiditySourceType,
OnSymbolDisabled, PriceVariant, Rate, RegisterPair, RewardReason, SyntheticInfoProvider,
TradingPairSourceManager, XSTUSD,
DataFeed, GetMarketInfo, LiquiditySource, LiquiditySourceType, OnSymbolDisabled, PriceVariant,
Rate, RewardReason, SyntheticInfoProvider, TradingPairSourceManager, XSTUSD,
};
use frame_support::pallet_prelude::DispatchResult;
use frame_support::traits::Get;
Expand Down Expand Up @@ -129,7 +128,6 @@ pub struct SyntheticInfo<Symbol> {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use common::IsTradingPairEnabled;
use frame_support::traits::StorageVersion;
use frame_support::{pallet_prelude::*, Parameter};
use frame_system::pallet_prelude::*;
Expand All @@ -143,8 +141,6 @@ pub mod pallet {
type EnsureDEXManager: EnsureDEXManager<Self::DEXId, Self::AccountId, DispatchError>;
type PriceToolsPallet: PriceToolsPallet<Self::AssetId>;
type Oracle: DataFeed<Self::Symbol, Rate, u64>;
type IsTradingPairEnabled: IsTradingPairEnabled<Self::DEXId, Self::AssetId>;
type RegisterPair: RegisterPair<Self::DEXId, Self::AssetId>;
/// Type of symbol received from oracles
type Symbol: Parameter + From<common::SymbolName> + MaybeSerializeDeserialize;
/// Maximum tradable amount of XST
Expand Down Expand Up @@ -517,15 +513,15 @@ impl<T: Config> Pallet<T> {
}

fn enable_synthetic_trading_pair(synthetic_asset_id: T::AssetId) -> sp_runtime::DispatchResult {
if T::IsTradingPairEnabled::is_trading_pair_enabled(
if T::TradingPairSourceManager::is_trading_pair_enabled(
&DEXId::Polkaswap.into(),
&T::GetSyntheticBaseAssetId::get(),
&synthetic_asset_id,
)? {
return Ok(());
}

T::RegisterPair::register_pair(
T::TradingPairSourceManager::register_pair(
DEXId::Polkaswap.into(),
T::GetSyntheticBaseAssetId::get(),
synthetic_asset_id,
Expand Down
2 changes: 0 additions & 2 deletions pallets/xst/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ impl Config for Runtime {
type Symbol = <Runtime as band::Config>::Symbol;
type GetSyntheticBaseBuySellLimit = GetSyntheticBaseBuySellLimit;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type IsTradingPairEnabled = trading_pair::Pallet<Runtime>;
type RegisterPair = trading_pair::Pallet<Runtime>;
type WeightInfo = ();
}

Expand Down
2 changes: 0 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,6 @@ impl xst::Config for Runtime {
type Oracle = OracleProxy;
type Symbol = <Runtime as band::Config>::Symbol;
type TradingPairSourceManager = TradingPair;
type IsTradingPairEnabled = trading_pair::Pallet<Runtime>;
type RegisterPair = trading_pair::Pallet<Runtime>;
type GetSyntheticBaseBuySellLimit = GetSyntheticBaseBuySellLimit;
}

Expand Down