Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OCEX Benchmarks and Tests #920

Merged
merged 14 commits into from
Mar 5, 2024
Merged
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions pallets/liquidity-mining/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ pub fn add_lmp_config() {
max_accounts_rewarded,
claim_safety_period
));
OCEX::start_new_epoch();
OCEX::start_new_epoch();
OCEX::start_new_epoch(1);
OCEX::start_new_epoch(2);
}

fn add_liquidity() {
Expand Down Expand Up @@ -638,21 +638,17 @@ fn register_test_pool(public_fund_allowed: bool) {
fn register_test_trading_pair() {
let base = AssetId::Polkadex;
let quote = AssetId::Asset(1);
let min_order_price: u128 = UNIT_BALANCE * 2;
let max_order_price: u128 = UNIT_BALANCE * 10;
let min_order_qty: u128 = UNIT_BALANCE * 2;
let max_order_qty: u128 = UNIT_BALANCE * 10;
let min_volume: u128 = UNIT_BALANCE * 2;
let max_volume: u128 = UNIT_BALANCE * 10;
let price_tick_size: u128 = UNIT_BALANCE;
let qty_step_size: u128 = UNIT_BALANCE;
assert_ok!(OCEX::set_exchange_state(RuntimeOrigin::root(), true));
assert_ok!(OCEX::register_trading_pair(
RuntimeOrigin::root(),
base,
quote,
min_order_price,
max_order_price,
min_order_qty,
max_order_qty,
min_volume,
max_volume,
price_tick_size,
qty_step_size
));
Expand Down
3 changes: 3 additions & 0 deletions pallets/ocex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ sp-application-crypto = { workspace = true }
sp-keystore = { workspace = true }
sp-io = { workspace = true }
pallet-lmp = { path = "../liquidity-mining", default-features = false }
lazy_static = "1.4.0"
sequential-test = "0.2.4"

[features]
default = ["std"]
Expand All @@ -62,6 +64,7 @@ std = [
"hash-db/std",
"trie-db/std",
"polkadex-primitives/std",
"frame-benchmarking?/std",
"rust_decimal/std",
"pallet-timestamp/std",
"sp-core/std",
Expand Down
12 changes: 6 additions & 6 deletions pallets/ocex/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub trait PolkadexOcexRpcApi<BlockHash, AccountId, Hash> {
market: String,
epoch: u16,
at: Option<BlockHash>,
) -> RpcResult<Vec<u16>>;
) -> RpcResult<String>;

#[method(name = "lmp_traderMetrics")]
fn get_trader_metrics(
Expand All @@ -125,7 +125,7 @@ pub trait PolkadexOcexRpcApi<BlockHash, AccountId, Hash> {
main: AccountId,
epoch: u16,
at: Option<BlockHash>,
) -> RpcResult<Vec<u16>>;
) -> RpcResult<(String, String, bool)>;
}

/// A structure that represents the Polkadex OCEX pallet RPC, which allows querying
Expand Down Expand Up @@ -399,9 +399,9 @@ where
None => self.client.info().best_hash,
};

let score = api.get_total_score(at, market, epoch).map_err(runtime_error_into_rpc_err)?;
let score = api.get_total_score(at, epoch, market).map_err(runtime_error_into_rpc_err)?;

Ok(score.to_string())
Ok(format!("{} {}",score.0.to_string(),score.1.to_string()))

}

Expand All @@ -414,8 +414,8 @@ where
None => self.client.info().best_hash,
};

let (mm_score, trading_score, is_claimed) = api.get_trader_metrics(at, market, epoch).map_err(runtime_error_into_rpc_err)?;

let (mm_score, trading_score, is_claimed) = api.get_trader_metrics(at, epoch, market, main).map_err(runtime_error_into_rpc_err)?;
Ok((mm_score.to_string(), trading_score.to_string(), is_claimed))
}
}

Expand Down
2 changes: 2 additions & 0 deletions pallets/ocex/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl<T: Config> AggregatorClient<T> {
/// * `id`: Batch id to load
/// # Returns
/// * `Option<UserActionBatch<T::AccountId>>`: Loaded batch or None if error occured
#[cfg(not(test))]
pub fn get_user_action_batch(id: u64) -> Option<UserActionBatch<T::AccountId>> {
let body = serde_json::json!({ "id": id }).to_string();
let result = match Self::send_request(
Expand Down Expand Up @@ -143,6 +144,7 @@ impl<T: Config> AggregatorClient<T> {
/// * `body`: Body of the request
/// # Returns
/// * `Result<Vec<u8>, &'static str>`: Response body or error message
#[cfg(not(test))]
pub fn send_request(log_target: &str, url: &str, body: &str) -> Result<Vec<u8>, &'static str> {
let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(12_000));

Expand Down
Loading