Skip to content

Commit ae0db41

Browse files
authored
Feature/split-threshold (#206)
* split threshold per trading pair * add fn ensure_can_enable_trading_pair * split threshold add unit tests * Refactoring code * Refactoring code * replace HashSet to vec * add trait MarginProtocolLiquidityPoolsManager * remove Hash * remove action from _enp_and_ell_risk_threshold_of_pool and _risk_threshold_of_trader * add margin _check_trader and _check_pool unit cases
1 parent 65bd096 commit ae0db41

File tree

13 files changed

+704
-285
lines changed

13 files changed

+704
-285
lines changed

modules/liquidity-pools/base/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use sp_runtime::{
1212
DispatchResult, ModuleId,
1313
};
1414
use sp_std::{prelude::*, result};
15-
use traits::{LiquidityPoolManager, LiquidityPools, OnDisableLiquidityPool, OnRemoveLiquidityPool};
15+
use traits::{BaseLiquidityPoolManager, LiquidityPools, OnDisableLiquidityPool, OnRemoveLiquidityPool};
1616

1717
mod mock;
1818
mod tests;
1919

2020
pub trait Trait<I: Instance = DefaultInstance>: system::Trait {
2121
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
2222
type LiquidityCurrency: BasicCurrency<Self::AccountId, Balance = Balance>;
23-
type PoolManager: LiquidityPoolManager<LiquidityPoolId, Balance>;
23+
type PoolManager: BaseLiquidityPoolManager<LiquidityPoolId, Balance>;
2424
type ExistentialDeposit: Get<Balance>;
2525
type ModuleId: Get<ModuleId>;
2626
type OnDisableLiquidityPool: OnDisableLiquidityPool;

modules/liquidity-pools/base/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl orml_tokens::Trait for Runtime {
8686
}
8787

8888
pub struct PoolManager;
89-
impl LiquidityPoolManager<LiquidityPoolId, Balance> for PoolManager {
89+
impl BaseLiquidityPoolManager<LiquidityPoolId, Balance> for PoolManager {
9090
fn can_remove(_pool_id: LiquidityPoolId) -> bool {
9191
true
9292
}

modules/liquidity-pools/margin/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use primitives::{AccumulateConfig, Balance, CurrencyId, Leverage, Leverages, Liq
1616
use sp_arithmetic::Fixed128;
1717
use sp_runtime::{traits::Saturating, DispatchResult, ModuleId, RuntimeDebug};
1818
use sp_std::{cmp::max, prelude::*};
19-
use traits::{LiquidityPools, MarginProtocolLiquidityPools, OnDisableLiquidityPool, OnRemoveLiquidityPool};
19+
use traits::{
20+
LiquidityPools, MarginProtocolLiquidityPools, MarginProtocolLiquidityPoolsManager, OnDisableLiquidityPool,
21+
OnRemoveLiquidityPool,
22+
};
2023

2124
#[cfg(feature = "std")]
2225
use serde::{Deserialize, Serialize};
@@ -40,6 +43,7 @@ pub const MODULE_ID: ModuleId = ModuleId(*b"lami/mlp");
4043
pub trait Trait: frame_system::Trait {
4144
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
4245
type BaseLiquidityPools: LiquidityPools<Self::AccountId>;
46+
type PoolManager: MarginProtocolLiquidityPoolsManager;
4347
type MultiCurrency: MultiCurrency<Self::AccountId, Balance = Balance, CurrencyId = CurrencyId>;
4448
type UpdateOrigin: EnsureOrigin<Self::Origin>;
4549
type MaxSwap: Get<Fixed128>;
@@ -192,6 +196,9 @@ decl_module! {
192196
let who = ensure_signed(origin)?;
193197
ensure!(Self::is_owner(pool_id, &who), Error::<T>::NoPermission);
194198
ensure!(Self::enabled_trading_pair(&pair).is_some(), Error::<T>::TradingPairNotEnabled);
199+
200+
<T::PoolManager as MarginProtocolLiquidityPoolsManager>::ensure_can_enable_trading_pair(pool_id, pair)?;
201+
195202
LiquidityPoolEnabledTradingPairs::insert(&pool_id, &pair, true);
196203
Self::deposit_event(RawEvent::LiquidityPoolTradingPairEnabled(pair))
197204
}

modules/liquidity-pools/margin/src/mock.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use sp_runtime::{
1414
use orml_currencies::Currency;
1515

1616
use primitives::{Balance, CurrencyId, LiquidityPoolId};
17-
use traits::LiquidityPoolManager;
17+
use traits::{BaseLiquidityPoolManager, MarginProtocolLiquidityPoolsManager};
1818

1919
pub type BlockNumber = u64;
2020
pub type AccountId = u32;
@@ -89,7 +89,7 @@ impl orml_tokens::Trait for Runtime {
8989
}
9090

9191
pub struct PoolManager;
92-
impl LiquidityPoolManager<LiquidityPoolId, Balance> for PoolManager {
92+
impl BaseLiquidityPoolManager<LiquidityPoolId, Balance> for PoolManager {
9393
fn can_remove(_pool_id: LiquidityPoolId) -> bool {
9494
true
9595
}
@@ -115,9 +115,17 @@ impl module_base_liquidity_pools::Trait<MarginInstance> for Runtime {
115115
}
116116
pub type BaseLiquidityPools = module_base_liquidity_pools::Module<Runtime, MarginInstance>;
117117

118+
pub struct DummyPoolManager;
119+
impl MarginProtocolLiquidityPoolsManager for DummyPoolManager {
120+
fn ensure_can_enable_trading_pair(_pool_id: LiquidityPoolId, _pair: TradingPair) -> DispatchResult {
121+
Ok(())
122+
}
123+
}
124+
118125
impl Trait for Runtime {
119126
type Event = ();
120127
type BaseLiquidityPools = module_base_liquidity_pools::Module<Runtime, MarginInstance>;
128+
type PoolManager = DummyPoolManager;
121129
type MultiCurrency = orml_currencies::Module<Runtime>;
122130
type UpdateOrigin = EnsureSignedBy<One, AccountId>;
123131
type MaxSwap = MaxSwap;

modules/liquidity-pools/synthetic/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use sp_runtime::{
1313

1414
use orml_currencies::Currency;
1515
use primitives::{Balance, CurrencyId, LiquidityPoolId};
16-
use traits::LiquidityPoolManager;
16+
use traits::BaseLiquidityPoolManager;
1717

1818
pub type BlockNumber = u64;
1919
pub type AccountId = u32;
@@ -88,7 +88,7 @@ impl orml_tokens::Trait for Runtime {
8888

8989
pub struct PoolManager;
9090

91-
impl LiquidityPoolManager<LiquidityPoolId, Balance> for PoolManager {
91+
impl BaseLiquidityPoolManager<LiquidityPoolId, Balance> for PoolManager {
9292
fn can_remove(_pool_id: LiquidityPoolId) -> bool {
9393
true
9494
}

0 commit comments

Comments
 (0)