@steerprotocol/data-connector-loader 2.1.0 → 3.0.0

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.
Files changed (52) hide show
  1. package/lib/{base → esm/bundle}/bundleBase.d.ts +7 -5
  2. package/lib/esm/bundle/bundleBase.js +127 -0
  3. package/lib/{bundle/bundleExecution.d.ts → esm/bundle/bundleDataConnector.d.ts} +2 -1
  4. package/lib/esm/bundle/bundleDataConnector.js +57 -0
  5. package/lib/esm/execution/executionApp.d.ts +17 -0
  6. package/lib/esm/execution/executionApp.js +304 -0
  7. package/lib/{loader/loaderBase.d.ts → esm/execution/executionBase.d.ts} +2 -2
  8. package/lib/esm/execution/executionBase.js +95 -0
  9. package/lib/esm/execution/executionDataConnector.d.ts +9 -0
  10. package/lib/esm/execution/executionDataConnector.js +90 -0
  11. package/lib/esm/index.d.ts +5 -0
  12. package/lib/esm/index.js +5 -0
  13. package/lib/esm/package.json +1 -0
  14. package/lib/esm/types.d.ts +104 -0
  15. package/lib/esm/types.js +1 -0
  16. package/lib/esm/utils/blockFinder.js +20 -0
  17. package/lib/esm/utils/consts.d.ts +4 -0
  18. package/lib/esm/utils/consts.js +4 -0
  19. package/lib/esm/utils/pluginManager.js +67 -0
  20. package/lib/esm/utils/utils.d.ts +16 -0
  21. package/lib/esm/utils/utils.js +119 -0
  22. package/lib/execution/executionApp.d.ts +3 -3
  23. package/lib/execution/executionApp.js +78 -80
  24. package/lib/execution/executionDataConnector.d.ts +2 -2
  25. package/lib/index.d.ts +1 -0
  26. package/lib/index.js +15 -0
  27. package/lib/types.d.ts +1 -1
  28. package/lib/utils/consts.js +2 -2
  29. package/lib/utils/utils.d.ts +5 -5
  30. package/lib/utils/utils.js +5 -5
  31. package/package.json +33 -3
  32. package/lib/base/bundleBase.js +0 -119
  33. package/lib/base/loaderBase.d.ts +0 -14
  34. package/lib/base/loaderBase.js +0 -111
  35. package/lib/blockFinder.js +0 -36
  36. package/lib/bundle/bundleApp.d.ts +0 -6
  37. package/lib/bundle/bundleApp.js +0 -11
  38. package/lib/bundle/bundleExecution.js +0 -42
  39. package/lib/bundleDataConnector.d.ts +0 -7
  40. package/lib/bundleDataConnector.js +0 -42
  41. package/lib/bundleExecution.d.ts +0 -7
  42. package/lib/bundleExecution.js +0 -42
  43. package/lib/dataConnector.d.ts +0 -27
  44. package/lib/dataConnector.js +0 -133
  45. package/lib/execution/executionBundle.d.ts +0 -5
  46. package/lib/execution/executionBundle.js +0 -29
  47. package/lib/loader/loaderBase.js +0 -111
  48. package/lib/pluginManager.js +0 -84
  49. package/lib/utils.d.ts +0 -2
  50. package/lib/utils.js +0 -28
  51. /package/lib/{blockFinder.d.ts → esm/utils/blockFinder.d.ts} +0 -0
  52. /package/lib/{pluginManager.d.ts → esm/utils/pluginManager.d.ts} +0 -0
