@defillama/sdk 2.3.10 → 2.3.14
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/computeTVL/index.d.ts +20 -0
- package/build/computeTVL/index.js +64 -27
- package/build/computeTVL/index.test.js +24 -24
- package/build/general.d.ts +1 -1
- package/build/general.js +5 -0
- package/package.json +1 -1
|
@@ -20,6 +20,26 @@ export declare const chainToCoingeckoId: {
|
|
|
20
20
|
celo: string;
|
|
21
21
|
arbitrum: string;
|
|
22
22
|
iotex: string;
|
|
23
|
+
moonriver: string;
|
|
24
|
+
solana: string;
|
|
25
|
+
terra: string;
|
|
26
|
+
tron: string;
|
|
27
|
+
waves: string;
|
|
28
|
+
klaytn: string;
|
|
29
|
+
osmosis: string;
|
|
30
|
+
kava: string;
|
|
31
|
+
icon: string;
|
|
32
|
+
optimism: string;
|
|
33
|
+
eos: string;
|
|
34
|
+
secret: string;
|
|
35
|
+
rsk: string;
|
|
36
|
+
neo: string;
|
|
37
|
+
tezos: string;
|
|
38
|
+
wan: string;
|
|
39
|
+
ontology: string;
|
|
40
|
+
algorand: string;
|
|
41
|
+
zilliqa: string;
|
|
42
|
+
kardia: string;
|
|
23
43
|
};
|
|
24
44
|
export default function (rawBalances: Balances, timestamp: number | "now", verbose?: boolean, knownTokenPrices?: TokenPrices, getCoingeckoLock?: GetCoingeckoLog, coingeckoMaxRetries?: number): Promise<{
|
|
25
45
|
usdTvl: number;
|
|
@@ -81,7 +81,27 @@ exports.chainToCoingeckoId = {
|
|
|
81
81
|
kcc: "kucoin-community-chain",
|
|
82
82
|
celo: "celo",
|
|
83
83
|
arbitrum: "arbitrum-one",
|
|
84
|
-
iotex: "iotex"
|
|
84
|
+
iotex: "iotex",
|
|
85
|
+
moonriver: "moonriver",
|
|
86
|
+
solana: "solana",
|
|
87
|
+
terra: "terra",
|
|
88
|
+
tron: "tron",
|
|
89
|
+
waves: "waves",
|
|
90
|
+
klaytn: "klay-token",
|
|
91
|
+
osmosis: "osmosis",
|
|
92
|
+
kava: "kava",
|
|
93
|
+
icon: "icon",
|
|
94
|
+
optimism: "optimistic-ethereum",
|
|
95
|
+
eos: "eos",
|
|
96
|
+
secret: "secret",
|
|
97
|
+
rsk: "rootstock",
|
|
98
|
+
neo: "neo",
|
|
99
|
+
tezos: "tezos",
|
|
100
|
+
wan: "wanchain",
|
|
101
|
+
ontology: "ontology",
|
|
102
|
+
algorand: "algorand",
|
|
103
|
+
zilliqa: "zilliqa",
|
|
104
|
+
kardia: "kardiachain",
|
|
85
105
|
};
|
|
86
106
|
function currentCoingeckoUrls(chain) {
|
|
87
107
|
if (chain === 'coingecko') {
|
|
@@ -94,46 +114,41 @@ function currentCoingeckoUrls(chain) {
|
|
|
94
114
|
throw new Error("Chain not supported");
|
|
95
115
|
}
|
|
96
116
|
var chains = Object.keys(exports.chainToCoingeckoId);
|
|
97
|
-
function
|
|
117
|
+
function getHistoricalChainPrices(ids, timestamp, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries) {
|
|
98
118
|
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
-
var chainPrices, _i, _a, chain, _b, _c
|
|
100
|
-
return __generator(this, function (
|
|
101
|
-
switch (
|
|
119
|
+
var chainPrices, _i, _a, chain, _b, _c;
|
|
120
|
+
return __generator(this, function (_d) {
|
|
121
|
+
switch (_d.label) {
|
|
102
122
|
case 0:
|
|
103
123
|
chainPrices = {};
|
|
104
124
|
_i = 0, _a = chains.concat(["coingecko"]);
|
|
105
|
-
|
|
125
|
+
_d.label = 1;
|
|
106
126
|
case 1:
|
|
107
|
-
if (!(_i < _a.length)) return [3 /*break*/,
|
|
127
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
108
128
|
chain = _a[_i];
|
|
109
129
|
if (!(ids[chain].length === 0)) return [3 /*break*/, 2];
|
|
110
130
|
chainPrices[chain] = {};
|
|
111
|
-
return [3 /*break*/,
|
|
131
|
+
return [3 /*break*/, 4];
|
|
112
132
|
case 2:
|
|
113
|
-
if (!(timestamp === "now")) return [3 /*break*/, 4];
|
|
114
133
|
_b = chainPrices;
|
|
115
134
|
_c = chain;
|
|
116
|
-
return [4 /*yield*/, prices_1.
|
|
135
|
+
return [4 /*yield*/, prices_1.getHistoricalTokenPrices(ids[chain], historicalCoingeckoUrls(chain), timestamp, getCoingeckoLock, coingeckoMaxRetries)];
|
|
117
136
|
case 3:
|
|
118
|
-
_b[_c] =
|
|
119
|
-
|
|
137
|
+
_b[_c] = _d.sent();
|
|
138
|
+
_d.label = 4;
|
|
120
139
|
case 4:
|
|
121
|
-
_d = chainPrices;
|
|
122
|
-
_e = chain;
|
|
123
|
-
return [4 /*yield*/, prices_1.getHistoricalTokenPrices(ids[chain], historicalCoingeckoUrls(chain), timestamp, getCoingeckoLock, coingeckoMaxRetries)];
|
|
124
|
-
case 5:
|
|
125
|
-
_d[_e] = _f.sent();
|
|
126
|
-
_f.label = 6;
|
|
127
|
-
case 6:
|
|
128
140
|
_i++;
|
|
129
141
|
return [3 /*break*/, 1];
|
|
130
|
-
case
|
|
142
|
+
case 5: return [2 /*return*/, chainPrices];
|
|
131
143
|
}
|
|
132
144
|
});
|
|
133
145
|
});
|
|
134
146
|
}
|
|
135
147
|
function getChainSymbolsAndDecimals(ids) {
|
|
136
|
-
var allCoins = Object.entries(ids).map(function (chain) {
|
|
148
|
+
var allCoins = Object.entries(ids).map(function (chain) {
|
|
149
|
+
return chain[1].map(function (coin) { return chain[0] === "coingecko" ? coin.toLowerCase() : chain[0] + ":" + coin.toLowerCase(); });
|
|
150
|
+
})
|
|
151
|
+
.reduce(function (acc, coins) {
|
|
137
152
|
coins.forEach(function (coin) {
|
|
138
153
|
acc.add(coin);
|
|
139
154
|
});
|
|
@@ -221,9 +236,31 @@ function default_1(rawBalances, timestamp, verbose, knownTokenPrices, getCoingec
|
|
|
221
236
|
}
|
|
222
237
|
}
|
|
223
238
|
symbolsAndDecimals = getChainSymbolsAndDecimals(chainIds);
|
|
224
|
-
return [
|
|
239
|
+
if (!(timestamp === "now")) return [3 /*break*/, 5];
|
|
240
|
+
return [4 /*yield*/, symbolsAndDecimals];
|
|
225
241
|
case 4:
|
|
242
|
+
allChainTokenPrices = (_c.sent()).reduce(function (prices, item) {
|
|
243
|
+
var chain, address;
|
|
244
|
+
if (item.coin.includes(":")) {
|
|
245
|
+
chain = item.coin.split(':')[0];
|
|
246
|
+
address = item.coin.split(':')[1];
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
chain = "coingecko";
|
|
250
|
+
address = item.coin;
|
|
251
|
+
}
|
|
252
|
+
if (prices[chain] === undefined) {
|
|
253
|
+
prices[chain] = {};
|
|
254
|
+
}
|
|
255
|
+
prices[chain][address] = { usd: item.price };
|
|
256
|
+
return prices;
|
|
257
|
+
}, {});
|
|
258
|
+
return [3 /*break*/, 7];
|
|
259
|
+
case 5: return [4 /*yield*/, getHistoricalChainPrices(chainIds, timestamp, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries)];
|
|
260
|
+
case 6:
|
|
226
261
|
allChainTokenPrices = _c.sent();
|
|
262
|
+
_c.label = 7;
|
|
263
|
+
case 7:
|
|
227
264
|
usdTokenBalances = {};
|
|
228
265
|
tokenBalances = {};
|
|
229
266
|
usdAmounts = Object.entries(normalizedBalances).map(function (_a) {
|
|
@@ -290,17 +327,17 @@ function default_1(rawBalances, timestamp, verbose, knownTokenPrices, getCoingec
|
|
|
290
327
|
});
|
|
291
328
|
});
|
|
292
329
|
});
|
|
293
|
-
if (!verbose) return [3 /*break*/,
|
|
330
|
+
if (!verbose) return [3 /*break*/, 9];
|
|
294
331
|
return [4 /*yield*/, Promise.all(usdAmounts)];
|
|
295
|
-
case
|
|
332
|
+
case 8:
|
|
296
333
|
(_c.sent())
|
|
297
334
|
.sort(function (a, b) { return b.usdAmount - a.usdAmount; })
|
|
298
335
|
.map(function (token) {
|
|
299
336
|
console.log(token.tokenSymbol.padEnd(25, " "), humanizeNumber_1.humanizeNumber(token.usdAmount));
|
|
300
337
|
});
|
|
301
|
-
_c.label =
|
|
302
|
-
case
|
|
303
|
-
case
|
|
338
|
+
_c.label = 9;
|
|
339
|
+
case 9: return [4 /*yield*/, Promise.all(usdAmounts)];
|
|
340
|
+
case 10:
|
|
304
341
|
usdTvl = (_c.sent()).reduce(function (sum, token) {
|
|
305
342
|
return sum + token.usdAmount;
|
|
306
343
|
}, 0);
|
|
@@ -49,31 +49,31 @@ test("compute tvl of ethereum and bsc tokens", function () { return __awaiter(vo
|
|
|
49
49
|
knownPrices = {};
|
|
50
50
|
_a = expect;
|
|
51
51
|
return [4 /*yield*/, _1.default({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
52
|
+
"0x6f259637dcd74c767781e37bc6133cd6a68aa161": "3193525665566784275723138",
|
|
53
|
+
"heco:0xecb56cf772B5c9A6907FB7d32387Da2fCbfB63b4": "1047556118646987925068",
|
|
54
|
+
"heco:0xA2c49cEe16a5E5bDEFDe931107dc1fae9f7773E3": "236654328014720960482935",
|
|
55
|
+
"heco:0xae3a768f9aB104c69A7CD6041fE16fFa235d1810": "16569632182924952096418",
|
|
56
|
+
"heco:0x9e004545c59D359F6B7BFB06a26390b087717b42": "961004175478694236526",
|
|
57
|
+
"binance-eth": 27.06634107102854,
|
|
58
|
+
"heco:0xa71EdC38d189767582C38A3145b5873052c3e47a": "31268806605177889114148968",
|
|
59
|
+
"heco:0x25D2e80cB6B86881Fd7e07dd263Fb79f4AbE033c": "192506692195331535945631",
|
|
60
|
+
"heco:0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047": "2158672533322793",
|
|
61
|
+
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": "11093082876512",
|
|
62
|
+
"heco:0x66a79D23E58475D2738179Ca52cd0b41d73f0BEa": "996379172178921963142",
|
|
63
|
+
"heco:0x22C54cE8321A4015740eE1109D9cBc25815C46E6": "23914657385695466323057",
|
|
64
|
+
"0x6b175474e89094c44da98b954eedeac495271d0f": "7107526494042094908468667",
|
|
65
|
+
"heco:0xE499Ef4616993730CEd0f31FA2703B92B50bB536": "137205675925769131064013486",
|
|
66
|
+
"heco:0xB4F019bEAc758AbBEe2F906033AAa2f0F6Dacb35": "364494623629203573",
|
|
67
|
+
"heco:0xeF3CEBD77E0C52cb6f60875d9306397B5Caca375": "3129531295952878112773",
|
|
68
|
+
"heco:0x64FF637fB478863B7468bc97D30a5bF3A428a1fD": "9192054317393320446391",
|
|
69
|
+
"heco:0x25d2e80cb6b86881fd7e07dd263fb79f4abe033c": "148911552859786953196071",
|
|
70
|
+
"heco:0x64ff637fb478863b7468bc97d30a5bf3a428a1fd": "5894279017068474040638",
|
|
71
|
+
"heco:0x66a79d23e58475d2738179ca52cd0b41d73f0bea": "612867016701208550102",
|
|
72
|
+
"heco:0x0298c2b32eae4da002a15f36fdf7615bea3da047": "322847070254",
|
|
73
|
+
"heco:0xa71edc38d189767582c38a3145b5873052c3e47a": "27261644010709722098844276",
|
|
74
|
+
}, "now", true, knownPrices)];
|
|
75
75
|
case 1:
|
|
76
|
-
_a.apply(void 0, [_g.sent()]).
|
|
76
|
+
_a.apply(void 0, [_g.sent()]).toMatchInlineSnapshot("\n Object {\n \"tokenBalances\": Object {\n \"DAI\": 7107526.494042095,\n \"ETH\": 15086.333334461793,\n \"HBCH\": 3129.531295952878,\n \"HBTC\": 1609.2461888801304,\n \"HDOT\": 236654.32801472096,\n \"HFIL\": 16569.632182924954,\n \"HLTC\": 1047.556118646988,\n \"HPT\": 137205675.92576912,\n \"HT\": 3193525.6655667843,\n \"HUSD\": 21589953.80393047,\n \"LINK\": 961.0041754786943,\n \"MDX\": 341418.2450551185,\n \"UNI\": 23914.657385695464,\n \"USDC\": 11093082.876512,\n \"USDT\": 58530450.61588761,\n \"YFI\": 0.3644946236292036,\n \"binance-eth\": 27.06634107102854,\n },\n \"usdTokenBalances\": Object {\n \"DAI\": 7099743.752531119,\n \"ETH\": 68626674.2951333,\n \"HBCH\": 1917651.5969080853,\n \"HBTC\": 99816713.35766785,\n \"HDOT\": 12829031.121678023,\n \"HFIL\": 1028808.4622378105,\n \"HLTC\": 223234.20888367313,\n \"HPT\": 963452.7681237137,\n \"HT\": 35192652.83454596,\n \"HUSD\": 21805853.341969773,\n \"LINK\": 29781.519398084733,\n \"MDX\": 365317.5222089768,\n \"UNI\": 614606.6948123734,\n \"USDC\": 11086671.074609376,\n \"USDT\": 58530450.61588761,\n \"YFI\": 12421.247784036,\n \"binance-eth\": 112462.81245740927,\n },\n \"usdTvl\": 320255527.22683716,\n }\n ");
|
|
77
77
|
return [2 /*return*/];
|
|
78
78
|
case 2:
|
|
79
79
|
_b.apply(void 0, [_g.sent()]).toBeGreaterThan(1e5);
|
package/build/general.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers, BigNumber } from "ethers";
|
|
2
|
-
export declare type Chain = "ethereum" | "bsc" | "polygon" | "heco" | "fantom" | "rsk" | "tomochain" | "xdai" | "avax" | "wan" | "iotex" | "harmony" | "thundercore" | "okexchain" | "optimism" | "arbitrum" | "energyweb" | "songbird" | "hpb" | "gochain" | "ethclassic" | "xdaiarb" | "kardia" | "fuse";
|
|
2
|
+
export declare type Chain = "ethereum" | "bsc" | "polygon" | "heco" | "fantom" | "rsk" | "tomochain" | "xdai" | "avax" | "wan" | "iotex" | "harmony" | "thundercore" | "okexchain" | "optimism" | "arbitrum" | "energyweb" | "songbird" | "hpb" | "gochain" | "ethclassic" | "xdaiarb" | "kardia" | "fuse" | "fusion" | "smartbch" | "hoo" | "esc";
|
|
3
3
|
export declare function getProvider(chain?: Chain): ethers.providers.BaseProvider;
|
|
4
4
|
export declare const TEN: ethers.BigNumber;
|
|
5
5
|
export declare function handleDecimals(num: BigNumber, decimals?: number): string;
|
package/build/general.js
CHANGED
|
@@ -54,6 +54,11 @@ var providers = {
|
|
|
54
54
|
xdaiarb: createProvider("xdaiarb", "https://arbitrum.xdaichain.com", 200),
|
|
55
55
|
kardia: createProvider("kardia", "https://rpc.kardiachain.io/", 0),
|
|
56
56
|
fuse: createProvider("fuse", "https://rpc.fuse.io", 122),
|
|
57
|
+
smartbch: createProvider("smartbch", "https://smartbch.fountainhead.cash/mainnet", 10000),
|
|
58
|
+
esc: createProvider("esc", "https://api.elastos.io/eth,https://api.trinity-tech.cn/eth", 20),
|
|
59
|
+
hoo: createProvider("hoo", "https://http-mainnet.hoosmartchain.com", 70),
|
|
60
|
+
fusion: createProvider("fusion", "https://mainnet.anyswap.exchange,https://mainway.freemoon.xyz/gate", 32659),
|
|
61
|
+
aurora: createProvider("aurora", "https://mainnet.aurora.dev", 1313161554)
|
|
57
62
|
};
|
|
58
63
|
function getProvider(chain) {
|
|
59
64
|
if (chain === void 0) { chain = "ethereum"; }
|