2025-09-08 18:29:05 +08:00
|
|
|
use crate::common::fast_fn::create_associated_token_account_idempotent_fast;
|
|
|
|
|
use smallvec::SmallVec;
|
|
|
|
|
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
|
|
|
|
|
use solana_system_interface::instruction::transfer;
|
|
|
|
|
use spl_token::instruction::close_account;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn handle_wsol(payer: &Pubkey, amount_in: u64) -> SmallVec<[Instruction; 3]> {
|
|
|
|
|
let wsol_token_account =
|
|
|
|
|
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
|
|
|
|
&payer,
|
|
|
|
|
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
|
|
|
|
&crate::constants::TOKEN_PROGRAM,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let mut insts = SmallVec::<[Instruction; 3]>::new();
|
2025-09-09 17:02:24 +08:00
|
|
|
insts.extend(create_associated_token_account_idempotent_fast(
|
|
|
|
|
&payer,
|
|
|
|
|
&payer,
|
|
|
|
|
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
|
|
|
|
&crate::constants::TOKEN_PROGRAM,
|
|
|
|
|
));
|
2025-09-08 18:29:05 +08:00
|
|
|
insts.extend([
|
|
|
|
|
transfer(&payer, &wsol_token_account, amount_in),
|
|
|
|
|
spl_token::instruction::sync_native(&crate::constants::TOKEN_PROGRAM, &wsol_token_account)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
insts
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-09 17:02:24 +08:00
|
|
|
pub fn close_wsol(payer: &Pubkey) -> Vec<Instruction> {
|
2025-09-08 18:29:05 +08:00
|
|
|
let wsol_token_account =
|
|
|
|
|
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
|
|
|
|
&payer,
|
|
|
|
|
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
|
|
|
|
&crate::constants::TOKEN_PROGRAM,
|
|
|
|
|
);
|
2025-09-09 17:02:24 +08:00
|
|
|
crate::common::fast_fn::get_cached_instructions(
|
2025-09-08 18:29:05 +08:00
|
|
|
crate::common::fast_fn::InstructionCacheKey::CloseWsolAccount {
|
|
|
|
|
payer: *payer,
|
|
|
|
|
wsol_token_account,
|
|
|
|
|
},
|
|
|
|
|
|| {
|
2025-09-09 17:02:24 +08:00
|
|
|
vec![close_account(
|
2025-09-08 18:29:05 +08:00
|
|
|
&crate::constants::TOKEN_PROGRAM,
|
|
|
|
|
&wsol_token_account,
|
|
|
|
|
&payer,
|
|
|
|
|
&payer,
|
|
|
|
|
&[],
|
|
|
|
|
)
|
2025-09-09 17:02:24 +08:00
|
|
|
.unwrap()]
|
2025-09-08 18:29:05 +08:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2025-09-09 17:02:24 +08:00
|
|
|
pub fn create_wsol_ata(payer: &Pubkey) -> Vec<Instruction> {
|
2025-09-08 18:29:05 +08:00
|
|
|
create_associated_token_account_idempotent_fast(
|
|
|
|
|
&payer,
|
|
|
|
|
&payer,
|
|
|
|
|
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
|
|
|
|
&crate::constants::TOKEN_PROGRAM,
|
|
|
|
|
)
|
|
|
|
|
}
|