@defillama/sdk 5.0.185 → 5.0.188

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.
@@ -9,6 +9,7 @@ export declare class Balances {
9
9
  chain: Chain | string;
10
10
  timestamp?: number;
11
11
  _balances: BalancesV1;
12
+ _llamaBalancesObject: boolean;
12
13
  _breakdownBalances: {
13
14
  [key: string]: Balances;
14
15
  };
package/build/Balances.js CHANGED
@@ -34,6 +34,7 @@ class Balances {
34
34
  this.timestamp = params.timestamp;
35
35
  this._balances = {};
36
36
  this._breakdownBalances = {};
37
+ this._llamaBalancesObject = true;
37
38
  }
38
39
  _add(token, balance, optionsOrLabel, options) {
39
40
  var _a;
@@ -218,7 +219,7 @@ class Balances {
218
219
  }
219
220
  subtract(balances, optionsOrLabel, options) {
220
221
  options = getOptions({ optionsOrLabel, options });
221
- if (balances instanceof Balances) {
222
+ if (typeof balances === 'object' && balances !== null && balances._llamaBalancesObject) {
222
223
  if (balances === this)
223
224
  return;
224
225
  balances = balances.getBalances();
@@ -55,6 +55,7 @@ export declare class ChainApi {
55
55
  protocol?: string;
56
56
  });
57
57
  addStat(method: string, value?: any, skipTotal?: boolean): void;
58
+ _setBlockFromTimestamp(): Promise<void>;
58
59
  call(params: CallOptions): Promise<any>;
59
60
  batchCall(params: CallOptions[]): Promise<any[]>;
60
61
  multiCall(params: MulticallOptions): Promise<any[]>;
package/build/ChainApi.js CHANGED
@@ -49,7 +49,17 @@ class ChainApi {
49
49
  this.stats[method] = 0;
50
50
  this.stats[method] += value;
51
51
  }
52
- call(params) {
52
+ // autoset block if timestamp is older than 2 hours
53
+ async _setBlockFromTimestamp() {
54
+ if (this.timestamp && !this.block) {
55
+ const twoHoursAgo = Date.now() / 1000 - 2 * 60 * 60;
56
+ if (this.timestamp > twoHoursAgo)
57
+ return;
58
+ await this.getBlock();
59
+ }
60
+ }
61
+ async call(params) {
62
+ await this._setBlockFromTimestamp();
53
63
  this.addStat('call');
54
64
  return (0, abi2_1.call)({
55
65
  ...params,
@@ -57,27 +67,30 @@ class ChainApi {
57
67
  chain: this.chain,
58
68
  });
59
69
  }
60
- batchCall(params) {
70
+ async batchCall(params) {
61
71
  return Promise.all(params.map(i => this.call(i)));
62
72
  }
63
- multiCall(params) {
73
+ async multiCall(params) {
64
74
  this.addStat('multiCall', params.calls.length, true);
65
75
  this.addStat('call');
76
+ await this._setBlockFromTimestamp();
66
77
  return (0, abi2_1.multiCall)({
67
78
  ...params,
68
79
  block: this.block,
69
80
  chain: this.chain,
70
81
  });
71
82
  }
72
- fetchList(params) {
83
+ async fetchList(params) {
73
84
  this.addStat('fetchList');
85
+ await this._setBlockFromTimestamp();
74
86
  return (0, abi2_1.fetchList)({
75
87
  ...params,
76
88
  block: this.block,
77
89
  chain: this.chain,
78
90
  });
79
91
  }
80
- bytecodeCall(params) {
92
+ async bytecodeCall(params) {
93
+ await this._setBlockFromTimestamp();
81
94
  return (0, abi2_1.bytecodeCall)({
82
95
  ...params,
83
96
  block: this.block,
@@ -165,6 +178,7 @@ class ChainApi {
165
178
  return this.getBalances();
166
179
  }
167
180
  async getTokenBalances({ token, tokens = [], owners = [], owner, tokensAndOwners = [], tokensAndOwners2 = [], blacklistedTokens = [], blacklistedOwners = [], ownerTokens = [], skipDuplicates = false, permitFailure = false, withTokenData = false, }) {
181
+ await this._setBlockFromTimestamp();
168
182
  if (tokensAndOwners2.length)
169
183
  tokensAndOwners.push(...tokensAndOwners2[0].map((i, j) => [i, tokensAndOwners2[1][j]]));
170
184
  if (token)
@@ -198,6 +198,7 @@ const DEPLOYMENT_BLOCK = {
198
198
  stratis: 1420372,
199
199
  '0g': 6546802,
200
200
  besc: 1,
201
+ monad: 1,
201
202
  };
202
203
  async function makeMultiCall(functionABI, calls, chain, block) {
203
204
  if (!functionABI)
@@ -1,6 +1,7 @@
1
1
  import * as blocks from "./computeTVL/blocks";
2
2
  import * as humanizeNumber from "./computeTVL/humanizeNumber";
3
3
  export { sliceIntoChunks, normalizeAddress, getTimestamp, tableToString, } from "./util";
4
+ export { isEvmChain, getEVMChainSet, getEVMProvidersConfigMap, } from "./util/LlamaProvider";
4
5
  export { runInPromisePool } from "./util/promisePool";
5
6
  export { sumMultiBalanceOf, sumSingleBalance, mergeBalances, removeTokenBalance, sumChainTvls, getUniqueAddresses, convertToBigInt, getProviderUrl, formError, formErrorString, shortenString, fetchJson, postJson, tronToEvmAddress, evmToTronAddress, sleep, sleepRandom, getHash, } from './util/common';
6
7
  export { blocks, humanizeNumber, };
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.humanizeNumber = exports.blocks = exports.getHash = exports.sleepRandom = exports.sleep = exports.evmToTronAddress = exports.tronToEvmAddress = exports.postJson = exports.fetchJson = exports.shortenString = exports.formErrorString = exports.formError = exports.getProviderUrl = exports.convertToBigInt = exports.getUniqueAddresses = exports.sumChainTvls = exports.removeTokenBalance = exports.mergeBalances = exports.sumSingleBalance = exports.sumMultiBalanceOf = exports.runInPromisePool = exports.tableToString = exports.getTimestamp = exports.normalizeAddress = exports.sliceIntoChunks = void 0;
36
+ exports.humanizeNumber = exports.blocks = exports.getHash = exports.sleepRandom = exports.sleep = exports.evmToTronAddress = exports.tronToEvmAddress = exports.postJson = exports.fetchJson = exports.shortenString = exports.formErrorString = exports.formError = exports.getProviderUrl = exports.convertToBigInt = exports.getUniqueAddresses = exports.sumChainTvls = exports.removeTokenBalance = exports.mergeBalances = exports.sumSingleBalance = exports.sumMultiBalanceOf = exports.runInPromisePool = exports.getEVMProvidersConfigMap = exports.getEVMChainSet = exports.isEvmChain = exports.tableToString = exports.getTimestamp = exports.normalizeAddress = exports.sliceIntoChunks = void 0;
37
37
  const blocks = __importStar(require("./computeTVL/blocks"));
38
38
  exports.blocks = blocks;
39
39
  const humanizeNumber = __importStar(require("./computeTVL/humanizeNumber"));
@@ -43,6 +43,10 @@ Object.defineProperty(exports, "sliceIntoChunks", { enumerable: true, get: funct
43
43
  Object.defineProperty(exports, "normalizeAddress", { enumerable: true, get: function () { return util_1.normalizeAddress; } });
44
44
  Object.defineProperty(exports, "getTimestamp", { enumerable: true, get: function () { return util_1.getTimestamp; } });
45
45
  Object.defineProperty(exports, "tableToString", { enumerable: true, get: function () { return util_1.tableToString; } });
46
+ var LlamaProvider_1 = require("./util/LlamaProvider");
47
+ Object.defineProperty(exports, "isEvmChain", { enumerable: true, get: function () { return LlamaProvider_1.isEvmChain; } });
48
+ Object.defineProperty(exports, "getEVMChainSet", { enumerable: true, get: function () { return LlamaProvider_1.getEVMChainSet; } });
49
+ Object.defineProperty(exports, "getEVMProvidersConfigMap", { enumerable: true, get: function () { return LlamaProvider_1.getEVMProvidersConfigMap; } });
46
50
  var promisePool_1 = require("./util/promisePool");
47
51
  Object.defineProperty(exports, "runInPromisePool", { enumerable: true, get: function () { return promisePool_1.runInPromisePool; } });
48
52
  // most of the code has been moved to util/common.ts to avoid circular dependencies
package/build/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { debugLog, debugTable } from "./util/debugLog";
2
2
  export { ChainApi } from './ChainApi';
3
3
  export { Balances } from './Balances';
4
- export { getProvider, setProvider } from './general';
4
+ export { getProvider, setProvider, } from './general';
5
5
  export * as util from "./generalUtil";
6
6
  export * as cache from "./util/cache";
7
7
  export { getLogs as getEventLogs } from "./util/logs";
package/build/index.js CHANGED
@@ -39,7 +39,7 @@ var ChainApi_1 = require("./ChainApi");
39
39
  Object.defineProperty(exports, "ChainApi", { enumerable: true, get: function () { return ChainApi_1.ChainApi; } });
40
40
  var Balances_1 = require("./Balances");
41
41
  Object.defineProperty(exports, "Balances", { enumerable: true, get: function () { return Balances_1.Balances; } });
42
- var general_1 = require("./general");
42
+ var general_1 = require("./general"); // need to rethink usage of providers in server repo, it is initally empty
43
43
  Object.defineProperty(exports, "getProvider", { enumerable: true, get: function () { return general_1.getProvider; } });
44
44
  Object.defineProperty(exports, "setProvider", { enumerable: true, get: function () { return general_1.setProvider; } });
45
45
  exports.util = __importStar(require("./generalUtil"));