@steerprotocol/data-connector-loader 0.0.14 → 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.js +27 -10
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -122,17 +122,28 @@ class DataConnectorExecution {
|
|
|
122
122
|
getAverageBlockTime(provider, blockCount = 5) {
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
const latestBlock = yield provider.getBlock('latest');
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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;
|
|
133
146
|
}
|
|
134
|
-
const averageBlockTime = totalTimeDiff / (blockCount - 1);
|
|
135
|
-
return averageBlockTime;
|
|
136
147
|
});
|
|
137
148
|
}
|
|
138
149
|
getBlockNumberFromAvgBlockTime(provider, targetTimestamp, avgBlockTime) {
|
|
@@ -140,6 +151,12 @@ class DataConnectorExecution {
|
|
|
140
151
|
const latestBlock = yield provider.getBlock('latest');
|
|
141
152
|
const currentTime = Math.floor(Date.now() / 1000);
|
|
142
153
|
const timeDifference = currentTime - targetTimestamp;
|
|
154
|
+
if (!latestBlock) {
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
if (avgBlockTime === 0) {
|
|
158
|
+
return latestBlock.number;
|
|
159
|
+
}
|
|
143
160
|
// Calculate the estimated number of blocks based on the average block time
|
|
144
161
|
const estimatedBlockCount = Math.floor(timeDifference / avgBlockTime);
|
|
145
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",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"lint:fix": "eslint src --fix --ext .js,.ts",
|
|
12
12
|
"test": "jest --config jest.config.js",
|
|
13
13
|
"prepare": "npm run build",
|
|
14
|
-
"prepublishOnly": "npm run lint",
|
|
14
|
+
"prepublishOnly": "npm test && npm run lint",
|
|
15
15
|
"preversion": "npm run lint",
|
|
16
16
|
"version": "npm run format && git add -A src",
|
|
17
17
|
"postversion": "git push && git push --tags"
|
|
@@ -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"
|