@defillama/sdk 4.0.47 → 4.0.49
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 +5 -5
- package/build/abi/tron.js +11 -6
- package/build/index.d.ts +1 -0
- package/build/index.js +2 -1
- package/build/providers.json +1 -1
- package/build/util/cache.d.ts +12 -11
- package/build/util/cache.js +208 -59
- package/build/util/internal-cache.d.ts +11 -0
- package/build/util/internal-cache.js +68 -0
- package/build/util/r2.d.ts +3 -0
- package/build/util/r2.js +113 -0
- package/package.json +3 -1
package/build/util/cache.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
export declare function readCache(file: string, options?: ReadCacheOptions): Promise<any>;
|
|
2
|
+
interface WriteCacheOptions {
|
|
3
|
+
skipR2CacheWrite?: boolean;
|
|
4
|
+
alreadyCompressed?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface ReadCacheOptions {
|
|
7
|
+
skipR2Cache?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function writeCache(file: string, data: any, options?: WriteCacheOptions): Promise<string | undefined>;
|
|
10
|
+
export declare function parseCache(dataString: string | object): Promise<any>;
|
|
11
|
+
export declare function compressCache(data: any): Promise<any>;
|
|
12
|
+
export {};
|
package/build/util/cache.js
CHANGED
|
@@ -1,68 +1,217 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 };
|
|
7
36
|
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
37
|
};
|
|
25
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return
|
|
39
|
+
exports.compressCache = exports.parseCache = exports.writeCache = exports.readCache = void 0;
|
|
40
|
+
var debugLog_1 = require("./debugLog");
|
|
41
|
+
var r2_1 = require("./r2");
|
|
42
|
+
var fs = require('fs').promises;
|
|
43
|
+
var path = require('path');
|
|
44
|
+
var lzma = require('lzma-native');
|
|
45
|
+
var promisify = require('util').promisify;
|
|
46
|
+
var zipAsync = promisify(lzma.compress);
|
|
47
|
+
var unzipAsync = promisify(lzma.decompress);
|
|
48
|
+
var foldersCreated = {};
|
|
49
|
+
var currentVersion = 'llama-zip-1.0.0';
|
|
50
|
+
function getCacheRootFolder() {
|
|
51
|
+
return process.env.TVL_LOCAL_CACHE_ROOT_FOLDER || path.join(__dirname, 'local_cache');
|
|
52
|
+
}
|
|
53
|
+
function getFilePath(file) {
|
|
54
|
+
return path.join(getCacheRootFolder(), file);
|
|
55
|
+
}
|
|
56
|
+
function createSubPath(folderPath) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var datRoot, error_1;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
datRoot = getCacheRootFolder();
|
|
63
|
+
folderPath = folderPath.replace(datRoot, '');
|
|
64
|
+
if (foldersCreated[folderPath])
|
|
65
|
+
return [2 /*return*/];
|
|
66
|
+
_a.label = 1;
|
|
67
|
+
case 1:
|
|
68
|
+
_a.trys.push([1, 3, , 4]);
|
|
69
|
+
return [4 /*yield*/, fs.mkdir(path.join(datRoot, folderPath), { recursive: true })];
|
|
70
|
+
case 2:
|
|
71
|
+
_a.sent();
|
|
72
|
+
return [3 /*break*/, 4];
|
|
73
|
+
case 3:
|
|
74
|
+
error_1 = _a.sent();
|
|
75
|
+
return [3 /*break*/, 4];
|
|
76
|
+
case 4:
|
|
77
|
+
foldersCreated[folderPath] = true;
|
|
78
|
+
return [2 /*return*/];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function readCache(file, options) {
|
|
84
|
+
if (options === void 0) { options = {}; }
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
function readFile(file, options) {
|
|
87
|
+
if (options === void 0) { options = {}; }
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var filePath, data, error_3, r2Data;
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
filePath = getFilePath(file);
|
|
94
|
+
_a.label = 1;
|
|
95
|
+
case 1:
|
|
96
|
+
_a.trys.push([1, 3, , 7]);
|
|
97
|
+
return [4 /*yield*/, fs.readFile(filePath)];
|
|
98
|
+
case 2:
|
|
99
|
+
data = _a.sent();
|
|
100
|
+
return [2 /*return*/, data];
|
|
101
|
+
case 3:
|
|
102
|
+
error_3 = _a.sent();
|
|
103
|
+
// debugLog('Error reading cache:', error)
|
|
104
|
+
if (options.skipR2Cache)
|
|
105
|
+
return [2 /*return*/];
|
|
106
|
+
return [4 /*yield*/, (0, r2_1.getR2JSONString)(file)];
|
|
107
|
+
case 4:
|
|
108
|
+
r2Data = _a.sent();
|
|
109
|
+
if (!r2Data) return [3 /*break*/, 6];
|
|
110
|
+
return [4 /*yield*/, writeCache(file, r2Data, { alreadyCompressed: true, skipR2CacheWrite: true })];
|
|
111
|
+
case 5:
|
|
112
|
+
_a.sent();
|
|
113
|
+
return [2 /*return*/, r2Data];
|
|
114
|
+
case 6: return [3 /*break*/, 7];
|
|
115
|
+
case 7: return [2 /*return*/];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
var data, error_2;
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
switch (_a.label) {
|
|
123
|
+
case 0:
|
|
124
|
+
_a.trys.push([0, 3, , 4]);
|
|
125
|
+
return [4 /*yield*/, readFile(file, options)];
|
|
126
|
+
case 1:
|
|
127
|
+
data = _a.sent();
|
|
128
|
+
return [4 /*yield*/, parseCache(data)];
|
|
129
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
130
|
+
case 3:
|
|
131
|
+
error_2 = _a.sent();
|
|
132
|
+
// debugLog('Error reading cache:', error)
|
|
133
|
+
return [2 /*return*/, {}];
|
|
134
|
+
case 4: return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
42
138
|
}
|
|
43
|
-
exports.
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
139
|
+
exports.readCache = readCache;
|
|
140
|
+
function writeCache(file, data, options) {
|
|
141
|
+
if (options === void 0) { options = {}; }
|
|
142
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
+
var fileData, _a, _b, _c, filePath;
|
|
144
|
+
return __generator(this, function (_d) {
|
|
145
|
+
switch (_d.label) {
|
|
146
|
+
case 0:
|
|
147
|
+
if (!options.alreadyCompressed) return [3 /*break*/, 1];
|
|
148
|
+
_a = data;
|
|
149
|
+
return [3 /*break*/, 3];
|
|
150
|
+
case 1: return [4 /*yield*/, compressCache(data)];
|
|
151
|
+
case 2:
|
|
152
|
+
_a = _d.sent();
|
|
153
|
+
_d.label = 3;
|
|
154
|
+
case 3:
|
|
155
|
+
fileData = _a;
|
|
156
|
+
if (!data || (typeof data === 'string' && data.length < 50) || fileData.length < 120) {
|
|
157
|
+
(0, debugLog_1.debugLog)('Data too small to cache: ', file);
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
_b = isSameData;
|
|
161
|
+
_c = [data];
|
|
162
|
+
return [4 /*yield*/, readCache(file, { skipR2Cache: true })];
|
|
163
|
+
case 4:
|
|
164
|
+
if (_b.apply(void 0, _c.concat([_d.sent()])))
|
|
165
|
+
return [2 /*return*/];
|
|
166
|
+
filePath = getFilePath(file);
|
|
167
|
+
return [4 /*yield*/, createSubPath(path.dirname(filePath))];
|
|
168
|
+
case 5:
|
|
169
|
+
_d.sent();
|
|
170
|
+
return [4 /*yield*/, fs.writeFile(filePath, fileData)];
|
|
171
|
+
case 6:
|
|
172
|
+
_d.sent();
|
|
173
|
+
if (!!options.skipR2CacheWrite) return [3 /*break*/, 8];
|
|
174
|
+
return [4 /*yield*/, (0, r2_1.storeR2JSONString)(file, fileData)];
|
|
175
|
+
case 7:
|
|
176
|
+
_d.sent();
|
|
177
|
+
_d.label = 8;
|
|
178
|
+
case 8: return [2 /*return*/, fileData];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
54
182
|
}
|
|
55
|
-
exports.
|
|
56
|
-
function
|
|
57
|
-
|
|
183
|
+
exports.writeCache = writeCache;
|
|
184
|
+
function parseCache(dataString) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
var decompressed;
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
switch (_a.label) {
|
|
189
|
+
case 0:
|
|
190
|
+
if (typeof dataString === 'string')
|
|
191
|
+
dataString = Buffer.from(dataString, 'base64');
|
|
192
|
+
return [4 /*yield*/, unzipAsync(dataString)];
|
|
193
|
+
case 1:
|
|
194
|
+
decompressed = _a.sent();
|
|
195
|
+
return [2 /*return*/, JSON.parse(decompressed).llamaWrapped];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
58
199
|
}
|
|
59
|
-
exports.
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
200
|
+
exports.parseCache = parseCache;
|
|
201
|
+
function compressCache(data) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
var comressedCache;
|
|
204
|
+
return __generator(this, function (_a) {
|
|
205
|
+
switch (_a.label) {
|
|
206
|
+
case 0: return [4 /*yield*/, zipAsync(JSON.stringify({ version: currentVersion, llamaWrapped: data }), 9)];
|
|
207
|
+
case 1:
|
|
208
|
+
comressedCache = _a.sent();
|
|
209
|
+
return [2 /*return*/, comressedCache];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
63
213
|
}
|
|
64
|
-
exports.
|
|
65
|
-
function
|
|
66
|
-
return
|
|
214
|
+
exports.compressCache = compressCache;
|
|
215
|
+
function isSameData(data1, data2) {
|
|
216
|
+
return JSON.stringify(data1) === JSON.stringify(data2);
|
|
67
217
|
}
|
|
68
|
-
exports.retriveCache = retriveCache;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function getCache(options: CacheOptions): any;
|
|
2
|
+
export declare function setCache(options: CacheOptions): void;
|
|
3
|
+
export declare function saveCache(): void;
|
|
4
|
+
export declare function startCache(_cache?: {}): void;
|
|
5
|
+
export declare function retriveCache(): any;
|
|
6
|
+
export type CacheOptions = {
|
|
7
|
+
address: string;
|
|
8
|
+
abi: string;
|
|
9
|
+
chain?: string;
|
|
10
|
+
value?: any;
|
|
11
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.retriveCache = exports.startCache = exports.saveCache = exports.setCache = exports.getCache = void 0;
|
|
27
|
+
var fs = __importStar(require("fs"));
|
|
28
|
+
// const cacheFile = __dirname + '/../../../sc-cache1.json'
|
|
29
|
+
var cacheFile = process.env.INTERNAL_SDK_CACHE_FILE;
|
|
30
|
+
var cache = {};
|
|
31
|
+
// if (cacheFile) cache = require(cacheFile) // disabled for now
|
|
32
|
+
function getCache(options) {
|
|
33
|
+
var address = options.address, abi = options.abi, _a = options.chain, chain = _a === void 0 ? "ethereum" : _a;
|
|
34
|
+
if (!address)
|
|
35
|
+
return;
|
|
36
|
+
address = address.slice(2).toLowerCase();
|
|
37
|
+
if (!cache[chain])
|
|
38
|
+
cache[chain] = {};
|
|
39
|
+
if (!cache[chain][abi])
|
|
40
|
+
cache[chain][abi] = {};
|
|
41
|
+
return cache[chain][abi][address];
|
|
42
|
+
}
|
|
43
|
+
exports.getCache = getCache;
|
|
44
|
+
function setCache(options) {
|
|
45
|
+
var address = options.address, abi = options.abi, _a = options.chain, chain = _a === void 0 ? "ethereum" : _a, value = options.value;
|
|
46
|
+
if (!address)
|
|
47
|
+
return;
|
|
48
|
+
address = address.slice(2).toLowerCase();
|
|
49
|
+
if (!cache[chain])
|
|
50
|
+
cache[chain] = {};
|
|
51
|
+
if (!cache[chain][abi])
|
|
52
|
+
cache[chain][abi] = {};
|
|
53
|
+
cache[chain][abi][address] = value;
|
|
54
|
+
}
|
|
55
|
+
exports.setCache = setCache;
|
|
56
|
+
function saveCache() {
|
|
57
|
+
fs.writeFileSync(cacheFile || './cache.json', JSON.stringify(cache));
|
|
58
|
+
}
|
|
59
|
+
exports.saveCache = saveCache;
|
|
60
|
+
function startCache(_cache) {
|
|
61
|
+
if (_cache === void 0) { _cache = {}; }
|
|
62
|
+
cache = _cache;
|
|
63
|
+
}
|
|
64
|
+
exports.startCache = startCache;
|
|
65
|
+
function retriveCache() {
|
|
66
|
+
return cache;
|
|
67
|
+
}
|
|
68
|
+
exports.retriveCache = retriveCache;
|
package/build/util/r2.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getR2JSONString = exports.storeR2JSONString = void 0;
|
|
40
|
+
var _a = require("@aws-sdk/client-s3"), S3Client = _a.S3Client, PutObjectCommand = _a.PutObjectCommand, GetObjectCommand = _a.GetObjectCommand;
|
|
41
|
+
var _b = process.env, R2_ENDPOINT = _b.R2_ENDPOINT, R2_ACCESS_KEY_ID = _b.R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY = _b.R2_SECRET_ACCESS_KEY;
|
|
42
|
+
var datasetBucket = "defillama-datasets";
|
|
43
|
+
var publicBucketUrl = "https://defillama-datasets.llama.fi";
|
|
44
|
+
var R2;
|
|
45
|
+
if (R2_ENDPOINT && R2_ACCESS_KEY_ID && R2_SECRET_ACCESS_KEY) {
|
|
46
|
+
R2 = new S3Client({
|
|
47
|
+
region: "auto",
|
|
48
|
+
endpoint: "https://" + R2_ENDPOINT,
|
|
49
|
+
credentials: {
|
|
50
|
+
accessKeyId: R2_ACCESS_KEY_ID,
|
|
51
|
+
secretAccessKey: R2_SECRET_ACCESS_KEY,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
var getKey = function (filename) { return filename.replace(/(:|'|#)/g, '/'); };
|
|
56
|
+
function storeR2JSONString(filename, body) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var command;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
if (typeof body !== 'string')
|
|
61
|
+
body = body.toString('base64');
|
|
62
|
+
if (!R2)
|
|
63
|
+
return [2 /*return*/];
|
|
64
|
+
command = new PutObjectCommand({
|
|
65
|
+
Bucket: datasetBucket,
|
|
66
|
+
Key: getKey(filename),
|
|
67
|
+
Body: body,
|
|
68
|
+
ContentType: "application/json",
|
|
69
|
+
});
|
|
70
|
+
return [2 /*return*/, R2.send(command)];
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.storeR2JSONString = storeR2JSONString;
|
|
75
|
+
function getR2JSONString(filename) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
function _fetchData() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var response;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0: return [4 /*yield*/, fetch("".concat(publicBucketUrl, "/").concat(filename))];
|
|
83
|
+
case 1:
|
|
84
|
+
response = _a.sent();
|
|
85
|
+
return [2 /*return*/, response.text()];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
var command, Body, e_1;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
_a.trys.push([0, 5, , 6]);
|
|
95
|
+
if (!!R2) return [3 /*break*/, 2];
|
|
96
|
+
return [4 /*yield*/, _fetchData()];
|
|
97
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
98
|
+
case 2:
|
|
99
|
+
command = new GetObjectCommand({ Bucket: datasetBucket, Key: getKey(filename), });
|
|
100
|
+
return [4 /*yield*/, R2.send(command)];
|
|
101
|
+
case 3:
|
|
102
|
+
Body = (_a.sent()).Body;
|
|
103
|
+
return [4 /*yield*/, Body.transformToString()];
|
|
104
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
105
|
+
case 5:
|
|
106
|
+
e_1 = _a.sent();
|
|
107
|
+
return [2 /*return*/, {}];
|
|
108
|
+
case 6: return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.getR2JSONString = getR2JSONString;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defillama/sdk",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.49",
|
|
4
4
|
"description": "SDK for calculating TVL",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,8 +23,10 @@
|
|
|
23
23
|
"build"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@aws-sdk/client-s3": "^3.400.0",
|
|
26
27
|
"@supercharge/promise-pool": "^2.1.0",
|
|
27
28
|
"ethers": "^5.4.5",
|
|
29
|
+
"lzma-native": "^8.0.6",
|
|
28
30
|
"node-fetch": "^2.6.7",
|
|
29
31
|
"tron-format-address": "^0.1.11"
|
|
30
32
|
},
|