93 lines
2.5 KiB
Rust
93 lines
2.5 KiB
Rust
pub mod calc;
|
|
pub mod price;
|
|
use crate::trading;
|
|
use crate::TradingClient;
|
|
use solana_sdk::pubkey::Pubkey;
|
|
use solana_sdk::signature::Keypair;
|
|
use solana_sdk::signer::Signer;
|
|
|
|
impl TradingClient {
|
|
#[inline]
|
|
pub async fn get_sol_balance(&self, payer: &Pubkey) -> Result<u64, anyhow::Error> {
|
|
trading::common::utils::get_sol_balance(&self.infrastructure.rpc, payer).await
|
|
}
|
|
|
|
#[inline]
|
|
pub async fn get_payer_sol_balance(&self) -> Result<u64, anyhow::Error> {
|
|
trading::common::utils::get_sol_balance(&self.infrastructure.rpc, &self.payer.pubkey())
|
|
.await
|
|
}
|
|
|
|
#[inline]
|
|
pub async fn get_token_balance(
|
|
&self,
|
|
payer: &Pubkey,
|
|
mint: &Pubkey,
|
|
) -> Result<u64, anyhow::Error> {
|
|
trading::common::utils::get_token_balance(&self.infrastructure.rpc, payer, mint).await
|
|
}
|
|
|
|
#[inline]
|
|
pub async fn get_payer_token_balance(&self, mint: &Pubkey) -> Result<u64, anyhow::Error> {
|
|
trading::common::utils::get_token_balance(
|
|
&self.infrastructure.rpc,
|
|
&self.payer.pubkey(),
|
|
mint,
|
|
)
|
|
.await
|
|
}
|
|
|
|
/// 使用与交易一致的 ATA 推导(含 seed 优化)查询 payer 某 mint 的余额;卖出前查余额应使用此接口并传入池的 base_token_program,否则若使用 seed ATA 会查错账户。
|
|
#[inline]
|
|
pub async fn get_payer_token_balance_with_program(
|
|
&self,
|
|
mint: &Pubkey,
|
|
token_program: &Pubkey,
|
|
) -> Result<u64, anyhow::Error> {
|
|
trading::common::utils::get_token_balance_with_options(
|
|
&self.infrastructure.rpc,
|
|
&self.payer.pubkey(),
|
|
mint,
|
|
token_program,
|
|
self.use_seed_optimize,
|
|
)
|
|
.await
|
|
}
|
|
|
|
#[inline]
|
|
pub fn get_payer_pubkey(&self) -> Pubkey {
|
|
self.payer.pubkey()
|
|
}
|
|
|
|
#[inline]
|
|
pub fn get_payer(&self) -> &Keypair {
|
|
self.payer.as_ref()
|
|
}
|
|
|
|
#[inline]
|
|
pub async fn transfer_sol(
|
|
&self,
|
|
payer: &Keypair,
|
|
receive_wallet: &Pubkey,
|
|
amount: u64,
|
|
) -> Result<(), anyhow::Error> {
|
|
trading::common::utils::transfer_sol(
|
|
&self.infrastructure.rpc,
|
|
payer,
|
|
receive_wallet,
|
|
amount,
|
|
)
|
|
.await
|
|
}
|
|
|
|
#[inline]
|
|
pub async fn close_token_account(&self, mint: &Pubkey) -> Result<(), anyhow::Error> {
|
|
trading::common::utils::close_token_account(
|
|
&self.infrastructure.rpc,
|
|
self.payer.as_ref(),
|
|
mint,
|
|
)
|
|
.await
|
|
}
|
|
}
|