manifest/program/instruction_builders/
global_withdraw_instruction.rs

1use crate::{
2    program::{global_withdraw::GlobalWithdrawParams, ManifestInstruction},
3    validation::{get_global_address, get_global_vault_address},
4};
5use borsh::BorshSerialize;
6use solana_program::{
7    instruction::{AccountMeta, Instruction},
8    pubkey::Pubkey,
9};
10
11pub fn global_withdraw_instruction(
12    mint: &Pubkey,
13    payer: &Pubkey,
14    trader_token_account: &Pubkey,
15    token_program: &Pubkey,
16    num_atoms: u64,
17) -> Instruction {
18    let (global, _global_bump) = get_global_address(mint);
19    let (global_vault, _global_vault_bump) = get_global_vault_address(mint);
20    Instruction {
21        program_id: crate::id(),
22        accounts: vec![
23            AccountMeta::new_readonly(*payer, true),
24            AccountMeta::new(global, false),
25            AccountMeta::new_readonly(*mint, false),
26            AccountMeta::new(global_vault, false),
27            AccountMeta::new(*trader_token_account, false),
28            AccountMeta::new_readonly(*token_program, false),
29        ],
30        data: [
31            ManifestInstruction::GlobalWithdraw.to_vec(),
32            GlobalWithdrawParams::new(num_atoms).try_to_vec().unwrap(),
33        ]
34        .concat(),
35    }
36}