Skip to main content

percli_chain/commands/
withdraw.rs

1use anyhow::Result;
2use solana_sdk::pubkey::Pubkey;
3
4use crate::config::ChainConfig;
5use crate::ix::{self, WithdrawArgs};
6use crate::rpc::ChainRpc;
7
8pub fn run(
9    config: &ChainConfig,
10    account_idx: u16,
11    amount: u64,
12    funding_rate: i64,
13    mint: &Pubkey,
14    user_token_account: &Pubkey,
15) -> Result<()> {
16    let rpc = ChainRpc::new(&config.rpc_url);
17    let (market_pda, _) = config.market_pda();
18    let (vault, _) = config.vault_pda();
19
20    let ix = ix::withdraw_ix(
21        &config.program_id,
22        &market_pda,
23        &config.authority(),
24        mint,
25        user_token_account,
26        &vault,
27        &spl_token::id(),
28        WithdrawArgs {
29            account_idx,
30            amount,
31            funding_rate,
32        },
33    );
34
35    println!("Withdrawing {amount} from account slot {account_idx}...");
36    let sig = rpc.send_tx(&[ix], &config.keypair)?;
37    println!("  Tx: {sig}");
38    Ok(())
39}