four-flap-meme-sdk 1.7.42 → 1.7.44

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.
@@ -31,9 +31,12 @@ export class MerkleClient {
31
31
  this.blockNumberCache = null;
32
32
  this.chainId = config.chainId;
33
33
  this.chainName = config.chainId === 56 ? 'bsc' : 'ethereum';
34
- // 构建 RPC URL
35
- const rpcUrl = config.customRpcUrl ||
36
- `https://mempool.merkle.io/rpc/${this.chainName}/${config.apiKey}`;
34
+ // 修复:移除弃用的 mempool.merkle.io RPC,使用公共 RPC 作为默认值
35
+ // 优先使用用户自定义 RPC,否则使用官方公共 RPC
36
+ const defaultRpc = config.chainId === 56
37
+ ? 'https://bsc-dataseed1.bnbchain.org'
38
+ : 'https://eth.llamarpc.com';
39
+ const rpcUrl = config.customRpcUrl || defaultRpc;
37
40
  this.provider = new JsonRpcProvider(rpcUrl, {
38
41
  chainId: this.chainId,
39
42
  name: this.chainName,
@@ -434,6 +434,7 @@ export async function bundleBatchSwap(params) {
434
434
  });
435
435
  }
436
436
  // 最后一个中间钱包转给第一个买家
437
+ // ⚠️ 注意:资金先到第一个买家,然后第一个买家转给其他买家
437
438
  if (hopWallets.length > 0) {
438
439
  calls.push({
439
440
  target: hopWallets[hopWallets.length - 1].address,
@@ -442,9 +443,25 @@ export async function bundleBatchSwap(params) {
442
443
  callData: delegateInterface.encodeFunctionData('transferTo', [buyerWallets[0].address]),
443
444
  });
444
445
  }
445
- // 买家买币(根据交易类型)
446
- for (const buyerWallet of buyerWallets) {
447
- const buyCall = buildBuyCall(buyerWallet, tokenAddress, tradeType, actualRouter, fee);
446
+ // ✅ 修复:计算每个买家分配的 OKB 金额(平分,扣除利润)
447
+ const portalInterface = new ethers.Interface(FLAP_PORTAL_ABI);
448
+ const okbForBuyers = estimatedOkbOut - profitAmount; // 扣除利润后可用于买入的 OKB
449
+ const buyAmountPerBuyer = okbForBuyers / BigInt(buyerWallets.length);
450
+ console.log(`[Bundle Batch Swap] 可用于买入: ${ethers.formatEther(okbForBuyers)} OKB`);
451
+ console.log(`[Bundle Batch Swap] 每个买家分配: ${ethers.formatEther(buyAmountPerBuyer)} OKB`);
452
+ // ✅ 修复:第一个买家收到所有资金后,转账给其他买家
453
+ for (let i = 1; i < buyerWallets.length; i++) {
454
+ calls.push({
455
+ target: buyerWallets[0].address, // 第一个买家转账
456
+ allowFailure: false,
457
+ value: 0n,
458
+ callData: delegateInterface.encodeFunctionData('transferTo', [buyerWallets[i].address]),
459
+ });
460
+ }
461
+ // ✅ 修复:使用 buildBuyCallInternal(有金额参数)
462
+ for (let i = 0; i < buyerWallets.length; i++) {
463
+ const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountPerBuyer, // ✅ 使用分配的金额
464
+ tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
448
465
  calls.push(buyCall);
449
466
  }
450
467
  // ✅ 利润刮取放在最后(从卖家钱包)
@@ -646,22 +663,22 @@ function buildBuyCallInternal(wallet, amount, tokenAddress, tradeType, routerAdd
646
663
  }
647
664
  case 'V2': {
648
665
  const path = [WOKB_ADDRESS, tokenAddress];
649
- // ✅ 修复:value 设为 0n,让钱包使用自己余额买入
666
+ // ✅ 修复:使用指定的买入金额,而不是 0(使用全部余额会导致严重 bug)
650
667
  return {
651
668
  target: wallet.address,
652
669
  allowFailure: false,
653
670
  value: 0n,
654
- callData: delegateInterface.encodeFunctionData('executeBuyV2', [routerAddress, path, 0]),
671
+ callData: delegateInterface.encodeFunctionData('executeBuyV2', [routerAddress, path, amount]),
655
672
  };
656
673
  }
657
674
  case 'V3': {
658
- // ✅ 修复:value 设为 0n,让钱包使用自己余额买入
675
+ // ✅ 修复:使用指定的买入金额,而不是 0(使用全部余额会导致严重 bug)
659
676
  return {
660
677
  target: wallet.address,
661
678
  allowFailure: false,
662
679
  value: 0n,
663
680
  callData: delegateInterface.encodeFunctionData('executeBuy', [
664
- routerAddress, WOKB_ADDRESS, tokenAddress, fee, 0
681
+ routerAddress, WOKB_ADDRESS, tokenAddress, fee, amount
665
682
  ]),
666
683
  };
667
684
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.42",
3
+ "version": "1.7.44",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",