Skip to content

Commit

Permalink
Get markets + all markets improvements (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
throwbackjams authored Feb 20, 2023
1 parent 8a85b76 commit beeea31
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ serde_json = "1.0"
spl-associated-token-account = { version = "1.1.1", features = [ "no-entrypoint" ] }
phoenix-v1 = "0.1.1"
phoenix-sdk = { version = "0.1.0" }
bytemuck = "1.13.0"
bytemuck = "1.13.0"
reqwest = "0.11.14"
5 changes: 4 additions & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use solana_sdk::signature::Signature;
#[derive(Debug, Clone, Parser)]
pub enum PhoenixCLICommand {
/// Get summary information on all markets
GetAllMarkets,
GetAllMarkets {
#[clap(short, long, required = false)]
no_gpa: bool,
},
/// Get detailed information on a specific market
GetMarket { market_pubkey: Pubkey },
/// Get active traders for a given market
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helpers/devnet_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub mod devnet_token_faucet {
let mint = get_mint_address(&ticker);
let mint_authority = get_mint_authority_address(&ticker);

let destination = spl_associated_token_account::get_associated_token_address(&payer, &mint);
let destination = spl_associated_token_account::get_associated_token_address(payer, &mint);

let accounts_vec: Vec<AccountMeta> = vec![
AccountMeta::new(mint, false),
Expand Down Expand Up @@ -118,7 +118,7 @@ pub mod devnet_token_faucet {
payer: &Pubkey,
amount: u64,
) -> Instruction {
let destination = spl_associated_token_account::get_associated_token_address(&payer, &mint);
let destination = spl_associated_token_account::get_associated_token_address(payer, mint);

let accounts_vec: Vec<AccountMeta> = vec![
AccountMeta::new(*mint, false),
Expand Down
23 changes: 18 additions & 5 deletions src/lib/helpers/print_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::BTreeMap;

use colored::Colorize;
use phoenix::program::get_vault_address;
use phoenix::program::status::MarketStatus;
use phoenix::program::MarketHeader;
use phoenix::state::{markets::Ladder, Side, TraderState};
use phoenix_sdk::sdk_client::*;
Expand Down Expand Up @@ -122,6 +123,11 @@ pub async fn print_market_details(

let quote_vault_acct =
spl_token::state::Account::unpack(&sdk.client.get_account(&quote_vault).await?.data)?;
println!("--------------------------------------------");
println!("Market: {}", market_pubkey);
println!("Status: {}", MarketStatus::from(market_header.status));
println!("Authority: {}", market_header.authority);
println!("Sequence number: {}", market_header.market_sequence_number);

println!(
"Base Vault balance: {:.3}",
Expand All @@ -135,29 +141,36 @@ pub async fn print_market_details(

println!("Base Token: {}", base_pubkey);
println!("Quote Token: {}", quote_pubkey);

println!("Base vault key: {}", market_header.base_params.vault_key);
println!("Quote vault key: {}", market_header.quote_params.vault_key);

println!(
"Base Lot Size: {}",
"Base Lot Size, in whole units: {}",
get_decimal_string(market_metadata.base_lot_size, market_metadata.base_decimals),
);

println!(
"Quote Lot Size: {}",
"Quote Lot Size, in whole units: {}",
get_decimal_string(
market_metadata.quote_lot_size,
market_metadata.quote_decimals
)
);
println!(
"Tick size: {}",
"Tick size in quote atoms per base unit: {}",
get_decimal_string(
market_metadata.tick_size_in_quote_atoms_per_base_unit,
market_metadata.quote_decimals
)
);
println!("Taker fees in basis points: {}", taker_fees);
println!("Fee destination pubkey: {:?}", market_header.fee_recipient);
println!(
"Raw base units per base unit: {}",
market_metadata.raw_base_units_per_base_unit
);
println!("Market Size Params: {:?}", market_header.market_size_params);
println!("Successor pubkey: {:?}", market_header.successor);
println!("Sequence number: {}", market_header.market_sequence_number);
Ok(())
}

Expand Down
48 changes: 47 additions & 1 deletion src/lib/processor/process_get_all_markets.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use anyhow::anyhow;
use ellipsis_client::EllipsisClient;
use phoenix::program::MarketHeader;
use std::mem::size_of;
use phoenix_sdk::sdk_client::SDKClient;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use std::{mem::size_of, str::FromStr};

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

Expand All @@ -22,3 +25,46 @@ pub async fn process_get_all_markets(client: &EllipsisClient) -> anyhow::Result<
}
Ok(())
}

pub async fn process_get_all_markets_no_gpa(
client: &EllipsisClient,
network_url: &str,
) -> anyhow::Result<()> {
let markets = get_market_config().await?;

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

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

let market_account_data = sdk.client.get_account_data(&market_pubkey).await?;
let (header_bytes, _market_bytes) = market_account_data.split_at(size_of::<MarketHeader>());
let header: &MarketHeader = bytemuck::try_from_bytes(header_bytes)
.map_err(|e| anyhow::anyhow!("Error getting market header. Error: {:?}", e))?;

print_market_summary_data(&market_pubkey, header);
}
Ok(())
}

#[derive(Serialize, Deserialize)]
struct MarketStatic {
market: String,
base_ticker: String,
quote_ticker: String,
base_pubkey: String,
quote_pubkey: String,
}

async fn get_market_config() -> anyhow::Result<Vec<MarketStatic>> {
let body = reqwest::get(
"https://raw.githubusercontent.com/Ellipsis-Labs/phoenix-sdk/master/mainnet_markets.json",
)
.await?
.text()
.await?;

let markets: Vec<MarketStatic> = serde_json::from_str(&body)?;
Ok(markets)
}
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ async fn main() -> anyhow::Result<()> {
let sdk = SDKClient::new(&market_pubkey, &payer, network_url).await;
process_get_market(&market_pubkey, &sdk).await?
}
PhoenixCLICommand::GetAllMarkets => process_get_all_markets(&client).await?,
PhoenixCLICommand::GetAllMarkets { no_gpa } => {
if no_gpa {
process_get_all_markets_no_gpa(&client, network_url).await?
} else {
process_get_all_markets(&client).await?
}
}
PhoenixCLICommand::GetTradersForMarket { market_pubkey } => {
let sdk = SDKClient::new(&market_pubkey, &payer, network_url).await;
process_get_traders_for_market(&market_pubkey, &sdk).await?
Expand Down

0 comments on commit beeea31

Please sign in to comment.