four-flap-meme-sdk 1.7.63 → 1.7.64

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.
@@ -119,13 +119,14 @@ function encodeV2BuyCall(tokenAddress, recipient, deadline) {
119
119
  }
120
120
  /**
121
121
  * 构建利润转账调用
122
+ * ✅ 使用 transferAmount 从钱包余额转出,而不是 msg.value
122
123
  */
123
124
  function buildProfitCall(walletAddress, profitAmount, profitRecipient, delegateInterface) {
124
125
  return {
125
126
  target: walletAddress,
126
127
  allowFailure: false,
127
- value: profitAmount,
128
- callData: delegateInterface.encodeFunctionData('transferTo', [profitRecipient]),
128
+ value: 0n, // ✅ 不需要 msg.value,从钱包余额转出
129
+ callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
129
130
  };
130
131
  }
131
132
  // ========================================
@@ -262,8 +263,8 @@ export async function bundleCreateBuy(params) {
262
263
  callData: buyBatchCall,
263
264
  });
264
265
  }
265
- // ✅ 修复:各钱包使用自己余额买入,主交易只支付利润和创建费用
266
- const totalValue = profitAmount + (params.quoteAmt ?? 0n);
266
+ // ✅ 利润从开发者钱包余额转出,主交易只支付创建费用
267
+ const totalValue = params.quoteAmt ?? 0n;
267
268
  // 构建签名交易
268
269
  const signedTransaction = buildEIP7702TransactionSync(mainWallet, authorizations, calls, totalValue, nonces[0], feeData, config);
269
270
  return {
@@ -417,8 +418,8 @@ export async function bundleCreateToDex(params) {
417
418
  });
418
419
  }
419
420
  }
420
- // ✅ 修复:各钱包使用自己余额买入,主交易只支付利润和创建费用
421
- const totalValue = profitAmount + (params.quoteAmt ?? 0n);
421
+ // ✅ 利润从 Payer 钱包余额转出,主交易只支付创建费用
422
+ const totalValue = params.quoteAmt ?? 0n;
422
423
  // 构建签名交易(一键发射会触发毕业,使用高 gas limit)
423
424
  const toDexConfig = {
424
425
  ...config,
@@ -616,8 +617,8 @@ export async function bundleGraduateBuy(params) {
616
617
  });
617
618
  }
618
619
  }
619
- // ✅ 修复:各钱包使用自己余额买入,主交易只支付利润
620
- const totalValue = profitAmount;
620
+ // ✅ 利润从 Payer 钱包余额转出,主交易不需要支付额外费用
621
+ const totalValue = 0n;
621
622
  // 构建签名交易(毕业操作强制使用高 gas limit)
622
623
  const graduateConfig = {
623
624
  ...config,
@@ -404,8 +404,10 @@ export async function bundleSwap(params) {
404
404
  callData: delegateInterface.encodeFunctionData('transferTo', [nextRecipient]),
405
405
  });
406
406
  }
407
- // 4. 买家买入(使用收到的全部 OKB
408
- const buyCall = buildBuyCallInternal(buyerWallet, tradeType === 'FLAP' ? buyAmountAfterProfit : 0n, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
407
+ // 4. 买家买入(使用收到的 OKB,按卖出所得计算)
408
+ // 资金利用率模式下,所有 tradeType 都使用精确金额
409
+ const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, // ✅ 使用卖出所得(扣除利润)
410
+ tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
409
411
  calls.push(buyCall);
410
412
  }
411
413
  else {
@@ -428,9 +430,8 @@ export async function bundleSwap(params) {
428
430
  callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
429
431
  });
430
432
  }
431
- // 3. 买家用自己的 OKB 买入
432
- const buyAmountForCall = tradeType === 'FLAP' ? buyAmountAfterProfit : 0n;
433
- const buyCall = buildBuyCallInternal(buyerWallet, buyAmountForCall, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
433
+ // 3. 买家用自己的 OKB 买入(金额 = 卖家卖出所得,避免买卖资金不匹配)
434
+ const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
434
435
  calls.push(buyCall);
435
436
  }
436
437
  // ========================================
@@ -542,32 +543,32 @@ export async function bundleBatchSwap(params) {
542
543
  // 构建调用
543
544
  // ========================================
544
545
  const calls = [];
545
- // 计算每个买家的买入金额
546
+ // 计算每个买家的买入金额
547
+ // 所有模式都按比例分配卖家卖出所得,避免买卖资金不匹配
546
548
  let buyAmountsPerBuyer;
547
- if (tradeType === 'FLAP') {
548
- if (buyerWallets.length === 1) {
549
- buyAmountsPerBuyer = [totalBuyAmountAfterProfit];
550
- }
551
- else if (buyerRatios && buyerRatios.length === buyerWallets.length) {
552
- let allocated = 0n;
553
- buyAmountsPerBuyer = buyerRatios.map((ratio, i) => {
554
- const amount = (totalBuyAmountAfterProfit * BigInt(Math.round(ratio * 10000))) / 10000n;
555
- if (i === buyerRatios.length - 1) {
556
- return totalBuyAmountAfterProfit - allocated;
557
- }
558
- allocated += amount;
559
- return amount;
560
- });
561
- }
562
- else {
563
- const avgAmount = totalBuyAmountAfterProfit / BigInt(buyerWallets.length);
564
- const remainder = totalBuyAmountAfterProfit % BigInt(buyerWallets.length);
565
- buyAmountsPerBuyer = buyerWallets.map((_, i) => i === buyerWallets.length - 1 ? avgAmount + remainder : avgAmount);
566
- }
549
+ if (buyerWallets.length === 1) {
550
+ // 单买家:使用全部卖出所得
551
+ buyAmountsPerBuyer = [totalBuyAmountAfterProfit];
552
+ }
553
+ else if (buyerRatios && buyerRatios.length === buyerWallets.length) {
554
+ // 多买家 + 有比例:按前端传入的比例分配
555
+ let allocated = 0n;
556
+ buyAmountsPerBuyer = buyerRatios.map((ratio, i) => {
557
+ const amount = (totalBuyAmountAfterProfit * BigInt(Math.round(ratio * 10000))) / 10000n;
558
+ if (i === buyerRatios.length - 1) {
559
+ return totalBuyAmountAfterProfit - allocated;
560
+ }
561
+ allocated += amount;
562
+ return amount;
563
+ });
567
564
  }
568
565
  else {
569
- buyAmountsPerBuyer = buyerWallets.map(() => 0n);
566
+ // 多买家无比例:均分
567
+ const avgAmount = totalBuyAmountAfterProfit / BigInt(buyerWallets.length);
568
+ const remainder = totalBuyAmountAfterProfit % BigInt(buyerWallets.length);
569
+ buyAmountsPerBuyer = buyerWallets.map((_, i) => i === buyerWallets.length - 1 ? avgAmount + remainder : avgAmount);
570
570
  }
571
+ console.log(`[bundleBatchSwap] 买入金额分配:`, buyAmountsPerBuyer.map(a => ethers.formatEther(a)));
571
572
  if (useFundUtilization) {
572
573
  // ========================================
573
574
  // ✅ 资金利用率模式(一卖多买)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.63",
3
+ "version": "1.7.64",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",