@steerprotocol/data-connector-loader 3.1.1 → 3.2.2
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/README.md +21 -1
- package/lib/bundle/bundleBase.d.ts +10 -5
- package/lib/bundle/bundleBase.js +89 -10
- package/lib/bundle/bundleDataConnector.d.ts +5 -4
- package/lib/bundle/bundleDataConnector.js +9 -11
- package/lib/esm/bundle/bundleBase.d.ts +10 -5
- package/lib/esm/bundle/bundleBase.js +84 -10
- package/lib/esm/bundle/bundleDataConnector.d.ts +5 -4
- package/lib/esm/bundle/bundleDataConnector.js +6 -8
- package/lib/esm/execution/executionApp.d.ts +52 -7
- package/lib/esm/execution/executionApp.js +561 -113
- package/lib/esm/execution/executionBase.d.ts +4 -4
- package/lib/esm/execution/executionBase.js +11 -12
- package/lib/esm/execution/executionDataConnector.d.ts +4 -2
- package/lib/esm/execution/executionDataConnector.js +56 -25
- package/lib/esm/index.d.ts +6 -4
- package/lib/esm/index.js +3 -4
- package/lib/esm/types.d.ts +17 -4
- package/lib/esm/utils/blockFinder.d.ts +1 -1
- package/lib/esm/utils/consts.js +43 -1
- package/lib/esm/utils/pluginManager.d.ts +1 -1
- package/lib/esm/utils/replace-old-subgraphs.d.ts +23 -0
- package/lib/esm/utils/replace-old-subgraphs.js +123 -0
- package/lib/esm/utils/utils.d.ts +7 -6
- package/lib/esm/utils/utils.js +8 -9
- package/lib/execution/executionApp.d.ts +52 -7
- package/lib/execution/executionApp.js +559 -117
- package/lib/execution/executionBase.d.ts +4 -4
- package/lib/execution/executionBase.js +11 -12
- package/lib/execution/executionDataConnector.d.ts +4 -2
- package/lib/execution/executionDataConnector.js +61 -29
- package/lib/index.d.ts +6 -4
- package/lib/index.js +6 -21
- package/lib/types.d.ts +17 -4
- package/lib/utils/blockFinder.d.ts +1 -1
- package/lib/utils/consts.js +43 -1
- package/lib/utils/pluginManager.d.ts +1 -1
- package/lib/utils/replace-old-subgraphs.d.ts +23 -0
- package/lib/utils/replace-old-subgraphs.js +129 -0
- package/lib/utils/utils.d.ts +7 -6
- package/lib/utils/utils.js +15 -16
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
# Steer Protocol App Loader
|
|
1
|
+
# Steer Protocol App Loader
|
|
2
|
+
|
|
3
|
+
## Public API
|
|
4
|
+
|
|
5
|
+
- `ExecutionAppConfig`: Configuration object for `ExecutionApp` (vault, chainId, subgraph URL, pool type flags, API keys, retries).
|
|
6
|
+
- `ExecutionApp`: High-level execution entrypoint for running bundles with a config-based constructor.
|
|
7
|
+
- `DataConnectorExecution`: Executes data connector bundles and handles request/response flow.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @steerprotocol/data-connector-loader
|
|
13
|
+
# or
|
|
14
|
+
yarn add @steerprotocol/data-connector-loader
|
|
15
|
+
# or
|
|
16
|
+
pnpm add @steerprotocol/data-connector-loader
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## ESM Support
|
|
20
|
+
|
|
21
|
+
This package publishes both CommonJS and ESM entrypoints via `exports`.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { WasmModule } from '@steerprotocol/app-loader';
|
|
1
|
+
import type { WasmModule } from '@steerprotocol/app-loader';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
|
-
import {
|
|
3
|
+
import type { ExecutionAppConfig } from '../execution/executionApp.js';
|
|
4
|
+
import type { EtherRpcConfig, ExecutionContext } from '../types.js';
|
|
4
5
|
export declare class BundleBase {
|
|
5
6
|
module?: WasmModule;
|
|
6
7
|
protected wasmFile: ArrayBuffer | string;
|
|
@@ -13,13 +14,17 @@ export declare class BundleBase {
|
|
|
13
14
|
executionContext?: ExecutionContext & {
|
|
14
15
|
epochTimestamp: number;
|
|
15
16
|
};
|
|
16
|
-
protected scheduleEpochTimestamp
|
|
17
|
-
|
|
17
|
+
protected scheduleEpochTimestamp?: number;
|
|
18
|
+
executionAppConfig: ExecutionAppConfig;
|
|
19
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, executionAppConfig: ExecutionAppConfig, identity?: ethers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
18
20
|
load(): Promise<WasmModule>;
|
|
19
21
|
loadSync(): WasmModule;
|
|
20
22
|
execute(response: string): Promise<string>;
|
|
23
|
+
transform(): Promise<string>;
|
|
21
24
|
executeBundle(data: Array<any>): Promise<string>;
|
|
22
|
-
|
|
25
|
+
executeDynamicJobBundle(data: Array<any>): Promise<string>;
|
|
26
|
+
reset(): void;
|
|
27
|
+
setExecutionContextStrategyExecution(executionContext: ExecutionContext, forceDeposit?: boolean): void;
|
|
23
28
|
setExecutionContextDataConnector(executionContext: ExecutionContext): void;
|
|
24
29
|
protected executeModule(response: string): Promise<string>;
|
|
25
30
|
getProvider(config: any): ethers.Provider | undefined;
|
package/lib/bundle/bundleBase.js
CHANGED
|
@@ -12,13 +12,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.BundleBase = void 0;
|
|
13
13
|
const app_loader_1 = require("@steerprotocol/app-loader");
|
|
14
14
|
const ethers_1 = require("ethers");
|
|
15
|
+
const UNSTABLE_RPC_PATTERNS = [/drpc\.org/i];
|
|
16
|
+
function createFallbackRpcProvider(urls) {
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
const preferred = [];
|
|
19
|
+
const deprioritized = [];
|
|
20
|
+
for (const url of urls) {
|
|
21
|
+
const trimmed = url.trim();
|
|
22
|
+
if (trimmed.length === 0 || seen.has(trimmed)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
seen.add(trimmed);
|
|
26
|
+
if (UNSTABLE_RPC_PATTERNS.some((pattern) => pattern.test(trimmed))) {
|
|
27
|
+
deprioritized.push(trimmed);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
preferred.push(trimmed);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const prioritized = preferred.length > 0 ? [...preferred, ...deprioritized] : [...preferred, ...deprioritized];
|
|
34
|
+
if (prioritized.length === 0) {
|
|
35
|
+
throw new Error('No RPC URLs configured');
|
|
36
|
+
}
|
|
37
|
+
const providers = prioritized.map((url) => new ethers_1.ethers.JsonRpcProvider(url));
|
|
38
|
+
return providers.length === 1 ? providers[0] : new ethers_1.ethers.FallbackProvider(providers);
|
|
39
|
+
}
|
|
40
|
+
function bigIntReplacer(_key, value) {
|
|
41
|
+
return typeof value === 'bigint' ? value.toString() : value;
|
|
42
|
+
}
|
|
15
43
|
class BundleBase {
|
|
16
|
-
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
44
|
+
constructor(wasmFile, _config, executionAppConfig, identity, etherRpcConfig) {
|
|
17
45
|
this.wasmFile = wasmFile;
|
|
18
46
|
this.config = _config;
|
|
19
47
|
this.configObj = JSON.parse(_config);
|
|
20
48
|
this.providerIdentity = identity;
|
|
21
49
|
this.etherRpcConfig = etherRpcConfig;
|
|
50
|
+
this.executionAppConfig = executionAppConfig;
|
|
22
51
|
}
|
|
23
52
|
load() {
|
|
24
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -29,8 +58,9 @@ class BundleBase {
|
|
|
29
58
|
});
|
|
30
59
|
}
|
|
31
60
|
loadSync() {
|
|
32
|
-
if (typeof this.wasmFile === 'string')
|
|
61
|
+
if (typeof this.wasmFile === 'string') {
|
|
33
62
|
throw new Error('Cannot load module synchronously unless wasmFile is of type ArrayBuffer');
|
|
63
|
+
}
|
|
34
64
|
this.module = (0, app_loader_1.loadWasmSync)(this.wasmFile, {});
|
|
35
65
|
return this.module;
|
|
36
66
|
}
|
|
@@ -55,6 +85,28 @@ class BundleBase {
|
|
|
55
85
|
return yield this.module.execute(response);
|
|
56
86
|
});
|
|
57
87
|
}
|
|
88
|
+
// For dynamic job data connector
|
|
89
|
+
transform() {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
if (!this.executionContext) {
|
|
92
|
+
throw new Error('Execution context missing');
|
|
93
|
+
}
|
|
94
|
+
// If the module is not initialized, try to load it
|
|
95
|
+
if (!this.module) {
|
|
96
|
+
try {
|
|
97
|
+
yield this.load();
|
|
98
|
+
}
|
|
99
|
+
catch (_a) {
|
|
100
|
+
throw new Error('Module not initialized');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// If the module is still not initialized, throw an error
|
|
104
|
+
if (!this.module)
|
|
105
|
+
throw new Error('Module not initialized');
|
|
106
|
+
// Call the main function with the response
|
|
107
|
+
return yield this.module.transform();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
58
110
|
executeBundle(data) {
|
|
59
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
112
|
if (!this.executionContext) {
|
|
@@ -76,7 +128,33 @@ class BundleBase {
|
|
|
76
128
|
return this.module.execute(...data);
|
|
77
129
|
});
|
|
78
130
|
}
|
|
79
|
-
|
|
131
|
+
executeDynamicJobBundle(data) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
if (!this.executionContext) {
|
|
134
|
+
throw new Error('Execution context missing');
|
|
135
|
+
}
|
|
136
|
+
// If the module is not initialized, try to load it
|
|
137
|
+
if (!this.module) {
|
|
138
|
+
try {
|
|
139
|
+
yield this.load();
|
|
140
|
+
}
|
|
141
|
+
catch (_a) {
|
|
142
|
+
throw new Error('Module not initialized');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// If the module is still not initialized, throw an error
|
|
146
|
+
if (!this.module)
|
|
147
|
+
throw new Error('Module not initialized');
|
|
148
|
+
// Call the main function with the response
|
|
149
|
+
return this.module.execute(...data);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
reset() {
|
|
153
|
+
if (this.module && this.module['reset']) {
|
|
154
|
+
this.module.reset();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
setExecutionContextStrategyExecution(executionContext, forceDeposit) {
|
|
80
158
|
var _a;
|
|
81
159
|
// Determine the timestamp for epoch
|
|
82
160
|
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
@@ -85,8 +163,10 @@ class BundleBase {
|
|
|
85
163
|
this.executionContext = Object.assign(Object.assign({}, executionContext), { epochTimestamp: timestampInSecs });
|
|
86
164
|
const completeConfig = Object.assign(Object.assign({}, JSON.parse(this.config)), this.executionContext);
|
|
87
165
|
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
88
|
-
|
|
89
|
-
|
|
166
|
+
if (completeConfig.triggerStyle && forceDeposit === true) {
|
|
167
|
+
completeConfig.triggerStyle = 'None';
|
|
168
|
+
}
|
|
169
|
+
(_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(completeConfig, bigIntReplacer));
|
|
90
170
|
}
|
|
91
171
|
setExecutionContextDataConnector(executionContext) {
|
|
92
172
|
var _a;
|
|
@@ -97,8 +177,7 @@ class BundleBase {
|
|
|
97
177
|
this.executionContext = Object.assign(Object.assign({}, executionContext), { epochTimestamp: timestampInSecs });
|
|
98
178
|
const completeConfig = Object.assign(Object.assign({}, JSON.parse(this.config)), { executionContext: this.executionContext });
|
|
99
179
|
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
100
|
-
|
|
101
|
-
(_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(completeConfig));
|
|
180
|
+
(_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(completeConfig, bigIntReplacer));
|
|
102
181
|
}
|
|
103
182
|
executeModule(response) {
|
|
104
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -112,8 +191,8 @@ class BundleBase {
|
|
|
112
191
|
// The chainId is first checked in the data connector config, and if not found
|
|
113
192
|
// it is checked in the request config. If the chainId is found in either of
|
|
114
193
|
// these places, the provider is returned from the etherRpcConfig object
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
194
|
getProvider(config) {
|
|
195
|
+
var _a;
|
|
117
196
|
let chainId;
|
|
118
197
|
// check if chainId is configured in data connector config
|
|
119
198
|
if (this.configObj.chainId) {
|
|
@@ -124,8 +203,8 @@ class BundleBase {
|
|
|
124
203
|
chainId = config.chainId;
|
|
125
204
|
}
|
|
126
205
|
if (chainId && this.etherRpcConfig && this.etherRpcConfig[chainId]) {
|
|
127
|
-
const
|
|
128
|
-
return
|
|
206
|
+
const rpcConfig = this.etherRpcConfig[chainId];
|
|
207
|
+
return createFallbackRpcProvider((_a = rpcConfig.urls) !== null && _a !== void 0 ? _a : [rpcConfig.url]);
|
|
129
208
|
}
|
|
130
209
|
else {
|
|
131
210
|
return this.providerIdentity;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ethers } from 'ethers';
|
|
2
|
+
import type { ExecutionAppConfig } from '../execution/executionApp.js';
|
|
3
|
+
import type { EtherRpcConfig, ViewConfig } from '../types.js';
|
|
4
|
+
import { BundleBase } from './bundleBase.js';
|
|
4
5
|
export declare class DataConnector extends BundleBase {
|
|
5
|
-
constructor(wasmFile: string | ArrayBuffer, _config: string, identity?: ethers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
6
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, executionAppConfig: ExecutionAppConfig, identity?: ethers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
6
7
|
getRpcUrl(config: any): string | undefined;
|
|
7
8
|
view(config: ViewConfig): Promise<string>;
|
|
8
9
|
}
|
|
@@ -11,13 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DataConnector = void 0;
|
|
13
13
|
const ethers_1 = require("ethers");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
class DataConnector extends
|
|
14
|
+
const consts_js_1 = require("../utils/consts.js");
|
|
15
|
+
const utils_js_1 = require("../utils/utils.js");
|
|
16
|
+
const bundleBase_js_1 = require("./bundleBase.js");
|
|
17
|
+
class DataConnector extends bundleBase_js_1.BundleBase {
|
|
18
18
|
// Identity should come from the node's IdentityManager.wallet
|
|
19
|
-
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
20
|
-
super(wasmFile, _config, identity, etherRpcConfig);
|
|
19
|
+
constructor(wasmFile, _config, executionAppConfig, identity, etherRpcConfig) {
|
|
20
|
+
super(wasmFile, _config, executionAppConfig, identity, etherRpcConfig);
|
|
21
21
|
}
|
|
22
22
|
// get rpc url from configuration
|
|
23
23
|
getRpcUrl(config) {
|
|
@@ -38,7 +38,6 @@ class DataConnector extends bundleBase_1.BundleBase {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
// Makes contract instance and calls, returns stringified result
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
41
|
view(config) {
|
|
43
42
|
var _a;
|
|
44
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -46,13 +45,12 @@ class DataConnector extends bundleBase_1.BundleBase {
|
|
|
46
45
|
if (!provider)
|
|
47
46
|
throw new Error('Provider not initialized');
|
|
48
47
|
const contract = new ethers_1.Contract(config.address, config.abi, provider);
|
|
49
|
-
// For formatting the parameters if needed
|
|
50
48
|
const paramsArray = config.arguments;
|
|
51
49
|
let result;
|
|
52
|
-
if (
|
|
50
|
+
if (consts_js_1.CENTRALIZE_CONTRACT_INTERACTION_CHAINS.indexOf(this.configObj.chainId.toString()) === -1) {
|
|
53
51
|
result = yield contract[config.method](...paramsArray, {
|
|
54
52
|
blockTag: (_a = this.executionContext) === null || _a === void 0 ? void 0 : _a.blockNumber,
|
|
55
|
-
});
|
|
53
|
+
});
|
|
56
54
|
}
|
|
57
55
|
else {
|
|
58
56
|
const viewContractConfig = {
|
|
@@ -63,7 +61,7 @@ class DataConnector extends bundleBase_1.BundleBase {
|
|
|
63
61
|
method: config.method,
|
|
64
62
|
rpcUrl: this.getRpcUrl(config),
|
|
65
63
|
};
|
|
66
|
-
result = yield (0,
|
|
64
|
+
result = yield (0, utils_js_1.callWithRetry)(viewContractConfig);
|
|
67
65
|
}
|
|
68
66
|
// This gets stringified before calling main
|
|
69
67
|
return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { WasmModule } from '@steerprotocol/app-loader';
|
|
1
|
+
import type { WasmModule } from '@steerprotocol/app-loader';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
|
-
import {
|
|
3
|
+
import type { ExecutionAppConfig } from '../execution/executionApp.js';
|
|
4
|
+
import type { EtherRpcConfig, ExecutionContext } from '../types.js';
|
|
4
5
|
export declare class BundleBase {
|
|
5
6
|
module?: WasmModule;
|
|
6
7
|
protected wasmFile: ArrayBuffer | string;
|
|
@@ -13,13 +14,17 @@ export declare class BundleBase {
|
|
|
13
14
|
executionContext?: ExecutionContext & {
|
|
14
15
|
epochTimestamp: number;
|
|
15
16
|
};
|
|
16
|
-
protected scheduleEpochTimestamp
|
|
17
|
-
|
|
17
|
+
protected scheduleEpochTimestamp?: number;
|
|
18
|
+
executionAppConfig: ExecutionAppConfig;
|
|
19
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, executionAppConfig: ExecutionAppConfig, identity?: ethers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
18
20
|
load(): Promise<WasmModule>;
|
|
19
21
|
loadSync(): WasmModule;
|
|
20
22
|
execute(response: string): Promise<string>;
|
|
23
|
+
transform(): Promise<string>;
|
|
21
24
|
executeBundle(data: Array<any>): Promise<string>;
|
|
22
|
-
|
|
25
|
+
executeDynamicJobBundle(data: Array<any>): Promise<string>;
|
|
26
|
+
reset(): void;
|
|
27
|
+
setExecutionContextStrategyExecution(executionContext: ExecutionContext, forceDeposit?: boolean): void;
|
|
23
28
|
setExecutionContextDataConnector(executionContext: ExecutionContext): void;
|
|
24
29
|
protected executeModule(response: string): Promise<string>;
|
|
25
30
|
getProvider(config: any): ethers.Provider | undefined;
|
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
import { loadWasm, loadWasmSync } from '@steerprotocol/app-loader';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
|
+
const UNSTABLE_RPC_PATTERNS = [/drpc\.org/i];
|
|
4
|
+
function createFallbackRpcProvider(urls) {
|
|
5
|
+
const seen = new Set();
|
|
6
|
+
const preferred = [];
|
|
7
|
+
const deprioritized = [];
|
|
8
|
+
for (const url of urls) {
|
|
9
|
+
const trimmed = url.trim();
|
|
10
|
+
if (trimmed.length === 0 || seen.has(trimmed)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
seen.add(trimmed);
|
|
14
|
+
if (UNSTABLE_RPC_PATTERNS.some((pattern) => pattern.test(trimmed))) {
|
|
15
|
+
deprioritized.push(trimmed);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
preferred.push(trimmed);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const prioritized = preferred.length > 0 ? [...preferred, ...deprioritized] : [...preferred, ...deprioritized];
|
|
22
|
+
if (prioritized.length === 0) {
|
|
23
|
+
throw new Error('No RPC URLs configured');
|
|
24
|
+
}
|
|
25
|
+
const providers = prioritized.map((url) => new ethers.JsonRpcProvider(url));
|
|
26
|
+
return providers.length === 1 ? providers[0] : new ethers.FallbackProvider(providers);
|
|
27
|
+
}
|
|
28
|
+
function bigIntReplacer(_key, value) {
|
|
29
|
+
return typeof value === 'bigint' ? value.toString() : value;
|
|
30
|
+
}
|
|
3
31
|
export class BundleBase {
|
|
4
|
-
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
32
|
+
constructor(wasmFile, _config, executionAppConfig, identity, etherRpcConfig) {
|
|
5
33
|
this.wasmFile = wasmFile;
|
|
6
34
|
this.config = _config;
|
|
7
35
|
this.configObj = JSON.parse(_config);
|
|
8
36
|
this.providerIdentity = identity;
|
|
9
37
|
this.etherRpcConfig = etherRpcConfig;
|
|
38
|
+
this.executionAppConfig = executionAppConfig;
|
|
10
39
|
}
|
|
11
40
|
async load() {
|
|
12
41
|
const instance = await loadWasm(this.wasmFile, {});
|
|
@@ -15,8 +44,9 @@ export class BundleBase {
|
|
|
15
44
|
return this.module;
|
|
16
45
|
}
|
|
17
46
|
loadSync() {
|
|
18
|
-
if (typeof this.wasmFile === 'string')
|
|
47
|
+
if (typeof this.wasmFile === 'string') {
|
|
19
48
|
throw new Error('Cannot load module synchronously unless wasmFile is of type ArrayBuffer');
|
|
49
|
+
}
|
|
20
50
|
this.module = loadWasmSync(this.wasmFile, {});
|
|
21
51
|
return this.module;
|
|
22
52
|
}
|
|
@@ -39,6 +69,26 @@ export class BundleBase {
|
|
|
39
69
|
// Call the main function with the response
|
|
40
70
|
return await this.module.execute(response);
|
|
41
71
|
}
|
|
72
|
+
// For dynamic job data connector
|
|
73
|
+
async transform() {
|
|
74
|
+
if (!this.executionContext) {
|
|
75
|
+
throw new Error('Execution context missing');
|
|
76
|
+
}
|
|
77
|
+
// If the module is not initialized, try to load it
|
|
78
|
+
if (!this.module) {
|
|
79
|
+
try {
|
|
80
|
+
await this.load();
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
throw new Error('Module not initialized');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// If the module is still not initialized, throw an error
|
|
87
|
+
if (!this.module)
|
|
88
|
+
throw new Error('Module not initialized');
|
|
89
|
+
// Call the main function with the response
|
|
90
|
+
return await this.module.transform();
|
|
91
|
+
}
|
|
42
92
|
async executeBundle(data) {
|
|
43
93
|
if (!this.executionContext) {
|
|
44
94
|
throw new Error('Execution context missing');
|
|
@@ -58,7 +108,31 @@ export class BundleBase {
|
|
|
58
108
|
// Call the main function with the response
|
|
59
109
|
return this.module.execute(...data);
|
|
60
110
|
}
|
|
61
|
-
|
|
111
|
+
async executeDynamicJobBundle(data) {
|
|
112
|
+
if (!this.executionContext) {
|
|
113
|
+
throw new Error('Execution context missing');
|
|
114
|
+
}
|
|
115
|
+
// If the module is not initialized, try to load it
|
|
116
|
+
if (!this.module) {
|
|
117
|
+
try {
|
|
118
|
+
await this.load();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new Error('Module not initialized');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// If the module is still not initialized, throw an error
|
|
125
|
+
if (!this.module)
|
|
126
|
+
throw new Error('Module not initialized');
|
|
127
|
+
// Call the main function with the response
|
|
128
|
+
return this.module.execute(...data);
|
|
129
|
+
}
|
|
130
|
+
reset() {
|
|
131
|
+
if (this.module && this.module['reset']) {
|
|
132
|
+
this.module.reset();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
setExecutionContextStrategyExecution(executionContext, forceDeposit) {
|
|
62
136
|
// Determine the timestamp for epoch
|
|
63
137
|
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
64
138
|
// Divide milliseconds data to seconds for transformation bundle
|
|
@@ -66,8 +140,10 @@ export class BundleBase {
|
|
|
66
140
|
this.executionContext = { ...executionContext, epochTimestamp: timestampInSecs };
|
|
67
141
|
const completeConfig = { ...JSON.parse(this.config), ...this.executionContext };
|
|
68
142
|
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
69
|
-
|
|
70
|
-
|
|
143
|
+
if (completeConfig.triggerStyle && forceDeposit === true) {
|
|
144
|
+
completeConfig.triggerStyle = 'None';
|
|
145
|
+
}
|
|
146
|
+
this.module?.initialize(JSON.stringify(completeConfig, bigIntReplacer));
|
|
71
147
|
}
|
|
72
148
|
setExecutionContextDataConnector(executionContext) {
|
|
73
149
|
// Determine the timestamp for epoch
|
|
@@ -77,8 +153,7 @@ export class BundleBase {
|
|
|
77
153
|
this.executionContext = { ...executionContext, epochTimestamp: timestampInSecs };
|
|
78
154
|
const completeConfig = { ...JSON.parse(this.config), executionContext: this.executionContext };
|
|
79
155
|
this.scheduleEpochTimestamp = executionContext.epochTimestamp;
|
|
80
|
-
|
|
81
|
-
this.module?.initialize(JSON.stringify(completeConfig));
|
|
156
|
+
this.module?.initialize(JSON.stringify(completeConfig, bigIntReplacer));
|
|
82
157
|
}
|
|
83
158
|
async executeModule(response) {
|
|
84
159
|
if (!this.module) {
|
|
@@ -90,7 +165,6 @@ export class BundleBase {
|
|
|
90
165
|
// The chainId is first checked in the data connector config, and if not found
|
|
91
166
|
// it is checked in the request config. If the chainId is found in either of
|
|
92
167
|
// these places, the provider is returned from the etherRpcConfig object
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
168
|
getProvider(config) {
|
|
95
169
|
let chainId;
|
|
96
170
|
// check if chainId is configured in data connector config
|
|
@@ -102,8 +176,8 @@ export class BundleBase {
|
|
|
102
176
|
chainId = config.chainId;
|
|
103
177
|
}
|
|
104
178
|
if (chainId && this.etherRpcConfig && this.etherRpcConfig[chainId]) {
|
|
105
|
-
const
|
|
106
|
-
return
|
|
179
|
+
const rpcConfig = this.etherRpcConfig[chainId];
|
|
180
|
+
return createFallbackRpcProvider(rpcConfig.urls ?? [rpcConfig.url]);
|
|
107
181
|
}
|
|
108
182
|
else {
|
|
109
183
|
return this.providerIdentity;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ethers } from 'ethers';
|
|
2
|
+
import type { ExecutionAppConfig } from '../execution/executionApp.js';
|
|
3
|
+
import type { EtherRpcConfig, ViewConfig } from '../types.js';
|
|
4
|
+
import { BundleBase } from './bundleBase.js';
|
|
4
5
|
export declare class DataConnector extends BundleBase {
|
|
5
|
-
constructor(wasmFile: string | ArrayBuffer, _config: string, identity?: ethers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
6
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string, executionAppConfig: ExecutionAppConfig, identity?: ethers.Provider, etherRpcConfig?: EtherRpcConfig);
|
|
6
7
|
getRpcUrl(config: any): string | undefined;
|
|
7
8
|
view(config: ViewConfig): Promise<string>;
|
|
8
9
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
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';
|
|
2
|
+
import { CENTRALIZE_CONTRACT_INTERACTION_CHAINS } from '../utils/consts.js';
|
|
3
|
+
import { callWithRetry } from '../utils/utils.js';
|
|
4
|
+
import { BundleBase } from './bundleBase.js';
|
|
5
5
|
export class DataConnector extends BundleBase {
|
|
6
6
|
// Identity should come from the node's IdentityManager.wallet
|
|
7
|
-
constructor(wasmFile, _config, identity, etherRpcConfig) {
|
|
8
|
-
super(wasmFile, _config, identity, etherRpcConfig);
|
|
7
|
+
constructor(wasmFile, _config, executionAppConfig, identity, etherRpcConfig) {
|
|
8
|
+
super(wasmFile, _config, executionAppConfig, identity, etherRpcConfig);
|
|
9
9
|
}
|
|
10
10
|
// get rpc url from configuration
|
|
11
11
|
getRpcUrl(config) {
|
|
@@ -26,19 +26,17 @@ export class DataConnector extends BundleBase {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
// Makes contract instance and calls, returns stringified result
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
29
|
async view(config) {
|
|
31
30
|
const provider = this.getProvider(config);
|
|
32
31
|
if (!provider)
|
|
33
32
|
throw new Error('Provider not initialized');
|
|
34
33
|
const contract = new Contract(config.address, config.abi, provider);
|
|
35
|
-
// For formatting the parameters if needed
|
|
36
34
|
const paramsArray = config.arguments;
|
|
37
35
|
let result;
|
|
38
36
|
if (CENTRALIZE_CONTRACT_INTERACTION_CHAINS.indexOf(this.configObj.chainId.toString()) === -1) {
|
|
39
37
|
result = await contract[config.method](...paramsArray, {
|
|
40
38
|
blockTag: this.executionContext?.blockNumber,
|
|
41
|
-
});
|
|
39
|
+
});
|
|
42
40
|
}
|
|
43
41
|
else {
|
|
44
42
|
const viewContractConfig = {
|
|
@@ -1,17 +1,62 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { EtherRpcConfig } from '../types';
|
|
3
|
-
import { ExecutionBase } from './executionBase';
|
|
4
|
-
export
|
|
1
|
+
import type { ethers } from 'ethers';
|
|
2
|
+
import type { EtherRpcConfig, JobDetails } from '../types.js';
|
|
3
|
+
import { ExecutionBase } from './executionBase.js';
|
|
4
|
+
export interface ExecutionAppConfig {
|
|
5
|
+
/** Vault address used for execution context and subgraph queries. */
|
|
6
|
+
vault: string;
|
|
7
|
+
/** Chain ID used to resolve RPC configuration and on-chain reads. */
|
|
8
|
+
chainId: number;
|
|
9
|
+
/** Subgraph endpoint used for protocol data queries. */
|
|
5
10
|
steerSubgraph: string;
|
|
11
|
+
poolType: {
|
|
12
|
+
/** Set true when the pool uses Algebra v1 semantics. */
|
|
13
|
+
isAlgebraPool: boolean;
|
|
14
|
+
/** Set true when the pool uses Algebra Integral semantics. */
|
|
15
|
+
isAlgebraIntegralPool: boolean;
|
|
16
|
+
/** Set true when the pool uses directional pool semantics. */
|
|
17
|
+
isDirectionalPool: boolean;
|
|
18
|
+
/** Set true when the pool uses PoolShark semantics. */
|
|
19
|
+
isPoolSharkPool: boolean;
|
|
20
|
+
/** Set true when the pool uses Aerodrome semantics. */
|
|
21
|
+
isAerodromePool: boolean;
|
|
22
|
+
};
|
|
23
|
+
apiKeys: {
|
|
24
|
+
/** API key for The Graph Studio / gateway endpoints. */
|
|
25
|
+
subgraphStudioKey: string;
|
|
26
|
+
/** API key for Sentio endpoints, if applicable. */
|
|
27
|
+
sentioApiKey: string;
|
|
28
|
+
};
|
|
29
|
+
/** Maximum number of retries for execution operations. */
|
|
30
|
+
maxRetries?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare class ExecutionApp extends ExecutionBase {
|
|
6
33
|
vault: string;
|
|
34
|
+
steerSubgraph: string;
|
|
35
|
+
chainId: number;
|
|
7
36
|
isAlgebraPool: boolean;
|
|
37
|
+
isAlgebraIntegralPool: boolean;
|
|
8
38
|
isDirectionalPool: boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
39
|
+
isPoolSharkPool: boolean;
|
|
40
|
+
isAerodromePool: boolean;
|
|
41
|
+
subgraphStudioKey: string;
|
|
42
|
+
sentioApiKey: string;
|
|
43
|
+
config: ExecutionAppConfig;
|
|
44
|
+
constructor(config: ExecutionAppConfig);
|
|
45
|
+
execute<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, _identity?: ethers.Provider, _etherRpcConfig?: EtherRpcConfig, forceDeposit?: boolean): Promise<Array<T>>;
|
|
46
|
+
executeStabilityVault<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, _identity?: ethers.Provider, _etherRpcConfig?: EtherRpcConfig, forceDeposit?: boolean): Promise<Array<T>>;
|
|
47
|
+
executeDynamicJobs<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, _job: JobDetails, _identity?: ethers.Provider, _etherRpcConfig?: EtherRpcConfig, forceDeposit?: boolean): Promise<Array<T>>;
|
|
12
48
|
private getSmartPoolExecutionContext;
|
|
13
49
|
private getPoolCurrentTick;
|
|
50
|
+
private getTickSpacing;
|
|
51
|
+
/**
|
|
52
|
+
* Converts a value to string, handling both native bigint and serialized bigint objects
|
|
53
|
+
* from the centralized API
|
|
54
|
+
*/
|
|
55
|
+
private convertToString;
|
|
56
|
+
private getTotalAmounts;
|
|
14
57
|
private getVaultPoolAddress;
|
|
15
58
|
private getSlot0;
|
|
59
|
+
private getSlot0Aerodrome;
|
|
60
|
+
private getGlobalStateAbi;
|
|
16
61
|
private getGlobalState;
|
|
17
62
|
}
|