four-flap-meme-sdk 1.7.64 → 1.7.65

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.
@@ -367,10 +367,12 @@ export async function bundleSwap(params) {
367
367
  if (useFundUtilization) {
368
368
  // ========================================
369
369
  // ✅ 资金利用率模式
370
+ // 核心逻辑:卖出获得的 OKB 按比例转给买家
370
371
  // 1. 卖家卖出代币 → 获得 OKB
371
- // 2. OKB 多跳转账 → 中间钱包1 → 中间钱包2 → ... → 买家
372
- // 3. 利润从卖家 OKB 中扣除
373
- // 4. 买家用收到的 OKB 买入
372
+ // 2. 利润从卖家 OKB 中扣除
373
+ // 3. (可选多跳)卖家 hop1 → hop2 → ... → 分发者
374
+ // 4. 分发者按比例转账给买家
375
+ // 5. 买家买入
374
376
  // ========================================
375
377
  console.log(`[Bundle Swap] 资金利用率模式,hopCount=${actualHopCount}`);
376
378
  // 1. 卖家卖出
@@ -385,29 +387,36 @@ export async function bundleSwap(params) {
385
387
  callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
386
388
  });
387
389
  }
388
- // 3. OKB 多跳转账(卖家 → hop1 → hop2 → ... → 买家)
389
- const firstRecipient = hopWallets.length > 0 ? hopWallets[0].address : buyerWallet.address;
390
- // 卖家 → 第一个接收者
391
- calls.push({
392
- target: sellerWallet.address,
393
- allowFailure: false,
394
- value: 0n,
395
- callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
396
- });
397
- // 中间钱包之间转账
398
- for (let i = 0; i < hopWallets.length; i++) {
399
- const nextRecipient = i < hopWallets.length - 1 ? hopWallets[i + 1].address : buyerWallet.address;
390
+ // 3. 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
391
+ const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
392
+ // 多跳转账(如果有)
393
+ if (hopWallets.length > 0) {
394
+ // 卖家 → hop1
400
395
  calls.push({
401
- target: hopWallets[i].address,
396
+ target: sellerWallet.address,
402
397
  allowFailure: false,
403
398
  value: 0n,
404
- callData: delegateInterface.encodeFunctionData('transferTo', [nextRecipient]),
399
+ callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[0].address]),
405
400
  });
401
+ // hop1 → hop2 → ... → 最后一个 hop(分发者)
402
+ for (let i = 0; i < hopWallets.length - 1; i++) {
403
+ calls.push({
404
+ target: hopWallets[i].address,
405
+ allowFailure: false,
406
+ value: 0n,
407
+ callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[i + 1].address]),
408
+ });
409
+ }
406
410
  }
407
- // 4. 买家买入(使用收到的 OKB,按卖出所得计算)
408
- // ✅ 资金利用率模式下,所有 tradeType 都使用精确金额
409
- const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, // ✅ 使用卖出所得(扣除利润)
410
- tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
411
+ // 4. 分发者按比例转账给买家
412
+ calls.push({
413
+ target: distributor.address,
414
+ allowFailure: false,
415
+ value: 0n,
416
+ callData: delegateInterface.encodeFunctionData('transferAmount', [buyerWallet.address, buyAmountAfterProfit]),
417
+ });
418
+ // 5. 买家买入(使用收到的 OKB)
419
+ const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
411
420
  calls.push(buyCall);
412
421
  }
413
422
  else {
@@ -574,7 +583,7 @@ export async function bundleBatchSwap(params) {
574
583
  // ✅ 资金利用率模式(一卖多买)
575
584
  // 1. 卖家卖出代币 → 获得 OKB
576
585
  // 2. 利润从卖家 OKB 中扣除
577
- // 3. OKB 多跳转账 → 分配给各买家
586
+ // 3. 卖家(或最后一个 hop)按比例转账给各买家
578
587
  // 4. 各买家用收到的 OKB 买入
579
588
  // ========================================
580
589
  console.log(`[Bundle Batch Swap] 资金利用率模式,hopCount=${actualHopCount}`);
@@ -590,32 +599,37 @@ export async function bundleBatchSwap(params) {
590
599
  callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
591
600
  });
592
601
  }
593
- // 3. OKB 多跳转账给第一个买家
594
- const firstRecipient = hopWallets.length > 0 ? hopWallets[0].address : buyerWallets[0].address;
595
- // 卖家 第一个接收者(转全部余额)
596
- calls.push({
597
- target: sellerWallet.address,
598
- allowFailure: false,
599
- value: 0n,
600
- callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
601
- });
602
- // 中间钱包之间转账
603
- for (let i = 0; i < hopWallets.length; i++) {
604
- const nextRecipient = i < hopWallets.length - 1 ? hopWallets[i + 1].address : buyerWallets[0].address;
602
+ // 3. OKB 转账逻辑
603
+ // 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
604
+ const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
605
+ if (hopWallets.length > 0) {
606
+ // 有多跳:卖家 → hop1 → hop2 → ... → 最后一个 hop(分发者)
605
607
  calls.push({
606
- target: hopWallets[i].address,
608
+ target: sellerWallet.address,
607
609
  allowFailure: false,
608
610
  value: 0n,
609
- callData: delegateInterface.encodeFunctionData('transferTo', [nextRecipient]),
611
+ callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[0].address]),
610
612
  });
613
+ // 中间钱包之间转账(到最后一个 hop)
614
+ for (let i = 0; i < hopWallets.length - 1; i++) {
615
+ calls.push({
616
+ target: hopWallets[i].address,
617
+ allowFailure: false,
618
+ value: 0n,
619
+ callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[i + 1].address]),
620
+ });
621
+ }
611
622
  }
612
- // 第一个买家分配给其他买家
613
- for (let i = 1; i < buyerWallets.length; i++) {
623
+ // 分发者按比例转给各买家
624
+ for (let i = 0; i < buyerWallets.length; i++) {
625
+ const amountToTransfer = buyAmountsPerBuyer[i];
626
+ if (amountToTransfer <= 0n)
627
+ continue;
614
628
  calls.push({
615
- target: buyerWallets[0].address,
629
+ target: distributor.address,
616
630
  allowFailure: false,
617
631
  value: 0n,
618
- callData: delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, buyAmountsPerBuyer[i]]),
632
+ callData: delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, amountToTransfer]),
619
633
  });
620
634
  }
621
635
  // 4. 所有买家买入
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.64",
3
+ "version": "1.7.65",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",