four-flap-meme-sdk 1.7.83 → 1.7.85

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.
@@ -61,6 +61,7 @@ export interface PancakeBundleBuyFirstSignParams {
61
61
  startNonces?: number[];
62
62
  buyCount?: number;
63
63
  sellCount?: number;
64
+ taxRateBps?: number;
64
65
  }
65
66
  export interface PancakeBundleBuyFirstParams {
66
67
  buyerPrivateKey: string;
@@ -117,7 +117,8 @@ function splitAmount(totalAmount, count) {
117
117
  }
118
118
  export async function pancakeBundleBuyFirstMerkle(params) {
119
119
  const { buyerPrivateKey, buyerPrivateKeys, sellerPrivateKey, sellerPrivateKeys, tokenAddress, routeParams, buyerFunds, buyerFundsPercentage, config, quoteToken, quoteTokenDecimals = 18, startNonces, // ✅ 可选:前端预获取的 nonces
120
- buyCount: _buyCount, sellCount: _sellCount } = params;
120
+ buyCount: _buyCount, sellCount: _sellCount, taxRateBps = 0 // ✅ 税率(基点),用于计算实际可卖出代币数量
121
+ } = params;
121
122
  // ✅ 判断是否为多钱包模式
122
123
  const isMultiWalletMode = !!(buyerPrivateKeys && buyerPrivateKeys.length > 0) ||
123
124
  !!(sellerPrivateKeys && sellerPrivateKeys.length > 0);
@@ -135,7 +136,8 @@ export async function pancakeBundleBuyFirstMerkle(params) {
135
136
  buyerFunds,
136
137
  config,
137
138
  quoteToken,
138
- quoteTokenDecimals
139
+ quoteTokenDecimals,
140
+ taxRateBps // ✅ 传递税率
139
141
  });
140
142
  }
141
143
  // ✅ 单钱包模式(向后兼容):验证买卖笔数
@@ -169,7 +171,15 @@ export async function pancakeBundleBuyFirstMerkle(params) {
169
171
  });
170
172
  // ✅ 拆分买入和卖出金额
171
173
  const buyAmountsWei = splitAmount(buyerFundsInfo.buyerFundsWei, buyCount);
172
- const sellAmountsWei = splitAmount(quoteResult.quotedTokenOut, sellCount);
174
+ // 税币支持:买入时会被扣税,实际获得的代币 = 报价 * (1 - 税率)
175
+ // 卖出金额需要按扣税后的实际代币数量来计算
176
+ let actualTokenOut = quoteResult.quotedTokenOut;
177
+ if (taxRateBps > 0) {
178
+ // 税率基点转换:500 bps = 5% = 0.05,实际获得 = 报价 * (10000 - 税率) / 10000
179
+ actualTokenOut = (quoteResult.quotedTokenOut * BigInt(10000 - taxRateBps)) / 10000n;
180
+ console.log(`[pancakeBundleBuyFirst] 税币模式: 税率=${taxRateBps}bps, 报价=${quoteResult.quotedTokenOut}, 实际可卖=${actualTokenOut}`);
181
+ }
182
+ const sellAmountsWei = splitAmount(actualTokenOut, sellCount);
173
183
  // ✅ 构建多笔买入和卖出交易
