/** * BlockRazor Bundle Service 客户端 * * 提供基于 BlockRazor 的 MEV 保护和捆绑交易服务 * * 官方文档: https://blockrazor.gitbook.io/blockrazor/bsc/block-builder/send-bundle * * 特点: * - 支持 BSC 链的 Bundle 提交 * - 激励机制:向 Builder EOA 转账 BNB 可提高优先级 * - 支持 Bundle 合并提高打包率 * * 使用示例: * ```typescript * import { BlockRazorClient } from 'four-flap-meme-sdk'; * * const client = new BlockRazorClient({ * apiKey: 'your-api-key', * chainId: 56 * }); * * const result = await client.sendBundle({ * transactions: [tx1, tx2, tx3], * blockOffset: 10 * }); * ``` */ import { JsonRpcProvider, Wallet, TransactionLike, ethers } from 'ethers'; /** * BlockRazor Builder EOA 地址 * 向此地址转账 BNB 可提高 Bundle 优先级 * 来源: https://blockrazor.gitbook.io/blockrazor/bsc/block-builder/send-bundle */ export declare const BLOCKRAZOR_BUILDER_EOA = "0x1266C6bE60392A8Ff346E8d5ECCd3E69dD9c5F20"; /** * BlockRazor 客户端配置 */ export interface BlockRazorConfig { /** API Key(可选,根据 Tier 等级需要) */ apiKey?: string; /** 链 ID: 56=BSC */ chainId: 56; /** 自定义 RPC URL(可选) */ customRpcUrl?: string; /** 自定义 Builder RPC URL(可选,用于发送 Bundle) */ builderRpcUrl?: string; } /** * BlockRazor Bundle 参数(原始格式) * 参考: https://blockrazor.gitbook.io/blockrazor/bsc/block-builder/send-bundle */ export interface BlockRazorBundleParams { /** 已签名的交易数组(原始交易字符串) */ txs: string[]; /** 最大有效区块号(默认: 当前区块 + 100) */ maxBlockNumber?: number; /** 最小有效时间戳(秒) */ minTimestamp?: number; /** 最大有效时间戳(秒) */ maxTimestamp?: number; /** 允许 revert 的交易哈希列表 */ revertingTxHashes?: string[]; /** 是否禁止 Bundle 合并(默认 false,允许合并可提高打包率) */ noMerge?: boolean; } /** * 发送 Bundle 的选项(高级接口) */ export interface SendBundleOptions { /** 已签名的交易数组 */ transactions: string[]; /** 区块偏移量(默认 10,即当前区块 + 10) */ blockOffset?: number; /** 最大区块偏移量(默认 100) */ maxBlockOffset?: number; /** 最小时间戳 */ minTimestamp?: number; /** 最大时间戳 */ maxTimestamp?: number; /** 允许 revert 的交易哈希列表 */ revertingTxHashes?: string[]; /** 是否禁止 Bundle 合并 */ noMerge?: boolean; /** 是否启用自动重试(默认 false) */ autoRetry?: boolean; /** 最大重试次数(默认 3) */ maxRetries?: number; } /** * Bundle 发送结果 */ export interface BundleResult { /** Bundle Hash */ bundleHash: string; /** 交易哈希列表 */ txHashes: string[]; /** 最大有效区块号 */ maxBlockNumber: number; /** 交易数量 */ txCount: number; } /** * 交易确认结果 */ export interface TransactionResult { /** 交易索引 */ index: number; /** 交易哈希 */ hash: string; /** 是否成功 */ success: boolean; /** 区块号 */ blockNumber?: number; /** Gas 使用量 */ gasUsed?: string; /** 有效 Gas Price */ effectiveGasPrice?: string; /** Gas 费用(BNB) */ gasCost?: string; /** 错误信息 */ error?: string; } /** * 激励交易参数 */ export interface IncentiveTransactionParams { /** 发送者钱包 */ wallet: Wallet; /** 激励金额(BNB) */ amount: string; /** Nonce(可选,自动获取) */ nonce?: number; /** Gas Price(可选,自动获取) */ gasPrice?: bigint; } /** * BlockRazor 客户端 */ export declare class BlockRazorClient { private provider; private chainId; private apiKey?; private builderUrl; private blockNumberCache; private static BLOCK_CACHE_TTL_MS; constructor(config: BlockRazorConfig); /** * 获取 Provider */ getProvider(): JsonRpcProvider; /** * 获取 Builder URL */ getBuilderUrl(): string; /** * 获取当前区块号(带缓存) */ getBlockNumber(forceRefresh?: boolean): Promise; /** * 获取 Gas 价格信息 */ getFeeData(): Promise; /** * 构建激励交易(向 BlockRazor Builder EOA 转账 BNB) * * 根据文档:向 Builder EOA 转账更多 BNB 可提高 Bundle 优先级 * * @param params 激励交易参数 * @returns 已签名的交易 */ buildIncentiveTransaction(params: IncentiveTransactionParams): Promise; /** * 发送捆绑交易(底层方法) * * ✅ 使用 fetch 直接发送请求,支持 Authorization 头 * * @param params Bundle 参数 * @returns Bundle Hash */ sendBundleRaw(params: BlockRazorBundleParams): Promise; /** * 发送捆绑交易(高级方法) * * @param options 发送选项 * @returns Bundle 结果 */ sendBundle(options: SendBundleOptions): Promise; /** * 发送带激励的 Bundle(自动添加激励交易) * * @param options 发送选项 * @param incentive 激励参数 * @returns Bundle 结果 */ sendBundleWithIncentive(options: SendBundleOptions, incentive: { wallet: Wallet; amount: string; }): Promise; /** * 等待 Bundle 中的交易确认 * * @param txHashes 交易哈希列表 * @param confirmations 确认数(默认 1) * @param timeout 超时时间(毫秒,默认 120000) * @returns 交易结果列表 */ waitForBundleConfirmation(txHashes: string[], confirmations?: number, timeout?: number): Promise; /** * 签名交易批次 * * @param wallet 钱包 * @param transactions 交易列表 * @param options 可选参数 * @returns 已签名的交易数组 */ signTransactions(wallet: Wallet, transactions: TransactionLike[], options?: { startNonce?: number; gasPrice?: bigint; gasPriceMultiplier?: number; }): Promise; /** * 检查交易是否已包含在区块中 */ isTransactionIncluded(txHash: string): Promise; /** * 并行广播交易(非捆绑) * * 所有交易同时广播,适合不同钱包的独立交易 * ⚠️ 注意:同一钱包的多笔交易(连续 nonce)不建议并行广播,可能导致后续交易延迟确认 * * @param signedTransactions 已签名的交易数组 * @param options 可选配置 * @returns 广播结果 */ broadcastTransactionsParallel(signedTransactions: string[], options?: { /** 自定义 Provider(可选) */ provider?: JsonRpcProvider; /** 并发限制(默认 10) */ concurrencyLimit?: number; }): Promise<{ success: boolean; txHashes: string[]; errors: Array<{ index: number; error: string; }>; }>; /** * 顺序广播交易(非捆绑) * * 按顺序逐笔广播,可选等待确认后再广播下一笔 * ✅ 适合同一钱包的多笔交易(连续 nonce),确保交易按顺序上链 * * @param signedTransactions 已签名的交易数组 * @param options 可选配置 * @returns 广播结果 */ broadcastTransactionsSequential(signedTransactions: string[], options?: { /** 自定义 Provider(可选) */ provider?: JsonRpcProvider; /** 是否等待每笔交易确认后再广播下一笔(默认 false,只等待广播成功) */ waitConfirmation?: boolean; /** 确认超时时间(毫秒,默认 60000) */ confirmationTimeout?: number; /** 广播间隔(毫秒,默认 100) */ broadcastDelay?: number; }): Promise<{ success: boolean; txHashes: string[]; errors: Array<{ index: number; error: string; }>; }>; /** * 智能广播交易(自动选择并行或顺序) * * 根据交易的发送者地址自动决定广播策略: * - 如果所有交易来自不同钱包:并行广播 * - 如果存在同一钱包的多笔交易:顺序广播 * * @param signedTransactions 已签名的交易数组 * @param options 可选配置 * @returns 广播结果 */ broadcastTransactionsSmart(signedTransactions: string[], options?: { /** 自定义 Provider(可选) */ provider?: JsonRpcProvider; /** 是否等待确认(顺序模式时生效,默认 false) */ waitConfirmation?: boolean; /** 确认超时时间(毫秒,默认 60000) */ confirmationTimeout?: number; }): Promise<{ success: boolean; txHashes: string[]; errors: Array<{ index: number; error: string; }>; mode: 'parallel' | 'sequential'; }>; /** * 获取客户端信息 */ getClientInfo(): { chainId: number; builderEOA: string; minGasPriceGwei: number; }; } /** * 创建 BlockRazor 客户端的便捷函数 */ export declare function createBlockRazorClient(apiKey?: string): BlockRazorClient;