four-flap-meme-sdk 4.0.12 → 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,8 +176,6 @@ export async function pancakeQuickBatchSwapMerkle(params) {
176
176
  sellerRequired = bribeAmount + sellerGasCost;
177
177
  }
178
178
  else {
179
- // ERC20 模式:子钱包已预留 BNB,不需要主钱包转 Gas
180
- // 卖方 Gas: 贿赂(BRIBE) + 卖出(gasLimit) + N个ERC20转账(65000 each) + 利润(BRIBE)
181
179
  sellerGasCost =
182
180
  gasPrice * (BRIBE_GAS_LIMIT + finalGasLimit + ERC20_TRANSFER_GAS * BigInt(buyers.length) + BRIBE_GAS_LIMIT);
183
181
  sellerRequired = bribeAmount + sellerGasCost;
@@ -255,7 +253,7 @@ export async function pancakeQuickBatchSwapMerkle(params) {
255
253
  type: txType,
256
254
  });
257
255
  // ==================== 3. 转账交易(支持多跳)====================
258
- const buyerGasCost = gasPrice * finalGasLimit;
256
+ // 买地址 gas 由用户自备,卖方只转买入金额 / 计价币
259
257
  // ✅ 生成多跳路径
260
258
  const hopPaths = generateDisperseHopPaths(buyers.map((b) => b.address), disperseHopCount, context.provider);
261
259
  // 收集所有中间钱包信息
@@ -265,12 +263,11 @@ export async function pancakeQuickBatchSwapMerkle(params) {
265
263
  });
266
264
  let transferTxs;
