@defillama/sdk 3.0.8 → 3.0.10

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.
@@ -2,7 +2,7 @@ import { ethers, BigNumber } from "ethers";
2
2
  export declare const providers: {
3
3
  [chain: string]: ethers.providers.BaseProvider;
4
4
  };
5
- export type Chain = "ethereum" | "bsc" | "polygon" | "heco" | "fantom" | "rsk" | "tomochain" | "xdai" | "avax" | "wan" | "iotex" | "harmony" | "thundercore" | "okexchain" | "optimism" | "arbitrum" | "kcc" | "celo" | "moonriver" | "shiden" | "palm" | "energyweb" | "energi" | "songbird" | "hpb" | "gochain" | "ethereumclassic" | "xdaiarb" | "kardia" | "fuse" | "smartbch" | "elastos" | "hoo" | "fusion" | "aurora" | "ronin" | "boba" | "cronos" | "polis" | "zyx" | "telos" | "metis" | "ubiq" | "velas" | "callisto" | "csc" | "nahmii" | "liquidchain" | "meter" | "theta" | "oasis" | "syscoin" | "moonbeam" | "curio" | "astar" | "godwoken" | "evmos" | "conflux" | "milkomeda" | "milkomeda_a1" | "dfk" | "bittorrent" | "findora" | "candle" | "lachain" | "reichain" | "rei" | "clv" | "echelon" | "multivac" | "sx" | "karura_evm" | "nova" | "ontology_evm" | "jfin" | "bitkub" | "bitgert" | "canto" | "dogechain" | "posi" | "arbitrum_nova" | "ultron" | "tombchain" | "vision" | "ethpow" | "functionx" | "cube" | "xdc" | "step" | "kekchain" | "muuchain";
5
+ export type Chain = "ethereum" | "bsc" | "polygon" | "heco" | "fantom" | "rsk" | "tomochain" | "xdai" | "avax" | "wan" | "iotex" | "harmony" | "thundercore" | "okexchain" | "optimism" | "arbitrum" | "kcc" | "celo" | "moonriver" | "shiden" | "palm" | "energyweb" | "energi" | "songbird" | "hpb" | "gochain" | "ethereumclassic" | "xdaiarb" | "kardia" | "fuse" | "smartbch" | "elastos" | "hoo" | "fusion" | "aurora" | "ronin" | "boba" | "cronos" | "polis" | "zyx" | "telos" | "metis" | "ubiq" | "velas" | "callisto" | "csc" | "nahmii" | "liquidchain" | "meter" | "theta" | "oasis" | "syscoin" | "moonbeam" | "curio" | "astar" | "godwoken" | "evmos" | "conflux" | "milkomeda" | "milkomeda_a1" | "dfk" | "bittorrent" | "findora" | "candle" | "lachain" | "reichain" | "rei" | "clv" | "echelon" | "multivac" | "sx" | "karura_evm" | "nova" | "ontology_evm" | "jfin" | "bitkub" | "bitgert" | "canto" | "dogechain" | "posi" | "arbitrum_nova" | "ultron" | "tombchain" | "vision" | "ethpow" | "functionx" | "cube" | "xdc" | "step" | "kekchain" | "muuchain" | "dexit";
6
6
  export declare function getProvider(chain?: Chain): ethers.providers.BaseProvider;
7
7
  export declare const TEN: ethers.BigNumber;
8
8
  export declare function handleDecimals(num: BigNumber, decimals?: number): string;
package/build/general.js CHANGED
@@ -133,6 +133,7 @@ exports.providers = {
133
133
  kekchain: createProvider("kekchain", "https://mainnet.kekchain.com", 420420),
134
134
  step: createProvider("step", "https://rpc.step.network/", 1234),
135
135
  muuchain: createProvider("muu", "https://mainnet-rpc.muuchain.com", 20402),
136
+ dexit: createProvider("dexit", "https://dxt.dexit.network", 877),
136
137
  };