@@ -20,36 +20,36 @@ class ExecutionApp extends executionBase_1.ExecutionBase {
20
20
  const slot0Abi = [
21
21
  {
22
22
  inputs: [],
23
- name: "slot0",
23
+ name: 'slot0',
24
24
  outputs: [
25
- { internalType: "uint160", name: "sqrtPriceX96", type: "uint160" },
26
- { internalType: "int24", name: "tick", type: "int24" },
27
- { internalType: "uint16", name: "observationIndex", type: "uint16" },
25
+ { internalType: 'uint160', name: 'sqrtPriceX96', type: 'uint160' },
26
+ { internalType: 'int24', name: 'tick', type: 'int24' },
27
+ { internalType: 'uint16', name: 'observationIndex', type: 'uint16' },
28
28
  {
29
- internalType: "uint16",
30
- name: "observationCardinality",
31
- type: "uint16",
29
+ internalType: 'uint16',
30
+ name: 'observationCardinality',
31
+ type: 'uint16',
32
32
  },
33
33
  {
34
- internalType: "uint16",
35
- name: "observationCardinalityNext",
36
- type: "uint16",
34
+ internalType: 'uint16',
35
+ name: 'observationCardinalityNext',
36
+ type: 'uint16',
37
37
  },
38
- { internalType: "uint8", name: "feeProtocol", type: "uint8" },
39
- { internalType: "bool", name: "unlocked", type: "bool" },
38
+ { internalType: 'uint8', name: 'feeProtocol', type: 'uint8' },
39
+ { internalType: 'bool', name: 'unlocked', type: 'bool' },
40
40
  ],
41
- stateMutability: "view",
42
- type: "function",
41
+ stateMutability: 'view',
42
+ type: 'function',
43
43
  },
44
44
  ];
45
45
  const slot0 = yield (0, utils_1.readSlot0Contract)({
46
46
  address: pool,
47
47
  abi: slot0Abi,
48
48
  currentExecutionContext,
49
- functionName: "slot0",
49
+ functionName: 'slot0',
50
50
  provider: provider,
51
51
  rpc,
52
- chainId: this.chainId
52
+ chainId: this.chainId,
53
53
  });
54
54
  return {
55
55
  sqrtPriceX96: slot0[0],
@@ -66,104 +66,104 @@ class ExecutionApp extends executionBase_1.ExecutionBase {
66
66
  !this.isDirectionalPool
67
67
  ? {
68
68
  inputs: [],
69
- name: "globalState",
69
+ name: 'globalState',
70
70
  outputs: [
71
71
  {
72
- internalType: "uint160",
73
- name: "price",
74
- type: "uint160",
72
+ internalType: 'uint160',
73
+ name: 'price',
74
+ type: 'uint160',
75
75
  },
76
76
  {
77
- internalType: "int24",
78
- name: "tick",
79
- type: "int24",
77
+ internalType: 'int24',
78
+ name: 'tick',
79
+ type: 'int24',
80
80
  },
81
81
  {
82
- internalType: "int24",
83
- name: "prevInitializedTick",
84
- type: "int24",
82
+ internalType: 'int24',
83
+ name: 'prevInitializedTick',
84
+ type: 'int24',
85
85
  },
86
86
  {
87
- internalType: "uint16",
88
- name: "fee",
89
- type: "uint16",
87
+ internalType: 'uint16',
88
+ name: 'fee',
89
+ type: 'uint16',
90
90
  },
91
91
  {
92
- internalType: "uint16",
93
- name: "timepointIndex",
94
- type: "uint16",
92
+ internalType: 'uint16',
93
+ name: 'timepointIndex',
94
+ type: 'uint16',
95
95
  },
96
96
  {
97
- internalType: "uint8",
98
- name: "communityFee",
99
- type: "uint8",
97
+ internalType: 'uint8',
98
+ name: 'communityFee',
99
+ type: 'uint8',
100
100
  },
101
101
  {
102
- internalType: "bool",
103
- name: "unlocked",
104
- type: "bool",
102
+ internalType: 'bool',
103
+ name: 'unlocked',
104
+ type: 'bool',
105
105
  },
106
106
  ],
107
- stateMutability: "view",
108
- type: "function",
107
+ stateMutability: 'view',
108
+ type: 'function',
109
109
  }
110
110
  : {
111
111
  inputs: [],
112
- name: "globalState",
112
+ name: 'globalState',
113
113
  outputs: [
114
114
  {
115
- internalType: "uint160",
116
- name: "price",
117
- type: "uint160",
115
+ internalType: 'uint160',
116
+ name: 'price',
117
+ type: 'uint160',
118
118
  },
119
119
  {
120
- internalType: "int24",
121
- name: "tick",
122
- type: "int24",
120
+ internalType: 'int24',
121
+ name: 'tick',
122
+ type: 'int24',
123
123
  },
124
124
  {
125
- internalType: "uint16",
126
- name: "feeZto",
127
- type: "uint16",
125
+ internalType: 'uint16',
126
+ name: 'feeZto',
127
+ type: 'uint16',
128
128
  },
129
129
  {
130
- internalType: "uint16",
131
- name: "feeOtz",
132
- type: "uint16",
130
+ internalType: 'uint16',
131
+ name: 'feeOtz',
132
+ type: 'uint16',
133
133
  },
134
134
  {
135
- internalType: "uint16",
136
- name: "timepointIndex",
137
- type: "uint16",
135
+ internalType: 'uint16',
136
+ name: 'timepointIndex',
137
+ type: 'uint16',
138
138
  },
139
139
  {
140
- internalType: "uint8",
141
- name: "communityFeeToken0",
142
- type: "uint8",
140
+ internalType: 'uint8',
141
+ name: 'communityFeeToken0',
142
+ type: 'uint8',
143
143
  },
144
144
  {
145
- internalType: "uint8",
146
- name: "communityFeeToken1",
147
- type: "uint8",
145
+ internalType: 'uint8',
146
+ name: 'communityFeeToken1',
147
+ type: 'uint8',
148
148
  },
149
149
  {
150
- internalType: "bool",
151
- name: "unlocked",
152
- type: "bool",
150
+ internalType: 'bool',
151
+ name: 'unlocked',
152
+ type: 'bool',
153
153
  },
154
154
  ],
155
- stateMutability: "view",
156
- type: "function",
155
+ stateMutability: 'view',
156
+ type: 'function',
157
157
  },
158
158
  ];
159
159
  const slot0 = yield (0, utils_1.readSlot0Contract)({
160
160
  address: pool,
161
161
  abi: slot0Abi,
162
162
  currentExecutionContext,
163
- functionName: "globalState",
163
+ functionName: 'globalState',
164
164
  provider: provider,
165
165
  rpc,
166
- chainId: this.chainId
166
+ chainId: this.chainId,
167
167
  });
168
168
  return this.isDirectionalPool
169
169
  ? {
@@ -229,10 +229,10 @@ class ExecutionApp extends executionBase_1.ExecutionBase {
229
229
  }
230
230
  }
231
231
  `,
232
- }
232
+ },
233
233
  };
234
234
  const response = yield (0, utils_1.fetchData)(request, 4);
235
- this.log("Subgraph response vault positions :", response);
235
+ this.log('Subgraph response vault positions :', response);
236
236
  const requestSnapshot = {
237
237
  method: 'POST',
238
238
  url: this.steerSubgraph,
@@ -248,10 +248,10 @@ class ExecutionApp extends executionBase_1.ExecutionBase {
248
248
  }
249
249
  }
250
250
  `,
251
- }
251
+ },
252
252
  };
