Skip to main content

sol_trade_sdk/utils/
mod.rs

1pub mod calc;
2pub mod price;
3use crate::trading;
4use crate::TradingClient;
5use solana_sdk::pubkey::Pubkey;
6use solana_sdk::signature::Keypair;
7use solana_sdk::signer::Signer;
8
9impl TradingClient {
10    #[inline]
11    pub async fn get_sol_balance(&self, payer: &Pubkey) -> Result<u64, anyhow::Error> {
12        trading::common::utils::get_sol_balance(&self.infrastructure.rpc, payer).await
13    }
14
15    #[inline]
16    pub async fn get_payer_sol_balance(&self) -> Result<u64, anyhow::Error> {
17        trading::common::utils::get_sol_balance(&self.infrastructure.rpc, &self.payer.pubkey()).await
18    }
19
20    #[inline]
21    pub async fn get_token_balance(
22        &self,
23        payer: &Pubkey,
24        mint: &Pubkey,
25    ) -> Result<u64, anyhow::Error> {
26        trading::common::utils::get_token_balance(&self.infrastructure.rpc, payer, mint).await
27    }
28
29    #[inline]
30    pub async fn get_payer_token_balance(&self, mint: &Pubkey) -> Result<u64, anyhow::Error> {
31        trading::common::utils::get_token_balance(&self.infrastructure.rpc, &self.payer.pubkey(), mint).await
32    }
33
34    #[inline]
35    pub fn get_payer_pubkey(&self) -> Pubkey {
36        self.payer.pubkey()
37    }
38
39    #[inline]
40    pub fn get_payer(&self) -> &Keypair {
41        self.payer.as_ref()
42    }
43
44    #[inline]
45    pub async fn transfer_sol(
46        &self,
47        payer: &Keypair,
48        receive_wallet: &Pubkey,
49        amount: u64,
50    ) -> Result<(), anyhow::Error> {
51        trading::common::utils::transfer_sol(&self.infrastructure.rpc, payer, receive_wallet, amount).await
52    }
53
54    #[inline]
55    pub async fn close_token_account(&self, mint: &Pubkey) -> Result<(), anyhow::Error> {
56        trading::common::utils::close_token_account(&self.infrastructure.rpc, self.payer.as_ref(), mint).await
57    }
58}