@defillama/sdk 2.3.4 → 2.3.5
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/util/index.js +18 -2
- package/package.json +1 -1
package/build/util/index.js
CHANGED
|
@@ -68,6 +68,22 @@ var terraBlockProvider = {
|
|
|
68
68
|
});
|
|
69
69
|
}); },
|
|
70
70
|
};
|
|
71
|
+
function getBlock(provider, height, chain) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var block;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, provider.getBlock(height)];
|
|
77
|
+
case 1:
|
|
78
|
+
block = _a.sent();
|
|
79
|
+
if (block === null) {
|
|
80
|
+
throw new Error("Can't get block of chain " + (chain !== null && chain !== void 0 ? chain : 'ethereum'));
|
|
81
|
+
}
|
|
82
|
+
return [2 /*return*/, block];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
71
87
|
function lookupBlock(timestamp, extraParams) {
|
|
72
88
|
var _a, _b, _c;
|
|
73
89
|
if (extraParams === void 0) { extraParams = {}; }
|
|
@@ -80,7 +96,7 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
80
96
|
provider = extraParams.chain === "terra"
|
|
81
97
|
? terraBlockProvider
|
|
82
98
|
: general_1.getProvider(extraParams.chain);
|
|
83
|
-
return [4 /*yield*/,
|
|
99
|
+
return [4 /*yield*/, getBlock(provider, "latest", extraParams.chain)];
|
|
84
100
|
case 1:
|
|
85
101
|
lastBlock = _d.sent();
|
|
86
102
|
if ((lastBlock.timestamp - timestamp) < -30 * 60) {
|
|
@@ -99,7 +115,7 @@ function lookupBlock(timestamp, extraParams) {
|
|
|
99
115
|
_d.label = 2;
|
|
100
116
|
case 2:
|
|
101
117
|
mid = Math.floor((high + low) / 2);
|
|
102
|
-
return [4 /*yield*/,
|
|
118
|
+
return [4 /*yield*/, getBlock(provider, mid, extraParams.chain)];
|
|
103
119
|
case 3:
|
|
104
120
|
block = _d.sent();
|
|
105
121
|
if (block.timestamp < timestamp) {
|