@steerprotocol/data-connector-loader 5.0.0-next.2 → 5.0.0-next.3
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 +44 -84
- 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 +65 -89
- 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/esm/utils/consts.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
export const API_BASE_URL =
|
|
1
|
+
export const API_BASE_URL = "https://cvrlulno2m.execute-api.ap-southeast-1.amazonaws.com/dev/contract-view-call";
|
|
2
2
|
// export const API_BASE_URL = "http://localhost:3000/dev/contract-view-call";
|
|
3
3
|
export const API_MAX_RETRIES = 3;
|
|
4
4
|
export const API_INITIAL_DELAY = 1000;
|
|
5
5
|
export const CENTRALIZE_CONTRACT_INTERACTION_CHAINS = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
6
|
+
"999",
|
|
7
|
+
"43114",
|
|
8
|
+
"6900",
|
|
9
|
+
"5464",
|
|
10
|
+
"2020",
|
|
11
|
+
"747474",
|
|
12
|
+
"1116",
|
|
13
|
+
"43111",
|
|
14
|
+
"80094",
|
|
15
|
+
"129399",
|
|
16
|
+
"130",
|
|
17
|
+
"146",
|
|
18
|
+
"1868",
|
|
19
|
+
"1",
|
|
20
|
+
"80084",
|
|
21
|
+
"2222",
|
|
22
|
+
"1329",
|
|
23
|
+
"1284",
|
|
24
|
+
"42161",
|
|
25
|
+
"9001",
|
|
26
|
+
"137",
|
|
27
|
+
"56",
|
|
28
|
+
"5000",
|
|
29
|
+
"250",
|
|
30
|
+
"3776",
|
|
31
|
+
"81457",
|
|
32
|
+
"592",
|
|
33
|
+
"1088",
|
|
34
|
+
"34443",
|
|
35
35
|
// "8453",
|
|
36
|
-
|
|
36
|
+
"30",
|
|
37
37
|
// "8453",
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
"167000",
|
|
39
|
+
"196",
|
|
40
|
+
"810180",
|
|
41
|
+
"137",
|
|
42
|
+
"314",
|
|
43
|
+
"33139",
|
|
44
|
+
"7000",
|
|
45
|
+
"3338",
|
|
46
46
|
];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import axios from
|
|
1
|
+
import axios from "axios";
|
|
2
2
|
export class PluginManager {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.registeredPluginConfigs = [];
|
|
5
5
|
}
|
|
6
6
|
async registerFromPublicConfig() {
|
|
7
|
-
const { data: dataConnectorPlugins } = await axios.get(
|
|
7
|
+
const { data: dataConnectorPlugins } = await axios.get("https://ro81h8hq6b.execute-api.us-east-1.amazonaws.com/data-connector-plugins");
|
|
8
8
|
for (const plugin of dataConnectorPlugins) {
|
|
9
9
|
this.registerPluginConfig(plugin.name, plugin.domain, plugin.headers);
|
|
10
10
|
}
|
|
@@ -26,7 +26,7 @@ export class PluginManager {
|
|
|
26
26
|
const envValue = process.env[envVar];
|
|
27
27
|
if (envValue === undefined) {
|
|
28
28
|
console.log(`Environment variable '${envVar}' not found.`);
|
|
29
|
-
return
|
|
29
|
+
return "";
|
|
30
30
|
}
|
|
31
31
|
return envValue;
|
|
32
32
|
});
|
|
@@ -34,13 +34,14 @@ export class PluginManager {
|
|
|
34
34
|
interpolateHeaders(headers) {
|
|
35
35
|
const interpolatedHeaders = {};
|
|
36
36
|
for (const [key, value] of Object.entries(headers)) {
|
|
37
|
-
interpolatedHeaders[key] =
|
|
37
|
+
interpolatedHeaders[key] =
|
|
38
|
+
typeof value === "string" ? this.interpolateEnvVars(value) : value;
|
|
38
39
|
}
|
|
39
40
|
return interpolatedHeaders;
|
|
40
41
|
}
|
|
41
42
|
async process(config) {
|
|
42
43
|
if (!config.url) {
|
|
43
|
-
throw new Error(
|
|
44
|
+
throw new Error("Request URL is not provided");
|
|
44
45
|
}
|
|
45
46
|
const matchingHeaders = this.findMatchingPluginConfigs(config.url);
|
|
46
47
|
const interpolatedHeaders = this.interpolateHeaders(matchingHeaders);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export class SubgraphUrlReplacer {
|
|
2
2
|
constructor(config) {
|
|
3
|
-
this.subgraphStudioKey = config?.subgraphStudioKey ??
|
|
3
|
+
this.subgraphStudioKey = config?.subgraphStudioKey ?? "";
|
|
4
4
|
this.subgraphUrlConfigs = config?.customConfigs || this.getDefaultConfigs();
|
|
5
5
|
}
|
|
6
6
|
changeUrlIfOld(url) {
|
|
@@ -11,105 +11,105 @@ export class SubgraphUrlReplacer {
|
|
|
11
11
|
return url;
|
|
12
12
|
}
|
|
13
13
|
getArbitrumSubgraphUrl(subgraphId, isDeploymentId) {
|
|
14
|
-
return `https://gateway-arbitrum.network.thegraph.com/api/${this.subgraphStudioKey}/${isDeploymentId ?
|
|
14
|
+
return `https://gateway-arbitrum.network.thegraph.com/api/${this.subgraphStudioKey}/${isDeploymentId ? "deployments" : "subgraphs"}/id/${subgraphId}`;
|
|
15
15
|
}
|
|
16
16
|
getDefaultConfigs() {
|
|
17
17
|
return [
|
|
18
18
|
{
|
|
19
|
-
chain:
|
|
20
|
-
protocol:
|
|
19
|
+
chain: "polygon",
|
|
20
|
+
protocol: "quickswap",
|
|
21
21
|
newUrl: this.getArbitrumSubgraphUrl(`FqsRcH1XqSjqVx9GRTvEJe959aCbKrcyGgDWBrUkG24g`, false),
|
|
22
|
-
oldUrl:
|
|
22
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/sameepsi/quickswap-v3",
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
chain:
|
|
26
|
-
protocol:
|
|
25
|
+
chain: "polygon",
|
|
26
|
+
protocol: "uniswap",
|
|
27
27
|
newUrl: this.getArbitrumSubgraphUrl(`3hCPRGf4z88VC5rsBKU5AA9FBBq5nF3jbKJG7VZCbhjm`, false),
|
|
28
|
-
oldUrl:
|
|
28
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon",
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
chain:
|
|
32
|
-
protocol:
|
|
31
|
+
chain: "optimism",
|
|
32
|
+
protocol: "uniswap",
|
|
33
33
|
newUrl: this.getArbitrumSubgraphUrl(`Cghf4LfVqPiFw6fp6Y5X5Ubc8UpmUhSfJL82zwiBFLaj`, false),
|
|
34
|
-
oldUrl:
|
|
34
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/ianlapham/optimism-post-regenesis",
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
chain:
|
|
38
|
-
protocol:
|
|
37
|
+
chain: "arbitrum",
|
|
38
|
+
protocol: "uniswap",
|
|
39
39
|
newUrl: this.getArbitrumSubgraphUrl(`FbCGRftH4a3yZugY7TnbYgPJVEv2LvMT6oF1fxPe9aJM`, false),
|
|
40
|
-
oldUrl:
|
|
40
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-dev",
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
|
-
chain:
|
|
44
|
-
protocol:
|
|
43
|
+
chain: "celo",
|
|
44
|
+
protocol: "uniswap",
|
|
45
45
|
newUrl: this.getArbitrumSubgraphUrl(`ESdrTJ3twMwWVoQ1hUE2u7PugEHX3QkenudD6aXCkDQ4`, false),
|
|
46
|
-
oldUrl:
|
|
46
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/jesse-sawa/uniswap-celo",
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
chain:
|
|
50
|
-
protocol:
|
|
51
|
-
newUrl:
|
|
52
|
-
oldUrl:
|
|
49
|
+
chain: "base",
|
|
50
|
+
protocol: "baseswap",
|
|
51
|
+
newUrl: "https://api.goldsky.com/api/public/project_cltceeuudv1ij01x7ekxhfl46/subgraphs/v3-base/prod/gn",
|
|
52
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/harleen-m/basex",
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
chain:
|
|
56
|
-
protocol:
|
|
57
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
58
|
-
oldUrl:
|
|
55
|
+
chain: "arbitrum",
|
|
56
|
+
protocol: "sushi",
|
|
57
|
+
newUrl: this.getArbitrumSubgraphUrl("QmevuQAmgiou1UX7Z2BQf6RKdX1WunQjH8VtawhkzSLj4V", true),
|
|
58
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/sushi-v3/v3-arbitrum",
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
|
-
chain:
|
|
62
|
-
protocol:
|
|
63
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
64
|
-
oldUrl:
|
|
61
|
+
chain: "avalanche",
|
|
62
|
+
protocol: "sushi",
|
|
63
|
+
newUrl: this.getArbitrumSubgraphUrl("Qmcdd4SGVwG9VY4itrXBnBPWBVsQvsxfzaib9bVny9C8jT", true),
|
|
64
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/sushi-v3/v3-avalanche",
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
|
-
chain:
|
|
68
|
-
protocol:
|
|
69
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
70
|
-
oldUrl:
|
|
67
|
+
chain: "bsc",
|
|
68
|
+
protocol: "sushi",
|
|
69
|
+
newUrl: this.getArbitrumSubgraphUrl("QmXsPN4TD4PUhT1ZWd5d1mdQPePFNMdJwUr6guSh1z9ZzA", true),
|
|
70
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/sushi-v3/v3-bsc",
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
|
-
chain:
|
|
74
|
-
protocol:
|
|
75
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
76
|
-
oldUrl:
|
|
73
|
+
chain: "base",
|
|
74
|
+
protocol: "sushi",
|
|
75
|
+
newUrl: this.getArbitrumSubgraphUrl("QmZ2R9ABG9ienaZdGyPLcDWDNDkG187RhXmh6fFuEtUaaS", true),
|
|
76
|
+
oldUrl: "https://api.studio.thegraph.com/query/32073/v3-base/v0.0.1",
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
|
-
chain:
|
|
80
|
-
protocol:
|
|
81
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
82
|
-
oldUrl:
|
|
79
|
+
chain: "optimism",
|
|
80
|
+
protocol: "sushi",
|
|
81
|
+
newUrl: this.getArbitrumSubgraphUrl("QmbT6ZsxJEZKUrbzLrAWV5EnQfSKZeYtZ265mQUaB552vK", true),
|
|
82
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/sushi-v3/v3-optimism",
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
|
-
chain:
|
|
86
|
-
protocol:
|
|
87
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
88
|
-
oldUrl:
|
|
85
|
+
chain: "polygon",
|
|
86
|
+
protocol: "sushi",
|
|
87
|
+
newUrl: this.getArbitrumSubgraphUrl("QmPbbjK9vtY69kSxMJRVLVz1dRzUBNwYbWTRYMiFzp9Tzm", true),
|
|
88
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/sushi-v3/v3-polygon",
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
|
-
chain:
|
|
92
|
-
protocol:
|
|
93
|
-
newUrl: this.getArbitrumSubgraphUrl(
|
|
94
|
-
oldUrl:
|
|
91
|
+
chain: "zkevm",
|
|
92
|
+
protocol: "sushi",
|
|
93
|
+
newUrl: this.getArbitrumSubgraphUrl("QmWH5ChjmF4Yp5Yhiaxczh5QwbG6HFSEi8bRwbKaUrJA6C", true),
|
|
94
|
+
oldUrl: "https://api.studio.thegraph.com/query/32073/v3-polygon-zkevm/v0.0.2",
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
|
-
chain:
|
|
98
|
-
protocol:
|
|
99
|
-
newUrl:
|
|
100
|
-
oldUrl:
|
|
97
|
+
chain: "arbitrum",
|
|
98
|
+
protocol: "camelot",
|
|
99
|
+
newUrl: "https://subgraph-proxy-server-xf2uthetka-as.a.run.app/gateway-arbitrum/3utanEBA9nqMjPnuQP1vMCCys6enSM3EawBpKTVwnUw2",
|
|
100
|
+
oldUrl: "https://api.thegraph.com/subgraphs/name/camelotlabs/camelot-amm-v3",
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
|
-
chain:
|
|
104
|
-
protocol:
|
|
105
|
-
newUrl:
|
|
106
|
-
oldUrl:
|
|
103
|
+
chain: "mode",
|
|
104
|
+
protocol: "swapmode",
|
|
105
|
+
newUrl: "https://api.goldsky.com/api/public/project_cltceeuudv1ij01x7ekxhfl46/subgraphs/swapmode-v3/prod/gn",
|
|
106
|
+
oldUrl: "https://api.goldsky.com/api/public/project_cltceeuudv1ij01x7ekxhfl46/subgraphs/swapmode-v3/1.0.0/gn",
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
|
-
chain:
|
|
110
|
-
protocol:
|
|
111
|
-
newUrl:
|
|
112
|
-
oldUrl:
|
|
109
|
+
chain: "linea",
|
|
110
|
+
protocol: "lynex",
|
|
111
|
+
newUrl: "https://api.goldsky.com/api/public/project_cltyhthusbmxp01s95k9l8a1u/subgraphs/lynex-cl/v1.0.2/gn",
|
|
112
|
+
oldUrl: "https://graph-query.linea.build/subgraphs/name/cryptoalgebra/analytics",
|
|
113
113
|
},
|
|
114
114
|
];
|
|
115
115
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createPublicClient, custom, fallback, http, } from "viem";
|
|
2
|
+
/** Each URL is checked on the same transport that will serve its reads. */
|
|
3
|
+
export function createRpcClient(access, chainId) {
|
|
4
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0)
|
|
5
|
+
throw new Error("Invalid execution chain ID");
|
|
6
|
+
if (access.client)
|
|
7
|
+
return access.client;
|
|
8
|
+
const urls = [
|
|
9
|
+
...new Set(access.urls.map((url) => url.trim()).filter(Boolean)),
|
|
10
|
+
];
|
|
11
|
+
if (!urls.length)
|
|
12
|
+
throw new Error("No RPC URLs configured");
|
|
13
|
+
const transports = urls.map((url) => {
|
|
14
|
+
const endpoint = createPublicClient({
|
|
15
|
+
transport: http(url, { retryCount: 0 }),
|
|
16
|
+
});
|
|
17
|
+
return custom({
|
|
18
|
+
async request({ method, params }) {
|
|
19
|
+
const actualChain = await endpoint.getChainId();
|
|
20
|
+
if (actualChain !== chainId) {
|
|
21
|
+
throw new Error("EXECUTION_CONTEXT_MISMATCH: provider chain does not match supplied context.");
|
|
22
|
+
}
|
|
23
|
+
if (method === "eth_chainId")
|
|
24
|
+
return `0x${actualChain.toString(16)}`;
|
|
25
|
+
return endpoint.request({ method, params });
|
|
26
|
+
},
|
|
27
|
+
}, { retryCount: 0 });
|
|
28
|
+
});
|
|
29
|
+
return createPublicClient({
|
|
30
|
+
transport: fallback(transports, { rank: false, retryCount: 0 }),
|
|
31
|
+
});
|
|
32
|
+
}
|
package/lib/esm/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/esm/utils/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import {
|
|
3
|
-
import { API_BASE_URL, API_INITIAL_DELAY, API_MAX_RETRIES, CENTRALIZE_CONTRACT_INTERACTION_CHAINS } from './consts.js';
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { getAbiItem, parseAbi, parseAbiItem, toFunctionSelector, } from "viem";
|
|
4
3
|
// 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
|
|
5
4
|
export const extendOHLCV = (rawData, period, endTimestamp) => {
|
|
6
5
|
// Sort rawData by timestamp
|
|
@@ -31,22 +30,25 @@ async function delay(ms) {
|
|
|
31
30
|
function exponentialBackoffDelay(attempts) {
|
|
32
31
|
const baseDelay = 1000; // 1 second
|
|
33
32
|
const maxDelay = 30000; // 30 seconds
|
|
34
|
-
const delay = Math.min(baseDelay *
|
|
33
|
+
const delay = Math.min(baseDelay * 2 ** (attempts - 1), maxDelay);
|
|
35
34
|
return delay;
|
|
36
35
|
}
|
|
37
36
|
export async function fetchData(request, attempts) {
|
|
38
|
-
log(
|
|
37
|
+
log("Request payload: =============", request);
|
|
39
38
|
attempts = attempts + 1;
|
|
40
39
|
try {
|
|
41
40
|
const response = (await axios(request)).data;
|
|
42
41
|
// this.log('API Response: =============', response);
|
|
43
|
-
if (
|
|
42
|
+
if (response !== null &&
|
|
43
|
+
typeof response === "object" &&
|
|
44
|
+
Array.isArray(response.errors) &&
|
|
45
|
+
response.errors.length > 0) {
|
|
44
46
|
if (attempts < 3) {
|
|
45
47
|
await delay(exponentialBackoffDelay(attempts));
|
|
46
48
|
return await fetchData(request, attempts);
|
|
47
49
|
}
|
|
48
50
|
else {
|
|
49
|
-
throw new Error(
|
|
51
|
+
throw new Error("Maximum retry attempts reached");
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
return response;
|
|
@@ -61,59 +63,63 @@ export async function fetchData(request, attempts) {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// For formatting the parameters if needed
|
|
70
|
-
const paramsArray = contractArguments || [];
|
|
71
|
-
// Calculate block number for determinism
|
|
72
|
-
// Best way to handle contextually non-null values?
|
|
73
|
-
// const syncedBlock = await getBlockFromTimestamp(this.executionContext!.epochTimestamp, this.providerIdentity!) //@note uncomment for deterministic blocks
|
|
74
|
-
// Call the desired method with the specified arguments at synced block
|
|
75
|
-
// , {blockTag: syncedBlock}
|
|
76
|
-
let result;
|
|
77
|
-
if (CENTRALIZE_CONTRACT_INTERACTION_CHAINS.indexOf(chainId.toString()) === -1) {
|
|
78
|
-
result = await contract[functionName](...paramsArray, {
|
|
79
|
-
blockTag: currentExecutionContext?.blockNumber,
|
|
80
|
-
}); // @note uncomment for deterministic blocks
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
console.log('Calling the centralized view');
|
|
84
|
-
const viewContractConfig = {
|
|
85
|
-
epochTimestamp: currentExecutionContext.epochTimestamp,
|
|
86
|
-
blockNumber: currentExecutionContext.blockNumber,
|
|
87
|
-
address,
|
|
88
|
-
abi,
|
|
89
|
-
arguments: paramsArray,
|
|
90
|
-
method: functionName,
|
|
91
|
-
rpcUrl: rpc,
|
|
66
|
+
function positionalTuple(value, parameter) {
|
|
67
|
+
if (/\[[0-9]*\]$/.test(parameter.type)) {
|
|
68
|
+
const item = {
|
|
69
|
+
...parameter,
|
|
70
|
+
type: parameter.type.replace(/\[[0-9]*\]$/, ""),
|
|
92
71
|
};
|
|
93
|
-
|
|
72
|
+
return value.map((entry) => positionalTuple(entry, item));
|
|
94
73
|
}
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
if (parameter.type !== "tuple" || !("components" in parameter))
|
|
75
|
+
return value;
|
|
76
|
+
return parameter.components.map((component, index) => positionalTuple(Array.isArray(value) ? value[index] : value[component.name], component));
|
|
97
77
|
}
|
|
98
|
-
export async function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
78
|
+
export async function readContract({ abi, address, contractArguments = [], currentExecutionContext, functionName, provider, }) {
|
|
79
|
+
if (!provider)
|
|
80
|
+
throw new Error("Provider not initialized");
|
|
81
|
+
const input = typeof abi === "string" ? JSON.parse(abi) : abi;
|
|
82
|
+
// Existing bundles may use ethers' optional tuple keyword.
|
|
83
|
+
const normalizeSignature = (signature) => signature.replace(/\btuple\s*\(/g, "(");
|
|
84
|
+
const normalizedAbi = (input.every((item) => typeof item === "string")
|
|
85
|
+
? parseAbi(input.map(normalizeSignature))
|
|
86
|
+
: input);
|
|
87
|
+
const explicit = functionName.includes("(")
|
|
88
|
+
? parseAbiItem(`function ${normalizeSignature(functionName)}`)
|
|
89
|
+
: undefined;
|
|
90
|
+
if (explicit && explicit.type !== "function")
|
|
91
|
+
throw new Error("Expected a function signature");
|
|
92
|
+
const selectedAbi = explicit
|
|
93
|
+
? normalizedAbi.filter((item) => item.type === "function" &&
|
|
94
|
+
toFunctionSelector(item) === toFunctionSelector(explicit))
|
|
95
|
+
: normalizedAbi;
|
|
96
|
+
if (explicit && !selectedAbi.length)
|
|
97
|
+
throw new Error(`Function ${functionName} not found in ABI`);
|
|
98
|
+
const resolvedName = explicit && "name" in explicit ? explicit.name : functionName;
|
|
99
|
+
const result = await provider.readContract({
|
|
100
|
+
address: address,
|
|
101
|
+
abi: selectedAbi,
|
|
102
|
+
functionName: resolvedName,
|
|
103
|
+
args: contractArguments,
|
|
104
|
+
...(currentExecutionContext?.blockNumber !== undefined
|
|
105
|
+
? { blockNumber: BigInt(currentExecutionContext.blockNumber) }
|
|
106
|
+
: {}),
|
|
107
|
+
});
|
|
108
|
+
const item = getAbiItem({
|
|
109
|
+
abi: selectedAbi,
|
|
110
|
+
name: resolvedName,
|
|
111
|
+
args: contractArguments,
|
|
112
|
+
});
|
|
113
|
+
if (!item || item.type !== "function")
|
|
114
|
+
return result;
|
|
115
|
+
if (!item.outputs?.length)
|
|
116
|
+
return [];
|
|
117
|
+
return item.outputs.length === 1
|
|
118
|
+
? positionalTuple(result, item.outputs[0])
|
|
119
|
+
: item.outputs.map((output, index) => positionalTuple(result[index], output));
|
|
114
120
|
}
|
|
115
121
|
function log(...args) {
|
|
116
|
-
if (process.env.DEBUG ===
|
|
122
|
+
if (process.env.DEBUG === "true") {
|
|
117
123
|
console.log(...args);
|
|
118
124
|
}
|
|
119
125
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import { ExecutionBase } from './executionBase.js';
|
|
1
|
+
import type { ExecuteWithContextOptions, JobDetails, RpcAccess } from "../types.js";
|
|
2
|
+
import { ExecutionBase } from "./executionBase.js";
|
|
4
3
|
export interface ExecutionAppConfig {
|
|
5
4
|
/** Vault address used for execution context and subgraph queries. */
|
|
6
5
|
vault: string;
|
|
@@ -42,7 +41,7 @@ export declare class ExecutionApp extends ExecutionBase {
|
|
|
42
41
|
sentioApiKey: string;
|
|
43
42
|
config: ExecutionAppConfig;
|
|
44
43
|
constructor(config: ExecutionAppConfig);
|
|
45
|
-
execute<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>,
|
|
44
|
+
execute<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, rpc?: RpcAccess, forceDeposit?: boolean): Promise<Array<T>>;
|
|
46
45
|
/**
|
|
47
46
|
* Executes a strategy against a supplied execution context.
|
|
48
47
|
* This is the recommended API for new consumers. It intentionally bypasses
|
|
@@ -52,8 +51,8 @@ export declare class ExecutionApp extends ExecutionBase {
|
|
|
52
51
|
private parseVaultConfig;
|
|
53
52
|
private validateExecutionContext;
|
|
54
53
|
private redactError;
|
|
55
|
-
executeStabilityVault<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>,
|
|
56
|
-
executeDynamicJobs<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, _job: JobDetails,
|
|
54
|
+
executeStabilityVault<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, rpc?: RpcAccess, forceDeposit?: boolean): Promise<Array<T>>;
|
|
55
|
+
executeDynamicJobs<T>(_wasmFile: string | ArrayBuffer, _vaultConfig: string, _data: Array<any>, _job: JobDetails, rpc?: RpcAccess, forceDeposit?: boolean): Promise<Array<T>>;
|
|
57
56
|
private getSmartPoolExecutionContext;
|
|
58
57
|
private getPoolCurrentTick;
|
|
59
58
|
private getTickSpacing;
|