feat(pumpswap): support virtual quote reserves
This commit is contained in:
@@ -21,6 +21,7 @@ cargo run --release --package pumpswap_trading
|
||||
|
||||
- The buy uses `BuyAmount::WithMaxInput`, which applies slippage to maximum quote cost and is appropriate when fill priority matters.
|
||||
- Buy parameters use post-trade reserves and LP/protocol/creator fee bps from the event.
|
||||
- `solana-streamer-sdk 0.5.0` predates the appended `virtual_quote_reserves` event field, so this compatibility example reads that Pool field once before quoting. When the parser exposes the field, pass it directly to `PumpSwapParams::from_trade_with_fee_basis_points` or keep it in a Pool account cache to remove this RPC from the hot path.
|
||||
- The example records the pre-buy balance and sells only the confirmed balance increase. It refreshes pool state and blockhash before selling.
|
||||
- Use `BuyAmount::ExactInput` when the quote spend must be exact. That mode protects minimum output and can fail more often in an active pool.
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ cargo run --release --package pumpswap_trading
|
||||
|
||||
- 买入使用 `BuyAmount::WithMaxInput`,适合优先成交的跟单/狙击场景,滑点限制最大 quote 成本。
|
||||
- 买入参数使用事件中的成交后储备和 LP/protocol/creator fee bps。
|
||||
- `solana-streamer-sdk 0.5.0` 尚未暴露追加的 `virtual_quote_reserves` 事件字段,因此该兼容示例会在报价前读取一次 Pool 字段。解析器暴露该字段后,应直接传给 `PumpSwapParams::from_trade_with_fee_basis_points`,或维护 Pool 账户缓存,以移除热路径中的这次 RPC。
|
||||
- 示例记录买前余额,只卖出确认后的余额增量;卖出前重新获取池状态和 blockhash。
|
||||
- 若业务必须精确花费 quote,应改用 `BuyAmount::ExactInput`。这会启用最小输出保护,在活跃池中更容易因状态变化而失败。
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use sol_trade_sdk::common::{clock::now_micros, SolanaRpcClient, TradeConfig};
|
||||
use sol_trade_sdk::instruction::utils::pumpswap::fetch_pool;
|
||||
use sol_trade_sdk::TradeTokenType;
|
||||
use sol_trade_sdk::{
|
||||
common::AnyResult,
|
||||
@@ -279,6 +280,10 @@ async fn pumpswap_trade_with_grpc_buy_event(
|
||||
blockhash_cache: BlockhashCache,
|
||||
trade_info: PumpSwapBuyEvent,
|
||||
) -> AnyResult<()> {
|
||||
// solana-streamer-sdk 0.5.0 predates the appended event field. Read the
|
||||
// Pool value so this compatibility example still prices effective reserves.
|
||||
let virtual_quote_reserves =
|
||||
fetch_pool(&client.infrastructure.rpc, &trade_info.pool).await?.virtual_quote_reserves;
|
||||
let params = PumpSwapParams::from_trade_with_fee_basis_points(
|
||||
trade_info.pool,
|
||||
trade_info.base_mint,
|
||||
@@ -287,6 +292,7 @@ async fn pumpswap_trade_with_grpc_buy_event(
|
||||
trade_info.pool_quote_token_account,
|
||||
trade_info.pool_base_token_reserves,
|
||||
trade_info.pool_quote_token_reserves,
|
||||
virtual_quote_reserves,
|
||||
trade_info.coin_creator_vault_ata,
|
||||
trade_info.coin_creator_vault_authority,
|
||||
trade_info.base_token_program,
|
||||
@@ -317,6 +323,8 @@ async fn pumpswap_trade_with_grpc_sell_event(
|
||||
blockhash_cache: BlockhashCache,
|
||||
trade_info: PumpSwapSellEvent,
|
||||
) -> AnyResult<()> {
|
||||
let virtual_quote_reserves =
|
||||
fetch_pool(&client.infrastructure.rpc, &trade_info.pool).await?.virtual_quote_reserves;
|
||||
let params = PumpSwapParams::from_trade_with_fee_basis_points(
|
||||
trade_info.pool,
|
||||
trade_info.base_mint,
|
||||
@@ -325,6 +333,7 @@ async fn pumpswap_trade_with_grpc_sell_event(
|
||||
trade_info.pool_quote_token_account,
|
||||
trade_info.pool_base_token_reserves,
|
||||
trade_info.pool_quote_token_reserves,
|
||||
virtual_quote_reserves,
|
||||
trade_info.coin_creator_vault_ata,
|
||||
trade_info.coin_creator_vault_authority,
|
||||
trade_info.base_token_program,
|
||||
|
||||
Reference in New Issue
Block a user