@steerprotocol/data-connector-loader 5.0.0-next.2 → 5.0.0-next.4
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 +74 -0
- package/lib/bundle/bundleBase.d.ts +11 -14
- package/lib/bundle/bundleBase.js +56 -88
- package/lib/bundle/bundleDataConnector.d.ts +2 -6
- package/lib/bundle/bundleDataConnector.js +22 -47
- package/lib/esm/bundle/bundleBase.d.ts +11 -14
- package/lib/esm/bundle/bundleBase.js +77 -91
- package/lib/esm/bundle/bundleDataConnector.d.ts +2 -6
- package/lib/esm/bundle/bundleDataConnector.js +26 -49
- package/lib/esm/execution/executionApp.d.ts +5 -6
- package/lib/esm/execution/executionApp.js +335 -309
- package/lib/esm/execution/executionBase.d.ts +7 -7
- package/lib/esm/execution/executionBase.js +27 -13
- package/lib/esm/execution/executionDataConnector.d.ts +6 -3
- package/lib/esm/execution/executionDataConnector.js +114 -68
- package/lib/esm/index.d.ts +7 -7
- package/lib/esm/index.js +4 -4
- package/lib/esm/types.d.ts +20 -24
- package/lib/esm/types.js +5 -5
- package/lib/esm/utils/blockFinder.d.ts +2 -2
- package/lib/esm/utils/blockFinder.js +3 -3
- package/lib/esm/utils/consts.js +39 -39
- package/lib/esm/utils/pluginManager.d.ts +1 -1
- package/lib/esm/utils/pluginManager.js +6 -5
- package/lib/esm/utils/replace-old-subgraphs.js +61 -61
- package/lib/esm/utils/rpc.d.ts +4 -0
- package/lib/esm/utils/rpc.js +32 -0
- package/lib/esm/utils/utils.d.ts +8 -11
- package/lib/esm/utils/utils.js +61 -55
- package/lib/execution/executionApp.d.ts +5 -6
- package/lib/execution/executionApp.js +323 -302
- package/lib/execution/executionBase.d.ts +7 -7
- package/lib/execution/executionBase.js +27 -13
- package/lib/execution/executionDataConnector.d.ts +6 -3
- package/lib/execution/executionDataConnector.js +116 -63
- package/lib/index.d.ts +7 -7
- package/lib/index.js +1 -1
- package/lib/types.d.ts +20 -24
- package/lib/types.js +5 -5
- package/lib/utils/blockFinder.d.ts +2 -2
- package/lib/utils/blockFinder.js +3 -3
- package/lib/utils/consts.js +39 -39
- package/lib/utils/pluginManager.d.ts +1 -1
- package/lib/utils/pluginManager.js +5 -4
- package/lib/utils/replace-old-subgraphs.js +61 -61
- package/lib/utils/rpc.d.ts +4 -0
- package/lib/utils/rpc.js +47 -0
- package/lib/utils/utils.d.ts +8 -11
- package/lib/utils/utils.js +55 -60
- package/package.json +14 -13
package/lib/utils/consts.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
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 =
|
|
4
|
+
exports.API_BASE_URL = "https://cvrlulno2m.execute-api.ap-southeast-1.amazonaws.com/dev/contract-view-call";
|
|
5
5
|
// export const API_BASE_URL = "http://localhost:3000/dev/contract-view-call";
|
|
6
6
|
exports.API_MAX_RETRIES = 3;
|
|
7
7
|
exports.API_INITIAL_DELAY = 1000;
|
|
8
8
|
exports.CENTRALIZE_CONTRACT_INTERACTION_CHAINS = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
38
|
// "8453",
|
|
39
|
-
|
|
39
|
+
"30",
|
|
40
40
|
// "8453",
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
"167000",
|
|
42
|
+
"196",
|
|
43
|
+
"810180",
|
|
44
|
+
"137",
|
|
45
|
+
"314",
|
|
46
|
+
"33139",
|
|
47
|
+
"7000",
|
|
48
|
+
"3338",
|
|
49
49
|
];
|
|
@@ -20,7 +20,7 @@ class PluginManager {
|
|
|
20
20
|
}
|
|
21
21
|
registerFromPublicConfig() {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const { data: dataConnectorPlugins } = yield axios_1.default.get(
|
|
23
|
+
const { data: dataConnectorPlugins } = yield axios_1.default.get("https://ro81h8hq6b.execute-api.us-east-1.amazonaws.com/data-connector-plugins");
|
|
24
24
|
for (const plugin of dataConnectorPlugins) {
|
|
25
25
|
this.registerPluginConfig(plugin.name, plugin.domain, plugin.headers);
|
|
26
26
|
}
|
|
@@ -43,7 +43,7 @@ class PluginManager {
|
|
|
43
43
|
const envValue = process.env[envVar];
|
|
44
44
|
if (envValue === undefined) {
|
|
45
45
|
console.log(`Environment variable '${envVar}' not found.`);
|
|
46
|
-
return
|
|
46
|
+
return "";
|
|
47
47
|
}
|
|
48
48
|
return envValue;
|
|
49
49
|
});
|
|
@@ -51,14 +51,15 @@ class PluginManager {
|
|
|
51
51
|
interpolateHeaders(headers) {
|
|
52
52
|
const interpolatedHeaders = {};
|
|
53
53
|
for (const [key, value] of Object.entries(headers)) {
|
|
54
|
-
interpolatedHeaders[key] =
|
|
54
|
+
interpolatedHeaders[key] =
|
|
55
|
+
typeof value === "string" ? this.interpolateEnvVars(value) : value;
|
|
55
56
|
}
|
|
56
57
|
return interpolatedHeaders;
|
|
57
58
|
}
|
|
58
59
|
process(config) {
|
|
59
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
61
|
if (!config.url) {
|
|
61
|
-
throw new Error(
|
|
62
|
+
throw new Error("Request URL is not provided");
|
|
62
63
|
}
|
|
63
64
|
const matchingHeaders = this.findMatchingPluginConfigs(config.url);
|
|
64
65
|
const interpolatedHeaders = this.interpolateHeaders(matchingHeaders);
|
|
@@ -4,7 +4,7 @@ exports.changeUrlIfOld = exports.SubgraphUrlReplacer = void 0;
|
|
|
4
4
|
class SubgraphUrlReplacer {
|
|
5
5
|
constructor(config) {
|
|
6
6
|
var _a;
|
|
7
|
-
this.subgraphStudioKey = (_a = config === null || config === void 0 ? void 0 : config.subgraphStudioKey) !== null && _a !== void 0 ? _a :
|
|
7
|
+
this.subgraphStudioKey = (_a = config === null || config === void 0 ? void 0 : config.subgraphStudioKey) !== null && _a !== void 0 ? _a : "";
|
|
8
8
|
this.subgraphUrlConfigs = (config === null || config === void 0 ? void 0 : config.customConfigs) || this.getDefaultConfigs();
|
|
9
9
|
}
|
|
10
10
|
changeUrlIfOld(url) {
|
|
@@ -15,105 +15,105 @@ class SubgraphUrlReplacer {
|
|
|
15
15
|
return url;
|
|
16
16
|
}
|
|
17
17
|
getArbitrumSubgraphUrl(subgraphId, isDeploymentId) {
|
|
18
|
-
return `https://gateway-arbitrum.network.thegraph.com/api/${this.subgraphStudioKey}/${isDeploymentId ?
|
|
18
|
+
return `https://gateway-arbitrum.network.thegraph.com/api/${this.subgraphStudioKey}/${isDeploymentId ? "deployments" : "subgraphs"}/id/${subgraphId}`;
|
|
19
19
|
}
|
|
20
20
|
getDefaultConfigs() {
|
|
21
21
|
return [
|
|
22
22
|
{
|
|
23
|
-
chain:
|
|
24
|
-
protocol:
|
|
23
|
+
chain: "polygon",
|
|
24
|
+
protocol: "quickswap",
|
|
25
25
|
newUrl: this.getArbitrumSubgraphUrl(`FqsRcH1XqSjqVx9GRTvEJe959aCbKrcyGgDWBrUkG24g`, false),
|
|
26
|
-
oldUrl:
|
|
26
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/sameepsi/quickswap-v3",
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
chain:
|
|
30
|
-
protocol:
|
|
29
|
+
chain: "polygon",
|
|
30
|
+
protocol: "uniswap",
|
|
31
31
|
newUrl: this.getArbitrumSubgraphUrl(`3hCPRGf4z88VC5rsBKU5AA9FBBq5nF3jbKJG7VZCbhjm`, false),
|
|
32
|
-
oldUrl:
|
|
32
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon",
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
chain:
|
|
36
|
-
protocol:
|
|
35
|
+
chain: "optimism",
|
|
36
|
+
protocol: "uniswap",
|
|
37
37
|
newUrl: this.getArbitrumSubgraphUrl(`Cghf4LfVqPiFw6fp6Y5X5Ubc8UpmUhSfJL82zwiBFLaj`, false),
|
|
38
|
-
oldUrl:
|
|
38
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/ianlapham/optimism-post-regenesis",
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
chain:
|
|
42
|
-
protocol:
|
|
41
|
+
chain: "arbitrum",
|
|
42
|
+
protocol: "uniswap",
|
|
43
43
|
newUrl: this.getArbitrumSubgraphUrl(`FbCGRftH4a3yZugY7TnbYgPJVEv2LvMT6oF1fxPe9aJM`, false),
|
|
44
|
-
oldUrl:
|
|
44
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-dev",
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
|
-
chain:
|
|
48
|
-
protocol:
|
|
47
|
+
chain: "celo",
|
|
48
|
+
protocol: "uniswap",
|
|
49
49
|
newUrl: this.getArbitrumSubgraphUrl(`ESdrTJ3twMwWVoQ1hUE2u7PugEHX3QkenudD6aXCkDQ4`, false),
|
|
50
|
-
oldUrl:
|
|
50
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/jesse-sawa/uniswap-celo",
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
|
-
chain:
|
|
54
|
-
protocol:
|
|
55
|
-
newUrl:
|
|
56
|
-
oldUrl:
|
|
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
57
|
},
|
|
58
58
|
{
|
|
59
|
-
chain:
|
|
60
|
-
protocol:
|
|
61
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
62
|
-
oldUrl:
|
|
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
63
|
},
|
|
64
64
|
{
|
|
65
|
-
chain:
|
|
66
|
-
protocol:
|
|
67
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
68
|
-
oldUrl:
|
|
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
69
|
},
|
|
70
70
|
{
|
|
71
|
-
chain:
|
|
72
|
-
protocol:
|
|
73
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
74
|
-
oldUrl:
|
|
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
75
|
},
|
|
76
76
|
{
|
|
77
|
-
chain:
|
|
78
|
-
protocol:
|
|
79
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
80
|
-
oldUrl:
|
|
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
81
|
},
|
|
82
82
|
{
|
|
83
|
-
chain:
|
|
84
|
-
protocol:
|
|
85
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
86
|
-
oldUrl:
|
|
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
87
|
},
|
|
88
88
|
{
|
|
89
|
-
chain:
|
|
90
|
-
protocol:
|
|
91
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
92
|
-
oldUrl:
|
|
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
93
|
},
|
|
94
94
|
{
|
|
95
|
-
chain:
|
|
96
|
-
protocol:
|
|
97
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
98
|
-
oldUrl:
|
|
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
99
|
},
|
|
100
100
|
{
|
|
101
|
-
chain:
|
|
102
|
-
protocol:
|
|
103
|
-
newUrl:
|
|
104
|
-
oldUrl:
|
|
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
105
|
},
|
|
106
106
|
{
|
|
107
|
-
chain:
|
|
108
|
-
protocol:
|
|
109
|
-
newUrl:
|
|
110
|
-
oldUrl:
|
|
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
111
|
},
|
|
112
112
|
{
|
|
113
|
-
chain:
|
|
114
|
-
protocol:
|
|
115
|
-
newUrl:
|
|
116
|
-
oldUrl:
|
|
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
117
|
},
|
|
118
118
|
];
|
|
119
119
|
}
|
package/lib/utils/rpc.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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.createRpcClient = void 0;
|
|
13
|
+
const viem_1 = require("viem");
|
|
14
|
+
/** Each URL is checked on the same transport that will serve its reads. */
|
|
15
|
+
function createRpcClient(access, chainId) {
|
|
16
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0)
|
|
17
|
+
throw new Error("Invalid execution chain ID");
|
|
18
|
+
if (access.client)
|
|
19
|
+
return access.client;
|
|
20
|
+
const urls = [
|
|
21
|
+
...new Set(access.urls.map((url) => url.trim()).filter(Boolean)),
|
|
22
|
+
];
|
|
23
|
+
if (!urls.length)
|
|
24
|
+
throw new Error("No RPC URLs configured");
|
|
25
|
+
const transports = urls.map((url) => {
|
|
26
|
+
const endpoint = (0, viem_1.createPublicClient)({
|
|
27
|
+
transport: (0, viem_1.http)(url, { retryCount: 0 }),
|
|
28
|
+
});
|
|
29
|
+
return (0, viem_1.custom)({
|
|
30
|
+
request({ method, params }) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const actualChain = yield endpoint.getChainId();
|
|
33
|
+
if (actualChain !== chainId) {
|
|
34
|
+
throw new Error("EXECUTION_CONTEXT_MISMATCH: provider chain does not match supplied context.");
|
|
35
|
+
}
|
|
36
|
+
if (method === "eth_chainId")
|
|
37
|
+
return `0x${actualChain.toString(16)}`;
|
|
38
|
+
return endpoint.request({ method, params });
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
}, { retryCount: 0 });
|
|
42
|
+
});
|
|
43
|
+
return (0, viem_1.createPublicClient)({
|
|
44
|
+
transport: (0, viem_1.fallback)(transports, { rank: false, retryCount: 0 }),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.createRpcClient = createRpcClient;
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import type { Candle } from
|
|
2
|
-
import type { AxiosRequestConfig } from
|
|
3
|
-
import { type
|
|
4
|
-
import type {
|
|
1
|
+
import type { Candle } from "@steerprotocol/app-loader";
|
|
2
|
+
import type { AxiosRequestConfig } from "axios";
|
|
3
|
+
import { type PublicClient } from "viem";
|
|
4
|
+
import type { ContractAbi, ExecutionContext } from "../types.js";
|
|
5
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 readContract({ abi, address,
|
|
7
|
+
export declare function readContract({ abi, address, contractArguments, currentExecutionContext, functionName, provider, }: {
|
|
8
8
|
address: string;
|
|
9
|
-
abi:
|
|
10
|
-
currentExecutionContext
|
|
9
|
+
abi: ContractAbi;
|
|
10
|
+
currentExecutionContext?: Pick<ExecutionContext, "blockNumber">;
|
|
11
11
|
functionName: string;
|
|
12
|
-
provider:
|
|
13
|
-
rpc: string;
|
|
12
|
+
provider: PublicClient;
|
|
14
13
|
contractArguments?: Array<any>;
|
|
15
|
-
chainId: number;
|
|
16
14
|
}): Promise<any>;
|
|
17
|
-
export declare function callWithRetry(config: ViewContractConfig): Promise<any>;
|
package/lib/utils/utils.js
CHANGED
|
@@ -12,10 +12,9 @@ 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.
|
|
15
|
+
exports.readContract = exports.fetchData = exports.extendOHLCV = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const
|
|
18
|
-
const consts_js_1 = require("./consts.js");
|
|
17
|
+
const viem_1 = require("viem");
|
|
19
18
|
// 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
19
|
const extendOHLCV = (rawData, period, endTimestamp) => {
|
|
21
20
|
// Sort rawData by timestamp
|
|
@@ -49,23 +48,26 @@ function delay(ms) {
|
|
|
49
48
|
function exponentialBackoffDelay(attempts) {
|
|
50
49
|
const baseDelay = 1000; // 1 second
|
|
51
50
|
const maxDelay = 30000; // 30 seconds
|
|
52
|
-
const delay = Math.min(baseDelay * Math.pow(2, attempts - 1), maxDelay);
|
|
51
|
+
const delay = Math.min(baseDelay * Math.pow(2, (attempts - 1)), maxDelay);
|
|
53
52
|
return delay;
|
|
54
53
|
}
|
|
55
54
|
function fetchData(request, attempts) {
|
|
56
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
log(
|
|
56
|
+
log("Request payload: =============", request);
|
|
58
57
|
attempts = attempts + 1;
|
|
59
58
|
try {
|
|
60
59
|
const response = (yield (0, axios_1.default)(request)).data;
|
|
61
60
|
// this.log('API Response: =============', response);
|
|
62
|
-
if (
|
|
61
|
+
if (response !== null &&
|
|
62
|
+
typeof response === "object" &&
|
|
63
|
+
Array.isArray(response.errors) &&
|
|
64
|
+
response.errors.length > 0) {
|
|
63
65
|
if (attempts < 3) {
|
|
64
66
|
yield delay(exponentialBackoffDelay(attempts));
|
|
65
67
|
return yield fetchData(request, attempts);
|
|
66
68
|
}
|
|
67
69
|
else {
|
|
68
|
-
throw new Error(
|
|
70
|
+
throw new Error("Maximum retry attempts reached");
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
return response;
|
|
@@ -82,65 +84,58 @@ function fetchData(request, attempts) {
|
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
86
|
exports.fetchData = fetchData;
|
|
85
|
-
function
|
|
87
|
+
function positionalTuple(value, parameter) {
|
|
88
|
+
if (/\[[0-9]*\]$/.test(parameter.type)) {
|
|
89
|
+
const item = Object.assign(Object.assign({}, parameter), { type: parameter.type.replace(/\[[0-9]*\]$/, "") });
|
|
90
|
+
return value.map((entry) => positionalTuple(entry, item));
|
|
91
|
+
}
|
|
92
|
+
if (parameter.type !== "tuple" || !("components" in parameter))
|
|
93
|
+
return value;
|
|
94
|
+
return parameter.components.map((component, index) => positionalTuple(Array.isArray(value) ? value[index] : value[component.name], component));
|
|
95
|
+
}
|
|
96
|
+
function readContract({ abi, address, contractArguments = [], currentExecutionContext, functionName, provider, }) {
|
|
97
|
+
var _a;
|
|
86
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
// Create a new contract instance
|
|
88
99
|
if (!provider)
|
|
89
|
-
throw new Error(
|
|
90
|
-
const
|
|
91
|
-
//
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
100
|
+
throw new Error("Provider not initialized");
|
|
101
|
+
const input = typeof abi === "string" ? JSON.parse(abi) : abi;
|
|
102
|
+
// Existing bundles may use ethers' optional tuple keyword.
|
|
103
|
+
const normalizeSignature = (signature) => signature.replace(/\btuple\s*\(/g, "(");
|
|
104
|
+
const normalizedAbi = (input.every((item) => typeof item === "string")
|
|
105
|
+
? (0, viem_1.parseAbi)(input.map(normalizeSignature))
|
|
106
|
+
: input);
|
|
107
|
+
const explicit = functionName.includes("(")
|
|
108
|
+
? (0, viem_1.parseAbiItem)(`function ${normalizeSignature(functionName)}`)
|
|
109
|
+
: undefined;
|
|
110
|
+
if (explicit && explicit.type !== "function")
|
|
111
|
+
throw new Error("Expected a function signature");
|
|
112
|
+
const selectedAbi = explicit
|
|
113
|
+
? normalizedAbi.filter((item) => item.type === "function" &&
|
|
114
|
+
(0, viem_1.toFunctionSelector)(item) === (0, viem_1.toFunctionSelector)(explicit))
|
|
115
|
+
: normalizedAbi;
|
|
116
|
+
if (explicit && !selectedAbi.length)
|
|
117
|
+
throw new Error(`Function ${functionName} not found in ABI`);
|
|
118
|
+
const resolvedName = explicit && "name" in explicit ? explicit.name : functionName;
|
|
119
|
+
const result = yield provider.readContract(Object.assign({ address: address, abi: selectedAbi, functionName: resolvedName, args: contractArguments }, ((currentExecutionContext === null || currentExecutionContext === void 0 ? void 0 : currentExecutionContext.blockNumber) !== undefined
|
|
120
|
+
? { blockNumber: BigInt(currentExecutionContext.blockNumber) }
|
|
121
|
+
: {})));
|
|
122
|
+
const item = (0, viem_1.getAbiItem)({
|
|
123
|
+
abi: selectedAbi,
|
|
124
|
+
name: resolvedName,
|
|
125
|
+
args: contractArguments,
|
|
126
|
+
});
|
|
127
|
+
if (!item || item.type !== "function")
|
|
128
|
+
return result;
|
|
129
|
+
if (!((_a = item.outputs) === null || _a === void 0 ? void 0 : _a.length))
|
|
130
|
+
return [];
|
|
131
|
+
return item.outputs.length === 1
|
|
132
|
+
? positionalTuple(result, item.outputs[0])
|
|
133
|
+
: item.outputs.map((output, index) => positionalTuple(result[index], output));
|
|
119
134
|
});
|
|
120
135
|
}
|
|
121
136
|
exports.readContract = readContract;
|
|
122
|
-
function callWithRetry(config) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
let retries = 0;
|
|
125
|
-
let delay = consts_js_1.API_INITIAL_DELAY;
|
|
126
|
-
while (retries < consts_js_1.API_MAX_RETRIES) {
|
|
127
|
-
try {
|
|
128
|
-
const response = yield axios_1.default.post(consts_js_1.API_BASE_URL, config);
|
|
129
|
-
return JSON.parse(response.data); // Return the data if the call was successful
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
console.error(`Attempt ${retries + 1} failed. Retrying in to fetch the contract method ${config.method} ${delay / 1000} seconds...`, error);
|
|
133
|
-
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
134
|
-
delay *= 2; // Double the delay for the next retry
|
|
135
|
-
retries++;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
throw new Error(`Failed after ${consts_js_1.API_MAX_RETRIES} attempts. to call method ${config.method}`);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
exports.callWithRetry = callWithRetry;
|
|
142
137
|
function log(...args) {
|
|
143
|
-
if (process.env.DEBUG ===
|
|
138
|
+
if (process.env.DEBUG === "true") {
|
|
144
139
|
console.log(...args);
|
|
145
140
|
}
|
|
146
141
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/data-connector-loader",
|
|
3
|
-
"version": "5.0.0-next.
|
|
3
|
+
"version": "5.0.0-next.4",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -18,19 +18,23 @@
|
|
|
18
18
|
"build": "npm run build:cjs && npm run build:esm",
|
|
19
19
|
"build:cjs": "tsc -p tsconfig.json && echo '{\"type\": \"commonjs\"}' > lib/package.json",
|
|
20
20
|
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > lib/esm/package.json",
|
|
21
|
-
"format": "
|
|
22
|
-
"lint": "
|
|
21
|
+
"format": "biome format --write .",
|
|
22
|
+
"lint": "biome lint .",
|
|
23
23
|
"lint:commit": "commitlint --from=HEAD~1 --to=HEAD",
|
|
24
|
-
"lint:fix": "
|
|
24
|
+
"lint:fix": "biome lint --write .",
|
|
25
25
|
"test": "jest --config jest.config.cjs",
|
|
26
26
|
"pack:local": "npm pack",
|
|
27
27
|
"test:packed-consumer": "node scripts/packed-consumer-smoke.cjs",
|
|
28
28
|
"publish:test": "node scripts/publish-test.cjs",
|
|
29
29
|
"prepare": "husky && npm run build",
|
|
30
|
-
"prepublishOnly": "npm
|
|
30
|
+
"prepublishOnly": "npm run check:code && npm test",
|
|
31
31
|
"preversion": "npm run lint",
|
|
32
32
|
"version": "npm run format && git add -A src",
|
|
33
|
-
"postversion": "git push && git push --tags"
|
|
33
|
+
"postversion": "git push && git push --tags",
|
|
34
|
+
"format:check": "biome format .",
|
|
35
|
+
"check": "npm run check:code && npm run build && npm test -- --runInBand",
|
|
36
|
+
"check:code": "biome ci .",
|
|
37
|
+
"fix": "biome check --write ."
|
|
34
38
|
},
|
|
35
39
|
"repository": {
|
|
36
40
|
"type": "git",
|
|
@@ -79,6 +83,7 @@
|
|
|
79
83
|
]
|
|
80
84
|
},
|
|
81
85
|
"devDependencies": {
|
|
86
|
+
"@biomejs/biome": "2.6.6",
|
|
82
87
|
"@commitlint/cli": "^20.5.0",
|
|
83
88
|
"@commitlint/config-conventional": "^20.5.0",
|
|
84
89
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
@@ -86,13 +91,9 @@
|
|
|
86
91
|
"@semantic-release/npm": "^13.1.5",
|
|
87
92
|
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
88
93
|
"@types/jest": "29.2.4",
|
|
89
|
-
"
|
|
90
|
-
"@typescript-eslint/parser": "5.47.1",
|
|
91
|
-
"eslint": "8.30.0",
|
|
92
|
-
"eslint-plugin-jest": "27.1.7",
|
|
94
|
+
"ethers": "^6.16.0",
|
|
93
95
|
"husky": "^9.1.7",
|
|
94
96
|
"jest": "29.3.1",
|
|
95
|
-
"prettier": "2.8.1",
|
|
96
97
|
"semantic-release": "^25.0.3",
|
|
97
98
|
"ts-jest": "29.0.3",
|
|
98
99
|
"typescript": "5.0.4"
|
|
@@ -104,7 +105,7 @@
|
|
|
104
105
|
"@steerprotocol/app-loader": "^3.0.6",
|
|
105
106
|
"@steerprotocol/strategy-utils": "^3.1.2",
|
|
106
107
|
"axios": "^1.3.4",
|
|
107
|
-
"
|
|
108
|
-
"
|
|
108
|
+
"timestring": "^7.0.0",
|
|
109
|
+
"viem": "^2.57.16"
|
|
109
110
|
}
|
|
110
111
|
}
|