From f9426983243462a446ae1e48b3964964e6c8b219 Mon Sep 17 00:00:00 2001 From: zktony Date: Fri, 23 Feb 2024 17:01:29 +0530 Subject: [PATCH 1/2] Updated lmp_config ext --- pallets/ocex/src/lib.rs | 126 +++++++++++++++++++++--------- pallets/ocex/src/validator.rs | 2 +- primitives/orderbook/src/types.rs | 8 ++ 3 files changed, 97 insertions(+), 39 deletions(-) diff --git a/pallets/ocex/src/lib.rs b/pallets/ocex/src/lib.rs index 7ca17d1dd..96005a28b 100644 --- a/pallets/ocex/src/lib.rs +++ b/pallets/ocex/src/lib.rs @@ -61,6 +61,7 @@ use orderbook_primitives::{ }; //pub use pallet::*; use polkadex_primitives::ocex::TradingPairConfig; +use orderbook_primitives::types::LmpConfig; use sp_std::collections::btree_set::BTreeSet; use sp_std::vec::Vec; @@ -1002,18 +1003,15 @@ pub mod pallet { Ok(()) } - /// Set Incentivised markets #[pallet::call_index(20)] #[pallet::weight(10_000)] - pub fn set_lmp_epoch_config( - origin: OriginFor, - total_liquidity_mining_rewards: Option>, - total_trading_rewards: Option>, - market_weightage: Option>, - min_fees_paid: Option>, - min_maker_volume: Option>, - max_accounts_rewarded: Option, - claim_safety_period: Option, + pub fn set_lmp_epoch_config(origin: OriginFor, + total_liquidity_mining_rewards: Option>, + total_trading_rewards: Option>, + lmp_config: Vec, + max_accounts_rewarded: Option, + claim_safety_period: Option, + ) -> DispatchResult { T::GovernanceOrigin::ensure_origin(origin)?; let mut config = >::get(); @@ -1025,37 +1023,24 @@ pub mod pallet { if let Some(total_trading_rewards) = total_trading_rewards { config.total_trading_rewards = Decimal::from(total_trading_rewards.0).div(unit); } - if let Some(market_weightage) = market_weightage { - let mut total_percent: u128 = 0u128; - let mut weightage_map = BTreeMap::new(); - for (market, percent) in market_weightage { - // Check if market is registered - ensure!( - >::get(market.base, market.quote).is_some(), + let mut total_percent: u128 = 0u128; + let mut weightage_map = BTreeMap::new(); + let mut fees_map = BTreeMap::new(); + let mut volume_map = BTreeMap::new(); + for market_config in lmp_config { + ensure!( + >::get(market_config.trading_pair.base, market_config.trading_pair.quote).is_some(), Error::::TradingPairNotRegistered ); - // Add market weightage to total percent - total_percent = total_percent.saturating_add(percent); - weightage_map.insert(market, Decimal::from(percent).div(unit)); - } - ensure!(total_percent == UNIT_BALANCE, Error::::InvalidMarketWeightage); - config.market_weightage = weightage_map; - } - if let Some(min_fees_paid) = min_fees_paid { - let mut fees_map = BTreeMap::new(); - for (market, fees_in_quote) in min_fees_paid { - fees_map.insert(market, Decimal::from(fees_in_quote).div(unit)); - } - config.min_fees_paid = fees_map; - } - - if let Some(min_maker_volume) = min_maker_volume { - let mut volume_map = BTreeMap::new(); - for (market, volume_in_quote) in min_maker_volume { - volume_map.insert(market, Decimal::from(volume_in_quote).div(unit)); - } - config.min_maker_volume = volume_map; + total_percent = total_percent.saturating_add(market_config.market_weightage); + weightage_map.insert(market_config.trading_pair, Decimal::from(market_config.market_weightage).div(unit)); + fees_map.insert(market_config.trading_pair, Decimal::from(market_config.min_fees_paid).div(unit)); + volume_map.insert(market_config.trading_pair, Decimal::from(market_config.min_maker_volume).div(unit)); } + ensure!(total_percent == UNIT_BALANCE, Error::::InvalidMarketWeightage); + config.market_weightage = weightage_map; + config.min_fees_paid = fees_map; + config.min_maker_volume = volume_map; if let Some(max_accounts_rewarded) = max_accounts_rewarded { config.max_accounts_rewarded = max_accounts_rewarded; } @@ -1067,6 +1052,71 @@ pub mod pallet { Ok(()) } + // /// Set Incentivised markets + // #[pallet::call_index(20)] + // #[pallet::weight(10_000)] + // pub fn set_lmp_epoch_config( + // origin: OriginFor, + // total_liquidity_mining_rewards: Option>, + // total_trading_rewards: Option>, + // market_weightage: Option>, + // min_fees_paid: Option>, + // min_maker_volume: Option>, + // max_accounts_rewarded: Option, + // claim_safety_period: Option, + // ) -> DispatchResult { + // T::GovernanceOrigin::ensure_origin(origin)?; + // let mut config = >::get(); + // let unit: Decimal = Decimal::from(UNIT_BALANCE); + // if let Some(total_liquidity_mining_rewards) = total_liquidity_mining_rewards { + // config.total_liquidity_mining_rewards = + // Decimal::from(total_liquidity_mining_rewards.0).div(unit); + // } + // if let Some(total_trading_rewards) = total_trading_rewards { + // config.total_trading_rewards = Decimal::from(total_trading_rewards.0).div(unit); + // } + // if let Some(market_weightage) = market_weightage { + // let mut total_percent: u128 = 0u128; + // let mut weightage_map = BTreeMap::new(); + // for (market, percent) in market_weightage { + // // Check if market is registered + // ensure!( + // >::get(market.base, market.quote).is_some(), + // Error::::TradingPairNotRegistered + // ); + // // Add market weightage to total percent + // total_percent = total_percent.saturating_add(percent); + // weightage_map.insert(market, Decimal::from(percent).div(unit)); + // } + // ensure!(total_percent == UNIT_BALANCE, Error::::InvalidMarketWeightage); + // config.market_weightage = weightage_map; + // } + // if let Some(min_fees_paid) = min_fees_paid { + // let mut fees_map = BTreeMap::new(); + // for (market, fees_in_quote) in min_fees_paid { + // fees_map.insert(market, Decimal::from(fees_in_quote).div(unit)); + // } + // config.min_fees_paid = fees_map; + // } + // + // if let Some(min_maker_volume) = min_maker_volume { + // let mut volume_map = BTreeMap::new(); + // for (market, volume_in_quote) in min_maker_volume { + // volume_map.insert(market, Decimal::from(volume_in_quote).div(unit)); + // } + // config.min_maker_volume = volume_map; + // } + // if let Some(max_accounts_rewarded) = max_accounts_rewarded { + // config.max_accounts_rewarded = max_accounts_rewarded; + // } + // if let Some(claim_safety_period) = claim_safety_period { + // config.claim_safety_period = claim_safety_period; + // } + // ensure!(config.verify(), Error::::InvalidLMPConfig); + // >::put(config); + // Ok(()) + // } + /// Set Fee Distribution #[pallet::call_index(21)] #[pallet::weight(10_000)] diff --git a/pallets/ocex/src/validator.rs b/pallets/ocex/src/validator.rs index 641a070d6..2777caf21 100644 --- a/pallets/ocex/src/validator.rs +++ b/pallets/ocex/src/validator.rs @@ -63,7 +63,7 @@ pub const LAST_PROCESSED_SNAPSHOT: [u8; 26] = *b"offchain-ocex::snapshot_id"; /// as it verifies the signature and and relays them to destination. /// As a future improvment, we can make it decentralized, by having the community run /// such aggregation endpoints -pub const AGGREGATOR: &str = "https://ob.aggregator.polkadex.trade"; +pub const AGGREGATOR: &str = "https://test.aggregator.polkadex.trade"; pub const CHECKPOINT_BLOCKS: u64 = 1260; type TraderMetricsType = BTreeMap< diff --git a/primitives/orderbook/src/types.rs b/primitives/orderbook/src/types.rs index 1131644ac..d6ee4a8d3 100644 --- a/primitives/orderbook/src/types.rs +++ b/primitives/orderbook/src/types.rs @@ -980,3 +980,11 @@ pub struct ApprovedSnapshot { /// sr25519 signature of the authority pub signature: Vec, } + +#[derive(Clone, Debug, Encode, Decode, Eq, PartialEq, Serialize, Deserialize, TypeInfo)] +pub struct LmpConfig { + pub trading_pair: TradingPair, + pub market_weightage: u128, + pub min_fees_paid: u128, + pub min_maker_volume: u128 +} From 2869b7904d078f69e454406a7a7d4973c75785d2 Mon Sep 17 00:00:00 2001 From: zktony Date: Fri, 23 Feb 2024 17:36:41 +0530 Subject: [PATCH 2/2] Updated url --- pallets/ocex/src/validator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ocex/src/validator.rs b/pallets/ocex/src/validator.rs index 2777caf21..641a070d6 100644 --- a/pallets/ocex/src/validator.rs +++ b/pallets/ocex/src/validator.rs @@ -63,7 +63,7 @@ pub const LAST_PROCESSED_SNAPSHOT: [u8; 26] = *b"offchain-ocex::snapshot_id"; /// as it verifies the signature and and relays them to destination. /// As a future improvment, we can make it decentralized, by having the community run /// such aggregation endpoints -pub const AGGREGATOR: &str = "https://test.aggregator.polkadex.trade"; +pub const AGGREGATOR: &str = "https://ob.aggregator.polkadex.trade"; pub const CHECKPOINT_BLOCKS: u64 = 1260; type TraderMetricsType = BTreeMap<