@defillama/sdk 5.0.9 → 5.0.11
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/Balances.d.ts +5 -0
- package/build/Balances.js +47 -107
- package/build/ChainApi.d.ts +1 -0
- package/build/ChainApi.js +152 -253
- package/build/abi/abi2.js +47 -144
- package/build/abi/convertResults.js +9 -29
- package/build/abi/index.js +220 -326
- package/build/abi/multicall.js +115 -217
- package/build/abi/multicall3.js +59 -123
- package/build/abi/rpcCall.js +43 -106
- package/build/abi/tron.js +153 -283
- package/build/api.js +3 -4
- package/build/computeTVL/humanizeNumber.js +6 -7
- package/build/computeTVL/prices.js +55 -145
- package/build/erc20/index.js +34 -122
- package/build/eth/index.js +37 -107
- package/build/general.js +22 -23
- package/build/generalUtil.js +72 -130
- package/build/index.js +2 -2
- package/build/providers.json +1 -1
- package/build/util/blocks.js +212 -371
- package/build/util/blockscout.js +13 -58
- package/build/util/cache.js +112 -274
- package/build/util/computeTVL.js +70 -150
- package/build/util/cosmos.js +21 -75
- package/build/util/debugLog.js +6 -14
- package/build/util/env.d.ts +1 -1
- package/build/util/env.js +24 -35
- package/build/util/index.js +72 -132
- package/build/util/internal-cache.js +7 -8
- package/build/util/logs.d.ts +1 -2
- package/build/util/logs.js +152 -225
- package/build/util/promisePool.js +11 -62
- package/build/util/r2.js +36 -95
- package/build/util/updateProviderList.js +23 -83
- package/package.json +2 -3
package/build/util/computeTVL.js
CHANGED
|
@@ -1,166 +1,86 @@
|
|
|
1
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.getUnique = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
function computeTVL(balances, timestamp) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var _c = (_b = priceCache[key]) !== null && _b !== void 0 ? _b : {}, price = _c.price, confidence = _c.confidence, _d = _c.decimals, decimals = _d === void 0 ? 0 : _d, _e = _c.symbol, symbol = _e === void 0 ? token : _e;
|
|
71
|
-
if (!price || confidence < confidenceThreshold)
|
|
72
|
-
return;
|
|
73
|
-
var value = +balance * price / (Math.pow(10, decimals));
|
|
74
|
-
usdTvl += value;
|
|
75
|
-
if (symbol === 'ETH')
|
|
76
|
-
symbol = 'WETH';
|
|
77
|
-
(0, generalUtil_1.sumSingleBalance)(usdTokenBalances, symbol, value);
|
|
78
|
-
});
|
|
79
|
-
return [2 /*return*/, { usdTvl: usdTvl, usdTokenBalances: usdTokenBalances }];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const generalUtil_1 = require("../generalUtil");
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const currentPriceCache = {};
|
|
11
|
+
const priceCaches = {};
|
|
12
|
+
let lastPriceUpdate = 0;
|
|
13
|
+
const confidenceThreshold = 0.5;
|
|
14
|
+
const priceUpdateTime = 1000 * 60 * 30; // 30 minutes
|
|
15
|
+
async function computeTVL(balances, timestamp) {
|
|
16
|
+
const usdTokenBalances = {};
|
|
17
|
+
let usdTvl = 0;
|
|
18
|
+
const keys = Object.keys(balances).filter(i => +balances[i] > 0).map(tokenToKey);
|
|
19
|
+
await updatePriceCache(keys, timestamp);
|
|
20
|
+
const priceCache = getPriceCache(timestamp);
|
|
21
|
+
Object.entries(balances).forEach(([token, balance]) => {
|
|
22
|
+
var _a;
|
|
23
|
+
if (+balance <= 0)
|
|
24
|
+
return;
|
|
25
|
+
const key = tokenToKey(token).toLowerCase();
|
|
26
|
+
let { price, confidence, decimals = 0, symbol = token } = (_a = priceCache[key]) !== null && _a !== void 0 ? _a : {};
|
|
27
|
+
if (!price || confidence < confidenceThreshold)
|
|
28
|
+
return;
|
|
29
|
+
const value = +balance * price / (10 ** decimals);
|
|
30
|
+
usdTvl += value;
|
|
31
|
+
if (symbol === 'ETH')
|
|
32
|
+
symbol = 'WETH';
|
|
33
|
+
(0, generalUtil_1.sumSingleBalance)(usdTokenBalances, symbol, value);
|
|
82
34
|
});
|
|
35
|
+
return { usdTvl, usdTokenBalances };
|
|
83
36
|
}
|
|
84
37
|
exports.default = computeTVL;
|
|
85
38
|
function tokenToKey(token) {
|
|
86
39
|
if (token.startsWith("0x"))
|
|
87
|
-
token =
|
|
40
|
+
token = `ethereum:${token}`;
|
|
88
41
|
else if (!token.includes(':'))
|
|
89
|
-
token =
|
|
42
|
+
token = `coingecko:${token}`;
|
|
90
43
|
return token;
|
|
91
44
|
}
|
|
92
|
-
function updatePriceCache(keys, timestamp) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
45
|
+
async function updatePriceCache(keys, timestamp) {
|
|
46
|
+
if (isNearlyNow(timestamp))
|
|
47
|
+
timestamp = undefined;
|
|
48
|
+
keys = getUnique(keys);
|
|
49
|
+
const pricesCache = getPriceCache(timestamp);
|
|
50
|
+
if (!timestamp && lastPriceUpdate && +Date.now() > lastPriceUpdate + priceUpdateTime) {
|
|
51
|
+
lastPriceUpdate = +Date.now();
|
|
52
|
+
Object.keys(pricesCache).forEach(key => delete pricesCache[key]); // clear cache
|
|
53
|
+
}
|
|
54
|
+
// hardcode cache for USDT
|
|
55
|
+
pricesCache['coingecko:tether'] = {
|
|
56
|
+
"price": 1,
|
|
57
|
+
"symbol": "USDT",
|
|
58
|
+
"confidence": 1
|
|
59
|
+
};
|
|
60
|
+
pricesCache['ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7'] = {
|
|
61
|
+
"price": 1,
|
|
62
|
+
"symbol": "USDT",
|
|
63
|
+
"decimals": 6,
|
|
64
|
+
"confidence": 1
|
|
65
|
+
};
|
|
66
|
+
const missingKeys = keys.filter(key => !pricesCache[key.toLowerCase()]);
|
|
67
|
+
const chunks = (0, _1.sliceIntoChunks)(missingKeys, 100);
|
|
68
|
+
for (const chunk of chunks) {
|
|
69
|
+
const coins = await getPrices(chunk);
|
|
70
|
+
for (const [token, data] of Object.entries(coins)) {
|
|
71
|
+
pricesCache[token.toLowerCase()] = data;
|
|
116
72
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
// hardcode cache for USDT
|
|
130
|
-
pricesCache['coingecko:tether'] = {
|
|
131
|
-
"price": 1,
|
|
132
|
-
"symbol": "USDT",
|
|
133
|
-
"confidence": 1
|
|
134
|
-
};
|
|
135
|
-
pricesCache['ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7'] = {
|
|
136
|
-
"price": 1,
|
|
137
|
-
"symbol": "USDT",
|
|
138
|
-
"decimals": 6,
|
|
139
|
-
"confidence": 1
|
|
140
|
-
};
|
|
141
|
-
missingKeys = keys.filter(function (key) { return !pricesCache[key.toLowerCase()]; });
|
|
142
|
-
chunks = (0, _1.sliceIntoChunks)(missingKeys, 100);
|
|
143
|
-
_i = 0, chunks_1 = chunks;
|
|
144
|
-
_d.label = 1;
|
|
145
|
-
case 1:
|
|
146
|
-
if (!(_i < chunks_1.length)) return [3 /*break*/, 4];
|
|
147
|
-
chunk = chunks_1[_i];
|
|
148
|
-
return [4 /*yield*/, getPrices(chunk)];
|
|
149
|
-
case 2:
|
|
150
|
-
coins = _d.sent();
|
|
151
|
-
for (_a = 0, _b = Object.entries(coins); _a < _b.length; _a++) {
|
|
152
|
-
_c = _b[_a], token = _c[0], data = _c[1];
|
|
153
|
-
pricesCache[token.toLowerCase()] = data;
|
|
154
|
-
}
|
|
155
|
-
chunk.map(function (i) { return i.toLowerCase(); }).filter(function (i) { return !pricesCache[i]; }).forEach(function (i) { return pricesCache[i] = {}; });
|
|
156
|
-
_d.label = 3;
|
|
157
|
-
case 3:
|
|
158
|
-
_i++;
|
|
159
|
-
return [3 /*break*/, 1];
|
|
160
|
-
case 4: return [2 /*return*/];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
73
|
+
chunk.map(i => i.toLowerCase()).filter(i => !pricesCache[i]).forEach(i => pricesCache[i] = {});
|
|
74
|
+
}
|
|
75
|
+
async function getPrices(keys) {
|
|
76
|
+
if (!timestamp) {
|
|
77
|
+
const { coins } = await (0, axios_1.default)(`https://coins.llama.fi/prices/current/${keys.join(',')}`).then((res) => res.data);
|
|
78
|
+
return coins;
|
|
79
|
+
}
|
|
80
|
+
// fetch post with timestamp in body
|
|
81
|
+
const { coins } = await axios_1.default.post("https://coins.llama.fi/prices?source=internal", { coins: keys, timestamp }).then((res) => res.data);
|
|
82
|
+
return coins;
|
|
83
|
+
}
|
|
164
84
|
}
|
|
165
85
|
function getPriceCache(timestamp) {
|
|
166
86
|
if (timestamp)
|
|
@@ -170,8 +90,8 @@ function getPriceCache(timestamp) {
|
|
|
170
90
|
return timestamp ? priceCaches[timestamp] : currentPriceCache;
|
|
171
91
|
}
|
|
172
92
|
function getUnique(addresses) {
|
|
173
|
-
|
|
174
|
-
addresses.forEach(
|
|
93
|
+
const set = {};
|
|
94
|
+
addresses.forEach(i => set[i] = true);
|
|
175
95
|
return Object.keys(set);
|
|
176
96
|
}
|
|
177
97
|
exports.getUnique = getUnique;
|
package/build/util/cosmos.js
CHANGED
|
@@ -1,52 +1,16 @@
|
|
|
1
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.getCosmosProvider = exports.getCosmosBlock = exports.isCosmosChain = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const env_1 = require("./env");
|
|
45
9
|
// where to find chain info
|
|
46
10
|
// https://proxy.atomscan.com/chains.json
|
|
47
11
|
// https://cosmos-chain.directory/chains/cosmoshub
|
|
48
12
|
// https://cosmos-chain.directory/chains
|
|
49
|
-
|
|
13
|
+
const endPoints = {
|
|
50
14
|
crescent: "https://mainnet.crescent.network:1317",
|
|
51
15
|
osmosis: "https://osmosis-api.polkachu.com",
|
|
52
16
|
cosmos: "https://cosmoshub-lcd.stakely.io",
|
|
@@ -78,48 +42,30 @@ var endPoints = {
|
|
|
78
42
|
nolus: "https://pirin-cl.nolus.network:1317",
|
|
79
43
|
bostrom: "https://lcd.bostrom.cybernode.ai"
|
|
80
44
|
};
|
|
81
|
-
|
|
82
|
-
|
|
45
|
+
const ibcChains = ['terra', 'terra2', 'crescent', 'osmosis', 'kujira', 'stargaze', 'juno', 'injective', 'cosmos', 'comdex', 'umee', 'orai', 'persistence', 'fxcore', 'neutron', 'quasar', 'chihuahua', 'sei', 'archway', 'migaloo', 'secret', 'aura', 'xpla', 'bostrom'];
|
|
46
|
+
const isCosmosChain = (chain) => ibcChains.includes(chain) || !!endPoints[chain];
|
|
83
47
|
exports.isCosmosChain = isCosmosChain;
|
|
84
|
-
function getCosmosBlock(block, chain) {
|
|
48
|
+
async function getCosmosBlock(block = 'latest', chain = 'cosmos') {
|
|
85
49
|
var _a;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return [4 /*yield*/, data.json()];
|
|
101
|
-
case 3:
|
|
102
|
-
_b = (_c.sent()).block.header, height = _b.height, time = _b.time;
|
|
103
|
-
return [2 /*return*/, {
|
|
104
|
-
number: Number(height),
|
|
105
|
-
timestamp: Math.floor(Date.parse(time) / 1000),
|
|
106
|
-
}];
|
|
107
|
-
case 4:
|
|
108
|
-
e_1 = _c.sent();
|
|
109
|
-
message = "Error fetchin cosmos block -\n chain: ".concat(chain, ", block: ").concat(block, ", endPoint: ").concat(endPoint, ", error: ").concat((_a = e_1 === null || e_1 === void 0 ? void 0 : e_1.message) !== null && _a !== void 0 ? _a : JSON.stringify(e_1));
|
|
110
|
-
throw new Error(message);
|
|
111
|
-
case 5: return [2 /*return*/];
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
50
|
+
const endPoint = (0, env_1.getEnvRPC)(chain) || endPoints[chain] || 'https://rest.cosmos.directory/' + chain;
|
|
51
|
+
try {
|
|
52
|
+
const { data } = await (0, axios_1.default)(`${endPoint}/blocks/${block}`);
|
|
53
|
+
const { block: { header: { height, time } } } = await data;
|
|
54
|
+
return {
|
|
55
|
+
number: Number(height),
|
|
56
|
+
timestamp: Math.floor(Date.parse(time) / 1000),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
const message = `Error fetchin cosmos block -
|
|
61
|
+
chain: ${chain}, block: ${block}, endPoint: ${endPoint}, error: ${(_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : JSON.stringify(e)}`;
|
|
62
|
+
throw new Error(message);
|
|
63
|
+
}
|
|
115
64
|
}
|
|
116
65
|
exports.getCosmosBlock = getCosmosBlock;
|
|
117
66
|
function getCosmosProvider(chain) {
|
|
118
67
|
return {
|
|
119
|
-
getBlock:
|
|
120
|
-
if (block === void 0) { block = 'latest'; }
|
|
121
|
-
return getCosmosBlock(block, chain);
|
|
122
|
-
}
|
|
68
|
+
getBlock: (block = 'latest') => getCosmosBlock(block, chain)
|
|
123
69
|
};
|
|
124
70
|
}
|
|
125
71
|
exports.getCosmosProvider = getCosmosProvider;
|
package/build/util/debugLog.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.debugTable = exports.debugLog = exports.DEBUG_ENABLED = void 0;
|
|
4
|
-
|
|
5
|
-
exports.DEBUG_ENABLED = env_1.ENV_CONSTANTS.
|
|
6
|
-
function debugLog() {
|
|
7
|
-
var args = [];
|
|
8
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
9
|
-
args[_i] = arguments[_i];
|
|
10
|
-
}
|
|
4
|
+
const env_1 = require("./env");
|
|
5
|
+
exports.DEBUG_ENABLED = env_1.ENV_CONSTANTS.DEBUG_ENABLED === "true";
|
|
6
|
+
function debugLog(...args) {
|
|
11
7
|
if (!exports.DEBUG_ENABLED)
|
|
12
8
|
return;
|
|
13
|
-
console.log
|
|
9
|
+
console.log(...args);
|
|
14
10
|
}
|
|
15
11
|
exports.debugLog = debugLog;
|
|
16
|
-
function debugTable() {
|
|
17
|
-
var args = [];
|
|
18
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
|
-
args[_i] = arguments[_i];
|
|
20
|
-
}
|
|
12
|
+
function debugTable(...args) {
|
|
21
13
|
if (!exports.DEBUG_ENABLED)
|
|
22
14
|
return;
|
|
23
|
-
console.table
|
|
15
|
+
console.table(...args);
|
|
24
16
|
}
|
|
25
17
|
exports.debugTable = debugTable;
|
package/build/util/env.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const ENV_CONSTANTS: {
|
|
2
2
|
[x: string]: string | undefined;
|
|
3
3
|
};
|
|
4
|
-
export declare function getChainId(chain: string, chainId: number
|
|
4
|
+
export declare function getChainId(chain: string, chainId: number): number;
|
|
5
5
|
export declare function getMaxParallelRequests(chain: string): number;
|
|
6
6
|
export declare function getParallelGetLogsLimit(chain: string): number;
|
|
7
7
|
export declare function getEnvRPC(chain: string): string | undefined;
|
package/build/util/env.js
CHANGED
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.getChainRPCs = exports.getArchivalRPCs = exports.getBatchMaxCount = exports.getDefaultChunkSize = exports.getEnvMulticallAddress = exports.getEnvCacheFolder = exports.getEnvValue = exports.getEnvRPC = exports.getParallelGetLogsLimit = exports.getMaxParallelRequests = exports.getChainId = exports.ENV_CONSTANTS = void 0;
|
|
15
|
-
|
|
4
|
+
const _ENV_CONSTANTS = {
|
|
16
5
|
DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
|
|
17
6
|
};
|
|
18
|
-
|
|
7
|
+
const whitelistedEnvConstants = [
|
|
19
8
|
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY',
|
|
20
9
|
];
|
|
21
|
-
|
|
10
|
+
const defaultEnvValues = {
|
|
22
11
|
INTERNAL_SDK_CACHE_FILE: './cache.json',
|
|
23
12
|
TRON_RPC_CONCURRENCY_LIMIT: '5',
|
|
24
13
|
TRON_RPC: 'https://api.trongrid.io',
|
|
25
14
|
};
|
|
26
|
-
whitelistedEnvConstants.forEach(
|
|
27
|
-
Object.keys(defaultEnvValues).forEach(
|
|
15
|
+
whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
|
|
16
|
+
Object.keys(defaultEnvValues).forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]));
|
|
28
17
|
// doing this as I am paranoid that that empty object when first declared might be exported before values are set
|
|
29
|
-
exports.ENV_CONSTANTS =
|
|
18
|
+
exports.ENV_CONSTANTS = { ..._ENV_CONSTANTS };
|
|
30
19
|
function getChainId(chain, chainId) {
|
|
31
20
|
var _a;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return +value;
|
|
21
|
+
const value = (_a = getEnvValue(`${chain}_RPC_CHAIN_ID`)) !== null && _a !== void 0 ? _a : chainId;
|
|
22
|
+
return +value;
|
|
35
23
|
}
|
|
36
24
|
exports.getChainId = getChainId;
|
|
37
25
|
function getMaxParallelRequests(chain) {
|
|
38
|
-
|
|
26
|
+
const chainKey = `${chain}_RPC_MAX_PARALLEL`;
|
|
39
27
|
if (getEnvValue(chainKey))
|
|
40
28
|
return +getEnvValue(chainKey);
|
|
41
29
|
if (['harmony', 'avax'].includes(chain))
|
|
@@ -44,18 +32,18 @@ function getMaxParallelRequests(chain) {
|
|
|
44
32
|
}
|
|
45
33
|
exports.getMaxParallelRequests = getMaxParallelRequests;
|
|
46
34
|
function getParallelGetLogsLimit(chain) {
|
|
47
|
-
|
|
48
|
-
return +(getEnvValue(
|
|
35
|
+
let defaultLimit = chain === 'fantom' ? '10' : '42';
|
|
36
|
+
return +(getEnvValue(`${chain}_RPC_GET_LOGS_CONCURRENCY_LIMIT`, defaultLimit));
|
|
49
37
|
}
|
|
50
38
|
exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
|
|
51
39
|
function getEnvRPC(chain) {
|
|
52
|
-
return getEnvValue(
|
|
40
|
+
return getEnvValue(`${chain}_RPC`);
|
|
53
41
|
}
|
|
54
42
|
exports.getEnvRPC = getEnvRPC;
|
|
55
43
|
function getEnvValue(key, defaultValue) {
|
|
56
44
|
var _a, _b, _c;
|
|
57
45
|
key = key.toUpperCase();
|
|
58
|
-
return (_c = (_b = (_a = process.env[key]) !== null && _a !== void 0 ? _a : process.env['SDK_' + key]) !== null && _b !== void 0 ? _b : process.env[
|
|
46
|
+
return (_c = (_b = (_a = process.env['LLAMA_SDK_' + key]) !== null && _a !== void 0 ? _a : process.env['SDK_' + key]) !== null && _b !== void 0 ? _b : process.env[key]) !== null && _c !== void 0 ? _c : defaultValue;
|
|
59
47
|
}
|
|
60
48
|
exports.getEnvValue = getEnvValue;
|
|
61
49
|
function getEnvCacheFolder(defaultCacheFolder) {
|
|
@@ -63,11 +51,11 @@ function getEnvCacheFolder(defaultCacheFolder) {
|
|
|
63
51
|
}
|
|
64
52
|
exports.getEnvCacheFolder = getEnvCacheFolder;
|
|
65
53
|
function getEnvMulticallAddress(chain) {
|
|
66
|
-
return getEnvValue(
|
|
54
|
+
return getEnvValue(`${chain}_RPC_MULTICALL`);
|
|
67
55
|
}
|
|
68
56
|
exports.getEnvMulticallAddress = getEnvMulticallAddress;
|
|
69
57
|
function getDefaultChunkSize(chain) {
|
|
70
|
-
|
|
58
|
+
const key = chain + '_MULTICALL_CHUNK_SIZE';
|
|
71
59
|
if (getEnvValue(key))
|
|
72
60
|
return +getEnvValue(key);
|
|
73
61
|
if (chain === 'cronos')
|
|
@@ -76,24 +64,25 @@ function getDefaultChunkSize(chain) {
|
|
|
76
64
|
}
|
|
77
65
|
exports.getDefaultChunkSize = getDefaultChunkSize;
|
|
78
66
|
function getBatchMaxCount(chain) {
|
|
79
|
-
|
|
67
|
+
const key = chain + '_BATCH_MAX_COUNT';
|
|
80
68
|
if (getEnvValue(key))
|
|
81
69
|
return +getEnvValue(key);
|
|
82
|
-
|
|
83
|
-
return
|
|
84
|
-
|
|
70
|
+
switch (chain) {
|
|
71
|
+
case 'cronos': return 5;
|
|
72
|
+
case 'zkfair': return 1;
|
|
73
|
+
default: return +getEnvValue('BATCH_MAX_COUNT', '99');
|
|
74
|
+
}
|
|
85
75
|
}
|
|
86
76
|
exports.getBatchMaxCount = getBatchMaxCount;
|
|
87
77
|
function getArchivalRPCs(chain) {
|
|
88
|
-
|
|
78
|
+
const key = chain + '_ARCHIVAL_RPC';
|
|
89
79
|
if (getEnvValue(key))
|
|
90
80
|
return getEnvValue(key).split(',');
|
|
91
81
|
return [];
|
|
92
82
|
}
|
|
93
83
|
exports.getArchivalRPCs = getArchivalRPCs;
|
|
94
|
-
function getChainRPCs(chain, defaultList) {
|
|
95
|
-
|
|
96
|
-
var key = chain + '_RPC';
|
|
84
|
+
function getChainRPCs(chain, defaultList = []) {
|
|
85
|
+
const key = chain + '_RPC';
|
|
97
86
|
if (getEnvValue(key))
|
|
98
87
|
return getEnvValue(key).split(',').concat(defaultList).join(',');
|
|
99
88
|
if (defaultList.length === 0)
|