import { ethers, Wallet, JsonRpcProvider } from 'ethers'; import { type GeneratedWallet } from '../../../utils/wallet.js'; import { NonceManager, CommonBundleConfig } from '../../../utils/bundle-helpers.js'; export declare const NATIVE_TRANSFER_GAS_LIMIT: 21055n; export declare const ERC20_TRANSFER_GAS_LIMIT_HOP: 65000n; export declare const BRIBE_GAS_LIMIT: 21000n; /** * 分发多跳路径信息 */ export type DisperseHopPath = { targetAddress: string; hopWallets: Wallet[]; hopWalletsInfo: GeneratedWallet[]; }; /** * 生成分发多跳路径 */ export declare function generateDisperseHopPaths(targetAddresses: string[], hopCount: number, provider: JsonRpcProvider): DisperseHopPath[]; /** * 构建原生代币多跳转账链 */ export declare function buildNativeHopChain(payer: Wallet, path: DisperseHopPath, finalAmount: bigint, gasPrice: bigint, chainId: number, txType: 0 | 2, payerNonce: number): Promise; /** * 构建 ERC20 多跳转账链(需要配合 BNB 多跳使用) */ export declare function buildERC20HopChain(payer: Wallet, path: DisperseHopPath, erc20Address: string, erc20Amount: bigint, gasPrice: bigint, chainId: number, txType: 0 | 2, payerNonce: number): Promise; /** * 构建 BNB 多跳转账链(为 ERC20 中间钱包预留 gas) */ export declare function buildBNBHopChainForERC20(payer: Wallet, path: DisperseHopPath, finalGasAmount: bigint, gasPrice: bigint, chainId: number, txType: 0 | 2, payerNonce: number): Promise; export declare function createPancakeContext(config: PancakeSwapSignConfig): PancakeContext; export type QuoteSellParams = { routeParams: RouteParams; sellAmountWei: bigint; provider: ethers.JsonRpcProvider; v2RouterAddress?: string; }; export declare function quoteSellOutput({ routeParams, sellAmountWei, provider, v2RouterAddress, }: QuoteSellParams): Promise; export type BuildSwapParams = { routeParams: RouteParams; sellAmountWei: bigint; buyAmountBNB: bigint; buyer: Wallet; seller: Wallet; tokenAddress: string; useNativeToken?: boolean; v2RouterAddress?: string; }; export declare function buildSwapTransactions({ routeParams, sellAmountWei, buyAmountBNB, buyer, seller, tokenAddress, useNativeToken, v2RouterAddress, }: BuildSwapParams): Promise; export type BuyerBudgetParams = { buyer: Wallet; quotedBNBOut: bigint; reserveGasBNB?: number; useNativeToken?: boolean; quoteToken?: string; quoteTokenDecimals?: number; provider?: ethers.JsonRpcProvider; }; export declare function calculateBuyerBudget({ buyer, quotedBNBOut, reserveGasBNB, useNativeToken, quoteToken, quoteTokenDecimals, provider, }: BuyerBudgetParams): Promise; export type PlanNonceParams = { seller: Wallet; buyer: Wallet; sameAddress: boolean; approvalExists: boolean; profitNeeded: boolean; needBribeTx: boolean; nonceManager: NonceManager; }; /** * ✅ 从前端传入的 startNonces 构建 NoncePlan(用于性能优化) * 顺序:[sellerBaseNonce, buyerNonce] */ export declare function buildNoncePlanFromNonces(startNonces: number[], sameAddress: boolean, approvalExists: boolean, profitNeeded: boolean, needBribeTx: boolean): NoncePlan; /** * ✅ 规划 nonce * 交易顺序:贿赂 → 授权 → 卖出 → 买入 → 利润 * 贿赂和利润由卖方发送 */ export declare function planNonces({ seller, buyer, sameAddress, approvalExists, profitNeeded, needBribeTx, nonceManager, }: PlanNonceParams): Promise; /** * 根据 userType 计算利润率 */ export declare function getProfitRateBps(userType?: UserType): number; export declare function calculateProfitAmount(estimatedBNBOut: bigint, userType?: UserType): bigint; /** * ✅ 获取 ERC20 代币 → 原生代币(BNB)的报价 * 用于将 ERC20 利润转换为 BNB * 使用共享的报价函数 */ export declare function getERC20ToNativeQuote(provider: ethers.JsonRpcProvider, tokenAddress: string, tokenAmount: bigint, version?: 'v2' | 'v3', fee?: number): Promise; export type BalanceValidationParams = { sameAddress: boolean; buyerBalance: bigint; buyAmountBNB: bigint; reserveGas: bigint; gasLimit: bigint; gasPrice: bigint; useNativeToken?: boolean; quoteTokenDecimals?: number; provider?: ethers.JsonRpcProvider; buyerAddress?: string; }; export declare function validateFinalBalances({ sameAddress, buyerBalance, buyAmountBNB, reserveGas, gasLimit, gasPrice, useNativeToken, quoteTokenDecimals, provider, buyerAddress, }: BalanceValidationParams): Promise; export declare function countTruthy(values: Array): number; /** * PancakeSwap V2/V3 通用捆绑换手(Merkle Bundle) * * 功能:钱包A卖出代币 → 钱包B买入相同数量 → 原子执行 * 适用于所有已迁移到外盘的代币(不区分Four/Flap) */ export type UserType = 'v0' | 'v1'; export interface PancakeSwapSignConfig { rpcUrl: string; gasLimit?: number | bigint; gasLimitMultiplier?: number; minGasPriceGwei?: number; maxGasPriceGwei?: number; txType?: 0 | 2; chainId?: number; reserveGasBNB?: number; userType?: UserType; bribeAmount?: number; v2RouterAddress?: string; } /** * 获取 Gas Limit */ export declare function getGasLimit(config: PancakeSwapSignConfig | PancakeSwapConfig, defaultGas?: number): bigint; export declare function getGasPrice(provider: ethers.JsonRpcProvider, config: PancakeSwapSignConfig | PancakeSwapConfig): Promise; export declare const PANCAKE_V2_ROUTER_ABI: string[]; export declare const PANCAKE_V3_ROUTER_ABI: (string | { inputs: { components: { name: string; type: string; }[]; name: string; type: string; }[]; name: string; outputs: { name: string; type: string; }[]; stateMutability: string; type: string; })[]; export declare const ERC20_BALANCE_OF_ABI: string[]; export declare const PANCAKE_V2_ROUTER_ADDRESS: "0x10ED43C718714eb63d5aA57B78B54704E256024E"; export declare const PANCAKE_V3_ROUTER_ADDRESS: "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4"; export declare const FLAT_FEE = 0n; export declare const WBNB_ADDRESS: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; export type SwapRouteType = 'v2' | 'v3-single' | 'v3-multi'; export interface PancakeSwapConfig extends CommonBundleConfig { apiKey: string; customRpcUrl?: string; bundleBlockOffset?: number; reserveGasBNB?: number; waitForConfirmation?: boolean; waitTimeoutMs?: number; } 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 PancakeBundleSwapSignParams { sellerPrivateKey: string; sellAmount?: string; sellPercentage?: number; buyerPrivateKey: string; tokenAddress: string; routeParams: RouteParams; config: PancakeSwapSignConfig; quoteToken?: string; quoteTokenDecimals?: number; startNonces?: number[]; } export interface PancakeBundleSwapParams { sellerPrivateKey: string; sellAmount?: string; sellPercentage?: number; buyerPrivateKey: string; tokenAddress: string; routeParams: RouteParams; config: PancakeSwapConfig; } /** ✅ Pancake Swap 结果(简化版) */ export type PancakeSwapResult = { signedTransactions: string[]; profitHopWallets?: GeneratedWallet[]; metadata?: { sellerAddress: string; buyerAddress: string; sellAmount: string; buyAmount: string; profitAmount?: string; }; }; export type PancakeContext = { chainId: number; provider: ethers.JsonRpcProvider; }; export type QuoteBNBResult = { estimatedBNBOut: bigint; }; export type SwapUnsignedResult = { sellUnsigned: ethers.TransactionLike; buyUnsigned: ethers.TransactionLike; }; export type BuyerBudget = { buyerBalance: bigint; reserveGas: bigint; requiredBalance: bigint; buyAmountBNB: bigint; useNativeToken: boolean; }; export type NoncePlan = { sellerNonce: number; buyerNonce: number; bribeNonce?: number; profitNonce?: number; }; export { ZERO_ADDRESS } from '../../../shared/constants/index.js'; /** * PancakeSwap捆绑换手(V2/V3通用) * ✅ 支持 quoteToken:传入 USDT 等地址时,卖出得到该代币,买入使用该代币 */