four-flap-meme-sdk 1.5.79 → 1.5.80
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.
- package/dist/flap/portal-bundle-merkle/encryption.d.ts +16 -0
- package/dist/flap/portal-bundle-merkle/encryption.js +146 -0
- package/dist/xlayer/aa-account.js +51 -43
- package/dist/xlayer/bundle.js +166 -131
- package/dist/xlayer/constants.d.ts +1 -1
- package/dist/xlayer/constants.js +2 -0
- package/dist/xlayer/index.d.ts +1 -1
- package/dist/xlayer/index.js +1 -1
- package/dist/xlayer/portal-ops.d.ts +13 -0
- package/dist/xlayer/portal-ops.js +24 -0
- package/dist/xlayer/types.d.ts +8 -0
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECDH + AES-GCM 加密工具(浏览器兼容)
|
|
3
|
+
* 用于将签名交易用服务器公钥加密
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 用服务器公钥加密签名交易(ECDH + AES-GCM)
|
|
7
|
+
*
|
|
8
|
+
* @param signedTransactions 签名后的交易数组
|
|
9
|
+
* @param publicKeyBase64 服务器提供的公钥(Base64 格式)
|
|
10
|
+
* @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
|
|
11
|
+
*/
|
|
12
|
+
export declare function encryptWithPublicKey(signedTransactions: string[], publicKeyBase64: string): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* 验证公钥格式(Base64)
|
|
15
|
+
*/
|
|
16
|
+
export declare function validatePublicKey(publicKeyBase64: string): boolean;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECDH + AES-GCM 加密工具(浏览器兼容)
|
|
3
|
+
* 用于将签名交易用服务器公钥加密
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 获取全局 crypto 对象(最简单直接的方式)
|
|
7
|
+
*/
|
|
8
|
+
function getCryptoAPI() {
|
|
9
|
+
// 尝试所有可能的全局对象,优先浏览器环境
|
|
10
|
+
const cryptoObj = (typeof window !== 'undefined' && window.crypto) ||
|
|
11
|
+
(typeof self !== 'undefined' && self.crypto) ||
|
|
12
|
+
(typeof global !== 'undefined' && global.crypto) ||
|
|
13
|
+
(typeof globalThis !== 'undefined' && globalThis.crypto);
|
|
14
|
+
if (!cryptoObj) {
|
|
15
|
+
const env = typeof window !== 'undefined' ? 'Browser' : 'Node.js';
|
|
16
|
+
const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
|
|
17
|
+
throw new Error(`❌ Crypto API 不可用。环境: ${env}, 协议: ${protocol}. ` +
|
|
18
|
+
'请确保在 HTTPS 或 localhost 下运行');
|
|
19
|
+
}
|
|
20
|
+
return cryptoObj;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 获取 SubtleCrypto(用于加密操作)
|
|
24
|
+
*/
|
|
25
|
+
function getSubtleCrypto() {
|
|
26
|
+
const crypto = getCryptoAPI();
|
|
27
|
+
if (!crypto.subtle) {
|
|
28
|
+
const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
|
|
29
|
+
const hostname = typeof location !== 'undefined' ? location.hostname : 'unknown';
|
|
30
|
+
throw new Error(`❌ SubtleCrypto API 不可用。协议: ${protocol}, 主机: ${hostname}. ` +
|
|
31
|
+
'请确保:1) 使用 HTTPS (或 localhost);2) 浏览器支持 Web Crypto API;' +
|
|
32
|
+
'3) 不在无痕/隐私浏览模式下');
|
|
33
|
+
}
|
|
34
|
+
return crypto.subtle;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Base64 转 ArrayBuffer(优先使用浏览器 API)
|
|
38
|
+
*/
|
|
39
|
+
function base64ToArrayBuffer(base64) {
|
|
40
|
+
// 浏览器环境(优先)
|
|
41
|
+
if (typeof atob !== 'undefined') {
|
|
42
|
+
const binaryString = atob(base64);
|
|
43
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
44
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
45
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
46
|
+
}
|
|
47
|
+
return bytes.buffer;
|
|
48
|
+
}
|
|
49
|
+
// Node.js 环境(fallback)
|
|
50
|
+
if (typeof Buffer !== 'undefined') {
|
|
51
|
+
return Buffer.from(base64, 'base64').buffer;
|
|
52
|
+
}
|
|
53
|
+
throw new Error('❌ Base64 解码不可用');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* ArrayBuffer 转 Base64(优先使用浏览器 API)
|
|
57
|
+
*/
|
|
58
|
+
function arrayBufferToBase64(buffer) {
|
|
59
|
+
// 浏览器环境(优先)
|
|
60
|
+
if (typeof btoa !== 'undefined') {
|
|
61
|
+
const bytes = new Uint8Array(buffer);
|
|
62
|
+
let binary = '';
|
|
63
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
64
|
+
binary += String.fromCharCode(bytes[i]);
|
|
65
|
+
}
|
|
66
|
+
return btoa(binary);
|
|
67
|
+
}
|
|
68
|
+
// Node.js 环境(fallback)
|
|
69
|
+
if (typeof Buffer !== 'undefined') {
|
|
70
|
+
return Buffer.from(buffer).toString('base64');
|
|
71
|
+
}
|
|
72
|
+
throw new Error('❌ Base64 编码不可用');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 生成随机 Hex 字符串
|
|
76
|
+
*/
|
|
77
|
+
function randomHex(length) {
|
|
78
|
+
const crypto = getCryptoAPI();
|
|
79
|
+
const array = new Uint8Array(length);
|
|
80
|
+
crypto.getRandomValues(array);
|
|
81
|
+
return Array.from(array)
|
|
82
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
83
|
+
.join('');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 用服务器公钥加密签名交易(ECDH + AES-GCM)
|
|
87
|
+
*
|
|
88
|
+
* @param signedTransactions 签名后的交易数组
|
|
89
|
+
* @param publicKeyBase64 服务器提供的公钥(Base64 格式)
|
|
90
|
+
* @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
|
|
91
|
+
*/
|
|
92
|
+
export async function encryptWithPublicKey(signedTransactions, publicKeyBase64) {
|
|
93
|
+
try {
|
|
94
|
+
// 0. 获取 SubtleCrypto 和 Crypto API
|
|
95
|
+
const subtle = getSubtleCrypto();
|
|
96
|
+
const crypto = getCryptoAPI();
|
|
97
|
+
// 1. 准备数据
|
|
98
|
+
const payload = {
|
|
99
|
+
signedTransactions,
|
|
100
|
+
timestamp: Date.now(),
|
|
101
|
+
nonce: randomHex(8)
|
|
102
|
+
};
|
|
103
|
+
const plaintext = JSON.stringify(payload);
|
|
104
|
+
// 2. 生成临时 ECDH 密钥对
|
|
105
|
+
const ephemeralKeyPair = await subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveKey']);
|
|
106
|
+
// 3. 导入服务器公钥
|
|
107
|
+
const publicKeyBuffer = base64ToArrayBuffer(publicKeyBase64);
|
|
108
|
+
const publicKey = await subtle.importKey('raw', publicKeyBuffer, { name: 'ECDH', namedCurve: 'P-256' }, false, []);
|
|
109
|
+
// 4. 派生共享密钥(AES-256)
|
|
110
|
+
const sharedKey = await subtle.deriveKey({ name: 'ECDH', public: publicKey }, ephemeralKeyPair.privateKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt']);
|
|
111
|
+
// 5. AES-GCM 加密
|
|
112
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
113
|
+
const encrypted = await subtle.encrypt({ name: 'AES-GCM', iv }, sharedKey, new TextEncoder().encode(plaintext));
|
|
114
|
+
// 6. 导出临时公钥
|
|
115
|
+
const ephemeralPublicKeyRaw = await subtle.exportKey('raw', ephemeralKeyPair.publicKey);
|
|
116
|
+
// 7. 返回加密包(JSON 格式)
|
|
117
|
+
return JSON.stringify({
|
|
118
|
+
e: arrayBufferToBase64(ephemeralPublicKeyRaw), // 临时公钥
|
|
119
|
+
i: arrayBufferToBase64(iv.buffer), // IV
|
|
120
|
+
d: arrayBufferToBase64(encrypted) // 密文
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new Error(`加密失败: ${error?.message || String(error)}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 验证公钥格式(Base64)
|
|
129
|
+
*/
|
|
130
|
+
export function validatePublicKey(publicKeyBase64) {
|
|
131
|
+
try {
|
|
132
|
+
if (!publicKeyBase64)
|
|
133
|
+
return false;
|
|
134
|
+
// Base64 字符集验证
|
|
135
|
+
if (!/^[A-Za-z0-9+/=]+$/.test(publicKeyBase64))
|
|
136
|
+
return false;
|
|
137
|
+
// ECDH P-256 公钥固定长度 65 字节(未压缩)
|
|
138
|
+
// Base64 编码后约 88 字符
|
|
139
|
+
if (publicKeyBase64.length < 80 || publicKeyBase64.length > 100)
|
|
140
|
+
return false;
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -637,54 +637,31 @@ export class AAAccountManager {
|
|
|
637
637
|
return [];
|
|
638
638
|
// 1) 批量预测 sender(优先 getAddress+multicall,失败回退 createAccount.staticCall)
|
|
639
639
|
const senders = await this.predictSendersByOwnersFast(owners);
|
|
640
|
-
// 2) 批量 getNonce
|
|
640
|
+
// 2) 批量 getNonce(multicall EntryPoint.getNonce)
|
|
641
641
|
const epIface = new Interface(ENTRYPOINT_ABI);
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
},
|
|
648
|
-
{
|
|
649
|
-
target: MULTICALL3,
|
|
650
|
-
allowFailure: true,
|
|
651
|
-
callData: '0x4d2301cc' + sender.slice(2).padStart(64, '0'), // getEthBalance(address)
|
|
652
|
-
},
|
|
653
|
-
]);
|
|
642
|
+
const nonceCalls = senders.map((sender) => ({
|
|
643
|
+
target: this.entryPointAddress,
|
|
644
|
+
allowFailure: true,
|
|
645
|
+
callData: epIface.encodeFunctionData('getNonce', [sender, 0]),
|
|
646
|
+
}));
|
|
654
647
|
const nonces = new Array(senders.length).fill(0n);
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
if (nonceRes?.success && nonceRes.returnData && nonceRes.returnData !== '0x') {
|
|
668
|
-
try {
|
|
669
|
-
const decoded = epIface.decodeFunctionResult('getNonce', nonceRes.returnData);
|
|
670
|
-
nonces[idx] = BigInt(decoded?.[0] ?? 0n);
|
|
671
|
-
}
|
|
672
|
-
catch { /* ignore */ }
|
|
673
|
-
}
|
|
674
|
-
// 解析 Balance
|
|
675
|
-
if (balanceRes?.success && balanceRes.returnData && balanceRes.returnData !== '0x') {
|
|
676
|
-
try {
|
|
677
|
-
balances[idx] = BigInt(balanceRes.returnData);
|
|
678
|
-
}
|
|
679
|
-
catch { /* ignore */ }
|
|
680
|
-
}
|
|
648
|
+
const BATCH = 350;
|
|
649
|
+
for (let cursor = 0; cursor < nonceCalls.length; cursor += BATCH) {
|
|
650
|
+
const sliceCalls = nonceCalls.slice(cursor, cursor + BATCH);
|
|
651
|
+
const res = await this.multicallAggregate3({ calls: sliceCalls });
|
|
652
|
+
for (let i = 0; i < res.length; i++) {
|
|
653
|
+
const r = res[i];
|
|
654
|
+
const idx = cursor + i;
|
|
655
|
+
if (!r?.success || !r.returnData || r.returnData === '0x')
|
|
656
|
+
continue;
|
|
657
|
+
try {
|
|
658
|
+
const decoded = epIface.decodeFunctionResult('getNonce', r.returnData);
|
|
659
|
+
nonces[idx] = BigInt(decoded?.[0] ?? 0n);
|
|
681
660
|
}
|
|
682
|
-
|
|
683
|
-
catch (err) {
|
|
684
|
-
console.warn(`[getMultipleAccountInfo] Multicall 失败,回退后续 logic 会处理缺失值:`, err);
|
|
661
|
+
catch { /* ignore */ }
|
|
685
662
|
}
|
|
686
663
|
}
|
|
687
|
-
// 3) deployed(getCode):小分片 + 并发上限 + 缓存 deployed=true
|
|
664
|
+
// 3) deployed(getCode):小分片 + 并发上限 + 缓存 deployed=true,避免 -32014 “batch request too many”
|
|
688
665
|
const deployed = new Array(senders.length).fill(false);
|
|
689
666
|
const needCode = [];
|
|
690
667
|
for (let i = 0; i < senders.length; i++) {
|
|
@@ -736,6 +713,37 @@ export class AAAccountManager {
|
|
|
736
713
|
}
|
|
737
714
|
}
|
|
738
715
|
}
|
|
716
|
+
// 4) balance(getEthBalance):用 Multicall3.getEthBalance 分片批量查询 OKB(减少 N 次 eth_getBalance)
|
|
717
|
+
const balances = new Array(senders.length).fill(0n);
|
|
718
|
+
const ethBalIface = new Interface(['function getEthBalance(address addr) view returns (uint256)']);
|
|
719
|
+
const balCalls = senders.map((sender) => ({
|
|
720
|
+
target: MULTICALL3,
|
|
721
|
+
allowFailure: true,
|
|
722
|
+
callData: ethBalIface.encodeFunctionData('getEthBalance', [sender]),
|
|
723
|
+
}));
|
|
724
|
+
const BAL_BATCH = 300;
|
|
725
|
+
try {
|
|
726
|
+
for (let cursor = 0; cursor < balCalls.length; cursor += BAL_BATCH) {
|
|
727
|
+
const sliceCalls = balCalls.slice(cursor, cursor + BAL_BATCH);
|
|
728
|
+
const res = await this.multicallAggregate3({ calls: sliceCalls });
|
|
729
|
+
for (let i = 0; i < res.length; i++) {
|
|
730
|
+
const r = res[i];
|
|
731
|
+
const idx = cursor + i;
|
|
732
|
+
if (!r?.success || !r.returnData || r.returnData === '0x')
|
|
733
|
+
continue;
|
|
734
|
+
try {
|
|
735
|
+
const decoded = ethBalIface.decodeFunctionResult('getEthBalance', r.returnData);
|
|
736
|
+
balances[idx] = BigInt(decoded?.[0] ?? 0n);
|
|
737
|
+
}
|
|
738
|
+
catch { /* ignore */ }
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
catch {
|
|
743
|
+
const fetched = await mapWithConcurrency(senders, 6, async (s) => await this.provider.getBalance(s));
|
|
744
|
+
for (let i = 0; i < fetched.length; i++)
|
|
745
|
+
balances[i] = fetched[i] ?? 0n;
|
|
746
|
+
}
|
|
739
747
|
return owners.map((owner, i) => ({
|
|
740
748
|
owner,
|
|
741
749
|
sender: senders[i],
|
package/dist/xlayer/bundle.js
CHANGED
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
import { Wallet, Interface, Contract, ethers } from 'ethers';
|
|
11
11
|
import { FLAP_PORTAL, ENTRYPOINT_ABI, PORTAL_ABI, DEFAULT_CALL_GAS_LIMIT_SELL, DEFAULT_WITHDRAW_RESERVE, WOKB, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, } from './constants.js';
|
|
12
12
|
import { AAAccountManager, encodeExecute, encodeExecuteBatch, createWallet } from './aa-account.js';
|
|
13
|
-
import { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, encodeCreateCallV2, encodeCreateCallV3, encodeCreateCallV4, PortalQuery, parseOkb, formatOkb, lpFeeProfileToV3Fee, } from './portal-ops.js';
|
|
13
|
+
import { encodeBuyCall, encodeBuyCallV3, encodeSellCall, encodeApproveCall, encodeTransferCall, encodeCreateCallV2, encodeCreateCallV3, encodeCreateCallV4, PortalQuery, parseOkb, formatOkb, lpFeeProfileToV3Fee, } from './portal-ops.js';
|
|
14
14
|
import { mapWithConcurrency } from '../utils/concurrency.js';
|
|
15
15
|
import { PROFIT_CONFIG, ZERO_ADDRESS } from '../utils/constants.js';
|
|
16
|
-
import { DexQuery
|
|
16
|
+
import { DexQuery } from './dex.js';
|
|
17
|
+
import { encodeSwapExactETHForTokensSupportingFee, encodeSwapExactETHForTokensV3, } from './dex.js';
|
|
17
18
|
// ============================================================================
|
|
18
19
|
// AA Nonce(EntryPoint nonce)本地分配器
|
|
19
20
|
// ============================================================================
|
|
@@ -1469,6 +1470,11 @@ export class BundleExecutor {
|
|
|
1469
1470
|
// ✅ 并行构建和签名所有外盘买入 UserOps
|
|
1470
1471
|
const signedDexBuyOps = await mapWithConcurrency(dexBuyData, 5, async (data) => {
|
|
1471
1472
|
const { wallet, info, buyWei } = data;
|
|
1473
|
+
// ✅ 外盘买入:使用 Portal 的 swapExactInput 进行自动路由
|
|
1474
|
+
// 优势:Portal 会自动识别代币的池子类型(V2/V3),无需手动指定
|
|
1475
|
+
// 参考 BSC 版本的逻辑(create-to-dex.ts:604-616)
|
|
1476
|
+
// const buyData = encodeBuyCall(tokenAddress, buyWei, 0n);
|
|
1477
|
+
// const dexBuyCallData = encodeExecute(FLAP_PORTAL, buyWei, buyData);
|
|
1472
1478
|
let swapData;
|
|
1473
1479
|
let routerAddress;
|
|
1474
1480
|
if (dexType === 'V3') {
|
|
@@ -1551,7 +1557,9 @@ export class BundleExecutor {
|
|
|
1551
1557
|
* 自动计算剩余毕业容量,将钱包分为内盘和外盘组,生成签名的交易列表
|
|
1552
1558
|
*/
|
|
1553
1559
|
async bundleGraduateBuy(params) {
|
|
1554
|
-
const { tokenAddress, privateKeys, payerPrivateKey, amountMode, totalBuyAmount, minAmount, maxAmount, walletAmounts, enableDexBuy = false,
|
|
1560
|
+
const { tokenAddress, privateKeys, payerPrivateKey, amountMode, totalBuyAmount, minAmount, maxAmount, walletAmounts, enableDexBuy = false,
|
|
1561
|
+
// ✅ 新增:前端传递的分组信息
|
|
1562
|
+
curveAddresses, dexAddresses, graduationAmount, config = {} } = params;
|
|
1555
1563
|
const aaManager = this.getAAManager();
|
|
1556
1564
|
const provider = aaManager.getProvider();
|
|
1557
1565
|
// 1. 获取代币状态,动态计算毕业容量
|
|
@@ -1565,12 +1573,17 @@ export class BundleExecutor {
|
|
|
1565
1573
|
const graduationReserveWei = h * k / (10n ** 18n);
|
|
1566
1574
|
const graduationReserve = ethers.formatEther(graduationReserveWei);
|
|
1567
1575
|
const poolReserveOkb = ethers.formatEther(tokenState.reserve);
|
|
1568
|
-
|
|
1576
|
+
// // ✅ 优先使用前端传递的动态毕业阈值
|
|
1577
|
+
const graduateCapacity = graduationAmount ?? 73.38;
|
|
1578
|
+
const remainingToGraduate = Math.max(0, graduateCapacity - parseFloat(poolReserveOkb));
|
|
1579
|
+
// const graduateCapacity = parseFloat(graduationReserve);
|
|
1569
1580
|
// 剩余毕业金额 = 毕业阈值 - 当前储备(加 0.5% 手续费缓冲)
|
|
1570
1581
|
const remaining = Math.max(0, graduateCapacity - parseFloat(poolReserveOkb));
|
|
1571
1582
|
const remainingWithFee = remaining * 1.005; // 0.5% 手续费缓冲
|
|
1572
|
-
const remainingToGraduate = remainingWithFee;
|
|
1583
|
+
// const remainingToGraduate = remainingWithFee;
|
|
1573
1584
|
const remainingToGraduateWei = ethers.parseEther(remainingToGraduate.toFixed(18));
|
|
1585
|
+
//
|
|
1586
|
+
// console.log(`[GraduateBuy] Pool Reserve: ${poolReserveOkb} OKB, GraduateCapacity: ${graduateCapacity} OKB, Remaining: ${remainingToGraduate} OKB`);
|
|
1574
1587
|
console.log(`[GraduateBuy] Pool Reserve: ${poolReserveOkb} OKB, Graduation: ${graduationReserve} OKB, Remaining: ${remainingToGraduate.toFixed(4)} OKB`);
|
|
1575
1588
|
// 2. 准备钱包
|
|
1576
1589
|
const sharedProvider = this.aaManager.getProvider();
|
|
@@ -1579,7 +1592,21 @@ export class BundleExecutor {
|
|
|
1579
1592
|
const payerAccount = await aaManager.getAccountInfo(payerWallet.address);
|
|
1580
1593
|
const nonceMap = new AANonceMap();
|
|
1581
1594
|
nonceMap.init(payerAccount.sender, payerAccount.nonce);
|
|
1595
|
+
// ✅ 预获取所有钱包的 Sender 地址,用于双重地址匹配
|
|
1596
|
+
// 前端可能传递 Sender 地址(AA 模式下 wallet.address 被切换为 Sender)
|
|
1597
|
+
const walletInfos = await mapWithConcurrency(wallets, 5, async (w) => {
|
|
1598
|
+
const info = await aaManager.getAccountInfo(w.address);
|
|
1599
|
+
return { owner: w.address.toLowerCase(), sender: info.sender.toLowerCase() };
|
|
1600
|
+
});
|
|
1601
|
+
// 建立 Owner->Sender 映射,用于后续匹配
|
|
1602
|
+
const ownerToSender = new Map();
|
|
1603
|
+
const senderToOwner = new Map();
|
|
1604
|
+
for (const info of walletInfos) {
|
|
1605
|
+
ownerToSender.set(info.owner, info.sender);
|
|
1606
|
+
senderToOwner.set(info.sender, info.owner);
|
|
1607
|
+
}
|
|
1582
1608
|
// 3. 计算每个钱包的金额
|
|
1609
|
+
// ✅ 修复:同时支持 Owner 和 Sender 地址匹配
|
|
1583
1610
|
let finalAmounts = [];
|
|
1584
1611
|
if (amountMode === 'average') {
|
|
1585
1612
|
const avg = (totalBuyAmount || 0) / wallets.length;
|
|
@@ -1594,148 +1621,159 @@ export class BundleExecutor {
|
|
|
1594
1621
|
});
|
|
1595
1622
|
}
|
|
1596
1623
|
else if (amountMode === 'custom') {
|
|
1597
|
-
finalAmounts = wallets.map(w =>
|
|
1624
|
+
finalAmounts = wallets.map(w => {
|
|
1625
|
+
const ownerAddr = w.address.toLowerCase();
|
|
1626
|
+
const senderAddr = ownerToSender.get(ownerAddr) || '';
|
|
1627
|
+
// ✅ 双重匹配:先按 Owner 地址查找,再按 Sender 地址查找
|
|
1628
|
+
return walletAmounts?.[w.address] ||
|
|
1629
|
+
walletAmounts?.[w.address.toLowerCase()] ||
|
|
1630
|
+
walletAmounts?.[senderAddr] ||
|
|
1631
|
+
(senderAddr ? (walletAmounts?.[senderAddr.toLowerCase()] || 0) : 0);
|
|
1632
|
+
});
|
|
1598
1633
|
}
|
|
1599
|
-
// 4.
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1634
|
+
// 4. 钱包分组
|
|
1635
|
+
const curveBuyers = [];
|
|
1636
|
+
const dexBuyers = [];
|
|
1637
|
+
// ✅ 优先使用前端传递的分组信息
|
|
1638
|
+
const hasFrontendGrouping = curveAddresses && curveAddresses.length > 0;
|
|
1639
|
+
if (hasFrontendGrouping) {
|
|
1640
|
+
// ✅ 使用前端计算好的分组,不再重新计算
|
|
1641
|
+
const curveSet = new Set(curveAddresses.map(a => a.toLowerCase()));
|
|
1642
|
+
const dexSet = dexAddresses ? new Set(dexAddresses.map(a => a.toLowerCase())) : new Set();
|
|
1643
|
+
console.log(`[GraduateBuy] Using frontend grouping: ${curveAddresses.length} curve, ${dexAddresses?.length || 0} dex`);
|
|
1644
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
1645
|
+
const wallet = wallets[i];
|
|
1646
|
+
const ownerAddr = wallet.address.toLowerCase();
|
|
1647
|
+
const senderAddr = ownerToSender.get(ownerAddr) || '';
|
|
1648
|
+
const amountWei = ethers.parseEther(finalAmounts[i].toFixed(18));
|
|
1649
|
+
// ✅ 双重匹配:同时检查 Owner 和 Sender 地址
|
|
1650
|
+
const isInCurve = curveSet.has(ownerAddr) || curveSet.has(senderAddr);
|
|
1651
|
+
const isInDex = dexSet.has(ownerAddr) || dexSet.has(senderAddr);
|
|
1652
|
+
if (isInCurve) {
|
|
1653
|
+
curveBuyers.push({ wallet, amount: amountWei });
|
|
1619
1654
|
}
|
|
1620
|
-
else {
|
|
1621
|
-
|
|
1622
|
-
tasks.push({
|
|
1623
|
-
target: FLAP_PORTAL,
|
|
1624
|
-
amount: needed,
|
|
1625
|
-
data: encodeBuyCall(tokenAddress, needed, 0n)
|
|
1626
|
-
});
|
|
1627
|
-
isTrigger = true; // 肯定是毕业触发者
|
|
1628
|
-
currentCurveTotal = remainingToGraduateWei;
|
|
1629
|
-
if (enableDexBuy) {
|
|
1630
|
-
const excess = amountWei - needed;
|
|
1631
|
-
const dexType = (tokenState.lpFeeProfile >= 0 && tokenState.tokenVersion >= 4) ? 'V3' : 'V2';
|
|
1632
|
-
const deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
1633
|
-
let swapData;
|
|
1634
|
-
let routerAddress;
|
|
1635
|
-
if (dexType === 'V3') {
|
|
1636
|
-
routerAddress = POTATOSWAP_V3_ROUTER;
|
|
1637
|
-
swapData = encodeSwapExactETHForTokensV3({
|
|
1638
|
-
tokenIn: WOKB, tokenOut: tokenAddress,
|
|
1639
|
-
fee: lpFeeProfileToV3Fee(tokenState.lpFeeProfile),
|
|
1640
|
-
recipient: ZERO_ADDRESS, // AA 内部 call,最终由 execute/executeBatch 决定 recipient
|
|
1641
|
-
deadline, amountIn: excess, amountOutMinimum: 0n, sqrtPriceLimitX96: 0n
|
|
1642
|
-
});
|
|
1643
|
-
}
|
|
1644
|
-
else {
|
|
1645
|
-
routerAddress = POTATOSWAP_V2_ROUTER;
|
|
1646
|
-
swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], ZERO_ADDRESS, deadline);
|
|
1647
|
-
}
|
|
1648
|
-
tasks.push({ target: routerAddress, amount: excess, data: swapData });
|
|
1649
|
-
}
|
|
1655
|
+
else if (isInDex && enableDexBuy) {
|
|
1656
|
+
dexBuyers.push({ wallet, amount: amountWei });
|
|
1650
1657
|
}
|
|
1658
|
+
// 如果钱包既不在 curveSet 也不在 dexSet,则跳过
|
|
1651
1659
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
}
|
|
1660
|
+
}
|
|
1661
|
+
else {
|
|
1662
|
+
// ✅ 原逻辑:SDK 自动分组(可能与前端不一致)
|
|
1663
|
+
console.log(`[GraduateBuy] No frontend grouping, using auto-split by remainingToGraduate=${remainingToGraduate} OKB`);
|
|
1664
|
+
let currentCurveTotal = 0n;
|
|
1665
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
1666
|
+
const wallet = wallets[i];
|
|
1667
|
+
const amountWei = ethers.parseEther(finalAmounts[i].toFixed(18));
|
|
1668
|
+
if (currentCurveTotal < remainingToGraduateWei) {
|
|
1669
|
+
const needed = remainingToGraduateWei - currentCurveTotal;
|
|
1670
|
+
if (amountWei <= needed) {
|
|
1671
|
+
curveBuyers.push({ wallet, amount: amountWei });
|
|
1672
|
+
currentCurveTotal += amountWei;
|
|
1673
|
+
}
|
|
1674
|
+
else {
|
|
1675
|
+
// 当前钱包金额超过了剩余容量,将其限制为 needed
|
|
1676
|
+
curveBuyers.push({ wallet, amount: needed });
|
|
1677
|
+
currentCurveTotal = remainingToGraduateWei;
|
|
1678
|
+
// 超出部分暂不处理(遵循单钱包单属性逻辑)
|
|
1679
|
+
}
|
|
1666
1680
|
}
|
|
1667
|
-
else {
|
|
1668
|
-
|
|
1669
|
-
swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], ZERO_ADDRESS, deadline);
|
|
1681
|
+
else if (enableDexBuy) {
|
|
1682
|
+
dexBuyers.push({ wallet, amount: amountWei });
|
|
1670
1683
|
}
|
|
1671
|
-
tasks.push({ target: routerAddress, amount: amountWei, data: swapData });
|
|
1672
|
-
}
|
|
1673
|
-
if (tasks.length > 0) {
|
|
1674
|
-
buyerTasks.push({ wallet, calls: tasks, isGraduationTrigger: isTrigger });
|
|
1675
1684
|
}
|
|
1676
1685
|
}
|
|
1686
|
+
// ✅ 统一计算内盘买入总金额(无论使用哪种分组方式)
|
|
1687
|
+
const curveTotalWei = curveBuyers.reduce((sum, b) => sum + b.amount, 0n);
|
|
1677
1688
|
// 5. 构建 UserOps
|
|
1678
1689
|
const effConfig = { ...(this.config ?? {}), ...(config ?? {}) };
|
|
1690
|
+
const signedTransactions = [];
|
|
1679
1691
|
const allOps = [];
|
|
1680
|
-
//
|
|
1681
|
-
const
|
|
1692
|
+
// --- 内盘 Ops ---
|
|
1693
|
+
const curveBuyerInfos = await mapWithConcurrency(curveBuyers.map(b => b.wallet), 5, async (w) => {
|
|
1682
1694
|
const info = await aaManager.getAccountInfo(w.address);
|
|
1683
1695
|
nonceMap.init(info.sender, info.nonce);
|
|
1684
1696
|
return info;
|
|
1685
1697
|
});
|
|
1686
|
-
const
|
|
1687
|
-
const { wallet,
|
|
1688
|
-
const info =
|
|
1689
|
-
//
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
// 为了绝对安全,我们在此时重新编码带有正确 sender 的 swapData
|
|
1697
|
-
if (c.target === POTATOSWAP_V3_ROUTER || c.target === POTATOSWAP_V2_ROUTER) {
|
|
1698
|
-
const dexType = (tokenState.lpFeeProfile >= 0 && tokenState.tokenVersion >= 4) ? 'V3' : 'V2';
|
|
1699
|
-
const deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
1700
|
-
if (dexType === 'V3') {
|
|
1701
|
-
callData = encodeSwapExactETHForTokensV3({
|
|
1702
|
-
tokenIn: WOKB, tokenOut: tokenAddress,
|
|
1703
|
-
fee: lpFeeProfileToV3Fee(tokenState.lpFeeProfile),
|
|
1704
|
-
recipient: info.sender,
|
|
1705
|
-
deadline, amountIn: c.amount, amountOutMinimum: 0n, sqrtPriceLimitX96: 0n
|
|
1706
|
-
});
|
|
1707
|
-
}
|
|
1708
|
-
else {
|
|
1709
|
-
callData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], info.sender, deadline);
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
return { ...c, data: callData };
|
|
1713
|
-
});
|
|
1714
|
-
let mainCallData;
|
|
1715
|
-
if (finalCalls.length === 1) {
|
|
1716
|
-
mainCallData = encodeExecute(finalCalls[0].target, finalCalls[0].amount, finalCalls[0].data);
|
|
1717
|
-
}
|
|
1718
|
-
else {
|
|
1719
|
-
mainCallData = encodeExecuteBatch(finalCalls.map(c => c.target), finalCalls.map(c => c.amount), finalCalls.map(c => c.data));
|
|
1720
|
-
}
|
|
1698
|
+
const signedCurveBuyOps = await mapWithConcurrency(curveBuyers, 5, async (data, i) => {
|
|
1699
|
+
const { wallet, amount } = data;
|
|
1700
|
+
const info = curveBuyerInfos[i];
|
|
1701
|
+
// ✅ 使用 swapExactInputV3(支持 extensionData),与 BSC 版本保持一致
|
|
1702
|
+
// 参考 create-to-dex.ts 第 604-616 行
|
|
1703
|
+
const extensionData = params.extensionData ?? '0x';
|
|
1704
|
+
const buyData = encodeBuyCallV3(tokenAddress, amount, 0n, extensionData);
|
|
1705
|
+
const buyCallData = encodeExecute(FLAP_PORTAL, amount, buyData);
|
|
1706
|
+
// ✅ 判断是否是最后一笔内盘买入(触发毕业的那笔)
|
|
1707
|
+
const isGraduationTrigger = (i === curveBuyers.length - 1);
|
|
1721
1708
|
const callGasLimit = isGraduationTrigger
|
|
1722
|
-
?
|
|
1723
|
-
: (effConfig.fixedGas?.callGasLimit ??
|
|
1724
|
-
const
|
|
1709
|
+
? 8000000n // 毕业触发交易需要更高 gas
|
|
1710
|
+
: (effConfig.fixedGas?.callGasLimit ?? 600000n); // 其他买入使用前端配置或默认值
|
|
1711
|
+
const buyOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1725
1712
|
ownerWallet: wallet,
|
|
1726
1713
|
sender: info.sender,
|
|
1727
|
-
callData:
|
|
1714
|
+
callData: buyCallData,
|
|
1728
1715
|
nonce: nonceMap.next(info.sender),
|
|
1729
1716
|
initCode: info.deployed ? '0x' : (await aaManager.generateInitCode(wallet.address)),
|
|
1730
1717
|
deployed: info.deployed,
|
|
1731
1718
|
fixedGas: { callGasLimit }
|
|
1732
1719
|
});
|
|
1733
|
-
const
|
|
1734
|
-
return
|
|
1720
|
+
const signedBuyOp = await aaManager.signUserOp(buyOpRes.userOp, wallet);
|
|
1721
|
+
return signedBuyOp.userOp;
|
|
1735
1722
|
});
|
|
1736
|
-
allOps.push(...
|
|
1723
|
+
allOps.push(...signedCurveBuyOps);
|
|
1724
|
+
// --- 外盘 Ops ---
|
|
1725
|
+
let totalDexBuyWei = 0n;
|
|
1726
|
+
if (enableDexBuy && dexBuyers.length > 0) {
|
|
1727
|
+
// ✅ 定义外盘买入所需的变量(参考 bundleCreateToDexSign 第 1860-1861 行)
|
|
1728
|
+
const deadline = Math.floor(Date.now() / 1000) + 1200; // 20 min
|
|
1729
|
+
const dexType = (tokenState.lpFeeProfile !== undefined && tokenState.lpFeeProfile >= 0) ? 'V3' : 'V2';
|
|
1730
|
+
const dexBuyerInfos = await mapWithConcurrency(dexBuyers.map(b => b.wallet), 5, async (w) => {
|
|
1731
|
+
const info = await aaManager.getAccountInfo(w.address);
|
|
1732
|
+
nonceMap.init(info.sender, info.nonce);
|
|
1733
|
+
return info;
|
|
1734
|
+
});
|
|
1735
|
+
const signedDexBuyOps = await mapWithConcurrency(dexBuyers, 5, async (data, i) => {
|
|
1736
|
+
const { wallet, amount } = data;
|
|
1737
|
+
const info = dexBuyerInfos[i];
|
|
1738
|
+
totalDexBuyWei += amount;
|
|
1739
|
+
// ✅ 外盘买入:直接调用 DEX Router 进行 swap
|
|
1740
|
+
// 代币毕业后无法通过 Portal 买入(会报 0xe2fae90a 错误),必须走 DEX
|
|
1741
|
+
// 参考 BSC 版本 create-to-dex.ts 第 655-752 行
|
|
1742
|
+
let swapData;
|
|
1743
|
+
let routerAddress;
|
|
1744
|
+
if (dexType === 'V3') {
|
|
1745
|
+
routerAddress = POTATOSWAP_V3_ROUTER;
|
|
1746
|
+
swapData = encodeSwapExactETHForTokensV3({
|
|
1747
|
+
tokenIn: WOKB,
|
|
1748
|
+
tokenOut: tokenAddress,
|
|
1749
|
+
fee: lpFeeProfileToV3Fee(tokenState.lpFeeProfile),
|
|
1750
|
+
recipient: info.sender,
|
|
1751
|
+
deadline,
|
|
1752
|
+
amountIn: amount,
|
|
1753
|
+
amountOutMinimum: 0n,
|
|
1754
|
+
sqrtPriceLimitX96: 0n
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
else {
|
|
1758
|
+
routerAddress = POTATOSWAP_V2_ROUTER;
|
|
1759
|
+
swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], info.sender, deadline);
|
|
1760
|
+
}
|
|
1761
|
+
const dexBuyCallData = encodeExecute(routerAddress, amount, swapData);
|
|
1762
|
+
const dexBuyOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1763
|
+
ownerWallet: wallet,
|
|
1764
|
+
sender: info.sender,
|
|
1765
|
+
callData: dexBuyCallData,
|
|
1766
|
+
nonce: nonceMap.next(info.sender),
|
|
1767
|
+
initCode: info.deployed ? '0x' : (await aaManager.generateInitCode(wallet.address)),
|
|
1768
|
+
deployed: info.deployed,
|
|
1769
|
+
fixedGas: { callGasLimit: effConfig.fixedGas?.callGasLimit ?? 800000n } // 外盘 swap 需要更多 gas
|
|
1770
|
+
});
|
|
1771
|
+
const signedDexBuyOp = await aaManager.signUserOp(dexBuyOpRes.userOp, wallet);
|
|
1772
|
+
return signedDexBuyOp.userOp;
|
|
1773
|
+
});
|
|
1774
|
+
allOps.push(...signedDexBuyOps);
|
|
1775
|
+
}
|
|
1737
1776
|
// 6. 签名唯一的 handleOps 交易
|
|
1738
|
-
const signedTransactions = [];
|
|
1739
1777
|
const startNonce = params.payerStartNonce ?? (await provider.getTransactionCount(payerWallet.address, 'pending'));
|
|
1740
1778
|
const signedMainTx = await this.signHandleOpsTx({
|
|
1741
1779
|
ops: allOps,
|
|
@@ -1746,12 +1784,9 @@ export class BundleExecutor {
|
|
|
1746
1784
|
gasPrice: effConfig.minGasPriceGwei ? ethers.parseUnits(effConfig.minGasPriceGwei.toString(), 'gwei') : undefined
|
|
1747
1785
|
});
|
|
1748
1786
|
signedTransactions.push(signedMainTx);
|
|
1749
|
-
// 7.
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
totalDexBuyWei += c.amount; }));
|
|
1753
|
-
const totalBuyWei = currentCurveTotal + totalDexBuyWei;
|
|
1754
|
-
const profitWei = (totalBuyWei * 4n) / 1000n;
|
|
1787
|
+
// 7. 计算并签利润提取交易 (EOA 转账,千分之 4)
|
|
1788
|
+
const totalBuyWei = curveTotalWei + totalDexBuyWei;
|
|
1789
|
+
const profitWei = (totalBuyWei * 4n) / 1000n; // 0.4%
|
|
1755
1790
|
if (profitWei > 0n) {
|
|
1756
1791
|
const profitRecipient = effConfig.profitRecipient || PROFIT_CONFIG.RECIPIENT;
|
|
1757
1792
|
const feeData = await provider.getFeeData();
|
|
@@ -1770,9 +1805,9 @@ export class BundleExecutor {
|
|
|
1770
1805
|
return {
|
|
1771
1806
|
signedTransactions,
|
|
1772
1807
|
metadata: {
|
|
1773
|
-
curveCount:
|
|
1774
|
-
dexCount:
|
|
1775
|
-
curveTotalAmount: ethers.formatEther(
|
|
1808
|
+
curveCount: curveBuyers.length,
|
|
1809
|
+
dexCount: dexBuyers.length,
|
|
1810
|
+
curveTotalAmount: ethers.formatEther(curveTotalWei),
|
|
1776
1811
|
dexTotalAmount: ethers.formatEther(totalDexBuyWei),
|
|
1777
1812
|
tokenAddress
|
|
1778
1813
|
}
|
|
@@ -69,7 +69,7 @@ export declare const ENTRYPOINT_ABI: readonly ["function getNonce(address sender
|
|
|
69
69
|
/** SimpleAccount ABI */
|
|
70
70
|
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"];
|
|
71
71
|
/** Flap Portal ABI */
|
|
72
|
-
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))", "function getTokenV7(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32,uint8,uint8))", "function newTokenV2((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData) params) external payable returns (address)", "function newTokenV3((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData) params) external payable returns (address)", "function newTokenV4((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData,uint8 dexId,uint8 lpFeeProfile) params) external payable returns (address)"];
|
|
72
|
+
export declare const PORTAL_ABI: readonly ["function swapExactInput((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData) params) payable returns (uint256)", "function swapExactInputV3((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData,bytes extensionData)) external 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))", "function getTokenV7(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32,uint8,uint8))", "function newTokenV2((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData) params) external payable returns (address)", "function newTokenV3((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData) params) external payable returns (address)", "function newTokenV4((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData,uint8 dexId,uint8 lpFeeProfile) params) external payable returns (address)"];
|
|
73
73
|
/** ERC20 ABI */
|
|
74
74
|
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)"];
|
|
75
75
|
/** PotatoSwap V2 Router ABI */
|
package/dist/xlayer/constants.js
CHANGED
|
@@ -107,6 +107,8 @@ export const SIMPLE_ACCOUNT_ABI = [
|
|
|
107
107
|
/** Flap Portal ABI */
|
|
108
108
|
export const PORTAL_ABI = [
|
|
109
109
|
'function swapExactInput((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData) params) payable returns (uint256)',
|
|
110
|
+
// ✅ swapExactInputV3: 支持 extensionData 扩展,用于买到毕业等场景
|
|
111
|
+
'function swapExactInputV3((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData,bytes extensionData)) external payable returns (uint256)',
|
|
110
112
|
'function buy(address token, address to, uint256 minAmount) external payable returns (uint256)',
|
|
111
113
|
'function sell(address token, uint256 amount, uint256 minEth) external returns (uint256)',
|
|
112
114
|
'function quoteExactInput((address inputToken,address outputToken,uint256 inputAmount)) external returns (uint256)',
|
package/dist/xlayer/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export * from './types.js';
|
|
|
61
61
|
import type { BundleSwapSignParams, BundleSwapSignResult, BundleBatchSwapSignParams, BundleBatchSwapSignResult } from './types.js';
|
|
62
62
|
export { BundlerClient, createBundlerClient, type BundlerConfig, type BundlerReceipt, } from './bundler.js';
|
|
63
63
|
export { AAAccountManager, createAAAccountManager, predictSender, createWallet, encodeExecute, encodeExecuteBatch, generateAAWallets, generateAAWalletsFromMnemonic, predictSendersFromPrivateKeys, type GeneratedAAWallet, type GenerateAAWalletsParams, type GenerateAAWalletsResult, } from './aa-account.js';
|
|
64
|
-
export { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, PortalQuery, createPortalQuery, applySlippage, formatOkb, parseOkb, formatTokenAmount, parseTokenAmount, type PortalQueryConfig, } from './portal-ops.js';
|
|
64
|
+
export { encodeBuyCall, encodeBuyCallV3, encodeSellCall, encodeApproveCall, encodeTransferCall, PortalQuery, createPortalQuery, applySlippage, formatOkb, parseOkb, formatTokenAmount, parseTokenAmount, type PortalQueryConfig, } from './portal-ops.js';
|
|
65
65
|
export { BundleExecutor, createBundleExecutor, bundleBuy, bundleSell, bundleBuySell, bundleCreateBuySign, bundleCreateToDexSign, bundleGraduateBuy, bundlePreApprove, checkApprovalStatus, } from './bundle.js';
|
|
66
66
|
export { DexBundleExecutor, createDexBundleExecutor, dexBundleBuySell, type DexBundleConfig, type DexBundleBuySellParams, } from './dex-bundle.js';
|
|
67
67
|
export { AAPortalSwapExecutor, } from './portal-bundle-swap.js';
|
package/dist/xlayer/index.js
CHANGED
|
@@ -77,7 +77,7 @@ generateAAWallets, generateAAWalletsFromMnemonic, predictSendersFromPrivateKeys,
|
|
|
77
77
|
// ============================================================================
|
|
78
78
|
// Portal 操作
|
|
79
79
|
// ============================================================================
|
|
80
|
-
export { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, PortalQuery, createPortalQuery, applySlippage, formatOkb, parseOkb, formatTokenAmount, parseTokenAmount, } from './portal-ops.js';
|
|
80
|
+
export { encodeBuyCall, encodeBuyCallV3, encodeSellCall, encodeApproveCall, encodeTransferCall, PortalQuery, createPortalQuery, applySlippage, formatOkb, parseOkb, formatTokenAmount, parseTokenAmount, } from './portal-ops.js';
|
|
81
81
|
// ============================================================================
|
|
82
82
|
// 捆绑交易
|
|
83
83
|
// ============================================================================
|
|
@@ -16,6 +16,19 @@ import { JsonRpcProvider } from 'ethers';
|
|
|
16
16
|
* @param minOutputAmount 最小输出代币数量(默认 0)
|
|
17
17
|
*/
|
|
18
18
|
export declare function encodeBuyCall(tokenAddress: string, inputAmount: bigint, minOutputAmount?: bigint): string;
|
|
19
|
+
/**
|
|
20
|
+
* 编码买入调用 V3(swapExactInputV3: native -> token,支持 extensionData)
|
|
21
|
+
*
|
|
22
|
+
* 与 BSC 版本的 create-to-dex.ts 保持一致:
|
|
23
|
+
* - 统一优先使用 swapExactInputV3(支持 extensionData;无扩展时传 0x 即可)
|
|
24
|
+
* - 这里的 V3 指"交易接口版本(扩展支持)",不是"外盘 V3 池子"
|
|
25
|
+
*
|
|
26
|
+
* @param tokenAddress 目标代币地址
|
|
27
|
+
* @param inputAmount 输入 OKB 数量(wei)
|
|
28
|
+
* @param minOutputAmount 最小输出代币数量(默认 0)
|
|
29
|
+
* @param extensionData 扩展数据(默认 0x)
|
|
30
|
+
*/
|
|
31
|
+
export declare function encodeBuyCallV3(tokenAddress: string, inputAmount: bigint, minOutputAmount?: bigint, extensionData?: string): string;
|
|
19
32
|
/**
|
|
20
33
|
* 编码卖出调用(swapExactInput: token -> native)
|
|
21
34
|
*
|
|
@@ -33,6 +33,30 @@ export function encodeBuyCall(tokenAddress, inputAmount, minOutputAmount = 0n) {
|
|
|
33
33
|
},
|
|
34
34
|
]);
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* 编码买入调用 V3(swapExactInputV3: native -> token,支持 extensionData)
|
|
38
|
+
*
|
|
39
|
+
* 与 BSC 版本的 create-to-dex.ts 保持一致:
|
|
40
|
+
* - 统一优先使用 swapExactInputV3(支持 extensionData;无扩展时传 0x 即可)
|
|
41
|
+
* - 这里的 V3 指"交易接口版本(扩展支持)",不是"外盘 V3 池子"
|
|
42
|
+
*
|
|
43
|
+
* @param tokenAddress 目标代币地址
|
|
44
|
+
* @param inputAmount 输入 OKB 数量(wei)
|
|
45
|
+
* @param minOutputAmount 最小输出代币数量(默认 0)
|
|
46
|
+
* @param extensionData 扩展数据(默认 0x)
|
|
47
|
+
*/
|
|
48
|
+
export function encodeBuyCallV3(tokenAddress, inputAmount, minOutputAmount = 0n, extensionData = '0x') {
|
|
49
|
+
return portalIface.encodeFunctionData('swapExactInputV3', [
|
|
50
|
+
{
|
|
51
|
+
inputToken: ZERO_ADDRESS,
|
|
52
|
+
outputToken: tokenAddress,
|
|
53
|
+
inputAmount,
|
|
54
|
+
minOutputAmount,
|
|
55
|
+
permitData: '0x',
|
|
56
|
+
extensionData,
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
36
60
|
/**
|
|
37
61
|
* 编码卖出调用(swapExactInput: token -> native)
|
|
38
62
|
*
|
package/dist/xlayer/types.d.ts
CHANGED
|
@@ -860,8 +860,16 @@ export interface BundleGraduateBuyParams {
|
|
|
860
860
|
walletAmounts?: Record<string, number>;
|
|
861
861
|
/** 是否启用外盘买入(默认 false) */
|
|
862
862
|
enableDexBuy?: boolean;
|
|
863
|
+
/** 内盘钱包地址列表(可选,传入则使用前端分组,不传则 SDK 自动分组) */
|
|
864
|
+
curveAddresses?: string[];
|
|
865
|
+
/** 外盘钱包地址列表(可选) */
|
|
866
|
+
dexAddresses?: string[];
|
|
867
|
+
/** 动态毕业阈值(可选,不传则使用默认 73.38 OKB) */
|
|
868
|
+
graduationAmount?: number;
|
|
863
869
|
/** 配置覆盖 */
|
|
864
870
|
config?: Partial<XLayerConfig>;
|
|
871
|
+
/** 扩展数据(传递给 swapExactInputV3,默认 0x) */
|
|
872
|
+
extensionData?: string;
|
|
865
873
|
/** Payer 起始 nonce */
|
|
866
874
|
payerStartNonce?: number;
|
|
867
875
|
/** beneficiary(默认 payer 地址) */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "four-flap-meme-sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.80",
|
|
4
4
|
"description": "SDK for Flap bonding curve and four.meme TokenManager",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^5.6.3"
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|