Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 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 trading_pair::Config supertrait from all pallets
  • Loading branch information
TheLedgerOfJoudi committed Oct 31, 2023
commit 877370bb6c0445e52f68bfc2b043c5b6c127d18a
16 changes: 10 additions & 6 deletions pallets/ceres-launchpad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod tests;
mod benchmarking;

use codec::{Decode, Encode};
use common::TradingPairSourceManager;
pub use weights::WeightInfo;

#[derive(Encode, Decode, Default, PartialEq, Eq, scale_info::TypeInfo)]
Expand Down Expand Up @@ -101,7 +102,6 @@ pub mod pallet {
pub trait Config:
frame_system::Config
+ assets::Config
+ trading_pair::Config
+ pool_xyk::Config
+ ceres_liquidity_locker::Config
+ pswap_distribution::Config
Expand All @@ -115,13 +115,14 @@ pub mod pallet {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

type TradingPairSourceManager: TradingPairSourceManager<Self::DEXId, Self::AssetId>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}

type Assets<T> = assets::Pallet<T>;
pub type Timestamp<T> = timestamp::Pallet<T>;
type TradingPair<T> = trading_pair::Pallet<T>;
type PoolXYK<T> = pool_xyk::Pallet<T>;
type CeresLiquidityLocker<T> = ceres_liquidity_locker::Pallet<T>;
type TokenLocker<T> = ceres_token_locker::Pallet<T>;
Expand Down Expand Up @@ -399,8 +400,12 @@ pub mod pallet {
};

ensure!(
!TradingPair::<T>::is_trading_pair_enabled(&dex_id, &base_asset, &asset_id)
.unwrap_or(true),
!<T as pallet::Config>::TradingPairSourceManager::is_trading_pair_enabled(
&dex_id,
&base_asset,
&asset_id
)
.unwrap_or(true),
Error::<T>::CantCreateILOForListedToken
);

Expand Down Expand Up @@ -733,8 +738,7 @@ pub mod pallet {
DEXId::PolkaswapXSTUSD.into()
};
// Register trading pair
TradingPair::<T>::register(
RawOrigin::Signed(pallet_account.clone()).into(),
<T as pallet::Config>::TradingPairSourceManager::register_pair(
dex_id,
ilo_info.base_asset,
asset_id,
Expand Down
1 change: 1 addition & 0 deletions pallets/ceres-launchpad/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl frame_system::Config for Runtime {
impl crate::Config for Runtime {
const MILLISECONDS_PER_DAY: Self::Moment = 86_400_000;
type RuntimeEvent = RuntimeEvent;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type WeightInfo = ();
}

Expand Down
19 changes: 7 additions & 12 deletions pallets/ceres-liquidity-locker/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
use ceres_liquidity_locker::AccountIdOf;
use codec::Decode;
use common::prelude::Balance;
use common::{balance, AssetName, AssetSymbol, DEXId, DEFAULT_BALANCE_PRECISION, XOR};
use common::{
balance, AssetName, AssetSymbol, DEXId, TradingPairSourceManager, DEFAULT_BALANCE_PRECISION,
XOR,
};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;
use hex_literal::hex;
Expand All @@ -17,13 +20,12 @@ use assets::Pallet as Assets;
use pallet_timestamp::Pallet as Timestamp;
use permissions::Pallet as Permissions;
use pool_xyk::Pallet as XYKPool;
use trading_pair::Pallet as TradingPair;

#[cfg(test)]
mod mock;

pub struct Pallet<T: Config>(ceres_liquidity_locker::Pallet<T>);
pub trait Config: ceres_liquidity_locker::Config + trading_pair::Config + pool_xyk::Config {}
pub trait Config: ceres_liquidity_locker::Config + pool_xyk::Config {}

pub const DEX: DEXId = DEXId::Polkaswap;

Expand All @@ -42,8 +44,6 @@ pub fn AUTHORITY<T: frame_system::Config>() -> T::AccountId {
fn setup_benchmark_assets_only<T: Config>() -> Result<(), &'static str> {
let owner = alice::<T>();
frame_system::Pallet::<T>::inc_providers(&owner);
let owner_origin: <T as frame_system::Config>::RuntimeOrigin =
RawOrigin::Signed(owner.clone()).into();
let ceres_asset_id = common::AssetId32::from_bytes(hex!(
"008bcfd2387d3fc453333557eecb0efe59fcba128769b2feefdd306e98e66440"
));
Expand Down Expand Up @@ -85,13 +85,8 @@ fn setup_benchmark_assets_only<T: Config>() -> Result<(), &'static str> {
None,
);

TradingPair::<T>::register(
owner_origin.clone(),
DEX.into(),
XOR.into(),
ceres_asset_id.into(),
)
.unwrap();
T::TradingPairSourceManager::register_pair(DEX.into(), XOR.into(), ceres_asset_id.into())
.unwrap();

Assets::<T>::mint_to(&XOR.into(), &owner.clone(), &owner.clone(), balance!(50000))?;
Assets::<T>::mint_to(
Expand Down
1 change: 1 addition & 0 deletions pallets/ceres-liquidity-locker/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl dex_api::Config for Runtime {
type MulticollateralBondingCurvePool = ();
type XYKPool = pool_xyk::Pallet<Runtime>;
type XSTPool = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;

#[cfg(feature = "wip")] // order-book
type OrderBook = ();
Expand Down
9 changes: 4 additions & 5 deletions pallets/dex-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

use common::prelude::{Balance, QuoteAmount, SwapAmount, SwapOutcome};
use common::{
DexInfoProvider, LiquidityRegistry, LiquiditySource, LiquiditySourceFilter, LiquiditySourceId,
LiquiditySourceType, RewardReason,
DEXInfo, DexInfoProvider, LiquidityRegistry, LiquiditySource, LiquiditySourceFilter,
LiquiditySourceId, LiquiditySourceType, RewardReason,
};
use frame_support::sp_runtime::DispatchError;
use frame_support::weights::Weight;
Expand Down Expand Up @@ -336,9 +336,7 @@ pub mod pallet {
use frame_system::pallet_prelude::*;

#[pallet::config]
pub trait Config:
frame_system::Config + common::Config + trading_pair::Config + assets::Config
{
pub trait Config: frame_system::Config + common::Config + assets::Config {
type MockLiquiditySource: LiquiditySource<
Self::DEXId,
Self::AccountId,
Expand Down Expand Up @@ -388,6 +386,7 @@ pub mod pallet {
Balance,
DispatchError,
>;
type DexInfoProvider: DexInfoProvider<Self::DEXId, DEXInfo<Self::AssetId>>;

#[cfg(feature = "wip")] // order-book
type OrderBook: LiquiditySource<
Expand Down
1 change: 1 addition & 0 deletions pallets/dex-api/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl Config for Runtime {
type MulticollateralBondingCurvePool = ();
type XYKPool = pool_xyk::Pallet<Runtime>;
type XSTPool = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;

#[cfg(feature = "wip")] // order-book
type OrderBook = ();
Expand Down
2 changes: 1 addition & 1 deletion pallets/liquidity-proxy/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ benchmarks! {
}

new_trivial {
let dex_info = <T as trading_pair::Config>::DexInfoProvider::get_dex_info(&DEX.into())?;
let dex_info = <T as pool_xyk::Config>::DexInfoProvider::get_dex_info(&DEX.into())?;
let from_asset: T::AssetId = XSTUSD.into();
let to_asset: T::AssetId = VAL.into();
}: {
Expand Down
2 changes: 2 additions & 0 deletions pallets/liquidity-proxy/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ impl dex_api::Config for Runtime {
type XYKPool = pool_xyk::Pallet<Runtime>;
type XSTPool = ();
type MulticollateralBondingCurvePool = multicollateral_bonding_curve_pool::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;

#[cfg(feature = "wip")] // order-book
type OrderBook = ();
Expand Down Expand Up @@ -523,6 +524,7 @@ impl pswap_distribution::Config for Runtime {
impl price_tools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LiquidityProxy = LiquidityProxy;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type WeightInfo = price_tools::weights::SubstrateWeight<Runtime>;
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/liquidity-proxy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl dex_api::Config for Runtime {
type XYKPool = pool_xyk::Pallet<Runtime>;
type MulticollateralBondingCurvePool = MockMCBCPool;
type XSTPool = MockXSTPool;

type DexInfoProvider = dex_manager::Pallet<Runtime>;
#[cfg(feature = "wip")] // order-book
type OrderBook = (); // todo
}
Expand Down
18 changes: 6 additions & 12 deletions pallets/multicollateral-bonding-curve-pool/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use crate::Pallet as MBCPool;
use assets::Pallet as Assets;
use permissions::Pallet as Permissions;
use pool_xyk::Pallet as XYKPool;
use trading_pair::Pallet as TradingPair;

#[cfg(not(test))]
use price_tools::Pallet as PriceTools;
Expand Down Expand Up @@ -176,8 +175,7 @@ benchmarks! {
None,
None
).unwrap();
TradingPair::<T>::register(
RawOrigin::Signed(caller.clone()).into(),
<T as pallet::Config>::TradingPairSourceManager::register_pair(
common::DEXId::Polkaswap.into(),
XOR.into(),
USDT.into()
Expand Down Expand Up @@ -244,7 +242,7 @@ benchmarks! {
None,
None
).unwrap();
TradingPair::<T>::register(RawOrigin::Signed(caller.clone()).into(), common::DEXId::Polkaswap.into(), XOR.into(), USDT.into()).unwrap();
<T as pallet::Config>::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), XOR.into(), USDT.into()).unwrap();
MBCPool::<T>::initialize_pool(RawOrigin::Signed(caller.clone()).into(), USDT.into()).unwrap();
}: {
Pallet::<T>::set_optional_reward_multiplier(
Expand Down Expand Up @@ -333,8 +331,7 @@ benchmarks! {
None,
)
.unwrap();
TradingPair::<T>::register(
RawOrigin::Signed(caller.clone()).into(),
<T as pallet::Config>::TradingPairSourceManager::register_pair(
common::DEXId::Polkaswap.into(),
XOR.into(),
USDT.into(),
Expand Down Expand Up @@ -393,8 +390,7 @@ benchmarks! {
balance!(50000000),
)
.unwrap();
TradingPair::<T>::register(
RawOrigin::Signed(caller.clone()).into(),
<T as pallet::Config>::TradingPairSourceManager::register_pair(
common::DEXId::Polkaswap.into(),
XOR.into(),
USDT.into(),
Expand Down Expand Up @@ -452,8 +448,7 @@ benchmarks! {
None,
None
).unwrap();
TradingPair::<T>::register(
RawOrigin::Signed(caller.clone()).into(),
<T as pallet::Config>::TradingPairSourceManager::register_pair(
common::DEXId::Polkaswap.into(),
XOR.into(),
USDT.into()
Expand Down Expand Up @@ -502,8 +497,7 @@ benchmarks! {
balance!(50000000),
)
.unwrap();
TradingPair::<T>::register(
RawOrigin::Signed(caller.clone()).into(),
<T as pallet::Config>::TradingPairSourceManager::register_pair(
common::DEXId::Polkaswap.into(),
XOR.into(),
USDT.into(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/multicollateral-bonding-curve-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
common::with_transaction(|| {
let base_asset_id = T::GetBaseAssetId::get();
let swapped_xor_amount = <T as pallet::Config>::LiquidityProxy::exchange(
let swapped_xor_amount = T::LiquidityProxy::exchange(
DEXId::Polkaswap.into(),
holder,
holder,
Expand Down
1 change: 1 addition & 0 deletions pallets/multicollateral-bonding-curve-pool/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ impl pswap_distribution::Config for Runtime {
impl price_tools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LiquidityProxy = ();
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type WeightInfo = price_tools::weights::SubstrateWeight<Runtime>;
}

Expand Down
11 changes: 4 additions & 7 deletions pallets/order-book/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ use assets::AssetIdOf;
use codec::Decode;
use common::prelude::{QuoteAmount, SwapAmount};
use common::{
balance, AssetInfoProvider, AssetName, AssetSymbol, DEXId, LiquiditySource, PriceVariant, VAL,
XOR,
balance, AssetInfoProvider, AssetName, AssetSymbol, DEXId, LiquiditySource, PriceVariant,
TradingPairSourceManager, VAL, XOR,
};
use frame_benchmarking::benchmarks;
use frame_support::traits::Time;
Expand All @@ -65,7 +65,6 @@ use sp_runtime::traits::UniqueSaturatedInto;

use assets::Pallet as Assets;
use frame_system::Pallet as FrameSystem;
use trading_pair::Pallet as TradingPair;
use Pallet as OrderBookPallet;

pub const DEX: DEXId = DEXId::Polkaswap;
Expand Down Expand Up @@ -291,8 +290,7 @@ benchmarks! {
quote: XOR.into(),
};

TradingPair::<T>::register(
RawOrigin::Signed(caller.clone()).into(),
T::TradingPairSourceManager::register_pair(
DEX.into(),
order_book_id.quote,
order_book_id.base
Expand Down Expand Up @@ -565,8 +563,7 @@ benchmarks! {
balance!(1000000).try_into().unwrap()
).unwrap();

TradingPair::<T>::register(
RawOrigin::Signed(creator.clone()).into(),
T::TradingPairSourceManager::register_pair(
DEX.into(),
order_book_id.quote,
order_book_id.base
Expand Down
2 changes: 0 additions & 2 deletions pallets/pool-xyk/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ fn alice<T: Config>() -> T::AccountId {
fn setup_benchmark_assets_only<T: Config>() -> Result<(), &'static str> {
let owner = alice::<T>();
frame_system::Pallet::<T>::inc_providers(&owner);
let owner_origin: <T as frame_system::Config>::RuntimeOrigin =
RawOrigin::Signed(owner.clone()).into();

// Grant permissions to self in case they haven't been explicitly given in genesis config
let _ = Permissions::<T>::assign_permission(
Expand Down
1 change: 1 addition & 0 deletions pallets/pool-xyk/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl dex_api::Config for Runtime {
type MulticollateralBondingCurvePool = ();
type XYKPool = pool_xyk::Pallet<Runtime>;
type XSTPool = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;

#[cfg(feature = "wip")] // order-book
type OrderBook = ();
Expand Down
14 changes: 7 additions & 7 deletions pallets/pool-xyk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<T: Config> Pallet<T> {
reserves_account_id: &T::AccountId,
fees_account_id: &T::AccountId,
) -> DispatchResult {
let dex_info = <T as pallet::Config>::DexInfoProvider::get_dex_info(dex_id)?;
let dex_info = T::DexInfoProvider::get_dex_info(dex_id)?;
let (sorted_asset_a, sorted_asset_b) = if dex_info.base_asset_id == *asset_a {
(asset_a, asset_b)
} else if dex_info.base_asset_id == *asset_b {
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<T: Config> Pallet<T> {
input_a_min: Balance,
input_b_min: Balance,
) -> DispatchResult {
let dex_info = <T as pallet::Config>::DexInfoProvider::get_dex_info(&dex_id)?;
let dex_info = T::DexInfoProvider::get_dex_info(&dex_id)?;
let (_, tech_acc_id) = Pallet::<T>::tech_account_from_dex_and_asset_pair(
dex_id,
input_asset_a,
Expand Down Expand Up @@ -307,7 +307,7 @@ impl<T: Config> Pallet<T> {
output_a_min: Balance,
output_b_min: Balance,
) -> DispatchResult {
let dex_info = <T as pallet::Config>::DexInfoProvider::get_dex_info(&dex_id)?;
let dex_info = T::DexInfoProvider::get_dex_info(&dex_id)?;
let (_, tech_acc_id) = Pallet::<T>::tech_account_from_dex_and_asset_pair(
dex_id,
output_asset_a,
Expand Down Expand Up @@ -358,7 +358,7 @@ impl<T: Config> LiquiditySource<T::DEXId, T::AccountId, T::AssetId, Balance, Dis
input_asset_id: &T::AssetId,
output_asset_id: &T::AssetId,
) -> bool {
if let Ok(dex_info) = <T as pallet::Config>::DexInfoProvider::get_dex_info(dex_id) {
if let Ok(dex_info) = T::DexInfoProvider::get_dex_info(dex_id) {
let target_asset_id = if *input_asset_id == dex_info.base_asset_id {
output_asset_id
} else if *output_asset_id == dex_info.base_asset_id {
Expand All @@ -380,7 +380,7 @@ impl<T: Config> LiquiditySource<T::DEXId, T::AccountId, T::AssetId, Balance, Dis
amount: QuoteAmount<Balance>,
deduce_fee: bool,
) -> Result<(SwapOutcome<Balance>, Weight), DispatchError> {
let dex_info = <T as pallet::Config>::DexInfoProvider::get_dex_info(dex_id)?;
let dex_info = T::DexInfoProvider::get_dex_info(dex_id)?;
// Get pool account.
let (_, tech_acc_id) = Pallet::<T>::tech_account_from_dex_and_asset_pair(
*dex_id,
Expand Down Expand Up @@ -442,7 +442,7 @@ impl<T: Config> LiquiditySource<T::DEXId, T::AccountId, T::AssetId, Balance, Dis
output_asset_id: &T::AssetId,
swap_amount: SwapAmount<Balance>,
) -> Result<(SwapOutcome<Balance>, Weight), DispatchError> {
let dex_info = <T as pallet::Config>::DexInfoProvider::get_dex_info(&dex_id)?;
let dex_info = T::DexInfoProvider::get_dex_info(&dex_id)?;
let (_, tech_acc_id) = Pallet::<T>::tech_account_from_dex_and_asset_pair(
*dex_id,
*input_asset_id,
Expand Down Expand Up @@ -521,7 +521,7 @@ impl<T: Config> LiquiditySource<T::DEXId, T::AccountId, T::AssetId, Balance, Dis
amount: QuoteAmount<Balance>,
deduce_fee: bool,
) -> Result<SwapOutcome<Balance>, DispatchError> {
let dex_info = <T as pallet::Config>::DexInfoProvider::get_dex_info(dex_id)?;
let dex_info = T::DexInfoProvider::get_dex_info(dex_id)?;
// Get pool account.
let (_, tech_acc_id) = Pallet::<T>::tech_account_from_dex_and_asset_pair(
*dex_id,
Expand Down
Loading