four-flap-meme-sdk 4.0.10 → 4.0.12
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.
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import { Contract, formatEther } from 'ethers';
|
|
8
8
|
import { ADDRESSES, ZERO_ADDRESS } from '../../core/constants/index.js';
|
|
9
9
|
import { Helper3 } from '../four/contracts/helper3.js';
|
|
10
|
-
import { FlapPortal } from '../flap/portal.js';
|
|
10
|
+
import { FlapPortal, TokenStatus, } from '../flap/portal.js';
|
|
11
|
+
import { getTaxTokenInfo, isTaxToken } from '../four/tax-token.js';
|
|
11
12
|
import { DEFAULT_V3_FEE_TIERS } from './lp-inspect-helpers.js';
|
|
12
13
|
import { getChainConfig } from './registry.js';
|
|
13
14
|
import { determinePlatform, formatBalance, getProvider, getTokenDecimals, normalizeLiquidity, queryV2Pairs, queryV3Pools, } from './inspect-helpers.js';
|
|
@@ -15,6 +16,21 @@ import { determinePlatform, formatBalance, getProvider, getTokenDecimals, normal
|
|
|
15
16
|
// 常量(从公共模块导入)
|
|
16
17
|
// ============================================================================
|
|
17
18
|
const MULTICALL3_ADDRESS = ADDRESSES.BSC.Multicall3;
|
|
19
|
+
/** 内盘可交易:1=Tradable,2=InDuel。0=无效(非 Flap 币常见)、3=已杀死、4=已毕业外盘,都不能当内盘提前返回。 */
|
|
20
|
+
function isFlapInnerMarket(status) {
|
|
21
|
+
const n = Number(status);
|
|
22
|
+
return n === TokenStatus.Tradable || n === TokenStatus.InDuel;
|
|
23
|
+
}
|
|
24
|
+
/** BSC V8 买卖税。只有真实 Flap 状态才读买卖税,避免非 Flap 币 slot 残留 100 bps。 */
|
|
25
|
+
function flapV8TaxBps(st) {
|
|
26
|
+
const status = Number(st.status);
|
|
27
|
+
if (status !== TokenStatus.Tradable &&
|
|
28
|
+
status !== TokenStatus.InDuel &&
|
|
29
|
+
status !== TokenStatus.DEX) {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
return Math.max(Number(st.buyTaxRate ?? 0n), Number(st.sellTaxRate ?? 0n));
|
|
33
|
+
}
|
|
18
34
|
// ============================================================================
|
|
19
35
|
// 主查询函数
|
|
20
36
|
// ============================================================================
|
|
@@ -64,30 +80,31 @@ export async function inspectTokenLP(token, opts) {
|
|
|
64
80
|
if (opts.flapChain) {
|
|
65
81
|
try {
|
|
66
82
|
const flap = new FlapPortal({ chain: opts.flapChain, rpcUrl: opts.rpcUrl });
|
|
67
|
-
// ✅ 优先尝试 getTokenV7(包含 taxRate),失败则 fallback 到 getTokenV5
|
|
68
83
|
let st = null;
|
|
69
84
|
let taxRate;
|
|
70
|
-
|
|
85
|
+
const useBscV8 = opts.flapChain === 'BSC';
|
|
86
|
+
if (useBscV8) {
|
|
71
87
|
try {
|
|
72
88
|
const stV8 = await flap.getTokenV8Safe(token);
|
|
73
89
|
st = stV8;
|
|
74
|
-
taxRate =
|
|
90
|
+
taxRate = flapV8TaxBps(stV8);
|
|
75
91
|
}
|
|
76
92
|
catch {
|
|
77
|
-
// V8
|
|
93
|
+
// V8 不可用时只借 V7/V5 读盘面,不用 V7 残留 taxRate(常见 100 bps)
|
|
78
94
|
}
|
|
79
95
|
}
|
|
80
96
|
if (!st) {
|
|
81
97
|
try {
|
|
82
98
|
const stV7 = await flap.getTokenV7(token);
|
|
83
99
|
st = stV7;
|
|
84
|
-
|
|
100
|
+
if (!useBscV8)
|
|
101
|
+
taxRate = Number(stV7.taxRate ?? 0n);
|
|
85
102
|
}
|
|
86
103
|
catch {
|
|
87
104
|
st = await flap.getTokenV5(token);
|
|
88
105
|
}
|
|
89
106
|
}
|
|
90
|
-
if (st &&
|
|
107
|
+
if (st && isFlapInnerMarket(st.status)) {
|
|
91
108
|
result.platform = 'FLAP';
|
|
92
109
|
let quoteDecimals = 18;
|
|
93
110
|
let quoteSymbol = chainConfig.wrappedNativeSymbol;
|
|
@@ -190,6 +207,17 @@ export async function inspectTokenLP(token, opts) {
|
|
|
190
207
|
const offerTokens = formatBalance(info.offers, shouldFormat);
|
|
191
208
|
const lastPrice = formatBalance(info.lastPrice, shouldFormat);
|
|
192
209
|
result.four = { helper: ADDRESSES.BSC.TokenManagerHelper3, reserveNative, offerTokens, lastPrice };
|
|
210
|
+
try {
|
|
211
|
+
if (await isTaxToken(token, opts.rpcUrl)) {
|
|
212
|
+
const fee = Number((await getTaxTokenInfo(token, opts.rpcUrl)).config.feeRate);
|
|
213
|
+
const taxRate = fee > 0 && fee <= 10 ? fee * 100 : fee;
|
|
214
|
+
if (taxRate > 0)
|
|
215
|
+
result.taxRate = taxRate;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// 非 TaxToken 或读费率失败
|
|
220
|
+
}
|
|
193
221
|
return result;
|
|
194
222
|
}
|
|
195
223
|
}
|
|
@@ -331,14 +359,8 @@ export async function inspectTokenLP(token, opts) {
|
|
|
331
359
|
const flap = new FlapPortal({ chain: opts.flapChain, rpcUrl: opts.rpcUrl });
|
|
332
360
|
let taxRate = 0;
|
|
333
361
|
if (opts.flapChain === 'BSC') {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
taxRate = Math.max(Number(stV8.buyTaxRate ?? 0n), Number(stV8.sellTaxRate ?? 0n));
|
|
337
|
-
}
|
|
338
|
-
catch {
|
|
339
|
-
const stV7 = await flap.getTokenV7(token);
|
|
340
|
-
taxRate = Number(stV7.taxRate ?? 0n);
|
|
341
|
-
}
|
|
362
|
+
const stV8 = await flap.getTokenV8Safe(token);
|
|
363
|
+
taxRate = flapV8TaxBps(stV8);
|
|
342
364
|
}
|
|
343
365
|
else {
|
|
344
366
|
const stV7 = await flap.getTokenV7(token);
|