@defillama/sdk 2.3.52 → 2.3.55

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.
@@ -0,0 +1,3 @@
1
+ import { Deferrable } from "@ethersproject/properties";
2
+ import { BaseProvider, BlockTag, TransactionRequest } from "@ethersproject/providers";
3
+ export declare function call(provider: BaseProvider, data: Deferrable<TransactionRequest>, block: BlockTag, chain?: string): Promise<string>;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.call = void 0;
40
+ var events_1 = require("events");
41
+ var DEBUG_MODE_ENABLED = !!process.env.LLAMA_DEBUG_MODE;
42
+ var maxParallelCalls = !!process.env.LLAMA_SDK_MAX_PARALLEL ? +process.env.LLAMA_SDK_MAX_PARALLEL : 100;
43
+ var COUNTERS = {};
44
+ var emitter = new events_1.EventEmitter();
45
+ emitter.setMaxListeners(500000);
46
+ function call(provider, data, block, chain) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ function onComplete() {
49
+ counter.activeWorkers--;
50
+ if (counter.queue.length) {
51
+ var nextRequestId = counter.pickFromTop ? counter.queue.shift() : counter.queue.pop();
52
+ counter.pickFromTop = !counter.pickFromTop;
53
+ emitter.emit(nextRequestId);
54
+ }
55
+ }
56
+ var counter, currentId, eventId, showEveryX, response, e_1;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ if (!chain)
61
+ chain = 'noChain';
62
+ counter = getChainCounter(chain);
63
+ currentId = counter.requestCount++;
64
+ eventId = chain + "-" + currentId;
65
+ if (!(counter.activeWorkers > maxParallelCalls)) return [3 /*break*/, 2];
66
+ counter.queue.push(eventId);
67
+ return [4 /*yield*/, events_1.once(emitter, eventId)];
68
+ case 1:
69
+ _a.sent();
70
+ _a.label = 2;
71
+ case 2:
72
+ counter.activeWorkers++;
73
+ if (DEBUG_MODE_ENABLED) {
74
+ showEveryX = counter.queue.length > 100 ? 50 : 10 // show log fewer times if lot more are queued up
75
+ ;
76
+ if (currentId % showEveryX === 0)
77
+ console.log("chain: " + chain + " request #: " + currentId + " queue: " + counter.queue.length + " active requests: " + counter.activeWorkers);
78
+ }
79
+ _a.label = 3;
80
+ case 3:
81
+ _a.trys.push([3, 5, , 6]);
82
+ return [4 /*yield*/, provider.call(data, block)];
83
+ case 4:
84
+ response = _a.sent();
85
+ onComplete();
86
+ return [3 /*break*/, 6];
87
+ case 5:
88
+ e_1 = _a.sent();
89
+ onComplete();
90
+ throw e_1;
91
+ case 6: return [2 /*return*/, response];
92
+ }
93
+ });
94
+ });
95
+ }
96
+ exports.call = call;
97
+ function getChainCounter(chain) {
98
+ if (!COUNTERS[chain])
99
+ COUNTERS[chain] = {
100
+ activeWorkers: 0,
101
+ queue: [],
102
+ requestCount: 0,
103
+ pickFromTop: true,
104
+ };
105
+ return COUNTERS[chain];
106
+ }
package/build/cli.js CHANGED
File without changes
@@ -47,6 +47,7 @@ export declare const chainToCoingeckoId: {
47
47
  telos: string;
48
48
  moonbeam: string;
49
49
  velas: string;
50
+ milkomeda: string;
50
51
  };
