@steerprotocol/data-connector-loader 0.1.5 → 1.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.
- package/lib/bundle/bundleBase.d.ts +29 -0
- package/lib/{dataConnector.js → bundle/bundleBase.js} +59 -42
- package/lib/bundle/bundleDataConnector.d.ts +8 -0
- package/lib/bundle/bundleDataConnector.js +73 -0
- package/lib/esm/bundle/bundleBase.d.ts +29 -0
- package/lib/esm/bundle/bundleBase.js +127 -0
- package/lib/esm/bundle/bundleDataConnector.d.ts +8 -0
- package/lib/esm/bundle/bundleDataConnector.js +57 -0
- package/lib/esm/execution/executionApp.d.ts +17 -0
- package/lib/esm/execution/executionApp.js +304 -0
- package/lib/esm/execution/executionBase.d.ts +14 -0
- package/lib/esm/execution/executionBase.js +95 -0
- package/lib/esm/execution/executionDataConnector.d.ts +9 -0
- package/lib/esm/execution/executionDataConnector.js +90 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/types.d.ts +104 -0
- package/lib/esm/types.js +1 -0
- package/lib/esm/utils/blockFinder.js +20 -0
- package/lib/esm/utils/consts.d.ts +4 -0
- package/lib/esm/utils/consts.js +4 -0
- package/lib/esm/utils/pluginManager.js +67 -0
- package/lib/esm/utils/utils.d.ts +16 -0
- package/lib/esm/utils/utils.js +119 -0
- package/lib/execution/executionApp.d.ts +17 -0
- package/lib/execution/executionApp.js +323 -0
- package/lib/execution/executionBase.d.ts +14 -0
- package/lib/execution/executionBase.js +118 -0
- package/lib/execution/executionDataConnector.d.ts +9 -0
- package/lib/execution/executionDataConnector.js +110 -0
- package/lib/index.d.ts +5 -15
- package/lib/index.js +21 -197
- package/lib/types.d.ts +40 -0
- package/lib/utils/blockFinder.d.ts +8 -0
- package/lib/utils/consts.d.ts +4 -0
- package/lib/utils/consts.js +7 -0
- package/lib/utils/pluginManager.d.ts +11 -0
- package/lib/utils/utils.d.ts +16 -0
- package/lib/utils/utils.js +146 -0
- package/package.json +35 -5
- package/lib/dataConnector.d.ts +0 -27
- package/lib/utils.d.ts +0 -2
- package/lib/utils.js +0 -28
- /package/lib/{blockFinder.d.ts → esm/utils/blockFinder.d.ts} +0 -0
- /package/lib/{pluginManager.d.ts → esm/utils/pluginManager.d.ts} +0 -0
- /package/lib/{blockFinder.js → utils/blockFinder.js} +0 -0
- /package/lib/{pluginManager.js → utils/pluginManager.js} +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WasmModule } from '@steerprotocol/app-loader';
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
|
+
import { EtherRpcConfig, ExecutionContext } from '../types';
|
|
4
|
+
export declare class BundleBase {
|
|
5
|
+
module?: WasmModule;
|
|
6
|
+
protected wasmFile: ArrayBuffer | string;
|
|
7
|
+
protected config: string;
|
|
8
|
+
configObj: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
protected etherRpcConfig?: EtherRpcConfig;
|
|
12
|
+
protected providerIdentity?: providers.Provider;
|
|
13
|
+
executionContext?: ExecutionContext & {
|
|
14
|
+
epochTimestamp: number;
|
|
15
|
+
};
|
|
16
|
+
protected scheduleEpochTimestamp: number | undefined;
|
|
17
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, identity?: providers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
18
|
+
load(): Promise<WasmModule>;
|
|
19
|
+
loadSync(): WasmModule;
|
|
20
|
+
execute(response: string): Promise<string>;
|
|
21
|
+
executeBundle(data: Array<any>): Promise<string>;
|
|
22
|
+
setExecutionContextStrategyExecution(executionContext: ExecutionContext): void;
|
|
23
|
+
setExecutionContextDataConnector(executionContext: ExecutionContext): void;
|
|
24
|
+
protected executeModule(response: string): Promise<string>;
|
|
25
|
+
getProvider(config: any): providers.Provider | undefined;
|
|
26
|
+
getResults(): string;
|
|
27
|
+
version(): number;
|
|
28
|
+
private subtractDate;
|
|
29
|
+
}
|
|
@@ -9,11 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.BundleBase = void 0;
|
|
13
13
|
const app_loader_1 = require("@steerprotocol/app-loader");
|
|
14
14
|
const ethers_1 = require("ethers");
|
|
15
|
-
class
|
|
16
|
-
// Identity should come from the node's IdentityManager.wallet
|
|
15
|
+
class BundleBase {
|
|
17
16
|
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
18
17
|
this.wasmFile = wasmFile;
|
|
19
18
|
this.config = _config;
|
|
@@ -30,25 +29,11 @@ class DataConnector {
|
|
|
30
29
|
});
|
|
31
30
|
}
|
|
32
31
|
loadSync() {
|
|
33
|
-
if (typeof this.wasmFile ===
|
|
34
|
-
throw new Error(
|
|
32
|
+
if (typeof this.wasmFile === 'string')
|
|
33
|
+
throw new Error('Cannot load module synchronously unless wasmFile is of type ArrayBuffer');
|
|
35
34
|
this.module = (0, app_loader_1.loadWasmSync)(this.wasmFile, {});
|
|
36
35
|
return this.module;
|
|
37
36
|
}
|
|
38
|
-
reset() {
|
|
39
|
-
if (this.module && this.module["reset"]) {
|
|
40
|
-
this.module.reset();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
setExecutionContext(executionContext) {
|
|
44
|
-
var _a;
|
|
45
|
-
// Determine the timestamp for epoch
|
|
46
|
-
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
47
|
-
// Divide milliseconds data to seconds for transformation bundle
|
|
48
|
-
const timestampInSecs = Math.floor(timestamp / 1000);
|
|
49
|
-
this.executionContext = Object.assign(Object.assign({}, executionContext), { epochTimestamp: timestampInSecs });
|
|
50
|
-
(_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(Object.assign(Object.assign({}, JSON.parse(this.config)), { executionContext: this.executionContext })));
|
|
51
|
-
}
|
|
52
37
|
execute(response) {
|
|
53
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
39
|
if (!this.executionContext) {
|
|
@@ -70,6 +55,59 @@ class DataConnector {
|
|
|
70
55
|
return yield this.module.execute(response);
|
|
71
56
|
});
|
|
72
57
|
}
|
|
58
|
+
executeBundle(data) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (!this.executionContext) {
|
|
61
|
+
throw new Error('Execution context missing');
|
|
62
|
+
}
|
|
63
|
+
// If the module is not initialized, try to load it
|
|
64
|
+
if (!this.module) {
|
|
65
|
+
try {
|
|
66
|
+
yield this.load();
|
|
67
|
+
}
|
|
68
|
+
catch (_a) {
|
|
69
|
+
throw new Error('Module not initialized');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// If the module is still not initialized, throw an error
|
|
73
|
+
if (!this.module)
|
|
74
|
+
throw new Error('Module not initialized');
|
|
75
|
+
// Call the main function with the response
|
|
76
|
+
return this.module.execute(...data);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
setExecutionContextStrategyExecution(executionContext) {
|
|
80
|
+
var _a;
|
|
81
|
+
// Determine the timestamp for epoch
|
|
82
|
+
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
83
|
+
// Divide milliseconds data to seconds for transformation bundle
|
|
84
|
+
const timestampInSecs = Math.floor(timestamp / 1000);
|
|
85
|
+
this.executionContext = Object.assign(Object.assign({}, executionContext), { epochTimestamp: timestampInSecs });
|
|
86
|
+
const completeConfig = Object.assign(Object.assign({}, JSON.parse(this.config)), this.executionContext);
|
|
87
|
+
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
88
|
+
console.log('Complete execution config : ', completeConfig);
|
|
89
|
+
(_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(completeConfig));
|
|
90
|
+
}
|
|
91
|
+
setExecutionContextDataConnector(executionContext) {
|
|
92
|
+
var _a;
|
|
93
|
+
// Determine the timestamp for epoch
|
|
94
|
+
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
95
|
+
// Divide milliseconds data to seconds for transformation bundle
|
|
96
|
+
const timestampInSecs = Math.floor(timestamp / 1000);
|
|
97
|
+
this.executionContext = Object.assign(Object.assign({}, executionContext), { epochTimestamp: timestampInSecs });
|
|
98
|
+
const completeConfig = Object.assign(Object.assign({}, JSON.parse(this.config)), { executionContext: this.executionContext });
|
|
99
|
+
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
100
|
+
console.log('Complete execution config : ', completeConfig);
|
|
101
|
+
(_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(completeConfig));
|
|
102
|
+
}
|
|
103
|
+
executeModule(response) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
if (!this.module) {
|
|
106
|
+
throw new Error('Module not initialized');
|
|
107
|
+
}
|
|
108
|
+
return yield this.module.execute(response);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
73
111
|
// This function returns a provider based on the chainId of the request
|
|
74
112
|
// The chainId is first checked in the data connector config, and if not found
|
|
75
113
|
// it is checked in the request config. If the chainId is found in either of
|
|
@@ -86,34 +124,13 @@ class DataConnector {
|
|
|
86
124
|
chainId = config.chainId;
|
|
87
125
|
}
|
|
88
126
|
if (chainId && this.etherRpcConfig && this.etherRpcConfig[chainId]) {
|
|
89
|
-
const provider = new ethers_1.
|
|
127
|
+
const provider = new ethers_1.providers.JsonRpcProvider(this.etherRpcConfig[chainId].url);
|
|
90
128
|
return provider;
|
|
91
129
|
}
|
|
92
130
|
else {
|
|
93
131
|
return this.providerIdentity;
|
|
94
132
|
}
|
|
95
133
|
}
|
|
96
|
-
// Makes contract instance and calls, returns stringified result
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
-
view(config) {
|
|
99
|
-
var _a;
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
const provider = this.getProvider(config);
|
|
102
|
-
if (!provider)
|
|
103
|
-
throw new Error('Provider not initialized');
|
|
104
|
-
const contract = new ethers_1.ethers.Contract(config.address, config.abi, provider);
|
|
105
|
-
// For formatting the parameters if needed
|
|
106
|
-
const paramsArray = config.arguments;
|
|
107
|
-
// Calculate block number for determinism
|
|
108
|
-
// Best way to handle contextually non-null values?
|
|
109
|
-
// const syncedBlock = await getBlockFromTimestamp(this.executionContext!.epochTimestamp, this.providerIdentity!) //@note uncomment for deterministic blocks
|
|
110
|
-
// Call the desired method with the specified arguments at synced block
|
|
111
|
-
// , {blockTag: syncedBlock}
|
|
112
|
-
const result = yield contract[config.method](...paramsArray, { blockTag: (_a = this.executionContext) === null || _a === void 0 ? void 0 : _a.blockNumber }); //@note uncomment for deterministic blocks
|
|
113
|
-
// This gets stringified before calling main
|
|
114
|
-
return result;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
134
|
getResults() {
|
|
118
135
|
if (!this.module)
|
|
119
136
|
throw new Error('Module not initialized');
|
|
@@ -130,4 +147,4 @@ class DataConnector {
|
|
|
130
147
|
return date;
|
|
131
148
|
}
|
|
132
149
|
}
|
|
133
|
-
exports.
|
|
150
|
+
exports.BundleBase = BundleBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { providers } from 'ethers';
|
|
2
|
+
import { EtherRpcConfig, ViewConfig } from '../types';
|
|
3
|
+
import { BundleBase } from './bundleBase';
|
|
4
|
+
export declare class DataConnector extends BundleBase {
|
|
5
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, identity?: providers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
6
|
+
getRpcUrl(config: any): string | undefined;
|
|
7
|
+
view(config: ViewConfig): Promise<string>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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.DataConnector = void 0;
|
|
13
|
+
const ethers_1 = require("ethers");
|
|
14
|
+
const consts_1 = require("../utils/consts");
|
|
15
|
+
const utils_1 = require("../utils/utils");
|
|
16
|
+
const bundleBase_1 = require("./bundleBase");
|
|
17
|
+
class DataConnector extends bundleBase_1.BundleBase {
|
|
18
|
+
// Identity should come from the node's IdentityManager.wallet
|
|
19
|
+
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
20
|
+
super(wasmFile, _config, identity, etherRpcConfig);
|
|
21
|
+
}
|
|
22
|
+
// get rpc url from configuration
|
|
23
|
+
getRpcUrl(config) {
|
|
24
|
+
let chainId;
|
|
25
|
+
// check if chainId is configured in data connector config
|
|
26
|
+
if (this.configObj.chainId) {
|
|
27
|
+
chainId = this.configObj.chainId;
|
|
28
|
+
}
|
|
29
|
+
else if (config && config.chainId) {
|
|
30
|
+
// if chainId is in the request config from dataconnector execution
|
|
31
|
+
chainId = config.chainId;
|
|
32
|
+
}
|
|
33
|
+
if (chainId && this.etherRpcConfig && this.etherRpcConfig[chainId]) {
|
|
34
|
+
return this.etherRpcConfig[chainId].url;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Makes contract instance and calls, returns stringified result
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
view(config) {
|
|
43
|
+
var _a;
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const provider = this.getProvider(config);
|
|
46
|
+
if (!provider)
|
|
47
|
+
throw new Error('Provider not initialized');
|
|
48
|
+
const contract = new ethers_1.Contract(config.address, config.abi, provider);
|
|
49
|
+
// For formatting the parameters if needed
|
|
50
|
+
const paramsArray = config.arguments;
|
|
51
|
+
let result;
|
|
52
|
+
if (consts_1.CENTRALIZE_CONTRACT_INTERACTION_CHAINS.indexOf(this.configObj.chainId.toString()) === -1) {
|
|
53
|
+
result = yield contract[config.method](...paramsArray, {
|
|
54
|
+
blockTag: (_a = this.executionContext) === null || _a === void 0 ? void 0 : _a.blockNumber,
|
|
55
|
+
}); //@note uncomment for deterministic blocks
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const viewContractConfig = {
|
|
59
|
+
epochTimestamp: this.scheduleEpochTimestamp,
|
|
60
|
+
address: this.configObj.address || config.address,
|
|
61
|
+
abi: config.abi,
|
|
62
|
+
arguments: paramsArray,
|
|
63
|
+
method: config.method,
|
|
64
|
+
rpcUrl: this.getRpcUrl(config),
|
|
65
|
+
};
|
|
66
|
+
result = yield (0, utils_1.callWithRetry)(viewContractConfig);
|
|
67
|
+
}
|
|
68
|
+
// This gets stringified before calling main
|
|
69
|
+
return result;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.DataConnector = DataConnector;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WasmModule } from '@steerprotocol/app-loader';
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
|
+
import { EtherRpcConfig, ExecutionContext } from '../types';
|
|
4
|
+
export declare class BundleBase {
|
|
5
|
+
module?: WasmModule;
|
|
6
|
+
protected wasmFile: ArrayBuffer | string;
|
|
7
|
+
protected config: string;
|
|
8
|
+
configObj: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
protected etherRpcConfig?: EtherRpcConfig;
|
|
12
|
+
protected providerIdentity?: providers.Provider;
|
|
13
|
+
executionContext?: ExecutionContext & {
|
|
14
|
+
epochTimestamp: number;
|
|
15
|
+
};
|
|
16
|
+
protected scheduleEpochTimestamp: number | undefined;
|
|
17
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, identity?: providers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
18
|
+
load(): Promise<WasmModule>;
|
|
19
|
+
loadSync(): WasmModule;
|
|
20
|
+
execute(response: string): Promise<string>;
|
|
21
|
+
executeBundle(data: Array<any>): Promise<string>;
|
|
22
|
+
setExecutionContextStrategyExecution(executionContext: ExecutionContext): void;
|
|
23
|
+
setExecutionContextDataConnector(executionContext: ExecutionContext): void;
|
|
24
|
+
protected executeModule(response: string): Promise<string>;
|
|
25
|
+
getProvider(config: any): providers.Provider | undefined;
|
|
26
|
+
getResults(): string;
|
|
27
|
+
version(): number;
|
|
28
|
+
private subtractDate;
|
|
29
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { loadWasm, loadWasmSync } from '@steerprotocol/app-loader';
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
|
+
export class BundleBase {
|
|
4
|
+
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
5
|
+
this.wasmFile = wasmFile;
|
|
6
|
+
this.config = _config;
|
|
7
|
+
this.configObj = JSON.parse(_config);
|
|
8
|
+
this.providerIdentity = identity;
|
|
9
|
+
this.etherRpcConfig = etherRpcConfig;
|
|
10
|
+
}
|
|
11
|
+
async load() {
|
|
12
|
+
const instance = await loadWasm(this.wasmFile, {});
|
|
13
|
+
this.module = instance;
|
|
14
|
+
this.module.initialize(this.config);
|
|
15
|
+
return this.module;
|
|
16
|
+
}
|
|
17
|
+
loadSync() {
|
|
18
|
+
if (typeof this.wasmFile === 'string')
|
|
19
|
+
throw new Error('Cannot load module synchronously unless wasmFile is of type ArrayBuffer');
|
|
20
|
+
this.module = loadWasmSync(this.wasmFile, {});
|
|
21
|
+
return this.module;
|
|
22
|
+
}
|
|
23
|
+
async execute(response) {
|
|
24
|
+
if (!this.executionContext) {
|
|
25
|
+
throw new Error('Execution context missing');
|
|
26
|
+
}
|
|
27
|
+
// If the module is not initialized, try to load it
|
|
28
|
+
if (!this.module) {
|
|
29
|
+
try {
|
|
30
|
+
await this.load();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new Error('Module not initialized');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// If the module is still not initialized, throw an error
|
|
37
|
+
if (!this.module)
|
|
38
|
+
throw new Error('Module not initialized');
|
|
39
|
+
// Call the main function with the response
|
|
40
|
+
return await this.module.execute(response);
|
|
41
|
+
}
|
|
42
|
+
async executeBundle(data) {
|
|
43
|
+
if (!this.executionContext) {
|
|
44
|
+
throw new Error('Execution context missing');
|
|
45
|
+
}
|
|
46
|
+
// If the module is not initialized, try to load it
|
|
47
|
+
if (!this.module) {
|
|
48
|
+
try {
|
|
49
|
+
await this.load();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new Error('Module not initialized');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// If the module is still not initialized, throw an error
|
|
56
|
+
if (!this.module)
|
|
57
|
+
throw new Error('Module not initialized');
|
|
58
|
+
// Call the main function with the response
|
|
59
|
+
return this.module.execute(...data);
|
|
60
|
+
}
|
|
61
|
+
setExecutionContextStrategyExecution(executionContext) {
|
|
62
|
+
// Determine the timestamp for epoch
|
|
63
|
+
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
64
|
+
// Divide milliseconds data to seconds for transformation bundle
|
|
65
|
+
const timestampInSecs = Math.floor(timestamp / 1000);
|
|
66
|
+
this.executionContext = { ...executionContext, epochTimestamp: timestampInSecs };
|
|
67
|
+
const completeConfig = { ...JSON.parse(this.config), ...this.executionContext };
|
|
68
|
+
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
69
|
+
console.log('Complete execution config : ', completeConfig);
|
|
70
|
+
this.module?.initialize(JSON.stringify(completeConfig));
|
|
71
|
+
}
|
|
72
|
+
setExecutionContextDataConnector(executionContext) {
|
|
73
|
+
// Determine the timestamp for epoch
|
|
74
|
+
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
75
|
+
// Divide milliseconds data to seconds for transformation bundle
|
|
76
|
+
const timestampInSecs = Math.floor(timestamp / 1000);
|
|
77
|
+
this.executionContext = { ...executionContext, epochTimestamp: timestampInSecs };
|
|
78
|
+
const completeConfig = { ...JSON.parse(this.config), executionContext: this.executionContext };
|
|
79
|
+
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
80
|
+
console.log('Complete execution config : ', completeConfig);
|
|
81
|
+
this.module?.initialize(JSON.stringify(completeConfig));
|
|
82
|
+
}
|
|
83
|
+
async executeModule(response) {
|
|
84
|
+
if (!this.module) {
|
|
85
|
+
throw new Error('Module not initialized');
|
|
86
|
+
}
|
|
87
|
+
return await this.module.execute(response);
|
|
88
|
+
}
|
|
89
|
+
// This function returns a provider based on the chainId of the request
|
|
90
|
+
// The chainId is first checked in the data connector config, and if not found
|
|
91
|
+
// it is checked in the request config. If the chainId is found in either of
|
|
92
|
+
// these places, the provider is returned from the etherRpcConfig object
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
+
getProvider(config) {
|
|
95
|
+
let chainId;
|
|
96
|
+
// check if chainId is configured in data connector config
|
|
97
|
+
if (this.configObj.chainId) {
|
|
98
|
+
chainId = this.configObj.chainId;
|
|
99
|
+
}
|
|
100
|
+
else if (config && config.chainId) {
|
|
101
|
+
// if chainId is in the request config from dataconnector execution
|
|
102
|
+
chainId = config.chainId;
|
|
103
|
+
}
|
|
104
|
+
if (chainId && this.etherRpcConfig && this.etherRpcConfig[chainId]) {
|
|
105
|
+
const provider = new providers.JsonRpcProvider(this.etherRpcConfig[chainId].url);
|
|
106
|
+
return provider;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return this.providerIdentity;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
getResults() {
|
|
113
|
+
if (!this.module)
|
|
114
|
+
throw new Error('Module not initialized');
|
|
115
|
+
return this.module.transform();
|
|
116
|
+
}
|
|
117
|
+
version() {
|
|
118
|
+
if (!this.module)
|
|
119
|
+
throw new Error('Module not initialized');
|
|
120
|
+
return Number(this.module.version());
|
|
121
|
+
}
|
|
122
|
+
subtractDate(timestamp, epochLength) {
|
|
123
|
+
const date = new Date(timestamp);
|
|
124
|
+
date.setSeconds(date.getSeconds() - epochLength);
|
|
125
|
+
return date;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { providers } from 'ethers';
|
|
2
|
+
import { EtherRpcConfig, ViewConfig } from '../types';
|
|
3
|
+
import { BundleBase } from './bundleBase';
|
|
4
|
+
export declare class DataConnector extends BundleBase {
|
|
5
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, identity?: providers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
6
|
+
getRpcUrl(config: any): string | undefined;
|
|
7
|
+
view(config: ViewConfig): Promise<string>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
|
+
import { CENTRALIZE_CONTRACT_INTERACTION_CHAINS } from '../utils/consts';
|
|
3
|
+
import { callWithRetry } from '../utils/utils';
|
|
4
|
+
import { BundleBase } from './bundleBase';
|
|
5
|
+
export class DataConnector extends BundleBase {
|
|
6
|
+
// Identity should come from the node's IdentityManager.wallet
|
|
7
|
+
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
8
|
+
super(wasmFile, _config, identity, etherRpcConfig);
|
|
9
|
+
}
|
|
10
|
+
// get rpc url from configuration
|
|
11
|
+
getRpcUrl(config) {
|
|
12
|
+
let chainId;
|
|
13
|
+
// check if chainId is configured in data connector config
|
|
14
|
+
if (this.configObj.chainId) {
|
|
15
|
+
chainId = this.configObj.chainId;
|
|
16
|
+
}
|
|
17
|
+
else if (config && config.chainId) {
|
|
18
|
+
// if chainId is in the request config from dataconnector execution
|
|
19
|
+
chainId = config.chainId;
|
|
20
|
+
}
|
|
21
|
+
if (chainId && this.etherRpcConfig && this.etherRpcConfig[chainId]) {
|
|
22
|
+
return this.etherRpcConfig[chainId].url;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Makes contract instance and calls, returns stringified result
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
async view(config) {
|
|
31
|
+
const provider = this.getProvider(config);
|
|
32
|
+
if (!provider)
|
|
33
|
+
throw new Error('Provider not initialized');
|
|
34
|
+
const contract = new Contract(config.address, config.abi, provider);
|
|
35
|
+
// For formatting the parameters if needed
|
|
36
|
+
const paramsArray = config.arguments;
|
|
37
|
+
let result;
|
|
38
|
+
if (CENTRALIZE_CONTRACT_INTERACTION_CHAINS.indexOf(this.configObj.chainId.toString()) === -1) {
|
|
39
|
+
result = await contract[config.method](...paramsArray, {
|
|
40
|
+
blockTag: this.executionContext?.blockNumber,
|
|
41
|
+
}); //@note uncomment for deterministic blocks
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const viewContractConfig = {
|
|
45
|
+
epochTimestamp: this.scheduleEpochTimestamp,
|
|
46
|
+
address: this.configObj.address || config.address,
|
|
47
|
+
abi: config.abi,
|
|
48
|
+
arguments: paramsArray,
|
|
49
|
+
method: config.method,
|
|
50
|
+
rpcUrl: this.getRpcUrl(config),
|
|
51
|
+
};
|
|
52
|
+
result = await callWithRetry(viewContractConfig);
|
|
53
|
+
}
|
|
54
|
+
// This gets stringified before calling main
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { EtherRpcConfig } from '../types';
|
|
3
|
+
import { ExecutionBase } from './executionBase';
|
|
4
|
+
export declare class ExecutionApp extends ExecutionBase {
|
|
5
|
+
steerSubgraph: string;
|
|
6
|
+
vault: string;
|
|
7
|
+
isAlgebraPool: boolean;
|
|
8
|
+
isDirectionalPool: boolean;
|
|
9
|
+
chainId: number;
|
|
10
|
+
constructor(vault: string, steerSubgraph: string, isAlgebraPool: boolean, isDirectionalPool: boolean, chainId: number, maxRetries?: number);
|
|
11
|
+
execute<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, _identity?: ethers.providers.Provider, _etherRpcConfig?: EtherRpcConfig): Promise<Array<T>>;
|
|
12
|
+
private getSmartPoolExecutionContext;
|
|
13
|
+
private getPoolCurrentTick;
|
|
14
|
+
private getVaultPoolAddress;
|
|
15
|
+
private getSlot0;
|
|
16
|
+
private getGlobalState;
|
|
17
|
+
}
|