@defillama/sdk 2.3.54 → 2.3.57
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/index.js +24 -41
- package/build/abi/multicall.js +19 -15
- package/build/cli.js +0 -0
- package/build/general.d.ts +1 -1
- package/build/general.js +4 -2
- package/build/util/index.js +16 -12
- package/package.json +2 -1
package/build/abi/index.js
CHANGED
|
@@ -56,6 +56,7 @@ var ethers_1 = require("ethers");
|
|
|
56
56
|
var general_1 = require("../general");
|
|
57
57
|
var multicall_1 = __importDefault(require("./multicall"));
|
|
58
58
|
var convertResults_1 = __importDefault(require("./convertResults"));
|
|
59
|
+
var promise_pool_1 = require("@supercharge/promise-pool");
|
|
59
60
|
function resolveABI(providedAbi) {
|
|
60
61
|
var abi = providedAbi;
|
|
61
62
|
if (typeof abi === "string") {
|
|
@@ -106,9 +107,9 @@ function call(params) {
|
|
|
106
107
|
}
|
|
107
108
|
exports.call = call;
|
|
108
109
|
function multiCall(params) {
|
|
109
|
-
var _a;
|
|
110
110
|
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
-
var abi, contractCalls,
|
|
111
|
+
var abi, contractCalls, chunkSize, contractChunks, i, _a, results, errors, flatResults, failed, newResults_1;
|
|
112
|
+
var _this = this;
|
|
112
113
|
return __generator(this, function (_b) {
|
|
113
114
|
switch (_b.label) {
|
|
114
115
|
case 0:
|
|
@@ -121,43 +122,25 @@ function multiCall(params) {
|
|
|
121
122
|
contract: (_a = call.target) !== null && _a !== void 0 ? _a : params.target,
|
|
122
123
|
};
|
|
123
124
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case 1:
|
|
138
|
-
_c.sent(); // It would be faster to just await on all of them, but if we do that at some point node crashes without error message, so to prevent that we have to periodically await smaller sets of calls
|
|
139
|
-
multicallCalls = []; // Clear them from memory
|
|
140
|
-
_c.label = 2;
|
|
141
|
-
case 2: return [2 /*return*/];
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
i = 0;
|
|
146
|
-
_b.label = 1;
|
|
125
|
+
chunkSize = 500;
|
|
126
|
+
contractChunks = [];
|
|
127
|
+
for (i = 0; i < contractCalls.length; i += chunkSize)
|
|
128
|
+
contractChunks.push(contractCalls.slice(i, i + chunkSize));
|
|
129
|
+
return [4 /*yield*/, promise_pool_1.PromisePool
|
|
130
|
+
.withConcurrency(20)
|
|
131
|
+
.for(contractChunks)
|
|
132
|
+
.process(function (calls, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
133
|
+
var _a;
|
|
134
|
+
return __generator(this, function (_b) {
|
|
135
|
+
return [2 /*return*/, multicall_1.default(abi, calls, (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum", params.block)];
|
|
136
|
+
});
|
|
137
|
+
}); })];
|
|
147
138
|
case 1:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
case 3:
|
|
154
|
-
i += 500;
|
|
155
|
-
return [3 /*break*/, 1];
|
|
156
|
-
case 4: return [4 /*yield*/, Promise.all(multicallCalls)];
|
|
157
|
-
case 5:
|
|
158
|
-
_b.sent();
|
|
159
|
-
flatResults = [].concat.apply([], result);
|
|
160
|
-
if (!(params.requery === true && flatResults.some(function (r) { return !r.success; }))) return [3 /*break*/, 7];
|
|
139
|
+
_a = _b.sent(), results = _a.results, errors = _a.errors;
|
|
140
|
+
if (errors.length)
|
|
141
|
+
throw errors[0];
|
|
142
|
+
flatResults = [].concat.apply([], results);
|
|
143
|
+
if (!(params.requery === true && flatResults.some(function (r) { return !r.success; }))) return [3 /*break*/, 3];
|
|
161
144
|
failed = flatResults.map(function (r, i) { return [r, i]; }).filter(function (r) { return !r[0].success; });
|
|
162
145
|
return [4 /*yield*/, multiCall({
|
|
163
146
|
abi: params.abi,
|
|
@@ -169,13 +152,13 @@ function multiCall(params) {
|
|
|
169
152
|
var output = _a.output;
|
|
170
153
|
return output;
|
|
171
154
|
})];
|
|
172
|
-
case
|
|
155
|
+
case 2:
|
|
173
156
|
newResults_1 = _b.sent();
|
|
174
157
|
failed.forEach(function (f, i) {
|
|
175
158
|
flatResults[f[1]] = newResults_1[i];
|
|
176
159
|
});
|
|
177
|
-
_b.label =
|
|
178
|
-
case
|
|
160
|
+
_b.label = 3;
|
|
161
|
+
case 3: return [2 /*return*/, {
|
|
179
162
|
output: flatResults, // flatten array
|
|
180
163
|
}];
|
|
181
164
|
}
|
package/build/abi/multicall.js
CHANGED
|
@@ -44,6 +44,7 @@ var ethers_1 = require("ethers");
|
|
|
44
44
|
var utils_1 = require("ethers/lib/utils");
|
|
45
45
|
var general_1 = require("../general");
|
|
46
46
|
var convertResults_1 = __importDefault(require("./convertResults"));
|
|
47
|
+
var rpcCall_1 = require("./rpcCall");
|
|
47
48
|
exports.MULTICALL_ADDRESS_MAINNET = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441";
|
|
48
49
|
exports.MULTICALL_ADDRESS_KOVAN = "0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a";
|
|
49
50
|
exports.MULTICALL_ADDRESS_RINKEBY = "0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821";
|
|
@@ -130,7 +131,7 @@ function executeCalls(contractCalls, chain, block) {
|
|
|
130
131
|
to: address,
|
|
131
132
|
data: callData,
|
|
132
133
|
};
|
|
133
|
-
return [4 /*yield*/, general_1.getProvider(chain)
|
|
134
|
+
return [4 /*yield*/, rpcCall_1.call(general_1.getProvider(chain), tx, block !== null && block !== void 0 ? block : "latest", chain)];
|
|
134
135
|
case 4:
|
|
135
136
|
returnData = _b.sent();
|
|
136
137
|
_a = ethers_1.ethers.utils.defaultAbiCoder.decode(["uint256", "bytes[]"], returnData), blockNumber = _a[0], returnValues = _a[1];
|
|
@@ -141,21 +142,24 @@ function executeCalls(contractCalls, chain, block) {
|
|
|
141
142
|
console.log("Multicall failed, defaulting to single transactions...");
|
|
142
143
|
}
|
|
143
144
|
return [3 /*break*/, 6];
|
|
144
|
-
case 6: return [4 /*yield*/, Promise.all(contractCalls.map(function (
|
|
145
|
-
var
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
case 6: return [4 /*yield*/, Promise.all(contractCalls.map(function (_a) {
|
|
146
|
+
var to = _a.to, data = _a.data;
|
|
147
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
148
|
+
var e_2;
|
|
149
|
+
return __generator(this, function (_b) {
|
|
150
|
+
switch (_b.label) {
|
|
151
|
+
case 0:
|
|
152
|
+
_b.trys.push([0, 2, , 3]);
|
|
153
|
+
return [4 /*yield*/, rpcCall_1.call(general_1.getProvider(chain), { to: to, data: data }, block !== null && block !== void 0 ? block : "latest", chain)];
|
|
154
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
155
|
+
case 2:
|
|
156
|
+
e_2 = _b.sent();
|
|
157
|
+
return [2 /*return*/, null];
|
|
158
|
+
case 3: return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
157
161
|
});
|
|
158
|
-
})
|
|
162
|
+
}))];
|
|
159
163
|
case 7:
|
|
160
164
|
values = _b.sent();
|
|
161
165
|
return [2 /*return*/, values];
|
package/build/cli.js
CHANGED
|
File without changes
|
package/build/general.d.ts
CHANGED
|
@@ -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" | "dfk";
|
|
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" | "bittorrent";
|
|
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.
|
|
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),
|
|
@@ -80,11 +80,13 @@ exports.providers = {
|
|
|
80
80
|
moonbeam: createProvider("moonbeam", 'https://rpc.api.moonbeam.network', 1284),
|
|
81
81
|
curio: createProvider("curio", 'https://mainnet-api.skalenodes.com/v1/fit-betelgeuse', 836542336838601),
|
|
82
82
|
astar: createProvider("astar", "https://rpc.astar.network:8545", 592),
|
|
83
|
-
godwoken: createProvider("godwoken", "https://mainnet.godwoken.io/rpc
|
|
83
|
+
godwoken: createProvider("godwoken", "https://mainnet.godwoken.io/rpc", 71394),
|
|
84
84
|
evmos: createProvider("evmos", "https://eth.bd.evmos.org:8545/", 9001),
|
|
85
85
|
conflux: createProvider("conflux", "https://evm.confluxrpc.com", 1030),
|
|
86
86
|
milkomeda: createProvider("milkomeda", "https://rpc-mainnet-cardano-evm.c1.milkomeda.com", 2001),
|
|
87
87
|
dfk: createProvider("dfk", "https://subnets.avax.network/defi-kingdoms/dfk-chain/rpc", 53935),
|
|
88
|
+
crab: createProvider("crab", "https://crab-rpc.darwinia.network", 44),
|
|
89
|
+
bittorrent: createProvider("bittorrent", "https://rpc.bittorrentchain.io", 199)
|
|
88
90
|
};
|
|
89
91
|
function getProvider(chain) {
|
|
90
92
|
if (chain === void 0) { chain = "ethereum"; }
|
package/build/util/index.js
CHANGED
|
@@ -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 (
|
|
124
|
-
switch (
|
|
127
|
+
return __generator(this, function (_f) {
|
|
128
|
+
switch (_f.label) {
|
|
125
129
|
case 0:
|
|
126
|
-
|
|
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 =
|
|
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)
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
160
|
+
_f.label = 4;
|
|
157
161
|
case 4:
|
|
158
162
|
if (high - low > 4) return [3 /*break*/, 2];
|
|
159
|
-
|
|
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 =
|
|
173
|
+
e_1 = _f.sent();
|
|
170
174
|
console.log(e_1);
|
|
171
|
-
throw new Error("Couldn't find block height for chain " + ((
|
|
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.
|
|
3
|
+
"version": "2.3.57",
|
|
4
4
|
"description": "SDK for calculating TVL",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"build"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@supercharge/promise-pool": "^2.1.0",
|
|
25
26
|
"ethers": "^5.4.5",
|
|
26
27
|
"graphql": "^15.5.0",
|
|
27
28
|
"graphql-request": "^3.4.0",
|