mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-07 06:07:45 +00:00
change unit_price, unit_limit to uint
This commit is contained in:
@@ -55,8 +55,8 @@ pub mod accounts {
|
||||
pub mod trade {
|
||||
pub const JITO_TIP_AMOUNT: f64 = 0.0001;
|
||||
pub const DEFAULT_SLIPPAGE: u64 = 3000; // 30%
|
||||
pub const DEFAULT_COMPUTE_UNIT_LIMIT: f64 = 78000.0;
|
||||
pub const DEFAULT_COMPUTE_UNIT_PRICE: f64 = 500000.0;
|
||||
pub const DEFAULT_COMPUTE_UNIT_LIMIT: u32 = 78000;
|
||||
pub const DEFAULT_COMPUTE_UNIT_PRICE: u64 = 500000;
|
||||
pub const DEFAULT_BUY_JITO_FEE: f64 = 0.0006;
|
||||
pub const DEFAULT_SELL_JITO_FEE: f64 = 0.00006;
|
||||
}
|
||||
|
||||
+4
-4
@@ -183,7 +183,7 @@ pub async fn build_buy_instructions(
|
||||
let result_cu = result.units_consumed.ok_or_else(|| anyhow!("No compute units consumed"))?;
|
||||
let fees = rpc.get_recent_prioritization_fees(&[])?;
|
||||
let average_fees = if fees.is_empty() {
|
||||
sol_to_lamports(DEFAULT_COMPUTE_UNIT_PRICE)
|
||||
DEFAULT_COMPUTE_UNIT_PRICE
|
||||
} else {
|
||||
fees.iter()
|
||||
.map(|fee| fee.prioritization_fee)
|
||||
@@ -191,7 +191,7 @@ pub async fn build_buy_instructions(
|
||||
};
|
||||
|
||||
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(priority_fee.unit_price) } else { average_fees };
|
||||
let unit_price = if average_fees == 0 { priority_fee.unit_price } else { average_fees };
|
||||
instructions[0] = ComputeBudgetInstruction::set_compute_unit_limit(result_cu as u32);
|
||||
instructions[1] = ComputeBudgetInstruction::set_compute_unit_price(unit_price);
|
||||
|
||||
@@ -224,8 +224,8 @@ pub async fn build_buy_instructions_with_jito(
|
||||
let buy_amount_with_slippage = calculate_with_slippage_buy(amount_sol, slippage_basis_points.unwrap_or(DEFAULT_SLIPPAGE));
|
||||
|
||||
let mut instructions = vec![
|
||||
ComputeBudgetInstruction::set_compute_unit_price(sol_to_lamports(priority_fee.unit_price)),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.unit_limit) as u32),
|
||||
ComputeBudgetInstruction::set_compute_unit_price(priority_fee.unit_price),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(priority_fee.unit_limit),
|
||||
];
|
||||
|
||||
let ata = get_associated_token_address(&payer.pubkey(), mint);
|
||||
|
||||
+4
-6
@@ -17,8 +17,8 @@ lazy_static::lazy_static! {
|
||||
#[derive(Debug, Deserialize, Clone, Copy, PartialEq)]
|
||||
|
||||
pub struct PriorityFee {
|
||||
pub unit_limit: f64,
|
||||
pub unit_price: f64,
|
||||
pub unit_limit: u32,
|
||||
pub unit_price: u64,
|
||||
pub buy_jito_fee: f64,
|
||||
pub sell_jito_fee: f64,
|
||||
}
|
||||
@@ -67,10 +67,8 @@ pub async fn transfer_sol(rpc: &RpcClient, payer: &Keypair, receive_wallet: &Pub
|
||||
#[inline]
|
||||
pub fn create_priority_fee_instructions(priority_fee: PriorityFee) -> Vec<Instruction> {
|
||||
let mut instructions = Vec::with_capacity(2);
|
||||
let unit_limit = sol_to_lamports(priority_fee.unit_limit);
|
||||
let unit_price = sol_to_lamports(priority_fee.unit_price);
|
||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(unit_limit as u32));
|
||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_price(unit_price));
|
||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(priority_fee.unit_limit));
|
||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_price(priority_fee.unit_price));
|
||||
|
||||
instructions
|
||||
}
|
||||
|
||||
+4
-4
@@ -242,7 +242,7 @@ pub async fn build_create_and_buy_instructions(
|
||||
let result_cu = result.units_consumed.ok_or_else(|| anyhow!("No compute units consumed"))?;
|
||||
let fees = rpc.get_recent_prioritization_fees(&[])?;
|
||||
let average_fees = if fees.is_empty() {
|
||||
sol_to_lamports(priority_fee.unit_price)
|
||||
priority_fee.unit_price
|
||||
} else {
|
||||
fees.iter()
|
||||
.map(|fee| fee.prioritization_fee)
|
||||
@@ -250,7 +250,7 @@ pub async fn build_create_and_buy_instructions(
|
||||
};
|
||||
|
||||
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(priority_fee.unit_price) } else { average_fees };
|
||||
let unit_price = if average_fees == 0 { priority_fee.unit_price } else { average_fees };
|
||||
|
||||
instructions[0] = ComputeBudgetInstruction::set_compute_unit_limit(result_cu as u32);
|
||||
instructions[1] = ComputeBudgetInstruction::set_compute_unit_price(unit_price);
|
||||
@@ -278,8 +278,8 @@ pub async fn build_create_and_buy_instructions_with_jito(
|
||||
get_buy_amount_with_slippage(amount_sol, slippage_basis_points);
|
||||
|
||||
let mut instructions = vec![
|
||||
ComputeBudgetInstruction::set_compute_unit_price(sol_to_lamports(priority_fee.unit_price)),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.unit_limit) as u32),
|
||||
ComputeBudgetInstruction::set_compute_unit_price(priority_fee.unit_price),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(priority_fee.unit_limit),
|
||||
];
|
||||
|
||||
instructions.push(instruction::create(
|
||||
|
||||
+5
-5
@@ -8,7 +8,7 @@ use spl_token::instruction::close_account;
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::{constants::trade::{DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SLIPPAGE, JITO_TIP_AMOUNT}, instruction, jito::JitoClient};
|
||||
use crate::{constants::trade::{DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SLIPPAGE}, instruction, jito::JitoClient};
|
||||
|
||||
use super::common::{calculate_with_slippage_sell, get_bonding_curve_account, get_global_account, PriorityFee};
|
||||
|
||||
@@ -212,14 +212,14 @@ pub async fn build_sell_instructions(
|
||||
let result_cu = result.units_consumed.ok_or_else(|| anyhow!("No compute units consumed"))?;
|
||||
let fees = rpc.get_recent_prioritization_fees(&[])?;
|
||||
let average_fees = if fees.is_empty() {
|
||||
sol_to_lamports(DEFAULT_COMPUTE_UNIT_PRICE)
|
||||
DEFAULT_COMPUTE_UNIT_PRICE
|
||||
} else {
|
||||
fees.iter()
|
||||
.map(|fee| fee.prioritization_fee)
|
||||
.sum::<u64>() / fees.len() as u64
|
||||
};
|
||||
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(priority_fee.unit_price) } else { average_fees };
|
||||
let unit_price = if average_fees == 0 { priority_fee.unit_price } else { average_fees };
|
||||
instructions[0] = ComputeBudgetInstruction::set_compute_unit_limit(result_cu as u32);
|
||||
instructions[1] = ComputeBudgetInstruction::set_compute_unit_price(unit_price);
|
||||
|
||||
@@ -253,8 +253,8 @@ pub async fn build_sell_instructions_with_jito(
|
||||
);
|
||||
|
||||
let mut instructions = vec![
|
||||
ComputeBudgetInstruction::set_compute_unit_price(sol_to_lamports(priority_fee.unit_price)),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.unit_limit) as u32),
|
||||
ComputeBudgetInstruction::set_compute_unit_price(priority_fee.unit_price),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(priority_fee.unit_limit),
|
||||
];
|
||||
|
||||
instructions.push(instruction::sell(
|
||||
|
||||
Reference in New Issue
Block a user