four-flap-meme-sdk 4.0.13 → 4.0.14
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.
|
@@ -206,6 +206,8 @@ export async function buildBNBHopChainForERC20(payer, path, finalGasAmount, gasP
|
|
|
206
206
|
const fromWallet = path.hopWallets[i];
|
|
207
207
|
const toAddress = i === hopCount - 1 ? path.targetAddress : path.hopWallets[i + 1].address;
|
|
208
208
|
const amount = i === hopCount - 1 ? finalGasAmount : amountsPerHop[i + 1];
|
|
209
|
+
if (i === hopCount - 1 && amount === 0n)
|
|
210
|
+
continue;
|
|
209
211
|
const tx = {
|
|
210
212
|
to: toAddress,
|
|
211
213
|
value: amount,
|
|
@@ -176,14 +176,9 @@ export async function pancakeQuickBatchSwapMerkle(params) {
|
|
|
176
176
|
sellerRequired = bribeAmount + sellerGasCost;
|
|
177
177
|
}
|
|
178
178
|
else {
|
|
179
|
-
// ERC20:卖方还要给每个买方转一笔买入 Gas(hop=0 直转 / hop>0 多跳)
|
|
180
179
|
sellerGasCost =
|
|
181
|
-
gasPrice *
|
|
182
|
-
|
|
183
|
-
finalGasLimit +
|
|
184
|
-
(NATIVE_TRANSFER_GAS_LIMIT + ERC20_TRANSFER_GAS) * BigInt(buyers.length) +
|
|
185
|
-
BRIBE_GAS_LIMIT);
|
|
186
|
-
sellerRequired = bribeAmount + sellerGasCost + gasPrice * finalGasLimit * BigInt(buyers.length);
|
|
180
|
+
gasPrice * (BRIBE_GAS_LIMIT + finalGasLimit + ERC20_TRANSFER_GAS * BigInt(buyers.length) + BRIBE_GAS_LIMIT);
|
|
181
|
+
sellerRequired = bribeAmount + sellerGasCost;
|
|
187
182
|
}
|
|
188
183
|
if (sellerBalance < sellerRequired) {
|
|
189
184
|
throw new Error(`主钱包 BNB 余额不足: 需要约 ${ethers.formatEther(sellerRequired)} BNB (贿赂: ${ethers.formatEther(bribeAmount)}, Gas: ${ethers.formatEther(sellerGasCost)}), 实际 ${ethers.formatEther(sellerBalance)} BNB`);
|
|
@@ -258,7 +253,7 @@ export async function pancakeQuickBatchSwapMerkle(params) {
|
|
|
258
253
|
type: txType,
|
|
259
254
|
});
|
|
260
255
|
// ==================== 3. 转账交易(支持多跳)====================
|
|
261
|
-
|
|
256
|
+
// 买地址 gas 由用户自备,卖方只转买入金额 / 计价币
|
|
262
257
|
// ✅ 生成多跳路径
|
|
263
258
|
const hopPaths = generateDisperseHopPaths(buyers.map((b) => b.address), disperseHopCount, context.provider);
|
|
264
259
|
// 收集所有中间钱包信息
|
|
@@ -272,7 +267,7 @@ export async function pancakeQuickBatchSwapMerkle(params) {
|
|
|
272
267
|
const transferNonces = buyers.map((_, i) => sellerNonce + i);
|
|
273
268
|
sellerNonce += buyers.length;
|
|
274
269
|
transferTxs = await Promise.all(buyers.map((buyer, i) => {
|
|
275
|
-
const transferValue = transferAmountsWei[i] + FLAT_FEE
|
|
270
|
+
const transferValue = transferAmountsWei[i] + FLAT_FEE;
|
|
276
271
|
return seller.signTransaction({
|
|
277
272
|
to: buyer.address,
|
|
278
273
|
value: transferValue,
|
|
@@ -286,30 +281,21 @@ export async function pancakeQuickBatchSwapMerkle(params) {
|
|
|
286
281
|
}
|
|
287
282
|
else {
|
|
288
283
|
const erc20Interface = new ethers.Interface(ERC20_ABI);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
transferTxs.push(await seller.signTransaction({
|
|
293
|
-
to: buyer.address,
|
|
294
|
-
value: buyerGasCost,
|
|
295
|
-
nonce: sellerNonce++,
|
|
296
|
-
gasPrice,
|
|
297
|
-
gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
|
|
298
|
-
chainId: context.chainId,
|
|
299
|
-
type: txType,
|
|
300
|
-
}));
|
|
284
|
+
const transferNonces = buyers.map((_, i) => sellerNonce + i);
|
|
285
|
+
sellerNonce += buyers.length;
|
|
286
|
+
transferTxs = await Promise.all(buyers.map((buyer, i) => {
|
|
301
287
|
const transferData = erc20Interface.encodeFunctionData('transfer', [buyer.address, transferAmountsWei[i]]);
|
|
302
|
-
|
|
288
|
+
return seller.signTransaction({
|
|
303
289
|
to: quoteToken,
|
|
304
290
|
data: transferData,
|
|
305
291
|
value: 0n,
|
|
306
|
-
nonce:
|
|
292
|
+
nonce: transferNonces[i],
|
|
307
293
|
gasPrice,
|
|
308
294
|
gasLimit: ERC20_TRANSFER_GAS,
|
|
309
295
|
chainId: context.chainId,
|
|
310
296
|
type: txType,
|
|
311
|
-
})
|
|
312
|
-
}
|
|
297
|
+
});
|
|
298
|
+
}));
|
|
313
299
|
}
|
|
314
300
|
}
|
|
315
301
|
else {
|
|
@@ -318,7 +304,7 @@ export async function pancakeQuickBatchSwapMerkle(params) {
|
|
|
318
304
|
// BNB 多跳转账
|
|
319
305
|
// ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
|
|
320
306
|
const hopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
321
|
-
const finalAmount = transferAmountsWei[i] + FLAT_FEE
|
|
307
|
+
const finalAmount = transferAmountsWei[i] + FLAT_FEE;
|
|
322
308
|
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
323
309
|
return buildNativeHopChain(seller, path, finalAmount, gasPrice, context.chainId, txType, payerNonce);
|
|
324
310
|
}));
|
|
@@ -328,12 +314,10 @@ export async function pancakeQuickBatchSwapMerkle(params) {
|
|
|
328
314
|
else {
|
|
329
315
|
// ERC20 多跳转账:先转 BNB(给中间钱包 gas),再转 ERC20
|
|
330
316
|
// ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0/1
|
|
331
|
-
// 1. 构建 BNB
|
|
317
|
+
// 1. 构建 BNB 多跳链(只给中间钱包 gas,买地址自备)
|
|
332
318
|
const bnbHopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
336
|
-
return buildBNBHopChainForERC20(seller, path, finalGasAmount, gasPrice, context.chainId, txType, payerNonce);
|
|
319
|
+
const payerNonce = sellerNonce + i;
|
|
320
|
+
return buildBNBHopChainForERC20(seller, path, 0n, gasPrice, context.chainId, txType, payerNonce);
|
|
337
321
|
}));
|
|
338
322
|
const bnbTxs = bnbHopChains.flat();
|
|
339
323
|
sellerNonce += buyers.length; // ✅ payer 只增加 buyers.length 个 nonce
|
|
@@ -165,6 +165,8 @@ export async function buildBNBHopChainForERC20(payer, path, finalGasAmount, gasP
|
|
|
165
165
|
const fromWallet = path.hopWallets[i];
|
|
166
166
|
const toAddress = i === hopCount - 1 ? path.targetAddress : path.hopWallets[i + 1].address;
|
|
167
167
|
const amount = i === hopCount - 1 ? finalGasAmount : amountsPerHop[i + 1];
|
|
168
|
+
if (i === hopCount - 1 && amount === 0n)
|
|
169
|
+
continue;
|
|
168
170
|
signedTxs.push(await fromWallet.signTransaction({
|
|
169
171
|
to: toAddress,
|
|
170
172
|
value: amount,
|
|
@@ -139,15 +139,9 @@ export async function flapQuickBatchSwapMerkle(params) {
|
|
|
139
139
|
sellerRequired = bribeAmount + sellerGasCost;
|
|
140
140
|
}
|
|
141
141
|
else {
|
|
142
|
-
const reserveForBuyers = ethers.parseEther((config.reserveGasETH || 0.0005).toString());
|
|
143
142
|
sellerGasCost =
|
|
144
|
-
gasPrice *
|
|
145
|
-
|
|
146
|
-
finalGasLimit +
|
|
147
|
-
(NATIVE_TRANSFER_GAS_LIMIT + ERC20_TRANSFER_GAS) * BigInt(buyers.length) +
|
|
148
|
-
BRIBE_GAS_LIMIT);
|
|
149
|
-
sellerRequired =
|
|
150
|
-
bribeAmount + sellerGasCost + (reserveForBuyers + gasPrice * finalGasLimit) * BigInt(buyers.length);
|
|
143
|
+
gasPrice * (BRIBE_GAS_LIMIT + finalGasLimit + ERC20_TRANSFER_GAS * BigInt(buyers.length) + BRIBE_GAS_LIMIT);
|
|
144
|
+
sellerRequired = bribeAmount + sellerGasCost;
|
|
151
145
|
}
|
|
152
146
|
if (sellerBalance < sellerRequired) {
|
|
153
147
|
throw new Error(`主钱包 ${chainContext.nativeToken} 余额不足: 需要约 ${ethers.formatEther(sellerRequired)} (贿赂: ${ethers.formatEther(bribeAmount)}, Gas: ${ethers.formatEther(sellerGasCost)}), 实际 ${ethers.formatEther(sellerBalance)}`);
|
|
@@ -189,8 +183,6 @@ export async function flapQuickBatchSwapMerkle(params) {
|
|
|
189
183
|
});
|
|
190
184
|
const signedSell = await seller.signTransaction(sellTx);
|
|
191
185
|
// ==================== 3. 转账交易(支持多跳)====================
|
|
192
|
-
const reserveGas = ethers.parseEther((config.reserveGasETH || 0.0005).toString());
|
|
193
|
-
const buyerGasCost = gasPrice * finalGasLimit;
|
|
194
186
|
// ✅ 生成多跳路径
|
|
195
187
|
const hopPaths = generateDisperseHopPaths(buyers.map((b) => b.address), disperseHopCount, chainContext.provider);
|
|
196
188
|
// 收集所有中间钱包信息
|
|
@@ -204,7 +196,7 @@ export async function flapQuickBatchSwapMerkle(params) {
|
|
|
204
196
|
const transferNonces = buyers.map((_, i) => sellerNonce + i);
|
|
205
197
|
sellerNonce += buyers.length;
|
|
206
198
|
transferTxs = await Promise.all(buyers.map((buyer, i) => {
|
|
207
|
-
const transferValue = transferAmountsWei[i]
|
|
199
|
+
const transferValue = transferAmountsWei[i];
|
|
208
200
|
return seller.signTransaction({
|
|
209
201
|
to: buyer.address,
|
|
210
202
|
value: transferValue,
|
|
@@ -218,30 +210,21 @@ export async function flapQuickBatchSwapMerkle(params) {
|
|
|
218
210
|
}
|
|
219
211
|
else {
|
|
220
212
|
const erc20Interface = new ethers.Interface(ERC20_ABI);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
transferTxs.push(await seller.signTransaction({
|
|
225
|
-
to: buyer.address,
|
|
226
|
-
value: reserveGas + buyerGasCost,
|
|
227
|
-
nonce: sellerNonce++,
|
|
228
|
-
gasPrice,
|
|
229
|
-
gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
|
|
230
|
-
chainId: chainContext.chainId,
|
|
231
|
-
type: txType,
|
|
232
|
-
}));
|
|
213
|
+
const transferNonces = buyers.map((_, i) => sellerNonce + i);
|
|
214
|
+
sellerNonce += buyers.length;
|
|
215
|
+
transferTxs = await Promise.all(buyers.map((buyer, i) => {
|
|
233
216
|
const transferData = erc20Interface.encodeFunctionData('transfer', [buyer.address, transferAmountsWei[i]]);
|
|
234
|
-
|
|
217
|
+
return seller.signTransaction({
|
|
235
218
|
to: quoteToken,
|
|
236
219
|
data: transferData,
|
|
237
220
|
value: 0n,
|
|
238
|
-
nonce:
|
|
221
|
+
nonce: transferNonces[i],
|
|
239
222
|
gasPrice,
|
|
240
223
|
gasLimit: ERC20_TRANSFER_GAS,
|
|
241
224
|
chainId: chainContext.chainId,
|
|
242
225
|
type: txType,
|
|
243
|
-
})
|
|
244
|
-
}
|
|
226
|
+
});
|
|
227
|
+
}));
|
|
245
228
|
}
|
|
246
229
|
}
|
|
247
230
|
else {
|
|
@@ -250,7 +233,7 @@ export async function flapQuickBatchSwapMerkle(params) {
|
|
|
250
233
|
// 原生代币多跳转账
|
|
251
234
|
// ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
|
|
252
235
|
const hopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
253
|
-
const finalAmount = transferAmountsWei[i]
|
|
236
|
+
const finalAmount = transferAmountsWei[i];
|
|
254
237
|
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
255
238
|
return buildNativeHopChain(seller, path, finalAmount, gasPrice, chainContext.chainId, txType, payerNonce);
|
|
256
239
|
}));
|
|
@@ -262,7 +245,7 @@ export async function flapQuickBatchSwapMerkle(params) {
|
|
|
262
245
|
// ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0/1
|
|
263
246
|
// 1. 构建 BNB 多跳链
|
|
264
247
|
const bnbHopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
265
|
-
const finalGasAmount =
|
|
248
|
+
const finalGasAmount = 0n;
|
|
266
249
|
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
267
250
|
return buildBNBHopChainForERC20(seller, path, finalGasAmount, gasPrice, chainContext.chainId, txType, payerNonce);
|
|
268
251
|
}));
|