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

add optional prio fees when sending transactions #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ anyhow = "1.0.66"
clap = { version = "4.0.26", features = ["derive"] }
shellexpand = "2.1.2"
solana-sdk = "1.10.32"
ellipsis-client = "0.2.0"
ellipsis-client = "0.2.1"
solana-client = "1.10.32"
solana-account-decoder = "1.14.7"
solana-cli-config = "1.14.7"
Expand Down
11 changes: 8 additions & 3 deletions src/lib/processor/process_claim_seat.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use ellipsis_client::EllipsisClient;
use phoenix_sdk::utils::create_claim_seat_ix_if_needed;
use solana_sdk::{pubkey::Pubkey, signer::Signer};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey, signer::Signer};

pub async fn process_claim_seat(
client: &EllipsisClient,
market_pubkey: &Pubkey,
prio_fee_instructions: Vec<Instruction>,
) -> anyhow::Result<()> {
let claim_seat_ix =
create_claim_seat_ix_if_needed(client, market_pubkey, &client.payer.pubkey()).await?;
println!("Claiming seat for pubkey: {}", client.payer.pubkey());

if !claim_seat_ix.is_empty() {
let tx = client.sign_send_instructions(claim_seat_ix, vec![]).await?;
println!("Claim seat transaction: {}", tx);
let ix_to_send = prio_fee_instructions
.into_iter()
.chain(claim_seat_ix)
.collect::<Vec<Instruction>>();
let tx = client.sign_send_instructions(ix_to_send, vec![]).await?;
println!("Claim seat transaction sent, signature: {} \nCan check transaction status with: phoenix-cli get-transaction {}", tx, tx);
} else {
println!("Seat already created for pubkey: {}", client.payer.pubkey());
}
Expand Down
11 changes: 7 additions & 4 deletions src/lib/processor/process_evict_seat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use phoenix_sdk::utils::get_evictable_trader_ix;
use phoenix_seat_manager::instruction_builders::{
create_evict_seat_instruction, EvictTraderAccountBackup,
};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};