137
138
  function getProvider(chain) {
138
139
  if (chain === void 0) { chain = "ethereum"; }
@@ -12,8 +12,8 @@ export declare function getLatestBlock(chain: string): Promise<TimestampBlock>;
12
12
  export declare function lookupBlock(timestamp: number, extraParams?: {
13
13
  chain?: Chain | "terra" | "kava" | "algorand";
14
14
  }): Promise<{
15
- block: number;
16
15
  timestamp: number;
16
+ block: any;
17
17
  }>;
18
18
  export declare function getLogs(params: {
19
19
  target: Address;
@@ -154,21 +154,35 @@ function lookupBlock(timestamp, extraParams) {
154
154
  var _a, _b, _c;
155
155
  if (extraParams === void 0) { extraParams = {}; }
156
156
  return __awaiter(this, void 0, void 0, function () {
157
- var chain, low, lowBlock, highBlock, provider, _d, lastBlock, firstBlock, block, i, time, allowedTimeRange, acceptableBlockImprecision, blockImprecision, imprecision, getPrecision_1, blockDiff, timeDiff, avgBlockTime, closeBlock, midBlock, blocks, e_1;
157
+ var chain, api, res, data, low, lowBlock, highBlock, provider, _d, lastBlock, firstBlock, block, i, time, allowedTimeRange, acceptableBlockImprecision, blockImprecision, imprecision, getPrecision_1, blockDiff, timeDiff, avgBlockTime, closeBlock, midBlock, blocks, e_1;
158
158
  return __generator(this, function (_e) {
159
159
  switch (_e.label) {
160
160
  case 0:
161
161
  chain = (_a = extraParams === null || extraParams === void 0 ? void 0 : extraParams.chain) !== null && _a !== void 0 ? _a : "ethereum";
162
- low = (_b = intialBlocks[chain]) !== null && _b !== void 0 ? _b : 100;
163
- _e.label = 1;
162
+ if (!(chain === 'celo')) return [3 /*break*/, 3];
163
+ api = "https://explorer.celo.org/mainnet/api?module=block&action=getblocknobytime&timestamp=".concat(timestamp, "&closest=before");
164
+ return [4 /*yield*/, (0, node_fetch_1.default)(api)];
164
165
  case 1:
165
- _e.trys.push([1, 7, , 8]);
166
+ res = _e.sent();
167
+ return [4 /*yield*/, res.json()];
168
+ case 2:
169
+ data = _e.sent();
170
+ console.log(data);
171
+ return [2 /*return*/, {
172
+ timestamp: timestamp,
173
+ block: data.result.blockNumber
174
+ }];
175
+ case 3:
176
+ low = (_b = intialBlocks[chain]) !== null && _b !== void 0 ? _b : 100;
177
+ _e.label = 4;
178
+ case 4:
179
+ _e.trys.push([4, 10, , 11]);
166
180
  provider = getExtraProvider(chain);
167
181
  return [4 /*yield*/, Promise.all([
168
182
  getBlock(provider, "latest", chain),
169
183
  getBlock(provider, low, chain),
170
184
  ])];
171
- case 2:
185
+ case 5:
172
186
  _d = _e.sent(), lastBlock = _d[0], firstBlock = _d[1];
173
187
  lowBlock = firstBlock;
174
188
  highBlock = lastBlock;
@@ -191,8 +205,8 @@ function lookupBlock(timestamp, extraParams) {
191
205
  blockImprecision = void 0;
192
206
  imprecision = void 0;
193
207
  getPrecision_1 = function (block) { return block.timestamp - timestamp > 0 ? block.timestamp - timestamp : timestamp - block.timestamp; };
194
- _e.label = 3;
195
- case 3:
208
+ _e.label = 6;
209
+ case 6:
196
210
  ++i;
197
211
  blockDiff = highBlock.number - lowBlock.number;
198
212
  timeDiff = highBlock.timestamp - lowBlock.timestamp;
@@ -203,7 +217,7 @@ function lookupBlock(timestamp, extraParams) {
203
217
  getBlock(provider, closeBlock, chain),
204
218
  getBlock(provider, midBlock, chain),
205
219
  ])];
206
- case 4:
220
+ case 7:
207
221
  blocks = _e.sent();
208
222
  blocks.push(highBlock, lowBlock);
209
223
  blocks.sort(function (a, b) { return getPrecision_1(a) - getPrecision_1(b); });
@@ -213,11 +227,11 @@ function lookupBlock(timestamp, extraParams) {
213
227
  highBlock = blocks.filter(function (i) { return i.timestamp > timestamp; }).reduce(function (highestBlock, block) { return (highestBlock.timestamp - timestamp) < (block.timestamp - timestamp) ? highestBlock : block; });
214
228
  imprecision = getPrecision_1(block);
215
229
  blockImprecision = highBlock.number - lowBlock.number;
216
- _e.label = 5;
217
- case 5:
218
- if (imprecision > allowedTimeRange && blockImprecision > acceptableBlockImprecision) return [3 /*break*/, 3];
219
- _e.label = 6;
220
- case 6:
230
+ _e.label = 8;
231
+ case 8:
232
+ if (imprecision > allowedTimeRange && blockImprecision > acceptableBlockImprecision) return [3 /*break*/, 6];
233
+ _e.label = 9;
234
+ case 9:
221
235
  (0, debugLog_1.debugLog)("chain: ".concat(chain, " block: ").concat(block.number, " #calls: ").concat(i, " imprecision: ").concat(Number((imprecision) / 60).toFixed(2), " (min) Time Taken: ").concat(Number((Date.now() - time) / 1000).toFixed(2), " (in sec)"));
222
236
  if (chain !== "bsc" && // this check is there because bsc halted the chain for few days
223
237
  Math.abs(block.timestamp - timestamp) > 3600) {
@@ -227,11 +241,11 @@ function lookupBlock(timestamp, extraParams) {
227
241
  block: block.number,
228
242
  timestamp: block.timestamp
229
243
  }];
230
- case 7:
244
+ case 10:
231
245
  e_1 = _e.sent();
232
246
  console.log(e_1);
233
247
  throw new Error("Couldn't find block height for chain ".concat(chain, ", RPC node rugged"));
234
- case 8: return [2 /*return*/];
248
+ case 11: return [2 /*return*/];
235
249
  }
236
250
  });
237
251
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "3.0.8",
3
+ "version": "3.0.10",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {