@steerprotocol/data-connector-loader 0.0.15 → 0.0.16
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/lib/index.d.ts +0 -1
- package/lib/index.js +28 -13
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -12,9 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.DataConnectorExecution =
|
|
16
|
-
const dataConnector_1 = require("./dataConnector");
|
|
17
|
-
Object.defineProperty(exports, "DataConnector", { enumerable: true, get: function () { return dataConnector_1.DataConnector; } });
|
|
15
|
+
exports.DataConnectorExecution = void 0;
|
|
18
16
|
const axios_1 = __importDefault(require("axios"));
|
|
19
17
|
const pluginManager_1 = require("./pluginManager");
|
|
20
18
|
class DataConnectorExecution {
|
|
@@ -124,17 +122,28 @@ class DataConnectorExecution {
|
|
|
124
122
|
getAverageBlockTime(provider, blockCount = 5) {
|
|
125
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
124
|
const latestBlock = yield provider.getBlock('latest');
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
125
|
+
if (latestBlock) {
|
|
126
|
+
const startBlockNumber = Math.max(0, latestBlock.number - blockCount + 1);
|
|
127
|
+
let totalTimeDiff = 0;
|
|
128
|
+
let previousBlock = yield provider.getBlock(startBlockNumber);
|
|
129
|
+
if (!previousBlock) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
for (let i = startBlockNumber + 1; i <= latestBlock.number; i++) {
|
|
133
|
+
const currentBlock = yield provider.getBlock(i);
|
|
134
|
+
if (!currentBlock || !previousBlock || !currentBlock.timestamp || !previousBlock.timestamp) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const timeDiff = currentBlock.timestamp - previousBlock.timestamp;
|
|
138
|
+
totalTimeDiff += timeDiff;
|
|
139
|
+
previousBlock = currentBlock;
|
|
140
|
+
}
|
|
141
|
+
const averageBlockTime = totalTimeDiff / (blockCount - 1);
|
|
142
|
+
return averageBlockTime;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return 0;
|
|
135
146
|
}
|
|
136
|
-
const averageBlockTime = totalTimeDiff / (blockCount - 1);
|
|
137
|
-
return averageBlockTime;
|
|
138
147
|
});
|
|
139
148
|
}
|
|
140
149
|
getBlockNumberFromAvgBlockTime(provider, targetTimestamp, avgBlockTime) {
|
|
@@ -142,6 +151,12 @@ class DataConnectorExecution {
|
|
|
142
151
|
const latestBlock = yield provider.getBlock('latest');
|
|
143
152
|
const currentTime = Math.floor(Date.now() / 1000);
|
|
144
153
|
const timeDifference = currentTime - targetTimestamp;
|
|
154
|
+
if (!latestBlock) {
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
if (avgBlockTime === 0) {
|
|
158
|
+
return latestBlock.number;
|
|
159
|
+
}
|
|
145
160
|
// Calculate the estimated number of blocks based on the average block time
|
|
146
161
|
const estimatedBlockCount = Math.floor(timeDifference / avgBlockTime);
|
|
147
162
|
// Calculate the estimated block number
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/data-connector-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@steerprotocol/app-loader": "0.1.6",
|
|
50
|
-
"@steerprotocol/strategy-utils": "^2.1.
|
|
50
|
+
"@steerprotocol/strategy-utils": "^2.1.0",
|
|
51
51
|
"axios": "^1.3.4",
|
|
52
52
|
"ethers": "^5.1.0",
|
|
53
53
|
"pondjs": "1.0.0-alpha.10"
|