UNPKG

four-flap-meme-sdk

Version:

SDK for Flap bonding curve and four.meme TokenManager

112 lines (111 loc) 4.34 kB
/** * V2/V3 报价工具函数 * * 提供统一的代币报价功能,支持: * - V2 Router 报价(直接路径 + 多跳路径) * - V3 Quoter 报价(多费率尝试 + 多跳路径) * - ERC20 → 原生代币转换报价 */ import { JsonRpcProvider } from 'ethers'; /** V3 常用费率档位 */ export declare const V3_FEE_TIERS: number[]; /** 各链的报价配置 */ export declare const QUOTE_CONFIG: { readonly BSC: { readonly v2Router: "0x10ED43C718714eb63d5aA57B78B54704E256024E"; readonly v3Quoter: "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997"; readonly wrappedNative: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; readonly stableCoins: readonly ["0x55d398326f99059fF775485246999027B3197955", "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d", "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"]; }; readonly MONAD: { readonly v2Router: "0xb1bc24c34e88f7d43d5923034e3a14b24daacff9"; readonly v3Quoter: ""; readonly wrappedNative: "0x3bd359c1119da7da1d913d1c4d2b7c461115433a"; readonly stableCoins: readonly []; }; readonly XLAYER: { readonly v2Router: "0x881fb2f98c13d521009464e7d1cbf16e1b394e8e"; readonly v3Quoter: ""; readonly wrappedNative: "0xe538905cf8410324e03a5a23c1c177a474d59b2b"; readonly stableCoins: readonly ["0x1E4a5963aBFD975d8c9021ce480b42188849D41d"]; }; }; export type SupportedChain = keyof typeof QUOTE_CONFIG; export interface QuoteParams { provider: JsonRpcProvider; tokenIn: string; tokenOut: string; amountIn: bigint; chain: string; version?: 'v2' | 'v3'; fee?: number; } export interface QuoteResult { amountOut: bigint; path?: string[]; fee?: number; } /** * V2 报价(直接路径 + 多跳路径) * ✅ 优化:并行尝试直接路径和多跳路径 * * @param provider - Provider 实例 * @param tokenIn - 输入代币地址 * @param tokenOut - 输出代币地址 * @param amountIn - 输入数量(wei) * @param chain - 链名称 * @returns 报价结果 */ export declare function quoteV2(provider: JsonRpcProvider, tokenIn: string, tokenOut: string, amountIn: bigint, chain: string): Promise<QuoteResult>; /** * V3 报价(多费率尝试 + 多跳路径) * ✅ 优化:并行尝试多个费率 * * @param provider - Provider 实例 * @param tokenIn - 输入代币地址 * @param tokenOut - 输出代币地址 * @param amountIn - 输入数量(wei) * @param chain - 链名称 * @param preferredFee - 优先尝试的费率(可选) * @returns 报价结果 */ export declare function quoteV3(provider: JsonRpcProvider, tokenIn: string, tokenOut: string, amountIn: bigint, chain: string, preferredFee?: number): Promise<QuoteResult>; /** * 统一报价接口(根据版本自动选择 V2 或 V3) * * @param params - 报价参数 * @returns 报价结果 */ export declare function quote(params: QuoteParams): Promise<QuoteResult>; /** * 获取 ERC20 代币 → 原生代币(WBNB/WMON 等)的报价 * * @param provider - Provider 实例 * @param tokenAddress - ERC20 代币地址 * @param tokenAmount - 代币数量(wei) * @param chain - 链名称 * @param version - 'v2' | 'v3' * @param fee - V3 费率档位(仅 V3 时使用) * @returns 等值的原生代币数量(wei),失败返回 0n */ export declare function getTokenToNativeQuote(provider: JsonRpcProvider, tokenAddress: string, tokenAmount: bigint, chain: string, version?: 'v2' | 'v3', fee?: number): Promise<bigint>; /** * 获取原生代币 → ERC20 代币的报价 * * @param provider - Provider 实例 * @param tokenAddress - ERC20 代币地址 * @param nativeAmount - 原生代币数量(wei) * @param chain - 链名称 * @param version - 'v2' | 'v3' * @param fee - V3 费率档位(仅 V3 时使用) * @returns 等值的 ERC20 代币数量(wei),失败返回 0n */ export declare function getNativeToTokenQuote(provider: JsonRpcProvider, tokenAddress: string, nativeAmount: bigint, chain: string, version?: 'v2' | 'v3', fee?: number): Promise<bigint>; /** * 获取链的包装原生代币地址 */ export declare function getWrappedNativeAddress(chain: string): string; /** * 获取链的稳定币列表 */ export declare function getStableCoins(chain: string): string[];