import { ethers, Wallet, JsonRpcProvider } from 'ethers'; import type { DirectRouterSignConfig } from './types.js'; import type { GeneratedWallet } from '../utils/wallet.js'; /** * 直接 Router 交易(不走代理合约) * * 支持: * - BSC: PancakeSwap V2/V3 * - Monad: PancakeSwap V2, Uniswap V2/V3 * * 收费方式:交易末尾附加利润提取交易(和内盘一致) */ export declare const providerCache: Map; export declare const PROVIDER_CACHE_TTL = 60000; export declare const providerCacheTimestamps: Map; /** * 获取缓存的 Provider 实例 * - 根据 rpcUrl + chainId 作为缓存 key * - 60秒后自动失效,避免长连接问题 */ export declare function getCachedProvider(rpcUrl: string, chainId: number, chainName: string): JsonRpcProvider; export declare const DEFAULT_GAS_LIMIT = 300000; export declare const DEADLINE_MINUTES = 20; /** * 截断小数位数,避免超过代币精度导致 parseUnits 报错 * 例如:truncateDecimals("21906.025000000000000000", 1) => "21906.0" */ export declare function truncateDecimals(value: string, decimals: number): string; /** Router 地址配置 - ✅ 使用公共模块中的地址 */ export declare const DIRECT_ROUTERS: { readonly BSC: { readonly PANCAKESWAP_V2: "0x10ED43C718714eb63d5aA57B78B54704E256024E"; readonly PANCAKESWAP_V3: "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4"; readonly IROSWAP_V2: "0xe90fb729E458092592a79EdaFefB3404ecb3C463"; readonly WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; }; readonly MONAD: { readonly PANCAKESWAP_V2: "0xb1bc24c34e88f7d43d5923034e3a14b24daacff9"; readonly PANCAKESWAP_V3: "0x1b81d678ffb9c0263b24a97847620c99d213eb14"; readonly UNISWAP_V2: "0x4b2ab38dbf28d31d467aa8993f6c2585981d6804"; readonly UNISWAP_V3: "0xd6145b2d3f379919e8cdeda7b97e37c4b2ca9c40"; readonly WMON: "0x3bd359c1119da7da1d913d1c4d2b7c461115433a"; }; readonly XLAYER: { readonly POTATOSWAP_V2: "0x881fb2f98c13d521009464e7d1cbf16e1b394e8e"; readonly POTATOSWAP_V3: "0xB45D0149249488333E3F3f9F359807F4b810C1FC"; readonly DYORSWAP_ROUTER: "0xfb001fbbace32f09cb6d3c449b935183de53ee96"; readonly DYORSWAP_FACTORY: "0x2CcaDb1e437AA9cDc741574bDa154686B1F04C09"; readonly V3_ROUTER: "0xBB069e9465BcabC4F488d21e793BDEf0F2d41D41"; readonly V3_FACTORY: "0xa1415fAe79c4B196d087F02b8aD5a622B8A827E5"; readonly WOKB: "0xe538905cf8410324e03a5a23c1c177a474d59b2b"; }; readonly ENI: { readonly DSWAP_V2: "0x97ed8be49d9a8b86247090aa41e908e76b8fcf22"; readonly DSWAP_V3: "0xcdE487F5B460a516f31FaC520D4e18BA1C8cda49"; readonly IROSWAP_V2: "0x93b1199fA96f6b9b1f993AA0226eB6076968a9BF"; readonly WEGAS: "0x6d1e851446f4d004ae2a72f9afed85e8829a205e"; }; }; /** 链 ID 映射 */ export declare const CHAIN_IDS: { readonly BSC: 56; readonly MONAD: 143; readonly XLAYER: 196; readonly ENI: 173; }; /** 获取原生包装代币地址 */ export declare function getWrappedNative(chain: string): string; /** V2 Router ABI */ export declare const V2_ROUTER_ABI: string[]; /** SwapRouter02 的 V2 方法 ABI - ✅ 从公共模块导入 */ export declare const SWAP_ROUTER02_V2_ABI: string[]; /** * DYORSwap SwapRouter02 的 V2 方法 * * ⚠️ 重要:DYORSwap 使用自定义的函数签名,无法通过标准 ABI 编码 * 必须手动构造 calldata * * swapExactTokensForTokens selector: 0x3234fe0d * unwrapWETH9 selector: 0x7342292e * refundETH selector: 0x6d29fcf4 */ export declare const DYORSWAP_SELECTORS: { swapExactTokensForTokens: string; unwrapWETH9: string; refundETH: string; multicall: string; }; /** * 手动编码 DYORSwap 的 swapExactTokensForTokens calldata * * 参数格式 (根据成功交易分析): * - amountIn: uint256 * - amountOutMin: uint256 * - path: address[] (动态) - offset from start * - pools: address[] (动态) - offset from start * - to: uint256 (address(2) = 2) * - flag: uint256 (1) * - factory: address * * 成功交易的布局: * [0] amountIn * [1] amountOutMin * [2] offset to path = 0xa0 = 160 = 5 * 32 (从参数区域开始) * [3] offset to pools = 0xe0 = 224 = 7 * 32 * [4] to = 2 * [5] flag = 1 * [6] factory * [7] path.length * [8+] path elements * [N] pools.length * [N+1+] pools elements */ export declare function encodeDYORSwapExactTokensForTokens(amountIn: bigint, amountOutMin: bigint, path: string[], pools: string[], to: string | bigint, // 可以是地址 (string) 或 address(2) 这样的特殊值 (bigint) flag: bigint, factory: string): string; /** * 手动编码 DYORSwap 的 unwrapWETH9 calldata * * 参数格式 (根据成功交易分析): * - amountMinimum: uint256 * - recipient: address * - pools: bytes (动态) - 包含特殊的 pool 数据 * * 成功交易的布局: * [0] amountMinimum * [1] recipient * [2] offset to pools = 0x60 = 96 = 3 * 32 * [3] pools 数据 (bytes) */ export declare function encodeDYORUnwrapWETH9(amountMinimum: bigint, recipient: string, poolsData?: string): string; /** * DYORSwap 的 ETHBack_Dividend 合约地址 * 这是 refundETH 中使用的固定地址,不是 LP 池地址 */ export declare const DYORSWAP_ETHBACK_DIVIDEND: "0x2e61b0b4410f6fb941d47205191cbb8963d44bcc"; /** * 手动编码 DYORSwap 的 refundETH calldata * * 根据成功交易分析,refundETH 的格式是: * refundETH(bytes pools) * * 成功交易的 refundETH (0x6d29fcf4): * [0] offset to pools = 0x20 = 32 * [1] pools 数组长度 = 1 * [2] fee = 30 (0x1e) * [3] ETHBack_Dividend 合约地址 */ export declare function encodeDYORRefundETH(fee?: number): string; /** * 手动编码 DYORSwap 的 multicall calldata * * multicall(uint256 deadline, bytes[] data) * 这个函数使用标准 ABI 编码 */ export declare function encodeDYORMulticall(deadline: bigint, data: string[]): string; /** V3 SwapRouter02 ABI (PancakeSwap V3, 新版 Uniswap) */ export declare const V3_ROUTER02_ABI: (string | { inputs: { components: { name: string; type: string; }[]; name: string; type: string; }[]; name: string; outputs: { name: string; type: string; }[]; stateMutability: string; type: string; })[]; /** V3 SwapRouter(旧版)ABI (Monad Uniswap V3) */ export declare const V3_ROUTER_LEGACY_ABI: (string | { inputs: { components: { name: string; type: string; }[]; name: string; type: string; }[]; name: string; outputs: { name: string; type: string; }[]; stateMutability: string; type: string; })[]; /** * 判断是否使用旧版 SwapRouter * * 旧版特征: * - exactInputSingle 包含 deadline 字段 * - multicall 只有 bytes[] 参数 * * Monad 上的 V3 DEX 都使用旧版: * - Uniswap V3: 0xd6145b2d3f379919e8cdeda7b97e37c4b2ca9c40 * - PancakeSwap V3: 0x1b81D678ffb9C0263b24A97847620C99d213eB14 * * XLayer: * - V3 Router (0xBB069e9465BcabC4F488d21e793BDEf0F2d41D41) - 旧版(exactInputSingle 包含 deadline) * - SwapRouter02 (0xB45D0149249488333E3F3f9F359807F4b810C1FC) - 新版(V2+V3 混合) * * BSC PancakeSwap V3 使用新版 SwapRouter02 */ export declare function isLegacySwapRouter(chain: string, routerAddress: string): boolean; /** ERC20 ABI - ✅ 从公共模块导入 */ export declare function getDeadline(minutes?: number): number; export declare function getGasLimit(config: DirectRouterSignConfig, defaultGas?: number): bigint; export declare function getGasPrice(provider: JsonRpcProvider, config: DirectRouterSignConfig): Promise; export declare function isNativeToken(quoteToken?: string): boolean; export declare const XLAYER_V3_FACTORY_ABI: readonly ["function getPool(address tokenA, address tokenB, uint24 fee) view returns (address pool)"]; export declare const XLAYER_V3_POOL_ABI: readonly ["function slot0() view returns (uint160 sqrtPriceX96,int24 tick,uint16 observationIndex,uint16 observationCardinality,uint16 observationCardinalityNext,uint8 feeProtocol,bool unlocked)", "function token0() view returns (address)", "function token1() view returns (address)"]; export declare const V3_FEE_DENOMINATOR = 1000000n; export declare function quoteXLayerV3TokenToNativeBySlot0(params: { provider: JsonRpcProvider; tokenIn: string; amountIn: bigint; fee: number; }): Promise; /** * ✅ 找到金额最大的钱包索引(和 core.ts 逻辑一致) */ export declare function findMaxFlowIndex(amounts: bigint[]): number; /** 计算利润金额 */ export declare function calculateProfitAmount(totalFlowWei: bigint): bigint; /** * 构建利润多跳转账交易(强制 2 跳中转) */ export declare function buildProfitTransactionWithHops(provider: JsonRpcProvider, wallet: Wallet, profitAmountWei: bigint, nonce: number, gasPrice: bigint, chainId: number, txType?: 0 | 2, profitRecipient?: string): Promise<{ signedTransactions: string[]; hopWallets?: GeneratedWallet[]; }>; /** * 获取贿赂金额(wei) * ✅ 仅 BSC 链支持贿赂 */ export declare function getBribeAmount(config: DirectRouterSignConfig, chain: string): bigint; /** 构建贿赂交易(向 BlockRazor Builder EOA 转账 BNB) */ export declare function buildBribeTransaction(wallet: Wallet, bribeAmountWei: bigint, nonce: number, gasPrice: bigint, chainId: number, txType?: 0 | 2): Promise; /** * 判断是否是 SwapRouter02 (XLayer PotatoSwap V3) * * SwapRouter02 风格的 Router 使用 multicall 包装 V2 方法: * - multicall(uint256 deadline, bytes[] data) * - data 内包含 swapExactTokensForTokens 等 V2 方法 * * SwapRouter02 的 V2 方法签名不同: * - swapExactTokensForTokens(amountIn, amountOutMin, path[], to) - 没有 deadline * - 需要通过 multicall 的 deadline 参数传递 deadline * * ⚠️ 注意:DYORSwap 虽然也用 multicall,但它的 ABI 完全不同,需要单独处理 */ export declare function isSwapRouter02(chain: string, routerAddress: string): boolean; /** * 判断是否是 DYORSwap Router * * DYORSwap 使用 multicall,但它的 swapExactTokensForTokens 有特殊的 ABI: * - swapExactTokensForTokens(amountIn, amountOutMin, path[], payer, flags, factory, pools) * - unwrapWETH9(amountMinimum, recipient, pools) */ export declare function isDYORSwap(chain: string, routerAddress: string): boolean; export declare function filterEniNativeBuyIndices(balances: bigint[], flowAmounts: bigint[], gasLimit: number | bigint, gasPrice: bigint, profitWei: bigint): number[] | null; /** * V2 批量买入(直接调用 Router) */