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
16fn user_wsol_ata(user: &Pubkey) -> Pubkey {
17 pda::associated_token(
18 user,
19 &constants::SPL_TOKEN_PROGRAM_ID,
20 &constants::NATIVE_MINT,
21 )
22 .0
23}
24
25pub fn wrap_sol_instructions(user: &Pubkey, lamports: u64) -> [Instruction; 2] {
28 let ata = user_wsol_ata(user);
29 [
30 system_instruction::transfer(user, &ata, lamports),
31 sync_native(&constants::SPL_TOKEN_PROGRAM_ID, &ata)
32 .expect("sync_native: token program id is constant"),
33 ]
34}
35
36pub fn unwrap_sol_instruction(user: &Pubkey) -> Instruction {
39 let ata = user_wsol_ata(user);
40 close_account(&constants::SPL_TOKEN_PROGRAM_ID, &ata, user, user, &[])
41 .expect("close_account: token program id is constant")
42}