pub async fn process_evict_seat(
client: &EllipsisClient,
market_pubkey: &Pubkey,
trader_to_evict: &Option<Pubkey>,
prio_fee_instructions: Vec<Instruction>,
) -> anyhow::Result<()> {
let market_bytes = client.get_account_data(market_pubkey).await?;
let (header_bytes, _market_bytes) = market_bytes.split_at(size_of::<MarketHeader>());
Expand All @@ -37,9 +38,11 @@ pub async fn process_evict_seat(

if let Some(evict_trader_ix) = maybe_evict_trader_ix {
println!("Evicting trader: {}", evict_trader_ix.accounts[13].pubkey);
let tx = client
.sign_send_instructions(vec![evict_trader_ix], vec![])
.await?;
let ix_to_send = prio_fee_instructions
.into_iter()
.chain(vec![evict_trader_ix])
.collect::<Vec<Instruction>>();
let tx = client.sign_send_instructions(ix_to_send, vec![]).await?;
println!("Evict trader tx: {}", tx);
} else {
println!("Cannot evict a trader when the market's trader state is not full.");
Expand Down
8 changes: 7 additions & 1 deletion src/lib/processor/process_get_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ pub async fn process_get_transaction(
let events = sdk
.parse_events_from_transaction(signature)
.await
.ok_or_else(|| anyhow::anyhow!("Failed to parse events from transaction"))?;
.ok_or_else(|| anyhow::anyhow!("Failed to find transaction"))?;
if events.is_empty() {
println!(
"Found Transaction: {} \nTransaction has no Trades, Places, or Cancels to log",
signature
);
}
log_market_events(sdk, events).await?;
Ok(())
}
19 changes: 15 additions & 4 deletions src/lib/processor/process_request_seat.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
use phoenix::program::instruction_builders::create_request_seat_instruction;
use phoenix_sdk::sdk_client::*;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};

pub async fn process_request_seat(market_pubkey: &Pubkey, sdk: &SDKClient) -> anyhow::Result<()> {
pub async fn process_request_seat(
market_pubkey: &Pubkey,
sdk: &SDKClient,
prio_fee_instructions: Vec<Instruction>,
) -> anyhow::Result<()> {
let ix = create_request_seat_instruction(&sdk.core.trader, market_pubkey);
let tx = sdk.client.sign_send_instructions(vec![ix], vec![]).await;
let ix_to_send = prio_fee_instructions
.into_iter()
.chain(vec![ix])
.collect::<Vec<Instruction>>();
let tx = sdk.client.sign_send_instructions(ix_to_send, vec![]).await;

match tx {
Ok(tx) => println!("Requested seat, transaction signature: {}", tx),
Ok(tx) => println!(
"Requested seat transaction sent, signature: {} \nCan check transaction status with: phoenix-cli get-transaction {}",
tx, tx
),
Err(e) => println!("Error requesting seat: {}", e),
}

Expand Down
37 changes: 34 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use phoenix_cli_processor::processor::{
use phoenix_sdk::sdk_client::*;
use solana_cli_config::{Config, ConfigInput, CONFIG_FILE};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use solana_sdk::signer::keypair::{read_keypair_file, Keypair};
use solana_sdk::signer::Signer;

Expand All @@ -33,6 +34,12 @@ struct Args {
/// Optionally include a commitment level. Defaults to your Solana CLI config file.
#[clap(global = true, short, long)]
commitment: Option<String>,
/// Optionally include a priority fee, in how many micro lamports you want to pay per compute unit. Defaults to no priority fee. Max is 1 million
#[clap(global = true, short, long)]
prio_fee: Option<u64>,
/// Optionally include the number of compute units you want to pay for. Only works if a priority fee is also set. If prio fee is set, this defaults to 1.4 million
#[clap(global = true, short, long)]
num_compute_units: Option<u32>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on updating this interface to take in the amount your'e willing to pay?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah can back it out from compute units, default it to like 500k. ill change it

}

pub fn get_network(network_str: &str) -> &str {
Expand Down Expand Up @@ -70,6 +77,24 @@ async fn main() -> anyhow::Result<()> {

let mut sdk = SDKClient::new(&payer, network_url).await?;

let prio_fee_instructions = match cli.prio_fee {
Some(compute_unit_price) => {
let num_compute_units = cli.num_compute_units.unwrap_or(1_200_000);
assert!(
num_compute_units <= 1_400_000,
"Number of compute units must be less than 1.4 million"
);
assert!(
compute_unit_price <= 1_000_000,
"Priority fee must be less than 1 million micro lamports"
);
let cu_limit = ComputeBudgetInstruction::set_compute_unit_limit(num_compute_units);
let cu_price = ComputeBudgetInstruction::set_compute_unit_price(compute_unit_price);
vec![cu_limit, cu_price]
}
None => vec![],
};
RahulJain28 marked this conversation as resolved.
Show resolved Hide resolved

match cli.command {
PhoenixCLICommand::GetMarket { market_pubkey } => {
sdk.add_market(&market_pubkey).await?;
Expand Down Expand Up @@ -134,7 +159,7 @@ async fn main() -> anyhow::Result<()> {
}
PhoenixCLICommand::RequestSeat { market_pubkey } => {
sdk.add_market(&market_pubkey).await?;
process_request_seat(&market_pubkey, &sdk).await?
process_request_seat(&market_pubkey, &sdk, prio_fee_instructions).await?
}
PhoenixCLICommand::MintTokens {
mint_ticker,
Expand Down Expand Up @@ -163,14 +188,20 @@ async fn main() -> anyhow::Result<()> {
}
PhoenixCLICommand::ClaimSeat { market_pubkey } => {
sdk.add_market(&market_pubkey).await?;
process_claim_seat(&sdk.client, &market_pubkey).await?
process_claim_seat(&sdk.client, &market_pubkey, prio_fee_instructions).await?
}
PhoenixCLICommand::EvictSeat {
market_pubkey,
trader_to_evict,
} => {
sdk.add_market(&market_pubkey).await?;
process_evict_seat(&sdk.client, &market_pubkey, &trader_to_evict).await?
process_evict_seat(
&sdk.client,
&market_pubkey,
&trader_to_evict,
prio_fee_instructions,
)
.await?
}
}

Expand Down