Skip to content

Commit

Permalink
change config this points to and support devnet for get all markets (#26
Browse files Browse the repository at this point in the history
)

* change config this points to and support devnet for get all markets

* update readme
  • Loading branch information
RahulJain28 authored Mar 16, 2023
1 parent 841a371 commit 7b95aaf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Optionally include the following parameters when running the cli:


### get-all-markets
Returns summary information on all markets that exist on Phoenix. Summary information includes market key, base and quote token keys, and authority key. Highly recommended to use the no-gpa flag for mainnet.
Returns summary information on all markets that exist on Phoenix. Summary information includes market key, base and quote token keys, and authority key. Recommended to use the no-gpa flag to read from a static config file and avoiding making an expensive network call.

`$ phoenix-cli -u main get-all-markets --no-gpa`
```
Expand Down
4 changes: 2 additions & 2 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use solana_sdk::signature::Signature;
pub enum PhoenixCLICommand {
/// Get summary information on all markets
GetAllMarkets {
/// Optionally skip the GetProgramAccounts network call. This will read a static list of markets in the config file instead.
/// Only for mainnet and highly recommended for mainnet
/// Optionally skip the GetProgramAccounts network call. This will read a static list of markets in a config file instead.
/// Highly recommended to use this flag as GetProgramAccounts is an expensive call.
#[clap(short, long, required = false)]
no_gpa: bool,
},
Expand Down
34 changes: 20 additions & 14 deletions src/lib/processor/process_get_all_markets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use phoenix_sdk::sdk_client::SDKClient;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use std::{mem::size_of, str::FromStr};

use std::collections::HashMap;
use crate::helpers::{market_helpers::get_all_markets, print_helpers::print_market_summary_data};

pub async fn process_get_all_markets(client: &EllipsisClient) -> anyhow::Result<()> {
Expand All @@ -30,12 +30,12 @@ pub async fn process_get_all_markets_no_gpa(
client: &EllipsisClient,
network_url: &str,
) -> anyhow::Result<()> {
let markets = get_market_config().await?;
let markets = get_market_config(client).await?.markets;

println!("Found {} market(s)", markets.len());

for market in markets {
let market_pubkey = Pubkey::from_str(&market.market)?;
let market_pubkey = Pubkey::from_str(&market)?;
let sdk = SDKClient::new(&market_pubkey, &client.payer, network_url).await;

let market_account_data = sdk.client.get_account_data(&market_pubkey).await?;
Expand All @@ -48,23 +48,29 @@ pub async fn process_get_all_markets_no_gpa(
Ok(())
}

#[derive(Serialize, Deserialize)]
struct MarketStatic {
market: String,
base_ticker: String,
quote_ticker: String,
base_pubkey: String,
quote_pubkey: String,
#[derive(Serialize, Deserialize, Clone)]
pub struct JsonMarketConfig {
pub markets: Vec<String>,
}

async fn get_market_config() -> anyhow::Result<Vec<MarketStatic>> {
async fn get_market_config(client: &EllipsisClient) -> anyhow::Result<JsonMarketConfig> {
let genesis = client.get_genesis_hash().await?;

//hardcoded in the genesis hashes for mainnet and devnet
let cluster = match genesis.to_string().as_str() {
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d" => "mainnet-beta",
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG" => "devnet",
_ => "localhost",
};

let body = reqwest::get(
"https://raw.githubusercontent.com/Ellipsis-Labs/phoenix-sdk/master/mainnet_markets.json",
"https://raw.githubusercontent.com/Ellipsis-Labs/phoenix-sdk/master/markets.json",
)
.await?
.text()
.await?;

let markets: Vec<MarketStatic> = serde_json::from_str(&body)?;
Ok(markets)
let markets: HashMap<String, JsonMarketConfig> = serde_json::from_str(&body)?;

Ok(markets.get(cluster).ok_or(anyhow!("No markets found for cluster"))?.clone())
}

0 comments on commit 7b95aaf

Please sign in to comment.