174
184
  const swapUnsignedArray = await buildMultiRouteTransactions({
175
185
  routeParams,
@@ -580,7 +590,8 @@ async function validateFinalBalances({ sameAddress, buyerFundsWei, buyerBalance,
580
590
  * - ✅ 优化:最大化并行操作
581
591
  */
582
592
  async function pancakeBundleBuyFirstMultiWallet(params) {
583
- const { buyerPrivateKeys, sellerPrivateKeys, tokenAddress, routeParams, buyerFunds, config, quoteToken, quoteTokenDecimals = 18 } = params;
593
+ const { buyerPrivateKeys, sellerPrivateKeys, tokenAddress, routeParams, buyerFunds, config, quoteToken, quoteTokenDecimals = 18, taxRateBps = 0 // ✅ 税率(基点)
594
+ } = params;
584
595
  const buyCount = buyerPrivateKeys.length;
585
596
  const sellCount = sellerPrivateKeys.length;
586
597
  if (buyCount === 0)
@@ -645,8 +656,14 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
645
656
  });
646
657
  // ✅ 将总金额平均分配给买方
647
658
  const buyAmountsWei = splitAmount(totalFundsWei, buyCount);
659
+ // ✅ 税币支持:买入时会被扣税,实际获得的代币 = 报价 * (1 - 税率)
660
+ let actualTokenOut = quoteResult.quotedTokenOut;
661
+ if (taxRateBps > 0) {
662
+ actualTokenOut = (quoteResult.quotedTokenOut * BigInt(10000 - taxRateBps)) / 10000n;
663
+ console.log(`[pancakeBundleBuyFirstMultiWallet] 税币模式: 税率=${taxRateBps}bps, 报价=${quoteResult.quotedTokenOut}, 实际可卖=${actualTokenOut}`);
664
+ }
648
665
  // ✅ 将代币平均分配给卖方
649
- const sellAmountsWei = splitAmount(quoteResult.quotedTokenOut, sellCount);
666
+ const sellAmountsWei = splitAmount(actualTokenOut, sellCount);
650
667
  // ✅ 直接使用总交易金额作为利润基础(多钱包模式)
651
668
  // profitRateBps = 每笔交易利润率(bps) * 交易笔数
652
669
  const tokenProfitAmount = (totalFundsWei * BigInt(profitRateBps)) / 10000n;
@@ -80,6 +80,7 @@ export interface LPInfo {
80
80
  reserveNative?: string;
81
81
  circulatingSupply?: string;
82
82
  price?: string;
83
+ taxRate?: number;
83
84
  };
84
85
  allPools: DexPoolInfo[];
85
86
  bestPools: BestPoolInfo[];
@@ -313,7 +313,23 @@ export async function inspectTokenLP(token, opts) {
313
313
  if (opts.flapChain) {
314
314
  try {
315
315
  const flap = new FlapPortal({ chain: opts.flapChain, rpcUrl: opts.rpcUrl });
316
- const st = await flap.getTokenV5(token);
316
+ // 优先尝试 getTokenV7(包含 taxRate),失败则 fallback 到 getTokenV5
317
+ let st = null;
318
+ let taxRate;
319
+ try {
320
+ const stV7 = await flap.getTokenV7(token);
321
+ st = stV7;
322
+ // taxRate 是 bigint,需要转换为 number
323
+ taxRate = typeof stV7.taxRate === 'bigint' ? Number(stV7.taxRate) : Number(stV7.taxRate ?? 0);
324
+ if (opts.debug)
325
+ console.log('[LP Inspect] Flap V7 taxRate:', taxRate);
326
+ }
327
+ catch {
328
+ // V7 不支持,fallback 到 V5
329
+ st = await flap.getTokenV5(token);
330
+ if (opts.debug)
331
+ console.log('[LP Inspect] Flap V7 failed, using V5');
332
+ }
317
333
  if (st && st.status !== undefined && Number(st.status) !== 4) {
318
334
  result.platform = 'FLAP';
319
335
  let quoteDecimals = 18;
@@ -331,6 +347,7 @@ export async function inspectTokenLP(token, opts) {
331
347
  reserveNative: formatBalance(st.reserve, shouldFormat, quoteDecimals),
332
348
  circulatingSupply: formatBalance(st.circulatingSupply, shouldFormat, tokenDecimals ?? 18),
333
349
  price: formatBalance(st.price, shouldFormat),
350
+ taxRate, // ✅ 包含税率
334
351
  };
335
352
  return result;
336
353
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.83",
3
+ "version": "1.7.85",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",