267
265
  if (disperseHopCount === 0) {
268
- // ✅ 无多跳:直接转账
269
- const transferNonces = buyers.map((_, i) => sellerNonce + i);
270
- sellerNonce += buyers.length;
271
266
  if (useNativeToken) {
267
+ const transferNonces = buyers.map((_, i) => sellerNonce + i);
268
+ sellerNonce += buyers.length;
272
269
  transferTxs = await Promise.all(buyers.map((buyer, i) => {
273
- const transferValue = transferAmountsWei[i] + FLAT_FEE + buyerGasCost;
270
+ const transferValue = transferAmountsWei[i] + FLAT_FEE;
274
271
  return seller.signTransaction({
275
272
  to: buyer.address,
276
273
  value: transferValue,
@@ -284,6 +281,8 @@ export async function pancakeQuickBatchSwapMerkle(params) {
284
281
  }
285
282
  else {
286
283
  const erc20Interface = new ethers.Interface(ERC20_ABI);
284
+ const transferNonces = buyers.map((_, i) => sellerNonce + i);
285
+ sellerNonce += buyers.length;
287
286
  transferTxs = await Promise.all(buyers.map((buyer, i) => {
288
287
  const transferData = erc20Interface.encodeFunctionData('transfer', [buyer.address, transferAmountsWei[i]]);
289
288
  return seller.signTransaction({
@@ -305,7 +304,7 @@ export async function pancakeQuickBatchSwapMerkle(params) {
305
304
  // BNB 多跳转账
306
305
  // ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
307
306
  const hopChains = await Promise.all(hopPaths.map((path, i) => {
308
- const finalAmount = transferAmountsWei[i] + FLAT_FEE + buyerGasCost;
307
+ const finalAmount = transferAmountsWei[i] + FLAT_FEE;
309
308
  const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
310
309
  return buildNativeHopChain(seller, path, finalAmount, gasPrice, context.chainId, txType, payerNonce);
311
310
  }));
@@ -315,12 +314,10 @@ export async function pancakeQuickBatchSwapMerkle(params) {
315
314
  else {
316
315
  // ERC20 多跳转账:先转 BNB(给中间钱包 gas),再转 ERC20
317
316
  // ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0/1
318
- // 1. 构建 BNB 多跳链(为中间钱包和最终钱包预留 gas
317
+ // 1. 构建 BNB 多跳链(只给中间钱包 gas,买地址自备)
319
318
  const bnbHopChains = await Promise.all(hopPaths.map((path, i) => {
320
- // 最终钱包需要的 gas(用于买入交易)
321
- const finalGasAmount = buyerGasCost;
322
- const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
323
- 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);
324
321
  }));
325
322
  const bnbTxs = bnbHopChains.flat();
326
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,7 +139,6 @@ export async function flapQuickBatchSwapMerkle(params) {
139
139
  sellerRequired = bribeAmount + sellerGasCost;
140
140
  }
141
141
  else {
142
- // ERC20 模式:贿赂 + Gas(卖出 + ERC20转账 + 利润)
143
142
  sellerGasCost =
144
143
  gasPrice * (BRIBE_GAS_LIMIT + finalGasLimit + ERC20_TRANSFER_GAS * BigInt(buyers.length) + BRIBE_GAS_LIMIT);
145
144
  sellerRequired = bribeAmount + sellerGasCost;
@@ -184,8 +183,6 @@ export async function flapQuickBatchSwapMerkle(params) {
184
183
  });
185
184
  const signedSell = await seller.signTransaction(sellTx);
186
185
  // ==================== 3. 转账交易(支持多跳)====================
187
- const reserveGas = ethers.parseEther((config.reserveGasETH || 0.0005).toString());
188
- const buyerGasCost = gasPrice * finalGasLimit;
189
186
  // ✅ 生成多跳路径
190
187
  const hopPaths = generateDisperseHopPaths(buyers.map((b) => b.address), disperseHopCount, chainContext.provider);
191
188
  // 收集所有中间钱包信息
@@ -195,12 +192,11 @@ export async function flapQuickBatchSwapMerkle(params) {
195
192
  });
196
193
  let transferTxs;
197
194
  if (disperseHopCount === 0) {
198
- // ✅ 无多跳:直接转账
199
- const transferNonces = buyers.map((_, i) => sellerNonce + i);
200
- sellerNonce += buyers.length;
201
195
  if (useNativeToken) {
196
+ const transferNonces = buyers.map((_, i) => sellerNonce + i);
197
+ sellerNonce += buyers.length;
202
198
  transferTxs = await Promise.all(buyers.map((buyer, i) => {
203
- const transferValue = transferAmountsWei[i] + reserveGas + buyerGasCost;
199
+ const transferValue = transferAmountsWei[i];
204
200
  return seller.signTransaction({
205
201
  to: buyer.address,
206
202
  value: transferValue,
@@ -214,6 +210,8 @@ export async function flapQuickBatchSwapMerkle(params) {
214
210
  }
215
211
  else {
216
212
  const erc20Interface = new ethers.Interface(ERC20_ABI);
213
+ const transferNonces = buyers.map((_, i) => sellerNonce + i);
214
+ sellerNonce += buyers.length;
217
215
  transferTxs = await Promise.all(buyers.map((buyer, i) => {
218
216
  const transferData = erc20Interface.encodeFunctionData('transfer', [buyer.address, transferAmountsWei[i]]);
219
217
  return seller.signTransaction({
@@ -235,7 +233,7 @@ export async function flapQuickBatchSwapMerkle(params) {
235
233
  // 原生代币多跳转账
236
234
  // ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
237
235
  const hopChains = await Promise.all(hopPaths.map((path, i) => {
238
- const finalAmount = transferAmountsWei[i] + reserveGas + buyerGasCost;
236
+ const finalAmount = transferAmountsWei[i];
239
237
  const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
240
238
  return buildNativeHopChain(seller, path, finalAmount, gasPrice, chainContext.chainId, txType, payerNonce);
241
239
  }));
@@ -247,7 +245,7 @@ export async function flapQuickBatchSwapMerkle(params) {
247
245
  // ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0/1
248
246
  // 1. 构建 BNB 多跳链
249
247
  const bnbHopChains = await Promise.all(hopPaths.map((path, i) => {
250
- const finalGasAmount = buyerGasCost;
248
+ const finalGasAmount = 0n;
251
249
  const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
252
250
  return buildBNBHopChainForERC20(seller, path, finalGasAmount, gasPrice, chainContext.chainId, txType, payerNonce);
253
251
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "4.0.12",
3
+ "version": "4.0.14",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",