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
Next Next commit
remove trading_pair dependency in liquidity_proxy pallet
  • Loading branch information
TheLedgerOfJoudi committed Oct 30, 2023
commit c92642b62ae2e05cdc3a8be108bfbadb4ec6c72f
22 changes: 22 additions & 0 deletions common/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@ pub trait LiquiditySource<TargetId, AccountId, AssetId, Amount, Error> {
fn check_rewards_weight() -> Weight;
}

/// Implements trading pairs LockedLiquiditySources storage

pub trait LockedLiquiditySourcesManager<LiquiditySourceType> {
fn get() -> Vec<LiquiditySourceType>;
fn set(liquidity_source_types: Vec<LiquiditySourceType>) -> ();
fn append(liquidity_source_type: LiquiditySourceType) -> ();
}

impl<LiquiditySourceType> LockedLiquiditySourcesManager<LiquiditySourceType> for () {
fn get() -> Vec<LiquiditySourceType> {
todo!()
}

fn set(_liquidity_source_types: Vec<LiquiditySourceType>) -> () {
todo!()
}

fn append(_liquidity_source_type: LiquiditySourceType) -> () {
todo!()
}
}

/// *Hook*-like trait for oracles to capture newly relayed symbols.
///
/// A struct implementing this trait can be specified in oracle pallet *Config*
Expand Down
3 changes: 3 additions & 0 deletions pallets/liquidity-proxy/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ impl liquidity_proxy::Config for Runtime {
type PrimaryMarketXST = ();
type SecondaryMarket = ();
type VestedRewardsPallet = vested_rewards::Pallet<Runtime>;
type LockedLiquiditySourcesManager = trading_pair::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type GetADARAccountId = GetADARAccountId;
type ADARCommissionRatioUpdateOrigin = EnsureRoot<AccountId>;
type MaxAdditionalDataLength = ConstU32<128>;
Expand Down
25 changes: 13 additions & 12 deletions pallets/liquidity-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use common::{
balance, fixed_wrapper, AccountIdOf, AssetInfoProvider, BuyBackHandler, DEXInfo, DexIdOf,
DexInfoProvider, FilterMode, Fixed, GetMarketInfo, GetPoolReserves, LiquidityProxyTrait,
LiquidityRegistry, LiquiditySource, LiquiditySourceFilter, LiquiditySourceId,
LiquiditySourceType, RewardReason, TradingPair, TradingPairSourceManager, VestedRewardsPallet,
XSTUSD,
LiquiditySourceType, LockedLiquiditySourcesManager, RewardReason, TradingPair,
TradingPairSourceManager, VestedRewardsPallet, XSTUSD,
};
use fallible_iterator::FallibleIterator as _;
use frame_support::dispatch::PostDispatchInfo;
Expand Down Expand Up @@ -986,7 +986,7 @@ impl<T: Config> Pallet<T> {
let mut sources =
T::LiquidityRegistry::list_liquidity_sources(input_asset_id, output_asset_id, filter)?;
let mut total_weight = <T as Config>::WeightInfo::list_liquidity_sources();
let locked = trading_pair::LockedLiquiditySources::<T>::get();
let locked = T::LockedLiquiditySourcesManager::get();
sources.retain(|x| !locked.contains(&x.liquidity_source_index));
ensure!(!sources.is_empty(), Error::<T>::UnavailableExchangePath);

Expand Down Expand Up @@ -1108,7 +1108,7 @@ impl<T: Config> Pallet<T> {
let pair = Self::weak_sort_pair(&dex_info, *from, *to);

// TODO: #441 use TradingPairSourceManager instead of trading-pair pallet
trading_pair::Pallet::<T>::list_enabled_sources_for_trading_pair(
T::TradingPairSourceManager::list_enabled_sources_for_trading_pair(
dex_id,
&pair.base_asset_id,
&pair.target_asset_id,
Expand All @@ -1129,7 +1129,7 @@ impl<T: Config> Pallet<T> {
let pair = Self::weak_sort_pair(&dex_info, *from, *to);

// TODO: #441 use TradingPairSourceManager instead of trading-pair pallet
let sources = trading_pair::Pallet::<T>::list_enabled_sources_for_trading_pair(
let sources = T::TradingPairSourceManager::list_enabled_sources_for_trading_pair(
&dex_id,
&pair.base_asset_id,
&pair.target_asset_id,
Expand Down Expand Up @@ -2199,9 +2199,7 @@ pub mod pallet {
// TODO: #395 use AssetInfoProvider instead of assets pallet
// TODO: #441 use TradingPairSourceManager instead of trading-pair pallet
#[pallet::config]
pub trait Config:
frame_system::Config + common::Config + assets::Config + trading_pair::Config
{
pub trait Config: frame_system::Config + common::Config + assets::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type LiquidityRegistry: LiquidityRegistry<
Self::DEXId,
Expand All @@ -2217,9 +2215,12 @@ pub mod pallet {
type PrimaryMarketXST: GetMarketInfo<Self::AssetId>;
type SecondaryMarket: GetPoolReserves<Self::AssetId>;
type VestedRewardsPallet: VestedRewardsPallet<Self::AccountId, Self::AssetId>;
type TradingPairSourceManager: TradingPairSourceManager<Self::DEXId, Self::AssetId>;
type LockedLiquiditySourcesManager: LockedLiquiditySourcesManager<LiquiditySourceType>;
type GetADARAccountId: Get<Self::AccountId>;
type ADARCommissionRatioUpdateOrigin: EnsureOrigin<Self::RuntimeOrigin>;
type MaxAdditionalDataLength: Get<u32>;
type DexInfoProvider: DexInfoProvider<Self::DEXId, DEXInfo<Self::AssetId>>;
/// Weight information for the extrinsics in this Pallet.
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -2390,15 +2391,15 @@ pub mod pallet {
Error::<T>::UnableToEnableLiquiditySource
);

let mut locked = trading_pair::LockedLiquiditySources::<T>::get();
let mut locked = T::LockedLiquiditySourcesManager::get();

ensure!(
locked.contains(&liquidity_source),
Error::<T>::LiquiditySourceAlreadyEnabled
);

locked.retain(|x| *x != liquidity_source);
trading_pair::LockedLiquiditySources::<T>::set(locked);
T::LockedLiquiditySourcesManager::set(locked);
Self::deposit_event(Event::<T>::LiquiditySourceEnabled(liquidity_source));
Ok(().into())
}
Expand All @@ -2420,10 +2421,10 @@ pub mod pallet {
Error::<T>::UnableToDisableLiquiditySource
);
ensure!(
!trading_pair::LockedLiquiditySources::<T>::get().contains(&liquidity_source),
!T::LockedLiquiditySourcesManager::get().contains(&liquidity_source),
Error::<T>::LiquiditySourceAlreadyDisabled
);
trading_pair::LockedLiquiditySources::<T>::append(liquidity_source);
T::LockedLiquiditySourcesManager::append(liquidity_source);
Self::deposit_event(Event::<T>::LiquiditySourceDisabled(liquidity_source));
Ok(().into())
}
Expand Down
4 changes: 4 additions & 0 deletions pallets/liquidity-proxy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,13 @@ impl Config for Runtime {
type PrimaryMarketXST = MockXSTPool;
type SecondaryMarket = mock_liquidity_source::Pallet<Runtime, mock_liquidity_source::Instance1>;
type VestedRewardsPallet = vested_rewards::Pallet<Runtime>;

type GetADARAccountId = GetADARAccountId;
type ADARCommissionRatioUpdateOrigin = EnsureRoot<AccountId>;
type MaxAdditionalDataLength = ConstU32<128>;
type LockedLiquiditySourcesManager = trading_pair::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
}

impl tokens::Config for Runtime {
Expand Down
14 changes: 13 additions & 1 deletion pallets/trading-pair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern crate alloc;

use common::{
AssetInfoProvider, DexInfoProvider, EnsureDEXManager, EnsureTradingPairExists,
LiquiditySourceType, ManagementMode, TradingPairSourceManager,
LiquiditySourceType, LockedLiquiditySourcesManager, ManagementMode, TradingPairSourceManager,
};
use frame_support::dispatch::{DispatchError, DispatchResult};
use frame_support::ensure;
Expand Down Expand Up @@ -75,6 +75,18 @@ impl<T: Config> EnsureTradingPairExists<T::DEXId, T::AssetId, DispatchError> for
}
}

impl<T: Config> LockedLiquiditySourcesManager<LiquiditySourceType> for Pallet<T> {
fn get() -> Vec<LiquiditySourceType> {
LockedLiquiditySources::<T>::get()
}
fn set(liquidity_source_types: Vec<LiquiditySourceType>) -> () {
LockedLiquiditySources::<T>::set(liquidity_source_types)
}
fn append(liquidity_source_type: LiquiditySourceType) -> () {
LockedLiquiditySources::<T>::append(liquidity_source_type)
}
}

impl<T: Config> TradingPairSourceManager<T::DEXId, T::AssetId> for Pallet<T> {
fn list_enabled_sources_for_trading_pair(
dex_id: &T::DEXId,
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,9 @@ impl liquidity_proxy::Config for Runtime {
type SecondaryMarket = pool_xyk::Pallet<Runtime>;
type WeightInfo = liquidity_proxy::weights::SubstrateWeight<Runtime>;
type VestedRewardsPallet = VestedRewards;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type LockedLiquiditySourcesManager = trading_pair::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type GetADARAccountId = GetADARAccountId;
type ADARCommissionRatioUpdateOrigin = EitherOfDiverse<
pallet_collective::EnsureProportionMoreThan<AccountId, TechnicalCollective, 1, 2>,
Expand Down