four-flap-meme-sdk 1.7.44 → 1.7.46

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.
@@ -371,7 +371,8 @@ export async function bundleSwap(params) {
371
371
  * });
372
372
  */
373
373
  export async function bundleBatchSwap(params) {
374
- const { sellerPrivateKey, buyerPrivateKeys, tokenAddress, tokenDecimals = 18, sellAmount, hopCount = 2, // ✅ 设为 0 则不多跳
374
+ const { sellerPrivateKey, buyerPrivateKeys, buyerRatios, // ✅ 添加:前端传入的分配比例
375
+ tokenAddress, tokenDecimals = 18, sellAmount, hopCount = 2, // ✅ 设为 0 则不多跳
375
376
  tradeType = 'V3', routerAddress, fee = V3_FEE_TIERS.MEDIUM, userType = 'v0', // ✅ 用户类型(影响利润率)
376
377
  config, } = params;
377
378
  const provider = getCachedProvider(config?.rpcUrl);
@@ -443,24 +444,39 @@ export async function bundleBatchSwap(params) {
443
444
  callData: delegateInterface.encodeFunctionData('transferTo', [buyerWallets[0].address]),
444
445
  });
445
446
  }
446
- // ✅ 修复:计算每个买家分配的 OKB 金额(平分,扣除利润)
447
+ // ✅ 修复:计算每个买家分配的 OKB 金额(支持按比例分配)
447
448
  const portalInterface = new ethers.Interface(FLAP_PORTAL_ABI);
448
449
  const okbForBuyers = estimatedOkbOut - profitAmount; // 扣除利润后可用于买入的 OKB
449
- const buyAmountPerBuyer = okbForBuyers / BigInt(buyerWallets.length);
450
+ // 计算每个买家的分配金额(按比例或平均)
451
+ let buyAmountsPerBuyer;
452
+ if (buyerRatios && buyerRatios.length === buyerWallets.length) {
453
+ // 按前端传入的比例分配
454
+ buyAmountsPerBuyer = buyerRatios.map(ratio => {
455
+ return (okbForBuyers * BigInt(Math.round(ratio * 10000))) / 10000n;
456
+ });
457
+ console.log(`[Bundle Batch Swap] 使用比例分配:`, buyerRatios);
458
+ }
459
+ else {
460
+ // 平均分配(向后兼容)
461
+ const avgAmount = okbForBuyers / BigInt(buyerWallets.length);
462
+ buyAmountsPerBuyer = buyerWallets.map(() => avgAmount);
463
+ console.log(`[Bundle Batch Swap] 使用平均分配: 每个买家 ${ethers.formatEther(avgAmount)} OKB`);
464
+ }
450
465
  console.log(`[Bundle Batch Swap] 可用于买入: ${ethers.formatEther(okbForBuyers)} OKB`);
451
- console.log(`[Bundle Batch Swap] 每个买家分配: ${ethers.formatEther(buyAmountPerBuyer)} OKB`);
452
- // ✅ 修复:第一个买家收到所有资金后,转账给其他买家
466
+ console.log(`[Bundle Batch Swap] 各买家分配金额:`, buyAmountsPerBuyer.map(a => ethers.formatEther(a)));
467
+ // ✅ 修复:第一个买家收到所有资金后,使用 transferAmount 按比例分配给其他买家
468
+ // 注意:transferTo 会转移全部余额,导致第一个买家无法买入!必须使用 transferAmount 指定金额
453
469
  for (let i = 1; i < buyerWallets.length; i++) {
454
470
  calls.push({
455
471
  target: buyerWallets[0].address, // 第一个买家转账
456
472
  allowFailure: false,
457
473
  value: 0n,
458
- callData: delegateInterface.encodeFunctionData('transferTo', [buyerWallets[i].address]),
474
+ callData: delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, buyAmountsPerBuyer[i]]),
459
475
  });
460
476
  }
461
477
  // ✅ 修复:使用 buildBuyCallInternal(有金额参数)
462
478
  for (let i = 0; i < buyerWallets.length; i++) {
463
- const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountPerBuyer, // ✅ 使用分配的金额
479
+ const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountsPerBuyer[i], // ✅ 使用各自分配的金额(按比例)
464
480
  tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
465
481
  calls.push(buyCall);
466
482
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.44",
3
+ "version": "1.7.46",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",