@defillama/sdk 5.0.170 → 5.0.172

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.
@@ -229,7 +229,8 @@ async function _lookupBlock(timestamp, extraParams) {
229
229
  ]);
230
230
  updateBlock(blocks);
231
231
  }
232
- (0, debugLog_1.debugLog)(`chain: ${chain} block: ${block.number} #calls: ${i} imprecision: ${Number((imprecision) / 60).toFixed(2)} (min) Time Taken: ${Number((Date.now() - time) / 1000).toFixed(2)} (in sec)`);
232
+ if (i > 2)
233
+ (0, debugLog_1.debugLog)(`chain: ${chain} block: ${block.number} #calls: ${i} imprecision: ${Number((imprecision) / 60).toFixed(2)} (min) Time Taken: ${Number((Date.now() - time) / 1000).toFixed(2)} (in sec)`);
233
234
  if (chain !== "bsc" && // this check is there because bsc halted the chain for few days
234
235
  Math.abs(block.timestamp - timestamp) > 3600) {
235
236
  throw new Error("Block selected is more than 1 hour away from the requested timestamp");
@@ -204,7 +204,7 @@ async function deleteCache(file) {
204
204
  }
205
205
  exports.deleteCache = deleteCache;
206
206
  async function readExpiringJsonCache(file) {
207
- const options = { readFromR2Cache: false, skipR2Cache: true };
207
+ const options = { readFromR2Cache: false, skipR2Cache: true, skipCompression: true };
208
208
  file = 'expiring/' + file;
209
209
  const data = await readCache(file, options);
210
210
  if (!data || Object.keys(data).length === 0)
@@ -1,6 +1,19 @@
1
1
  import { Balances } from "../types";
2
- export default function computeTVL(balances: Balances, timestamp?: number): Promise<{
2
+ export default function computeTVL(balances: Balances, timestamp?: number, { debug }?: {
3
+ debug?: boolean;
4
+ }): Promise<{
3
5
  usdTvl: number;
4
6
  usdTokenBalances: Balances;
7
+ debugData: {
8
+ tokenData: {
9
+ balance: string | number;
10
+ price: number;
11
+ decimals: number;
12
+ value: number;
13
+ confidence: number;
14
+ token: string;
15
+ symbol: string;
16
+ }[];
17
+ };
5
18
  }>;
6
19
  export declare function getUnique(addresses: string[]): string[];
@@ -13,8 +13,11 @@ const priceCaches = {};
13
13
  let lastPriceUpdate = 0;
14
14
  const confidenceThreshold = 0.5;
15
15
  const priceUpdateTime = 1000 * 60 * 30; // 30 minutes
16
- async function computeTVL(balances, timestamp) {
16
+ async function computeTVL(balances, timestamp, { debug = false } = {}) {
17
17
  const usdTokenBalances = {};
18
+ const debugData = {
19
+ tokenData: []
20
+ };
18
21
  let usdTvl = 0;
19
22
  const keys = Object.keys(balances)
20
23
  // .filter(i => +balances[i] > 0)
@@ -36,8 +39,10 @@ async function computeTVL(balances, timestamp) {
36
39
  if (symbol === 'ETH')
37
40
  symbol = 'WETH';
38
41
  (0, generalUtil_1.sumSingleBalance)(usdTokenBalances, symbol, value);
42
+ if (debug && !isNaN(+value))
43
+ debugData.tokenData.push({ symbol, value, token, price, confidence, balance, decimals, });
39
44
  });
40
- return { usdTvl, usdTokenBalances };
45
+ return { usdTvl, usdTokenBalances, debugData, };
41
46
  }
42
47
  exports.default = computeTVL;
43
48
  function tokenToKey(token) {
@@ -87,6 +87,7 @@ async function main() {
87
87
  if (droppedChains.length > 20) {
88
88
  throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${droppedChains.join('\n')}`);
89
89
  }
90
+ delete providerList.bitcoin; // what were they smoking?
90
91
  fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
91
92
  }
92
93
  const blacklist = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.170",
3
+ "version": "5.0.172",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {