@defillama/sdk 5.0.169 → 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.
@@ -31,13 +31,30 @@ export declare class Balances {
31
31
  removeTokenBalance(token: string): void;
32
32
  getUSDValue(): Promise<number>;
33
33
  getUSDString(): Promise<string>;
34
- getUSDJSONs(): Promise<{
34
+ getUSDJSONs({ debug, debugOptions: { printTokenTable, minTokenUSDValue } }?: {
35
+ debug?: boolean;
36
+ debugOptions?: {
37
+ printTokenTable?: boolean;
38
+ minTokenUSDValue?: number;
39
+ };
40
+ }): Promise<{
35
41
  usdTvl: number;
36
42
  usdTokenBalances: BalancesV1;
37
43
  rawTokenBalances: BalancesV1;
38
44
  labelBreakdown?: {
39
45
  [key: string]: number;
40
46
  };
47
+ debugData?: {
48
+ tokenData: {
49
+ balance: string | number;
50
+ price: number;
51
+ decimals: number;
52
+ value: number;
53
+ confidence: number;
54
+ token: string;
55
+ symbol: string;
56
+ }[];
57
+ };
41
58
  }>;
42
59
  resizeBy(ratio: number): this;
43
60
  static getUSDValue(balances: BalancesV1, timestamp?: number): Promise<number>;
@@ -45,6 +62,17 @@ export declare class Balances {
45
62
  static getBalanceObjects(balances: BalancesV1, timestamp?: number): Promise<{
46
63
  usdTvl: number;
47
64
  usdTokenBalances: BalancesV1;
65
+ debugData: {
66
+ tokenData: {
67
+ balance: string | number;
68
+ price: number;
69
+ decimals: number;
70
+ value: number;
71
+ confidence: number;
72
+ token: string;
73
+ symbol: string;
74
+ }[];
75
+ };
48
76
  }>;
49
77
  static getUSDJSONs(balances: BalancesV1, timestamp?: number): Promise<{
50
78
  usdTvl: number;
@@ -59,6 +87,7 @@ export declare class Balances {
59
87
  [key: string]: any;
60
88
  }>;
61
89
  hasBreakdownBalances(): boolean;
90
+ isEmpty(): boolean;
62
91
  getBreakdownBalances(): {
63
92
  [key: string]: Balances;
64
93
  };
package/build/Balances.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Balances = void 0;
7
7
  const generalUtil_1 = require("./generalUtil");
8
8
  const computeTVL_1 = __importDefault(require("./util/computeTVL"));
9
+ const humanizeNumber_1 = require("./computeTVL/humanizeNumber");
9
10
  const nullAddress = '0x0000000000000000000000000000000000000000';
10
11
  // the last parameter of add function can be either a string or an object with options (or both as last two parameters)
11
12
  function getOptions({ optionsOrLabel = {}, options = {} } = {}) {
@@ -153,9 +154,29 @@ class Balances {
153
154
  async getUSDString() {
154
155
  return Number(await this.getUSDValue()).toFixed(0);
155
156
  }
156
- async getUSDJSONs() {
157
- const { usdTvl, usdTokenBalances } = await (0, computeTVL_1.default)(this.getBalances(), this.timestamp);
157
+ async getUSDJSONs({ debug = false, debugOptions: { printTokenTable = true, minTokenUSDValue } = {} } = {}) {
158
+ const { usdTvl, usdTokenBalances, debugData } = await (0, computeTVL_1.default)(this.getBalances(), this.timestamp, { debug });
158
159
  const response = { usdTvl, usdTokenBalances, rawTokenBalances: this.getBalances(), labelBreakdown: {} };
160
+ if (debug) {
161
+ response.debugData = debugData;
162
+ if (!minTokenUSDValue && minTokenUSDValue !== 0) {
163
+ minTokenUSDValue = usdTvl / 100; // default to 1% of total TVL
164
+ }
165
+ let tokenData = debugData.tokenData;
166
+ // filter out tokens with value less than minTokenUSDValue
167
+ if (minTokenUSDValue)
168
+ tokenData = tokenData.filter((i) => +i.value >= minTokenUSDValue);
169
+ tokenData.sort((a, b) => b.value - a.value); // sort descending by value
170
+ if (printTokenTable) {
171
+ const dataClone = tokenData.map((i) => ({ ...i, value: (0, humanizeNumber_1.humanizeNumber)(i.value), }));
172
+ console.log((0, generalUtil_1.tableToString)(dataClone));
173
+ }
174
+ // add a humanized value field so it's easier to read big numbers
175
+ tokenData.forEach((i) => {
176
+ i.valueHN = (0, humanizeNumber_1.humanizeNumber)(i.value);
177
+ });
178
+ debugData.tokenData = tokenData;
179
+ }
159
180
  if (!this.hasBreakdownBalances())
160
181
  return response;
161
182
  for (const [label, breakdown] of Object.entries(this.getBreakdownBalances())) {
@@ -232,7 +253,10 @@ class Balances {
232
253
  return response;
233
254
  }
234
255
  hasBreakdownBalances() {
235
- return Object.keys(this._breakdownBalances).length > 0;
256
+ return Object.keys(this._breakdownBalances).length > 0 && Object.values(this._breakdownBalances).some(b => !b.isEmpty());
257
+ }
258
+ isEmpty() {
259
+ return Object.keys(this._balances).length === 0;
236
260
  }
237
261
  getBreakdownBalances() {
238
262
  return this._breakdownBalances;
@@ -82,6 +82,17 @@ export declare class ChainApi {
82
82
  labelBreakdown?: {
83
83
  [key: string]: number;
84
84
  } | undefined;
85
+ debugData?: {
86
+ tokenData: {
87
+ balance: string | number;
88
+ price: number;
89
+ decimals: number;
90
+ value: number;
91
+ confidence: number;
92
+ token: string;
93
+ symbol: string;
94
+ }[];
95
+ } | undefined;
85
96
  }>;
86
97
  getLogs(params: GetLogsOptions): Promise<any[] | import("ethers").EventLog[] | import("ethers").EventLog[][]>;
87
98
  getBalancesV2(): Balances;
@@ -211,6 +211,8 @@ const DEPLOYMENT_BLOCK = {
211
211
  somnia: 1,
212
212
  camp: 1,
213
213
  bitci: 1,
214
+ plasma: 1,
215
+ eteria: 918,
214
216
  };
215
217
  async function makeMultiCall(functionABI, calls, chain, block) {
216
218
  if (chain === 'tron')
@@ -313,4 +315,5 @@ const CUSTOM_MULTICALL_ADDRESSES = {
313
315
  'eventum': '0xc7dEfc896E1Dd9D98AEa402d928C78c0FD1dc36C',
314
316
  'somnia': '0x5e44F178E8cF9B2F5409B6f18ce936aB817C5a11',
315
317
  'bitci': '0x777238B119cD07e6849b0817f284532DC0F9F8D9',
318
+ 'eteria': '0x8cC688B1F99b651ee00bB0Cb0aae61F416F8384b',
316
319
  };