Files
sol-trade-sdk/docs/ADDRESS_LOOKUP_TABLE_CN.md
T
ysq 2d9976368b refactor: Replace global address lookup table cache with direct fetch approach
Replace the global AddressLookupTableCache with a direct fetch function to simplify address lookup table management. This change improves code maintainability by removing global state and makes the API more explicit.

Key changes:
- Remove AddressLookupTableCache and AddressLookupManager
- Add new fetch_address_lookup_table_account function
- Update TradeBuyParams and TradeSellParams to use AddressLookupTableAccount instead of Pubkey
- Update all examples to use the new direct fetch approach
- Update documentation to reflect the simplified workflow
2025-10-07 20:56:02 +08:00

2.5 KiB

地址查找表指南

本指南介绍如何在 Sol Trade SDK 中使用地址查找表 (ALT) 来优化交易大小并降低费用。

📋 什么是地址查找表?

地址查找表是 Solana 的一项功能,允许您将经常使用的地址以紧凑的表格格式存储。您可以通过查找表中的索引来引用地址,而不是在交易中包含完整的 32 字节地址,从而显著减少交易大小和成本。

🚀 核心优势

  • 交易大小优化: 使用地址索引而非完整地址来减少交易大小
  • 成本降低: 由于交易大小减小而降低交易费用
  • 性能提升: 更快的交易处理和验证速度
  • 网络效率: 减少带宽使用和区块空间消耗

🛠️ 实现方法

在您的交易参数中包含查找表:

let lookup_table_key = Pubkey::from_str("use_your_lookup_table_key_here").unwrap();
let address_lookup_table_account = fetch_address_lookup_table_account(&client.rpc, &lookup_table_key).await.ok();

// 在交易参数中包含查找表
let buy_params = sol_trade_sdk::TradeBuyParams {
    dex_type: DexType::PumpFun,
    mint: mint_pubkey,
    sol_amount: buy_sol_amount,
    slippage_basis_points: Some(100),
    recent_blockhash: Some(recent_blockhash),
    extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
    address_lookup_table_account: address_lookup_table_account, // 包含查找表
    wait_transaction_confirmed: true,
    create_wsol_ata: false,
    close_wsol_ata: false,
    create_mint_ata: true,
    open_seed_optimize: false,
};

// 执行交易
client.buy(buy_params).await?;

📊 性能对比

方面 不使用 ALT 使用 ALT 改进幅度
交易大小 ~1,232 字节 ~800 字节 减少 35%
地址存储 每个地址 32 字节 每个地址 1 字节 减少 97%
交易费用 更高 更低 节省高达 30%
区块空间使用 更多 更少 提高网络效率

⚠️ 重要注意事项

  1. 查找表地址: 必须提供有效的地址查找表地址
  2. RPC 兼容性: 确保您的 RPC 提供商支持查找表
  3. 网络: 查找表是特定于网络的(主网/开发网/测试网)
  4. 测试: 在主网使用前请务必在开发网测试

🔗 相关文档

📚 外部资源