253
253
  const responseSnapshot = yield (0, utils_1.fetchData)(requestSnapshot, 4);
254
- this.log("Subgraph response current snapshot", responseSnapshot);
254
+ this.log('Subgraph response current snapshot', responseSnapshot);
255
255
  const positions = [];
256
256
  if (((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.vaultPositions) && ((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.vaultPositions.length) > 0) {
257
257
  const positionResponse = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.vaultPositions[0];
@@ -268,19 +268,17 @@ class ExecutionApp extends executionBase_1.ExecutionBase {
268
268
  if (((_d = responseSnapshot === null || responseSnapshot === void 0 ? void 0 : responseSnapshot.data) === null || _d === void 0 ? void 0 : _d.vaultSnapshots) && ((_e = responseSnapshot === null || responseSnapshot === void 0 ? void 0 : responseSnapshot.data) === null || _e === void 0 ? void 0 : _e.vaultSnapshots.length) > 0) {
269
269
  lastSnapshot = (_f = responseSnapshot === null || responseSnapshot === void 0 ? void 0 : responseSnapshot.data) === null || _f === void 0 ? void 0 : _f.vaultSnapshots[0];
270
270
  }
271
- this.log("Subgraph response vault positions", positions);
271
+ this.log('Subgraph response vault positions', positions);
272
272
  smartPoolExecutionContext.positions = positions;
273
273
  if (lastSnapshot) {
274
- smartPoolExecutionContext.lastExecutionTime =
275
- (Date.now() - (Number(lastSnapshot.timestamp) * 1000)) / 1000;
274
+ smartPoolExecutionContext.lastExecutionTime = (Date.now() - Number(lastSnapshot.timestamp) * 1000) / 1000;
276
275
  }
277
276
  else {
278
- smartPoolExecutionContext.lastExecutionTime =
279
- currentExecutionContext.epochTimestamp;
277
+ smartPoolExecutionContext.lastExecutionTime = currentExecutionContext.epochTimestamp;
280
278
  }
281
279
  const provider = dataConnector.getProvider(vaultConfig);
282
280
  if (!provider) {
283
- throw new Error("Provider configuration issue, unable to process Smart Pool execution context.");
281
+ throw new Error('Provider configuration issue, unable to process Smart Pool execution context.');
284
282
  }
285
283
  const poolAddress = yield this.getVaultPoolAddress();
286
284
  const currentTick = yield this.getPoolCurrentTick(poolAddress, provider, currentExecutionContext, rpc);
@@ -315,7 +313,7 @@ class ExecutionApp extends executionBase_1.ExecutionBase {
315
313
  }
316
314
  }
317
315
  `,
318
- }
316
+ },
319
317
  };
320
318
  const response = yield (0, utils_1.fetchData)(requestSnapshot, 4);
321
319
  return response.data.vault.pool;
@@ -1,5 +1,5 @@
1
- import { ExecutionBase } from "./executionBase";
2
- import { DataConnector } from "../bundle/bundleDataConnector";
1
+ import { ExecutionBase } from './executionBase';
2
+ import { DataConnector } from '../bundle/bundleDataConnector';
3
3
  export declare class DataConnectorExecution extends ExecutionBase {
4
4
  private dataConnectors;
5
5
  constructor(dataConnectors: Array<DataConnector>, maxRetries?: number);
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DataConnector } from './bundle/bundleDataConnector';
2
2
  import { DataConnectorExecution } from './execution/executionDataConnector';
3
3
  import { ExecutionApp } from './execution/executionApp';
4
+ export * from './types';
4
5
  export { DataConnector, DataConnectorExecution, ExecutionApp };
package/lib/index.js CHANGED
@@ -1,4 +1,18 @@
1
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.ExecutionApp = exports.DataConnectorExecution = exports.DataConnector = void 0;
4
18
  const bundleDataConnector_1 = require("./bundle/bundleDataConnector");
@@ -7,3 +21,4 @@ const executionDataConnector_1 = require("./execution/executionDataConnector");
7
21
  Object.defineProperty(exports, "DataConnectorExecution", { enumerable: true, get: function () { return executionDataConnector_1.DataConnectorExecution; } });
8
22
  const executionApp_1 = require("./execution/executionApp");
9
23
  Object.defineProperty(exports, "ExecutionApp", { enumerable: true, get: function () { return executionApp_1.ExecutionApp; } });
24
+ __exportStar(require("./types"), exports);
package/lib/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContractInterface } from "ethers";
1
+ import { ContractInterface } from 'ethers';
2
2
  export type VaultInput = {
3
3
  _id?: string;
4
4
  tokenId: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CENTRALIZE_CONTRACT_INTERACTION_CHAINS = exports.API_INITIAL_DELAY = exports.API_MAX_RETRIES = exports.API_BASE_URL = void 0;
4
- exports.API_BASE_URL = "https://cvrlulno2m.execute-api.ap-southeast-1.amazonaws.com/dev/contract-view-call";
4
+ exports.API_BASE_URL = 'https://cvrlulno2m.execute-api.ap-southeast-1.amazonaws.com/dev/contract-view-call';
5
5
  exports.API_MAX_RETRIES = 3;
6
6
  exports.API_INITIAL_DELAY = 1000;
7
- exports.CENTRALIZE_CONTRACT_INTERACTION_CHAINS = ["2222", "42161", "9001", "137", "56"];
7
+ exports.CENTRALIZE_CONTRACT_INTERACTION_CHAINS = ['2222', '42161', '9001', '137', '56'];
@@ -1,10 +1,10 @@
1
- import { Candle } from "@steerprotocol/app-loader";
2
- import { AxiosRequestConfig } from "axios";
3
- import { ExecutionContext, ViewContractConfig } from "../types";
4
- import { providers } from "ethers";
1
+ import { Candle } from '@steerprotocol/app-loader';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ import { ExecutionContext, ViewContractConfig } from '../types';
4
+ import { providers } from 'ethers';
5
5
  export declare const extendOHLCV: (rawData: Candle[], period: number, endTimestamp: number) => Candle[];
6
6
  export declare function fetchData(request: AxiosRequestConfig, attempts: number): Promise<any>;
7
- export declare function readSlot0Contract({ address, abi, currentExecutionContext, functionName, provider, rpc, chainId }: {
7
+ export declare function readSlot0Contract({ address, abi, currentExecutionContext, functionName, provider, rpc, chainId, }: {
8
8
  address: string;
9
9
  abi: any;
10
10
  currentExecutionContext: ExecutionContext;
@@ -54,18 +54,18 @@ function exponentialBackoffDelay(attempts) {
54
54
  }
55
55
  function fetchData(request, attempts) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
- log("Request payload: =============", request);
57
+ log('Request payload: =============', request);
58
58
  attempts = attempts + 1;
59
59
  try {
60
60
  const response = (yield (0, axios_1.default)(request)).data;
61
61
  // this.log('API Response: =============', response);
62
- if ("errors" in response && response["errors"].length > 0) {
62
+ if ('errors' in response && response['errors'].length > 0) {
63
63
  if (attempts < 3) {
64
64
  yield delay(exponentialBackoffDelay(attempts));
65
65
  return yield fetchData(request, attempts);
66
66
  }
67
67
  else {
68
- throw new Error("Maximum retry attempts reached");
68
+ throw new Error('Maximum retry attempts reached');
69
69
  }
70
70
  }
71
71
  return response;
@@ -82,12 +82,12 @@ function fetchData(request, attempts) {
82
82
  });
83
83
  }
84
84
  exports.fetchData = fetchData;
85
- function readSlot0Contract({ address, abi, currentExecutionContext, functionName, provider, rpc, chainId }) {
85
+ function readSlot0Contract({ address, abi, currentExecutionContext, functionName, provider, rpc, chainId, }) {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
87
  // Create a new contract instance
88
88
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
89
  if (!provider)
90
- throw new Error("Provider not initialized");
90
+ throw new Error('Provider not initialized');
91
91
  const contract = new ethers_1.Contract(address, abi, provider);
92
92
  // For formatting the parameters if needed
93
93
  const paramsArray = [];
package/package.json CHANGED
@@ -1,11 +1,22 @@
1
1
  {
2
2
  "name": "@steerprotocol/data-connector-loader",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "App Loader for Steer Protocol",
5
5
  "main": "lib/index.js",
6
+ "module": "lib/esm/index.js",
6
7
  "types": "lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/index.js"
13
+ },
14
+ "./*": "./lib/*"
15
+ },
7
16
  "scripts": {
8
- "build": "tsc",
17
+ "build": "npm run build:cjs && npm run build:esm",
18
+ "build:cjs": "tsc -p tsconfig.json",
19
+ "build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > lib/esm/package.json",
9
20
  "format": "prettier --write \"src/**/*.(js|ts)\"",
10
21
  "lint": "eslint src --ext .js,.ts",
11
22
  "lint:fix": "eslint src --fix --ext .js,.ts",
@@ -18,7 +29,10 @@
18
29
  },
19
30
  "repository": {
20
31
  "type": "git",
21
- "url": "git+https://github.com/SteerProtocol/data-connector-loader.git"
32
+ "url": "https://github.com/SteerProtocol/data-connector-loader.git"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
22
36
  },
23
37
  "keywords": [
24
38
  "boilerplate",
@@ -30,7 +44,22 @@
30
44
  "url": "https://github.com/SteerProtocol/data-connector-loader/issues"
31
45
  },
32
46
  "homepage": "https://github.com/SteerProtocol/data-connector-loader#readme",
47
+ "release": {
48
+ "branches": [
49
+ "main"
50
+ ],
51
+ "plugins": [
52
+ "@semantic-release/commit-analyzer",
53
+ "@semantic-release/release-notes-generator",
54
+ "@semantic-release/npm",
55
+ "@semantic-release/github"
56
+ ]
57
+ },
33
58
  "devDependencies": {
59
+ "@semantic-release/commit-analyzer": "^13.0.1",
60
+ "@semantic-release/github": "^10.3.5",
61
+ "@semantic-release/npm": "^12.0.2",
62
+ "@semantic-release/release-notes-generator": "^14.1.0",
34
63
  "@types/jest": "29.2.4",
35
64
  "@typescript-eslint/eslint-plugin": "5.46.0",
36
65
  "@typescript-eslint/parser": "5.47.1",
@@ -39,6 +68,7 @@
39
68
  "eslint-plugin-jest": "27.1.7",
40
69
  "jest": "29.3.1",
41
70
  "prettier": "2.8.1",
71
+ "semantic-release": "^24.2.9",
42
72
  "ts-jest": "29.0.3",
43
73
  "typescript": "4.9.4"
44
74
  },
@@ -1,119 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.BundleBase = void 0;
13
- const app_loader_1 = require("@steerprotocol/app-loader");
14
- const ethers_1 = require("ethers");
15
- class BundleBase {
16
- constructor(wasmFile, _config, identity, etherRpcConfig) {
17
- this.wasmFile = wasmFile;
18
- this.config = _config;
19
- this.configObj = JSON.parse(_config);
20
- this.providerIdentity = identity;
21
- this.etherRpcConfig = etherRpcConfig;
22
- }
23
- load() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const instance = yield (0, app_loader_1.loadWasm)(this.wasmFile, {});
26
- this.module = instance;
27
- this.module.initialize(this.config);
28
- return this.module;
29
- });
30
- }
31
- loadSync() {
32
- if (typeof this.wasmFile === 'string')
33
- throw new Error('Cannot load module synchronously unless wasmFile is of type ArrayBuffer');
34
- this.module = (0, app_loader_1.loadWasmSync)(this.wasmFile, {});
35
- return this.module;
36
- }
37
- execute(response) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- if (!this.executionContext) {
40
- throw new Error('Execution context missing');
41
- }
42
- // If the module is not initialized, try to load it
43
- if (!this.module) {
44
- try {
45
- yield this.load();
46
- }
47
- catch (_a) {
48
- throw new Error('Module not initialized');
49
- }
50
- }
51
- // If the module is still not initialized, throw an error
52
- if (!this.module)
53
- throw new Error('Module not initialized');
54
- // Call the main function with the response
55
- return yield this.module.execute(response);
56
- });
57
- }
58
- reset() {
59
- if (this.module && this.module['reset']) {
60
- this.module.reset();
61
- }
62
- }
63
- setExecutionContext(executionContext) {
64
- var _a;
65
- // Determine the timestamp for epoch
66
- const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
67
- // Divide milliseconds data to seconds for transformation bundle
68
- const timestampInSecs = Math.floor(timestamp / 1000);
69
- this.executionContext = Object.assign(Object.assign({}, executionContext), { epochTimestamp: timestampInSecs });
70
- (_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(Object.assign(Object.assign({}, JSON.parse(this.config)), { executionContext: this.executionContext })));
71
- }
72
- executeModule(response) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- if (!this.module) {
75
- throw new Error('Module not initialized');
76
- }
77
- return yield this.module.execute(response);
78
- });
79
- }
80
- // This function returns a provider based on the chainId of the request
81
- // The chainId is first checked in the data connector config, and if not found
82
- // it is checked in the request config. If the chainId is found in either of
83
- // these places, the provider is returned from the etherRpcConfig object
84
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
- getProvider(config) {
86
- let chainId;
87
- // check if chainId is configured in data connector config
88
- if (this.configObj.chainId) {
89
- chainId = this.configObj.chainId;
90
- }
91
- else if (config && config.chainId) {
92
- // if chainId is in the request config from dataconnector execution
93
- chainId = config.chainId;
94
- }
95
- if (chainId && this.etherRpcConfig && this.etherRpcConfig[chainId]) {
96
- const provider = new ethers_1.providers.JsonRpcProvider(this.etherRpcConfig[chainId].url);
97
- return provider;
98
- }
99
- else {
100
- return this.providerIdentity;
101
- }
102
- }
103
- getResults() {
104
- if (!this.module)
105
- throw new Error('Module not initialized');
106
- return this.module.transform();
107
- }
108
- version() {
109
- if (!this.module)
110
- throw new Error('Module not initialized');
111
- return Number(this.module.version());
112
- }
113
- subtractDate(timestamp, epochLength) {
114
- const date = new Date(timestamp);
115
- date.setSeconds(date.getSeconds() - epochLength);
116
- return date;
117
- }
118
- }
119
- exports.BundleBase = BundleBase;
@@ -1,14 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { DataConnector } from '../bundleDataConnector';
3
- import { VaultConfigPayload, ExecutionContext } from '../types';
4
- export declare class ExecutionBase {
5
- maxRetries: number;
6
- constructor(maxRetries?: number);
7
- protected delay(ms: number): Promise<void>;
8
- protected log(...args: any[]): void;
9
- protected getExecutionContext(dataConnector: DataConnector, vaultConfig: VaultConfigPayload): Promise<ExecutionContext>;
10
- execute<T>(_vaultConfig: string): Promise<Array<T>>;
11
- private getDataConnectorVersion;
12
- getAverageBlockTime(provider: ethers.providers.Provider, blockCount?: number): Promise<number>;
13
- getBlockNumberFromAvgBlockTime(provider: ethers.providers.Provider, targetTimestamp: number, avgBlockTime: number): Promise<number>;
14
- }