manifest/program/instruction_builders/
global_withdraw_instruction.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::{
    program::{global_withdraw::GlobalWithdrawParams, ManifestInstruction},
    validation::{get_global_address, get_global_vault_address},
};
use borsh::BorshSerialize;
use solana_program::{
    instruction::{AccountMeta, Instruction},
    pubkey::Pubkey,
};

pub fn global_withdraw_instruction(
    mint: &Pubkey,
    payer: &Pubkey,
    trader_token_account: &Pubkey,
    token_program: &Pubkey,
    num_atoms: u64,
) -> Instruction {
    let (global, _global_bump) = get_global_address(mint);
    let (global_vault, _global_vault_bump) = get_global_vault_address(mint);
    Instruction {
        program_id: crate::id(),
        accounts: vec![
            AccountMeta::new(*payer, true),
            AccountMeta::new(global, false),
            AccountMeta::new_readonly(*mint, false),
            AccountMeta::new(global_vault, false),
            AccountMeta::new(*trader_token_account, false),
            AccountMeta::new_readonly(*token_program, false),
        ],
        data: [
            ManifestInstruction::GlobalWithdraw.to_vec(),
            GlobalWithdrawParams::new(num_atoms).try_to_vec().unwrap(),
        ]
        .concat(),
    }
}