feat(pumpswap): Auto-wrap SOL and enrich gRPC events

This commit introduces two main enhancements:

    1.  Adds an `auto_handle_wsol` parameter to `PumpSwap` buy/sell functions. When enabled, the SDK automatically manages the wrapping of SOL to WSOL and unwrapping back to SOL, simplifying client-side logic.
    2.  Enriches `PumpSwap` gRPC buy/sell events by parsing transaction instructions to include token mints and account addresses, providing more context for event consumers.
This commit is contained in:
ysq
2025-06-23 00:50:51 +08:00
parent 9396871b01
commit a0579a338b
6 changed files with 97 additions and 0 deletions
+47
View File
@@ -58,6 +58,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
*pool_quote_token_account,
*user_base_token_account,
*user_quote_token_account,
protocol_params.auto_handle_wsol,
)
.await
}
@@ -148,6 +149,7 @@ impl PumpSwapInstructionBuilder {
pool_quote_token_account,
user_base_token_account,
user_quote_token_account,
true,
)
.await
}
@@ -210,6 +212,7 @@ impl PumpSwapInstructionBuilder {
pool_quote_token_account: Pubkey,
user_base_token_account: Pubkey,
user_quote_token_account: Pubkey,
auto_handle_wsol: bool,
) -> Result<Vec<Instruction>> {
if params.rpc.is_none() {
return Err(anyhow!("RPC is not set"));
@@ -226,6 +229,36 @@ impl PumpSwapInstructionBuilder {
let mut instructions = vec![];
if auto_handle_wsol {
// 插入wsol
instructions.push(
// 创建wSOL ATA账户,如果不存在
create_associated_token_account_idempotent(
&params.payer.pubkey(),
&params.payer.pubkey(),
&accounts::WSOL_TOKEN_ACCOUNT,
&accounts::TOKEN_PROGRAM,
),
);
instructions.push(
// 将SOL转入wSOL ATA账户
solana_sdk::system_instruction::transfer(
&params.payer.pubkey(),
&user_quote_token_account,
max_sol_amount,
),
);
// 同步wSOL余额
instructions.push(
spl_token::instruction::sync_native(
&accounts::TOKEN_PROGRAM,
&user_quote_token_account,
)
.unwrap(),
);
}
// 创建用户的基础代币账户
instructions.push(create_associated_token_account_idempotent(
&params.payer.pubkey(),
@@ -275,6 +308,20 @@ impl PumpSwapInstructionBuilder {
data,
});
if auto_handle_wsol {
// 关闭wSOL ATA账户,回收租金
instructions.push(
spl_token::instruction::close_account(
&accounts::TOKEN_PROGRAM,
&user_quote_token_account,
&params.payer.pubkey(),
&params.payer.pubkey(),
&[],
)
.unwrap(),
);
}
Ok(instructions)
}