/** * EIP-7702 XLayer 工具函数 */ import { Wallet, JsonRpcProvider } from 'ethers'; import type { Authorization, Call3Value, WalletType, GeneratedWallet, EIP7702Config } from './types.js'; export declare function bigintToBytes(value: bigint): Uint8Array; export declare function addressToBytes(address: string): Uint8Array; export declare function hexToBytes(hex: string): Uint8Array; export declare function trimLeadingZeros(bytes: Uint8Array): Uint8Array; export declare function getCachedProvider(rpcUrl?: string): JsonRpcProvider; export declare function clearProviderCache(): void; /** * 操作类型(用于 gas 估算) */ export type OperationType = 'transfer' | 'buy' | 'sell' | 'swap' | 'create' | 'approve' | 'graduate' | 'unknown'; /** * 动态估算 Gas Limit * * @param authorizationCount 授权数量 * @param calls Multicall 调用列表 * @param configGasLimit 配置的 gas limit(可选,优先使用) * @returns 估算的 gas limit */ export declare function estimateGasLimit(authorizationCount: number, calls: Call3Value[], configGasLimit?: bigint): bigint; /** * 简化版 gas 估算(仅根据调用数量) * 适用于无法分析 callData 的场景 */ export declare function estimateGasLimitSimple(authorizationCount: number, callCount: number, operationType?: 'simple' | 'buy' | 'sell' | 'swap' | 'create' | 'graduate', configGasLimit?: bigint): bigint; export declare function createWallet(privateKey: string, provider?: JsonRpcProvider): Wallet; export declare function generateRandomWallet(): GeneratedWallet; export declare function generateRandomWallets(count: number): GeneratedWallet[]; export declare function signAuthorization(wallet: WalletType, delegateAddress: string, nonce: bigint, chainId?: number): Promise; export declare function signAuthorizationWithNonce(wallet: WalletType, delegateAddress: string, provider: JsonRpcProvider, isTransactionSender?: boolean): Promise; /** * 批量签署授权 - 并行获取 nonce,并行签名 */ export declare function signAuthorizationsBatch(wallets: WalletType[], delegateAddress: string, provider: JsonRpcProvider, mainWalletIndex?: number): Promise; /** * 批量签署授权(带预取 nonce)- 用于与其他操作并行 */ export declare function signAuthorizationsWithNonces(wallets: WalletType[], nonces: number[], delegateAddress: string, mainWalletIndex?: number): Authorization[]; /** * 批量获取多个地址的 nonce - 并行 */ export declare function batchGetNonces(addresses: string[], provider: JsonRpcProvider): Promise; export declare function buildEIP7702Transaction(mainWallet: Wallet, authorizations: Authorization[], calls: Call3Value[], totalValue: bigint, config?: EIP7702Config): Promise; /** * 构建 EIP-7702 交易(带预取数据)- 用于已并行获取 nonce/feeData 的场景 */ export declare function buildEIP7702TransactionSync(mainWallet: Wallet, authorizations: Authorization[], calls: Call3Value[], totalValue: bigint, nonce: number, feeData: { maxPriorityFeePerGas: bigint | null; maxFeePerGas: bigint | null; }, config?: EIP7702Config): string; export type UserType = 'v0' | 'v1' | 'default'; /** * 根据用户类型获取利润率(单边模式) * - v0: 8 bps = 0.08% * - v1: 10 bps = 0.10% * - default: 8 bps = 0.08% */ export declare function getProfitRateBps(userType?: UserType): number; /** * 根据用户类型获取利润率(双边/换手模式) * - v0: 4 bps = 0.04% * - v1: 5 bps = 0.05% * - default: 4 bps = 0.04% */ export declare function getProfitRateBpsDouble(userType?: UserType): number; /** * 计算利润金额(旧版兼容) */ export declare function calculateProfitAmount(totalFlowWei: bigint, isSwapMode?: boolean): bigint; /** * 计算利润金额(基于用户类型) * @param totalFlowWei 总资金流水 * @param userType 用户类型 * @param isDoubleMode 是否双边模式(换手模式) */ export declare function calculateProfitAmountByUserType(totalFlowWei: bigint, userType?: UserType, isDoubleMode?: boolean): bigint; /** * 根据交易数量计算利润金额 * @param totalFlowWei 总资金流水 * @param txCount 交易数量 * @param userType 用户类型 */ export declare function calculateProfitAmountByTxCount(totalFlowWei: bigint, txCount: number, userType?: UserType): bigint; export declare function getProfitRecipient(config?: EIP7702Config): string; export declare function getDeadline(minutes?: number): number; export declare function delay(ms: number): Promise;