pump_rust_client/
token.rs1use anchor_spl::token::spl_token::instruction::{close_account, sync_native};
10use solana_program::{instruction::Instruction, pubkey::Pubkey, system_instruction};
11
12pub use anchor_spl::associated_token::spl_associated_token_account::instruction::create_associated_token_account_idempotent;
13
14use crate::{constants, pda};
15
16pub fn wrap_sol_instructions(user: &Pubkey, lamports: u64) -> [Instruction; 2] {
19 let user_wsol_ata = pda::associated_token(
20 user,
21 &constants::SPL_TOKEN_PROGRAM_ID,
22 &constants::NATIVE_MINT,
23 )
24 .0;
25 [
26 system_instruction::transfer(user, &user_wsol_ata, lamports),
27 sync_native(&constants::SPL_TOKEN_PROGRAM_ID, &user_wsol_ata)
28 .expect("sync_native: token program id is constant"),
29 ]
30}
31
32pub fn unwrap_sol_instruction(user: &Pubkey) -> Instruction {
35 let user_wsol_ata = pda::associated_token(
36 user,
37 &constants::SPL_TOKEN_PROGRAM_ID,
38 &constants::NATIVE_MINT,
39 )
40 .0;
41 close_account(
42 &constants::SPL_TOKEN_PROGRAM_ID,
43 &user_wsol_ata,
44 user,
45 user,
46 &[],
47 )
48 .expect("close_account: token program id is constant")
49}