From 14a6d9dedd924d5bc1b3a6a1c35a0345dcb14ea9 Mon Sep 17 00:00:00 2001 From: Rahul Jain Date: Thu, 16 Mar 2023 15:50:28 -0400 Subject: [PATCH 1/2] change config this points to and support devnet for get all markets --- src/command.rs | 4 +-- src/lib/processor/process_get_all_markets.rs | 34 ++++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/command.rs b/src/command.rs index 2cc2a4d..05a6a2f 100644 --- a/src/command.rs +++ b/src/command.rs @@ -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, }, diff --git a/src/lib/processor/process_get_all_markets.rs b/src/lib/processor/process_get_all_markets.rs index c8a6b27..d23c4e1 100644 --- a/src/lib/processor/process_get_all_markets.rs +++ b/src/lib/processor/process_get_all_markets.rs @@ -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<()> { @@ -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?; @@ -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, } -async fn get_market_config() -> anyhow::Result> { +async fn get_market_config(client: &EllipsisClient) -> anyhow::Result { + 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 = serde_json::from_str(&body)?; - Ok(markets) + let markets: HashMap = serde_json::from_str(&body)?; + + Ok(markets.get(cluster).ok_or(anyhow!("No markets found for cluster"))?.clone()) } From f0dae5f97a8d006a928daf4fbefca4626210351d Mon Sep 17 00:00:00 2001 From: Rahul Jain Date: Thu, 16 Mar 2023 15:52:24 -0400 Subject: [PATCH 2/2] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f21f8bc..5eadda4 100644 --- a/README.md +++ b/README.md @@ -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` ```