@defillama/sdk 5.0.236 → 5.0.238

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/build/ChainApi.js CHANGED
@@ -17,6 +17,15 @@ const logs_1 = __importDefault(require("./util/logs"));
17
17
  const transactions_1 = require("./util/transactions");
18
18
  const callStatsByProject = {};
19
19
  const nullAddress = '0x0000000000000000000000000000000000000000';
20
+ // ERC-20 views of the native coin: balanceOf returns the same balance as eth_getBalance, so when summing
21
+ // they are read as the native coin and deduped per owner, otherwise listing both counts the coin twice
22
+ const nativeTokenAliases = {
23
+ polygon: '0x0000000000000000000000000000000000001010', // POL (MRC20)
24
+ celo: '0x471ece3750da237f93b8e339c536989b8978a438', // CELO (GoldToken)
25
+ metis: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // METIS
26
+ arc: '0x3600000000000000000000000000000000000000', // USDC (6 decimals, native is 18)
27
+ stable: '0x779ded0c9e1022225f8e0630b35a9b54be713736', // USDT0 (6 decimals, native is 18)
28
+ };
20
29
  class ChainApi {
21
30
  constructor(params) {
22
31
  var _a, _b;
@@ -197,6 +206,10 @@ class ChainApi {
197
206
  blacklistedOwners = (0, common_1.getUniqueAddresses)(blacklistedOwners, this.chain);
198
207
  blacklistedTokens = (0, common_1.getUniqueAddresses)(blacklistedTokens, this.chain);
199
208
  tokensAndOwners = tokensAndOwners.filter(i => !blacklistedTokens.includes(i[0]) && !blacklistedOwners.includes(i[1]));
209
+ // only when summing: plain balance lookups expect the alias's own (ERC-20 decimals) value back
210
+ const nativeAlias = nativeTokenAliases[this.chain];
211
+ if (skipDuplicates && nativeAlias)
212
+ tokensAndOwners = getUniqueTokensAndOwners(tokensAndOwners.map(([t, o]) => [t === nativeAlias ? nullAddress : t, o]), this.chain);
200
213
  const tokenBalances = [];
201
214
  const erc20TokensResponseIndex = [];
202
215
  const ethBalanceResponseIndex = [];
package/build/abi/tron.js CHANGED
@@ -65,7 +65,13 @@ async function getBalance(params) {
65
65
  throw new Error('getBalance: target is required');
66
66
  const data = await limitRPCCalls(() => {
67
67
  if (!balanceCache[params.target])
68
- balanceCache[params.target] = post({ address: params.target, visible: true, }, '/wallet/getaccount');
68
+ // drop the entry if the request fails, otherwise the rejected promise is served to every
69
+ // later call for this address and the process never retries it
70
+ balanceCache[params.target] = post({ address: params.target, visible: true, }, '/wallet/getaccount')
71
+ .catch((e) => {
72
+ delete balanceCache[params.target];
73
+ throw e;
74
+ });
69
75
  return balanceCache[params.target];
70
76
  });
71
77
  const frozenBalance = (_b = (_a = data.frozen) === null || _a === void 0 ? void 0 : _a.reduce((t, { frozen_balance }) => t + frozen_balance, 0)) !== null && _b !== void 0 ? _b : 0;