four-flap-meme-sdk 1.2.49 → 1.2.51

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.
@@ -107,11 +107,15 @@ export async function pancakeBundleBuyFirstMerkle(params) {
107
107
  gasPrice,
108
108
  txType
109
109
  });
110
- const profitAmount = await estimateProfitAmount({
110
+ // 修复:基于买入金额估算利润,而不是基于卖出预估(因为代币可能还没有流动性)
111
+ // 在先买后卖的场景中,卖出收益 ≈ 买入金额(忽略滑点和手续费)
112
+ const estimatedProfitFromSell = await estimateProfitAmount({
111
113
  provider: context.provider,
112
114
  tokenAddress,
113
115
  sellAmountToken: quoteResult.quotedTokenOut
114
116
  });
117
+ const profitBase = estimatedProfitFromSell > 0n ? estimatedProfitFromSell : (buyerFundsInfo.buyerFundsWei * BigInt(PROFIT_CONFIG.RATE_BPS)) / 10000n;
118
+ const profitAmount = profitBase;
115
119
  const noncePlan = await planNonces({
116
120
  buyer,
117
121
  seller,
@@ -30,6 +30,15 @@ export async function inspectTokenLP(token, opts) {
30
30
  const out = { platform: 'UNKNOWN' };
31
31
  // 默认格式化余额为 Ether 单位
32
32
  const shouldFormat = opts.formatBalances !== false;
33
+ // ✅ 优先查询代币精度(在所有逻辑之前)
34
+ let tokenDecimals;
35
+ try {
36
+ const tokenContract = new Contract(token, I_ERC20_ABI, provider);
37
+ tokenDecimals = await tokenContract.decimals();
38
+ }
39
+ catch {
40
+ // 如果查询失败,保持 undefined
41
+ }
33
42
  // 解析 Multicall3 地址
34
43
  let multicall3 = opts.multicall3 || '';
35
44
  if (!multicall3) {
@@ -41,14 +50,6 @@ export async function inspectTokenLP(token, opts) {
41
50
  multicall3 = '0xca11bde05977b3631167028862be2a173976ca11';
42
51
  }
43
52
  }
44
- // 查询代币精度
45
- try {
46
- const tokenContract = new Contract(token, I_ERC20_ABI, provider);
47
- out.decimals = await tokenContract.decimals();
48
- }
49
- catch {
50
- // 如果查询失败,不设置 decimals(保持 undefined)
51
- }
52
53
  async function resolveFactories() {
53
54
  // 1) 直接给出工厂
54
55
  if (opts.factoryV2 && opts.factoryV3)
@@ -93,6 +94,7 @@ export async function inspectTokenLP(token, opts) {
93
94
  // status: 1=Tradable(内盘),4=DEX(已外盘)
94
95
  if (Number(st.status) !== 4) {
95
96
  out.platform = 'FLAP';
97
+ out.decimals = tokenDecimals;
96
98
  out.flap = {
97
99
  quoteToken: st.quoteTokenAddress,
98
100
  reserveNative: formatBalance(st.reserve, shouldFormat),
@@ -119,6 +121,7 @@ export async function inspectTokenLP(token, opts) {
119
121
  // 若已添加流动性(已上 DEX),则继续外盘检测
120
122
  if (!liquidityAdded) {
121
123
  out.platform = 'FOUR';
124
+ out.decimals = tokenDecimals;
122
125
  const reserveNative = info.funds !== undefined ? formatBalance(info.funds, shouldFormat) : undefined;
123
126
  const offerTokens = info.offers !== undefined ? formatBalance(info.offers, shouldFormat) : undefined;
124
127
  const lastPrice = info.lastPrice !== undefined ? formatBalance(info.lastPrice, shouldFormat) : undefined;
@@ -336,5 +339,7 @@ export async function inspectTokenLP(token, opts) {
336
339
  else if (hasV2) {
337
340
  out.platform = 'PANCAKE_V2';
338
341
  }
342
+ // ✅ 确保返回 decimals
343
+ out.decimals = tokenDecimals;
339
344
  return out;
340
345
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.49",
3
+ "version": "1.2.51",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",