@clonegod/ttd-bsc-common 3.0.50 → 3.0.52

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.
@@ -34,9 +34,7 @@ export interface CheckSyncParams {
34
34
  export declare class QuoteAccuracyChecker {
35
35
  private quoteCache;
36
36
  private reserveCache;
37
- private pendingLogs;
38
37
  private get enabled();
39
- getAndClearLog(poolAddress: string): string | null;
40
38
  cacheQuote(poolAddress: string, priceId: string, source: string, askPrice: number, bidPrice: number, blockNumber: number, quoteAmountUsd: number, token0PriceUsd?: number, token1PriceUsd?: number): void;
41
39
  checkSwap(params: CheckSwapParams): void;
42
40
  checkSync(params: CheckSyncParams): void;
@@ -6,17 +6,10 @@ class QuoteAccuracyChecker {
6
6
  constructor() {
7
7
  this.quoteCache = new Map();
8
8
  this.reserveCache = new Map();
9
- this.pendingLogs = new Map();
10
9
  }
11
10
  get enabled() {
12
11
  return process.env.QUOTE_ACCURACY_LOG === 'true';
13
12
  }
14
- getAndClearLog(poolAddress) {
15
- const log = this.pendingLogs.get(poolAddress);
16
- if (log)
17
- this.pendingLogs.delete(poolAddress);
18
- return log || null;
19
- }
20
13
  cacheQuote(poolAddress, priceId, source, askPrice, bidPrice, blockNumber, quoteAmountUsd, token0PriceUsd = 0, token1PriceUsd = 0) {
21
14
  if (!this.enabled)
22
15
  return;
@@ -62,7 +55,7 @@ class QuoteAccuracyChecker {
62
55
  else {
63
56
  return;
64
57
  }
65
- this.compareAndLog(poolAddress, poolName, poolInfo, cached, inputTokenAddress, outputTokenAddress, inputAmountUi, outputAmountUi, cached.token0PriceUsd, cached.token1PriceUsd, token0Address, txHash);
58
+ this.compareAndLog(poolAddress, poolName, poolInfo, cached, inputTokenAddress, outputTokenAddress, inputAmountUi, outputAmountUi, cached.token0PriceUsd, cached.token1PriceUsd, token0Address, blockNumber, txHash);
66
59
  }
67
60
  checkSync(params) {
68
61
  if (!this.enabled)
@@ -104,9 +97,9 @@ class QuoteAccuracyChecker {
104
97
  inputAmountUi = Number(delta1) / Math.pow(10, token1Decimals);
105
98
  outputAmountUi = Number(-delta0) / Math.pow(10, token0Decimals);
106
99
  }
107
- this.compareAndLog(poolAddress, poolName, poolInfo, cached, inputTokenAddress, outputTokenAddress, inputAmountUi, outputAmountUi, cached.token0PriceUsd, cached.token1PriceUsd, token0Address);
100
+ this.compareAndLog(poolAddress, poolName, poolInfo, cached, inputTokenAddress, outputTokenAddress, inputAmountUi, outputAmountUi, cached.token0PriceUsd, cached.token1PriceUsd, token0Address, blockNumber);
108
101
  }
109
- compareAndLog(poolAddress, poolName, poolInfo, cached, inputTokenAddress, outputTokenAddress, inputAmountUi, outputAmountUi, token0PriceUsd, token1PriceUsd, token0Address, txHash) {
102
+ compareAndLog(poolAddress, poolName, poolInfo, cached, inputTokenAddress, outputTokenAddress, inputAmountUi, outputAmountUi, token0PriceUsd, token1PriceUsd, token0Address, swapBlockNumber, txHash) {
110
103
  if (inputAmountUi <= 0 || outputAmountUi <= 0)
111
104
  return;
112
105
  let swapUsd = 0;
@@ -138,10 +131,14 @@ class QuoteAccuracyChecker {
138
131
  const tradeFlow = isBuy
139
132
  ? `${inputAmountUi.toFixed(4)} ${quoteToken.symbol} -> ${outputAmountUi.toFixed(4)} ${baseToken.symbol}`
140
133
  : `${inputAmountUi.toFixed(4)} ${baseToken.symbol} -> ${outputAmountUi.toFixed(4)} ${quoteToken.symbol}`;
141
- const txTag = txHash ? ` tx:${txHash.slice(0, 10)}` : '';
142
- const srcTag = cached.source ? ` [${cached.source}]` : '';
143
- const msg = ` ↳ [QuoteAccuracy] vs blk:${cached.blockNumber}${srcTag} ${side} ${usdStr} (${tradeFlow}), ${isBuy ? 'ask' : 'bid'}=${refPrice.toFixed(12)} vs exec=${execPriceNum.toFixed(12)}, diff=${diffBps > 0 ? '+' : ''}${diffBps.toFixed(1)}bps ${status}${rangeTag}${txTag}`;
144
- this.pendingLogs.set(poolAddress, msg);
134
+ const quoteSrc = cached.source || '?';
135
+ const quoteTag = `quote[${quoteSrc} blk:${cached.blockNumber}]`;
136
+ const swapBlk = swapBlockNumber || '?';
137
+ const swapTx = txHash ? ` ${txHash.slice(0, 10)}` : '';
138
+ const swapTag = `swap[blk:${swapBlk}${swapTx}]`;
139
+ const priceLabel = isBuy ? 'ask' : 'bid';
140
+ const msg = ` ↳ [QuoteAccuracy] ${side} ${usdStr} (${tradeFlow}) ${quoteTag} ${priceLabel}=${refPrice.toFixed(12)} vs ${swapTag} exec=${execPriceNum.toFixed(12)} diff=${diffBps > 0 ? '+' : ''}${diffBps.toFixed(1)}bps ${status}${rangeTag}`;
141
+ console.log(msg);
145
142
  }
146
143
  }
147
144
  exports.QuoteAccuracyChecker = QuoteAccuracyChecker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.0.50",
3
+ "version": "3.0.52",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",