@clonegod/ttd-bsc-common 3.0.13 → 3.0.15

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.
package/dist/index.d.ts CHANGED
@@ -6,4 +6,3 @@ export * from './types';
6
6
  export * from './utils';
7
7
  export * from './redis';
8
8
  export * from './ws';
9
- export * from './yyws';
package/dist/index.js CHANGED
@@ -22,4 +22,3 @@ __exportStar(require("./types"), exports);
22
22
  __exportStar(require("./utils"), exports);
23
23
  __exportStar(require("./redis"), exports);
24
24
  __exportStar(require("./ws"), exports);
25
- __exportStar(require("./yyws"), exports);
@@ -2,32 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildQuoteFromPriceFeed = buildQuoteFromPriceFeed;
4
4
  const ttd_core_1 = require("@clonegod/ttd-core");
5
- const constants_1 = require("../common/constants");
6
- function isSameToken(addr1, addr2) {
7
- const a = addr1.toLowerCase();
8
- const b = addr2.toLowerCase();
9
- if (a === b)
10
- return true;
11
- const bnbAddrs = [constants_1.WBNB_ADDRESS.toLowerCase(), constants_1.NATIVE_BNB_ADDRESS.toLowerCase()];
12
- return bnbAddrs.includes(a) && bnbAddrs.includes(b);
13
- }
14
5
  function buildQuoteFromPriceFeed(poolInfo, data) {
15
- var _a;
16
- const quoteTokenAddr = ((_a = poolInfo.quote_token) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
6
+ const quoteTokenSymbol = (poolInfo.quote_token || '').toUpperCase();
17
7
  const tokenA = poolInfo.tokenA;
18
8
  const tokenB = poolInfo.tokenB;
19
9
  if (!tokenA || !tokenB) {
20
10
  (0, ttd_core_1.log_warn)(`[PriceFeed] poolInfo missing tokenA/tokenB: ${poolInfo.pool_address}`);
21
11
  return null;
22
12
  }
13
+ const normSymbol = (s) => {
14
+ const u = s.toUpperCase();
15
+ return u === 'WBNB' ? 'BNB' : u;
16
+ };
23
17
  let askPrice;
24
18
  let bidPrice;
25
19
  let baseToken;
26
20
  let quoteToken;
27
- const tokenAIsQuote = isSameToken(tokenA.address, quoteTokenAddr);
28
- const tokenBIsQuote = isSameToken(tokenB.address, quoteTokenAddr);
21
+ const tokenAIsQuote = normSymbol(tokenA.symbol) === normSymbol(quoteTokenSymbol);
22
+ const tokenBIsQuote = normSymbol(tokenB.symbol) === normSymbol(quoteTokenSymbol);
29
23
  if (!tokenAIsQuote && !tokenBIsQuote) {
30
- (0, ttd_core_1.log_warn)(`[PriceFeed] quote_token ${quoteTokenAddr} not found in pool ${poolInfo.pool_name}`);
24
+ (0, ttd_core_1.log_warn)(`[PriceFeed] quote_token ${quoteTokenSymbol} not found in pool ${poolInfo.pool_name} (tokenA=${tokenA.symbol}, tokenB=${tokenB.symbol})`);
31
25
  return null;
32
26
  }
33
27
  if (tokenAIsQuote) {
@@ -38,21 +32,20 @@ function buildQuoteFromPriceFeed(poolInfo, data) {
38
32
  quoteToken = tokenB;
39
33
  baseToken = tokenA;
40
34
  }
41
- const feedToken0 = (data.token0Symbol || '').toUpperCase();
42
- const feedToken1 = (data.token1Symbol || '').toUpperCase();
43
- const baseSymbol = baseToken.symbol.toUpperCase();
44
- const quoteSymbol = quoteToken.symbol.toUpperCase();
45
- const normSymbol = (s) => (s === 'WBNB' ? 'BNB' : s);
46
- if (normSymbol(feedToken0) === normSymbol(quoteSymbol)) {
35
+ const feedToken0 = normSymbol(data.token0Symbol || '');
36
+ const feedToken1 = normSymbol(data.token1Symbol || '');
37
+ const baseSymbolNorm = normSymbol(baseToken.symbol);
38
+ const quoteSymbolNorm = normSymbol(quoteToken.symbol);
39
+ if (normSymbol(feedToken0) === quoteSymbolNorm) {
47
40
  askPrice = data.askToken1InToken0;
48
41
  bidPrice = data.bidToken1InToken0;
49
42
  }
50
- else if (normSymbol(feedToken1) === normSymbol(quoteSymbol)) {
43
+ else if (normSymbol(feedToken1) === quoteSymbolNorm) {
51
44
  askPrice = data.askToken0InToken1;
52
45
  bidPrice = data.bidToken0InToken1;
53
46
  }
54
47
  else {
55
- (0, ttd_core_1.log_warn)(`[PriceFeed] Cannot match quote_token symbol: quote=${quoteSymbol}, feed=[${feedToken0}/${feedToken1}], pool=${poolInfo.pool_name}`);
48
+ (0, ttd_core_1.log_warn)(`[PriceFeed] Cannot match quote_token symbol: quote=${quoteSymbolNorm}, feed=[${feedToken0}/${feedToken1}], pool=${poolInfo.pool_name}`);
56
49
  return null;
57
50
  }
58
51
  if (!askPrice || !bidPrice) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.0.13",
3
+ "version": "3.0.15",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",