@defillama/sdk 2.3.126 → 3.0.1
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/abi/convertResults.js +42 -45
- package/build/abi/index.d.ts +1 -1
- package/build/abi/index.js +7 -7
- package/build/abi/multicall.js +7 -7
- package/build/abi/rpcCall.js +6 -6
- package/build/api.d.ts +2 -2
- package/build/api.js +7 -3
- package/build/computeTVL/blocks.js +3 -3
- package/build/computeTVL/humanizeNumber.js +1 -1
- package/build/computeTVL/prices.d.ts +1 -1
- package/build/computeTVL/prices.js +5 -5
- package/build/erc20/index.js +4 -4
- package/build/eth/index.js +4 -4
- package/build/general.d.ts +1 -1
- package/build/generalUtil.d.ts +7 -4
- package/build/generalUtil.js +53 -16
- package/build/index.js +5 -1
- package/build/types.d.ts +3 -3
- package/build/util/debugLog.d.ts +2 -0
- package/build/util/debugLog.js +14 -0
- package/build/util/index.d.ts +0 -9
- package/build/util/index.js +29 -55
- package/package.json +6 -13
- package/LICENSE +0 -661
- package/build/cdp/index.d.ts +0 -29
- package/build/cdp/index.js +0 -124
- package/build/cli.d.ts +0 -2
- package/build/cli.js +0 -95
- package/build/computeTVL/index.d.ts +0 -59
- package/build/computeTVL/index.js +0 -375
package/build/types.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debugLog = exports.DEBUG_ENABLED = void 0;
|
|
4
|
+
exports.DEBUG_ENABLED = process.env.SDK_DEBUG === "true" || process.env.LLAMA_DEBUG_MODE;
|
|
5
|
+
function debugLog() {
|
|
6
|
+
var args = [];
|
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
+
args[_i] = arguments[_i];
|
|
9
|
+
}
|
|
10
|
+
if (!exports.DEBUG_ENABLED)
|
|
11
|
+
return;
|
|
12
|
+
console.log.apply(console, args);
|
|
13
|
+
}
|
|
14
|
+
exports.debugLog = debugLog;
|
package/build/util/index.d.ts
CHANGED
|
@@ -12,15 +12,6 @@ export declare function lookupBlock(timestamp: number, extraParams?: {
|
|
|
12
12
|
block: number;
|
|
13
13
|
timestamp: number;
|
|
14
14
|
}>;
|
|
15
|
-
export declare function kyberTokens(): Promise<{
|
|
16
|
-
output: {
|
|
17
|
-
[address: string]: {
|
|
18
|
-
symbol: string;
|
|
19
|
-
decimals: number;
|
|
20
|
-
ethPrice: number;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
}>;
|
|
24
15
|
export declare function getLogs(params: {
|
|
25
16
|
target: Address;
|
|
26
17
|
topic: string;
|
package/build/util/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
29
|
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;
|
|
30
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -50,16 +50,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.normalizeBalances = exports.normalizePrefixes = exports.normalizeAddress = exports.getLogs = exports.
|
|
54
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
53
|
+
exports.normalizeBalances = exports.normalizePrefixes = exports.normalizeAddress = exports.getLogs = exports.lookupBlock = exports.getLatestBlock = void 0;
|
|
55
54
|
var general_1 = require("../general");
|
|
56
55
|
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
57
56
|
var ethers_1 = require("ethers");
|
|
58
57
|
var generalUtil_1 = require("../generalUtil");
|
|
58
|
+
var debugLog_1 = require("./debugLog");
|
|
59
59
|
var kavaBlockProvider = {
|
|
60
60
|
getBlock: function (height) { return __awaiter(void 0, void 0, void 0, function () {
|
|
61
61
|
return __generator(this, function (_a) {
|
|
62
|
-
return [2 /*return*/, node_fetch_1.default("https://api.data.kava.io/blocks/"
|
|
62
|
+
return [2 /*return*/, (0, node_fetch_1.default)("https://api.data.kava.io/blocks/".concat(height))
|
|
63
63
|
.then(function (res) { return res.json(); })
|
|
64
64
|
.then(function (block) { return ({
|
|
65
65
|
number: Number(block.block.header.height),
|
|
@@ -71,7 +71,7 @@ var kavaBlockProvider = {
|
|
|
71
71
|
var terraBlockProvider = {
|
|
72
72
|
getBlock: function (height) { return __awaiter(void 0, void 0, void 0, function () {
|
|
73
73
|
return __generator(this, function (_a) {
|
|
74
|
-
return [2 /*return*/, node_fetch_1.default("https://lcd.terra.dev/blocks/"
|
|
74
|
+
return [2 /*return*/, (0, node_fetch_1.default)("https://lcd.terra.dev/blocks/".concat(height))
|
|
75
75
|
.then(function (res) { return res.json(); })
|
|
76
76
|
.then(function (block) { return ({
|
|
77
77
|
number: Number(block.block.header.height),
|
|
@@ -84,13 +84,13 @@ var algorandBlockProvider = {
|
|
|
84
84
|
getBlock: function (height) { return __awaiter(void 0, void 0, void 0, function () {
|
|
85
85
|
return __generator(this, function (_a) {
|
|
86
86
|
if (height !== 'latest')
|
|
87
|
-
return [2 /*return*/, node_fetch_1.default("https://algoindexer.algoexplorerapi.io/v2/blocks/"
|
|
87
|
+
return [2 /*return*/, (0, node_fetch_1.default)("https://algoindexer.algoexplorerapi.io/v2/blocks/".concat(height))
|
|
88
88
|
.then(function (res) { return res.json(); })
|
|
89
89
|
.then(function (block) { return ({
|
|
90
90
|
number: block.round,
|
|
91
91
|
timestamp: block.timestamp
|
|
92
92
|
}); })];
|
|
93
|
-
return [2 /*return*/, node_fetch_1.default('https://algoindexer.algoexplorerapi.io/health')
|
|
93
|
+
return [2 /*return*/, (0, node_fetch_1.default)('https://algoindexer.algoexplorerapi.io/health')
|
|
94
94
|
.then(function (res) { return res.json(); })
|
|
95
95
|
.then(function (block) { return algorandBlockProvider.getBlock(block.round); })];
|
|
96
96
|
});
|
|
@@ -105,7 +105,7 @@ function getBlock(provider, height, chain) {
|
|
|
105
105
|
case 1:
|
|
106
106
|
block = _a.sent();
|
|
107
107
|
if (block === null) {
|
|
108
|
-
throw new Error("Can't get block of chain "
|
|
108
|
+
throw new Error("Can't get block of chain ".concat(chain !== null && chain !== void 0 ? chain : "ethereum"));
|
|
109
109
|
}
|
|
110
110
|
return [2 /*return*/, block];
|
|
111
111
|
}
|
|
@@ -122,7 +122,7 @@ function getExtraProvider(chain) {
|
|
|
122
122
|
else if (chain === "algorand") {
|
|
123
123
|
return algorandBlockProvider;
|
|
124
124
|
}
|
|
125
|
-
return general_1.getProvider(chain);
|
|
125
|
+
return (0, general_1.getProvider)(chain);
|
|
126
126
|
}
|
|
127
127
|
function getLatestBlock(chain) {
|
|
128
128
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -139,29 +139,29 @@ var intialBlocks = {
|
|
|
139
139
|
crab: 4969901
|
|
140
140
|
};
|
|
141
141
|
function lookupBlock(timestamp, extraParams) {
|
|
142
|
-
var _a, _b, _c
|
|
142
|
+
var _a, _b, _c;
|
|
143
143
|
if (extraParams === void 0) { extraParams = {}; }
|
|
144
144
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
-
var chain, low, lowBlock, highBlock, provider,
|
|
146
|
-
return __generator(this, function (
|
|
147
|
-
switch (
|
|
145
|
+
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;
|
|
146
|
+
return __generator(this, function (_e) {
|
|
147
|
+
switch (_e.label) {
|
|
148
148
|
case 0:
|
|
149
149
|
chain = (_a = extraParams === null || extraParams === void 0 ? void 0 : extraParams.chain) !== null && _a !== void 0 ? _a : "ethereum";
|
|
150
150
|
low = (_b = intialBlocks[chain]) !== null && _b !== void 0 ? _b : 100;
|
|
151
|
-
|
|
151
|
+
_e.label = 1;
|
|
152
152
|
case 1:
|
|
153
|
-
|
|
153
|
+
_e.trys.push([1, 7, , 8]);
|
|
154
154
|
provider = getExtraProvider(chain);
|
|
155
155
|
return [4 /*yield*/, Promise.all([
|
|
156
156
|
getBlock(provider, "latest", chain),
|
|
157
157
|
getBlock(provider, low, chain),
|
|
158
158
|
])];
|
|
159
159
|
case 2:
|
|
160
|
-
|
|
160
|
+
_d = _e.sent(), lastBlock = _d[0], firstBlock = _d[1];
|
|
161
161
|
lowBlock = firstBlock;
|
|
162
162
|
highBlock = lastBlock;
|
|
163
163
|
if (lastBlock.timestamp - timestamp < -30 * 60) {
|
|
164
|
-
throw new Error("Last block of chain \""
|
|
164
|
+
throw new Error("Last block of chain \"".concat(chain, "\" is further than 30 minutes into the past. Provider is \"").concat((_c = provider === null || provider === void 0 ? void 0 : provider.connection) === null || _c === void 0 ? void 0 : _c.url, "\""));
|
|
165
165
|
}
|
|
166
166
|
if (Math.abs(lastBlock.timestamp - timestamp) < 60) {
|
|
167
167
|
// Short-circuit in case we are trying to get the current block
|
|
@@ -179,7 +179,7 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
179
179
|
blockImprecision = void 0;
|
|
180
180
|
imprecision = void 0;
|
|
181
181
|
getPrecision_1 = function (block) { return block.timestamp - timestamp > 0 ? block.timestamp - timestamp : timestamp - block.timestamp; };
|
|
182
|
-
|
|
182
|
+
_e.label = 3;
|
|
183
183
|
case 3:
|
|
184
184
|
++i;
|
|
185
185
|
blockDiff = highBlock.number - lowBlock.number;
|
|
@@ -192,7 +192,7 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
192
192
|
getBlock(provider, midBlock, chain),
|
|
193
193
|
])];
|
|
194
194
|
case 4:
|
|
195
|
-
blocks =
|
|
195
|
+
blocks = _e.sent();
|
|
196
196
|
blocks.push(highBlock, lowBlock);
|
|
197
197
|
blocks.sort(function (a, b) { return getPrecision_1(a) - getPrecision_1(b); });
|
|
198
198
|
block = blocks[0];
|
|
@@ -201,13 +201,12 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
201
201
|
highBlock = blocks.filter(function (i) { return i.timestamp > timestamp; }).reduce(function (highestBlock, block) { return (highestBlock.timestamp - timestamp) < (block.timestamp - timestamp) ? highestBlock : block; });
|
|
202
202
|
imprecision = getPrecision_1(block);
|
|
203
203
|
blockImprecision = highBlock.number - lowBlock.number;
|
|
204
|
-
|
|
204
|
+
_e.label = 5;
|
|
205
205
|
case 5:
|
|
206
206
|
if (imprecision > allowedTimeRange && blockImprecision > acceptableBlockImprecision) return [3 /*break*/, 3];
|
|
207
|
-
|
|
207
|
+
_e.label = 6;
|
|
208
208
|
case 6:
|
|
209
|
-
|
|
210
|
-
console.log("chain: " + chain + " block: " + block.number + " #calls: " + i + " imprecision: " + Number((imprecision) / 60).toFixed(2) + " (min) Time Taken: " + Number((Date.now() - time) / 1000).toFixed(2) + " (in sec)");
|
|
209
|
+
(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)"));
|
|
211
210
|
if (chain !== "bsc" && // this check is there because bsc halted the chain for few days
|
|
212
211
|
Math.abs(block.timestamp - timestamp) > 3600) {
|
|
213
212
|
throw new Error("Block selected is more than 1 hour away from the requested timestamp");
|
|
@@ -217,40 +216,15 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
217
216
|
timestamp: block.timestamp
|
|
218
217
|
}];
|
|
219
218
|
case 7:
|
|
220
|
-
e_1 =
|
|
219
|
+
e_1 = _e.sent();
|
|
221
220
|
console.log(e_1);
|
|
222
|
-
throw new Error("Couldn't find block height for chain "
|
|
221
|
+
throw new Error("Couldn't find block height for chain ".concat(chain, ", RPC node rugged"));
|
|
223
222
|
case 8: return [2 /*return*/];
|
|
224
223
|
}
|
|
225
224
|
});
|
|
226
225
|
});
|
|
227
226
|
}
|
|
228
227
|
exports.lookupBlock = lookupBlock;
|
|
229
|
-
function kyberTokens() {
|
|
230
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
-
var pairs, tokens;
|
|
232
|
-
return __generator(this, function (_a) {
|
|
233
|
-
switch (_a.label) {
|
|
234
|
-
case 0: return [4 /*yield*/, node_fetch_1.default("https://api.kyber.network/api/tokens/pairs").then(function (res) { return res.json(); })];
|
|
235
|
-
case 1:
|
|
236
|
-
pairs = _a.sent();
|
|
237
|
-
tokens = Object.keys(pairs).reduce(function (acc, pairName) {
|
|
238
|
-
var pair = pairs[pairName];
|
|
239
|
-
acc[pair.contractAddress] = {
|
|
240
|
-
symbol: pair.symbol,
|
|
241
|
-
decimals: pair.decimals,
|
|
242
|
-
ethPrice: pair.currentPrice
|
|
243
|
-
};
|
|
244
|
-
return acc;
|
|
245
|
-
}, {});
|
|
246
|
-
return [2 /*return*/, {
|
|
247
|
-
output: tokens
|
|
248
|
-
}];
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
exports.kyberTokens = kyberTokens;
|
|
254
228
|
// SMALL INCOMPATIBILITY: On the old API we don't return ids but we should
|
|
255
229
|
function getLogs(params) {
|
|
256
230
|
var _a;
|
|
@@ -278,7 +252,7 @@ function getLogs(params) {
|
|
|
278
252
|
_b.label = 2;
|
|
279
253
|
case 2:
|
|
280
254
|
_b.trys.push([2, 4, , 5]);
|
|
281
|
-
return [4 /*yield*/, general_1.getProvider(params.chain).getLogs(__assign(__assign({}, filter), { fromBlock: currentBlock, toBlock: nextBlock }))];
|
|
255
|
+
return [4 /*yield*/, (0, general_1.getProvider)(params.chain).getLogs(__assign(__assign({}, filter), { fromBlock: currentBlock, toBlock: nextBlock }))];
|
|
282
256
|
case 3:
|
|
283
257
|
partLogs = _b.sent();
|
|
284
258
|
logs = logs.concat(partLogs);
|
|
@@ -326,9 +300,9 @@ function normalizePrefixes(address) {
|
|
|
326
300
|
if (["solana", "tezos"].includes(prefix))
|
|
327
301
|
return address;
|
|
328
302
|
return address.startsWith("0x")
|
|
329
|
-
? "ethereum:"
|
|
303
|
+
? "ethereum:".concat(address.toLowerCase())
|
|
330
304
|
: !address.includes(":")
|
|
331
|
-
? "coingecko:"
|
|
305
|
+
? "coingecko:".concat(address.toLowerCase())
|
|
332
306
|
: address.toLowerCase();
|
|
333
307
|
}
|
|
334
308
|
exports.normalizePrefixes = normalizePrefixes;
|
|
@@ -344,12 +318,12 @@ function normalizeBalances(balances) {
|
|
|
344
318
|
var normalisedKey = normalizePrefixes(key);
|
|
345
319
|
if (normalisedKey == key)
|
|
346
320
|
return;
|
|
347
|
-
generalUtil_1.sumSingleBalance(balances, normalisedKey, balances[key]);
|
|
321
|
+
(0, generalUtil_1.sumSingleBalance)(balances, normalisedKey, balances[key]);
|
|
348
322
|
delete balances[key];
|
|
349
323
|
});
|
|
350
324
|
var eth = balances[ethereumAddress];
|
|
351
325
|
if (eth !== undefined) {
|
|
352
|
-
balances[weth] =
|
|
326
|
+
balances[weth] = ethers_1.BigNumber.from((_a = balances[weth]) !== null && _a !== void 0 ? _a : 0).add(eth).toString();
|
|
353
327
|
delete balances[ethereumAddress];
|
|
354
328
|
}
|
|
355
329
|
return balances;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defillama/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "SDK for calculating TVL",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,21 +23,14 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@supercharge/promise-pool": "^2.1.0",
|
|
26
|
-
"bignumber.js": "^9.1.0",
|
|
27
26
|
"ethers": "^5.4.5",
|
|
28
|
-
"
|
|
29
|
-
"graphql-request": "^3.4.0",
|
|
30
|
-
"lodash": "^4.17.21",
|
|
31
|
-
"node-fetch": "^2.6.1"
|
|
27
|
+
"node-fetch": "^2.6.7"
|
|
32
28
|
},
|
|
33
29
|
"devDependencies": {
|
|
34
|
-
"@types/jest": "^
|
|
35
|
-
"@types/lodash": "^4.14.168",
|
|
30
|
+
"@types/jest": "^29.2.3",
|
|
36
31
|
"@types/node-fetch": "^2.5.8",
|
|
37
|
-
"jest": "^
|
|
38
|
-
"
|
|
39
|
-
"ts-jest": "^26.5.3",
|
|
32
|
+
"jest": "^29.3.1",
|
|
33
|
+
"ts-jest": "^29.0.3",
|
|
40
34
|
"typescript": "^4.2.3"
|
|
41
|
-
}
|
|
42
|
-
"bin": "build/cli.js"
|
|
35
|
+
}
|
|
43
36
|
}
|