update fee for custructor
This commit is contained in:
@@ -57,4 +57,6 @@ pub mod trade {
|
||||
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_BUY_JITO_FEE: f64 = 0.0006;
|
||||
pub const DEFAULT_SELL_JITO_FEE: f64 = 0.00006;
|
||||
}
|
||||
|
||||
+16
-23
@@ -29,6 +29,7 @@ pub struct PumpFun {
|
||||
pub payer: Arc<Keypair>,
|
||||
pub rpc: RpcClient,
|
||||
pub jito_client: Option<JitoClient>,
|
||||
pub priority_fee: PriorityFee,
|
||||
}
|
||||
|
||||
impl Clone for PumpFun {
|
||||
@@ -40,6 +41,7 @@ impl Clone for PumpFun {
|
||||
self.rpc.commitment()
|
||||
),
|
||||
jito_client: self.jito_client.clone(),
|
||||
priority_fee: self.priority_fee.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,8 +51,9 @@ impl PumpFun {
|
||||
pub fn new(
|
||||
payer: Arc<Keypair>,
|
||||
rpc_url: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
jito_url: Option<String>,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Self {
|
||||
let rpc = RpcClient::new_with_commitment(
|
||||
rpc_url,
|
||||
@@ -63,6 +66,7 @@ impl PumpFun {
|
||||
payer,
|
||||
rpc,
|
||||
jito_client,
|
||||
priority_fee,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,14 +75,13 @@ impl PumpFun {
|
||||
&self,
|
||||
mint: &Keypair,
|
||||
ipfs: TokenMetadataIPFS,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
trade::create::create(
|
||||
&self.rpc,
|
||||
&self.payer,
|
||||
mint,
|
||||
ipfs,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -88,7 +91,6 @@ impl PumpFun {
|
||||
ipfs: TokenMetadataIPFS,
|
||||
amount_sol: u64,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
trade::create::create_and_buy(
|
||||
&self.rpc,
|
||||
@@ -97,7 +99,7 @@ impl PumpFun {
|
||||
ipfs,
|
||||
amount_sol,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -108,7 +110,6 @@ impl PumpFun {
|
||||
ipfs: TokenMetadataIPFS,
|
||||
amount_sols: Vec<u64>,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
trade::create::create_and_buy_list_with_jito(
|
||||
&self.rpc,
|
||||
@@ -118,7 +119,7 @@ impl PumpFun {
|
||||
ipfs,
|
||||
amount_sols,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -129,7 +130,6 @@ impl PumpFun {
|
||||
ipfs: TokenMetadataIPFS,
|
||||
amount_sol: u64,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
trade::create::create_and_buy_with_jito(
|
||||
&self.rpc,
|
||||
@@ -139,7 +139,7 @@ impl PumpFun {
|
||||
ipfs,
|
||||
amount_sol,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
/// Buy tokens
|
||||
@@ -148,7 +148,6 @@ impl PumpFun {
|
||||
mint: &Pubkey,
|
||||
amount_sol: u64,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
trade::buy::buy(
|
||||
&self.rpc,
|
||||
@@ -156,7 +155,7 @@ impl PumpFun {
|
||||
mint,
|
||||
amount_sol,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -166,7 +165,6 @@ impl PumpFun {
|
||||
mint: &Pubkey,
|
||||
amount_sol: u64,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
trade::buy::buy_with_jito(
|
||||
&self.rpc,
|
||||
@@ -175,7 +173,7 @@ impl PumpFun {
|
||||
mint,
|
||||
amount_sol,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -185,7 +183,6 @@ impl PumpFun {
|
||||
mint: &Pubkey,
|
||||
amount_sols: Vec<u64>,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
trade::buy::buy_list_with_jito(
|
||||
&self.rpc,
|
||||
@@ -194,7 +191,7 @@ impl PumpFun {
|
||||
mint,
|
||||
amount_sols,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -204,7 +201,6 @@ impl PumpFun {
|
||||
mint: &Pubkey,
|
||||
amount_token: Option<u64>,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
trade::sell::sell(
|
||||
&self.rpc,
|
||||
@@ -212,7 +208,7 @@ impl PumpFun {
|
||||
mint,
|
||||
amount_token,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -222,7 +218,6 @@ impl PumpFun {
|
||||
mint: &Pubkey,
|
||||
percent: u64,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
trade::sell::sell_by_percent(
|
||||
&self.rpc,
|
||||
@@ -230,7 +225,7 @@ impl PumpFun {
|
||||
mint,
|
||||
percent,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -239,7 +234,6 @@ impl PumpFun {
|
||||
mint: &Pubkey,
|
||||
percent: u64,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
trade::sell::sell_by_percent_with_jito(
|
||||
&self.rpc,
|
||||
@@ -248,7 +242,7 @@ impl PumpFun {
|
||||
mint,
|
||||
percent,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
@@ -258,7 +252,6 @@ impl PumpFun {
|
||||
mint: &Pubkey,
|
||||
amount_token: Option<u64>,
|
||||
slippage_basis_points: Option<u64>,
|
||||
priority_fee: PriorityFee,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
let jito_client = self.jito_client.as_ref()
|
||||
.ok_or_else(|| anyhow!("Jito client not found"))?;
|
||||
@@ -270,7 +263,7 @@ impl PumpFun {
|
||||
mint,
|
||||
amount_token,
|
||||
slippage_basis_points,
|
||||
priority_fee,
|
||||
self.priority_fee,
|
||||
).await
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -190,7 +190,8 @@ pub async fn build_buy_instructions(
|
||||
.sum::<u64>() / fees.len() as u64
|
||||
};
|
||||
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(priority_fee.price) } else { average_fees };
|
||||
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(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);
|
||||
|
||||
@@ -223,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.price)),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.limit) as u32),
|
||||
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),
|
||||
];
|
||||
|
||||
let ata = get_associated_token_address(&payer.pubkey(), mint);
|
||||
@@ -249,7 +250,7 @@ pub async fn build_buy_instructions_with_jito(
|
||||
|
||||
let tip_account = jito_client.get_tip_account().await.map_err(|e| anyhow!(e))?;
|
||||
|
||||
let jito_fee = priority_fee.jito_fee.unwrap_or(JITO_TIP_AMOUNT);
|
||||
let jito_fee = priority_fee.buy_jito_fee;
|
||||
instructions.push(
|
||||
system_instruction::transfer(
|
||||
&payer.pubkey(),
|
||||
|
||||
+18
-8
@@ -1,4 +1,5 @@
|
||||
use anyhow::anyhow;
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::RwLock;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use solana_client::rpc_client::RpcClient;
|
||||
@@ -6,23 +7,30 @@ use solana_sdk::{
|
||||
compute_budget::ComputeBudgetInstruction, instruction::Instruction, native_token::sol_to_lamports, pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction, transaction::Transaction
|
||||
};
|
||||
use spl_associated_token_account::get_associated_token_address;
|
||||
use crate::{accounts, common::logs_data::TradeInfo, constants::{self, trade::{DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SLIPPAGE}}};
|
||||
use crate::{accounts, common::logs_data::TradeInfo, constants::{self, trade::{DEFAULT_BUY_JITO_FEE, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SELL_JITO_FEE, DEFAULT_SLIPPAGE}}};
|
||||
use borsh::BorshDeserialize;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref ACCOUNT_CACHE: RwLock<HashMap<Pubkey, Arc<accounts::GlobalAccount>>> = RwLock::new(HashMap::new());
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Deserialize, Clone, Copy, PartialEq)]
|
||||
|
||||
pub struct PriorityFee {
|
||||
pub limit: f64,
|
||||
pub price: f64,
|
||||
pub jito_fee: Option<f64>,
|
||||
pub unit_limit: f64,
|
||||
pub unit_price: f64,
|
||||
pub buy_jito_fee: f64,
|
||||
pub sell_jito_fee: f64,
|
||||
}
|
||||
|
||||
impl Default for PriorityFee {
|
||||
fn default() -> Self {
|
||||
Self { limit: DEFAULT_COMPUTE_UNIT_LIMIT, price: DEFAULT_COMPUTE_UNIT_PRICE, jito_fee: None }
|
||||
Self {
|
||||
unit_limit: DEFAULT_COMPUTE_UNIT_LIMIT,
|
||||
unit_price: DEFAULT_COMPUTE_UNIT_PRICE,
|
||||
buy_jito_fee: DEFAULT_BUY_JITO_FEE,
|
||||
sell_jito_fee: DEFAULT_SELL_JITO_FEE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +67,10 @@ 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);
|
||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.limit) as u32));
|
||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_price(sol_to_lamports(priority_fee.price)));
|
||||
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
|
||||
}
|
||||
|
||||
+5
-5
@@ -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.price)
|
||||
sol_to_lamports(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.price) } else { average_fees };
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(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.price)),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.limit) as u32),
|
||||
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),
|
||||
];
|
||||
|
||||
instructions.push(instruction::create(
|
||||
@@ -313,7 +313,7 @@ pub async fn build_create_and_buy_instructions_with_jito(
|
||||
));
|
||||
|
||||
let tip_account = jito_client.get_tip_account().await.map_err(|e| anyhow!(e))?;
|
||||
let jito_fee = priority_fee.jito_fee.unwrap_or(JITO_TIP_AMOUNT);
|
||||
let jito_fee = priority_fee.buy_jito_fee;
|
||||
instructions.push(
|
||||
system_instruction::transfer(
|
||||
&payer.pubkey(),
|
||||
|
||||
+4
-4
@@ -219,7 +219,7 @@ pub async fn build_sell_instructions(
|
||||
.sum::<u64>() / fees.len() as u64
|
||||
};
|
||||
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(priority_fee.price) } else { average_fees };
|
||||
let unit_price = if average_fees == 0 { sol_to_lamports(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.price)),
|
||||
ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.limit) as u32),
|
||||
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),
|
||||
];
|
||||
|
||||
instructions.push(instruction::sell(
|
||||
@@ -276,7 +276,7 @@ pub async fn build_sell_instructions_with_jito(
|
||||
)?);
|
||||
|
||||
let tip_account = jito_client.get_tip_account().await.map_err(|e| anyhow!(e))?;
|
||||
let jito_fee = priority_fee.jito_fee.unwrap_or(JITO_TIP_AMOUNT);
|
||||
let jito_fee = priority_fee.sell_jito_fee;
|
||||
instructions.push(
|
||||
system_instruction::transfer(
|
||||
&payer.pubkey(),
|
||||
|
||||
Reference in New Issue
Block a user