four-flap-meme-sdk 1.7.52 → 1.7.54

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.
@@ -369,11 +369,12 @@ export async function bundleSwap(params) {
369
369
  calls.push(buyCall);
370
370
  }
371
371
  else {
372
- // 资金利用率模式:进行转账
373
- const swapCalls = await buildSwapCalls(sellerWallet, buyerWallet, hopWallets, sellAmountWei, buyAmount, tokenAddress, tradeType, actualRouter, fee);
374
- // 1. 先添加卖出调用
375
- calls.push(swapCalls[0]);
376
- // 2. 利润刮取(卖出后立即进行)
372
+ // 资金利用率模式:卖出 -> 扣利润 -> 转账 -> 买入
373
+ const firstRecipient = hopWallets.length > 0 ? hopWallets[0].address : buyerWallet.address;
374
+ // 1. 卖家卖出 (独立卖出,不包含转账)
375
+ const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
376
+ calls.push(sellCall);
377
+ // 2. 利润刮取 (卖出后,转账前)
377
378
  if (profitAmount > 0n) {
378
379
  calls.push({
379
380
  target: sellerWallet.address,
@@ -382,10 +383,26 @@ export async function bundleSwap(params) {
382
383
  callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
383
384
  });
384
385
  }
385
- // 3. 添加剩余的调用(转账和买入)
386
- for (let i = 1; i < swapCalls.length; i++) {
387
- calls.push(swapCalls[i]);
386
+ // 3. 卖家转账给第一个接收者 (分发剩余 OKB)
387
+ calls.push({
388
+ target: sellerWallet.address,
389
+ allowFailure: false,
390
+ value: 0n,
391
+ callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
392
+ });
393
+ // 4. 中间钱包之间的转账
394
+ for (let i = 0; i < hopWallets.length; i++) {
395
+ const nextRecipient = i < hopWallets.length - 1 ? hopWallets[i + 1].address : buyerWallet.address;
396
+ calls.push({
397
+ target: hopWallets[i].address,
398
+ allowFailure: false,
399
+ value: 0n,
400
+ callData: delegateInterface.encodeFunctionData('transferTo', [nextRecipient]),
401
+ });
388
402
  }
403
+ // 5. 买家买入 (使用指定金额)
404
+ const buyCall = buildBuyCallInternal(buyerWallet, buyAmount, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
405
+ calls.push(buyCall);
389
406
  }
390
407
  // ========================================
391
408
  // 同步构建交易
@@ -470,21 +487,38 @@ export async function bundleBatchSwap(params) {
470
487
  // 普通模式:只卖币,不转账
471
488
  const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
472
489
  calls.push(sellCall);
490
+ // ✅ 利润刮取 (如果是 Independent 模式,直接从卖家余额扣)
491
+ if (profitAmount > 0n) {
492
+ calls.push({
493
+ target: sellerWallet.address,
494
+ allowFailure: false,
495
+ value: 0n,
496
+ callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
497
+ });
498
+ }
473
499
  }
474
500
  else {
475
- // 资金利用率模式:卖币并转账
501
+ // 资金利用率模式:卖出 -> 扣利润 -> 转账 -> 买入
476
502
  const firstRecipient = hopWallets.length > 0 ? hopWallets[0].address : buyerWallets[0].address;
477
- const sellCall = buildSellAndTransferCall(sellerWallet, sellAmountWei, tokenAddress, firstRecipient, tradeType, actualRouter, fee);
503
+ // 1.1 卖出 (统一使用非转账 sell 函数,确保利润能成功扣除)
504
+ const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
478
505
  calls.push(sellCall);
479
- // FLAP 模式需要额外的转账调用
480
- if (tradeType === 'FLAP') {
506
+ // 1.2 扣除利润 (在卖家转账给下游之前)
507
+ if (profitAmount > 0n) {
481
508
  calls.push({
482
509
  target: sellerWallet.address,
483
510
  allowFailure: false,
484
511
  value: 0n,
485
- callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
512
+ callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
486
513
  });
487
514
  }
515
+ // 1.3 卖家转账给第一个接收者
516
+ calls.push({
517
+ target: sellerWallet.address,
518
+ allowFailure: false,
519
+ value: 0n,
520
+ callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
521
+ });
488
522
  // 中间钱包转账
489
523
  for (let i = 0; i < hopWallets.length - 1; i++) {
490
524
  calls.push({
@@ -532,15 +566,6 @@ export async function bundleBatchSwap(params) {
532
566
  const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountsPerBuyer[i], tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
533
567
  calls.push(buyCall);
534
568
  }
535
- // ✅ 5. 利润刮取(放在最后)
536
- if (profitAmount > 0n) {
537
- calls.push({
538
- target: sellerWallet.address,
539
- allowFailure: false,
540
- value: 0n,
541
- callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
542
- });
543
- }
544
569
  // ========================================
545
570
  // 同步签署授权(并行)
546
571
  // ========================================
@@ -784,8 +809,8 @@ function buildSellCallWithAmountInternal(wallet, amount, tokenAddress, tradeType
784
809
  target: wallet.address,
785
810
  allowFailure: false,
786
811
  value: 0n,
787
- // ✅ 传 0 让合约自动查询余额
788
- callData: delegateInterface.encodeFunctionData('executeSellV2', [routerAddress, path, 0]),
812
+ // ✅ 修复:传入实际数量,避免卖出全部
813
+ callData: delegateInterface.encodeFunctionData('executeSellV2', [routerAddress, path, amount]),
789
814
  };
790
815
  }
791
816
  case 'V3': {
@@ -793,9 +818,9 @@ function buildSellCallWithAmountInternal(wallet, amount, tokenAddress, tradeType
793
818
  target: wallet.address,
794
819
  allowFailure: false,
795
820
  value: 0n,
796
- // ✅ 传 0 让合约自动查询余额
821
+ // ✅ 修复:传入实际数量,避免卖出全部
797
822
  callData: delegateInterface.encodeFunctionData('executeSell', [
798
- routerAddress, tokenAddress, WOKB_ADDRESS, fee, 0
823
+ routerAddress, tokenAddress, WOKB_ADDRESS, fee, amount
799
824
  ]),
800
825
  };
801
826
  }
@@ -677,20 +677,22 @@ function buildSellCall(wallet, tokenAddress, sellPercent, tokenDecimals, poolTyp
677
677
  }
678
678
  case 'V2': {
679
679
  const path = [tokenAddress, WOKB_ADDRESS];
680
+ // ✅ 修复:传入实际数量,避免卖出全部
680
681
  return {
681
682
  target: wallet.address,
682
683
  allowFailure: false,
683
684
  value: 0n,
684
- callData: delegateInterface.encodeFunctionData('executeSellV2', [routerAddress, path, 0]),
685
+ callData: delegateInterface.encodeFunctionData('executeSellV2', [routerAddress, path, sellPercent === 100 ? 0 : 0n]),
685
686
  };
686
687
  }
687
688
  case 'V3': {
689
+ // ✅ 修复:传入实际数量,避免卖出全部
688
690
  return {
689
691
  target: wallet.address,
690
692
  allowFailure: false,
691
693
  value: 0n,
692
694
  callData: delegateInterface.encodeFunctionData('executeSell', [
693
- routerAddress, tokenAddress, WOKB_ADDRESS, fee, 0
695
+ routerAddress, tokenAddress, WOKB_ADDRESS, fee, sellPercent === 100 ? 0 : 0n
694
696
  ]),
695
697
  };
696
698
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.52",
3
+ "version": "1.7.54",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",