@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
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { DataConnector } from '../bundle/bundleDataConnector';
|
|
3
|
-
import {
|
|
1
|
+
import type { ethers } from 'ethers';
|
|
2
|
+
import type { DataConnector } from '../bundle/bundleDataConnector.js';
|
|
3
|
+
import type { EtherRpcConfig, ExecutionContext, VaultConfigPayload } from '../types.js';
|
|
4
4
|
export declare class ExecutionBase {
|
|
5
5
|
maxRetries: number;
|
|
6
6
|
constructor(maxRetries?: number);
|
|
7
7
|
protected delay(ms: number): Promise<void>;
|
|
8
|
-
protected log(...args: any
|
|
8
|
+
protected log(...args: Array<any>): void;
|
|
9
9
|
protected getExecutionContext(dataConnector: DataConnector, vaultConfig: VaultConfigPayload): Promise<ExecutionContext>;
|
|
10
10
|
execute<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, _identity?: ethers.Provider, _etherRpcConfig?: EtherRpcConfig): Promise<Array<T>>;
|
|
11
11
|
protected getDataConnectorVersion(dataConnector: DataConnector): Promise<number>;
|
|
@@ -18,7 +18,6 @@ class ExecutionBase {
|
|
|
18
18
|
delay(ms) {
|
|
19
19
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
20
|
}
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
21
|
log(...args) {
|
|
23
22
|
if (process.env.DEBUG === 'true') {
|
|
24
23
|
console.log(...args);
|
|
@@ -29,25 +28,25 @@ class ExecutionBase {
|
|
|
29
28
|
const provider = dataConnector.getProvider({});
|
|
30
29
|
let blockTime = 0;
|
|
31
30
|
let blockNumber = 9;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
blockNumber = yield this.getBlockNumberFromAvgBlockTime(provider, vaultConfig.epochTimestamp / 1000, // convert to seconds
|
|
38
|
-
blockTime);
|
|
31
|
+
// Use anchorBlockNumber if provided, otherwise calculate from average block time
|
|
32
|
+
if (vaultConfig.anchorBlockNumber !== undefined) {
|
|
33
|
+
blockNumber = vaultConfig.anchorBlockNumber;
|
|
34
|
+
if (provider) {
|
|
35
|
+
blockTime = yield this.getAverageBlockTime(provider);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
if (
|
|
42
|
-
|
|
38
|
+
else if (provider) {
|
|
39
|
+
blockTime = yield this.getAverageBlockTime(provider);
|
|
40
|
+
blockNumber = yield this.getBlockNumberFromAvgBlockTime(provider, vaultConfig.epochTimestamp / 1000, // convert to seconds
|
|
41
|
+
blockNumber);
|
|
43
42
|
}
|
|
44
43
|
const context = {
|
|
45
44
|
executionTimestamp: new Date().getTime(),
|
|
46
45
|
epochTimestamp: vaultConfig.epochTimestamp,
|
|
47
46
|
epochLength: Number(vaultConfig.strategyConfigData.epochLength),
|
|
48
47
|
vaultAddress: vaultConfig.vaultAddress,
|
|
49
|
-
blockTime
|
|
50
|
-
blockNumber
|
|
48
|
+
blockTime,
|
|
49
|
+
blockNumber,
|
|
51
50
|
};
|
|
52
51
|
return context;
|
|
53
52
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { DataConnector } from '../bundle/bundleDataConnector.js';
|
|
2
|
+
import { ExecutionBase } from './executionBase.js';
|
|
3
3
|
export declare class DataConnectorExecution extends ExecutionBase {
|
|
4
4
|
private dataConnectors;
|
|
5
5
|
constructor(dataConnectors: Array<DataConnector>, maxRetries?: number);
|
|
6
6
|
execute<T>(_vaultConfig: string): Promise<Array<T>>;
|
|
7
|
+
private executeV2Bundle;
|
|
8
|
+
executeDynamicJob<T>(_vaultConfig: string): Promise<Array<T>>;
|
|
7
9
|
private handleRequestResponse;
|
|
8
10
|
private transformData;
|
|
9
11
|
}
|
|
@@ -10,10 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DataConnectorExecution = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
13
|
+
const pluginManager_js_1 = require("../utils/pluginManager.js");
|
|
14
|
+
const replace_old_subgraphs_js_1 = require("../utils/replace-old-subgraphs.js");
|
|
15
|
+
const utils_js_1 = require("../utils/utils.js");
|
|
16
|
+
const executionBase_js_1 = require("./executionBase.js");
|
|
17
|
+
class DataConnectorExecution extends executionBase_js_1.ExecutionBase {
|
|
17
18
|
constructor(dataConnectors, maxRetries = 3) {
|
|
18
19
|
super(maxRetries);
|
|
19
20
|
this.dataConnectors = dataConnectors;
|
|
@@ -22,30 +23,69 @@ class DataConnectorExecution extends executionBase_1.ExecutionBase {
|
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
const vaultConfig = JSON.parse(_vaultConfig);
|
|
24
25
|
const transformationData = [];
|
|
25
|
-
const pluginManager = new
|
|
26
|
+
const pluginManager = new pluginManager_js_1.PluginManager();
|
|
26
27
|
yield pluginManager.registerFromPublicConfig();
|
|
27
28
|
for (const dataConnector of this.dataConnectors) {
|
|
28
29
|
if (!dataConnector.module) {
|
|
29
30
|
yield dataConnector.load();
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
let version = 1;
|
|
33
|
+
try {
|
|
34
|
+
version = dataConnector.version();
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
version = 1;
|
|
38
|
+
}
|
|
39
|
+
if (version >= 2) {
|
|
40
|
+
const transformData = yield this.executeV2Bundle(dataConnector, vaultConfig);
|
|
41
|
+
transformationData.push(transformData);
|
|
39
42
|
}
|
|
40
43
|
else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
try {
|
|
45
|
+
const executionContext = yield this.getExecutionContext(dataConnector, vaultConfig);
|
|
46
|
+
dataConnector.setExecutionContextDataConnector(executionContext);
|
|
47
|
+
const initialRequest = yield dataConnector.execute('');
|
|
48
|
+
const finalResponse = yield this.handleRequestResponse(dataConnector, pluginManager, initialRequest);
|
|
49
|
+
const transformedData = yield this.transformData(dataConnector, finalResponse);
|
|
50
|
+
transformationData.push(transformedData);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
const transformData = yield this.executeV2Bundle(dataConnector, vaultConfig);
|
|
54
|
+
transformationData.push(transformData);
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
}
|
|
46
58
|
return transformationData;
|
|
47
59
|
});
|
|
48
60
|
}
|
|
61
|
+
executeV2Bundle(dataConnector, vaultConfig) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const executionContext = yield this.getExecutionContext(dataConnector, vaultConfig);
|
|
64
|
+
dataConnector.setExecutionContextDataConnector(executionContext);
|
|
65
|
+
yield dataConnector.execute('');
|
|
66
|
+
const result = yield dataConnector.transform();
|
|
67
|
+
return JSON.parse(result);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
executeDynamicJob(_vaultConfig) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const vaultConfig = JSON.parse(_vaultConfig);
|
|
73
|
+
const transformationData = [];
|
|
74
|
+
const pluginManager = new pluginManager_js_1.PluginManager();
|
|
75
|
+
yield pluginManager.registerFromPublicConfig();
|
|
76
|
+
for (const dataConnector of this.dataConnectors) {
|
|
77
|
+
if (!dataConnector.module) {
|
|
78
|
+
yield dataConnector.load();
|
|
79
|
+
}
|
|
80
|
+
const executionContext = yield this.getExecutionContext(dataConnector, vaultConfig);
|
|
81
|
+
dataConnector.setExecutionContextDataConnector(executionContext);
|
|
82
|
+
yield dataConnector.execute('');
|
|
83
|
+
const result = yield dataConnector.transform();
|
|
84
|
+
transformationData.push(JSON.parse(result));
|
|
85
|
+
}
|
|
86
|
+
return transformationData;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
49
89
|
handleRequestResponse(dataConnector, pluginManager, initialRequest) {
|
|
50
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
91
|
let request = initialRequest;
|
|
@@ -57,8 +97,11 @@ class DataConnectorExecution extends executionBase_1.ExecutionBase {
|
|
|
57
97
|
}
|
|
58
98
|
else {
|
|
59
99
|
const parsedRequest = yield pluginManager.process(typeof request == 'string' ? JSON.parse(request) : request);
|
|
100
|
+
const url = (0, replace_old_subgraphs_js_1.changeUrlIfOld)(parsedRequest.url, dataConnector.configObj.subgraphStudioKey);
|
|
101
|
+
parsedRequest.url = url;
|
|
102
|
+
parsedRequest.headers = Object.assign({ 'Content-Type': url && !url.includes('subgraph-proxy-server') ? 'application/json' : 'text/plain;charset=UTF-8' }, ((url === null || url === void 0 ? void 0 : url.includes('sentio')) ? { 'api-key': dataConnector.executionAppConfig.apiKeys.sentioApiKey } : {}));
|
|
60
103
|
yield this.delay(1000);
|
|
61
|
-
response = yield (0,
|
|
104
|
+
response = yield (0, utils_js_1.fetchData)(parsedRequest, 0);
|
|
62
105
|
}
|
|
63
106
|
request = yield dataConnector.execute(JSON.stringify(response));
|
|
64
107
|
}
|
|
@@ -73,21 +116,10 @@ class DataConnectorExecution extends executionBase_1.ExecutionBase {
|
|
|
73
116
|
return dataConnector.getResults();
|
|
74
117
|
});
|
|
75
118
|
}
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
119
|
transformData(dataConnector, rawData) {
|
|
78
120
|
var _a, _b, _c;
|
|
79
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
122
|
let transformedData = typeof rawData === 'string' ? JSON.parse(rawData) : rawData;
|
|
81
|
-
if (transformedData == null || transformedData.length == 0) {
|
|
82
|
-
const results = dataConnector.getResults();
|
|
83
|
-
const parsedResults = JSON.parse(results);
|
|
84
|
-
if (parsedResults.length == null) {
|
|
85
|
-
transformedData = results;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
transformedData = parsedResults;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
123
|
const version = yield this.getDataConnectorVersion(dataConnector);
|
|
92
124
|
if (version == 1 && transformedData.length > 0) {
|
|
93
125
|
const keys = Object.keys(transformedData[0]);
|
|
@@ -98,7 +130,7 @@ class DataConnectorExecution extends executionBase_1.ExecutionBase {
|
|
|
98
130
|
if (hasAllKeys && !!lookback) {
|
|
99
131
|
// Now that we have identified a v1 data connector, we need to transform the data so that the data is up to the current execution epoch timestamp
|
|
100
132
|
if ((_b = dataConnector === null || dataConnector === void 0 ? void 0 : dataConnector.executionContext) === null || _b === void 0 ? void 0 : _b.epochTimestamp) {
|
|
101
|
-
const extended = (0,
|
|
133
|
+
const extended = (0, utils_js_1.extendOHLCV)(transformedData, lookback, ((_c = dataConnector === null || dataConnector === void 0 ? void 0 : dataConnector.executionContext) === null || _c === void 0 ? void 0 : _c.epochTimestamp) * 1000);
|
|
102
134
|
transformedData = extended;
|
|
103
135
|
}
|
|
104
136
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { DataConnector } from './bundle/bundleDataConnector';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { DataConnector } from './bundle/bundleDataConnector.js';
|
|
2
|
+
import { ExecutionApp, type ExecutionAppConfig } from './execution/executionApp.js';
|
|
3
|
+
import { DataConnectorExecution } from './execution/executionDataConnector.js';
|
|
4
|
+
import type { VaultConfigPayload } from './types.js';
|
|
5
|
+
export type * from './types.js';
|
|
5
6
|
export { DataConnector, DataConnectorExecution, ExecutionApp };
|
|
7
|
+
export type { ExecutionAppConfig, VaultConfigPayload };
|
package/lib/index.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
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
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
3
|
exports.ExecutionApp = exports.DataConnectorExecution = exports.DataConnector = void 0;
|
|
18
|
-
const
|
|
19
|
-
Object.defineProperty(exports, "DataConnector", { enumerable: true, get: function () { return
|
|
20
|
-
const
|
|
21
|
-
Object.defineProperty(exports, "
|
|
22
|
-
const
|
|
23
|
-
Object.defineProperty(exports, "
|
|
24
|
-
__exportStar(require("./types"), exports);
|
|
4
|
+
const bundleDataConnector_js_1 = require("./bundle/bundleDataConnector.js");
|
|
5
|
+
Object.defineProperty(exports, "DataConnector", { enumerable: true, get: function () { return bundleDataConnector_js_1.DataConnector; } });
|
|
6
|
+
const executionApp_js_1 = require("./execution/executionApp.js");
|
|
7
|
+
Object.defineProperty(exports, "ExecutionApp", { enumerable: true, get: function () { return executionApp_js_1.ExecutionApp; } });
|
|
8
|
+
const executionDataConnector_js_1 = require("./execution/executionDataConnector.js");
|
|
9
|
+
Object.defineProperty(exports, "DataConnectorExecution", { enumerable: true, get: function () { return executionDataConnector_js_1.DataConnectorExecution; } });
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InterfaceAbi } from 'ethers';
|
|
1
|
+
import type { InterfaceAbi } from 'ethers';
|
|
2
2
|
export type VaultInput = {
|
|
3
3
|
_id?: string;
|
|
4
4
|
tokenId: string;
|
|
@@ -23,7 +23,7 @@ export type VaultInput = {
|
|
|
23
23
|
export interface VaultConfigPayload {
|
|
24
24
|
strategyConfigData: StrategyConfigData;
|
|
25
25
|
vaultPayload: VaultPayload;
|
|
26
|
-
dataConnectorsData: DataConnectorsDaum
|
|
26
|
+
dataConnectorsData: Array<DataConnectorsDaum>;
|
|
27
27
|
vaultAddress: string;
|
|
28
28
|
epochTimestamp: number;
|
|
29
29
|
anchorBlockNumber?: number;
|
|
@@ -63,12 +63,16 @@ export interface Position {
|
|
|
63
63
|
weight: number;
|
|
64
64
|
}
|
|
65
65
|
export interface SmartPoolExecutionContext extends ExecutionContext {
|
|
66
|
-
positions: Position
|
|
66
|
+
positions: Array<Position>;
|
|
67
67
|
currentTick: number;
|
|
68
68
|
lastExecutionTime: number;
|
|
69
|
+
totalAmount0: string;
|
|
70
|
+
totalAmount1: string;
|
|
71
|
+
tickSpacing: number;
|
|
69
72
|
}
|
|
70
73
|
export type RpcConfig = {
|
|
71
74
|
url: string;
|
|
75
|
+
urls?: ReadonlyArray<string>;
|
|
72
76
|
network?: string;
|
|
73
77
|
};
|
|
74
78
|
export type EtherRpcConfig = {
|
|
@@ -78,7 +82,7 @@ export interface ViewConfig {
|
|
|
78
82
|
address: string;
|
|
79
83
|
abi: InterfaceAbi;
|
|
80
84
|
method: string;
|
|
81
|
-
arguments: unknown
|
|
85
|
+
arguments: Array<unknown>;
|
|
82
86
|
}
|
|
83
87
|
export interface Slot0 {
|
|
84
88
|
sqrtPriceX96?: bigint;
|
|
@@ -102,3 +106,12 @@ export type ViewContractConfig = {
|
|
|
102
106
|
method: string;
|
|
103
107
|
rpcUrl?: string;
|
|
104
108
|
};
|
|
109
|
+
export type JobDetails = {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
timestamp: string;
|
|
113
|
+
jobInfo: ReadonlyArray<unknown>;
|
|
114
|
+
targetAddresses: ReadonlyArray<string>;
|
|
115
|
+
ipfsHash: string;
|
|
116
|
+
status: string;
|
|
117
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
1
|
+
import type { ethers } from 'ethers';
|
|
2
2
|
/**
|
|
3
3
|
* Iterates down from current block to find the block previous or equal to the given timestamp
|
|
4
4
|
* Not the most efficient for far past timestamps, a binary search could be used for better performance
|
package/lib/utils/consts.js
CHANGED
|
@@ -2,6 +2,48 @@
|
|
|
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
4
|
exports.API_BASE_URL = 'https://cvrlulno2m.execute-api.ap-southeast-1.amazonaws.com/dev/contract-view-call';
|
|
5
|
+
// export const API_BASE_URL = "http://localhost:3000/dev/contract-view-call";
|
|
5
6
|
exports.API_MAX_RETRIES = 3;
|
|
6
7
|
exports.API_INITIAL_DELAY = 1000;
|
|
7
|
-
exports.CENTRALIZE_CONTRACT_INTERACTION_CHAINS = [
|
|
8
|
+
exports.CENTRALIZE_CONTRACT_INTERACTION_CHAINS = [
|
|
9
|
+
'999',
|
|
10
|
+
'43114',
|
|
11
|
+
'6900',
|
|
12
|
+
'5464',
|
|
13
|
+
'2020',
|
|
14
|
+
'747474',
|
|
15
|
+
'1116',
|
|
16
|
+
'43111',
|
|
17
|
+
'80094',
|
|
18
|
+
'129399',
|
|
19
|
+
'130',
|
|
20
|
+
'146',
|
|
21
|
+
'1868',
|
|
22
|
+
'1',
|
|
23
|
+
'80084',
|
|
24
|
+
'2222',
|
|
25
|
+
'1329',
|
|
26
|
+
'1284',
|
|
27
|
+
'42161',
|
|
28
|
+
'9001',
|
|
29
|
+
'137',
|
|
30
|
+
'56',
|
|
31
|
+
'5000',
|
|
32
|
+
'250',
|
|
33
|
+
'3776',
|
|
34
|
+
'81457',
|
|
35
|
+
'592',
|
|
36
|
+
'1088',
|
|
37
|
+
'34443',
|
|
38
|
+
// "8453",
|
|
39
|
+
'30',
|
|
40
|
+
// "8453",
|
|
41
|
+
'167000',
|
|
42
|
+
'196',
|
|
43
|
+
'810180',
|
|
44
|
+
'137',
|
|
45
|
+
'314',
|
|
46
|
+
'33139',
|
|
47
|
+
'7000',
|
|
48
|
+
'3338',
|
|
49
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface SubgraphUrlConfig {
|
|
2
|
+
chain: string;
|
|
3
|
+
protocol: string;
|
|
4
|
+
newUrl: string;
|
|
5
|
+
oldUrl: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SubgraphReplacerConfig {
|
|
8
|
+
subgraphStudioKey?: string;
|
|
9
|
+
customConfigs?: Array<SubgraphUrlConfig>;
|
|
10
|
+
}
|
|
11
|
+
export declare class SubgraphUrlReplacer {
|
|
12
|
+
private readonly subgraphStudioKey;
|
|
13
|
+
private readonly subgraphUrlConfigs;
|
|
14
|
+
constructor(config?: SubgraphReplacerConfig);
|
|
15
|
+
changeUrlIfOld(url?: string): string | undefined;
|
|
16
|
+
private getArbitrumSubgraphUrl;
|
|
17
|
+
private getDefaultConfigs;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convenience function that uses the default SubgraphUrlReplacer instance
|
|
21
|
+
* For custom configuration, create a new SubgraphUrlReplacer instance
|
|
22
|
+
*/
|
|
23
|
+
export declare const changeUrlIfOld: (url?: string, subgraphStudioKey?: string) => string | undefined;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changeUrlIfOld = exports.SubgraphUrlReplacer = void 0;
|
|
4
|
+
class SubgraphUrlReplacer {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
var _a;
|
|
7
|
+
this.subgraphStudioKey = (_a = config === null || config === void 0 ? void 0 : config.subgraphStudioKey) !== null && _a !== void 0 ? _a : '';
|
|
8
|
+
this.subgraphUrlConfigs = (config === null || config === void 0 ? void 0 : config.customConfigs) || this.getDefaultConfigs();
|
|
9
|
+
}
|
|
10
|
+
changeUrlIfOld(url) {
|
|
11
|
+
const subgraphUrl = this.subgraphUrlConfigs.find(({ oldUrl }) => url === oldUrl);
|
|
12
|
+
if (subgraphUrl) {
|
|
13
|
+
return subgraphUrl.newUrl;
|
|
14
|
+
}
|
|
15
|
+
return url;
|
|
16
|
+
}
|
|
17
|
+
getArbitrumSubgraphUrl(subgraphId, isDeploymentId) {
|
|
18
|
+
return `https://gateway-arbitrum.network.thegraph.com/api/${this.subgraphStudioKey}/${isDeploymentId ? 'deployments' : 'subgraphs'}/id/${subgraphId}`;
|
|
19
|
+
}
|
|
20
|
+
getDefaultConfigs() {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
chain: 'polygon',
|
|
24
|
+
protocol: 'quickswap',
|
|
25
|
+
newUrl: this.getArbitrumSubgraphUrl(`FqsRcH1XqSjqVx9GRTvEJe959aCbKrcyGgDWBrUkG24g`, false),
|
|
26
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/sameepsi/quickswap-v3',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
chain: 'polygon',
|
|
30
|
+
protocol: 'uniswap',
|
|
31
|
+
newUrl: this.getArbitrumSubgraphUrl(`3hCPRGf4z88VC5rsBKU5AA9FBBq5nF3jbKJG7VZCbhjm`, false),
|
|
32
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
chain: 'optimism',
|
|
36
|
+
protocol: 'uniswap',
|
|
37
|
+
newUrl: this.getArbitrumSubgraphUrl(`Cghf4LfVqPiFw6fp6Y5X5Ubc8UpmUhSfJL82zwiBFLaj`, false),
|
|
38
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/ianlapham/optimism-post-regenesis',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
chain: 'arbitrum',
|
|
42
|
+
protocol: 'uniswap',
|
|
43
|
+
newUrl: this.getArbitrumSubgraphUrl(`FbCGRftH4a3yZugY7TnbYgPJVEv2LvMT6oF1fxPe9aJM`, false),
|
|
44
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-dev',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
chain: 'celo',
|
|
48
|
+
protocol: 'uniswap',
|
|
49
|
+
newUrl: this.getArbitrumSubgraphUrl(`ESdrTJ3twMwWVoQ1hUE2u7PugEHX3QkenudD6aXCkDQ4`, false),
|
|
50
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/jesse-sawa/uniswap-celo',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
chain: 'base',
|
|
54
|
+
protocol: 'baseswap',
|
|
55
|
+
newUrl: 'https://api.goldsky.com/api/public/project_cltceeuudv1ij01x7ekxhfl46/subgraphs/v3-base/prod/gn',
|
|
56
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/harleen-m/basex',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
chain: 'arbitrum',
|
|
60
|
+
protocol: 'sushi',
|
|
61
|
+
newUrl: this.getArbitrumSubgraphUrl('QmevuQAmgiou1UX7Z2BQf6RKdX1WunQjH8VtawhkzSLj4V', true),
|
|
62
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-arbitrum',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
chain: 'avalanche',
|
|
66
|
+
protocol: 'sushi',
|
|
67
|
+
newUrl: this.getArbitrumSubgraphUrl('Qmcdd4SGVwG9VY4itrXBnBPWBVsQvsxfzaib9bVny9C8jT', true),
|
|
68
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-avalanche',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
chain: 'bsc',
|
|
72
|
+
protocol: 'sushi',
|
|
73
|
+
newUrl: this.getArbitrumSubgraphUrl('QmXsPN4TD4PUhT1ZWd5d1mdQPePFNMdJwUr6guSh1z9ZzA', true),
|
|
74
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-bsc',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
chain: 'base',
|
|
78
|
+
protocol: 'sushi',
|
|
79
|
+
newUrl: this.getArbitrumSubgraphUrl('QmZ2R9ABG9ienaZdGyPLcDWDNDkG187RhXmh6fFuEtUaaS', true),
|
|
80
|
+
oldUrl: 'https://api.studio.thegraph.com/query/32073/v3-base/v0.0.1',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
chain: 'optimism',
|
|
84
|
+
protocol: 'sushi',
|
|
85
|
+
newUrl: this.getArbitrumSubgraphUrl('QmbT6ZsxJEZKUrbzLrAWV5EnQfSKZeYtZ265mQUaB552vK', true),
|
|
86
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-optimism',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
chain: 'polygon',
|
|
90
|
+
protocol: 'sushi',
|
|
91
|
+
newUrl: this.getArbitrumSubgraphUrl('QmPbbjK9vtY69kSxMJRVLVz1dRzUBNwYbWTRYMiFzp9Tzm', true),
|
|
92
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/sushi-v3/v3-polygon',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
chain: 'zkevm',
|
|
96
|
+
protocol: 'sushi',
|
|
97
|
+
newUrl: this.getArbitrumSubgraphUrl('QmWH5ChjmF4Yp5Yhiaxczh5QwbG6HFSEi8bRwbKaUrJA6C', true),
|
|
98
|
+
oldUrl: 'https://api.studio.thegraph.com/query/32073/v3-polygon-zkevm/v0.0.2',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
chain: 'arbitrum',
|
|
102
|
+
protocol: 'camelot',
|
|
103
|
+
newUrl: 'https://subgraph-proxy-server-xf2uthetka-as.a.run.app/gateway-arbitrum/3utanEBA9nqMjPnuQP1vMCCys6enSM3EawBpKTVwnUw2',
|
|
104
|
+
oldUrl: 'https://api.thegraph.com/subgraphs/name/camelotlabs/camelot-amm-v3',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
chain: 'mode',
|
|
108
|
+
protocol: 'swapmode',
|
|
109
|
+
newUrl: 'https://api.goldsky.com/api/public/project_cltceeuudv1ij01x7ekxhfl46/subgraphs/swapmode-v3/prod/gn',
|
|
110
|
+
oldUrl: 'https://api.goldsky.com/api/public/project_cltceeuudv1ij01x7ekxhfl46/subgraphs/swapmode-v3/1.0.0/gn',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
chain: 'linea',
|
|
114
|
+
protocol: 'lynex',
|
|
115
|
+
newUrl: 'https://api.goldsky.com/api/public/project_cltyhthusbmxp01s95k9l8a1u/subgraphs/lynex-cl/v1.0.2/gn',
|
|
116
|
+
oldUrl: 'https://graph-query.linea.build/subgraphs/name/cryptoalgebra/analytics',
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.SubgraphUrlReplacer = SubgraphUrlReplacer;
|
|
122
|
+
/**
|
|
123
|
+
* Convenience function that uses the default SubgraphUrlReplacer instance
|
|
124
|
+
* For custom configuration, create a new SubgraphUrlReplacer instance
|
|
125
|
+
*/
|
|
126
|
+
const changeUrlIfOld = (url, subgraphStudioKey) => {
|
|
127
|
+
return new SubgraphUrlReplacer({ subgraphStudioKey }).changeUrlIfOld(url);
|
|
128
|
+
};
|
|
129
|
+
exports.changeUrlIfOld = changeUrlIfOld;
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Candle } from '@steerprotocol/app-loader';
|
|
2
|
-
import { AxiosRequestConfig } from 'axios';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export declare const extendOHLCV: (rawData: Candle
|
|
1
|
+
import type { Candle } from '@steerprotocol/app-loader';
|
|
2
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { type Provider } from 'ethers';
|
|
4
|
+
import type { ExecutionContext, ViewContractConfig } from '../types.js';
|
|
5
|
+
export declare const extendOHLCV: (rawData: Array<Candle>, period: number, endTimestamp: number) => Array<Candle>;
|
|
6
6
|
export declare function fetchData(request: AxiosRequestConfig, attempts: number): Promise<any>;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function readContract({ abi, address, chainId, contractArguments, currentExecutionContext, functionName, provider, rpc, }: {
|
|
8
8
|
address: string;
|
|
9
9
|
abi: any;
|
|
10
10
|
currentExecutionContext: ExecutionContext;
|
|
11
11
|
functionName: string;
|
|
12
12
|
provider: Provider;
|
|
13
13
|
rpc: string;
|
|
14
|
+
contractArguments?: Array<any>;
|
|
14
15
|
chainId: number;
|
|
15
16
|
}): Promise<any>;
|
|
16
17
|
export declare function callWithRetry(config: ViewContractConfig): Promise<any>;
|
package/lib/utils/utils.js
CHANGED
|
@@ -12,10 +12,10 @@ 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.callWithRetry = exports.
|
|
15
|
+
exports.callWithRetry = exports.readContract = exports.fetchData = exports.extendOHLCV = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const ethers_1 = require("ethers");
|
|
18
|
-
const
|
|
18
|
+
const consts_js_1 = require("./consts.js");
|
|
19
19
|
// The purpose of this function is to look at the end timestamp and extend the current candle array so that it backfills any missing candles up to the end timestamp
|
|
20
20
|
const extendOHLCV = (rawData, period, endTimestamp) => {
|
|
21
21
|
// Sort rawData by timestamp
|
|
@@ -82,31 +82,31 @@ function fetchData(request, attempts) {
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
exports.fetchData = fetchData;
|
|
85
|
-
function
|
|
85
|
+
function readContract({ abi, address, chainId, contractArguments = [], currentExecutionContext, functionName, provider, rpc, }) {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
87
|
// Create a new contract instance
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
88
|
if (!provider)
|
|
90
89
|
throw new Error('Provider not initialized');
|
|
91
90
|
const contract = new ethers_1.Contract(address, abi, provider);
|
|
92
91
|
// For formatting the parameters if needed
|
|
93
|
-
const paramsArray = [];
|
|
92
|
+
const paramsArray = contractArguments || [];
|
|
94
93
|
// Calculate block number for determinism
|
|
95
94
|
// Best way to handle contextually non-null values?
|
|
96
95
|
// const syncedBlock = await getBlockFromTimestamp(this.executionContext!.epochTimestamp, this.providerIdentity!) //@note uncomment for deterministic blocks
|
|
97
96
|
// Call the desired method with the specified arguments at synced block
|
|
98
97
|
// , {blockTag: syncedBlock}
|
|
99
98
|
let result;
|
|
100
|
-
if (
|
|
99
|
+
if (consts_js_1.CENTRALIZE_CONTRACT_INTERACTION_CHAINS.indexOf(chainId.toString()) === -1) {
|
|
101
100
|
result = yield contract[functionName](...paramsArray, {
|
|
102
101
|
blockTag: currentExecutionContext === null || currentExecutionContext === void 0 ? void 0 : currentExecutionContext.blockNumber,
|
|
103
|
-
});
|
|
102
|
+
}); // @note uncomment for deterministic blocks
|
|
104
103
|
}
|
|
105
104
|
else {
|
|
105
|
+
console.log('Calling the centralized view');
|
|
106
106
|
const viewContractConfig = {
|
|
107
107
|
epochTimestamp: currentExecutionContext.epochTimestamp,
|
|
108
|
-
address
|
|
109
|
-
abi
|
|
108
|
+
address,
|
|
109
|
+
abi,
|
|
110
110
|
arguments: paramsArray,
|
|
111
111
|
method: functionName,
|
|
112
112
|
rpcUrl: rpc,
|
|
@@ -117,28 +117,27 @@ function readSlot0Contract({ address, abi, currentExecutionContext, functionName
|
|
|
117
117
|
return result;
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
exports.
|
|
120
|
+
exports.readContract = readContract;
|
|
121
121
|
function callWithRetry(config) {
|
|
122
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
123
|
let retries = 0;
|
|
124
|
-
let delay =
|
|
125
|
-
while (retries <
|
|
124
|
+
let delay = consts_js_1.API_INITIAL_DELAY;
|
|
125
|
+
while (retries < consts_js_1.API_MAX_RETRIES) {
|
|
126
126
|
try {
|
|
127
|
-
const response = yield axios_1.default.post(
|
|
127
|
+
const response = yield axios_1.default.post(consts_js_1.API_BASE_URL, config);
|
|
128
128
|
return JSON.parse(response.data); // Return the data if the call was successful
|
|
129
129
|
}
|
|
130
130
|
catch (error) {
|
|
131
|
-
console.error(`Attempt ${retries + 1} failed. Retrying in to fetch the contract method ${config.method} ${delay / 1000} seconds
|
|
131
|
+
console.error(`Attempt ${retries + 1} failed. Retrying in to fetch the contract method ${config.method} ${delay / 1000} seconds...`, error);
|
|
132
132
|
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
133
133
|
delay *= 2; // Double the delay for the next retry
|
|
134
134
|
retries++;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
throw new Error(`Failed after ${
|
|
137
|
+
throw new Error(`Failed after ${consts_js_1.API_MAX_RETRIES} attempts. to call method ${config.method}`);
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
exports.callWithRetry = callWithRetry;
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
141
|
function log(...args) {
|
|
143
142
|
if (process.env.DEBUG === 'true') {
|
|
144
143
|
console.log(...args);
|