four-flap-meme-sdk 1.5.34 → 1.5.35

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.
@@ -435,9 +435,11 @@ export class BundleExecutor {
435
435
  nonce: params.nonce,
436
436
  initCode: params.initCode,
437
437
  });
438
- // 计算可归集金额(用已知余额近似;fund 发生时余额会变大,属于可接受的保守近似)
439
- const withdrawAmount = senderBalance > prefundWei + params.reserveWei
440
- ? senderBalance - prefundWei - params.reserveWei
438
+ // 使用最新余额计算可归集金额(避免因预充导致旧余额低估)
439
+ const freshBalance = await this.aaManager.getProvider().getBalance(params.sender);
440
+ const baseBalance = freshBalance > 0n ? freshBalance : senderBalance;
441
+ const withdrawAmount = baseBalance > prefundWei + params.reserveWei
442
+ ? baseBalance - prefundWei - params.reserveWei
441
443
  : 0n;
442
444
  if (withdrawAmount <= 0n) {
443
445
  console.log(`\n[${params.ownerName ?? 'owner'}] 归集后可转出=0(余额不足以覆盖 prefund+reserve)`);
@@ -674,7 +676,7 @@ export class BundleExecutor {
674
676
  },
675
677
  });
676
678
  // 确保 profit sender 有足够余额(用于支付利润转账的 gas)
677
- await this.aaManager.ensureSenderBalance(profitOwner, profitSender, profitPrefund + parseOkb('0.0001'), `profit-transfer-fund`);
679
+ await this.aaManager.ensureSenderBalance(profitOwner, profitSender, nativeProfitAmount + profitPrefund + parseOkb('0.0001'), `profit-transfer-fund`);
678
680
  const signedProfit = await this.aaManager.signUserOp(profitOp, profitOwner);
679
681
  profitOps.push(signedProfit.userOp);
680
682
  }
@@ -1021,7 +1023,7 @@ export class BundleExecutor {
1021
1023
  callGasLimit: effProfitCfgBuySell.fixedGas?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT_WITHDRAW,
1022
1024
  },
1023
1025
  });
1024
- await this.aaManager.ensureSenderBalance(profitOwner, profitSender, profitPrefund + parseOkb('0.0001'), `profit-transfer-fund`);
1026
+ await this.aaManager.ensureSenderBalance(profitOwner, profitSender, nativeBuyProfitAmount + profitPrefund + parseOkb('0.0001'), `profit-transfer-fund`);
1025
1027
  const signedProfit = await this.aaManager.signUserOp(profitOp, profitOwner);
1026
1028
  profitOps.push(signedProfit.userOp);
1027
1029
  }
@@ -123,13 +123,13 @@ export class AAPortalSwapExecutor {
123
123
  })();
124
124
  const quotedSellOutWei = quoted;
125
125
  // 3.1 利润提取(从卖出输出 OKB 里按比例刮取;但必须保证买入资金充足)
126
- const requestedBuyWei = buyAmountOkb
126
+ const profitWeiRaw = extractProfit ? calculateProfitWei(quotedSellOutWei, profitBps) : 0n;
127
+ let requestedBuyWei = buyAmountOkb
127
128
  ? parseOkb(String(buyAmountOkb))
128
- : (quotedSellOutWei * BigInt(10000 - slippageBps)) / 10000n;
129
+ : (quotedSellOutWei - profitWeiRaw);
129
130
  if (requestedBuyWei > quotedSellOutWei) {
130
131
  throw new Error('AA 捆绑换手:buyAmountOkb 超过预估卖出输出(quotedSellOut)');
131
132
  }
132
- const profitWeiRaw = extractProfit ? calculateProfitWei(quotedSellOutWei, profitBps) : 0n;
133
133
  const profitCap = quotedSellOutWei - requestedBuyWei;
134
134
  const profitWei = profitWeiRaw > profitCap ? profitCap : profitWeiRaw;
135
135
  const finalBuyAmountWei = requestedBuyWei;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.5.34",
3
+ "version": "1.5.35",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -36,4 +36,4 @@
36
36
  "devDependencies": {
37
37
  "typescript": "^5.6.3"
38
38
  }
39
- }
39
+ }