51
52
  export default function (rawBalances: Balances, timestamp: number | "now", verbose?: boolean, knownTokenPrices?: TokenPrices, getCoingeckoLock?: GetCoingeckoLog, coingeckoMaxRetries?: number): Promise<{
52
53
  usdTvl: number;
@@ -109,6 +109,7 @@ exports.chainToCoingeckoId = {
109
109
  telos: "telos",
110
110
  moonbeam: "moonbeam",
111
111
  velas: "velas",
112
+ milkomeda: "milkomeda-cardano",
112
113
  };
113
114
  var chains = Object.keys(exports.chainToCoingeckoId);
114
115
  function getHistoricalChainPrices(ids, timestamp, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries) {
@@ -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 declare type Chain = "ethereum" | "bsc" | "polygon" | "heco" | "fantom" | "rsk" | "tomochain" | "xdai" | "avax" | "wan" | "iotex" | "harmony" | "thundercore" | "okexchain" | "optimism" | "arbitrum" | "energyweb" | "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";
5
+ export declare type Chain = "ethereum" | "bsc" | "polygon" | "heco" | "fantom" | "rsk" | "tomochain" | "xdai" | "avax" | "wan" | "iotex" | "harmony" | "thundercore" | "okexchain" | "optimism" | "arbitrum" | "energyweb" | "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" | "dfk";
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
@@ -44,7 +44,7 @@ exports.providers = {
44
44
  celo: createProvider("celo", "https://forno.celo.org", 42220),
45
45
  iotex: createProvider("iotex", "https://babel-api.mainnet.iotex.io", 4689),
46
46
  moonriver: createProvider("moonriver", "https://rpc.api.moonriver.moonbeam.network/,https://moonriver.api.onfinality.io/public", 1285),
47
- shiden: createProvider("shiden", "https://rpc.shiden.astar.network:8545/", 336),
47
+ shiden: createProvider("shiden", "https://rpc.astar.network:8545,https://astar.api.onfinality.io/public", 336),
48
48
  palm: createProvider("palm", "https://palm-mainnet.infura.io/v3/3a961d6501e54add9a41aa53f15de99b", 11297108109),
49
49
  energyweb: createProvider("energyweb", "https://rpc.energyweb.org", 246),
50
50
  songbird: createProvider("songbird", "https://songbird.towolabs.com/rpc", 19),
@@ -69,7 +69,7 @@ exports.providers = {
69
69
  ubiq: createProvider("ubiq", "https://rpc.octano.dev", 8),
70
70
  velas: createProvider("velas", "https://evmexplorer.velas.com/rpc", 106),
71
71
  callisto: createProvider("callisto", "https://clo-geth.0xinfra.com/", 820),
72
- klaytn: createProvider("klaytn", "http://175.209.78.135:8551", 8217),
72
+ klaytn: createProvider("klaytn", "https://public-node-api.klaytnapi.com/v1/cypress,http://175.209.78.135:8551", 8217),
73
73
  csc: createProvider("csc", "https://rpc.coinex.net/,https://rpc1.coinex.net/,https://rpc2.coinex.net/,https://rpc3.coinex.net/,https://rpc4.coinex.net/", 52),
74
74
  nahmii: createProvider("nahmii", "https://l2.nahmii.io/", 5551),
75
75
  liquidchain: createProvider("xlc", "https://rpc.liquidchain.net/,https://rpc.xlcscan.com/", 5050),
@@ -83,7 +83,9 @@ exports.providers = {
83
83
  godwoken: createProvider("godwoken", "https://mainnet.godwoken.io/rpc/eth-wallet", 71394),
84
84
  evmos: createProvider("evmos", "https://eth.bd.evmos.org:8545/", 9001),
85
85
  conflux: createProvider("conflux", "https://evm.confluxrpc.com", 1030),
86
- milkomeda: createProvider("milkomeda", "https://rpc-mainnet-cardano-evm.c1.milkomeda.com", 2001)
86
+ milkomeda: createProvider("milkomeda", "https://rpc-mainnet-cardano-evm.c1.milkomeda.com", 2001),
87
+ dfk: createProvider("dfk", "https://subnets.avax.network/defi-kingdoms/dfk-chain/rpc", 53935),
88
+ crab: createProvider("crab", "https://crab-rpc.darwinia.network", 44),
87
89
  };
88
90
  function getProvider(chain) {
89
91
  if (chain === void 0) { chain = "ethereum"; }
@@ -115,19 +115,23 @@ function getLatestBlock(chain) {
115
115
  });
116
116
  }
117
117
  exports.getLatestBlock = getLatestBlock;
118
+ var intialBlocks = {
119
+ terra: 4724001,
120
+ crab: 4969901
121
+ };
118
122
  function lookupBlock(timestamp, extraParams) {
119
- var _a, _b, _c;
123
+ var _a, _b, _c, _d, _e;
120
124
  if (extraParams === void 0) { extraParams = {}; }
121
125
  return __awaiter(this, void 0, void 0, function () {
122
126
  var provider, lastBlock, high, low, block, mid, e_1;
123
- return __generator(this, function (_d) {
124
- switch (_d.label) {
127
+ return __generator(this, function (_f) {
128
+ switch (_f.label) {
125
129
  case 0:
126
- _d.trys.push([0, 6, , 7]);
130
+ _f.trys.push([0, 6, , 7]);
127
131
  provider = getExtraProvider(extraParams.chain);
128
132
  return [4 /*yield*/, getBlock(provider, "latest", extraParams.chain)];
129
133
  case 1:
130
- lastBlock = _d.sent();
134
+ lastBlock = _f.sent();
131
135
  if ((lastBlock.timestamp - timestamp) < -30 * 60) {
132
136
  throw new Error("Last block of chain \"" + extraParams.chain + "\" is further than 30 minutes into the past. Provider is \"" + ((_b = (_a = provider) === null || _a === void 0 ? void 0 : _a.connection) === null || _b === void 0 ? void 0 : _b.url) + "\"");
133
137
  }
@@ -139,24 +143,24 @@ function lookupBlock(timestamp, extraParams) {
139
143
  }];
140
144
  }
141
145
  high = lastBlock.number;
142
- low = (extraParams === null || extraParams === void 0 ? void 0 : extraParams.chain) === "terra" ? 4724001 : 0;
146
+ low = (_d = intialBlocks[(_c = extraParams === null || extraParams === void 0 ? void 0 : extraParams.chain) !== null && _c !== void 0 ? _c : "ethereum"]) !== null && _d !== void 0 ? _d : 0;
143
147
  block = void 0;
144
- _d.label = 2;
148
+ _f.label = 2;
145
149
  case 2:
146
150
  mid = Math.floor((high + low) / 2);
147
151
  return [4 /*yield*/, getBlock(provider, mid, extraParams.chain)];
148
152
  case 3:
149
- block = _d.sent();
153
+ block = _f.sent();
150
154
  if (block.timestamp < timestamp) {
151
155
  low = mid + 1;
152
156
  }
153
157
  else {
154
158
  high = mid - 1;
155
159
  }
156
- _d.label = 4;
160
+ _f.label = 4;
157
161
  case 4:
158
162
  if (high - low > 4) return [3 /*break*/, 2];
159
- _d.label = 5;
163
+ _f.label = 5;
160
164
  case 5:
161
165
  if (Math.abs(block.timestamp - timestamp) > 3600) {
162
166
  throw new Error("Block selected is more than 1 hour away from the requested timestamp");
@@ -166,9 +170,9 @@ function lookupBlock(timestamp, extraParams) {
166
170
  timestamp: block.timestamp,
167
171
  }];
168
172
  case 6:
169
- e_1 = _d.sent();
173
+ e_1 = _f.sent();
170
174
  console.log(e_1);
171
- throw new Error("Couldn't find block height for chain " + ((_c = extraParams.chain) !== null && _c !== void 0 ? _c : 'ethereum') + ", RPC node rugged");
175
+ throw new Error("Couldn't find block height for chain " + ((_e = extraParams.chain) !== null && _e !== void 0 ? _e : 'ethereum') + ", RPC node rugged");
172
176
  case 7: return [2 /*return*/];
173
177
  }
174
178
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "2.3.52",
3
+ "version": "2.3.55",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {