@steerprotocol/data-connector-loader 4.1.0 → 5.0.0-next.10
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 +136 -20
- package/lib/bundle/bundleBase.d.ts +11 -14
- package/lib/bundle/bundleBase.js +58 -90
- 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 +79 -93
- package/lib/esm/bundle/bundleDataConnector.d.ts +2 -6
- package/lib/esm/bundle/bundleDataConnector.js +26 -49
- package/lib/esm/execution/executionApp.d.ts +18 -17
- package/lib/esm/execution/executionApp.js +390 -370
- package/lib/esm/execution/executionBase.d.ts +6 -6
- package/lib/esm/execution/executionBase.js +27 -13
- package/lib/esm/execution/executionDataConnector.d.ts +7 -4
- package/lib/esm/execution/executionDataConnector.js +143 -76
- package/lib/esm/index.d.ts +7 -7
- package/lib/esm/index.js +4 -4
- package/lib/esm/types.d.ts +23 -25
- 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 +79 -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 +18 -17
- package/lib/execution/executionApp.js +379 -364
- package/lib/execution/executionBase.d.ts +6 -6
- package/lib/execution/executionBase.js +27 -13
- package/lib/execution/executionDataConnector.d.ts +7 -4
- package/lib/execution/executionDataConnector.js +146 -71
- package/lib/index.d.ts +7 -7
- package/lib/index.js +1 -1
- package/lib/package.json +1 -0
- package/lib/types.d.ts +23 -25
- 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 +79 -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 +22 -17
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
import { DataConnector } from
|
|
2
|
-
import { ExecutionContextError, StrategyExecutionError } from
|
|
3
|
-
import { fetchData, readContract } from
|
|
4
|
-
import { ExecutionBase } from
|
|
1
|
+
import { DataConnector } from "../bundle/bundleDataConnector.js";
|
|
2
|
+
import { ExecutionContextError, StrategyExecutionError } from "../types.js";
|
|
3
|
+
import { fetchData, readContract } from "../utils/utils.js";
|
|
4
|
+
import { ExecutionBase } from "./executionBase.js";
|
|
5
5
|
export class ExecutionApp extends ExecutionBase {
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super(config.maxRetries ?? 3);
|
|
8
|
-
this.getSlot0 = async (pool, currentExecutionContext, provider
|
|
8
|
+
this.getSlot0 = async (pool, currentExecutionContext, provider) => {
|
|
9
9
|
const slot0Abi = [
|
|
10
10
|
{
|
|
11
11
|
inputs: [],
|
|
12
|
-
name:
|
|
12
|
+
name: "slot0",
|
|
13
13
|
outputs: [
|
|
14
|
-
{ internalType:
|
|
15
|
-
{ internalType:
|
|
16
|
-
{ internalType:
|
|
14
|
+
{ internalType: "uint160", name: "sqrtPriceX96", type: "uint160" },
|
|
15
|
+
{ internalType: "int24", name: "tick", type: "int24" },
|
|
16
|
+
{ internalType: "uint16", name: "observationIndex", type: "uint16" },
|
|
17
17
|
{
|
|
18
|
-
internalType:
|
|
19
|
-
name:
|
|
20
|
-
type:
|
|
18
|
+
internalType: "uint16",
|
|
19
|
+
name: "observationCardinality",
|
|
20
|
+
type: "uint16",
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
internalType:
|
|
24
|
-
name:
|
|
25
|
-
type:
|
|
23
|
+
internalType: "uint16",
|
|
24
|
+
name: "observationCardinalityNext",
|
|
25
|
+
type: "uint16",
|
|
26
26
|
},
|
|
27
|
-
{ internalType:
|
|
28
|
-
{ internalType:
|
|
27
|
+
{ internalType: "uint8", name: "feeProtocol", type: "uint8" },
|
|
28
|
+
{ internalType: "bool", name: "unlocked", type: "bool" },
|
|
29
29
|
],
|
|
30
|
-
stateMutability:
|
|
31
|
-
type:
|
|
30
|
+
stateMutability: "view",
|
|
31
|
+
type: "function",
|
|
32
32
|
},
|
|
33
33
|
];
|
|
34
34
|
const slot0 = await readContract({
|
|
35
35
|
address: pool,
|
|
36
36
|
abi: slot0Abi,
|
|
37
37
|
currentExecutionContext,
|
|
38
|
-
functionName:
|
|
38
|
+
functionName: "slot0",
|
|
39
39
|
provider,
|
|
40
|
-
rpc,
|
|
41
|
-
chainId: this.chainId,
|
|
42
40
|
});
|
|
43
41
|
return {
|
|
44
42
|
sqrtPriceX96: slot0[0],
|
|
@@ -50,55 +48,53 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
50
48
|
unlocked: slot0[6],
|
|
51
49
|
};
|
|
52
50
|
};
|
|
53
|
-
this.getSlot0Aerodrome = async (pool, currentExecutionContext, provider
|
|
51
|
+
this.getSlot0Aerodrome = async (pool, currentExecutionContext, provider) => {
|
|
54
52
|
const slot0Abi = [
|
|
55
53
|
{
|
|
56
54
|
inputs: [],
|
|
57
|
-
name:
|
|
55
|
+
name: "slot0",
|
|
58
56
|
outputs: [
|
|
59
57
|
{
|
|
60
|
-
internalType:
|
|
61
|
-
name:
|
|
62
|
-
type:
|
|
58
|
+
internalType: "uint160",
|
|
59
|
+
name: "sqrtPriceX96",
|
|
60
|
+
type: "uint160",
|
|
63
61
|
},
|
|
64
62
|
{
|
|
65
|
-
internalType:
|
|
66
|
-
name:
|
|
67
|
-
type:
|
|
63
|
+
internalType: "int24",
|
|
64
|
+
name: "tick",
|
|
65
|
+
type: "int24",
|
|
68
66
|
},
|
|
69
67
|
{
|
|
70
|
-
internalType:
|
|
71
|
-
name:
|
|
72
|
-
type:
|
|
68
|
+
internalType: "uint16",
|
|
69
|
+
name: "observationIndex",
|
|
70
|
+
type: "uint16",
|
|
73
71
|
},
|
|
74
72
|
{
|
|
75
|
-
internalType:
|
|
76
|
-
name:
|
|
77
|
-
type:
|
|
73
|
+
internalType: "uint16",
|
|
74
|
+
name: "observationCardinality",
|
|
75
|
+
type: "uint16",
|
|
78
76
|
},
|
|
79
77
|
{
|
|
80
|
-
internalType:
|
|
81
|
-
name:
|
|
82
|
-
type:
|
|
78
|
+
internalType: "uint16",
|
|
79
|
+
name: "observationCardinalityNext",
|
|
80
|
+
type: "uint16",
|
|
83
81
|
},
|
|
84
82
|
{
|
|
85
|
-
internalType:
|
|
86
|
-
name:
|
|
87
|
-
type:
|
|
83
|
+
internalType: "bool",
|
|
84
|
+
name: "unlocked",
|
|
85
|
+
type: "bool",
|
|
88
86
|
},
|
|
89
87
|
],
|
|
90
|
-
stateMutability:
|
|
91
|
-
type:
|
|
88
|
+
stateMutability: "view",
|
|
89
|
+
type: "function",
|
|
92
90
|
},
|
|
93
91
|
];
|
|
94
92
|
const slot0 = await readContract({
|
|
95
93
|
address: pool,
|
|
96
94
|
abi: slot0Abi,
|
|
97
95
|
currentExecutionContext,
|
|
98
|
-
functionName:
|
|
96
|
+
functionName: "slot0",
|
|
99
97
|
provider,
|
|
100
|
-
rpc,
|
|
101
|
-
chainId: this.chainId,
|
|
102
98
|
});
|
|
103
99
|
return {
|
|
104
100
|
sqrtPriceX96: slot0[0],
|
|
@@ -113,317 +109,315 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
113
109
|
if (this.isAlgebraIntegralPool) {
|
|
114
110
|
return {
|
|
115
111
|
inputs: [],
|
|
116
|
-
name:
|
|
112
|
+
name: "globalState",
|
|
117
113
|
outputs: [
|
|
118
114
|
{
|
|
119
|
-
internalType:
|
|
120
|
-
name:
|
|
121
|
-
type:
|
|
115
|
+
internalType: "uint160",
|
|
116
|
+
name: "price",
|
|
117
|
+
type: "uint160",
|
|
122
118
|
},
|
|
123
119
|
{
|
|
124
|
-
internalType:
|
|
125
|
-
name:
|
|
126
|
-
type:
|
|
120
|
+
internalType: "int24",
|
|
121
|
+
name: "tick",
|
|
122
|
+
type: "int24",
|
|
127
123
|
},
|
|
128
124
|
{
|
|
129
|
-
internalType:
|
|
130
|
-
name:
|
|
131
|
-
type:
|
|
125
|
+
internalType: "uint16",
|
|
126
|
+
name: "lastFee",
|
|
127
|
+
type: "uint16",
|
|
132
128
|
},
|
|
133
129
|
{
|
|
134
|
-
internalType:
|
|
135
|
-
name:
|
|
136
|
-
type:
|
|
130
|
+
internalType: "uint8",
|
|
131
|
+
name: "pluginConfig",
|
|
132
|
+
type: "uint8",
|
|
137
133
|
},
|
|
138
134
|
{
|
|
139
|
-
internalType:
|
|
140
|
-
name:
|
|
141
|
-
type:
|
|
135
|
+
internalType: "uint16",
|
|
136
|
+
name: "communityFee",
|
|
137
|
+
type: "uint16",
|
|
142
138
|
},
|
|
143
139
|
{
|
|
144
|
-
internalType:
|
|
145
|
-
name:
|
|
146
|
-
type:
|
|
140
|
+
internalType: "bool",
|
|
141
|
+
name: "unlocked",
|
|
142
|
+
type: "bool",
|
|
147
143
|
},
|
|
148
144
|
],
|
|
149
|
-
stateMutability:
|
|
150
|
-
type:
|
|
145
|
+
stateMutability: "view",
|
|
146
|
+
type: "function",
|
|
151
147
|
};
|
|
152
148
|
}
|
|
153
149
|
else if (this.isDirectionalPool) {
|
|
154
150
|
return {
|
|
155
151
|
inputs: [],
|
|
156
|
-
name:
|
|
152
|
+
name: "globalState",
|
|
157
153
|
outputs: [
|
|
158
154
|
{
|
|
159
|
-
internalType:
|
|
160
|
-
name:
|
|
161
|
-
type:
|
|
155
|
+
internalType: "uint160",
|
|
156
|
+
name: "price",
|
|
157
|
+
type: "uint160",
|
|
162
158
|
},
|
|
163
159
|
{
|
|
164
|
-
internalType:
|
|
165
|
-
name:
|
|
166
|
-
type:
|
|
160
|
+
internalType: "int24",
|
|
161
|
+
name: "tick",
|
|
162
|
+
type: "int24",
|
|
167
163
|
},
|
|
168
164
|
{
|
|
169
|
-
internalType:
|
|
170
|
-
name:
|
|
171
|
-
type:
|
|
165
|
+
internalType: "uint16",
|
|
166
|
+
name: "feeZto",
|
|
167
|
+
type: "uint16",
|
|
172
168
|
},
|
|
173
169
|
{
|
|
174
|
-
internalType:
|
|
175
|
-
name:
|
|
176
|
-
type:
|
|
170
|
+
internalType: "uint16",
|
|
171
|
+
name: "feeOtz",
|
|
172
|
+
type: "uint16",
|
|
177
173
|
},
|
|
178
174
|
{
|
|
179
|
-
internalType:
|
|
180
|
-
name:
|
|
181
|
-
type:
|
|
175
|
+
internalType: "uint16",
|
|
176
|
+
name: "timepointIndex",
|
|
177
|
+
type: "uint16",
|
|
182
178
|
},
|
|
183
179
|
{
|
|
184
|
-
internalType:
|
|
185
|
-
name:
|
|
186
|
-
type:
|
|
180
|
+
internalType: "uint8",
|
|
181
|
+
name: "communityFeeToken0",
|
|
182
|
+
type: "uint8",
|
|
187
183
|
},
|
|
188
184
|
{
|
|
189
|
-
internalType:
|
|
190
|
-
name:
|
|
191
|
-
type:
|
|
185
|
+
internalType: "uint8",
|
|
186
|
+
name: "communityFeeToken1",
|
|
187
|
+
type: "uint8",
|
|
192
188
|
},
|
|
193
189
|
{
|
|
194
|
-
internalType:
|
|
195
|
-
name:
|
|
196
|
-
type:
|
|
190
|
+
internalType: "bool",
|
|
191
|
+
name: "unlocked",
|
|
192
|
+
type: "bool",
|
|
197
193
|
},
|
|
198
194
|
],
|
|
199
|
-
stateMutability:
|
|
200
|
-
type:
|
|
195
|
+
stateMutability: "view",
|
|
196
|
+
type: "function",
|
|
201
197
|
};
|
|
202
198
|
}
|
|
203
199
|
else if (this.isPoolSharkPool) {
|
|
204
200
|
return {
|
|
205
201
|
inputs: [],
|
|
206
|
-
name:
|
|
202
|
+
name: "globalState",
|
|
207
203
|
outputs: [
|
|
208
204
|
{
|
|
209
205
|
components: [
|
|
210
206
|
{
|
|
211
207
|
components: [
|
|
212
208
|
{
|
|
213
|
-
internalType:
|
|
214
|
-
name:
|
|
215
|
-
type:
|
|
209
|
+
internalType: "uint16",
|
|
210
|
+
name: "index",
|
|
211
|
+
type: "uint16",
|
|
216
212
|
},
|
|
217
213
|
{
|
|
218
|
-
internalType:
|
|
219
|
-
name:
|
|
220
|
-
type:
|
|
214
|
+
internalType: "uint16",
|
|
215
|
+
name: "count",
|
|
216
|
+
type: "uint16",
|
|
221
217
|
},
|
|
222
218
|
{
|
|
223
|
-
internalType:
|
|
224
|
-
name:
|
|
225
|
-
type:
|
|
219
|
+
internalType: "uint16",
|
|
220
|
+
name: "countMax",
|
|
221
|
+
type: "uint16",
|
|
226
222
|
},
|
|
227
223
|
],
|
|
228
|
-
internalType:
|
|
229
|
-
name:
|
|
230
|
-
type:
|
|
224
|
+
internalType: "struct PoolsharkStructs.SampleState",
|
|
225
|
+
name: "samples",
|
|
226
|
+
type: "tuple",
|
|
231
227
|
},
|
|
232
228
|
{
|
|
233
|
-
internalType:
|
|
234
|
-
name:
|
|
235
|
-
type:
|
|
229
|
+
internalType: "uint200",
|
|
230
|
+
name: "feeGrowthGlobal0",
|
|
231
|
+
type: "uint200",
|
|
236
232
|
},
|
|
237
233
|
{
|
|
238
|
-
internalType:
|
|
239
|
-
name:
|
|
240
|
-
type:
|
|
234
|
+
internalType: "uint200",
|
|
235
|
+
name: "feeGrowthGlobal1",
|
|
236
|
+
type: "uint200",
|
|
241
237
|
},
|
|
242
238
|
{
|
|
243
|
-
internalType:
|
|
244
|
-
name:
|
|
245
|
-
type:
|
|
239
|
+
internalType: "uint160",
|
|
240
|
+
name: "secondsPerLiquidityAccum",
|
|
241
|
+
type: "uint160",
|
|
246
242
|
},
|
|
247
243
|
{
|
|
248
|
-
internalType:
|
|
249
|
-
name:
|
|
250
|
-
type:
|
|
244
|
+
internalType: "uint160",
|
|
245
|
+
name: "price",
|
|
246
|
+
type: "uint160",
|
|
251
247
|
},
|
|
252
248
|
{
|
|
253
|
-
internalType:
|
|
254
|
-
name:
|
|
255
|
-
type:
|
|
249
|
+
internalType: "uint128",
|
|
250
|
+
name: "liquidity",
|
|
251
|
+
type: "uint128",
|
|
256
252
|
},
|
|
257
253
|
{
|
|
258
|
-
internalType:
|
|
259
|
-
name:
|
|
260
|
-
type:
|
|
254
|
+
internalType: "int56",
|
|
255
|
+
name: "tickSecondsAccum",
|
|
256
|
+
type: "int56",
|
|
261
257
|
},
|
|
262
258
|
{
|
|
263
|
-
internalType:
|
|
264
|
-
name:
|
|
265
|
-
type:
|
|
259
|
+
internalType: "int24",
|
|
260
|
+
name: "tickAtPrice",
|
|
261
|
+
type: "int24",
|
|
266
262
|
},
|
|
267
263
|
{
|
|
268
|
-
internalType:
|
|
269
|
-
name:
|
|
270
|
-
type:
|
|
264
|
+
internalType: "uint16",
|
|
265
|
+
name: "protocolSwapFee0",
|
|
266
|
+
type: "uint16",
|
|
271
267
|
},
|
|
272
268
|
{
|
|
273
|
-
internalType:
|
|
274
|
-
name:
|
|
275
|
-
type:
|
|
269
|
+
internalType: "uint16",
|
|
270
|
+
name: "protocolSwapFee1",
|
|
271
|
+
type: "uint16",
|
|
276
272
|
},
|
|
277
273
|
],
|
|
278
|
-
internalType:
|
|
279
|
-
name:
|
|
280
|
-
type:
|
|
274
|
+
internalType: "struct PoolsharkStructs.RangePoolState",
|
|
275
|
+
name: "pool",
|
|
276
|
+
type: "tuple",
|
|
281
277
|
},
|
|
282
278
|
{
|
|
283
279
|
components: [
|
|
284
280
|
{
|
|
285
|
-
internalType:
|
|
286
|
-
name:
|
|
287
|
-
type:
|
|
281
|
+
internalType: "uint160",
|
|
282
|
+
name: "price",
|
|
283
|
+
type: "uint160",
|
|
288
284
|
},
|
|
289
285
|
{
|
|
290
|
-
internalType:
|
|
291
|
-
name:
|
|
292
|
-
type:
|
|
286
|
+
internalType: "uint128",
|
|
287
|
+
name: "liquidity",
|
|
288
|
+
type: "uint128",
|
|
293
289
|
},
|
|
294
290
|
{
|
|
295
|
-
internalType:
|
|
296
|
-
name:
|
|
297
|
-
type:
|
|
291
|
+
internalType: "uint128",
|
|
292
|
+
name: "protocolFees",
|
|
293
|
+
type: "uint128",
|
|
298
294
|
},
|
|
299
295
|
{
|
|
300
|
-
internalType:
|
|
301
|
-
name:
|
|
302
|
-
type:
|
|
296
|
+
internalType: "uint16",
|
|
297
|
+
name: "protocolFillFee",
|
|
298
|
+
type: "uint16",
|
|
303
299
|
},
|
|
304
300
|
{
|
|
305
|
-
internalType:
|
|
306
|
-
name:
|
|
307
|
-
type:
|
|
301
|
+
internalType: "int24",
|
|
302
|
+
name: "tickAtPrice",
|
|
303
|
+
type: "int24",
|
|
308
304
|
},
|
|
309
305
|
],
|
|
310
|
-
internalType:
|
|
311
|
-
name:
|
|
312
|
-
type:
|
|
306
|
+
internalType: "struct PoolsharkStructs.LimitPoolState",
|
|
307
|
+
name: "pool0",
|
|
308
|
+
type: "tuple",
|
|
313
309
|
},
|
|
314
310
|
{
|
|
315
311
|
components: [
|
|
316
312
|
{
|
|
317
|
-
internalType:
|
|
318
|
-
name:
|
|
319
|
-
type:
|
|
313
|
+
internalType: "uint160",
|
|
314
|
+
name: "price",
|
|
315
|
+
type: "uint160",
|
|
320
316
|
},
|
|
321
317
|
{
|
|
322
|
-
internalType:
|
|
323
|
-
name:
|
|
324
|
-
type:
|
|
318
|
+
internalType: "uint128",
|
|
319
|
+
name: "liquidity",
|
|
320
|
+
type: "uint128",
|
|
325
321
|
},
|
|
326
322
|
{
|
|
327
|
-
internalType:
|
|
328
|
-
name:
|
|
329
|
-
type:
|
|
323
|
+
internalType: "uint128",
|
|
324
|
+
name: "protocolFees",
|
|
325
|
+
type: "uint128",
|
|
330
326
|
},
|
|
331
327
|
{
|
|
332
|
-
internalType:
|
|
333
|
-
name:
|
|
334
|
-
type:
|
|
328
|
+
internalType: "uint16",
|
|
329
|
+
name: "protocolFillFee",
|
|
330
|
+
type: "uint16",
|
|
335
331
|
},
|
|
336
332
|
{
|
|
337
|
-
internalType:
|
|
338
|
-
name:
|
|
339
|
-
type:
|
|
333
|
+
internalType: "int24",
|
|
334
|
+
name: "tickAtPrice",
|
|
335
|
+
type: "int24",
|
|
340
336
|
},
|
|
341
337
|
],
|
|
342
|
-
internalType:
|
|
343
|
-
name:
|
|
344
|
-
type:
|
|
338
|
+
internalType: "struct PoolsharkStructs.LimitPoolState",
|
|
339
|
+
name: "pool1",
|
|
340
|
+
type: "tuple",
|
|
345
341
|
},
|
|
346
342
|
{
|
|
347
|
-
internalType:
|
|
348
|
-
name:
|
|
349
|
-
type:
|
|
343
|
+
internalType: "uint128",
|
|
344
|
+
name: "liquidityGlobal",
|
|
345
|
+
type: "uint128",
|
|
350
346
|
},
|
|
351
347
|
{
|
|
352
|
-
internalType:
|
|
353
|
-
name:
|
|
354
|
-
type:
|
|
348
|
+
internalType: "uint32",
|
|
349
|
+
name: "positionIdNext",
|
|
350
|
+
type: "uint32",
|
|
355
351
|
},
|
|
356
352
|
{
|
|
357
|
-
internalType:
|
|
358
|
-
name:
|
|
359
|
-
type:
|
|
353
|
+
internalType: "uint32",
|
|
354
|
+
name: "epoch",
|
|
355
|
+
type: "uint32",
|
|
360
356
|
},
|
|
361
357
|
{
|
|
362
|
-
internalType:
|
|
363
|
-
name:
|
|
364
|
-
type:
|
|
358
|
+
internalType: "uint8",
|
|
359
|
+
name: "unlocked",
|
|
360
|
+
type: "uint8",
|
|
365
361
|
},
|
|
366
362
|
],
|
|
367
|
-
stateMutability:
|
|
368
|
-
type:
|
|
363
|
+
stateMutability: "view",
|
|
364
|
+
type: "function",
|
|
369
365
|
};
|
|
370
366
|
}
|
|
371
367
|
else {
|
|
372
368
|
return {
|
|
373
369
|
inputs: [],
|
|
374
|
-
name:
|
|
370
|
+
name: "globalState",
|
|
375
371
|
outputs: [
|
|
376
372
|
{
|
|
377
|
-
internalType:
|
|
378
|
-
name:
|
|
379
|
-
type:
|
|
373
|
+
internalType: "uint160",
|
|
374
|
+
name: "price",
|
|
375
|
+
type: "uint160",
|
|
380
376
|
},
|
|
381
377
|
{
|
|
382
|
-
internalType:
|
|
383
|
-
name:
|
|
384
|
-
type:
|
|
378
|
+
internalType: "int24",
|
|
379
|
+
name: "tick",
|
|
380
|
+
type: "int24",
|
|
385
381
|
},
|
|
386
382
|
{
|
|
387
|
-
internalType:
|
|
388
|
-
name:
|
|
389
|
-
type:
|
|
383
|
+
internalType: "int24",
|
|
384
|
+
name: "prevInitializedTick",
|
|
385
|
+
type: "int24",
|
|
390
386
|
},
|
|
391
387
|
{
|
|
392
|
-
internalType:
|
|
393
|
-
name:
|
|
394
|
-
type:
|
|
388
|
+
internalType: "uint16",
|
|
389
|
+
name: "fee",
|
|
390
|
+
type: "uint16",
|
|
395
391
|
},
|
|
396
392
|
{
|
|
397
|
-
internalType:
|
|
398
|
-
name:
|
|
399
|
-
type:
|
|
393
|
+
internalType: "uint16",
|
|
394
|
+
name: "timepointIndex",
|
|
395
|
+
type: "uint16",
|
|
400
396
|
},
|
|
401
397
|
{
|
|
402
|
-
internalType:
|
|
403
|
-
name:
|
|
404
|
-
type:
|
|
398
|
+
internalType: "uint8",
|
|
399
|
+
name: "communityFee",
|
|
400
|
+
type: "uint8",
|
|
405
401
|
},
|
|
406
402
|
{
|
|
407
|
-
internalType:
|
|
408
|
-
name:
|
|
409
|
-
type:
|
|
403
|
+
internalType: "bool",
|
|
404
|
+
name: "unlocked",
|
|
405
|
+
type: "bool",
|
|
410
406
|
},
|
|
411
407
|
],
|
|
412
|
-
stateMutability:
|
|
413
|
-
type:
|
|
408
|
+
stateMutability: "view",
|
|
409
|
+
type: "function",
|
|
414
410
|
};
|
|
415
411
|
}
|
|
416
412
|
};
|
|
417
|
-
this.getGlobalState = async (pool, currentExecutionContext, provider
|
|
413
|
+
this.getGlobalState = async (pool, currentExecutionContext, provider) => {
|
|
418
414
|
const slot0Abi = [this.getGlobalStateAbi()];
|
|
419
415
|
const slot0 = await readContract({
|
|
420
416
|
address: pool,
|
|
421
417
|
abi: slot0Abi,
|
|
422
418
|
currentExecutionContext,
|
|
423
|
-
functionName:
|
|
419
|
+
functionName: "globalState",
|
|
424
420
|
provider,
|
|
425
|
-
rpc,
|
|
426
|
-
chainId: this.chainId,
|
|
427
421
|
});
|
|
428
422
|
if (this.isPoolSharkPool) {
|
|
429
423
|
return {
|
|
@@ -457,48 +451,65 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
457
451
|
};
|
|
458
452
|
};
|
|
459
453
|
this.vault = config.vault;
|
|
460
|
-
this.steerSubgraph = config.steerSubgraph;
|
|
454
|
+
this.steerSubgraph = config.steerSubgraph ?? "";
|
|
461
455
|
this.chainId = config.chainId;
|
|
462
|
-
this.isAlgebraPool = config.poolType
|
|
463
|
-
this.isAlgebraIntegralPool =
|
|
464
|
-
|
|
465
|
-
this.
|
|
466
|
-
this.
|
|
467
|
-
this.
|
|
468
|
-
this.sentioApiKey = config.apiKeys
|
|
456
|
+
this.isAlgebraPool = config.poolType?.isAlgebraPool ?? false;
|
|
457
|
+
this.isAlgebraIntegralPool =
|
|
458
|
+
config.poolType?.isAlgebraIntegralPool ?? false;
|
|
459
|
+
this.isDirectionalPool = config.poolType?.isDirectionalPool ?? false;
|
|
460
|
+
this.isPoolSharkPool = config.poolType?.isPoolSharkPool ?? false;
|
|
461
|
+
this.isAerodromePool = config.poolType?.isAerodromePool ?? false;
|
|
462
|
+
this.sentioApiKey = config.apiKeys?.sentioApiKey ?? "";
|
|
469
463
|
this.config = config;
|
|
470
464
|
}
|
|
471
|
-
async execute(_wasmFile, _vaultConfig, _data,
|
|
472
|
-
|
|
465
|
+
async execute(_wasmFile, _vaultConfig, _data, rpc, forceDeposit) {
|
|
466
|
+
if (!this.config.poolType) {
|
|
467
|
+
throw new Error("poolType is required by execute() for pool discovery.");
|
|
468
|
+
}
|
|
469
|
+
if (!this.steerSubgraph.trim()) {
|
|
470
|
+
throw new Error("steerSubgraph is required by execute() for pool discovery.");
|
|
471
|
+
}
|
|
472
|
+
const dataConnector = new DataConnector({
|
|
473
|
+
wasmFile: _wasmFile,
|
|
474
|
+
config: _vaultConfig,
|
|
475
|
+
executionConfig: this.config,
|
|
476
|
+
rpc,
|
|
477
|
+
});
|
|
473
478
|
await dataConnector.loadSync();
|
|
474
479
|
const executionContext = await this.getExecutionContext(dataConnector, JSON.parse(_vaultConfig));
|
|
475
|
-
|
|
476
|
-
if (_etherRpcConfig) {
|
|
477
|
-
rpc = _etherRpcConfig[this.chainId.toString()].url;
|
|
478
|
-
}
|
|
479
|
-
const smartPoolExecutionContext = await this.getSmartPoolExecutionContext(executionContext, dataConnector, JSON.parse(_vaultConfig), rpc);
|
|
480
|
+
const smartPoolExecutionContext = await this.getSmartPoolExecutionContext(executionContext, dataConnector, JSON.parse(_vaultConfig));
|
|
480
481
|
dataConnector.setExecutionContextStrategyExecution({
|
|
481
482
|
...executionContext,
|
|
482
483
|
...smartPoolExecutionContext,
|
|
483
484
|
}, forceDeposit);
|
|
484
485
|
_data = _data.map((element) => JSON.stringify(element));
|
|
485
486
|
const result = await dataConnector.executeBundle(_data);
|
|
486
|
-
return
|
|
487
|
+
return this.parseStrategyResult(result);
|
|
487
488
|
}
|
|
488
489
|
/**
|
|
489
|
-
* Executes a strategy against
|
|
490
|
+
* Executes a strategy against a supplied execution context.
|
|
490
491
|
* This is the recommended API for new consumers. It intentionally bypasses
|
|
491
492
|
* all legacy vault, pool, subgraph, clock, and block-estimation reads.
|
|
492
493
|
*/
|
|
493
494
|
async executeWithContext(options) {
|
|
494
495
|
const vaultConfig = this.parseVaultConfig(options.vaultConfig);
|
|
495
|
-
|
|
496
|
-
const
|
|
496
|
+
this.validateExecutionContext(options.executionContext, vaultConfig);
|
|
497
|
+
const executionContext = {
|
|
498
|
+
...options.executionContext,
|
|
499
|
+
positions: options.executionContext.positions.map((position) => ({
|
|
500
|
+
...position,
|
|
501
|
+
})),
|
|
502
|
+
};
|
|
503
|
+
const dataConnector = new DataConnector({
|
|
504
|
+
wasmFile: options.wasmFile,
|
|
505
|
+
config: options.vaultConfig,
|
|
506
|
+
executionConfig: this.config,
|
|
507
|
+
});
|
|
497
508
|
try {
|
|
498
509
|
await dataConnector.loadSync();
|
|
499
|
-
dataConnector.
|
|
510
|
+
dataConnector.initializeStrategyWithContext(executionContext, options.forceDeposit);
|
|
500
511
|
const result = await dataConnector.executeBundle(options.data.map((item) => JSON.stringify(item)));
|
|
501
|
-
return
|
|
512
|
+
return this.parseStrategyResult(result);
|
|
502
513
|
}
|
|
503
514
|
catch (error) {
|
|
504
515
|
if (error instanceof ExecutionContextError)
|
|
@@ -506,98 +517,92 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
506
517
|
throw new StrategyExecutionError(this.redactError(error));
|
|
507
518
|
}
|
|
508
519
|
}
|
|
520
|
+
/** T is the complete decoded JSON result. Only the exact sentinel skips JSON decoding. */
|
|
521
|
+
parseStrategyResult(result) {
|
|
522
|
+
if (result === "continue")
|
|
523
|
+
return result;
|
|
524
|
+
try {
|
|
525
|
+
return JSON.parse(result);
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
throw new StrategyExecutionError(this.redactError(error));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
509
531
|
parseVaultConfig(vaultConfig) {
|
|
510
532
|
try {
|
|
511
533
|
return JSON.parse(vaultConfig);
|
|
512
534
|
}
|
|
513
535
|
catch {
|
|
514
|
-
throw new ExecutionContextError(
|
|
536
|
+
throw new ExecutionContextError("INVALID_EXECUTION_CONTEXT", "vaultConfig must be valid JSON.");
|
|
515
537
|
}
|
|
516
538
|
}
|
|
517
|
-
|
|
518
|
-
if (!context || typeof context !==
|
|
519
|
-
throw new ExecutionContextError(
|
|
539
|
+
validateExecutionContext(context, vaultConfig) {
|
|
540
|
+
if (!context || typeof context !== "object") {
|
|
541
|
+
throw new ExecutionContextError("INVALID_EXECUTION_CONTEXT", "An execution context is required.");
|
|
520
542
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
if (!Number.isInteger(context.chainId) ||
|
|
543
|
+
if (!Number.isSafeInteger(context.chainId) ||
|
|
544
|
+
!Number.isSafeInteger(context.blockNumber) ||
|
|
545
|
+
context.blockNumber < 0 ||
|
|
546
|
+
!Number.isSafeInteger(context.epochTimestamp) ||
|
|
547
|
+
context.epochTimestamp < 0 ||
|
|
548
|
+
!Number.isSafeInteger(context.executionTimestamp) ||
|
|
549
|
+
context.executionTimestamp < 0 ||
|
|
550
|
+
context.executionTimestamp !== context.epochTimestamp * 1000 ||
|
|
551
|
+
!Number.isFinite(context.epochLength) ||
|
|
552
|
+
!Number.isFinite(context.blockTime) ||
|
|
534
553
|
!Number.isInteger(context.currentTick) ||
|
|
535
|
-
!Number.isInteger(context.tickSpacing)
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
!/^\d+$/.test(context.
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
554
|
+
!Number.isInteger(context.tickSpacing) ||
|
|
555
|
+
typeof context.vaultAddress !== "string" ||
|
|
556
|
+
context.vaultAddress.length === 0 ||
|
|
557
|
+
typeof context.totalAmount0 !== "string" ||
|
|
558
|
+
!/^\d+$/.test(context.totalAmount0) ||
|
|
559
|
+
typeof context.totalAmount1 !== "string" ||
|
|
560
|
+
!/^\d+$/.test(context.totalAmount1) ||
|
|
561
|
+
!Array.isArray(context.positions) ||
|
|
562
|
+
!Number.isFinite(context.lastExecutionTime) ||
|
|
563
|
+
context.lastExecutionTime < 0) {
|
|
564
|
+
throw new ExecutionContextError("INVALID_EXECUTION_CONTEXT", "Execution context is malformed.");
|
|
545
565
|
}
|
|
546
566
|
const sameAddress = (left, right) => left?.toLowerCase() === right?.toLowerCase();
|
|
547
567
|
if (!sameAddress(this.vault, context.vaultAddress) ||
|
|
548
568
|
!sameAddress(vaultConfig.vaultAddress, context.vaultAddress)) {
|
|
549
|
-
throw new ExecutionContextError(
|
|
569
|
+
throw new ExecutionContextError("EXECUTION_CONTEXT_MISMATCH", "Supplied context vault does not match the execution request.");
|
|
550
570
|
}
|
|
551
571
|
if (this.chainId !== context.chainId ||
|
|
552
|
-
(vaultConfig.chainId !== undefined &&
|
|
553
|
-
|
|
572
|
+
(vaultConfig.chainId !== undefined &&
|
|
573
|
+
Number(vaultConfig.chainId) !== context.chainId)) {
|
|
574
|
+
throw new ExecutionContextError("EXECUTION_CONTEXT_MISMATCH", "Supplied context chain does not match the execution request.");
|
|
554
575
|
}
|
|
555
|
-
if (vaultConfig.anchorBlockNumber !== undefined &&
|
|
556
|
-
|
|
576
|
+
if (vaultConfig.anchorBlockNumber !== undefined &&
|
|
577
|
+
String(vaultConfig.anchorBlockNumber) !== String(context.blockNumber)) {
|
|
578
|
+
throw new ExecutionContextError("EXECUTION_CONTEXT_MISMATCH", "Supplied context block does not match anchorBlockNumber.");
|
|
557
579
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
throw new ExecutionContextError(
|
|
580
|
+
if (Number(vaultConfig.strategyConfigData?.epochLength) !==
|
|
581
|
+
context.epochLength) {
|
|
582
|
+
throw new ExecutionContextError("EXECUTION_CONTEXT_MISMATCH", "Supplied context epoch length does not match vaultConfig.");
|
|
561
583
|
}
|
|
562
584
|
for (const position of context.positions) {
|
|
563
|
-
if (!
|
|
564
|
-
!Number.isInteger(position.
|
|
565
|
-
!Number.
|
|
566
|
-
|
|
585
|
+
if (!position ||
|
|
586
|
+
!Number.isInteger(position.startTick) ||
|
|
587
|
+
!Number.isInteger(position.endTick) ||
|
|
588
|
+
!Number.isFinite(position.weight)) {
|
|
589
|
+
throw new ExecutionContextError("INVALID_EXECUTION_CONTEXT", "Execution context contains an invalid position.");
|
|
567
590
|
}
|
|
568
591
|
}
|
|
569
|
-
// Null is deterministic: WASM receives zero elapsed seconds, never wall-clock time.
|
|
570
|
-
const lastExecutionTime = context.lastExecutionTimeSeconds === null ? 0 : Number(context.lastExecutionTimeSeconds);
|
|
571
|
-
if (!Number.isFinite(lastExecutionTime) || lastExecutionTime < 0) {
|
|
572
|
-
throw new ExecutionContextError('INVALID_EXECUTION_CONTEXT', 'SDK execution context has invalid lastExecutionTimeSeconds.');
|
|
573
|
-
}
|
|
574
|
-
return {
|
|
575
|
-
executionTimestamp: Number(context.epochTimestamp) * 1000,
|
|
576
|
-
epochTimestamp: Number(context.epochTimestamp),
|
|
577
|
-
epochLength,
|
|
578
|
-
vaultAddress: context.vaultAddress,
|
|
579
|
-
blockTime: 0,
|
|
580
|
-
blockNumber: Number(context.blockNumber),
|
|
581
|
-
currentTick: context.currentTick,
|
|
582
|
-
tickSpacing: context.tickSpacing,
|
|
583
|
-
positions: context.positions.map(({ lowerTick, upperTick, relativeWeight }) => ({
|
|
584
|
-
startTick: lowerTick,
|
|
585
|
-
endTick: upperTick,
|
|
586
|
-
weight: relativeWeight,
|
|
587
|
-
})),
|
|
588
|
-
totalAmount0: context.totalAmount0,
|
|
589
|
-
totalAmount1: context.totalAmount1,
|
|
590
|
-
lastExecutionTime,
|
|
591
|
-
};
|
|
592
592
|
}
|
|
593
593
|
redactError(error) {
|
|
594
594
|
const message = error instanceof Error ? error.message : String(error);
|
|
595
595
|
return message
|
|
596
|
-
.replace(/https?:\/\/[^\s@/]+(?::[^\s@/]+)?@/gi,
|
|
597
|
-
.replace(/([?&](?:key|token|api[_-]?key|password)=)[^&\s]+/gi,
|
|
596
|
+
.replace(/https?:\/\/[^\s@/]+(?::[^\s@/]+)?@/gi, "https://[REDACTED]@")
|
|
597
|
+
.replace(/([?&](?:key|token|api[_-]?key|password)=)[^&\s]+/gi, "$1[REDACTED]");
|
|
598
598
|
}
|
|
599
|
-
async executeStabilityVault(_wasmFile, _vaultConfig, _data,
|
|
600
|
-
const dataConnector = new DataConnector(
|
|
599
|
+
async executeStabilityVault(_wasmFile, _vaultConfig, _data, rpc, forceDeposit) {
|
|
600
|
+
const dataConnector = new DataConnector({
|
|
601
|
+
wasmFile: _wasmFile,
|
|
602
|
+
config: _vaultConfig,
|
|
603
|
+
executionConfig: this.config,
|
|
604
|
+
rpc,
|
|
605
|
+
});
|
|
601
606
|
await dataConnector.loadSync();
|
|
602
607
|
const executionContext = await this.getExecutionContext(dataConnector, JSON.parse(_vaultConfig));
|
|
603
608
|
const dynamicJobExecutionContext = {};
|
|
@@ -607,15 +612,20 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
607
612
|
}, forceDeposit);
|
|
608
613
|
_data = _data.map((element) => JSON.stringify(element));
|
|
609
614
|
const result = await dataConnector.executeDynamicJobBundle(_data);
|
|
610
|
-
return
|
|
615
|
+
return this.parseStrategyResult(result);
|
|
611
616
|
}
|
|
612
|
-
async executeDynamicJobs(_wasmFile, _vaultConfig, _data, _job,
|
|
613
|
-
const dataConnector = new DataConnector(
|
|
617
|
+
async executeDynamicJobs(_wasmFile, _vaultConfig, _data, _job, rpc, forceDeposit) {
|
|
618
|
+
const dataConnector = new DataConnector({
|
|
619
|
+
wasmFile: _wasmFile,
|
|
620
|
+
config: _vaultConfig,
|
|
621
|
+
executionConfig: this.config,
|
|
622
|
+
rpc,
|
|
623
|
+
});
|
|
614
624
|
await dataConnector.loadSync();
|
|
615
625
|
const executionContext = await this.getExecutionContext(dataConnector, JSON.parse(_vaultConfig));
|
|
616
626
|
const smartRewardsContractAddress = _job.targetAddresses[0];
|
|
617
627
|
if (!smartRewardsContractAddress) {
|
|
618
|
-
throw new Error(
|
|
628
|
+
throw new Error("Dynamic job must include at least one target address");
|
|
619
629
|
}
|
|
620
630
|
const dynamicJobExecutionContext = {
|
|
621
631
|
smartRewardsContractAddress,
|
|
@@ -626,18 +636,20 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
626
636
|
}, forceDeposit);
|
|
627
637
|
_data = _data.map((element) => JSON.stringify(element));
|
|
628
638
|
const result = await dataConnector.executeDynamicJobBundle(_data);
|
|
629
|
-
return
|
|
639
|
+
return this.parseStrategyResult(result);
|
|
630
640
|
}
|
|
631
|
-
async getSmartPoolExecutionContext(currentExecutionContext, dataConnector, vaultConfig
|
|
641
|
+
async getSmartPoolExecutionContext(currentExecutionContext, dataConnector, vaultConfig) {
|
|
632
642
|
const smartPoolExecutionContext = {};
|
|
633
643
|
const request = {
|
|
634
|
-
method:
|
|
644
|
+
method: "POST",
|
|
635
645
|
url: this.steerSubgraph,
|
|
636
646
|
headers: {
|
|
637
|
-
|
|
638
|
-
?
|
|
639
|
-
:
|
|
640
|
-
...(this.steerSubgraph.includes(
|
|
647
|
+
"Content-Type": !this.steerSubgraph.includes("subgraph-proxy-server")
|
|
648
|
+
? "application/json"
|
|
649
|
+
: "text/plain;charset=UTF-8",
|
|
650
|
+
...(this.steerSubgraph.includes("sentio")
|
|
651
|
+
? { "api-key": this.sentioApiKey }
|
|
652
|
+
: {}),
|
|
641
653
|
},
|
|
642
654
|
data: {
|
|
643
655
|
query: `
|
|
@@ -657,15 +669,17 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
657
669
|
},
|
|
658
670
|
};
|
|
659
671
|
const response = await fetchData(request, 4);
|
|
660
|
-
this.log(
|
|
672
|
+
this.log("Subgraph response vault positions :", response);
|
|
661
673
|
const requestSnapshot = {
|
|
662
|
-
method:
|
|
674
|
+
method: "POST",
|
|
663
675
|
url: this.steerSubgraph,
|
|
664
676
|
headers: {
|
|
665
|
-
|
|
666
|
-
?
|
|
667
|
-
:
|
|
668
|
-
...(this.steerSubgraph.includes(
|
|
677
|
+
"Content-Type": !this.steerSubgraph.includes("subgraph-proxy-server")
|
|
678
|
+
? "application/json"
|
|
679
|
+
: "text/plain;charset=UTF-8",
|
|
680
|
+
...(this.steerSubgraph.includes("sentio")
|
|
681
|
+
? { "api-key": this.sentioApiKey }
|
|
682
|
+
: {}),
|
|
669
683
|
},
|
|
670
684
|
data: {
|
|
671
685
|
query: `
|
|
@@ -682,9 +696,10 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
682
696
|
},
|
|
683
697
|
};
|
|
684
698
|
const responseSnapshot = await fetchData(requestSnapshot, 4);
|
|
685
|
-
this.log(
|
|
699
|
+
this.log("Subgraph response current snapshot", responseSnapshot);
|
|
686
700
|
const positions = [];
|
|
687
|
-
if (response?.data?.vaultPositions &&
|
|
701
|
+
if (response?.data?.vaultPositions &&
|
|
702
|
+
response?.data?.vaultPositions.length > 0) {
|
|
688
703
|
const positionResponse = response?.data?.vaultPositions[0];
|
|
689
704
|
for (let i = 0; i < positionResponse.upperTick.length; i++) {
|
|
690
705
|
const position = positionResponse;
|
|
@@ -696,25 +711,31 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
696
711
|
}
|
|
697
712
|
}
|
|
698
713
|
let lastSnapshot;
|
|
699
|
-
if (responseSnapshot?.data?.vaultSnapshots &&
|
|
714
|
+
if (responseSnapshot?.data?.vaultSnapshots &&
|
|
715
|
+
responseSnapshot?.data?.vaultSnapshots.length > 0) {
|
|
700
716
|
lastSnapshot = responseSnapshot?.data?.vaultSnapshots[0];
|
|
701
717
|
}
|
|
702
|
-
this.log(
|
|
718
|
+
this.log("Subgraph response vault positions", positions);
|
|
703
719
|
smartPoolExecutionContext.positions = positions;
|
|
704
720
|
if (lastSnapshot) {
|
|
705
|
-
smartPoolExecutionContext.lastExecutionTime =
|
|
721
|
+
smartPoolExecutionContext.lastExecutionTime =
|
|
722
|
+
(Date.now() - Number(lastSnapshot.timestamp) * 1000) / 1000;
|
|
706
723
|
}
|
|
707
724
|
else {
|
|
708
|
-
smartPoolExecutionContext.lastExecutionTime =
|
|
725
|
+
smartPoolExecutionContext.lastExecutionTime =
|
|
726
|
+
currentExecutionContext.epochTimestamp;
|
|
709
727
|
}
|
|
710
|
-
const provider = dataConnector.
|
|
728
|
+
const provider = dataConnector.getClient();
|
|
711
729
|
if (!provider) {
|
|
712
|
-
throw new Error(
|
|
730
|
+
throw new Error("Provider configuration issue, unable to process Smart Pool execution context.");
|
|
731
|
+
}
|
|
732
|
+
if ((await provider.getChainId()) !== currentExecutionContext.chainId) {
|
|
733
|
+
throw new Error("EXECUTION_CONTEXT_MISMATCH: provider chain does not match supplied context.");
|
|
713
734
|
}
|
|
714
735
|
const poolAddress = await this.getVaultPoolAddress();
|
|
715
|
-
const currentTick = await this.getPoolCurrentTick(poolAddress, provider, currentExecutionContext
|
|
716
|
-
const tickSpacing = await this.getTickSpacing(poolAddress, provider,
|
|
717
|
-
const totalAmounts = await this.getTotalAmounts(this.vault, currentExecutionContext, provider
|
|
736
|
+
const currentTick = await this.getPoolCurrentTick(poolAddress, provider, currentExecutionContext);
|
|
737
|
+
const tickSpacing = await this.getTickSpacing(poolAddress, provider, currentExecutionContext);
|
|
738
|
+
const totalAmounts = await this.getTotalAmounts(this.vault, currentExecutionContext, provider);
|
|
718
739
|
// Handle both bigint and serialized bigint from centralized API
|
|
719
740
|
smartPoolExecutionContext.totalAmount0 = this.convertToString(totalAmounts.total0);
|
|
720
741
|
smartPoolExecutionContext.totalAmount1 = this.convertToString(totalAmounts.total1);
|
|
@@ -723,58 +744,56 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
723
744
|
// "currentTick": 10,
|
|
724
745
|
return smartPoolExecutionContext;
|
|
725
746
|
}
|
|
726
|
-
async getPoolCurrentTick(poolAddress, provider, currentExecutionContext
|
|
747
|
+
async getPoolCurrentTick(poolAddress, provider, currentExecutionContext) {
|
|
727
748
|
if (this.isAlgebraPool || this.isPoolSharkPool) {
|
|
728
|
-
const slot0 = await this.getGlobalState(poolAddress, currentExecutionContext, provider
|
|
749
|
+
const slot0 = await this.getGlobalState(poolAddress, currentExecutionContext, provider);
|
|
729
750
|
return slot0.tick;
|
|
730
751
|
}
|
|
731
752
|
else if (this.isAerodromePool) {
|
|
732
|
-
const slot0 = await this.getSlot0Aerodrome(poolAddress, currentExecutionContext, provider
|
|
753
|
+
const slot0 = await this.getSlot0Aerodrome(poolAddress, currentExecutionContext, provider);
|
|
733
754
|
return slot0.tick;
|
|
734
755
|
}
|
|
735
756
|
else {
|
|
736
|
-
const slot0 = await this.getSlot0(poolAddress, currentExecutionContext, provider
|
|
757
|
+
const slot0 = await this.getSlot0(poolAddress, currentExecutionContext, provider);
|
|
737
758
|
return slot0.tick;
|
|
738
759
|
}
|
|
739
760
|
}
|
|
740
|
-
async getTickSpacing(poolAddress, provider,
|
|
761
|
+
async getTickSpacing(poolAddress, provider, currentExecutionContext) {
|
|
741
762
|
const tickSpacingAbi = [
|
|
742
763
|
this.isPoolSharkPool
|
|
743
764
|
? {
|
|
744
765
|
inputs: [],
|
|
745
|
-
name:
|
|
766
|
+
name: "tickSpacing",
|
|
746
767
|
outputs: [
|
|
747
768
|
{
|
|
748
|
-
internalType:
|
|
749
|
-
name:
|
|
750
|
-
type:
|
|
769
|
+
internalType: "int24",
|
|
770
|
+
name: "",
|
|
771
|
+
type: "int24",
|
|
751
772
|
},
|
|
752
773
|
],
|
|
753
|
-
stateMutability:
|
|
754
|
-
type:
|
|
774
|
+
stateMutability: "view",
|
|
775
|
+
type: "function",
|
|
755
776
|
}
|
|
756
777
|
: {
|
|
757
778
|
inputs: [],
|
|
758
|
-
name:
|
|
779
|
+
name: "tickSpacing",
|
|
759
780
|
outputs: [
|
|
760
781
|
{
|
|
761
|
-
internalType:
|
|
762
|
-
name:
|
|
763
|
-
type:
|
|
782
|
+
internalType: "int16",
|
|
783
|
+
name: "",
|
|
784
|
+
type: "int16",
|
|
764
785
|
},
|
|
765
786
|
],
|
|
766
|
-
stateMutability:
|
|
767
|
-
type:
|
|
787
|
+
stateMutability: "pure",
|
|
788
|
+
type: "function",
|
|
768
789
|
},
|
|
769
790
|
];
|
|
770
791
|
const tickSpacing = await readContract({
|
|
771
792
|
address: poolAddress,
|
|
772
793
|
abi: tickSpacingAbi,
|
|
773
794
|
currentExecutionContext,
|
|
774
|
-
functionName:
|
|
795
|
+
functionName: "tickSpacing",
|
|
775
796
|
provider,
|
|
776
|
-
rpc,
|
|
777
|
-
chainId: this.chainId,
|
|
778
797
|
});
|
|
779
798
|
return tickSpacing;
|
|
780
799
|
}
|
|
@@ -783,17 +802,17 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
783
802
|
* from the centralized API
|
|
784
803
|
*/
|
|
785
804
|
convertToString(value) {
|
|
786
|
-
if (typeof value ===
|
|
805
|
+
if (typeof value === "bigint") {
|
|
787
806
|
return value.toString();
|
|
788
807
|
}
|
|
789
|
-
if (typeof value ===
|
|
808
|
+
if (typeof value === "number") {
|
|
790
809
|
return value.toString();
|
|
791
810
|
}
|
|
792
|
-
if (typeof value ===
|
|
811
|
+
if (typeof value === "string") {
|
|
793
812
|
return value;
|
|
794
813
|
}
|
|
795
814
|
// Handle serialized bigint from centralized API (e.g., { type: 'BigNumber', hex: '0x...' })
|
|
796
|
-
if (value && typeof value ===
|
|
815
|
+
if (value && typeof value === "object") {
|
|
797
816
|
// If it's a BigNumber-like object with hex property
|
|
798
817
|
if (value.hex !== undefined) {
|
|
799
818
|
return BigInt(value.hex).toString();
|
|
@@ -803,34 +822,33 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
803
822
|
return BigInt(value._hex).toString();
|
|
804
823
|
}
|
|
805
824
|
// If it has toString method, try using it
|
|
806
|
-
if (typeof value.toString ===
|
|
825
|
+
if (typeof value.toString === "function" &&
|
|
826
|
+
value.toString() !== "[object Object]") {
|
|
807
827
|
return value.toString();
|
|
808
828
|
}
|
|
809
829
|
}
|
|
810
830
|
// Fallback: convert to string (may result in '[object Object]' if not handled above)
|
|
811
831
|
return String(value);
|
|
812
832
|
}
|
|
813
|
-
async getTotalAmounts(vaultAddress, currentExecutionContext, provider
|
|
833
|
+
async getTotalAmounts(vaultAddress, currentExecutionContext, provider) {
|
|
814
834
|
const getTotalAmountsABI = [
|
|
815
835
|
{
|
|
816
836
|
inputs: [],
|
|
817
|
-
name:
|
|
837
|
+
name: "getTotalAmounts",
|
|
818
838
|
outputs: [
|
|
819
|
-
{ internalType:
|
|
820
|
-
{ internalType:
|
|
839
|
+
{ internalType: "uint256", name: "total0", type: "uint256" },
|
|
840
|
+
{ internalType: "uint256", name: "total1", type: "uint256" },
|
|
821
841
|
],
|
|
822
|
-
stateMutability:
|
|
823
|
-
type:
|
|
842
|
+
stateMutability: "view",
|
|
843
|
+
type: "function",
|
|
824
844
|
},
|
|
825
845
|
];
|
|
826
846
|
const totalAmounts = await readContract({
|
|
827
847
|
address: vaultAddress,
|
|
828
848
|
abi: getTotalAmountsABI,
|
|
829
849
|
currentExecutionContext,
|
|
830
|
-
functionName:
|
|
850
|
+
functionName: "getTotalAmounts",
|
|
831
851
|
provider,
|
|
832
|
-
rpc,
|
|
833
|
-
chainId: this.chainId,
|
|
834
852
|
});
|
|
835
853
|
return {
|
|
836
854
|
total0: totalAmounts[0],
|
|
@@ -839,7 +857,7 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
839
857
|
}
|
|
840
858
|
async getVaultPoolAddress() {
|
|
841
859
|
const requestSnapshot = {
|
|
842
|
-
method:
|
|
860
|
+
method: "POST",
|
|
843
861
|
url: this.steerSubgraph,
|
|
844
862
|
data: {
|
|
845
863
|
query: `
|
|
@@ -852,10 +870,12 @@ export class ExecutionApp extends ExecutionBase {
|
|
|
852
870
|
`,
|
|
853
871
|
},
|
|
854
872
|
headers: {
|
|
855
|
-
|
|
856
|
-
?
|
|
857
|
-
:
|
|
858
|
-
...(this.steerSubgraph.includes(
|
|
873
|
+
"Content-Type": !this.steerSubgraph.includes("subgraph-proxy-server")
|
|
874
|
+
? "application/json"
|
|
875
|
+
: "text/plain;charset=UTF-8",
|
|
876
|
+
...(this.steerSubgraph.includes("sentio")
|
|
877
|
+
? { "api-key": this.sentioApiKey }
|
|
878
|
+
: {}),
|
|
859
879
|
},
|
|
860
880
|
};
|
|
861
881
|
const response = await fetchData(requestSnapshot, 4);
|