@defillama/sdk 5.0.187 → 5.0.192

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)