/** * PancakeSwap Buy-First 类型定义(从 bundle-buy-first-helpers.ts 抽取) */ import type { ethers, Wallet } from 'ethers'; import type { GeneratedWallet } from '../../../utils/wallet.js'; import type { CommonBundleConfig, NonceManager } from '../../../utils/bundle-helpers.js'; export interface PancakeBuyFirstSignConfig { rpcUrl: string; gasLimit?: number | bigint; gasLimitMultiplier?: number; minGasPriceGwei?: number; maxGasPriceGwei?: number; txType?: 0 | 2; chainId?: number; reserveGasBNB?: number; skipQuoteOnError?: boolean; userType?: UserType; bribeAmount?: number; /** 滑点基点,默认 100 = 1%。 */ slippageBps?: number; v2RouterAddress?: string; } export type UserType = 'v0' | 'v1'; /** 多笔买卖 nonce 规划(与 Flap 一致) */ export type MultiNoncePlan = { buyerNonces: number[]; sellerNonces: number[]; bribeNonce?: number; profitNonce?: number; }; export type SwapRouteType = 'v2' | 'v3-single' | 'v3-multi'; export interface V2RouteParams { routeType: 'v2'; v2Path: string[]; } export interface V3SingleRouteParams { routeType: 'v3-single'; v3TokenIn: string; v3TokenOut: string; v3Fee: number; v2Path?: string[]; } export interface V3MultiRouteParams { routeType: 'v3-multi'; v3LpAddresses: string[]; v3ExactTokenIn: string; v2Path?: string[]; } export type RouteParams = V2RouteParams | V3SingleRouteParams | V3MultiRouteParams; export interface PancakeBuyFirstConfig extends CommonBundleConfig { apiKey: string; customRpcUrl?: string; bundleBlockOffset?: number; reserveGasBNB?: number; waitForConfirmation?: boolean; waitTimeoutMs?: number; } export interface PancakeBundleBuyFirstSignParams { buyerPrivateKey?: string; buyerPrivateKeys?: string[]; sellerPrivateKey?: string; sellerPrivateKeys?: string[]; tokenAddress: string; routeParams: RouteParams; buyerFunds?: string; buyerFundsPercentage?: number; config: PancakeBuyFirstSignConfig; quoteToken?: string; quoteTokenDecimals?: number; startNonces?: number[]; buyCount?: number; sellCount?: number; taxRateBps?: number; } export interface PancakeBundleBuyFirstParams { buyerPrivateKey: string; sellerPrivateKey: string; tokenAddress: string; routeParams: RouteParams; buyerFunds?: string; buyerFundsPercentage?: number; config: PancakeBuyFirstConfig; } /** ✅ Pancake BuyFirst 结果(简化版) */ export type PancakeBuyFirstResult = { signedTransactions: string[]; profitHopWallets?: GeneratedWallet[]; metadata?: { buyerAddress: string; sellerAddress: string; buyAmount: string; sellAmount: string; profitAmount?: string; buyCount?: number; sellCount?: number; buyAmounts?: string[]; sellAmounts?: string[]; }; }; export type PancakeContext = { chainId: number; provider: ethers.JsonRpcProvider; }; export type BuyerFundsResult = { buyerFundsWei: bigint; buyerBalance: bigint; reserveGas: bigint; }; export type QuoteTokenResult = { quotedTokenOut: bigint; }; export type CalculateBuyerFundsParams = { buyer: Wallet; buyerFunds?: string; buyerFundsPercentage?: number; reserveGas?: number; useNativeToken?: boolean; quoteToken?: string; quoteTokenDecimals?: number; provider?: ethers.JsonRpcProvider; }; export type QuoteTokenParams = { routeParams: RouteParams; buyerFundsWei: bigint; provider: ethers.JsonRpcProvider; v2RouterOverride?: string; }; export type MultiSwapTxParams = { routeParams: RouteParams; buyAmountsWei: bigint[]; sellAmountsWei: bigint[]; buyer: Wallet; seller: Wallet; useNativeToken?: boolean; v2RouterAddress?: string; buyAmountOutMins?: bigint[]; sellAmountOutMins?: bigint[]; }; export type MultiSwapUnsignedResult = { buyUnsignedArray: ethers.TransactionLike[]; sellUnsignedArray: ethers.TransactionLike[]; }; export type PlanMultiNonceParams = { buyer: Wallet; seller: Wallet; buyCount: number; sellCount: number; sameAddress: boolean; extractProfit: boolean; needBribeTx: boolean; nonceManager: NonceManager; }; export type ProfitTxParams = { provider: ethers.JsonRpcProvider; seller: Wallet; profitAmount: bigint; profitNonce?: number; gasPrice: bigint; chainId: number; txType: number; }; export type BalanceValidationParams = { sameAddress: boolean; buyerFundsWei: bigint; buyerBalance: bigint; reserveGas: bigint; gasLimit: bigint; gasPrice: bigint; useNativeToken?: boolean; quoteTokenDecimals?: number; provider?: ethers.JsonRpcProvider; buyerAddress?: string; }; export interface MultiWalletParams { buyerPrivateKeys: string[]; sellerPrivateKeys: string[]; routeParams: RouteParams; buyerFunds?: string; config: PancakeBuyFirstSignConfig; quoteToken?: string; quoteTokenDecimals?: number; taxRateBps?: number; }