This commit is contained in:
William
2025-05-13 07:08:01 +08:00
parent 3a60969b22
commit 07651638b9
5 changed files with 23 additions and 21 deletions
+1 -1
View File
@@ -202,7 +202,7 @@ pub fn sell(
AccountMeta::new_readonly(constants::global_constants::GLOBAL_ACCOUNT, false), AccountMeta::new_readonly(constants::global_constants::GLOBAL_ACCOUNT, false),
AccountMeta::new(*fee_recipient, false), AccountMeta::new(*fee_recipient, false),
AccountMeta::new_readonly(*mint, false), AccountMeta::new_readonly(*mint, false),
AccountMeta::new(bonding_curve, false), AccountMeta::new(*bonding_curve, false),
AccountMeta::new(get_associated_token_address(&bonding_curve, mint), false), AccountMeta::new(get_associated_token_address(&bonding_curve, mint), false),
AccountMeta::new(get_associated_token_address(&payer.pubkey(), mint), false), AccountMeta::new(get_associated_token_address(&payer.pubkey(), mint), false),
AccountMeta::new(payer.pubkey(), true), AccountMeta::new(payer.pubkey(), true),
+5 -5
View File
@@ -7,11 +7,11 @@ use spl_associated_token_account::instruction::create_associated_token_account;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use std::{str::FromStr, time::Instant, sync::Arc}; use std::{str::FromStr, time::Instant, sync::Arc};
use crate::{common::{PriorityFee, SolanaRpcClient}, constants::{self, trade::DEFAULT_SLIPPAGE}, instruction, swqos::FeeClient}; use crate::{common::{PriorityFee, SolanaRpcClient}, constants::{self, global_constants::FEE_RECIPIENT, trade::DEFAULT_SLIPPAGE}, instruction, swqos::FeeClient};
const MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT: u32 = 250000; const MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT: u32 = 250000;
use super::common::{calculate_with_slippage_buy, get_bonding_curve_account, get_global_account, get_initial_buy_price}; use super::common::{calculate_with_slippage_buy, get_bonding_curve_account, get_buy_token_amount, get_creator_vault_pda, get_global_account, get_initial_buy_price};
pub async fn buy( pub async fn buy(
rpc: Arc<SolanaRpcClient>, rpc: Arc<SolanaRpcClient>,
@@ -139,10 +139,10 @@ pub async fn build_buy_instructions(
rpc: Arc<SolanaRpcClient>, rpc: Arc<SolanaRpcClient>,
payer: Arc<Keypair>, payer: Arc<Keypair>,
mint: Arc<Pubkey>, mint: Arc<Pubkey>,
amount_sol: u64, buy_sol_cost: u64,
slippage_basis_points: Option<u64>, slippage_basis_points: Option<u64>,
) -> Result<Vec<Instruction>, anyhow::Error> { ) -> Result<Vec<Instruction>, anyhow::Error> {
if amount_sol == 0 { if buy_sol_cost == 0 {
return Err(anyhow!("Amount cannot be zero")); return Err(anyhow!("Amount cannot be zero"));
} }
@@ -165,7 +165,7 @@ pub async fn build_buy_instructions(
&mint, &mint,
&bonding_curve_pda, &bonding_curve_pda,
&creator_vault_pda, &creator_vault_pda,
&global_account.fee_recipient, &FEE_RECIPIENT,
instruction::Buy { instruction::Buy {
_amount: buy_token_amount, _amount: buy_token_amount,
_max_sol_cost: max_sol_cost, _max_sol_cost: max_sol_cost,
+1 -1
View File
@@ -177,7 +177,7 @@ pub async fn get_bonding_curve_account(
#[inline] #[inline]
pub fn get_buy_token_amount( pub fn get_buy_token_amount(
bonding_curve_account: &BondingCurveAccount, bonding_curve_account: &Arc<accounts::BondingCurveAccount>,
buy_sol_cost: u64, buy_sol_cost: u64,
slippage_basis_points: Option<u64>, slippage_basis_points: Option<u64>,
) -> anyhow::Result<(u64, u64)> { ) -> anyhow::Result<(u64, u64)> {
+15 -13
View File
@@ -10,9 +10,7 @@ use spl_associated_token_account::{
}; };
use crate::{ use crate::{
common::{PriorityFee, SolanaRpcClient}, constants, instruction, common::{PriorityFee, SolanaRpcClient}, constants::{self, global_constants::FEE_RECIPIENT}, instruction, ipfs::TokenMetadataIPFS, pumpfun::buy::build_buy_transaction_with_tip, swqos::FeeClient
ipfs::TokenMetadataIPFS, swqos::FeeClient,
pumpfun::buy::build_buy_transaction_with_tip
}; };
use crate::pumpfun::common::{ use crate::pumpfun::common::{
@@ -20,6 +18,8 @@ use crate::pumpfun::common::{
get_buy_amount_with_slippage, get_global_account get_buy_amount_with_slippage, get_global_account
}; };
use super::common::{get_bonding_curve_account, get_buy_token_amount, get_creator_vault_pda};
/// Create a new token /// Create a new token
pub async fn create( pub async fn create(
rpc: Arc<SolanaRpcClient>, rpc: Arc<SolanaRpcClient>,
@@ -181,19 +181,19 @@ pub async fn build_create_and_buy_instructions(
payer: Arc<Keypair>, payer: Arc<Keypair>,
mint: Arc<Keypair>, mint: Arc<Keypair>,
ipfs: TokenMetadataIPFS, ipfs: TokenMetadataIPFS,
amount_sol: u64, buy_sol_cost: u64,
slippage_basis_points: Option<u64>, slippage_basis_points: Option<u64>,
priority_fee: PriorityFee, priority_fee: PriorityFee,
) -> Result<Vec<Instruction>, anyhow::Error> { ) -> Result<Vec<Instruction>, anyhow::Error> {
if amount_sol == 0 { if buy_sol_cost == 0 {
return Err(anyhow!("Amount cannot be zero")); return Err(anyhow!("Amount cannot be zero"));
} }
let rpc = rpc.as_ref(); let (bonding_curve_account, bonding_curve_pda) = get_bonding_curve_account(&rpc, &mint.pubkey()).await?;
let global_account = get_global_account(rpc).await?;
let buy_amount = global_account.get_initial_buy_price(amount_sol); let creator_vault_pda = get_creator_vault_pda(&bonding_curve_account.creator).unwrap();
let buy_amount_with_slippage =
get_buy_amount_with_slippage(amount_sol, slippage_basis_points); let (buy_token_amount, max_sol_cost) = get_buy_token_amount(&bonding_curve_account, buy_sol_cost, slippage_basis_points)?;
let mut instructions = vec![]; let mut instructions = vec![];
@@ -218,10 +218,12 @@ pub async fn build_create_and_buy_instructions(
instructions.push(instruction::buy( instructions.push(instruction::buy(
payer.as_ref(), payer.as_ref(),
&mint.pubkey(), &mint.pubkey(),
&global_account.fee_recipient, &bonding_curve_pda,
&creator_vault_pda,
&FEE_RECIPIENT,
instruction::Buy { instruction::Buy {
_amount: buy_amount, _amount: buy_token_amount,
_max_sol_cost: buy_amount_with_slippage, _max_sol_cost: max_sol_cost,
}, },
)); ));
+1 -1
View File
@@ -12,7 +12,7 @@ use std::{str::FromStr, time::Instant, sync::Arc};
use crate::{common::{PriorityFee, SolanaRpcClient}, constants::trade::{DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SLIPPAGE}, instruction, swqos::FeeClient}; use crate::{common::{PriorityFee, SolanaRpcClient}, constants::trade::{DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SLIPPAGE}, instruction, swqos::FeeClient};
use super::common::{calculate_with_slippage_sell, get_bonding_curve_account, get_global_account}; use super::common::{calculate_with_slippage_sell, get_bonding_curve_account, get_creator_vault_pda, get_global_account};
async fn get_token_balance(rpc: &SolanaRpcClient, payer: &Keypair, mint: &Pubkey) -> Result<(u64, Pubkey), anyhow::Error> { async fn get_token_balance(rpc: &SolanaRpcClient, payer: &Keypair, mint: &Pubkey) -> Result<(u64, Pubkey), anyhow::Error> {
let ata = get_associated_token_address(&payer.pubkey(), mint); let ata = get_associated_token_address(&payer.pubkey(), mint);