four-flap-meme-sdk 1.4.91 → 1.4.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,162 @@
1
+ /**
2
+ * XLayer Bundler 客户端
3
+ *
4
+ * 与 Particle Bundler 交互,提供 ERC-4337 相关 RPC 方法
5
+ */
6
+ import { PARTICLE_BUNDLER_URL, XLAYER_CHAIN_ID, ENTRYPOINT_V06, } from './constants.js';
7
+ // ============================================================================
8
+ // Bundler 客户端类
9
+ // ============================================================================
10
+ let nextRpcId = 1;
11
+ /**
12
+ * Particle Bundler 客户端
13
+ *
14
+ * 提供与 ERC-4337 Bundler 交互的方法:
15
+ * - eth_supportedEntryPoints
16
+ * - eth_estimateUserOperationGas
17
+ * - eth_sendUserOperation
18
+ * - eth_getUserOperationReceipt
19
+ * - eth_getUserOperationByHash
20
+ */
21
+ export class BundlerClient {
22
+ constructor(config = {}) {
23
+ this.url = config.url ?? PARTICLE_BUNDLER_URL;
24
+ this.chainId = config.chainId ?? XLAYER_CHAIN_ID;
25
+ this.entryPoint = config.entryPoint ?? ENTRYPOINT_V06;
26
+ this.timeoutMs = config.timeoutMs ?? 20000;
27
+ this.headers = config.headers ?? {};
28
+ }
29
+ /**
30
+ * 发送 JSON-RPC 请求到 Bundler
31
+ */
32
+ async rpc(method, params = []) {
33
+ const controller = new AbortController();
34
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
35
+ try {
36
+ const body = {
37
+ jsonrpc: '2.0',
38
+ id: nextRpcId++,
39
+ method,
40
+ params,
41
+ chainId: this.chainId,
42
+ };
43
+ const res = await fetch(this.url, {
44
+ method: 'POST',
45
+ headers: {
46
+ 'content-type': 'application/json',
47
+ ...this.headers,
48
+ },
49
+ body: JSON.stringify(body),
50
+ signal: controller.signal,
51
+ });
52
+ const text = await res.text();
53
+ let data;
54
+ try {
55
+ data = JSON.parse(text);
56
+ }
57
+ catch {
58
+ throw new Error(`非 JSON 响应 (HTTP ${res.status}): ${text.slice(0, 400)}`);
59
+ }
60
+ if (!res.ok) {
61
+ throw new Error(`HTTP ${res.status}: ${JSON.stringify(data).slice(0, 800)}`);
62
+ }
63
+ if (data?.error) {
64
+ throw new Error(`RPC error: ${JSON.stringify(data.error)}`);
65
+ }
66
+ return data?.result;
67
+ }
68
+ finally {
69
+ clearTimeout(timer);
70
+ }
71
+ }
72
+ /**
73
+ * 获取支持的 EntryPoint 列表
74
+ */
75
+ async getSupportedEntryPoints() {
76
+ return await this.rpc('eth_supportedEntryPoints', []);
77
+ }
78
+ /**
79
+ * 估算 UserOperation Gas
80
+ *
81
+ * @param userOp 未签名的 UserOperation(signature 可为空)
82
+ * @returns Gas 估算结果
83
+ */
84
+ async estimateUserOperationGas(userOp) {
85
+ return await this.rpc('eth_estimateUserOperationGas', [
86
+ userOp,
87
+ this.entryPoint,
88
+ ]);
89
+ }
90
+ /**
91
+ * 发送 UserOperation
92
+ *
93
+ * @param userOp 已签名的 UserOperation
94
+ * @returns userOpHash
95
+ */
96
+ async sendUserOperation(userOp) {
97
+ return await this.rpc('eth_sendUserOperation', [
98
+ userOp,
99
+ this.entryPoint,
100
+ ]);
101
+ }
102
+ /**
103
+ * 获取 UserOperation 回执
104
+ *
105
+ * @param userOpHash UserOperation 哈希
106
+ * @returns 回执(如果还未被打包则返回 null)
107
+ */
108
+ async getUserOperationReceipt(userOpHash) {
109
+ return await this.rpc('eth_getUserOperationReceipt', [
110
+ userOpHash,
111
+ ]);
112
+ }
113
+ /**
114
+ * 根据 hash 获取 UserOperation
115
+ *
116
+ * @param userOpHash UserOperation 哈希
117
+ */
118
+ async getUserOperationByHash(userOpHash) {
119
+ return await this.rpc('eth_getUserOperationByHash', [userOpHash]);
120
+ }
121
+ /**
122
+ * 等待 UserOperation 被打包
123
+ *
124
+ * @param userOpHash UserOperation 哈希
125
+ * @param maxTries 最大轮询次数(默认 80)
126
+ * @param intervalMs 轮询间隔(默认 1500ms)
127
+ * @returns 回执
128
+ */
129
+ async waitForUserOperationReceipt(userOpHash, maxTries = 80, intervalMs = 1500) {
130
+ for (let i = 0; i < maxTries; i++) {
131
+ const receipt = await this.getUserOperationReceipt(userOpHash);
132
+ if (receipt)
133
+ return receipt;
134
+ await sleep(intervalMs);
135
+ }
136
+ return null;
137
+ }
138
+ /**
139
+ * 获取当前使用的 EntryPoint 地址
140
+ */
141
+ getEntryPoint() {
142
+ return this.entryPoint;
143
+ }
144
+ /**
145
+ * 获取当前链 ID
146
+ */
147
+ getChainId() {
148
+ return this.chainId;
149
+ }
150
+ }
151
+ // ============================================================================
152
+ // 工具函数
153
+ // ============================================================================
154
+ function sleep(ms) {
155
+ return new Promise((resolve) => setTimeout(resolve, ms));
156
+ }
157
+ /**
158
+ * 创建默认的 Bundler 客户端
159
+ */
160
+ export function createBundlerClient(config) {
161
+ return new BundlerClient(config);
162
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * XLayer SDK 常量配置
3
+ *
4
+ * XLayer 链 (chainId: 196) 的核心配置信息
5
+ * 支持 ERC-4337 AA 钱包模式进行 Flap 内盘交易
6
+ */
7
+ /** XLayer 链 ID */
8
+ export declare const XLAYER_CHAIN_ID = 196;
9
+ /** XLayer 链名称 */
10
+ export declare const XLAYER_CHAIN_NAME = "xlayer";
11
+ /** 默认 RPC URL */
12
+ export declare const DEFAULT_RPC_URL = "https://rpc.xlayer.tech";
13
+ /** 高级 RPC URL(QuikNode) */
14
+ export declare const QUIKNODE_RPC_URL = "https://stylish-practical-valley.xlayer-mainnet.quiknode.pro/84bb5dedac404fa486f57ab6387e32254dee1f83";
15
+ /** EntryPoint v0.6 合约地址 */
16
+ export declare const ENTRYPOINT_V06 = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
17
+ /** SimpleAccountFactory 合约地址 */
18
+ export declare const SIMPLE_ACCOUNT_FACTORY = "0x9406Cc6185a346906296840746125a0E44976454";
19
+ /** Particle Bundler URL */
20
+ export declare const PARTICLE_BUNDLER_URL = "https://bundler.particle.network";
21
+ /** Flap Portal 合约地址(XLayer 内盘) */
22
+ export declare const FLAP_PORTAL = "0xb30D8c4216E1f21F27444D2FfAee3ad577808678";
23
+ /** Flap Token 实现合约地址 */
24
+ export declare const FLAP_TOKEN_IMPL = "0x12Dc83157Bf1cfCB8Db5952b3ba5bb56Cc38f8C9";
25
+ /** WOKB 原生包装代币 */
26
+ export declare const WOKB = "0xe538905cf8410324e03a5a23c1c177a474d59b2b";
27
+ /** Multicall3 合约 */
28
+ export declare const MULTICALL3 = "0xca11bde05977b3631167028862be2a173976ca11";
29
+ /** PotatoSwap V2 Router */
30
+ export declare const POTATOSWAP_V2_ROUTER = "0x881fb2f98c13d521009464e7d1cbf16e1b394e8e";
31
+ /** PotatoSwap SwapRouter02 */
32
+ export declare const POTATOSWAP_SWAP_ROUTER02 = "0xB45D0149249488333E3F3f9F359807F4b810C1FC";
33
+ /** PotatoSwap V3 Router */
34
+ export declare const POTATOSWAP_V3_ROUTER = "0xBB069e9465BcabC4F488d21e793BDEf0F2d41D41";
35
+ /** PotatoSwap V3 Factory */
36
+ export declare const POTATOSWAP_V3_FACTORY = "0xa1415fAe79c4B196d087F02b8aD5a622B8A827E5";
37
+ /** USDT (6位精度) */
38
+ export declare const USDT = "0x1e4a5963abfd975d8c9021ce480b42188849d41d";
39
+ /** USDC (6位精度) */
40
+ export declare const USDC = "0x74b7f16337b8972027f6196a17a631ac6de26d22";
41
+ /** 零地址(表示原生代币 OKB) */
42
+ export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
43
+ /** 默认 Gas Price 兜底值(0.1 gwei) */
44
+ export declare const DEFAULT_GAS_PRICE = 100000000n;
45
+ /** 默认 Salt(用于 AA 账户派生) */
46
+ export declare const DEFAULT_SALT = 0n;
47
+ /** 默认 Withdraw Reserve(保留在 sender 的最小 OKB) */
48
+ export declare const DEFAULT_WITHDRAW_RESERVE = "0.00005";
49
+ /** Gas 估算安全余量(20%) */
50
+ export declare const GAS_LIMIT_MULTIPLIER = 1.2;
51
+ /** 验证 Gas 上限(未部署账户) */
52
+ export declare const VERIFICATION_GAS_LIMIT_DEPLOY = 800000n;
53
+ /** 验证 Gas 上限(已部署账户) */
54
+ export declare const VERIFICATION_GAS_LIMIT_NORMAL = 250000n;
55
+ /** Pre-verification Gas */
56
+ export declare const PRE_VERIFICATION_GAS = 60000n;
57
+ /** 默认 Call Gas Limit(卖出时的保守值) */
58
+ export declare const DEFAULT_CALL_GAS_LIMIT_SELL = 450000n;
59
+ /** XLayer Flap 买入手续费率 (1.5%) */
60
+ export declare const FLAP_BUY_FEE_RATE = 0.015;
61
+ /** XLayer Flap 卖出手续费率 (1.5%) */
62
+ export declare const FLAP_SELL_FEE_RATE = 0.015;
63
+ /** SimpleAccountFactory ABI */
64
+ export declare const FACTORY_ABI: readonly ["function createAccount(address owner, uint256 salt) returns (address)", "function getAddress(address owner, uint256 salt) view returns (address)", "function accountImplementation() view returns (address)"];
65
+ /** EntryPoint v0.6 ABI */
66
+ export declare const ENTRYPOINT_ABI: readonly ["function getNonce(address sender, uint192 key) view returns (uint256)", "function getUserOpHash((address sender,uint256 nonce,bytes initCode,bytes callData,uint256 callGasLimit,uint256 verificationGasLimit,uint256 preVerificationGas,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,bytes paymasterAndData,bytes signature) userOp) view returns (bytes32)", "function handleOps((address sender,uint256 nonce,bytes initCode,bytes callData,uint256 callGasLimit,uint256 verificationGasLimit,uint256 preVerificationGas,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,bytes paymasterAndData,bytes signature)[] ops, address payable beneficiary) external", "function depositTo(address account) public payable", "function balanceOf(address account) public view returns (uint256)", "event UserOperationEvent(bytes32 indexed userOpHash, address indexed sender, address indexed paymaster, uint256 nonce, bool success, uint256 actualGasCost, uint256 actualGasUsed)"];
67
+ /** SimpleAccount ABI */
68
+ export declare const SIMPLE_ACCOUNT_ABI: readonly ["function execute(address dest, uint256 value, bytes func) external", "function executeBatch(address[] calldata dest, bytes[] calldata func) external", "function executeBatch(address[] calldata dest, uint256[] calldata values, bytes[] calldata func) external"];
69
+ /** Flap Portal ABI */
70
+ export declare const PORTAL_ABI: readonly ["function swapExactInput((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData) params) payable returns (uint256)", "function buy(address token, address to, uint256 minAmount) external payable returns (uint256)", "function sell(address token, uint256 amount, uint256 minEth) external returns (uint256)", "function quoteExactInput((address inputToken,address outputToken,uint256 inputAmount)) external returns (uint256)", "function previewBuy(address token, uint256 ethAmount) external view returns (uint256)", "function previewSell(address token, uint256 tokenAmount) external view returns (uint256)", "function getTokenV5(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32))"];
71
+ /** ERC20 ABI */
72
+ export declare const ERC20_ABI: readonly ["function balanceOf(address account) view returns (uint256)", "function allowance(address owner, address spender) view returns (uint256)", "function approve(address spender, uint256 amount) returns (bool)", "function transfer(address to, uint256 amount) returns (bool)", "function decimals() view returns (uint8)", "function symbol() view returns (string)", "function name() view returns (string)"];
73
+ /** PotatoSwap V2 Router ABI */
74
+ export declare const POTATOSWAP_V2_ROUTER_ABI: readonly ["function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)", "function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)", "function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)", "function swapExactETHForTokensSupportingFeeOnTransferTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable", "function swapExactTokensForETHSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external", "function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external", "function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)", "function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts)", "function WETH() external pure returns (address)"];
75
+ export type HexString = `0x${string}`;
@@ -0,0 +1,145 @@
1
+ /**
2
+ * XLayer SDK 常量配置
3
+ *
4
+ * XLayer 链 (chainId: 196) 的核心配置信息
5
+ * 支持 ERC-4337 AA 钱包模式进行 Flap 内盘交易
6
+ */
7
+ // ============================================================================
8
+ // 链基础配置
9
+ // ============================================================================
10
+ /** XLayer 链 ID */
11
+ export const XLAYER_CHAIN_ID = 196;
12
+ /** XLayer 链名称 */
13
+ export const XLAYER_CHAIN_NAME = 'xlayer';
14
+ /** 默认 RPC URL */
15
+ export const DEFAULT_RPC_URL = 'https://rpc.xlayer.tech';
16
+ /** 高级 RPC URL(QuikNode) */
17
+ export const QUIKNODE_RPC_URL = 'https://stylish-practical-valley.xlayer-mainnet.quiknode.pro/84bb5dedac404fa486f57ab6387e32254dee1f83';
18
+ // ============================================================================
19
+ // ERC-4337 相关合约地址
20
+ // ============================================================================
21
+ /** EntryPoint v0.6 合约地址 */
22
+ export const ENTRYPOINT_V06 = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789';
23
+ /** SimpleAccountFactory 合约地址 */
24
+ export const SIMPLE_ACCOUNT_FACTORY = '0x9406Cc6185a346906296840746125a0E44976454';
25
+ /** Particle Bundler URL */
26
+ export const PARTICLE_BUNDLER_URL = 'https://bundler.particle.network';
27
+ // ============================================================================
28
+ // Flap Portal 相关合约地址
29
+ // ============================================================================
30
+ /** Flap Portal 合约地址(XLayer 内盘) */
31
+ export const FLAP_PORTAL = '0xb30D8c4216E1f21F27444D2FfAee3ad577808678';
32
+ /** Flap Token 实现合约地址 */
33
+ export const FLAP_TOKEN_IMPL = '0x12Dc83157Bf1cfCB8Db5952b3ba5bb56Cc38f8C9';
34
+ // ============================================================================
35
+ // DEX 相关合约地址
36
+ // ============================================================================
37
+ /** WOKB 原生包装代币 */
38
+ export const WOKB = '0xe538905cf8410324e03a5a23c1c177a474d59b2b';
39
+ /** Multicall3 合约 */
40
+ export const MULTICALL3 = '0xca11bde05977b3631167028862be2a173976ca11';
41
+ /** PotatoSwap V2 Router */
42
+ export const POTATOSWAP_V2_ROUTER = '0x881fb2f98c13d521009464e7d1cbf16e1b394e8e';
43
+ /** PotatoSwap SwapRouter02 */
44
+ export const POTATOSWAP_SWAP_ROUTER02 = '0xB45D0149249488333E3F3f9F359807F4b810C1FC';
45
+ /** PotatoSwap V3 Router */
46
+ export const POTATOSWAP_V3_ROUTER = '0xBB069e9465BcabC4F488d21e793BDEf0F2d41D41';
47
+ /** PotatoSwap V3 Factory */
48
+ export const POTATOSWAP_V3_FACTORY = '0xa1415fAe79c4B196d087F02b8aD5a622B8A827E5';
49
+ // ============================================================================
50
+ // 稳定币地址
51
+ // ============================================================================
52
+ /** USDT (6位精度) */
53
+ export const USDT = '0x1e4a5963abfd975d8c9021ce480b42188849d41d';
54
+ /** USDC (6位精度) */
55
+ export const USDC = '0x74b7f16337b8972027f6196a17a631ac6de26d22';
56
+ // ============================================================================
57
+ // 零地址
58
+ // ============================================================================
59
+ /** 零地址(表示原生代币 OKB) */
60
+ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
61
+ // ============================================================================
62
+ // Gas 配置
63
+ // ============================================================================
64
+ /** 默认 Gas Price 兜底值(0.1 gwei) */
65
+ export const DEFAULT_GAS_PRICE = 100000000n;
66
+ /** 默认 Salt(用于 AA 账户派生) */
67
+ export const DEFAULT_SALT = 0n;
68
+ /** 默认 Withdraw Reserve(保留在 sender 的最小 OKB) */
69
+ export const DEFAULT_WITHDRAW_RESERVE = '0.00005';
70
+ /** Gas 估算安全余量(20%) */
71
+ export const GAS_LIMIT_MULTIPLIER = 1.2;
72
+ /** 验证 Gas 上限(未部署账户) */
73
+ export const VERIFICATION_GAS_LIMIT_DEPLOY = 800000n;
74
+ /** 验证 Gas 上限(已部署账户) */
75
+ export const VERIFICATION_GAS_LIMIT_NORMAL = 250000n;
76
+ /** Pre-verification Gas */
77
+ export const PRE_VERIFICATION_GAS = 60000n;
78
+ /** 默认 Call Gas Limit(卖出时的保守值) */
79
+ export const DEFAULT_CALL_GAS_LIMIT_SELL = 450000n;
80
+ // ============================================================================
81
+ // 费率配置
82
+ // ============================================================================
83
+ /** XLayer Flap 买入手续费率 (1.5%) */
84
+ export const FLAP_BUY_FEE_RATE = 0.015;
85
+ /** XLayer Flap 卖出手续费率 (1.5%) */
86
+ export const FLAP_SELL_FEE_RATE = 0.015;
87
+ // ============================================================================
88
+ // ABI 定义
89
+ // ============================================================================
90
+ /** SimpleAccountFactory ABI */
91
+ export const FACTORY_ABI = [
92
+ 'function createAccount(address owner, uint256 salt) returns (address)',
93
+ 'function getAddress(address owner, uint256 salt) view returns (address)',
94
+ 'function accountImplementation() view returns (address)',
95
+ ];
96
+ /** EntryPoint v0.6 ABI */
97
+ export const ENTRYPOINT_ABI = [
98
+ 'function getNonce(address sender, uint192 key) view returns (uint256)',
99
+ 'function getUserOpHash((address sender,uint256 nonce,bytes initCode,bytes callData,uint256 callGasLimit,uint256 verificationGasLimit,uint256 preVerificationGas,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,bytes paymasterAndData,bytes signature) userOp) view returns (bytes32)',
100
+ 'function handleOps((address sender,uint256 nonce,bytes initCode,bytes callData,uint256 callGasLimit,uint256 verificationGasLimit,uint256 preVerificationGas,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,bytes paymasterAndData,bytes signature)[] ops, address payable beneficiary) external',
101
+ 'function depositTo(address account) public payable',
102
+ 'function balanceOf(address account) public view returns (uint256)',
103
+ 'event UserOperationEvent(bytes32 indexed userOpHash, address indexed sender, address indexed paymaster, uint256 nonce, bool success, uint256 actualGasCost, uint256 actualGasUsed)',
104
+ ];
105
+ /** SimpleAccount ABI */
106
+ export const SIMPLE_ACCOUNT_ABI = [
107
+ 'function execute(address dest, uint256 value, bytes func) external',
108
+ 'function executeBatch(address[] calldata dest, bytes[] calldata func) external',
109
+ 'function executeBatch(address[] calldata dest, uint256[] calldata values, bytes[] calldata func) external',
110
+ ];
111
+ /** Flap Portal ABI */
112
+ export const PORTAL_ABI = [
113
+ 'function swapExactInput((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData) params) payable returns (uint256)',
114
+ 'function buy(address token, address to, uint256 minAmount) external payable returns (uint256)',
115
+ 'function sell(address token, uint256 amount, uint256 minEth) external returns (uint256)',
116
+ 'function quoteExactInput((address inputToken,address outputToken,uint256 inputAmount)) external returns (uint256)',
117
+ 'function previewBuy(address token, uint256 ethAmount) external view returns (uint256)',
118
+ 'function previewSell(address token, uint256 tokenAmount) external view returns (uint256)',
119
+ 'function getTokenV5(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32))',
120
+ ];
121
+ /** ERC20 ABI */
122
+ export const ERC20_ABI = [
123
+ 'function balanceOf(address account) view returns (uint256)',
124
+ 'function allowance(address owner, address spender) view returns (uint256)',
125
+ 'function approve(address spender, uint256 amount) returns (bool)',
126
+ 'function transfer(address to, uint256 amount) returns (bool)',
127
+ 'function decimals() view returns (uint8)',
128
+ 'function symbol() view returns (string)',
129
+ 'function name() view returns (string)',
130
+ ];
131
+ /** PotatoSwap V2 Router ABI */
132
+ export const POTATOSWAP_V2_ROUTER_ABI = [
133
+ // 标准 swap 函数
134
+ 'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)',
135
+ 'function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)',
136
+ 'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)',
137
+ // SupportingFeeOnTransferTokens 版本(支持有手续费/分红的代币)
138
+ 'function swapExactETHForTokensSupportingFeeOnTransferTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable',
139
+ 'function swapExactTokensForETHSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external',
140
+ 'function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external',
141
+ // 查询函数
142
+ 'function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)',
143
+ 'function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts)',
144
+ 'function WETH() external pure returns (address)',
145
+ ];
@@ -0,0 +1,132 @@
1
+ /**
2
+ * XLayer 外盘交易 SDK
3
+ *
4
+ * 通过 PotatoSwap 进行外盘交易:
5
+ * - V2 Router 交易
6
+ * - 支持 OKB/Token 双向交换
7
+ * - 通过 AA 账户执行
8
+ */
9
+ import type { XLayerConfig, DexSwapResult } from './types.js';
10
+ /**
11
+ * 编码 swapExactETHForTokens 调用
12
+ */
13
+ export declare function encodeSwapExactETHForTokens(amountOutMin: bigint, path: string[], to: string, deadline: number): string;
14
+ /**
15
+ * 编码 swapExactETHForTokensSupportingFeeOnTransferTokens 调用
16
+ * 推荐使用:支持有手续费/分红机制的代币
17
+ */
18
+ export declare function encodeSwapExactETHForTokensSupportingFee(amountOutMin: bigint, path: string[], to: string, deadline: number): string;
19
+ /**
20
+ * 编码 swapExactTokensForETH 调用
21
+ */
22
+ export declare function encodeSwapExactTokensForETH(amountIn: bigint, amountOutMin: bigint, path: string[], to: string, deadline: number): string;
23
+ /**
24
+ * 编码 swapExactTokensForETHSupportingFeeOnTransferTokens 调用
25
+ * 推荐使用:支持有手续费/分红机制的代币
26
+ */
27
+ export declare function encodeSwapExactTokensForETHSupportingFee(amountIn: bigint, amountOutMin: bigint, path: string[], to: string, deadline: number): string;
28
+ /**
29
+ * 编码 swapExactTokensForTokens 调用
30
+ */
31
+ export declare function encodeSwapExactTokensForTokens(amountIn: bigint, amountOutMin: bigint, path: string[], to: string, deadline: number): string;
32
+ /**
33
+ * 编码 swapExactTokensForTokensSupportingFeeOnTransferTokens 调用
34
+ * 推荐使用:支持有手续费/分红机制的代币
35
+ */
36
+ export declare function encodeSwapExactTokensForTokensSupportingFee(amountIn: bigint, amountOutMin: bigint, path: string[], to: string, deadline: number): string;
37
+ export interface DexConfig extends XLayerConfig {
38
+ routerAddress?: string;
39
+ wokbAddress?: string;
40
+ deadlineMinutes?: number;
41
+ }
42
+ /**
43
+ * DEX 交易查询器
44
+ */
45
+ export declare class DexQuery {
46
+ private provider;
47
+ private router;
48
+ private routerAddress;
49
+ private wokb;
50
+ constructor(config?: DexConfig);
51
+ /**
52
+ * 获取交易路径的输出金额
53
+ */
54
+ getAmountsOut(amountIn: bigint, path: string[]): Promise<bigint[]>;
55
+ /**
56
+ * 获取交易路径的输入金额
57
+ */
58
+ getAmountsIn(amountOut: bigint, path: string[]): Promise<bigint[]>;
59
+ /**
60
+ * 获取 OKB -> Token 的预期输出
61
+ */
62
+ quoteOkbToToken(okbAmount: bigint, tokenAddress: string): Promise<bigint>;
63
+ /**
64
+ * 获取 Token -> OKB 的预期输出
65
+ */
66
+ quoteTokenToOkb(tokenAmount: bigint, tokenAddress: string): Promise<bigint>;
67
+ /**
68
+ * 获取 WOKB 地址
69
+ */
70
+ getWokbAddress(): string;
71
+ /**
72
+ * 获取 Router 地址
73
+ */
74
+ getRouterAddress(): string;
75
+ }
76
+ /**
77
+ * DEX 交易执行器
78
+ *
79
+ * 通过 AA 账户在 PotatoSwap 上进行交易
80
+ */
81
+ export declare class DexExecutor {
82
+ private aaManager;
83
+ private dexQuery;
84
+ private config;
85
+ private routerAddress;
86
+ private wokb;
87
+ private deadlineMinutes;
88
+ constructor(config?: DexConfig);
89
+ /**
90
+ * 获取 deadline 时间戳
91
+ */
92
+ private getDeadline;
93
+ /**
94
+ * OKB -> Token 交易(通过 EOA 直接执行)
95
+ * 使用 SupportingFeeOnTransferTokens 版本,支持有手续费/分红的代币
96
+ */
97
+ swapOkbForToken(privateKey: string, tokenAddress: string, okbAmount: bigint, minTokenAmount?: bigint): Promise<DexSwapResult>;
98
+ /**
99
+ * Token -> OKB 交易(通过 EOA 直接执行)
100
+ * 使用 SupportingFeeOnTransferTokens 版本,支持有手续费/分红的代币
101
+ */
102
+ swapTokenForOkb(privateKey: string, tokenAddress: string, tokenAmount: bigint, minOkbAmount?: bigint): Promise<DexSwapResult>;
103
+ /**
104
+ * 通过 AA 账户执行 OKB -> Token 交易
105
+ * 使用 SupportingFeeOnTransferTokens 版本,支持有手续费/分红的代币
106
+ */
107
+ swapOkbForTokenViaAA(privateKey: string, tokenAddress: string, okbAmount: bigint, minTokenAmount?: bigint): Promise<DexSwapResult>;
108
+ /**
109
+ * 通过 AA 账户执行 Token -> OKB 交易
110
+ */
111
+ swapTokenForOkbViaAA(privateKey: string, tokenAddress: string, tokenAmount: bigint, minOkbAmount?: bigint): Promise<DexSwapResult>;
112
+ /**
113
+ * 获取 DEX 查询器
114
+ */
115
+ getDexQuery(): DexQuery;
116
+ }
117
+ /**
118
+ * 创建 DEX 查询器
119
+ */
120
+ export declare function createDexQuery(config?: DexConfig): DexQuery;
121
+ /**
122
+ * 创建 DEX 执行器
123
+ */
124
+ export declare function createDexExecutor(config?: DexConfig): DexExecutor;
125
+ /**
126
+ * 快速获取 OKB -> Token 报价
127
+ */
128
+ export declare function quoteOkbToToken(okbAmount: bigint, tokenAddress: string, config?: DexConfig): Promise<bigint>;
129
+ /**
130
+ * 快速获取 Token -> OKB 报价
131
+ */
132
+ export declare function quoteTokenToOkb(tokenAmount: bigint, tokenAddress: string, config?: DexConfig): Promise<bigint>;