@steerprotocol/app-loader 3.0.6 → 3.1.0
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 +86 -0
- package/lib/browser.d.ts +5 -2
- package/lib/browser.mjs +247 -72
- package/lib/browser.mjs.map +1 -1
- package/lib/index.cjs +3687 -107
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +5 -2
- package/lib/index.mjs +3687 -107
- package/lib/index.mjs.map +1 -1
- package/lib/internal/asyncHostCalls.d.ts +37 -0
- package/lib/internal/instantiate.d.ts +3 -4
- package/lib/internal/loadOptions.d.ts +1 -0
- package/lib/internal/panoptic/deps.d.ts +24 -0
- package/lib/internal/panoptic/dynamicJobs/fragments.d.ts +10 -0
- package/lib/internal/panoptic/dynamicJobs/renderExecuteJob.d.ts +8 -0
- package/lib/internal/panoptic/fragments/collateral.d.ts +5 -0
- package/lib/internal/panoptic/fragments/erc20.d.ts +3 -0
- package/lib/internal/panoptic/fragments/hypovault.d.ts +12 -0
- package/lib/internal/panoptic/fragments/merkle.d.ts +22 -0
- package/lib/internal/panoptic/fragments/panoptic.d.ts +17 -0
- package/lib/internal/panoptic/fragments/permit2.d.ts +3 -0
- package/lib/internal/panoptic/fragments/support.d.ts +16 -0
- package/lib/internal/panoptic/fragments/uniswap.d.ts +10 -0
- package/lib/internal/panoptic/fragments/weth.d.ts +19 -0
- package/lib/internal/panoptic/handlers.d.ts +27 -0
- package/lib/internal/panoptic/protocol.d.ts +29 -0
- package/lib/internal/panoptic/reads/account.d.ts +11 -0
- package/lib/internal/panoptic/reads/greeks.d.ts +5 -0
- package/lib/internal/panoptic/reads/hypovault.d.ts +7 -0
- package/lib/internal/panoptic/reads/pool.d.ts +10 -0
- package/lib/internal/panoptic/reads/uniswap.d.ts +6 -0
- package/lib/internal/panoptic/support.d.ts +20 -0
- package/lib/internal/panopticBrowserRuntime.d.ts +6 -0
- package/lib/internal/panopticDtos.d.ts +72 -0
- package/lib/internal/panopticHostEnvelope.d.ts +2 -0
- package/lib/internal/panopticHostImport.d.ts +17 -0
- package/lib/internal/panopticJsonArgs.d.ts +26 -0
- package/lib/internal/panopticRuntime.d.ts +12 -0
- package/lib/internal/panopticScalars.d.ts +10 -0
- package/lib/internal/panopticSerialization.d.ts +19 -0
- package/lib/internal/panopticSources.d.ts +22 -0
- package/lib/loadOptions.d.ts +5 -0
- package/lib/node.cjs +3634 -72
- package/lib/node.cjs.map +1 -1
- package/lib/node.d.ts +5 -2
- package/lib/node.mjs +3634 -72
- package/lib/node.mjs.map +1 -1
- package/lib/panoptic.cjs +19 -0
- package/lib/panoptic.cjs.map +1 -0
- package/lib/panoptic.d.ts +56 -0
- package/lib/panoptic.mjs +1 -0
- package/lib/panoptic.mjs.map +1 -0
- package/package.json +44 -3
package/lib/node.mjs
CHANGED
|
@@ -173,6 +173,160 @@ var RawTradeData = class {
|
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
175
|
|
|
176
|
+
// src/internal/asyncHostCalls.ts
|
|
177
|
+
function createAsyncHostCallSlot() {
|
|
178
|
+
let stagedHostCall = null;
|
|
179
|
+
let completedHostCall = null;
|
|
180
|
+
function stage(call) {
|
|
181
|
+
if (stagedHostCall || completedHostCall) {
|
|
182
|
+
throw new Error("Only one async host call can be staged per asyncify unwind.");
|
|
183
|
+
}
|
|
184
|
+
stagedHostCall = call;
|
|
185
|
+
}
|
|
186
|
+
async function complete() {
|
|
187
|
+
if (!stagedHostCall) {
|
|
188
|
+
throw new Error("Asyncify unwound without a staged host call.");
|
|
189
|
+
}
|
|
190
|
+
const call = stagedHostCall;
|
|
191
|
+
stagedHostCall = null;
|
|
192
|
+
if (call.kind === "fetch-buffer") {
|
|
193
|
+
completedHostCall = { kind: "fetch-buffer", value: await call.run() };
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (call.kind === "ccxt-ohlcv") {
|
|
197
|
+
completedHostCall = { kind: "ccxt-ohlcv", value: await call.run() };
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
completedHostCall = { kind: "panoptic-json", value: await call.run() };
|
|
201
|
+
}
|
|
202
|
+
function take(kind) {
|
|
203
|
+
if (!completedHostCall) {
|
|
204
|
+
throw new Error(`Asyncify rewind for ${kind} did not have a completed host result.`);
|
|
205
|
+
}
|
|
206
|
+
if (completedHostCall.kind !== kind) {
|
|
207
|
+
throw new Error(`Asyncify rewind expected ${kind} but found ${completedHostCall.kind}.`);
|
|
208
|
+
}
|
|
209
|
+
const call = completedHostCall;
|
|
210
|
+
completedHostCall = null;
|
|
211
|
+
return call;
|
|
212
|
+
}
|
|
213
|
+
function reset() {
|
|
214
|
+
stagedHostCall = null;
|
|
215
|
+
completedHostCall = null;
|
|
216
|
+
}
|
|
217
|
+
return { stage, complete, take, reset };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/internal/panoptic/protocol.ts
|
|
221
|
+
var DEFAULT_MAX_REQUEST_BYTES = 512 * 1024;
|
|
222
|
+
function parsePanopticRequest(value, maxBytes = DEFAULT_MAX_REQUEST_BYTES) {
|
|
223
|
+
if (utf8ByteLength(value) > maxBytes) {
|
|
224
|
+
throw new Error(`Invalid Panoptic request JSON: request exceeds maximum size ${maxBytes} bytes.`);
|
|
225
|
+
}
|
|
226
|
+
let parsed;
|
|
227
|
+
try {
|
|
228
|
+
parsed = JSON.parse(value);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
throw new Error(`Invalid Panoptic request JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
231
|
+
}
|
|
232
|
+
if (!isJsonObject(parsed) || !isJsonValue(parsed)) {
|
|
233
|
+
throw new Error("Invalid Panoptic request JSON: expected a JSON-safe object envelope.");
|
|
234
|
+
}
|
|
235
|
+
return parsed;
|
|
236
|
+
}
|
|
237
|
+
function assertPanopticSuccessResponse(value) {
|
|
238
|
+
const keys = isJsonObject(value) ? Object.keys(value) : [];
|
|
239
|
+
if (!isJsonObject(value) || value.ok !== true || !("result" in value) || !isJsonValue(value.result) || keys.length !== 2 || !keys.includes("ok") || !keys.includes("result")) {
|
|
240
|
+
throw new Error("Panoptic runtime adapter returned an invalid success response.");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function panopticSuccess(result) {
|
|
244
|
+
return { ok: true, result };
|
|
245
|
+
}
|
|
246
|
+
function isJsonObject(value) {
|
|
247
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
const prototype = Object.getPrototypeOf(value);
|
|
251
|
+
return prototype === Object.prototype || prototype === null;
|
|
252
|
+
}
|
|
253
|
+
function isJsonRecord(value) {
|
|
254
|
+
return isJsonObject(value) && isJsonValue(value);
|
|
255
|
+
}
|
|
256
|
+
function requestArgs(request, method) {
|
|
257
|
+
if (!isJsonRecord(request.args)) {
|
|
258
|
+
throw new Error(`Panoptic ${method} args must be an object.`);
|
|
259
|
+
}
|
|
260
|
+
return request.args;
|
|
261
|
+
}
|
|
262
|
+
function sanitizePanopticError(error) {
|
|
263
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
264
|
+
return message.split("\n")[0].replace(/https?:\/\/[^\s)]+/gi, "[redacted-url]").replace(/\b(api[_-]?key|token|secret|authorization)=([^&\s]+)/gi, "$1=[redacted]").replace(/\b(authorization|proxy-authorization)\s*:\s*(bearer|basic)\s+[^\s,}]+/gi, "$1: $2 [redacted]").replace(/\b(bearer|basic)\s+[a-z0-9._~+/-]+=*/gi, "$1 [redacted]").replace(/"(api[_-]?key|token|secret|authorization)"\s*:\s*"[^"]*"/gi, '"$1":"[redacted]"').replace(/\b(api[_-]?key|token|secret)\s*:\s*([^\s,}]+)/gi, "$1: [redacted]").slice(0, 240);
|
|
265
|
+
}
|
|
266
|
+
function isJsonValue(value) {
|
|
267
|
+
if (value === null) return true;
|
|
268
|
+
const valueType = typeof value;
|
|
269
|
+
if (valueType === "string" || valueType === "number" || valueType === "boolean") {
|
|
270
|
+
return Number.isFinite(value) || valueType !== "number";
|
|
271
|
+
}
|
|
272
|
+
if (Array.isArray(value)) {
|
|
273
|
+
return value.every(isJsonValue);
|
|
274
|
+
}
|
|
275
|
+
if (isJsonObject(value)) {
|
|
276
|
+
return Object.values(value).every(isJsonValue);
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
function utf8ByteLength(value) {
|
|
281
|
+
let bytes = 0;
|
|
282
|
+
for (let i = 0; i < value.length; i++) {
|
|
283
|
+
const codePoint = value.codePointAt(i) || 0;
|
|
284
|
+
if (codePoint <= 127) {
|
|
285
|
+
bytes += 1;
|
|
286
|
+
} else if (codePoint <= 2047) {
|
|
287
|
+
bytes += 2;
|
|
288
|
+
} else if (codePoint <= 65535) {
|
|
289
|
+
bytes += 3;
|
|
290
|
+
} else {
|
|
291
|
+
bytes += 4;
|
|
292
|
+
i += 1;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return bytes;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/internal/panopticHostImport.ts
|
|
299
|
+
function createPanopticHostImport(options) {
|
|
300
|
+
return (methodPtr, paramsJsonPtr) => {
|
|
301
|
+
if (options.getAsyncifyState() === options.rewindingState) {
|
|
302
|
+
options.stopRewind();
|
|
303
|
+
const completed = options.hostCalls.take("panoptic-json");
|
|
304
|
+
return options.lowerString(completed.value, "wasm");
|
|
305
|
+
}
|
|
306
|
+
const method = options.liftString(methodPtr);
|
|
307
|
+
const paramsJson = options.liftString(paramsJsonPtr) || "{}";
|
|
308
|
+
options.hostCalls.stage({
|
|
309
|
+
kind: "panoptic-json",
|
|
310
|
+
run: async () => {
|
|
311
|
+
if (!method) {
|
|
312
|
+
throw new Error("Panoptic method not provided.");
|
|
313
|
+
}
|
|
314
|
+
const request = parsePanopticRequest(paramsJson);
|
|
315
|
+
const response = await callPanopticOrThrow(options.runtime, method, request);
|
|
316
|
+
assertPanopticSuccessResponse(response);
|
|
317
|
+
return JSON.stringify({ ok: true, result: response.result });
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
options.startUnwind();
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
async function callPanopticOrThrow(runtime, method, request) {
|
|
324
|
+
if (!runtime.callPanoptic) {
|
|
325
|
+
throw new Error("Panoptic runtime adapter is not available in this runtime.");
|
|
326
|
+
}
|
|
327
|
+
return runtime.callPanoptic(method, request);
|
|
328
|
+
}
|
|
329
|
+
|
|
176
330
|
// src/internal/instantiate.ts
|
|
177
331
|
function instantiate(module, imports = {}, runtime = {}) {
|
|
178
332
|
let WASM_MEMORY;
|
|
@@ -181,9 +335,7 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
181
335
|
let ASYNCIFY_PTR = 0;
|
|
182
336
|
let ASYNCIFY_MEM;
|
|
183
337
|
let ASYNCIFY_INITIALIZED = false;
|
|
184
|
-
|
|
185
|
-
let ccxtFn = null;
|
|
186
|
-
let detachedValue = null;
|
|
338
|
+
const hostCalls = createAsyncHostCallSlot();
|
|
187
339
|
let executeInFlight = false;
|
|
188
340
|
const pinScopes = [];
|
|
189
341
|
const adaptedImports = Object.assign(
|
|
@@ -281,31 +433,50 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
281
433
|
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
282
434
|
if (currentState === 2 /* Rewinding */) {
|
|
283
435
|
WASM_EXPORTS.asyncify_stop_rewind();
|
|
436
|
+
const completed = hostCalls.take("ccxt-ohlcv");
|
|
284
437
|
const ptr = __lowerStaticArray(
|
|
285
438
|
(pointer, value) => {
|
|
286
|
-
__setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array));
|
|
439
|
+
__setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array, "wasm"));
|
|
287
440
|
},
|
|
288
441
|
8,
|
|
289
442
|
2,
|
|
290
|
-
|
|
443
|
+
completed.value,
|
|
444
|
+
null,
|
|
445
|
+
"host"
|
|
291
446
|
);
|
|
292
447
|
return ptr;
|
|
293
448
|
}
|
|
294
449
|
const _exchange = __liftString(exchangeId);
|
|
295
450
|
const _symbol = __liftString(symbol);
|
|
296
451
|
const _timeframe = __liftString(timeframe);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
452
|
+
hostCalls.stage({
|
|
453
|
+
kind: "ccxt-ohlcv",
|
|
454
|
+
run: async () => {
|
|
455
|
+
if (!_exchange || !_symbol || !_timeframe)
|
|
456
|
+
throw new Error("Exchange, Symbol, or Timeframe not provided when fetching OHCLV data.");
|
|
457
|
+
const ccxt = await getCcxtOrThrow(runtime);
|
|
458
|
+
const data = await new ccxt[_exchange]({
|
|
459
|
+
apiKey: "",
|
|
460
|
+
secret: ""
|
|
461
|
+
}).fetchOHLCV(_symbol, _timeframe, since, limit);
|
|
462
|
+
return data;
|
|
463
|
+
}
|
|
464
|
+
});
|
|
307
465
|
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
308
|
-
}
|
|
466
|
+
},
|
|
467
|
+
panoptic_call: createPanopticHostImport({
|
|
468
|
+
runtime,
|
|
469
|
+
hostCalls,
|
|
470
|
+
// @ts-ignore
|
|
471
|
+
getAsyncifyState: () => WASM_EXPORTS.asyncify_get_state(),
|
|
472
|
+
rewindingState: 2 /* Rewinding */,
|
|
473
|
+
// @ts-ignore
|
|
474
|
+
stopRewind: () => WASM_EXPORTS.asyncify_stop_rewind(),
|
|
475
|
+
// @ts-ignore
|
|
476
|
+
startUnwind: () => WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR),
|
|
477
|
+
liftString: __liftString,
|
|
478
|
+
lowerString: __lowerString
|
|
479
|
+
})
|
|
309
480
|
},
|
|
310
481
|
"as-fetch": {
|
|
311
482
|
/**
|
|
@@ -336,25 +507,28 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
336
507
|
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
337
508
|
if (currentState === 2 /* Rewinding */) {
|
|
338
509
|
WASM_EXPORTS.asyncify_stop_rewind();
|
|
339
|
-
const
|
|
340
|
-
|
|
510
|
+
const completed = hostCalls.take("fetch-buffer");
|
|
511
|
+
const ptr = __lowerBuffer(completed.value, "wasm");
|
|
341
512
|
return ptr;
|
|
342
513
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
514
|
+
hostCalls.stage({
|
|
515
|
+
kind: "fetch-buffer",
|
|
516
|
+
run: async () => {
|
|
517
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
518
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
519
|
+
method: "POST",
|
|
520
|
+
mode: modeToString(mode) || "cors",
|
|
521
|
+
headers: __liftArray(
|
|
522
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
523
|
+
2,
|
|
524
|
+
headers
|
|
525
|
+
) || [],
|
|
526
|
+
body: __liftBuffer(body)
|
|
527
|
+
});
|
|
528
|
+
const value = await res.arrayBuffer();
|
|
529
|
+
return value;
|
|
530
|
+
}
|
|
531
|
+
});
|
|
358
532
|
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
359
533
|
},
|
|
360
534
|
/**
|
|
@@ -368,24 +542,27 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
368
542
|
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
369
543
|
if (currentState === 2 /* Rewinding */) {
|
|
370
544
|
WASM_EXPORTS.asyncify_stop_rewind();
|
|
371
|
-
const
|
|
372
|
-
|
|
545
|
+
const completed = hostCalls.take("fetch-buffer");
|
|
546
|
+
const ptr = __lowerBuffer(completed.value, "wasm");
|
|
373
547
|
return ptr;
|
|
374
548
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
549
|
+
hostCalls.stage({
|
|
550
|
+
kind: "fetch-buffer",
|
|
551
|
+
run: async () => {
|
|
552
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
553
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
554
|
+
method: "GET",
|
|
555
|
+
mode: modeToString(mode) || "cors",
|
|
556
|
+
headers: __liftArray(
|
|
557
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
558
|
+
2,
|
|
559
|
+
headers
|
|
560
|
+
) || []
|
|
561
|
+
});
|
|
562
|
+
const value = await res.arrayBuffer();
|
|
563
|
+
return value;
|
|
564
|
+
}
|
|
565
|
+
});
|
|
389
566
|
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
390
567
|
},
|
|
391
568
|
/**
|
|
@@ -516,16 +693,7 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
516
693
|
if (ASYNCIFY_INITIALIZED) {
|
|
517
694
|
while (WASM_EXPORTS.asyncify_get_state() === 1 /* Unwinding */) {
|
|
518
695
|
WASM_EXPORTS.asyncify_stop_unwind();
|
|
519
|
-
|
|
520
|
-
const pendingFetch = fetchFn;
|
|
521
|
-
fetchFn = null;
|
|
522
|
-
detachedValue = await pendingFetch();
|
|
523
|
-
}
|
|
524
|
-
if (ccxtFn) {
|
|
525
|
-
const pendingCcxt = ccxtFn;
|
|
526
|
-
ccxtFn = null;
|
|
527
|
-
detachedValue = await pendingCcxt();
|
|
528
|
-
}
|
|
696
|
+
await hostCalls.complete();
|
|
529
697
|
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
530
698
|
result = executeWithReplayArgs(replayArgs);
|
|
531
699
|
}
|
|
@@ -536,9 +704,7 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
536
704
|
for (let i = scope.length - 1; i >= 0; i--) {
|
|
537
705
|
WASM_EXPORTS.__unpin(scope[i]);
|
|
538
706
|
}
|
|
539
|
-
|
|
540
|
-
ccxtFn = null;
|
|
541
|
-
detachedValue = null;
|
|
707
|
+
hostCalls.reset();
|
|
542
708
|
executeInFlight = false;
|
|
543
709
|
}
|
|
544
710
|
},
|
|
@@ -632,10 +798,10 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
632
798
|
while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
|
|
633
799
|
return string + String.fromCharCode(...memoryU16.subarray(start, end));
|
|
634
800
|
}
|
|
635
|
-
function __lowerString(value) {
|
|
801
|
+
function __lowerString(value, owner = "host") {
|
|
636
802
|
if (value == null) return 0;
|
|
637
803
|
const length = value.length;
|
|
638
|
-
const ptr =
|
|
804
|
+
const ptr = allocateLoweredPointer(length << 1, 2, owner);
|
|
639
805
|
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
640
806
|
for (let i = 0; i < length; ++i) memoryU16[(ptr >>> 1) + i] = value.charCodeAt(i);
|
|
641
807
|
return ptr;
|
|
@@ -644,9 +810,9 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
644
810
|
if (!ptr) return null;
|
|
645
811
|
return WASM_MEMORY.buffer.slice(ptr, ptr + new Uint32Array(WASM_MEMORY.buffer)[ptr - 4 >>> 2]);
|
|
646
812
|
}
|
|
647
|
-
function __lowerBuffer(value) {
|
|
813
|
+
function __lowerBuffer(value, owner = "host") {
|
|
648
814
|
if (value == null) return 0;
|
|
649
|
-
const ptr =
|
|
815
|
+
const ptr = allocateLoweredPointer(value.byteLength, 1, owner);
|
|
650
816
|
new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);
|
|
651
817
|
return ptr;
|
|
652
818
|
}
|
|
@@ -658,10 +824,10 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
658
824
|
for (let i = 0; i < length; ++i) values[i] = liftElement(dataStart + (i << align >>> 0));
|
|
659
825
|
return values;
|
|
660
826
|
}
|
|
661
|
-
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null) {
|
|
827
|
+
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null, owner = "host") {
|
|
662
828
|
if (values == null) return 0;
|
|
663
829
|
const length = values.length;
|
|
664
|
-
const buffer =
|
|
830
|
+
const buffer = allocateLoweredPointer(length << align, id, owner) >>> 0;
|
|
665
831
|
if (typedConstructor) {
|
|
666
832
|
new typedConstructor(WASM_MEMORY.buffer, buffer, length).set(values);
|
|
667
833
|
} else {
|
|
@@ -669,6 +835,13 @@ function instantiate(module, imports = {}, runtime = {}) {
|
|
|
669
835
|
}
|
|
670
836
|
return buffer;
|
|
671
837
|
}
|
|
838
|
+
function allocateLoweredPointer(size, id, owner) {
|
|
839
|
+
const ptr = WASM_EXPORTS.__new(size, id) >>> 0;
|
|
840
|
+
if (owner === "wasm") {
|
|
841
|
+
return ptr;
|
|
842
|
+
}
|
|
843
|
+
return trackPinnedPointer(WASM_EXPORTS.__pin(ptr) >>> 0);
|
|
844
|
+
}
|
|
672
845
|
function __setU32(ptr, value) {
|
|
673
846
|
try {
|
|
674
847
|
WASM_DV.setUint32(ptr, value, true);
|
|
@@ -715,18 +888,3407 @@ function modeToString(mode) {
|
|
|
715
888
|
return null;
|
|
716
889
|
}
|
|
717
890
|
|
|
891
|
+
// src/internal/panoptic/deps.ts
|
|
892
|
+
var PANOPTIC_MODULE_SPECIFIERS = {
|
|
893
|
+
sdk: "@panoptic-eng/sdk",
|
|
894
|
+
sdkV2: "@panoptic-eng/sdk/v2",
|
|
895
|
+
uniswap: "@panoptic-eng/sdk/uniswap",
|
|
896
|
+
viem: "viem"
|
|
897
|
+
};
|
|
898
|
+
var dynamicImport = null;
|
|
899
|
+
var runtimeImport = null;
|
|
900
|
+
var moduleCache = /* @__PURE__ */ new Map();
|
|
901
|
+
function createPanopticDependencies() {
|
|
902
|
+
return {
|
|
903
|
+
sdk: () => loadPanopticModuleRecord("sdk"),
|
|
904
|
+
sdkV2: () => loadPanopticModuleRecord("sdkV2"),
|
|
905
|
+
uniswap: () => loadPanopticModuleRecord("uniswap"),
|
|
906
|
+
viem: () => loadPanopticModuleRecord("viem")
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
async function loadPanopticModule(key) {
|
|
910
|
+
const cached = moduleCache.get(key);
|
|
911
|
+
if (cached) {
|
|
912
|
+
return cached;
|
|
913
|
+
}
|
|
914
|
+
const specifier = PANOPTIC_MODULE_SPECIFIERS[key];
|
|
915
|
+
const loaded = getRuntimeImport()(specifier).catch(() => {
|
|
916
|
+
moduleCache.delete(key);
|
|
917
|
+
throw missingPanopticDependencyError(specifier);
|
|
918
|
+
});
|
|
919
|
+
moduleCache.set(key, loaded);
|
|
920
|
+
return loaded;
|
|
921
|
+
}
|
|
922
|
+
async function loadPanopticModuleRecord(key) {
|
|
923
|
+
const loadedModule = await loadPanopticModule(key);
|
|
924
|
+
if (!isRecord(loadedModule)) {
|
|
925
|
+
return {};
|
|
926
|
+
}
|
|
927
|
+
return loadedModule;
|
|
928
|
+
}
|
|
929
|
+
function missingPanopticDependencyError(specifier) {
|
|
930
|
+
return new Error(
|
|
931
|
+
`Panoptic runtime dependency "${specifier}" is not available. Install the optional Panoptic dependencies before calling Panoptic methods.`
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
function isRecord(value) {
|
|
935
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
936
|
+
}
|
|
937
|
+
function getRuntimeImport() {
|
|
938
|
+
if (runtimeImport) {
|
|
939
|
+
return runtimeImport;
|
|
940
|
+
}
|
|
941
|
+
if (!dynamicImport) {
|
|
942
|
+
dynamicImport = new Function("s", "return import(s)");
|
|
943
|
+
}
|
|
944
|
+
return dynamicImport;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// src/internal/panopticSerialization.ts
|
|
948
|
+
var DEFAULT_MAX_ARRAY_ITEMS = 256;
|
|
949
|
+
var DEFAULT_MAX_OBJECT_KEYS = 128;
|
|
950
|
+
var DEFAULT_MAX_DEPTH = 32;
|
|
951
|
+
var DEFAULT_MAX_REQUEST_BYTES2 = 512 * 1024;
|
|
952
|
+
var DEFAULT_MAX_RESPONSE_BYTES = 512 * 1024;
|
|
953
|
+
var DEFAULT_MAX_CALLDATA_BYTES = 256 * 1024;
|
|
954
|
+
var DEFAULT_MAX_STRING_BYTES = 64 * 1024;
|
|
955
|
+
var DEFAULT_MAX_DECIMAL_DIGITS = 96;
|
|
956
|
+
function normalizePanopticAddress(value, fieldName = "address") {
|
|
957
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) {
|
|
958
|
+
throw new Error(`Panoptic ${fieldName} must be a 20-byte hex address.`);
|
|
959
|
+
}
|
|
960
|
+
return value.toLowerCase();
|
|
961
|
+
}
|
|
962
|
+
function normalizePanopticHex(value, fieldName = "hex", maxBytes = DEFAULT_MAX_CALLDATA_BYTES) {
|
|
963
|
+
if (typeof value === "string" && value.length > maxBytes * 2 + 2) {
|
|
964
|
+
throw new Error(`Panoptic ${fieldName} exceeds maximum hex size ${maxBytes} bytes.`);
|
|
965
|
+
}
|
|
966
|
+
if (typeof value !== "string" || !/^0x(?:[0-9a-fA-F]{2})*$/.test(value)) {
|
|
967
|
+
throw new Error(`Panoptic ${fieldName} must be an even-length hex string.`);
|
|
968
|
+
}
|
|
969
|
+
return value.toLowerCase();
|
|
970
|
+
}
|
|
971
|
+
function normalizePanopticDecimalString(value, fieldName = "value", maxDigits = DEFAULT_MAX_DECIMAL_DIGITS) {
|
|
972
|
+
if (typeof value === "string" && /^(0|[1-9][0-9]*)$/.test(value)) {
|
|
973
|
+
assertDecimalDigitLength(value, fieldName, maxDigits);
|
|
974
|
+
return BigInt(value).toString(10);
|
|
975
|
+
}
|
|
976
|
+
throw new Error(`Panoptic ${fieldName} must be an unsigned decimal string.`);
|
|
977
|
+
}
|
|
978
|
+
function projectPanopticSerializableValue(value, limits = {}, label = "result") {
|
|
979
|
+
const normalized = normalizeSerializableValue(value, normalizeLimits(limits), label, 0, /* @__PURE__ */ new WeakSet());
|
|
980
|
+
assertSerializedSize(normalized, limits.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES, label, "response");
|
|
981
|
+
return normalized;
|
|
982
|
+
}
|
|
983
|
+
function normalizeSerializableValue(value, limits, path, depth, seen) {
|
|
984
|
+
if (depth > limits.maxDepth) {
|
|
985
|
+
throw new Error(`Panoptic ${path} exceeds maximum JSON depth.`);
|
|
986
|
+
}
|
|
987
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
988
|
+
enforceHexSizeIfNeeded(value, limits, path);
|
|
989
|
+
if (typeof value === "string" && utf8ByteLength2(value) > limits.maxStringBytes) {
|
|
990
|
+
throw new Error(`Panoptic ${path} exceeds maximum string length ${limits.maxStringBytes} bytes.`);
|
|
991
|
+
}
|
|
992
|
+
return value;
|
|
993
|
+
}
|
|
994
|
+
if (typeof value === "bigint") {
|
|
995
|
+
return value.toString(10);
|
|
996
|
+
}
|
|
997
|
+
if (typeof value === "number") {
|
|
998
|
+
if (!Number.isFinite(value)) {
|
|
999
|
+
throw new Error(`Panoptic ${path} must be a finite number.`);
|
|
1000
|
+
}
|
|
1001
|
+
return value;
|
|
1002
|
+
}
|
|
1003
|
+
if (value instanceof Uint8Array) {
|
|
1004
|
+
if (value.byteLength > limits.maxCalldataBytes) {
|
|
1005
|
+
throw new Error(`Panoptic ${path} exceeds maximum encoded calldata size ${limits.maxCalldataBytes} bytes.`);
|
|
1006
|
+
}
|
|
1007
|
+
return bytesToHex(value);
|
|
1008
|
+
}
|
|
1009
|
+
if (value instanceof ArrayBuffer) {
|
|
1010
|
+
if (value.byteLength > limits.maxCalldataBytes) {
|
|
1011
|
+
throw new Error(`Panoptic ${path} exceeds maximum encoded calldata size ${limits.maxCalldataBytes} bytes.`);
|
|
1012
|
+
}
|
|
1013
|
+
return bytesToHex(new Uint8Array(value));
|
|
1014
|
+
}
|
|
1015
|
+
if (Array.isArray(value)) {
|
|
1016
|
+
if (value.length > limits.maxArrayItems) {
|
|
1017
|
+
throw new Error(`Panoptic ${path} exceeds maximum array length ${limits.maxArrayItems}.`);
|
|
1018
|
+
}
|
|
1019
|
+
return value.map((item, index) => normalizeSerializableValue(item, limits, `${path}[${index}]`, depth + 1, seen));
|
|
1020
|
+
}
|
|
1021
|
+
if (typeof value === "object" && value !== null) {
|
|
1022
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1023
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
1024
|
+
throw new Error(`Panoptic ${path} must be explicitly projected before crossing the wasm boundary.`);
|
|
1025
|
+
}
|
|
1026
|
+
if (seen.has(value)) {
|
|
1027
|
+
throw new Error(`Panoptic ${path} contains a circular reference.`);
|
|
1028
|
+
}
|
|
1029
|
+
seen.add(value);
|
|
1030
|
+
const entries = Object.entries(value);
|
|
1031
|
+
if (entries.length > limits.maxObjectKeys) {
|
|
1032
|
+
throw new Error(`Panoptic ${path} exceeds maximum object key count ${limits.maxObjectKeys}.`);
|
|
1033
|
+
}
|
|
1034
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
1035
|
+
for (const [key, entryValue] of entries) {
|
|
1036
|
+
if (isUnsafeObjectKey(key)) {
|
|
1037
|
+
throw new Error(`Panoptic ${path}.${key} is not supported as an object key.`);
|
|
1038
|
+
}
|
|
1039
|
+
if (entryValue === void 0 || typeof entryValue === "function" || typeof entryValue === "symbol") {
|
|
1040
|
+
throw new Error(`Panoptic ${path}.${key} is not serializable.`);
|
|
1041
|
+
}
|
|
1042
|
+
normalized[key] = normalizeSerializableValue(entryValue, limits, `${path}.${key}`, depth + 1, seen);
|
|
1043
|
+
}
|
|
1044
|
+
seen.delete(value);
|
|
1045
|
+
return normalized;
|
|
1046
|
+
}
|
|
1047
|
+
throw new Error(`Panoptic ${path} is not serializable.`);
|
|
1048
|
+
}
|
|
1049
|
+
function normalizeLimits(limits) {
|
|
1050
|
+
return {
|
|
1051
|
+
maxArrayItems: limits.maxArrayItems ?? DEFAULT_MAX_ARRAY_ITEMS,
|
|
1052
|
+
maxObjectKeys: limits.maxObjectKeys ?? DEFAULT_MAX_OBJECT_KEYS,
|
|
1053
|
+
maxDepth: limits.maxDepth ?? DEFAULT_MAX_DEPTH,
|
|
1054
|
+
maxRequestBytes: limits.maxRequestBytes ?? DEFAULT_MAX_REQUEST_BYTES2,
|
|
1055
|
+
maxResponseBytes: limits.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES,
|
|
1056
|
+
maxCalldataBytes: limits.maxCalldataBytes ?? DEFAULT_MAX_CALLDATA_BYTES,
|
|
1057
|
+
maxStringBytes: limits.maxStringBytes ?? DEFAULT_MAX_STRING_BYTES,
|
|
1058
|
+
maxDecimalDigits: limits.maxDecimalDigits ?? DEFAULT_MAX_DECIMAL_DIGITS
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function assertSerializedSize(value, maxBytes, label, kind) {
|
|
1062
|
+
const serialized = JSON.stringify(value);
|
|
1063
|
+
if (utf8ByteLength2(serialized) > maxBytes) {
|
|
1064
|
+
throw new Error(`Panoptic ${label} exceeds maximum ${kind} size ${maxBytes} bytes.`);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
function utf8ByteLength2(value) {
|
|
1068
|
+
let bytes = 0;
|
|
1069
|
+
for (let i = 0; i < value.length; i++) {
|
|
1070
|
+
const codePoint = value.codePointAt(i) || 0;
|
|
1071
|
+
if (codePoint > 65535) {
|
|
1072
|
+
i += 1;
|
|
1073
|
+
}
|
|
1074
|
+
if (codePoint <= 127) {
|
|
1075
|
+
bytes += 1;
|
|
1076
|
+
} else if (codePoint <= 2047) {
|
|
1077
|
+
bytes += 2;
|
|
1078
|
+
} else if (codePoint <= 65535) {
|
|
1079
|
+
bytes += 3;
|
|
1080
|
+
} else {
|
|
1081
|
+
bytes += 4;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
return bytes;
|
|
1085
|
+
}
|
|
1086
|
+
function enforceHexSizeIfNeeded(value, limits, path) {
|
|
1087
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]*$/.test(value)) {
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
const byteLength = Math.max(0, (value.length - 2) / 2);
|
|
1091
|
+
if (byteLength > limits.maxCalldataBytes) {
|
|
1092
|
+
throw new Error(`Panoptic ${path} exceeds maximum encoded calldata size ${limits.maxCalldataBytes} bytes.`);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
function bytesToHex(bytes) {
|
|
1096
|
+
let hex = "0x";
|
|
1097
|
+
for (const byte of bytes) {
|
|
1098
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
1099
|
+
}
|
|
1100
|
+
return hex;
|
|
1101
|
+
}
|
|
1102
|
+
function assertDecimalDigitLength(value, fieldName, maxDigits) {
|
|
1103
|
+
if (value.length > maxDigits) {
|
|
1104
|
+
throw new Error(`Panoptic ${fieldName} exceeds maximum decimal digit length ${maxDigits}.`);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
function isUnsafeObjectKey(key) {
|
|
1108
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// src/internal/panopticSources.ts
|
|
1112
|
+
var DEFAULT_OPERATION_TIMEOUT_MS = 1e4;
|
|
1113
|
+
var DEFAULT_OPERATION_RETRIES = 2;
|
|
1114
|
+
var DEFAULT_CLIENT_CACHE_MAX_ENTRIES = 16;
|
|
1115
|
+
var publicClientCache = /* @__PURE__ */ new Map();
|
|
1116
|
+
function resolvePanopticSource(context, registry) {
|
|
1117
|
+
if (!context?.sourceId && !context?.chainId && !context?.rpcUrl) {
|
|
1118
|
+
throw new Error("Panoptic source context must include sourceId or chainId.");
|
|
1119
|
+
}
|
|
1120
|
+
if (!registry?.sources?.length) {
|
|
1121
|
+
throw new Error("Panoptic source registry is not configured.");
|
|
1122
|
+
}
|
|
1123
|
+
const requestedChainId = context.chainId ? normalizeDecimalString(context.chainId, "chainId") : null;
|
|
1124
|
+
const source = selectRegistrySource(context.sourceId, requestedChainId, registry);
|
|
1125
|
+
const sourceChainId = normalizeDecimalString(source.chainId, "source.chainId");
|
|
1126
|
+
if (requestedChainId && sourceChainId !== requestedChainId) {
|
|
1127
|
+
throw new Error(
|
|
1128
|
+
`Panoptic source "${source.sourceId}" is configured for chain ${sourceChainId}, not requested chain ${requestedChainId}.`
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
const registryRpcUrl = normalizeRegistryRpcUrl(source, registry);
|
|
1132
|
+
const rpcUrl = context.rpcUrl ? normalizeOverrideRpcUrl(context.rpcUrl, source, registry) : registryRpcUrl;
|
|
1133
|
+
return {
|
|
1134
|
+
source,
|
|
1135
|
+
chainId: sourceChainId,
|
|
1136
|
+
rpcUrl,
|
|
1137
|
+
normalizedRpcUrl: rpcUrl,
|
|
1138
|
+
overrideApplied: !!context.rpcUrl && rpcUrl !== registryRpcUrl
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
async function preparePanopticSourceContext(request, viemModule, registry, operationOptions = {}, cacheOptions = {}) {
|
|
1142
|
+
const source = resolvePanopticSource(request.context, registry);
|
|
1143
|
+
const client = getPanopticPublicClient(viemModule, source, cacheOptions);
|
|
1144
|
+
await runPanopticOperation(
|
|
1145
|
+
"Panoptic RPC chain verification",
|
|
1146
|
+
() => verifyPanopticSourceChain(client, source.chainId),
|
|
1147
|
+
operationOptions
|
|
1148
|
+
);
|
|
1149
|
+
const blockNumber = request.context?.blockNumber ? normalizeDecimalString(request.context.blockNumber, "blockNumber") : await runPanopticOperation("Panoptic RPC block pinning", () => readPanopticBlockNumber(client), operationOptions);
|
|
1150
|
+
return {
|
|
1151
|
+
source,
|
|
1152
|
+
client,
|
|
1153
|
+
blockNumber,
|
|
1154
|
+
sourceMeta: buildSourceMeta(source, blockNumber)
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
function getPanopticPublicClient(viemModule, source, options = {}) {
|
|
1158
|
+
const viem = viemModule;
|
|
1159
|
+
if (typeof viem.createPublicClient !== "function" || typeof viem.http !== "function") {
|
|
1160
|
+
throw new Error('Panoptic runtime dependency "viem" does not provide createPublicClient and http.');
|
|
1161
|
+
}
|
|
1162
|
+
const maxEntries = normalizeClientCacheMaxEntries(options.maxEntries);
|
|
1163
|
+
const cacheKey = buildPublicClientCacheKey(source);
|
|
1164
|
+
const cached = publicClientCache.get(cacheKey);
|
|
1165
|
+
if (cached) {
|
|
1166
|
+
publicClientCache.delete(cacheKey);
|
|
1167
|
+
publicClientCache.set(cacheKey, cached);
|
|
1168
|
+
return cached;
|
|
1169
|
+
}
|
|
1170
|
+
const clientOptions = getNormalizedClientOptions(source);
|
|
1171
|
+
const client = viem.createPublicClient({
|
|
1172
|
+
...clientOptions,
|
|
1173
|
+
chain: {
|
|
1174
|
+
id: Number(source.chainId),
|
|
1175
|
+
name: source.source.label || source.source.sourceId,
|
|
1176
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
1177
|
+
rpcUrls: { default: { http: [source.normalizedRpcUrl] } }
|
|
1178
|
+
},
|
|
1179
|
+
transport: viem.http(source.normalizedRpcUrl)
|
|
1180
|
+
});
|
|
1181
|
+
publicClientCache.set(cacheKey, client);
|
|
1182
|
+
evictPublicClientCache(maxEntries);
|
|
1183
|
+
return client;
|
|
1184
|
+
}
|
|
1185
|
+
async function verifyPanopticSourceChain(client, expectedChainId) {
|
|
1186
|
+
const actualChainId = normalizeChainIdValue(await readPanopticChainId(client), "rpc.chainId");
|
|
1187
|
+
if (actualChainId !== expectedChainId) {
|
|
1188
|
+
throw new Error(`Panoptic RPC chain mismatch: expected ${expectedChainId}, received ${actualChainId}.`);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
async function readPanopticBlockNumber(client) {
|
|
1192
|
+
const blockNumber = await callClient(client, "getBlockNumber", { method: "eth_blockNumber" });
|
|
1193
|
+
return normalizeChainIdValue(blockNumber, "rpc.blockNumber");
|
|
1194
|
+
}
|
|
1195
|
+
function buildSourceMeta(source, blockNumber) {
|
|
1196
|
+
return {
|
|
1197
|
+
chainId: source.chainId,
|
|
1198
|
+
blockNumber,
|
|
1199
|
+
rpcSourceId: source.source.sourceId,
|
|
1200
|
+
...source.source.subgraph?.sourceId ? { subgraphSourceId: source.source.subgraph.sourceId } : {}
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
async function runPanopticOperation(label, operation, options = {}) {
|
|
1204
|
+
const retries = options.retries ?? DEFAULT_OPERATION_RETRIES;
|
|
1205
|
+
let lastError;
|
|
1206
|
+
for (let attempt = 1; attempt <= retries + 1; attempt++) {
|
|
1207
|
+
const startedAt = Date.now();
|
|
1208
|
+
try {
|
|
1209
|
+
throwIfAborted(options.signal);
|
|
1210
|
+
const result = await withTimeout(operation(), label, options.timeoutMs ?? DEFAULT_OPERATION_TIMEOUT_MS);
|
|
1211
|
+
options.onAudit?.({ label, status: "success", attempt, durationMs: Date.now() - startedAt });
|
|
1212
|
+
return result;
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
lastError = error;
|
|
1215
|
+
options.onAudit?.({
|
|
1216
|
+
label,
|
|
1217
|
+
status: "failure",
|
|
1218
|
+
attempt,
|
|
1219
|
+
durationMs: Date.now() - startedAt,
|
|
1220
|
+
error: sanitizeOperationError(error)
|
|
1221
|
+
});
|
|
1222
|
+
if (attempt > retries || isNonRetryablePanopticOperationError(error)) {
|
|
1223
|
+
break;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
throw new Error(`${label} failed: ${sanitizeOperationError(lastError)}`);
|
|
1228
|
+
}
|
|
1229
|
+
function buildPublicClientCacheKey(source) {
|
|
1230
|
+
return `${source.chainId}:${source.normalizedRpcUrl}:${stableStringify(getNormalizedClientOptions(source))}`;
|
|
1231
|
+
}
|
|
1232
|
+
function getNormalizedClientOptions(source) {
|
|
1233
|
+
if (!isJsonObject2(source.source.clientOptions)) {
|
|
1234
|
+
return {};
|
|
1235
|
+
}
|
|
1236
|
+
const normalized = projectPanopticSerializableValue(
|
|
1237
|
+
source.source.clientOptions,
|
|
1238
|
+
{ maxDepth: 8, maxObjectKeys: 64, maxResponseBytes: 32 * 1024 },
|
|
1239
|
+
"source.clientOptions"
|
|
1240
|
+
);
|
|
1241
|
+
if (!isJsonObject2(normalized)) {
|
|
1242
|
+
return {};
|
|
1243
|
+
}
|
|
1244
|
+
return normalized;
|
|
1245
|
+
}
|
|
1246
|
+
function selectRegistrySource(sourceId, requestedChainId, registry) {
|
|
1247
|
+
if (sourceId) {
|
|
1248
|
+
const source = registry.sources.find((candidate) => candidate.sourceId === sourceId);
|
|
1249
|
+
if (!source) {
|
|
1250
|
+
throw new Error(`Panoptic source "${sourceId}" is not configured.`);
|
|
1251
|
+
}
|
|
1252
|
+
return source;
|
|
1253
|
+
}
|
|
1254
|
+
const candidates = registry.sources.filter(
|
|
1255
|
+
(source) => normalizeDecimalString(source.chainId, "source.chainId") === requestedChainId
|
|
1256
|
+
);
|
|
1257
|
+
if (candidates.length === 0) {
|
|
1258
|
+
throw new Error(`No Panoptic source is configured for chain ${requestedChainId}.`);
|
|
1259
|
+
}
|
|
1260
|
+
if (candidates.length > 1) {
|
|
1261
|
+
throw new Error(`Multiple Panoptic sources are configured for chain ${requestedChainId}; sourceId is required.`);
|
|
1262
|
+
}
|
|
1263
|
+
return candidates[0];
|
|
1264
|
+
}
|
|
1265
|
+
function normalizeOverrideRpcUrl(value, source, registry) {
|
|
1266
|
+
if (!source.overrideable) {
|
|
1267
|
+
throw new Error(`Panoptic source "${source.sourceId}" does not allow RPC URL overrides.`);
|
|
1268
|
+
}
|
|
1269
|
+
const normalized = normalizeRpcUrl(value);
|
|
1270
|
+
const overrideUrl = new URL(normalized);
|
|
1271
|
+
const registryUrl = new URL(normalizeRegistryRpcUrl(source, registry));
|
|
1272
|
+
const allowLocalhost = !!(registry.devMode && source.allowLocalhostOverrides);
|
|
1273
|
+
if (isLocalOrPrivateHostname(overrideUrl.hostname) && !allowLocalhost) {
|
|
1274
|
+
throw new Error("Panoptic RPC URL override uses a localhost or private host without explicit dev-mode permission.");
|
|
1275
|
+
}
|
|
1276
|
+
if (overrideUrl.protocol !== "https:" && !(allowLocalhost && overrideUrl.protocol === "http:")) {
|
|
1277
|
+
throw new Error("Panoptic RPC URL override must use https.");
|
|
1278
|
+
}
|
|
1279
|
+
const allowedHosts = /* @__PURE__ */ new Set([
|
|
1280
|
+
registryUrl.hostname.toLowerCase(),
|
|
1281
|
+
...(registry.allowedOverrideHosts || []).map((host) => host.toLowerCase()),
|
|
1282
|
+
...(source.allowedOverrideHosts || []).map((host) => host.toLowerCase())
|
|
1283
|
+
]);
|
|
1284
|
+
if (!hostMatchesAllowedList(overrideUrl.hostname, allowedHosts)) {
|
|
1285
|
+
throw new Error(`Panoptic RPC URL override host "${overrideUrl.hostname}" is not allowed.`);
|
|
1286
|
+
}
|
|
1287
|
+
return normalized;
|
|
1288
|
+
}
|
|
1289
|
+
function normalizeRegistryRpcUrl(source, registry) {
|
|
1290
|
+
const normalized = normalizeRpcUrl(source.rpcUrl);
|
|
1291
|
+
const url = new URL(normalized);
|
|
1292
|
+
const allowLocalhost = !!(registry.devMode && source.allowLocalhostOverrides);
|
|
1293
|
+
if (isLocalOrPrivateHostname(url.hostname) && !allowLocalhost) {
|
|
1294
|
+
throw new Error("Panoptic registry RPC URL uses a localhost or private host without explicit dev-mode permission.");
|
|
1295
|
+
}
|
|
1296
|
+
if (url.protocol !== "https:" && !(allowLocalhost && url.protocol === "http:")) {
|
|
1297
|
+
throw new Error("Panoptic registry RPC URL must use https.");
|
|
1298
|
+
}
|
|
1299
|
+
return normalized;
|
|
1300
|
+
}
|
|
1301
|
+
function normalizeRpcUrl(value) {
|
|
1302
|
+
let url;
|
|
1303
|
+
try {
|
|
1304
|
+
url = new URL(value);
|
|
1305
|
+
} catch {
|
|
1306
|
+
throw new Error("Panoptic RPC URL must be an absolute URL.");
|
|
1307
|
+
}
|
|
1308
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
1309
|
+
throw new Error("Panoptic RPC URL must use http or https.");
|
|
1310
|
+
}
|
|
1311
|
+
if (url.hash) {
|
|
1312
|
+
throw new Error("Panoptic RPC URL must not include a fragment.");
|
|
1313
|
+
}
|
|
1314
|
+
url.protocol = url.protocol.toLowerCase();
|
|
1315
|
+
url.hostname = url.hostname.toLowerCase();
|
|
1316
|
+
if (url.pathname === "/" && !url.search) {
|
|
1317
|
+
return `${url.protocol}//${url.host}`;
|
|
1318
|
+
}
|
|
1319
|
+
return url.toString();
|
|
1320
|
+
}
|
|
1321
|
+
function normalizeDecimalString(value, fieldName) {
|
|
1322
|
+
if (!/^(0|[1-9][0-9]*)$/.test(value)) {
|
|
1323
|
+
throw new Error(`Panoptic ${fieldName} must be a decimal string.`);
|
|
1324
|
+
}
|
|
1325
|
+
return BigInt(value).toString(10);
|
|
1326
|
+
}
|
|
1327
|
+
function normalizeChainIdValue(value, fieldName) {
|
|
1328
|
+
if (typeof value === "bigint") {
|
|
1329
|
+
return value.toString(10);
|
|
1330
|
+
}
|
|
1331
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) {
|
|
1332
|
+
return value.toString(10);
|
|
1333
|
+
}
|
|
1334
|
+
if (typeof value === "string") {
|
|
1335
|
+
if (/^0x[0-9a-f]+$/i.test(value)) {
|
|
1336
|
+
return BigInt(value).toString(10);
|
|
1337
|
+
}
|
|
1338
|
+
return normalizeDecimalString(value, fieldName);
|
|
1339
|
+
}
|
|
1340
|
+
throw new Error(`Panoptic ${fieldName} must be a decimal string, hex string, bigint, or safe integer.`);
|
|
1341
|
+
}
|
|
1342
|
+
async function readPanopticChainId(client) {
|
|
1343
|
+
return callClient(client, "getChainId", { method: "eth_chainId" });
|
|
1344
|
+
}
|
|
1345
|
+
async function callClient(client, methodName, request) {
|
|
1346
|
+
if (isRecord2(client) && typeof client[methodName] === "function") {
|
|
1347
|
+
return client[methodName]();
|
|
1348
|
+
}
|
|
1349
|
+
if (isRecord2(client) && typeof client.request === "function") {
|
|
1350
|
+
return client.request(request);
|
|
1351
|
+
}
|
|
1352
|
+
throw new Error(`Panoptic viem client does not provide ${methodName} or request.`);
|
|
1353
|
+
}
|
|
1354
|
+
function evictPublicClientCache(maxEntries) {
|
|
1355
|
+
while (publicClientCache.size > maxEntries) {
|
|
1356
|
+
const oldestKey = publicClientCache.keys().next().value;
|
|
1357
|
+
if (oldestKey === void 0) {
|
|
1358
|
+
break;
|
|
1359
|
+
}
|
|
1360
|
+
publicClientCache.delete(oldestKey);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function normalizeClientCacheMaxEntries(maxEntries) {
|
|
1364
|
+
if (maxEntries === void 0) {
|
|
1365
|
+
return DEFAULT_CLIENT_CACHE_MAX_ENTRIES;
|
|
1366
|
+
}
|
|
1367
|
+
if (!Number.isInteger(maxEntries) || maxEntries < 1) {
|
|
1368
|
+
throw new Error("Panoptic client cache maxEntries must be a positive integer.");
|
|
1369
|
+
}
|
|
1370
|
+
return maxEntries;
|
|
1371
|
+
}
|
|
1372
|
+
function hostMatchesAllowedList(hostname, allowedHosts) {
|
|
1373
|
+
const normalized = hostname.toLowerCase();
|
|
1374
|
+
for (const allowedHost of allowedHosts) {
|
|
1375
|
+
if (allowedHost.startsWith("*.") && normalized.endsWith(allowedHost.slice(1))) {
|
|
1376
|
+
return true;
|
|
1377
|
+
}
|
|
1378
|
+
if (normalized === allowedHost) {
|
|
1379
|
+
return true;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
return false;
|
|
1383
|
+
}
|
|
1384
|
+
function isLocalOrPrivateHostname(hostname) {
|
|
1385
|
+
const normalized = hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
1386
|
+
if (normalized === "localhost" || normalized === "::" || normalized === "::1" || normalized === "0:0:0:0:0:0:0:0" || normalized === "0:0:0:0:0:0:0:1") {
|
|
1387
|
+
return true;
|
|
1388
|
+
}
|
|
1389
|
+
if (normalized.startsWith("::ffff:")) {
|
|
1390
|
+
return true;
|
|
1391
|
+
}
|
|
1392
|
+
const ipv4Parts = normalized.split(".").map((part) => Number(part));
|
|
1393
|
+
if (ipv4Parts.length === 4 && ipv4Parts.every((part) => Number.isInteger(part) && part >= 0 && part <= 255)) {
|
|
1394
|
+
const [first, second] = ipv4Parts;
|
|
1395
|
+
return first === 0 || first === 10 || first === 127 || first === 172 && second >= 16 && second <= 31 || first === 192 && second === 168 || first === 169 && second === 254;
|
|
1396
|
+
}
|
|
1397
|
+
return normalized.startsWith("fc") || normalized.startsWith("fd") || normalized.startsWith("fe8") || normalized.startsWith("fe9") || normalized.startsWith("fea") || normalized.startsWith("feb");
|
|
1398
|
+
}
|
|
1399
|
+
async function withTimeout(promise, label, timeoutMs) {
|
|
1400
|
+
let timeout = null;
|
|
1401
|
+
try {
|
|
1402
|
+
return await Promise.race([
|
|
1403
|
+
promise,
|
|
1404
|
+
new Promise((_, reject) => {
|
|
1405
|
+
timeout = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms.`)), timeoutMs);
|
|
1406
|
+
})
|
|
1407
|
+
]);
|
|
1408
|
+
} finally {
|
|
1409
|
+
if (timeout) {
|
|
1410
|
+
clearTimeout(timeout);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
function throwIfAborted(signal) {
|
|
1415
|
+
if (signal?.aborted) {
|
|
1416
|
+
throw new Error("Panoptic operation was aborted.");
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
function sanitizeOperationError(error) {
|
|
1420
|
+
return sanitizePanopticError(error);
|
|
1421
|
+
}
|
|
1422
|
+
function isNonRetryablePanopticOperationError(error) {
|
|
1423
|
+
return sanitizeOperationError(error).startsWith('Panoptic runtime dependency "');
|
|
1424
|
+
}
|
|
1425
|
+
function stableStringify(value) {
|
|
1426
|
+
if (Array.isArray(value)) {
|
|
1427
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
1428
|
+
}
|
|
1429
|
+
if (isJsonObject2(value)) {
|
|
1430
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(",")}}`;
|
|
1431
|
+
}
|
|
1432
|
+
return JSON.stringify(value);
|
|
1433
|
+
}
|
|
1434
|
+
function isJsonObject2(value) {
|
|
1435
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1436
|
+
}
|
|
1437
|
+
function isRecord2(value) {
|
|
1438
|
+
return typeof value === "object" && value !== null;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// src/internal/panopticJsonArgs.ts
|
|
1442
|
+
function decimalValue(value, label) {
|
|
1443
|
+
if (typeof value !== "string" || !/^(0|[1-9][0-9]*)$/.test(value)) {
|
|
1444
|
+
throw new Error(`Panoptic ${label} must be a decimal string.`);
|
|
1445
|
+
}
|
|
1446
|
+
return BigInt(value);
|
|
1447
|
+
}
|
|
1448
|
+
function signedDecimalValue(value, label) {
|
|
1449
|
+
if (typeof value !== "string" || !/^-?(0|[1-9][0-9]*)$/.test(value)) {
|
|
1450
|
+
throw new Error(`Panoptic ${label} must be a signed decimal string.`);
|
|
1451
|
+
}
|
|
1452
|
+
return BigInt(value);
|
|
1453
|
+
}
|
|
1454
|
+
function stringValue(value, label) {
|
|
1455
|
+
if (typeof value !== "string") {
|
|
1456
|
+
throw new Error(`Panoptic ${label} must be a string.`);
|
|
1457
|
+
}
|
|
1458
|
+
return value;
|
|
1459
|
+
}
|
|
1460
|
+
function booleanValue(value, label) {
|
|
1461
|
+
if (typeof value !== "boolean") {
|
|
1462
|
+
throw new Error(`Panoptic ${label} must be a boolean.`);
|
|
1463
|
+
}
|
|
1464
|
+
return value;
|
|
1465
|
+
}
|
|
1466
|
+
function numberValue(value, label) {
|
|
1467
|
+
if (typeof value !== "number") {
|
|
1468
|
+
throw new Error(`Panoptic ${label} must be a number.`);
|
|
1469
|
+
}
|
|
1470
|
+
return value;
|
|
1471
|
+
}
|
|
1472
|
+
function decimalArg(args, fieldName) {
|
|
1473
|
+
return decimalValue(args[fieldName], `args.${fieldName}`);
|
|
1474
|
+
}
|
|
1475
|
+
function signedDecimalArg(args, fieldName) {
|
|
1476
|
+
return signedDecimalValue(args[fieldName], `args.${fieldName}`);
|
|
1477
|
+
}
|
|
1478
|
+
function optionalDecimalArg(args, fieldName) {
|
|
1479
|
+
return args[fieldName] === void 0 ? void 0 : decimalArg(args, fieldName);
|
|
1480
|
+
}
|
|
1481
|
+
function optionalSignedDecimalArg(args, fieldName) {
|
|
1482
|
+
return args[fieldName] === void 0 ? void 0 : signedDecimalArg(args, fieldName);
|
|
1483
|
+
}
|
|
1484
|
+
function optionalBooleanArg(args, fieldName) {
|
|
1485
|
+
return args[fieldName] === void 0 ? void 0 : booleanValue(args[fieldName], `args.${fieldName}`);
|
|
1486
|
+
}
|
|
1487
|
+
function decimalArrayArg(args, fieldName) {
|
|
1488
|
+
return decimalArrayValue(args[fieldName], `args.${fieldName}`);
|
|
1489
|
+
}
|
|
1490
|
+
function optionalDecimalArrayArg(args, fieldName) {
|
|
1491
|
+
return args[fieldName] === void 0 ? void 0 : decimalArrayArg(args, fieldName);
|
|
1492
|
+
}
|
|
1493
|
+
function signedDecimalArrayArg(args, fieldName) {
|
|
1494
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
1495
|
+
(item, index) => signedDecimalValue(item, `args.${fieldName}[${index}]`)
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
function decimalMatrixArg(args, fieldName) {
|
|
1499
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
1500
|
+
(row, rowIndex) => decimalArrayValue(row, `args.${fieldName}[${rowIndex}]`)
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
function optionalStringArrayArg(args, fieldName) {
|
|
1504
|
+
if (args[fieldName] === void 0) {
|
|
1505
|
+
return void 0;
|
|
1506
|
+
}
|
|
1507
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
1508
|
+
(item, index) => stringValue(item, `args.${fieldName}[${index}]`)
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1511
|
+
function decimalArrayValue(value, label) {
|
|
1512
|
+
return arrayValue(value, label).map((item, index) => decimalValue(item, `${label}[${index}]`));
|
|
1513
|
+
}
|
|
1514
|
+
function arrayValue(value, label) {
|
|
1515
|
+
if (!Array.isArray(value)) {
|
|
1516
|
+
throw new Error(`Panoptic ${label} must be an array.`);
|
|
1517
|
+
}
|
|
1518
|
+
return value;
|
|
1519
|
+
}
|
|
1520
|
+
function recordValue(value, label) {
|
|
1521
|
+
if (!isJsonRecord2(value)) {
|
|
1522
|
+
throw new Error(`Panoptic ${label} must be an object.`);
|
|
1523
|
+
}
|
|
1524
|
+
return value;
|
|
1525
|
+
}
|
|
1526
|
+
function isJsonRecord2(value) {
|
|
1527
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1528
|
+
}
|
|
1529
|
+
function isRecord3(value) {
|
|
1530
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
// src/internal/panopticDtos.ts
|
|
1534
|
+
function collateralAddressesValue(value, label) {
|
|
1535
|
+
const record = recordValue(value, label);
|
|
1536
|
+
return {
|
|
1537
|
+
collateralToken0: stringValue(record.collateralToken0, `${label}.collateralToken0`),
|
|
1538
|
+
collateralToken1: stringValue(record.collateralToken1, `${label}.collateralToken1`)
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
function poolInfoArrayArg(args, fieldName) {
|
|
1542
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
1543
|
+
(item, index) => poolInfoValue(item, `args.${fieldName}[${index}]`)
|
|
1544
|
+
);
|
|
1545
|
+
}
|
|
1546
|
+
function poolInfoValue(value, label) {
|
|
1547
|
+
const record = recordValue(value, label);
|
|
1548
|
+
return {
|
|
1549
|
+
pool: stringValue(record.pool, `${label}.pool`),
|
|
1550
|
+
token0: stringValue(record.token0, `${label}.token0`),
|
|
1551
|
+
token1: stringValue(record.token1, `${label}.token1`),
|
|
1552
|
+
maxPriceDeviation: numberValue(record.maxPriceDeviation, `${label}.maxPriceDeviation`)
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
function poolMetadataValue(value, label) {
|
|
1556
|
+
const record = recordValue(value, label);
|
|
1557
|
+
return {
|
|
1558
|
+
poolKeyBytes: stringValue(record.poolKeyBytes, `${label}.poolKeyBytes`),
|
|
1559
|
+
poolId: decimalValue(record.poolId, `${label}.poolId`),
|
|
1560
|
+
collateralToken0Address: stringValue(record.collateralToken0Address, `${label}.collateralToken0Address`),
|
|
1561
|
+
collateralToken1Address: stringValue(record.collateralToken1Address, `${label}.collateralToken1Address`),
|
|
1562
|
+
riskEngineAddress: stringValue(record.riskEngineAddress, `${label}.riskEngineAddress`),
|
|
1563
|
+
token0Asset: stringValue(record.token0Asset, `${label}.token0Asset`),
|
|
1564
|
+
token1Asset: stringValue(record.token1Asset, `${label}.token1Asset`),
|
|
1565
|
+
token0Symbol: stringValue(record.token0Symbol, `${label}.token0Symbol`),
|
|
1566
|
+
token1Symbol: stringValue(record.token1Symbol, `${label}.token1Symbol`),
|
|
1567
|
+
token0Decimals: decimalValue(record.token0Decimals, `${label}.token0Decimals`),
|
|
1568
|
+
token1Decimals: decimalValue(record.token1Decimals, `${label}.token1Decimals`),
|
|
1569
|
+
token0Name: stringValue(record.token0Name, `${label}.token0Name`),
|
|
1570
|
+
token1Name: stringValue(record.token1Name, `${label}.token1Name`),
|
|
1571
|
+
underlyingPoolId: stringValue(record.underlyingPoolId, `${label}.underlyingPoolId`),
|
|
1572
|
+
isV4: booleanValue(record.isV4, `${label}.isV4`),
|
|
1573
|
+
tickSpacing: decimalValue(record.tickSpacing, `${label}.tickSpacing`),
|
|
1574
|
+
fee: decimalValue(record.fee, `${label}.fee`),
|
|
1575
|
+
sfpmAddress: stringValue(record.sfpmAddress, `${label}.sfpmAddress`)
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
function tokenIdLegArrayArg(args, fieldName) {
|
|
1579
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
1580
|
+
(item, index) => tokenIdLegValue(item, `args.${fieldName}[${index}]`)
|
|
1581
|
+
);
|
|
1582
|
+
}
|
|
1583
|
+
function tokenIdLegValue(value, label) {
|
|
1584
|
+
const record = recordValue(value, label);
|
|
1585
|
+
return {
|
|
1586
|
+
index: decimalValue(record.index, `${label}.index`),
|
|
1587
|
+
asset: decimalValue(record.asset, `${label}.asset`),
|
|
1588
|
+
optionRatio: decimalValue(record.optionRatio, `${label}.optionRatio`),
|
|
1589
|
+
isLong: booleanValue(record.isLong, `${label}.isLong`),
|
|
1590
|
+
tokenType: decimalValue(record.tokenType, `${label}.tokenType`),
|
|
1591
|
+
riskPartner: decimalValue(record.riskPartner, `${label}.riskPartner`),
|
|
1592
|
+
strike: signedDecimalValue(record.strike, `${label}.strike`),
|
|
1593
|
+
width: decimalValue(record.width, `${label}.width`),
|
|
1594
|
+
tickLower: signedDecimalValue(record.tickLower, `${label}.tickLower`),
|
|
1595
|
+
tickUpper: signedDecimalValue(record.tickUpper, `${label}.tickUpper`)
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
function storedPositionArrayArg(args, fieldName) {
|
|
1599
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
1600
|
+
(item, index) => storedPositionValue(item, `args.${fieldName}[${index}]`)
|
|
1601
|
+
);
|
|
1602
|
+
}
|
|
1603
|
+
function storedPositionValue(value, label) {
|
|
1604
|
+
const record = recordValue(value, label);
|
|
1605
|
+
return {
|
|
1606
|
+
tokenId: decimalValue(record.tokenId, `${label}.tokenId`),
|
|
1607
|
+
legs: arrayValue(record.legs, `${label}.legs`).map((leg, index) => tokenIdLegValue(leg, `${label}.legs[${index}]`)),
|
|
1608
|
+
tickAtMint: signedDecimalValue(record.tickAtMint, `${label}.tickAtMint`),
|
|
1609
|
+
positionSize: decimalValue(record.positionSize, `${label}.positionSize`)
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
function vaultCandidatesByPoolArrayArg(args, fieldName) {
|
|
1613
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
1614
|
+
(item, index) => vaultCandidatesByPoolValue(item, `args.${fieldName}[${index}]`)
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
function vaultCandidatesByPoolValue(value, label) {
|
|
1618
|
+
const record = recordValue(value, label);
|
|
1619
|
+
return {
|
|
1620
|
+
poolAddress: stringValue(record.poolAddress, `${label}.poolAddress`),
|
|
1621
|
+
candidates: decimalArrayValue(record.candidates, `${label}.candidates`)
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
function uniswapAddressesValue(value, label) {
|
|
1625
|
+
const record = recordValue(value, label);
|
|
1626
|
+
return {
|
|
1627
|
+
universalRouter: stringValue(record.universalRouter, `${label}.universalRouter`),
|
|
1628
|
+
v4Quoter: stringValue(record.v4Quoter, `${label}.v4Quoter`),
|
|
1629
|
+
poolManager: stringValue(record.poolManager, `${label}.poolManager`),
|
|
1630
|
+
permit2: stringValue(record.permit2, `${label}.permit2`)
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
// src/internal/panopticScalars.ts
|
|
1635
|
+
var UINT48_MAX = (BigInt(1) << BigInt(48)) - BigInt(1);
|
|
1636
|
+
var UINT128_MAX = (BigInt(1) << BigInt(128)) - BigInt(1);
|
|
1637
|
+
var UINT160_MAX = (BigInt(1) << BigInt(160)) - BigInt(1);
|
|
1638
|
+
var UINT256_MAX = (BigInt(1) << BigInt(256)) - BigInt(1);
|
|
1639
|
+
var INT24_MIN = -(BigInt(1) << BigInt(23));
|
|
1640
|
+
var INT24_MAX = (BigInt(1) << BigInt(23)) - BigInt(1);
|
|
1641
|
+
function uint48Arg(args, fieldName) {
|
|
1642
|
+
return unsignedDecimalValue(args[fieldName], `args.${fieldName}`, UINT48_MAX, "uint48");
|
|
1643
|
+
}
|
|
1644
|
+
function uint128Arg(args, fieldName) {
|
|
1645
|
+
return unsignedDecimalValue(args[fieldName], `args.${fieldName}`, UINT128_MAX, "uint128");
|
|
1646
|
+
}
|
|
1647
|
+
function uint160Arg(args, fieldName) {
|
|
1648
|
+
return unsignedDecimalValue(args[fieldName], `args.${fieldName}`, UINT160_MAX, "uint160");
|
|
1649
|
+
}
|
|
1650
|
+
function uint256Arg(args, fieldName) {
|
|
1651
|
+
return unsignedDecimalValue(args[fieldName], `args.${fieldName}`, UINT256_MAX, "uint256");
|
|
1652
|
+
}
|
|
1653
|
+
function optionalUint256Arg(args, fieldName) {
|
|
1654
|
+
return args[fieldName] === void 0 ? void 0 : unsignedDecimalValue(args[fieldName], `args.${fieldName}`, UINT256_MAX, "uint256");
|
|
1655
|
+
}
|
|
1656
|
+
function uint256ArrayArg(args, fieldName) {
|
|
1657
|
+
const value = args[fieldName];
|
|
1658
|
+
if (!Array.isArray(value)) {
|
|
1659
|
+
throw new Error(`Panoptic args.${fieldName} must be an array.`);
|
|
1660
|
+
}
|
|
1661
|
+
return value.map((item, index) => unsignedDecimalValue(item, `args.${fieldName}[${index}]`, UINT256_MAX, "uint256"));
|
|
1662
|
+
}
|
|
1663
|
+
function int24Arg(args, fieldName) {
|
|
1664
|
+
return signedDecimalValue2(args[fieldName], `args.${fieldName}`, INT24_MIN, INT24_MAX, "int24");
|
|
1665
|
+
}
|
|
1666
|
+
function optionalInt24Arg(args, fieldName) {
|
|
1667
|
+
return args[fieldName] === void 0 ? void 0 : signedDecimalValue2(args[fieldName], `args.${fieldName}`, INT24_MIN, INT24_MAX, "int24");
|
|
1668
|
+
}
|
|
1669
|
+
function unsignedDecimalValue(value, label, maxValue, rangeLabel) {
|
|
1670
|
+
if (typeof value !== "string" || !/^(0|[1-9][0-9]*)$/.test(value)) {
|
|
1671
|
+
throw new Error(`Panoptic ${label} must be an unsigned decimal string.`);
|
|
1672
|
+
}
|
|
1673
|
+
const parsed = BigInt(value);
|
|
1674
|
+
if (parsed > maxValue) {
|
|
1675
|
+
throw new Error(`Panoptic ${label} exceeds ${rangeLabel} range.`);
|
|
1676
|
+
}
|
|
1677
|
+
return parsed;
|
|
1678
|
+
}
|
|
1679
|
+
function signedDecimalValue2(value, label, minValue, maxValue, rangeLabel) {
|
|
1680
|
+
if (typeof value !== "string" || !/^-?(0|[1-9][0-9]*)$/.test(value)) {
|
|
1681
|
+
throw new Error(`Panoptic ${label} must be a signed decimal string.`);
|
|
1682
|
+
}
|
|
1683
|
+
const parsed = BigInt(value);
|
|
1684
|
+
if (parsed < minValue || parsed > maxValue) {
|
|
1685
|
+
throw new Error(`Panoptic ${label} exceeds ${rangeLabel} range.`);
|
|
1686
|
+
}
|
|
1687
|
+
return parsed;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
// src/internal/panoptic/support.ts
|
|
1691
|
+
function rejectContext(request, method) {
|
|
1692
|
+
if (request.context !== void 0) {
|
|
1693
|
+
throw new Error(`Panoptic ${method} is a pure method and does not accept runtime context.`);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
function requireSourceContext(request, method) {
|
|
1697
|
+
if (request.context) {
|
|
1698
|
+
rejectExtraContextKeys(request, method);
|
|
1699
|
+
}
|
|
1700
|
+
if (!request.context?.sourceId && !request.context?.chainId) {
|
|
1701
|
+
throw new Error(`Panoptic ${method} requires context.sourceId or context.chainId.`);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
function rejectExtraContextKeys(request, method) {
|
|
1705
|
+
const context = request.context;
|
|
1706
|
+
if (!context) {
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
const allowed = /* @__PURE__ */ new Set(["chainId", "sourceId", "blockNumber", "account", "panopticSubgraphId", "rpcUrl"]);
|
|
1710
|
+
for (const key of Object.keys(context)) {
|
|
1711
|
+
if (!allowed.has(key)) {
|
|
1712
|
+
throw new Error(`Panoptic ${method} context.${key} is not supported by the schema.`);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
function rejectExtraKeys(args, allowedKeys, method) {
|
|
1717
|
+
const allowed = new Set(allowedKeys);
|
|
1718
|
+
for (const key of Object.keys(args)) {
|
|
1719
|
+
if (!allowed.has(key)) {
|
|
1720
|
+
throw new Error(`Panoptic ${method} args.${key} is not supported by the schema.`);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
function requireString(value, label) {
|
|
1725
|
+
if (typeof value !== "string") {
|
|
1726
|
+
throw new Error(`Panoptic ${label} must be a string.`);
|
|
1727
|
+
}
|
|
1728
|
+
return value;
|
|
1729
|
+
}
|
|
1730
|
+
function requirePlainResult(value, label) {
|
|
1731
|
+
if (!isRecord4(value)) {
|
|
1732
|
+
throw new Error(`Panoptic ${label} must be an object.`);
|
|
1733
|
+
}
|
|
1734
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1735
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
1736
|
+
throw new Error(`Panoptic ${label} must be a plain object.`);
|
|
1737
|
+
}
|
|
1738
|
+
return value;
|
|
1739
|
+
}
|
|
1740
|
+
function requireSdkFunction(sdkModule, name, label) {
|
|
1741
|
+
const defaultExport = isRecord4(sdkModule.default) ? sdkModule.default : void 0;
|
|
1742
|
+
const sdkExport = sdkModule[name] ?? defaultExport?.[name];
|
|
1743
|
+
if (typeof sdkExport !== "function") {
|
|
1744
|
+
throw new Error(`Panoptic runtime dependency "${label}" does not provide ${name}.`);
|
|
1745
|
+
}
|
|
1746
|
+
return sdkExport;
|
|
1747
|
+
}
|
|
1748
|
+
async function prepareRuntimeSourceContext(deps, request, options) {
|
|
1749
|
+
return preparePanopticSourceContext(
|
|
1750
|
+
request,
|
|
1751
|
+
await deps.viem(),
|
|
1752
|
+
options.sourceRegistry,
|
|
1753
|
+
options.operation,
|
|
1754
|
+
options.clientCache
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
function withSource(value, sourceContext, blockNumberRole, label, blockNumber, reconciled) {
|
|
1758
|
+
const projectedValue = omitSdkMeta(requirePlainResult(value, label));
|
|
1759
|
+
const sourceMeta = buildMethodSourceMeta(sourceContext, blockNumberRole, blockNumber, reconciled);
|
|
1760
|
+
return {
|
|
1761
|
+
...projectedValue,
|
|
1762
|
+
source: sourceMeta
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
function isRecord4(value) {
|
|
1766
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1767
|
+
}
|
|
1768
|
+
function omitSdkMeta(value) {
|
|
1769
|
+
const { _meta: _ignored, ...publicValue } = value;
|
|
1770
|
+
void _ignored;
|
|
1771
|
+
return publicValue;
|
|
1772
|
+
}
|
|
1773
|
+
function buildMethodSourceMeta(sourceContext, blockNumberRole, blockNumber, reconciled) {
|
|
1774
|
+
const { blockNumber: preparedBlockNumber, ...baseMeta } = sourceContext.sourceMeta;
|
|
1775
|
+
const sourceBlockNumber = blockNumber || preparedBlockNumber;
|
|
1776
|
+
return {
|
|
1777
|
+
...baseMeta,
|
|
1778
|
+
...blockNumberRole === "preflight" ? { preflightBlockNumber: sourceBlockNumber } : { blockNumber: sourceBlockNumber },
|
|
1779
|
+
blockNumberRole,
|
|
1780
|
+
...reconciled === void 0 ? {} : { reconciled }
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
// src/internal/panoptic/reads/account.ts
|
|
1785
|
+
async function getPosition({
|
|
1786
|
+
deps,
|
|
1787
|
+
method,
|
|
1788
|
+
request,
|
|
1789
|
+
options
|
|
1790
|
+
}) {
|
|
1791
|
+
const input = parseTokenIdRequest(request, method);
|
|
1792
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1793
|
+
const sdkGetPosition = await loadSdkV2Function(deps, "getPosition");
|
|
1794
|
+
return withSource(
|
|
1795
|
+
await sdkGetPosition({
|
|
1796
|
+
...ownerReadParams(sourceContext, input.account),
|
|
1797
|
+
poolAddress: input.poolAddress,
|
|
1798
|
+
tokenId: input.tokenId
|
|
1799
|
+
}),
|
|
1800
|
+
sourceContext,
|
|
1801
|
+
"pinned",
|
|
1802
|
+
`${method} result`
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
async function getPositions({
|
|
1806
|
+
deps,
|
|
1807
|
+
method,
|
|
1808
|
+
request,
|
|
1809
|
+
options
|
|
1810
|
+
}) {
|
|
1811
|
+
const input = parseTokenIdsRequest(request, method);
|
|
1812
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1813
|
+
const sdkGetPositions = await loadSdkV2Function(deps, "getPositions");
|
|
1814
|
+
return withSource(
|
|
1815
|
+
await sdkGetPositions({
|
|
1816
|
+
...ownerReadParams(sourceContext, input.account),
|
|
1817
|
+
poolAddress: input.poolAddress,
|
|
1818
|
+
tokenIds: input.tokenIds
|
|
1819
|
+
}),
|
|
1820
|
+
sourceContext,
|
|
1821
|
+
"pinned",
|
|
1822
|
+
`${method} result`
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
async function getOpenPositionIds({
|
|
1826
|
+
deps,
|
|
1827
|
+
method,
|
|
1828
|
+
request,
|
|
1829
|
+
options
|
|
1830
|
+
}) {
|
|
1831
|
+
const input = parseOpenPositionIdsRequest(request, method);
|
|
1832
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1833
|
+
const sdkGetOpenPositionIds = await loadSdkV2Function(deps, "getOpenPositionIds");
|
|
1834
|
+
const tokenIds = await sdkGetOpenPositionIds({
|
|
1835
|
+
client: sourceContext.client,
|
|
1836
|
+
chainId: BigInt(sourceContext.source.chainId),
|
|
1837
|
+
poolAddress: input.poolAddress,
|
|
1838
|
+
account: input.account,
|
|
1839
|
+
lastDispatchTxHash: input.lastDispatchTxHash
|
|
1840
|
+
});
|
|
1841
|
+
return withSource({ tokenIds }, sourceContext, "preflight", `${method} result`, void 0, false);
|
|
1842
|
+
}
|
|
1843
|
+
async function getAccountCollateral({
|
|
1844
|
+
deps,
|
|
1845
|
+
method,
|
|
1846
|
+
request,
|
|
1847
|
+
options
|
|
1848
|
+
}) {
|
|
1849
|
+
const input = parseAccountCollateralRequest(request, method);
|
|
1850
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1851
|
+
const sdkGetAccountCollateral = await loadSdkV2Function(deps, "getAccountCollateral");
|
|
1852
|
+
return withSource(
|
|
1853
|
+
await sdkGetAccountCollateral({
|
|
1854
|
+
...accountReadParams(sourceContext, input.account),
|
|
1855
|
+
poolAddress: input.poolAddress,
|
|
1856
|
+
collateralAddresses: input.collateralAddresses
|
|
1857
|
+
}),
|
|
1858
|
+
sourceContext,
|
|
1859
|
+
"pinned",
|
|
1860
|
+
`${method} result`
|
|
1861
|
+
);
|
|
1862
|
+
}
|
|
1863
|
+
async function getAccountSummaryBasic({
|
|
1864
|
+
deps,
|
|
1865
|
+
method,
|
|
1866
|
+
request,
|
|
1867
|
+
options
|
|
1868
|
+
}) {
|
|
1869
|
+
const input = parseAccountSummaryBasicRequest(request, method);
|
|
1870
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1871
|
+
const sdkGetAccountSummaryBasic = await loadSdkV2Function(deps, "getAccountSummaryBasic");
|
|
1872
|
+
return withSource(
|
|
1873
|
+
await sdkGetAccountSummaryBasic({
|
|
1874
|
+
...accountReadParams(sourceContext, input.account, true),
|
|
1875
|
+
poolAddress: input.poolAddress,
|
|
1876
|
+
tokenIds: input.tokenIds,
|
|
1877
|
+
poolMetadata: input.poolMetadata
|
|
1878
|
+
}),
|
|
1879
|
+
sourceContext,
|
|
1880
|
+
"pinned",
|
|
1881
|
+
`${method} result`
|
|
1882
|
+
);
|
|
1883
|
+
}
|
|
1884
|
+
async function getAccountSummaryRisk({
|
|
1885
|
+
deps,
|
|
1886
|
+
method,
|
|
1887
|
+
request,
|
|
1888
|
+
options
|
|
1889
|
+
}) {
|
|
1890
|
+
const input = parseAccountSummaryRiskRequest(request, method);
|
|
1891
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1892
|
+
const sdkGetAccountSummaryRisk = await loadSdkV2Function(deps, "getAccountSummaryRisk");
|
|
1893
|
+
return withSource(
|
|
1894
|
+
await sdkGetAccountSummaryRisk({
|
|
1895
|
+
...accountReadParams(sourceContext, input.account, true),
|
|
1896
|
+
poolAddress: input.poolAddress,
|
|
1897
|
+
tokenIds: input.tokenIds,
|
|
1898
|
+
queryAddress: input.queryAddress,
|
|
1899
|
+
atTick: input.atTick,
|
|
1900
|
+
includePendingPremium: input.includePendingPremium,
|
|
1901
|
+
poolMetadata: input.poolMetadata
|
|
1902
|
+
}),
|
|
1903
|
+
sourceContext,
|
|
1904
|
+
"pinned",
|
|
1905
|
+
`${method} result`
|
|
1906
|
+
);
|
|
1907
|
+
}
|
|
1908
|
+
async function getNetLiquidationValue({
|
|
1909
|
+
deps,
|
|
1910
|
+
method,
|
|
1911
|
+
request,
|
|
1912
|
+
options
|
|
1913
|
+
}) {
|
|
1914
|
+
const input = parseNetLiquidationValueRequest(request, method);
|
|
1915
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1916
|
+
const sdkGetNetLiquidationValue = await loadSdkV2Function(deps, "getNetLiquidationValue");
|
|
1917
|
+
return withSource(
|
|
1918
|
+
await sdkGetNetLiquidationValue({
|
|
1919
|
+
...accountReadParams(sourceContext, input.account),
|
|
1920
|
+
poolAddress: input.poolAddress,
|
|
1921
|
+
tokenIds: input.tokenIds,
|
|
1922
|
+
queryAddress: input.queryAddress,
|
|
1923
|
+
atTick: input.atTick,
|
|
1924
|
+
includePendingPremium: input.includePendingPremium
|
|
1925
|
+
}),
|
|
1926
|
+
sourceContext,
|
|
1927
|
+
"pinned",
|
|
1928
|
+
`${method} result`
|
|
1929
|
+
);
|
|
1930
|
+
}
|
|
1931
|
+
async function getNetLiquidationValues({
|
|
1932
|
+
deps,
|
|
1933
|
+
method,
|
|
1934
|
+
request,
|
|
1935
|
+
options
|
|
1936
|
+
}) {
|
|
1937
|
+
const input = parseNetLiquidationValuesRequest(request, method);
|
|
1938
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1939
|
+
const sdkGetNetLiquidationValues = await loadSdkV2Function(deps, "getNetLiquidationValues");
|
|
1940
|
+
return withSource(
|
|
1941
|
+
await sdkGetNetLiquidationValues({
|
|
1942
|
+
...accountReadParams(sourceContext, input.account),
|
|
1943
|
+
poolAddress: input.poolAddress,
|
|
1944
|
+
tokenIds: input.tokenIds,
|
|
1945
|
+
queryAddress: input.queryAddress,
|
|
1946
|
+
atTicks: input.atTicks,
|
|
1947
|
+
includePendingPremium: input.includePendingPremium
|
|
1948
|
+
}),
|
|
1949
|
+
sourceContext,
|
|
1950
|
+
"pinned",
|
|
1951
|
+
`${method} result`
|
|
1952
|
+
);
|
|
1953
|
+
}
|
|
1954
|
+
async function getLiquidationPrices({
|
|
1955
|
+
deps,
|
|
1956
|
+
method,
|
|
1957
|
+
request,
|
|
1958
|
+
options
|
|
1959
|
+
}) {
|
|
1960
|
+
const input = parseLiquidationPricesRequest(request, method);
|
|
1961
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
1962
|
+
const sdkGetLiquidationPrices = await loadSdkV2Function(deps, "getLiquidationPrices");
|
|
1963
|
+
return withSource(
|
|
1964
|
+
await sdkGetLiquidationPrices({
|
|
1965
|
+
...accountReadParams(sourceContext, input.account),
|
|
1966
|
+
poolAddress: input.poolAddress,
|
|
1967
|
+
tokenIds: input.tokenIds,
|
|
1968
|
+
queryAddress: input.queryAddress
|
|
1969
|
+
}),
|
|
1970
|
+
sourceContext,
|
|
1971
|
+
"pinned",
|
|
1972
|
+
`${method} result`
|
|
1973
|
+
);
|
|
1974
|
+
}
|
|
1975
|
+
function parseTokenIdRequest(request, method) {
|
|
1976
|
+
const { account, args } = accountArgs(request, method, ["poolAddress", "tokenId"]);
|
|
1977
|
+
return { account, poolAddress: poolAddress(args.poolAddress, method), tokenId: uint256Arg(args, "tokenId") };
|
|
1978
|
+
}
|
|
1979
|
+
function parseTokenIdsRequest(request, method) {
|
|
1980
|
+
const { account, args } = accountArgs(request, method, ["poolAddress", "tokenIds"]);
|
|
1981
|
+
return { account, poolAddress: poolAddress(args.poolAddress, method), tokenIds: uint256ArrayArg(args, "tokenIds") };
|
|
1982
|
+
}
|
|
1983
|
+
function parseOpenPositionIdsRequest(request, method) {
|
|
1984
|
+
rejectLatestOnlyBlockNumber(request, method);
|
|
1985
|
+
const { account, args } = accountArgs(request, method, ["poolAddress", "lastDispatchTxHash"]);
|
|
1986
|
+
return {
|
|
1987
|
+
account,
|
|
1988
|
+
poolAddress: poolAddress(args.poolAddress, method),
|
|
1989
|
+
lastDispatchTxHash: normalizePanopticHex(
|
|
1990
|
+
requireArgString(args, "lastDispatchTxHash", method),
|
|
1991
|
+
`${method} args.lastDispatchTxHash`
|
|
1992
|
+
)
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1995
|
+
function parseAccountCollateralRequest(request, method) {
|
|
1996
|
+
const { account, args } = accountArgs(request, method, ["poolAddress", "collateralAddresses"]);
|
|
1997
|
+
return {
|
|
1998
|
+
account,
|
|
1999
|
+
poolAddress: poolAddress(args.poolAddress, method),
|
|
2000
|
+
...args.collateralAddresses === void 0 ? {} : {
|
|
2001
|
+
collateralAddresses: collateralAddressesValue(args.collateralAddresses, `${method} args.collateralAddresses`)
|
|
2002
|
+
}
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
2005
|
+
function parseAccountSummaryBasicRequest(request, method) {
|
|
2006
|
+
const { account, args } = accountArgs(request, method, ["poolAddress", "tokenIds", "poolMetadata"]);
|
|
2007
|
+
return {
|
|
2008
|
+
account,
|
|
2009
|
+
poolAddress: poolAddress(args.poolAddress, method),
|
|
2010
|
+
tokenIds: uint256ArrayArg(args, "tokenIds"),
|
|
2011
|
+
...args.poolMetadata === void 0 ? {} : { poolMetadata: poolMetadataValue(args.poolMetadata, `${method} args.poolMetadata`) }
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
function parseAccountSummaryRiskRequest(request, method) {
|
|
2015
|
+
const { account, args } = accountArgs(request, method, [
|
|
2016
|
+
"poolAddress",
|
|
2017
|
+
"tokenIds",
|
|
2018
|
+
"queryAddress",
|
|
2019
|
+
"atTick",
|
|
2020
|
+
"includePendingPremium",
|
|
2021
|
+
"poolMetadata"
|
|
2022
|
+
]);
|
|
2023
|
+
return {
|
|
2024
|
+
account,
|
|
2025
|
+
poolAddress: poolAddress(args.poolAddress, method),
|
|
2026
|
+
tokenIds: uint256ArrayArg(args, "tokenIds"),
|
|
2027
|
+
queryAddress: normalizePanopticAddress(args.queryAddress, `${method} args.queryAddress`),
|
|
2028
|
+
atTick: optionalSignedDecimalArg(args, "atTick"),
|
|
2029
|
+
includePendingPremium: optionalBooleanArg(args, "includePendingPremium"),
|
|
2030
|
+
...args.poolMetadata === void 0 ? {} : { poolMetadata: poolMetadataValue(args.poolMetadata, `${method} args.poolMetadata`) }
|
|
2031
|
+
};
|
|
2032
|
+
}
|
|
2033
|
+
function parseNetLiquidationValueRequest(request, method) {
|
|
2034
|
+
const { account, args } = accountArgs(request, method, [
|
|
2035
|
+
"poolAddress",
|
|
2036
|
+
"tokenIds",
|
|
2037
|
+
"queryAddress",
|
|
2038
|
+
"atTick",
|
|
2039
|
+
"includePendingPremium"
|
|
2040
|
+
]);
|
|
2041
|
+
return {
|
|
2042
|
+
account,
|
|
2043
|
+
poolAddress: poolAddress(args.poolAddress, method),
|
|
2044
|
+
tokenIds: uint256ArrayArg(args, "tokenIds"),
|
|
2045
|
+
queryAddress: normalizePanopticAddress(args.queryAddress, `${method} args.queryAddress`),
|
|
2046
|
+
atTick: optionalSignedDecimalArg(args, "atTick"),
|
|
2047
|
+
includePendingPremium: optionalBooleanArg(args, "includePendingPremium")
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
function parseNetLiquidationValuesRequest(request, method) {
|
|
2051
|
+
const { account, args } = accountArgs(request, method, [
|
|
2052
|
+
"poolAddress",
|
|
2053
|
+
"tokenIds",
|
|
2054
|
+
"queryAddress",
|
|
2055
|
+
"atTicks",
|
|
2056
|
+
"includePendingPremium"
|
|
2057
|
+
]);
|
|
2058
|
+
return {
|
|
2059
|
+
account,
|
|
2060
|
+
poolAddress: poolAddress(args.poolAddress, method),
|
|
2061
|
+
tokenIds: uint256ArrayArg(args, "tokenIds"),
|
|
2062
|
+
queryAddress: normalizePanopticAddress(args.queryAddress, `${method} args.queryAddress`),
|
|
2063
|
+
atTicks: signedDecimalArrayArg(args, "atTicks"),
|
|
2064
|
+
includePendingPremium: optionalBooleanArg(args, "includePendingPremium")
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
function parseLiquidationPricesRequest(request, method) {
|
|
2068
|
+
const { account, args } = accountArgs(request, method, ["poolAddress", "tokenIds", "queryAddress"]);
|
|
2069
|
+
return {
|
|
2070
|
+
account,
|
|
2071
|
+
poolAddress: poolAddress(args.poolAddress, method),
|
|
2072
|
+
tokenIds: uint256ArrayArg(args, "tokenIds"),
|
|
2073
|
+
queryAddress: normalizePanopticAddress(args.queryAddress, `${method} args.queryAddress`)
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
function accountArgs(request, method, allowedKeys) {
|
|
2077
|
+
requireSourceContext(request, method);
|
|
2078
|
+
const account = requireAccount(request, method);
|
|
2079
|
+
const args = requestArgs(request, method);
|
|
2080
|
+
rejectExtraKeys(args, allowedKeys, method);
|
|
2081
|
+
return { account, args };
|
|
2082
|
+
}
|
|
2083
|
+
function requireAccount(request, method) {
|
|
2084
|
+
const account = request?.context?.account;
|
|
2085
|
+
if (!account) {
|
|
2086
|
+
throw new Error(`Panoptic ${method} requires context.account.`);
|
|
2087
|
+
}
|
|
2088
|
+
return normalizePanopticAddress(account, `${method} context.account`);
|
|
2089
|
+
}
|
|
2090
|
+
function rejectLatestOnlyBlockNumber(request, method) {
|
|
2091
|
+
if (request.context?.blockNumber !== void 0) {
|
|
2092
|
+
throw new Error(`Panoptic ${method} does not accept context.blockNumber because its block policy is latestOnly.`);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
function ownerReadParams(sourceContext, account) {
|
|
2096
|
+
return { client: sourceContext.client, blockNumber: BigInt(sourceContext.blockNumber), owner: account };
|
|
2097
|
+
}
|
|
2098
|
+
function accountReadParams(sourceContext, account, includeChainId = false) {
|
|
2099
|
+
return {
|
|
2100
|
+
client: sourceContext.client,
|
|
2101
|
+
...includeChainId ? { chainId: BigInt(sourceContext.source.chainId) } : {},
|
|
2102
|
+
blockNumber: BigInt(sourceContext.blockNumber),
|
|
2103
|
+
account
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
async function loadSdkV2Function(deps, name) {
|
|
2107
|
+
return requireSdkFunction(await deps.sdkV2(), name, "@panoptic-eng/sdk/v2");
|
|
2108
|
+
}
|
|
2109
|
+
function poolAddress(value, method) {
|
|
2110
|
+
return normalizePanopticAddress(value, `${method} args.poolAddress`);
|
|
2111
|
+
}
|
|
2112
|
+
function requireArgString(args, fieldName, method) {
|
|
2113
|
+
const value = args[fieldName];
|
|
2114
|
+
if (value === void 0) {
|
|
2115
|
+
throw new Error(`Panoptic ${method} args.${fieldName} is required.`);
|
|
2116
|
+
}
|
|
2117
|
+
if (typeof value !== "string") {
|
|
2118
|
+
throw new Error(`Panoptic ${method} args.${fieldName} must be a string.`);
|
|
2119
|
+
}
|
|
2120
|
+
return value;
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
// src/internal/panoptic/reads/greeks.ts
|
|
2124
|
+
async function getPositionGreeks({
|
|
2125
|
+
deps,
|
|
2126
|
+
method,
|
|
2127
|
+
request,
|
|
2128
|
+
options
|
|
2129
|
+
}) {
|
|
2130
|
+
const input = parseGetPositionGreeksRequest(request, method);
|
|
2131
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2132
|
+
const sdkGetPositionGreeks = await loadSdkFunction(deps, "getPositionGreeks");
|
|
2133
|
+
const rawResult = await sdkGetPositionGreeks({
|
|
2134
|
+
client: sourceContext.client,
|
|
2135
|
+
blockNumber: BigInt(sourceContext.blockNumber),
|
|
2136
|
+
poolAddress: input.poolAddress,
|
|
2137
|
+
owner: input.account,
|
|
2138
|
+
tokenId: input.tokenId,
|
|
2139
|
+
atTick: input.atTick
|
|
2140
|
+
});
|
|
2141
|
+
return withSource(rawResult, sourceContext, "pinned", "greeks.getPositionGreeks result");
|
|
2142
|
+
}
|
|
2143
|
+
async function calculatePositionGreeks({ deps, method, request }) {
|
|
2144
|
+
const input = parseCalculatePositionGreeksRequest(request, method);
|
|
2145
|
+
const sdkV2 = await deps.sdkV2();
|
|
2146
|
+
const sdkCalculatePositionGreeks = requireSdkFunction(sdkV2, "calculatePositionGreeks", "@panoptic-eng/sdk/v2");
|
|
2147
|
+
const result = await sdkCalculatePositionGreeks(input);
|
|
2148
|
+
if (input.swapAtMint !== void 0) {
|
|
2149
|
+
const calculatePositionDeltaWithSwap = requireSdkFunction(
|
|
2150
|
+
sdkV2,
|
|
2151
|
+
"calculatePositionDeltaWithSwap",
|
|
2152
|
+
"@panoptic-eng/sdk/v2"
|
|
2153
|
+
);
|
|
2154
|
+
const delta = await calculatePositionDeltaWithSwap(input);
|
|
2155
|
+
if (isRecord3(result)) {
|
|
2156
|
+
return { ...result, delta };
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
return result;
|
|
2160
|
+
}
|
|
2161
|
+
async function calculateAccountGreeksPure({ deps, method, request }) {
|
|
2162
|
+
const input = parseCalculateAccountGreeksPureRequest(request, method);
|
|
2163
|
+
const sdkCalculateAccountGreeksPure = await loadSdkFunction(deps, "calculateAccountGreeksPure");
|
|
2164
|
+
return sdkCalculateAccountGreeksPure(input);
|
|
2165
|
+
}
|
|
2166
|
+
function parseGetPositionGreeksRequest(request, method) {
|
|
2167
|
+
requireSourceContext(request, method);
|
|
2168
|
+
const account = requireAccount2(request, method);
|
|
2169
|
+
const args = requestArgs(request, method);
|
|
2170
|
+
rejectExtraKeys(args, ["poolAddress", "tokenId", "atTick"], method);
|
|
2171
|
+
return {
|
|
2172
|
+
account,
|
|
2173
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2174
|
+
tokenId: uint256Arg(args, "tokenId"),
|
|
2175
|
+
atTick: optionalSignedDecimalArg(args, "atTick")
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
function parseCalculatePositionGreeksRequest(request, method) {
|
|
2179
|
+
rejectContext(request, method);
|
|
2180
|
+
const args = requestArgs(request, method);
|
|
2181
|
+
rejectExtraKeys(
|
|
2182
|
+
args,
|
|
2183
|
+
["legs", "currentTick", "mintTick", "positionSize", "poolTickSpacing", "assetIndex", "swapAtMint"],
|
|
2184
|
+
method
|
|
2185
|
+
);
|
|
2186
|
+
return {
|
|
2187
|
+
legs: tokenIdLegArrayArg(args, "legs"),
|
|
2188
|
+
currentTick: signedDecimalArg(args, "currentTick"),
|
|
2189
|
+
mintTick: signedDecimalArg(args, "mintTick"),
|
|
2190
|
+
positionSize: decimalArg(args, "positionSize"),
|
|
2191
|
+
poolTickSpacing: decimalArg(args, "poolTickSpacing"),
|
|
2192
|
+
...args.assetIndex === void 0 ? {} : { assetIndex: optionalDecimalArg(args, "assetIndex") },
|
|
2193
|
+
...args.swapAtMint === void 0 ? {} : { swapAtMint: optionalBooleanArg(args, "swapAtMint") }
|
|
2194
|
+
};
|
|
2195
|
+
}
|
|
2196
|
+
function parseCalculateAccountGreeksPureRequest(request, method) {
|
|
2197
|
+
rejectContext(request, method);
|
|
2198
|
+
const args = requestArgs(request, method);
|
|
2199
|
+
rejectExtraKeys(args, ["positions", "tickSpacing", "atTicks", "collateralAssets", "assetIndex"], method);
|
|
2200
|
+
return {
|
|
2201
|
+
positions: storedPositionArrayArg(args, "positions"),
|
|
2202
|
+
tickSpacing: decimalArg(args, "tickSpacing"),
|
|
2203
|
+
atTicks: signedDecimalArrayArg(args, "atTicks"),
|
|
2204
|
+
...args.collateralAssets === void 0 ? {} : { collateralAssets: optionalDecimalArrayArg(args, "collateralAssets") },
|
|
2205
|
+
...args.assetIndex === void 0 ? {} : { assetIndex: optionalDecimalArg(args, "assetIndex") }
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
async function loadSdkFunction(deps, name) {
|
|
2209
|
+
return requireSdkFunction(await deps.sdkV2(), name, "@panoptic-eng/sdk/v2");
|
|
2210
|
+
}
|
|
2211
|
+
function requireAccount2(request, method) {
|
|
2212
|
+
const account = request.context?.account;
|
|
2213
|
+
if (!account) {
|
|
2214
|
+
throw new Error(`Panoptic ${method} requires context.account.`);
|
|
2215
|
+
}
|
|
2216
|
+
return normalizePanopticAddress(account, `${method} context.account`);
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
// src/internal/panoptic/reads/hypovault.ts
|
|
2220
|
+
async function buildVaultManagerInputAtBlock({
|
|
2221
|
+
deps,
|
|
2222
|
+
method,
|
|
2223
|
+
request,
|
|
2224
|
+
options
|
|
2225
|
+
}) {
|
|
2226
|
+
const input = parseBuildVaultManagerInputAtBlockRequest(request, method);
|
|
2227
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2228
|
+
const sdkBuildManagerInputAtBlock = requireSdkFunction(
|
|
2229
|
+
await deps.sdk(),
|
|
2230
|
+
"buildManagerInputAtBlock",
|
|
2231
|
+
"@panoptic-eng/sdk"
|
|
2232
|
+
);
|
|
2233
|
+
const managerInput = await sdkBuildManagerInputAtBlock({
|
|
2234
|
+
viemClient: sourceContext.client,
|
|
2235
|
+
poolInfos: input.poolInfos,
|
|
2236
|
+
tokenIds: input.tokenIds,
|
|
2237
|
+
underlyingToken: input.underlyingToken,
|
|
2238
|
+
wethAddress: input.wethAddress,
|
|
2239
|
+
blockNumber: BigInt(sourceContext.blockNumber),
|
|
2240
|
+
erc4626Vaults: input.erc4626Vaults
|
|
2241
|
+
});
|
|
2242
|
+
return withSource({ managerInput }, sourceContext, "pinned", "hypovault.buildVaultManagerInputAtBlock result");
|
|
2243
|
+
}
|
|
2244
|
+
async function verifyVaultOpenTokenIdsAtBlock({
|
|
2245
|
+
deps,
|
|
2246
|
+
method,
|
|
2247
|
+
request,
|
|
2248
|
+
options
|
|
2249
|
+
}) {
|
|
2250
|
+
const input = parseVerifyVaultOpenTokenIdsAtBlockRequest(request, method);
|
|
2251
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2252
|
+
const sdkVerifyVaultOpenTokenIdsAtBlock = requireSdkFunction(
|
|
2253
|
+
await deps.sdk(),
|
|
2254
|
+
"verifyVaultOpenTokenIdsAtBlock",
|
|
2255
|
+
"@panoptic-eng/sdk"
|
|
2256
|
+
);
|
|
2257
|
+
const tokenIdsByPool = await sdkVerifyVaultOpenTokenIdsAtBlock({
|
|
2258
|
+
viemClient: sourceContext.client,
|
|
2259
|
+
vaultAddress: input.vaultAddress,
|
|
2260
|
+
candidatesByPool: input.candidatesByPool,
|
|
2261
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2262
|
+
});
|
|
2263
|
+
return withSource({ tokenIdsByPool }, sourceContext, "pinned", "hypovault.verifyVaultOpenTokenIdsAtBlock result");
|
|
2264
|
+
}
|
|
2265
|
+
async function getOpenPositionIds2({
|
|
2266
|
+
deps,
|
|
2267
|
+
method,
|
|
2268
|
+
request,
|
|
2269
|
+
options
|
|
2270
|
+
}) {
|
|
2271
|
+
const input = parseGetOpenPositionIdsRequest(request, method);
|
|
2272
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2273
|
+
const sdkGetOpenPositionIds = requireSdkFunction(await deps.sdkV2(), "getOpenPositionIds", "@panoptic-eng/sdk/v2");
|
|
2274
|
+
const tokenIds = await sdkGetOpenPositionIds({
|
|
2275
|
+
client: sourceContext.client,
|
|
2276
|
+
chainId: BigInt(sourceContext.source.chainId),
|
|
2277
|
+
poolAddress: input.poolAddress,
|
|
2278
|
+
account: input.account,
|
|
2279
|
+
lastDispatchTxHash: input.lastDispatchTxHash
|
|
2280
|
+
});
|
|
2281
|
+
return withSource({ tokenIds }, sourceContext, "preflight", "hypovault.getOpenPositionIds result", void 0, false);
|
|
2282
|
+
}
|
|
2283
|
+
async function getEpochContext({
|
|
2284
|
+
deps,
|
|
2285
|
+
method,
|
|
2286
|
+
request,
|
|
2287
|
+
options
|
|
2288
|
+
}) {
|
|
2289
|
+
const input = parseGetEpochContextRequest(request, method);
|
|
2290
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2291
|
+
const readContract = readContractFunction(sourceContext.client, method);
|
|
2292
|
+
const [depositEpoch, withdrawalEpoch, totalSupply] = await Promise.all([
|
|
2293
|
+
readContract({
|
|
2294
|
+
address: input.vaultAddress,
|
|
2295
|
+
abi: HYPOVAULT_READ_ABI,
|
|
2296
|
+
functionName: "depositEpoch",
|
|
2297
|
+
args: [],
|
|
2298
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2299
|
+
}),
|
|
2300
|
+
readContract({
|
|
2301
|
+
address: input.vaultAddress,
|
|
2302
|
+
abi: HYPOVAULT_READ_ABI,
|
|
2303
|
+
functionName: "withdrawalEpoch",
|
|
2304
|
+
args: [],
|
|
2305
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2306
|
+
}),
|
|
2307
|
+
readContract({
|
|
2308
|
+
address: input.vaultAddress,
|
|
2309
|
+
abi: HYPOVAULT_READ_ABI,
|
|
2310
|
+
functionName: "totalSupply",
|
|
2311
|
+
args: [],
|
|
2312
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2313
|
+
})
|
|
2314
|
+
]);
|
|
2315
|
+
const depositEpochNumber = toBigInt(depositEpoch, `${method} depositEpoch`);
|
|
2316
|
+
const withdrawalEpochNumber = toBigInt(withdrawalEpoch, `${method} withdrawalEpoch`);
|
|
2317
|
+
const [depositState, withdrawalState, queuedDeposit, queuedWithdrawal, block] = await Promise.all([
|
|
2318
|
+
readContract({
|
|
2319
|
+
address: input.vaultAddress,
|
|
2320
|
+
abi: HYPOVAULT_READ_ABI,
|
|
2321
|
+
functionName: "depositEpochState",
|
|
2322
|
+
args: [depositEpochNumber],
|
|
2323
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2324
|
+
}),
|
|
2325
|
+
readContract({
|
|
2326
|
+
address: input.vaultAddress,
|
|
2327
|
+
abi: HYPOVAULT_READ_ABI,
|
|
2328
|
+
functionName: "withdrawalEpochState",
|
|
2329
|
+
args: [withdrawalEpochNumber],
|
|
2330
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2331
|
+
}),
|
|
2332
|
+
input.account ? readContract({
|
|
2333
|
+
address: input.vaultAddress,
|
|
2334
|
+
abi: HYPOVAULT_READ_ABI,
|
|
2335
|
+
functionName: "queuedDeposit",
|
|
2336
|
+
args: [input.account, depositEpochNumber],
|
|
2337
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2338
|
+
}) : void 0,
|
|
2339
|
+
input.account ? readContract({
|
|
2340
|
+
address: input.vaultAddress,
|
|
2341
|
+
abi: HYPOVAULT_READ_ABI,
|
|
2342
|
+
functionName: "queuedWithdrawal",
|
|
2343
|
+
args: [input.account, withdrawalEpochNumber],
|
|
2344
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2345
|
+
}) : void 0,
|
|
2346
|
+
getBlockIfAvailable(sourceContext.client, sourceContext.blockNumber)
|
|
2347
|
+
]);
|
|
2348
|
+
const deposit = depositEpochState(depositState, method);
|
|
2349
|
+
const withdrawal = withdrawalEpochState(withdrawalState, method);
|
|
2350
|
+
return withSource(
|
|
2351
|
+
{
|
|
2352
|
+
vaultAddress: input.vaultAddress,
|
|
2353
|
+
...input.account === void 0 ? {} : { account: input.account },
|
|
2354
|
+
totalSupply: toBigInt(totalSupply, `${method} totalSupply`).toString(10),
|
|
2355
|
+
...block?.timestamp === void 0 ? {} : { currentTimestamp: block.timestamp.toString(10) },
|
|
2356
|
+
deposit: {
|
|
2357
|
+
epoch: depositEpochNumber.toString(10),
|
|
2358
|
+
...deposit,
|
|
2359
|
+
pendingValue: nonnegativeDifference(deposit.assetsDeposited, deposit.assetsFulfilled).toString(10),
|
|
2360
|
+
...queuedDeposit === void 0 ? {} : { queuedDeposit: toBigInt(queuedDeposit, `${method} queuedDeposit`).toString(10) }
|
|
2361
|
+
},
|
|
2362
|
+
withdrawal: {
|
|
2363
|
+
epoch: withdrawalEpochNumber.toString(10),
|
|
2364
|
+
...withdrawal,
|
|
2365
|
+
pendingShares: nonnegativeDifference(withdrawal.sharesWithdrawn, withdrawal.sharesFulfilled).toString(10),
|
|
2366
|
+
...queuedWithdrawal === void 0 ? {} : { queuedWithdrawal: queuedWithdrawalState(queuedWithdrawal, method) }
|
|
2367
|
+
}
|
|
2368
|
+
},
|
|
2369
|
+
sourceContext,
|
|
2370
|
+
"pinned",
|
|
2371
|
+
"hypovault.getEpochContext result"
|
|
2372
|
+
);
|
|
2373
|
+
}
|
|
2374
|
+
async function getPositionsHashStatus({
|
|
2375
|
+
deps,
|
|
2376
|
+
method,
|
|
2377
|
+
request,
|
|
2378
|
+
options
|
|
2379
|
+
}) {
|
|
2380
|
+
const input = parseGetPositionsHashStatusRequest(request, method);
|
|
2381
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2382
|
+
const readContract = readContractFunction(sourceContext.client, method);
|
|
2383
|
+
const positionsHash = normalizePanopticHex(
|
|
2384
|
+
await readContract({
|
|
2385
|
+
address: input.poolAddress,
|
|
2386
|
+
abi: PANOPTIC_POOL_READ_ABI,
|
|
2387
|
+
functionName: "positionsHash",
|
|
2388
|
+
args: [input.account],
|
|
2389
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
2390
|
+
}),
|
|
2391
|
+
`${method} positionsHash`
|
|
2392
|
+
);
|
|
2393
|
+
const tokenIds = input.tokenIds ?? await recoverTokenIds(deps, sourceContext, input, method);
|
|
2394
|
+
const computedHash = tokenIds === void 0 ? void 0 : await computePositionsHash(await deps.viem(), tokenIds, method);
|
|
2395
|
+
return withSource(
|
|
2396
|
+
{
|
|
2397
|
+
account: input.account,
|
|
2398
|
+
poolAddress: input.poolAddress,
|
|
2399
|
+
positionsHash,
|
|
2400
|
+
...tokenIds === void 0 ? {} : { tokenIds },
|
|
2401
|
+
...computedHash === void 0 ? {} : { computedHash, valid: computedHash === positionsHash }
|
|
2402
|
+
},
|
|
2403
|
+
sourceContext,
|
|
2404
|
+
"pinned",
|
|
2405
|
+
"hypovault.getPositionsHashStatus result"
|
|
2406
|
+
);
|
|
2407
|
+
}
|
|
2408
|
+
function parseBuildVaultManagerInputAtBlockRequest(request, method) {
|
|
2409
|
+
requireSourceContext(request, method);
|
|
2410
|
+
const args = requestArgs(request, method);
|
|
2411
|
+
rejectExtraKeys(
|
|
2412
|
+
args,
|
|
2413
|
+
["vaultAddress", "underlyingToken", "poolInfos", "tokenIds", "managerAddress", "wethAddress", "erc4626Vaults"],
|
|
2414
|
+
method
|
|
2415
|
+
);
|
|
2416
|
+
return {
|
|
2417
|
+
vaultAddress: normalizePanopticAddress(args.vaultAddress, `${method} args.vaultAddress`),
|
|
2418
|
+
underlyingToken: normalizePanopticAddress(args.underlyingToken, `${method} args.underlyingToken`),
|
|
2419
|
+
poolInfos: poolInfoArrayArg(args, "poolInfos"),
|
|
2420
|
+
tokenIds: decimalMatrixArg(args, "tokenIds"),
|
|
2421
|
+
...args.wethAddress === void 0 ? {} : { wethAddress: normalizePanopticAddress(args.wethAddress, `${method} args.wethAddress`) },
|
|
2422
|
+
...args.erc4626Vaults === void 0 ? {} : { erc4626Vaults: optionalStringArrayArg(args, "erc4626Vaults") }
|
|
2423
|
+
};
|
|
2424
|
+
}
|
|
2425
|
+
function parseVerifyVaultOpenTokenIdsAtBlockRequest(request, method) {
|
|
2426
|
+
requireSourceContext(request, method);
|
|
2427
|
+
const args = requestArgs(request, method);
|
|
2428
|
+
rejectExtraKeys(args, ["vaultAddress", "candidatesByPool"], method);
|
|
2429
|
+
return {
|
|
2430
|
+
vaultAddress: normalizePanopticAddress(args.vaultAddress, `${method} args.vaultAddress`),
|
|
2431
|
+
candidatesByPool: vaultCandidatesByPoolArrayArg(args, "candidatesByPool")
|
|
2432
|
+
};
|
|
2433
|
+
}
|
|
2434
|
+
function parseGetOpenPositionIdsRequest(request, method) {
|
|
2435
|
+
requireSourceContext(request, method);
|
|
2436
|
+
rejectLatestOnlyBlockNumber2(request, method);
|
|
2437
|
+
const account = requireAccount3(request, method);
|
|
2438
|
+
const args = requestArgs(request, method);
|
|
2439
|
+
rejectExtraKeys(args, ["poolAddress", "lastDispatchTxHash"], method);
|
|
2440
|
+
return {
|
|
2441
|
+
account,
|
|
2442
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2443
|
+
lastDispatchTxHash: normalizePanopticHex(
|
|
2444
|
+
requireArgString2(args, "lastDispatchTxHash", method),
|
|
2445
|
+
`${method} args.lastDispatchTxHash`
|
|
2446
|
+
)
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
function parseGetEpochContextRequest(request, method) {
|
|
2450
|
+
requireSourceContext(request, method);
|
|
2451
|
+
const args = requestArgs(request, method);
|
|
2452
|
+
rejectExtraKeys(args, ["vaultAddress", "account"], method);
|
|
2453
|
+
return {
|
|
2454
|
+
vaultAddress: normalizePanopticAddress(args.vaultAddress, `${method} args.vaultAddress`),
|
|
2455
|
+
...args.account === void 0 ? {} : { account: normalizePanopticAddress(args.account, `${method} args.account`) }
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
function parseGetPositionsHashStatusRequest(request, method) {
|
|
2459
|
+
requireSourceContext(request, method);
|
|
2460
|
+
const args = requestArgs(request, method);
|
|
2461
|
+
rejectExtraKeys(args, ["poolAddress", "account", "tokenIds", "lastDispatchTxHash"], method);
|
|
2462
|
+
return {
|
|
2463
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2464
|
+
account: normalizePanopticAddress(args.account ?? request.context?.account, `${method} args.account`),
|
|
2465
|
+
...args.tokenIds === void 0 ? {} : { tokenIds: decimalMatrixArg({ tokenIds: [args.tokenIds] }, "tokenIds")[0].map((id) => id.toString(10)) },
|
|
2466
|
+
...args.lastDispatchTxHash === void 0 ? {} : {
|
|
2467
|
+
lastDispatchTxHash: normalizePanopticHex(
|
|
2468
|
+
requireArgString2(args, "lastDispatchTxHash", method),
|
|
2469
|
+
`${method} args.lastDispatchTxHash`
|
|
2470
|
+
)
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
function requireAccount3(request, method) {
|
|
2475
|
+
const account = request.context?.account;
|
|
2476
|
+
if (!account) {
|
|
2477
|
+
throw new Error(`Panoptic ${method} requires context.account.`);
|
|
2478
|
+
}
|
|
2479
|
+
return normalizePanopticAddress(account, `${method} context.account`);
|
|
2480
|
+
}
|
|
2481
|
+
function requireArgString2(args, fieldName, method) {
|
|
2482
|
+
const value = args[fieldName];
|
|
2483
|
+
if (value === void 0) {
|
|
2484
|
+
throw new Error(`Panoptic ${method} args.${fieldName} is required.`);
|
|
2485
|
+
}
|
|
2486
|
+
if (typeof value !== "string") {
|
|
2487
|
+
throw new Error(`Panoptic ${method} args.${fieldName} must be a string.`);
|
|
2488
|
+
}
|
|
2489
|
+
return value;
|
|
2490
|
+
}
|
|
2491
|
+
function rejectLatestOnlyBlockNumber2(request, method) {
|
|
2492
|
+
if (request.context?.blockNumber !== void 0) {
|
|
2493
|
+
throw new Error(`Panoptic ${method} does not accept context.blockNumber because its block policy is latestOnly.`);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
var HYPOVAULT_READ_ABI = [
|
|
2497
|
+
{ type: "function", name: "depositEpoch", stateMutability: "view", inputs: [], outputs: [{ type: "uint128" }] },
|
|
2498
|
+
{ type: "function", name: "withdrawalEpoch", stateMutability: "view", inputs: [], outputs: [{ type: "uint128" }] },
|
|
2499
|
+
{ type: "function", name: "totalSupply", stateMutability: "view", inputs: [], outputs: [{ type: "uint256" }] },
|
|
2500
|
+
{
|
|
2501
|
+
type: "function",
|
|
2502
|
+
name: "depositEpochState",
|
|
2503
|
+
stateMutability: "view",
|
|
2504
|
+
inputs: [{ type: "uint256" }],
|
|
2505
|
+
outputs: [
|
|
2506
|
+
{ name: "assetsDeposited", type: "uint128" },
|
|
2507
|
+
{ name: "assetsFulfilled", type: "uint128" },
|
|
2508
|
+
{ name: "sharesReceived", type: "uint128" }
|
|
2509
|
+
]
|
|
2510
|
+
},
|
|
2511
|
+
{
|
|
2512
|
+
type: "function",
|
|
2513
|
+
name: "withdrawalEpochState",
|
|
2514
|
+
stateMutability: "view",
|
|
2515
|
+
inputs: [{ type: "uint256" }],
|
|
2516
|
+
outputs: [
|
|
2517
|
+
{ name: "sharesWithdrawn", type: "uint128" },
|
|
2518
|
+
{ name: "sharesFulfilled", type: "uint128" },
|
|
2519
|
+
{ name: "assetsPaid", type: "uint128" }
|
|
2520
|
+
]
|
|
2521
|
+
},
|
|
2522
|
+
{
|
|
2523
|
+
type: "function",
|
|
2524
|
+
name: "queuedDeposit",
|
|
2525
|
+
stateMutability: "view",
|
|
2526
|
+
inputs: [{ type: "address" }, { type: "uint256" }],
|
|
2527
|
+
outputs: [{ type: "uint128" }]
|
|
2528
|
+
},
|
|
2529
|
+
{
|
|
2530
|
+
type: "function",
|
|
2531
|
+
name: "queuedWithdrawal",
|
|
2532
|
+
stateMutability: "view",
|
|
2533
|
+
inputs: [{ type: "address" }, { type: "uint256" }],
|
|
2534
|
+
outputs: [
|
|
2535
|
+
{ name: "amount", type: "uint128" },
|
|
2536
|
+
{ name: "basis", type: "uint128" },
|
|
2537
|
+
{ name: "shouldRedeposit", type: "bool" }
|
|
2538
|
+
]
|
|
2539
|
+
}
|
|
2540
|
+
];
|
|
2541
|
+
var PANOPTIC_POOL_READ_ABI = [
|
|
2542
|
+
{
|
|
2543
|
+
type: "function",
|
|
2544
|
+
name: "positionsHash",
|
|
2545
|
+
stateMutability: "view",
|
|
2546
|
+
inputs: [{ type: "address" }],
|
|
2547
|
+
outputs: [{ type: "bytes32" }]
|
|
2548
|
+
}
|
|
2549
|
+
];
|
|
2550
|
+
function readContractFunction(client, method) {
|
|
2551
|
+
if (!isRecord4(client) || typeof client.readContract !== "function") {
|
|
2552
|
+
throw new Error(`Panoptic ${method} requires a viem public client with readContract.`);
|
|
2553
|
+
}
|
|
2554
|
+
return client.readContract;
|
|
2555
|
+
}
|
|
2556
|
+
async function getBlockIfAvailable(client, blockNumber) {
|
|
2557
|
+
if (!isRecord4(client) || typeof client.getBlock !== "function") {
|
|
2558
|
+
return void 0;
|
|
2559
|
+
}
|
|
2560
|
+
const block = await client.getBlock({
|
|
2561
|
+
blockNumber: BigInt(blockNumber)
|
|
2562
|
+
});
|
|
2563
|
+
if (!isRecord4(block) || block.timestamp === void 0) {
|
|
2564
|
+
return void 0;
|
|
2565
|
+
}
|
|
2566
|
+
return { timestamp: toBigInt(block.timestamp, "block.timestamp") };
|
|
2567
|
+
}
|
|
2568
|
+
function depositEpochState(value, method) {
|
|
2569
|
+
return {
|
|
2570
|
+
assetsDeposited: tupleBigInt(value, "assetsDeposited", 0, `${method} depositEpochState`).toString(10),
|
|
2571
|
+
assetsFulfilled: tupleBigInt(value, "assetsFulfilled", 1, `${method} depositEpochState`).toString(10),
|
|
2572
|
+
sharesReceived: tupleBigInt(value, "sharesReceived", 2, `${method} depositEpochState`).toString(10)
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
function withdrawalEpochState(value, method) {
|
|
2576
|
+
return {
|
|
2577
|
+
sharesWithdrawn: tupleBigInt(value, "sharesWithdrawn", 0, `${method} withdrawalEpochState`).toString(10),
|
|
2578
|
+
sharesFulfilled: tupleBigInt(value, "sharesFulfilled", 1, `${method} withdrawalEpochState`).toString(10),
|
|
2579
|
+
assetsPaid: tupleBigInt(value, "assetsPaid", 2, `${method} withdrawalEpochState`).toString(10)
|
|
2580
|
+
};
|
|
2581
|
+
}
|
|
2582
|
+
function queuedWithdrawalState(value, method) {
|
|
2583
|
+
return {
|
|
2584
|
+
amount: tupleBigInt(value, "amount", 0, `${method} queuedWithdrawal`).toString(10),
|
|
2585
|
+
basis: tupleBigInt(value, "basis", 1, `${method} queuedWithdrawal`).toString(10),
|
|
2586
|
+
shouldRedeposit: tupleBoolean(value, "shouldRedeposit", 2, `${method} queuedWithdrawal`)
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
function tupleBigInt(value, field, index, label) {
|
|
2590
|
+
if (Array.isArray(value)) {
|
|
2591
|
+
return toBigInt(value[index], `${label}[${index}]`);
|
|
2592
|
+
}
|
|
2593
|
+
if (isRecord4(value)) {
|
|
2594
|
+
return toBigInt(value[field], `${label}.${field}`);
|
|
2595
|
+
}
|
|
2596
|
+
throw new Error(`Panoptic ${label} must be a tuple-like value.`);
|
|
2597
|
+
}
|
|
2598
|
+
function tupleBoolean(value, field, index, label) {
|
|
2599
|
+
const raw = Array.isArray(value) ? value[index] : isRecord4(value) ? value[field] : void 0;
|
|
2600
|
+
if (typeof raw !== "boolean") {
|
|
2601
|
+
throw new Error(`Panoptic ${label}.${field} must be a boolean.`);
|
|
2602
|
+
}
|
|
2603
|
+
return raw;
|
|
2604
|
+
}
|
|
2605
|
+
function toBigInt(value, label) {
|
|
2606
|
+
if (typeof value === "bigint") return value;
|
|
2607
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return BigInt(value);
|
|
2608
|
+
if (typeof value === "string" && /^(0|[1-9][0-9]*)$/.test(value)) return BigInt(value);
|
|
2609
|
+
throw new Error(`Panoptic ${label} must be a uint-like value.`);
|
|
2610
|
+
}
|
|
2611
|
+
function nonnegativeDifference(left, right) {
|
|
2612
|
+
const difference = BigInt(left) - BigInt(right);
|
|
2613
|
+
return difference < BigInt(0) ? BigInt(0) : difference;
|
|
2614
|
+
}
|
|
2615
|
+
async function recoverTokenIds(deps, sourceContext, input, method) {
|
|
2616
|
+
if (!input.lastDispatchTxHash) return void 0;
|
|
2617
|
+
const sdkGetOpenPositionIds = requireSdkFunction(await deps.sdkV2(), "getOpenPositionIds", "@panoptic-eng/sdk/v2");
|
|
2618
|
+
const tokenIds = await sdkGetOpenPositionIds({
|
|
2619
|
+
client: sourceContext.client,
|
|
2620
|
+
chainId: BigInt(sourceContext.source.chainId),
|
|
2621
|
+
poolAddress: input.poolAddress,
|
|
2622
|
+
account: input.account,
|
|
2623
|
+
lastDispatchTxHash: input.lastDispatchTxHash
|
|
2624
|
+
});
|
|
2625
|
+
if (!Array.isArray(tokenIds)) {
|
|
2626
|
+
throw new Error(`Panoptic ${method} getOpenPositionIds result must be an array.`);
|
|
2627
|
+
}
|
|
2628
|
+
return tokenIds.map((tokenId, index) => toBigInt(tokenId, `${method} tokenIds[${index}]`).toString(10));
|
|
2629
|
+
}
|
|
2630
|
+
async function computePositionsHash(viem, tokenIds, method) {
|
|
2631
|
+
const keccak256 = requireSdkFunction(viem, "keccak256", "viem");
|
|
2632
|
+
let hash = BigInt(0);
|
|
2633
|
+
for (const [index, tokenId] of tokenIds.entries()) {
|
|
2634
|
+
const encodedTokenId = `0x${BigInt(tokenId).toString(16).padStart(64, "0")}`;
|
|
2635
|
+
const tokenHash = normalizePanopticHex(await keccak256(encodedTokenId), `${method} tokenIds[${index}] hash`);
|
|
2636
|
+
hash ^= BigInt(tokenHash);
|
|
2637
|
+
}
|
|
2638
|
+
return `0x${hash.toString(16).padStart(64, "0")}`;
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
// src/internal/panoptic/reads/pool.ts
|
|
2642
|
+
async function getPool({
|
|
2643
|
+
deps,
|
|
2644
|
+
method,
|
|
2645
|
+
request,
|
|
2646
|
+
options
|
|
2647
|
+
}) {
|
|
2648
|
+
const input = parseGetPoolRequest(request, method);
|
|
2649
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2650
|
+
const sdkGetPool = await loadSdkFunction2(deps, "getPool");
|
|
2651
|
+
const rawResult = await sdkGetPool({
|
|
2652
|
+
client: sourceContext.client,
|
|
2653
|
+
chainId: BigInt(sourceContext.source.chainId),
|
|
2654
|
+
blockNumber: BigInt(sourceContext.blockNumber),
|
|
2655
|
+
poolAddress: input.poolAddress,
|
|
2656
|
+
poolMetadata: input.poolMetadata,
|
|
2657
|
+
stateViewAddress: input.stateViewAddress
|
|
2658
|
+
});
|
|
2659
|
+
return withSource(rawResult, sourceContext, "pinned", "pool.getPool result");
|
|
2660
|
+
}
|
|
2661
|
+
async function fetchPoolId({
|
|
2662
|
+
deps,
|
|
2663
|
+
method,
|
|
2664
|
+
request,
|
|
2665
|
+
options
|
|
2666
|
+
}) {
|
|
2667
|
+
const input = parsePoolAddressRequest(["poolAddress"])(request, method);
|
|
2668
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2669
|
+
const sdkFetchPoolId = await loadSdkFunction2(deps, "fetchPoolId");
|
|
2670
|
+
const rawResult = await sdkFetchPoolId({ client: sourceContext.client, poolAddress: input.poolAddress });
|
|
2671
|
+
const sdkBlockNumber = readSdkResultBlockNumber(rawResult);
|
|
2672
|
+
return withSource(
|
|
2673
|
+
rawResult,
|
|
2674
|
+
sourceContext,
|
|
2675
|
+
sdkBlockNumber ? "sdkResult" : "preflight",
|
|
2676
|
+
"pool.fetchPoolId result",
|
|
2677
|
+
sdkBlockNumber || void 0,
|
|
2678
|
+
sdkBlockNumber ? void 0 : false
|
|
2679
|
+
);
|
|
2680
|
+
}
|
|
2681
|
+
async function getPoolMetadata({
|
|
2682
|
+
deps,
|
|
2683
|
+
method,
|
|
2684
|
+
request,
|
|
2685
|
+
options
|
|
2686
|
+
}) {
|
|
2687
|
+
const input = parsePoolAddressRequest(["poolAddress"])(request, method);
|
|
2688
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2689
|
+
const sdkGetPoolMetadata = await loadSdkFunction2(deps, "getPoolMetadata");
|
|
2690
|
+
return withSource(
|
|
2691
|
+
await sdkGetPoolMetadata({ client: sourceContext.client, poolAddress: input.poolAddress }),
|
|
2692
|
+
sourceContext,
|
|
2693
|
+
"staticReference",
|
|
2694
|
+
"pool.getPoolMetadata result"
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
async function getRiskParameters({
|
|
2698
|
+
deps,
|
|
2699
|
+
method,
|
|
2700
|
+
request,
|
|
2701
|
+
options
|
|
2702
|
+
}) {
|
|
2703
|
+
const input = parseRiskParametersRequest(request, method);
|
|
2704
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2705
|
+
const sdkGetRiskParameters = await loadSdkFunction2(deps, "getRiskParameters");
|
|
2706
|
+
return withSource(
|
|
2707
|
+
await sdkGetRiskParameters({
|
|
2708
|
+
client: sourceContext.client,
|
|
2709
|
+
blockNumber: BigInt(sourceContext.blockNumber),
|
|
2710
|
+
poolAddress: input.poolAddress,
|
|
2711
|
+
builderCode: input.builderCode,
|
|
2712
|
+
riskEngineAddress: input.riskEngineAddress
|
|
2713
|
+
}),
|
|
2714
|
+
sourceContext,
|
|
2715
|
+
"pinned",
|
|
2716
|
+
"pool.getRiskParameters result"
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2719
|
+
async function getUtilization({
|
|
2720
|
+
deps,
|
|
2721
|
+
method,
|
|
2722
|
+
request,
|
|
2723
|
+
options
|
|
2724
|
+
}) {
|
|
2725
|
+
const input = parseUtilizationRequest(request, method);
|
|
2726
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2727
|
+
const sdkGetUtilization = await loadSdkFunction2(deps, "getUtilization");
|
|
2728
|
+
return withSource(
|
|
2729
|
+
await sdkGetUtilization({
|
|
2730
|
+
client: sourceContext.client,
|
|
2731
|
+
blockNumber: BigInt(sourceContext.blockNumber),
|
|
2732
|
+
poolAddress: input.poolAddress,
|
|
2733
|
+
collateralAddresses: input.collateralAddresses
|
|
2734
|
+
}),
|
|
2735
|
+
sourceContext,
|
|
2736
|
+
"pinned",
|
|
2737
|
+
"pool.getUtilization result"
|
|
2738
|
+
);
|
|
2739
|
+
}
|
|
2740
|
+
async function getOracleState({
|
|
2741
|
+
deps,
|
|
2742
|
+
method,
|
|
2743
|
+
request,
|
|
2744
|
+
options
|
|
2745
|
+
}) {
|
|
2746
|
+
const input = parsePoolAddressRequest(["poolAddress"])(request, method);
|
|
2747
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2748
|
+
const sdkGetOracleState = await loadSdkFunction2(deps, "getOracleState");
|
|
2749
|
+
return withSource(
|
|
2750
|
+
await sdkGetOracleState({
|
|
2751
|
+
client: sourceContext.client,
|
|
2752
|
+
blockNumber: BigInt(sourceContext.blockNumber),
|
|
2753
|
+
poolAddress: input.poolAddress
|
|
2754
|
+
}),
|
|
2755
|
+
sourceContext,
|
|
2756
|
+
"pinned",
|
|
2757
|
+
"pool.getOracleState result"
|
|
2758
|
+
);
|
|
2759
|
+
}
|
|
2760
|
+
async function getTickSpacing({ deps, method, request }) {
|
|
2761
|
+
const input = parseGetTickSpacingRequest(request, method);
|
|
2762
|
+
const sdkGetTickSpacing = await loadSdkFunction2(deps, "getTickSpacing");
|
|
2763
|
+
return sdkGetTickSpacing(input.feeBps);
|
|
2764
|
+
}
|
|
2765
|
+
async function getPricesAtTick({ deps, method, request }) {
|
|
2766
|
+
const input = parsePricesAtTickRequest(request, method);
|
|
2767
|
+
const sdkGetPricesAtTick = await loadSdkFunction2(deps, "getPricesAtTick");
|
|
2768
|
+
return sdkGetPricesAtTick(input.tick, input.decimals0, input.decimals1, input.precision);
|
|
2769
|
+
}
|
|
2770
|
+
function parseGetTickSpacingRequest(request, method) {
|
|
2771
|
+
rejectContext(request, method);
|
|
2772
|
+
const args = requestArgs(request, method);
|
|
2773
|
+
rejectExtraKeys(args, ["feeBps"], method);
|
|
2774
|
+
return { feeBps: uint256Arg(args, "feeBps") };
|
|
2775
|
+
}
|
|
2776
|
+
function parseGetPoolRequest(request, method) {
|
|
2777
|
+
requireSourceContext(request, method);
|
|
2778
|
+
const args = requestArgs(request, method);
|
|
2779
|
+
rejectExtraKeys(args, ["poolAddress", "poolMetadata", "stateViewAddress"], method);
|
|
2780
|
+
return {
|
|
2781
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2782
|
+
...args.poolMetadata === void 0 ? {} : { poolMetadata: poolMetadataValue(args.poolMetadata, `${method} args.poolMetadata`) },
|
|
2783
|
+
...args.stateViewAddress === void 0 ? {} : { stateViewAddress: normalizePanopticAddress(args.stateViewAddress, `${method} args.stateViewAddress`) }
|
|
2784
|
+
};
|
|
2785
|
+
}
|
|
2786
|
+
function parsePoolAddressRequest(allowedKeys) {
|
|
2787
|
+
return (request, method) => {
|
|
2788
|
+
requireSourceContext(request, method);
|
|
2789
|
+
rejectLatestOnlyBlockNumber3(request, method);
|
|
2790
|
+
const args = requestArgs(request, method);
|
|
2791
|
+
rejectExtraKeys(args, allowedKeys, method);
|
|
2792
|
+
return { poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`) };
|
|
2793
|
+
};
|
|
2794
|
+
}
|
|
2795
|
+
function parseRiskParametersRequest(request, method) {
|
|
2796
|
+
requireSourceContext(request, method);
|
|
2797
|
+
const args = requestArgs(request, method);
|
|
2798
|
+
rejectExtraKeys(args, ["poolAddress", "builderCode", "riskEngineAddress"], method);
|
|
2799
|
+
return {
|
|
2800
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2801
|
+
builderCode: optionalUint256Arg(args, "builderCode"),
|
|
2802
|
+
...args.riskEngineAddress === void 0 ? {} : { riskEngineAddress: normalizePanopticAddress(args.riskEngineAddress, `${method} args.riskEngineAddress`) }
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2805
|
+
function parseUtilizationRequest(request, method) {
|
|
2806
|
+
requireSourceContext(request, method);
|
|
2807
|
+
const args = requestArgs(request, method);
|
|
2808
|
+
rejectExtraKeys(args, ["poolAddress", "collateralAddresses"], method);
|
|
2809
|
+
return {
|
|
2810
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2811
|
+
...args.collateralAddresses === void 0 ? {} : {
|
|
2812
|
+
collateralAddresses: collateralAddressesValue(args.collateralAddresses, `${method} args.collateralAddresses`)
|
|
2813
|
+
}
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2816
|
+
function parsePricesAtTickRequest(request, method) {
|
|
2817
|
+
rejectContext(request, method);
|
|
2818
|
+
const args = requestArgs(request, method);
|
|
2819
|
+
rejectExtraKeys(args, ["tick", "decimals0", "decimals1", "precision"], method);
|
|
2820
|
+
return {
|
|
2821
|
+
tick: signedDecimalValue(args.tick, `${method} args.tick`),
|
|
2822
|
+
decimals0: uint256Arg(args, "decimals0"),
|
|
2823
|
+
decimals1: uint256Arg(args, "decimals1"),
|
|
2824
|
+
precision: uint256Arg(args, "precision")
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
async function loadSdkFunction2(deps, name) {
|
|
2828
|
+
return requireSdkFunction(await deps.sdkV2(), name, "@panoptic-eng/sdk/v2");
|
|
2829
|
+
}
|
|
2830
|
+
function rejectLatestOnlyBlockNumber3(request, method) {
|
|
2831
|
+
if (method === "pool.fetchPoolId" && request.context?.blockNumber !== void 0) {
|
|
2832
|
+
throw new Error(`Panoptic ${method} does not accept context.blockNumber because its block policy is latestOnly.`);
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
function readSdkResultBlockNumber(value) {
|
|
2836
|
+
if (!isRecord4(value) || !isRecord4(value._meta)) {
|
|
2837
|
+
return null;
|
|
2838
|
+
}
|
|
2839
|
+
return normalizeBlockNumberValue(value._meta.blockNumber);
|
|
2840
|
+
}
|
|
2841
|
+
function normalizeBlockNumberValue(value) {
|
|
2842
|
+
if (typeof value === "bigint") {
|
|
2843
|
+
return value.toString(10);
|
|
2844
|
+
}
|
|
2845
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) {
|
|
2846
|
+
return value.toString(10);
|
|
2847
|
+
}
|
|
2848
|
+
if (typeof value === "string") {
|
|
2849
|
+
if (/^0x[0-9a-f]+$/i.test(value)) {
|
|
2850
|
+
return BigInt(value).toString(10);
|
|
2851
|
+
}
|
|
2852
|
+
if (/^(0|[1-9][0-9]*)$/.test(value)) {
|
|
2853
|
+
return BigInt(value).toString(10);
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
return null;
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
// src/internal/panoptic/reads/uniswap.ts
|
|
2860
|
+
async function resolveSwapRoute({
|
|
2861
|
+
deps,
|
|
2862
|
+
method,
|
|
2863
|
+
request,
|
|
2864
|
+
options
|
|
2865
|
+
}) {
|
|
2866
|
+
const input = parseResolveSwapRouteRequest(request, method);
|
|
2867
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2868
|
+
const sdkResolveSwapRoute = await loadUniswapFunction(deps, "resolveSwapRoute");
|
|
2869
|
+
return withSource(
|
|
2870
|
+
await sdkResolveSwapRoute({
|
|
2871
|
+
...pinnedParams(sourceContext),
|
|
2872
|
+
poolAddress: input.poolAddress,
|
|
2873
|
+
tokenIn: input.tokenIn
|
|
2874
|
+
}),
|
|
2875
|
+
sourceContext,
|
|
2876
|
+
"pinned",
|
|
2877
|
+
`${method} result`
|
|
2878
|
+
);
|
|
2879
|
+
}
|
|
2880
|
+
async function quoteSwapExactInViaRouter({
|
|
2881
|
+
deps,
|
|
2882
|
+
method,
|
|
2883
|
+
request,
|
|
2884
|
+
options
|
|
2885
|
+
}) {
|
|
2886
|
+
const input = parseQuoteSwapExactInRequest(request, method);
|
|
2887
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2888
|
+
const sdkQuoteSwapExactInViaRouter = await loadUniswapFunction(deps, "quoteSwapExactInViaRouter");
|
|
2889
|
+
return withSource(
|
|
2890
|
+
await sdkQuoteSwapExactInViaRouter({
|
|
2891
|
+
...pinnedParams(sourceContext),
|
|
2892
|
+
poolAddress: input.poolAddress,
|
|
2893
|
+
tokenIn: input.tokenIn,
|
|
2894
|
+
amountIn: input.amountIn,
|
|
2895
|
+
slippageBps: input.slippageBps,
|
|
2896
|
+
addresses: input.addresses
|
|
2897
|
+
}),
|
|
2898
|
+
sourceContext,
|
|
2899
|
+
"pinned",
|
|
2900
|
+
`${method} result`
|
|
2901
|
+
);
|
|
2902
|
+
}
|
|
2903
|
+
async function quoteSwapExactOutViaRouter({
|
|
2904
|
+
deps,
|
|
2905
|
+
method,
|
|
2906
|
+
request,
|
|
2907
|
+
options
|
|
2908
|
+
}) {
|
|
2909
|
+
const input = parseQuoteSwapExactOutRequest(request, method);
|
|
2910
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2911
|
+
const sdkQuoteSwapExactOutViaRouter = await loadUniswapFunction(deps, "quoteSwapExactOutViaRouter");
|
|
2912
|
+
return withSource(
|
|
2913
|
+
await sdkQuoteSwapExactOutViaRouter({
|
|
2914
|
+
...pinnedParams(sourceContext),
|
|
2915
|
+
poolAddress: input.poolAddress,
|
|
2916
|
+
tokenIn: input.tokenIn,
|
|
2917
|
+
amountOut: input.amountOut,
|
|
2918
|
+
slippageBps: input.slippageBps,
|
|
2919
|
+
addresses: input.addresses
|
|
2920
|
+
}),
|
|
2921
|
+
sourceContext,
|
|
2922
|
+
"pinned",
|
|
2923
|
+
`${method} result`
|
|
2924
|
+
);
|
|
2925
|
+
}
|
|
2926
|
+
async function checkRouterApproval({
|
|
2927
|
+
deps,
|
|
2928
|
+
method,
|
|
2929
|
+
request,
|
|
2930
|
+
options
|
|
2931
|
+
}) {
|
|
2932
|
+
const input = parseCheckApprovalRequest(request, method);
|
|
2933
|
+
const sourceContext = await prepareRuntimeSourceContext(deps, request, options);
|
|
2934
|
+
const sdkCheckRouterApproval = await loadUniswapFunction(deps, "checkRouterApproval");
|
|
2935
|
+
return withSource(
|
|
2936
|
+
await sdkCheckRouterApproval({
|
|
2937
|
+
client: sourceContext.client,
|
|
2938
|
+
chainId: BigInt(sourceContext.source.chainId),
|
|
2939
|
+
tokenIn: input.tokenIn,
|
|
2940
|
+
owner: input.owner,
|
|
2941
|
+
amount: input.amount,
|
|
2942
|
+
addresses: input.addresses
|
|
2943
|
+
}),
|
|
2944
|
+
sourceContext,
|
|
2945
|
+
"preflight",
|
|
2946
|
+
`${method} result`,
|
|
2947
|
+
void 0,
|
|
2948
|
+
false
|
|
2949
|
+
);
|
|
2950
|
+
}
|
|
2951
|
+
function parseResolveSwapRouteRequest(request, method) {
|
|
2952
|
+
const args = readArgs(request, method, ["poolAddress", "tokenIn"]);
|
|
2953
|
+
return {
|
|
2954
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2955
|
+
tokenIn: normalizePanopticAddress(args.tokenIn, `${method} args.tokenIn`)
|
|
2956
|
+
};
|
|
2957
|
+
}
|
|
2958
|
+
function parseQuoteSwapExactInRequest(request, method) {
|
|
2959
|
+
const args = readArgs(request, method, ["poolAddress", "tokenIn", "amountIn", "slippageBps", "addresses"]);
|
|
2960
|
+
return {
|
|
2961
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2962
|
+
tokenIn: normalizePanopticAddress(args.tokenIn, `${method} args.tokenIn`),
|
|
2963
|
+
amountIn: decimalArg(args, "amountIn"),
|
|
2964
|
+
slippageBps: decimalArg(args, "slippageBps"),
|
|
2965
|
+
...args.addresses === void 0 ? {} : { addresses: uniswapAddressesValue(args.addresses, `${method} args.addresses`) }
|
|
2966
|
+
};
|
|
2967
|
+
}
|
|
2968
|
+
function parseQuoteSwapExactOutRequest(request, method) {
|
|
2969
|
+
const args = readArgs(request, method, ["poolAddress", "tokenIn", "amountOut", "slippageBps", "addresses"]);
|
|
2970
|
+
return {
|
|
2971
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
2972
|
+
tokenIn: normalizePanopticAddress(args.tokenIn, `${method} args.tokenIn`),
|
|
2973
|
+
amountOut: decimalArg(args, "amountOut"),
|
|
2974
|
+
slippageBps: decimalArg(args, "slippageBps"),
|
|
2975
|
+
...args.addresses === void 0 ? {} : { addresses: uniswapAddressesValue(args.addresses, `${method} args.addresses`) }
|
|
2976
|
+
};
|
|
2977
|
+
}
|
|
2978
|
+
function parseCheckApprovalRequest(request, method) {
|
|
2979
|
+
requireSourceContext(request, method);
|
|
2980
|
+
rejectLatestOnlyBlockNumber4(request, method);
|
|
2981
|
+
const args = requestArgs(request, method);
|
|
2982
|
+
rejectExtraKeys(args, ["tokenIn", "owner", "amount", "addresses"], method);
|
|
2983
|
+
return {
|
|
2984
|
+
tokenIn: normalizePanopticAddress(args.tokenIn, `${method} args.tokenIn`),
|
|
2985
|
+
owner: normalizePanopticAddress(args.owner, `${method} args.owner`),
|
|
2986
|
+
amount: decimalArg(args, "amount"),
|
|
2987
|
+
...args.addresses === void 0 ? {} : { addresses: uniswapAddressesValue(args.addresses, `${method} args.addresses`) }
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
function readArgs(request, method, allowedKeys) {
|
|
2991
|
+
requireSourceContext(request, method);
|
|
2992
|
+
const args = requestArgs(request, method);
|
|
2993
|
+
rejectExtraKeys(args, allowedKeys, method);
|
|
2994
|
+
return args;
|
|
2995
|
+
}
|
|
2996
|
+
function pinnedParams(sourceContext) {
|
|
2997
|
+
return {
|
|
2998
|
+
client: sourceContext.client,
|
|
2999
|
+
chainId: BigInt(sourceContext.source.chainId),
|
|
3000
|
+
blockNumber: BigInt(sourceContext.blockNumber)
|
|
3001
|
+
};
|
|
3002
|
+
}
|
|
3003
|
+
function rejectLatestOnlyBlockNumber4(request, method) {
|
|
3004
|
+
if (request.context?.blockNumber !== void 0) {
|
|
3005
|
+
throw new Error(`Panoptic ${method} does not accept context.blockNumber because its block policy is latestOnly.`);
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
async function loadUniswapFunction(deps, name) {
|
|
3009
|
+
return requireSdkFunction(await deps.uniswap(), name, "@panoptic-eng/sdk/uniswap");
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
// src/internal/panoptic/dynamicJobs/fragments.ts
|
|
3013
|
+
function makeDynamicJobFragment(input) {
|
|
3014
|
+
return validateDynamicJobFragment(input, "fragment");
|
|
3015
|
+
}
|
|
3016
|
+
function validateDynamicJobFragment(value, label) {
|
|
3017
|
+
if (!isRecord5(value)) {
|
|
3018
|
+
throw new Error(`Panoptic ${label} must be an object.`);
|
|
3019
|
+
}
|
|
3020
|
+
rejectExtraKeys2(value, ["target", "userProvidedData", "strategyProvidedData", "value"], label);
|
|
3021
|
+
const fragment = {
|
|
3022
|
+
target: normalizePanopticAddress(value.target, `${label}.target`),
|
|
3023
|
+
userProvidedData: normalizePanopticHex(value.userProvidedData, `${label}.userProvidedData`),
|
|
3024
|
+
strategyProvidedData: normalizePanopticHex(value.strategyProvidedData, `${label}.strategyProvidedData`),
|
|
3025
|
+
value: normalizePanopticDecimalString(value.value, `${label}.value`)
|
|
3026
|
+
};
|
|
3027
|
+
if (fragment.userProvidedData.length < 10 || (fragment.userProvidedData.length - 10) % 64 !== 0) {
|
|
3028
|
+
throw new Error(`Panoptic ${label}.userProvidedData must be a 4-byte selector followed by zero or more ABI words.`);
|
|
3029
|
+
}
|
|
3030
|
+
if (fragment.value !== "0") {
|
|
3031
|
+
throw new Error(`Panoptic ${label}.value must be 0 because DynamicJobs.executeJob does not forward native value.`);
|
|
3032
|
+
}
|
|
3033
|
+
return fragment;
|
|
3034
|
+
}
|
|
3035
|
+
function isRecord5(value) {
|
|
3036
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3037
|
+
}
|
|
3038
|
+
function rejectExtraKeys2(value, allowedKeys, label) {
|
|
3039
|
+
const allowed = new Set(allowedKeys);
|
|
3040
|
+
for (const key of Object.keys(value)) {
|
|
3041
|
+
if (!allowed.has(key)) {
|
|
3042
|
+
throw new Error(`Panoptic ${label}.${key} is not supported by DynamicJobFragment.`);
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
// src/internal/panoptic/fragments/support.ts
|
|
3048
|
+
function splitCalldata(value, method, options = {}) {
|
|
3049
|
+
const record = isRecord6(value) ? value : void 0;
|
|
3050
|
+
const rawCalldata = record ? record.data : value;
|
|
3051
|
+
const calldata = normalizePanopticHex(rawCalldata, `${method} calldata`).toLowerCase();
|
|
3052
|
+
const target = record?.to === void 0 ? void 0 : normalizePanopticAddress(record.to, `${method} SDK target`);
|
|
3053
|
+
const staticArgWords = options.staticArgWords || 0;
|
|
3054
|
+
const prefixLength = 10 + staticArgWords * 64;
|
|
3055
|
+
if (calldata.length < 10) {
|
|
3056
|
+
throw new Error(`Panoptic ${method} calldata must include a selector.`);
|
|
3057
|
+
}
|
|
3058
|
+
const selector = calldata.slice(0, 10);
|
|
3059
|
+
const expectedSelector = options.expectedSelector?.toLowerCase();
|
|
3060
|
+
if (expectedSelector && selector !== expectedSelector) {
|
|
3061
|
+
throw new Error(
|
|
3062
|
+
`Panoptic ${method} calldata selector ${selector} does not match expected selector ${expectedSelector}.`
|
|
3063
|
+
);
|
|
3064
|
+
}
|
|
3065
|
+
if (calldata.length < prefixLength) {
|
|
3066
|
+
throw new Error(`Panoptic ${method} calldata must include ${staticArgWords} static argument word(s).`);
|
|
3067
|
+
}
|
|
3068
|
+
const userProvidedData = calldata.slice(0, prefixLength);
|
|
3069
|
+
const strategyProvidedData = `0x${calldata.slice(prefixLength)}`;
|
|
3070
|
+
if (options.requireStrategyData !== false && strategyProvidedData === "0x") {
|
|
3071
|
+
throw new Error(`Panoptic ${method} calldata must include ABI-encoded arguments.`);
|
|
3072
|
+
}
|
|
3073
|
+
return target ? { calldata, userProvidedData, strategyProvidedData, target } : { calldata, userProvidedData, strategyProvidedData };
|
|
3074
|
+
}
|
|
3075
|
+
function assertUserProvidedData(value, expected, method) {
|
|
3076
|
+
if (value.toLowerCase() !== expected.toLowerCase()) {
|
|
3077
|
+
throw new Error(`Panoptic ${method} generated calldata does not match the requested static argument prefix.`);
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
function addressAbiWord(address) {
|
|
3081
|
+
return address.slice(2).toLowerCase().padStart(64, "0");
|
|
3082
|
+
}
|
|
3083
|
+
function uint256AbiWord(value) {
|
|
3084
|
+
if (value < BigInt(0) || value >= BigInt(1) << BigInt(256)) {
|
|
3085
|
+
throw new Error("Panoptic ABI uint256 value exceeds range.");
|
|
3086
|
+
}
|
|
3087
|
+
return value.toString(16).padStart(64, "0");
|
|
3088
|
+
}
|
|
3089
|
+
function isRecord6(value) {
|
|
3090
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
// src/internal/panoptic/fragments/erc20.ts
|
|
3094
|
+
var ERC20_APPROVE_SELECTOR = "0x095ea7b3";
|
|
3095
|
+
async function approveFragment({ deps, method, request, options }) {
|
|
3096
|
+
void options;
|
|
3097
|
+
const input = parseApproveRequest(request, method);
|
|
3098
|
+
const encodeApproveFunctionData = requireSdkFunction(
|
|
3099
|
+
await deps.sdk(),
|
|
3100
|
+
"encodeApproveFunctionData",
|
|
3101
|
+
"@panoptic-eng/sdk"
|
|
3102
|
+
);
|
|
3103
|
+
const calldata = await encodeApproveFunctionData({
|
|
3104
|
+
spender: input.spender,
|
|
3105
|
+
amount: input.amount
|
|
3106
|
+
});
|
|
3107
|
+
const split = splitCalldata(calldata, method, {
|
|
3108
|
+
expectedSelector: ERC20_APPROVE_SELECTOR,
|
|
3109
|
+
staticArgWords: 1
|
|
3110
|
+
});
|
|
3111
|
+
assertUserProvidedData(split.userProvidedData, `${ERC20_APPROVE_SELECTOR}${addressAbiWord(input.spender)}`, method);
|
|
3112
|
+
return makeDynamicJobFragment({
|
|
3113
|
+
target: input.token,
|
|
3114
|
+
userProvidedData: split.userProvidedData,
|
|
3115
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3116
|
+
value: "0"
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
function parseApproveRequest(request, method) {
|
|
3120
|
+
rejectContext(request, method);
|
|
3121
|
+
const args = requestArgs(request, method);
|
|
3122
|
+
rejectExtraKeys(args, ["token", "spender", "amount"], method);
|
|
3123
|
+
return {
|
|
3124
|
+
token: normalizePanopticAddress(args.token, `${method} args.token`),
|
|
3125
|
+
spender: normalizePanopticAddress(args.spender, `${method} args.spender`),
|
|
3126
|
+
amount: uint256Arg(args, "amount")
|
|
3127
|
+
};
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
// src/internal/panoptic/fragments/collateral.ts
|
|
3131
|
+
var DEPOSIT_SELECTOR = "0x6e553f65";
|
|
3132
|
+
var WITHDRAW_SELECTOR = "0xb460af94";
|
|
3133
|
+
var WITHDRAW_WITH_POSITIONS_SELECTOR = "0xe51161ba";
|
|
3134
|
+
var WITHDRAW_WITH_POSITIONS_ABI = [
|
|
3135
|
+
{
|
|
3136
|
+
type: "function",
|
|
3137
|
+
name: "withdraw",
|
|
3138
|
+
stateMutability: "nonpayable",
|
|
3139
|
+
inputs: [
|
|
3140
|
+
{ name: "assets", type: "uint256" },
|
|
3141
|
+
{ name: "receiver", type: "address" },
|
|
3142
|
+
{ name: "owner", type: "address" },
|
|
3143
|
+
{ name: "positionIdList", type: "uint256[]" },
|
|
3144
|
+
{ name: "usePremiaAsCollateral", type: "bool" }
|
|
3145
|
+
],
|
|
3146
|
+
outputs: [{ name: "shares", type: "uint256" }]
|
|
3147
|
+
}
|
|
3148
|
+
];
|
|
3149
|
+
async function depositFragment({ deps, method, request, options }) {
|
|
3150
|
+
void options;
|
|
3151
|
+
const input = parseDepositRequest(request, method);
|
|
3152
|
+
const encodeDepositFunctionData = requireSdkFunction(
|
|
3153
|
+
await deps.sdk(),
|
|
3154
|
+
"encodeDepositFunctionData",
|
|
3155
|
+
"@panoptic-eng/sdk"
|
|
3156
|
+
);
|
|
3157
|
+
const split = splitCalldata(
|
|
3158
|
+
await encodeDepositFunctionData({
|
|
3159
|
+
assets: input.assets,
|
|
3160
|
+
receiver: input.receiver
|
|
3161
|
+
}),
|
|
3162
|
+
method,
|
|
3163
|
+
{ expectedSelector: DEPOSIT_SELECTOR }
|
|
3164
|
+
);
|
|
3165
|
+
return makeDynamicJobFragment({
|
|
3166
|
+
target: input.collateralTracker,
|
|
3167
|
+
userProvidedData: split.userProvidedData,
|
|
3168
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3169
|
+
value: "0"
|
|
3170
|
+
});
|
|
3171
|
+
}
|
|
3172
|
+
async function withdrawFragment({ deps, method, request, options }) {
|
|
3173
|
+
void options;
|
|
3174
|
+
const input = parseWithdrawRequest(request, method);
|
|
3175
|
+
const encodeWithdrawFunctionData = requireSdkFunction(
|
|
3176
|
+
await deps.sdk(),
|
|
3177
|
+
"encodeWithdrawFunctionData",
|
|
3178
|
+
"@panoptic-eng/sdk"
|
|
3179
|
+
);
|
|
3180
|
+
const split = splitCalldata(
|
|
3181
|
+
await encodeWithdrawFunctionData({
|
|
3182
|
+
assets: input.assets,
|
|
3183
|
+
receiver: input.receiver,
|
|
3184
|
+
owner: input.owner
|
|
3185
|
+
}),
|
|
3186
|
+
method,
|
|
3187
|
+
{ expectedSelector: WITHDRAW_SELECTOR }
|
|
3188
|
+
);
|
|
3189
|
+
return makeDynamicJobFragment({
|
|
3190
|
+
target: input.collateralTracker,
|
|
3191
|
+
userProvidedData: split.userProvidedData,
|
|
3192
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3193
|
+
value: "0"
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
3196
|
+
async function withdrawWithPositionsFragment({ deps, method, request, options }) {
|
|
3197
|
+
void options;
|
|
3198
|
+
const input = parseWithdrawWithPositionsRequest(request, method);
|
|
3199
|
+
const encodeFunctionData = requireSdkFunction(await deps.viem(), "encodeFunctionData", "viem");
|
|
3200
|
+
const split = splitCalldata(
|
|
3201
|
+
await encodeFunctionData({
|
|
3202
|
+
abi: WITHDRAW_WITH_POSITIONS_ABI,
|
|
3203
|
+
functionName: "withdraw",
|
|
3204
|
+
args: [input.assets, input.receiver, input.owner, input.positionIdList, input.usePremiaAsCollateral]
|
|
3205
|
+
}),
|
|
3206
|
+
method,
|
|
3207
|
+
{ expectedSelector: WITHDRAW_WITH_POSITIONS_SELECTOR }
|
|
3208
|
+
);
|
|
3209
|
+
return makeDynamicJobFragment({
|
|
3210
|
+
target: input.collateralTracker,
|
|
3211
|
+
userProvidedData: split.userProvidedData,
|
|
3212
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3213
|
+
value: "0"
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
function parseDepositRequest(request, method) {
|
|
3217
|
+
rejectContext(request, method);
|
|
3218
|
+
const args = requestArgs(request, method);
|
|
3219
|
+
rejectExtraKeys(args, ["collateralTracker", "assets", "receiver"], method);
|
|
3220
|
+
return {
|
|
3221
|
+
collateralTracker: normalizePanopticAddress(args.collateralTracker, `${method} args.collateralTracker`),
|
|
3222
|
+
assets: uint256Arg(args, "assets"),
|
|
3223
|
+
receiver: normalizePanopticAddress(args.receiver, `${method} args.receiver`)
|
|
3224
|
+
};
|
|
3225
|
+
}
|
|
3226
|
+
function parseWithdrawRequest(request, method) {
|
|
3227
|
+
rejectContext(request, method);
|
|
3228
|
+
const args = requestArgs(request, method);
|
|
3229
|
+
rejectExtraKeys(args, ["collateralTracker", "assets", "receiver", "owner"], method);
|
|
3230
|
+
return {
|
|
3231
|
+
collateralTracker: normalizePanopticAddress(args.collateralTracker, `${method} args.collateralTracker`),
|
|
3232
|
+
assets: uint256Arg(args, "assets"),
|
|
3233
|
+
receiver: normalizePanopticAddress(args.receiver, `${method} args.receiver`),
|
|
3234
|
+
owner: normalizePanopticAddress(args.owner, `${method} args.owner`)
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
function parseWithdrawWithPositionsRequest(request, method) {
|
|
3238
|
+
const input = parseWithdrawWithPositionBase(request, method);
|
|
3239
|
+
const { args, ...base } = input;
|
|
3240
|
+
return {
|
|
3241
|
+
...base,
|
|
3242
|
+
positionIdList: uint256ArrayArg(args, "positionIdList"),
|
|
3243
|
+
usePremiaAsCollateral: booleanArg(args.usePremiaAsCollateral, `${method} args.usePremiaAsCollateral`)
|
|
3244
|
+
};
|
|
3245
|
+
}
|
|
3246
|
+
function parseWithdrawWithPositionBase(request, method) {
|
|
3247
|
+
rejectContext(request, method);
|
|
3248
|
+
const args = requestArgs(request, method);
|
|
3249
|
+
rejectExtraKeys(
|
|
3250
|
+
args,
|
|
3251
|
+
["collateralTracker", "assets", "receiver", "owner", "positionIdList", "usePremiaAsCollateral"],
|
|
3252
|
+
method
|
|
3253
|
+
);
|
|
3254
|
+
return {
|
|
3255
|
+
args,
|
|
3256
|
+
collateralTracker: normalizePanopticAddress(args.collateralTracker, `${method} args.collateralTracker`),
|
|
3257
|
+
assets: uint256Arg(args, "assets"),
|
|
3258
|
+
receiver: normalizePanopticAddress(args.receiver, `${method} args.receiver`),
|
|
3259
|
+
owner: normalizePanopticAddress(args.owner, `${method} args.owner`)
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
function booleanArg(value, label) {
|
|
3263
|
+
if (typeof value !== "boolean") {
|
|
3264
|
+
throw new Error(`Panoptic ${label} must be a boolean.`);
|
|
3265
|
+
}
|
|
3266
|
+
return value;
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
// src/internal/panoptic/fragments/hypovault.ts
|
|
3270
|
+
var FULFILL_DEPOSITS_SELECTOR = "0x50dcdee9";
|
|
3271
|
+
var FULFILL_WITHDRAWALS_SELECTOR = "0x69838516";
|
|
3272
|
+
var MANAGE_SELECTOR = "0xf6e715d0";
|
|
3273
|
+
var MANAGE_ABI = [
|
|
3274
|
+
{
|
|
3275
|
+
type: "function",
|
|
3276
|
+
name: "manage",
|
|
3277
|
+
stateMutability: "payable",
|
|
3278
|
+
inputs: [
|
|
3279
|
+
{ name: "target", type: "address" },
|
|
3280
|
+
{ name: "data", type: "bytes" },
|
|
3281
|
+
{ name: "value", type: "uint256" }
|
|
3282
|
+
],
|
|
3283
|
+
outputs: []
|
|
3284
|
+
}
|
|
3285
|
+
];
|
|
3286
|
+
async function fulfillDepositsFragment({ deps, method, request, options }) {
|
|
3287
|
+
void options;
|
|
3288
|
+
const input = parseFulfillDepositsRequest(request, method);
|
|
3289
|
+
const encodeFulfillDepositsFunctionData = requireSdkFunction(
|
|
3290
|
+
await deps.sdk(),
|
|
3291
|
+
"encodeFulfillDepositsFunctionData",
|
|
3292
|
+
"@panoptic-eng/sdk"
|
|
3293
|
+
);
|
|
3294
|
+
const split = splitCalldata(
|
|
3295
|
+
await encodeFulfillDepositsFunctionData({
|
|
3296
|
+
assetsToFulfill: input.assetsToFulfill,
|
|
3297
|
+
managerInput: input.managerInput
|
|
3298
|
+
}),
|
|
3299
|
+
method,
|
|
3300
|
+
{ expectedSelector: FULFILL_DEPOSITS_SELECTOR }
|
|
3301
|
+
);
|
|
3302
|
+
return makeDynamicJobFragment({
|
|
3303
|
+
target: input.vaultManager,
|
|
3304
|
+
userProvidedData: split.userProvidedData,
|
|
3305
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3306
|
+
value: "0"
|
|
3307
|
+
});
|
|
3308
|
+
}
|
|
3309
|
+
async function fulfillWithdrawalsFragment({ deps, method, request, options }) {
|
|
3310
|
+
void options;
|
|
3311
|
+
const input = parseFulfillWithdrawalsRequest(request, method);
|
|
3312
|
+
const encodeFulfillWithdrawalsFunctionData = requireSdkFunction(
|
|
3313
|
+
await deps.sdk(),
|
|
3314
|
+
"encodeFulfillWithdrawalsFunctionData",
|
|
3315
|
+
"@panoptic-eng/sdk"
|
|
3316
|
+
);
|
|
3317
|
+
const split = splitCalldata(
|
|
3318
|
+
await encodeFulfillWithdrawalsFunctionData({
|
|
3319
|
+
sharesToFulfill: input.sharesToFulfill,
|
|
3320
|
+
maxAssetsReceived: input.maxAssetsReceived,
|
|
3321
|
+
managerInput: input.managerInput
|
|
3322
|
+
}),
|
|
3323
|
+
method,
|
|
3324
|
+
{ expectedSelector: FULFILL_WITHDRAWALS_SELECTOR }
|
|
3325
|
+
);
|
|
3326
|
+
return makeDynamicJobFragment({
|
|
3327
|
+
target: input.vaultManager,
|
|
3328
|
+
userProvidedData: split.userProvidedData,
|
|
3329
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3330
|
+
value: "0"
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
async function manageCalldataParts({ deps, method, request, options }) {
|
|
3334
|
+
void options;
|
|
3335
|
+
const input = parseManageRequest(request, method, false);
|
|
3336
|
+
const split = splitCalldata(await encodeManageCalldata(deps, input), method, { expectedSelector: MANAGE_SELECTOR });
|
|
3337
|
+
return {
|
|
3338
|
+
functionName: "manage",
|
|
3339
|
+
calldata: split.calldata,
|
|
3340
|
+
userProvidedData: split.userProvidedData,
|
|
3341
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3342
|
+
value: "0"
|
|
3343
|
+
};
|
|
3344
|
+
}
|
|
3345
|
+
async function manageFragment({ deps, method, request, options }) {
|
|
3346
|
+
void options;
|
|
3347
|
+
const input = parseManageRequest(request, method, true);
|
|
3348
|
+
const split = splitCalldata(await encodeManageCalldata(deps, input), method, { expectedSelector: MANAGE_SELECTOR });
|
|
3349
|
+
return makeDynamicJobFragment({
|
|
3350
|
+
target: input.manager,
|
|
3351
|
+
userProvidedData: split.userProvidedData,
|
|
3352
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3353
|
+
value: "0"
|
|
3354
|
+
});
|
|
3355
|
+
}
|
|
3356
|
+
async function encodeManageCalldata(deps, input) {
|
|
3357
|
+
const encodeFunctionData = requireSdkFunction(await deps.viem(), "encodeFunctionData", "viem");
|
|
3358
|
+
return encodeFunctionData({
|
|
3359
|
+
abi: MANAGE_ABI,
|
|
3360
|
+
functionName: "manage",
|
|
3361
|
+
args: [input.innerTarget, input.innerData, input.value]
|
|
3362
|
+
});
|
|
3363
|
+
}
|
|
3364
|
+
function parseFulfillDepositsRequest(request, method) {
|
|
3365
|
+
rejectContext(request, method);
|
|
3366
|
+
const args = requestArgs(request, method);
|
|
3367
|
+
rejectExtraKeys(args, ["vaultManager", "assetsToFulfill", "managerInput"], method);
|
|
3368
|
+
return {
|
|
3369
|
+
vaultManager: normalizePanopticAddress(args.vaultManager, `${method} args.vaultManager`),
|
|
3370
|
+
assetsToFulfill: uint256Arg(args, "assetsToFulfill"),
|
|
3371
|
+
managerInput: normalizePanopticHex(args.managerInput, `${method} args.managerInput`)
|
|
3372
|
+
};
|
|
3373
|
+
}
|
|
3374
|
+
function parseFulfillWithdrawalsRequest(request, method) {
|
|
3375
|
+
rejectContext(request, method);
|
|
3376
|
+
const args = requestArgs(request, method);
|
|
3377
|
+
rejectExtraKeys(args, ["vaultManager", "sharesToFulfill", "maxAssetsReceived", "managerInput"], method);
|
|
3378
|
+
return {
|
|
3379
|
+
vaultManager: normalizePanopticAddress(args.vaultManager, `${method} args.vaultManager`),
|
|
3380
|
+
sharesToFulfill: uint256Arg(args, "sharesToFulfill"),
|
|
3381
|
+
maxAssetsReceived: uint256Arg(args, "maxAssetsReceived"),
|
|
3382
|
+
managerInput: normalizePanopticHex(args.managerInput, `${method} args.managerInput`)
|
|
3383
|
+
};
|
|
3384
|
+
}
|
|
3385
|
+
function parseManageRequest(request, method, requireManager) {
|
|
3386
|
+
rejectContext(request, method);
|
|
3387
|
+
const args = requestArgs(request, method);
|
|
3388
|
+
rejectExtraKeys(
|
|
3389
|
+
args,
|
|
3390
|
+
requireManager ? ["manager", "innerTarget", "innerData", "value"] : ["innerTarget", "innerData", "value"],
|
|
3391
|
+
method
|
|
3392
|
+
);
|
|
3393
|
+
return {
|
|
3394
|
+
...requireManager ? { manager: normalizePanopticAddress(args.manager, `${method} args.manager`) } : {},
|
|
3395
|
+
innerTarget: normalizePanopticAddress(args.innerTarget, `${method} args.innerTarget`),
|
|
3396
|
+
innerData: normalizePanopticHex(args.innerData, `${method} args.innerData`),
|
|
3397
|
+
value: args.value === void 0 ? BigInt(0) : uint256Arg(args, "value")
|
|
3398
|
+
};
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3401
|
+
// src/internal/panoptic/fragments/merkle.ts
|
|
3402
|
+
var MANAGE_VAULT_WITH_MERKLE_VERIFICATION_SELECTOR = "0x244b0f6a";
|
|
3403
|
+
var MANAGE_VAULT_WITH_MERKLE_VERIFICATION_ABI = [
|
|
3404
|
+
{
|
|
3405
|
+
type: "function",
|
|
3406
|
+
name: "manageVaultWithMerkleVerification",
|
|
3407
|
+
stateMutability: "nonpayable",
|
|
3408
|
+
inputs: [
|
|
3409
|
+
{ name: "manageProofs", type: "bytes32[][]" },
|
|
3410
|
+
{ name: "decodersAndSanitizers", type: "address[]" },
|
|
3411
|
+
{ name: "targets", type: "address[]" },
|
|
3412
|
+
{ name: "targetData", type: "bytes[]" },
|
|
3413
|
+
{ name: "values", type: "uint256[]" }
|
|
3414
|
+
],
|
|
3415
|
+
outputs: []
|
|
3416
|
+
}
|
|
3417
|
+
];
|
|
3418
|
+
async function manageVaultWithVerificationFragment({ deps, method, request, options }) {
|
|
3419
|
+
void options;
|
|
3420
|
+
const input = parseManageVaultWithVerificationRequest(request, method);
|
|
3421
|
+
const encodeFunctionData = requireSdkFunction(await deps.viem(), "encodeFunctionData", "viem");
|
|
3422
|
+
const split = splitCalldata(
|
|
3423
|
+
await encodeFunctionData({
|
|
3424
|
+
abi: MANAGE_VAULT_WITH_MERKLE_VERIFICATION_ABI,
|
|
3425
|
+
functionName: "manageVaultWithMerkleVerification",
|
|
3426
|
+
args: [input.proofs, input.decoders, input.innerTargets, input.innerDatas, input.values]
|
|
3427
|
+
}),
|
|
3428
|
+
method,
|
|
3429
|
+
{ expectedSelector: MANAGE_VAULT_WITH_MERKLE_VERIFICATION_SELECTOR }
|
|
3430
|
+
);
|
|
3431
|
+
return makeDynamicJobFragment({
|
|
3432
|
+
target: input.manager,
|
|
3433
|
+
userProvidedData: split.userProvidedData,
|
|
3434
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3435
|
+
value: "0"
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
function findLeaf({ request, method }) {
|
|
3439
|
+
const input = parseFindLeafRequest(request, method);
|
|
3440
|
+
const leaf = findArtifactLeaf(input.artifact, input.query, method);
|
|
3441
|
+
return projectLeafWithProof(input.artifact, leaf, method);
|
|
3442
|
+
}
|
|
3443
|
+
function buildManageArgs({ request, method }) {
|
|
3444
|
+
const input = parseBuildManageArgsRequest(request, method);
|
|
3445
|
+
const proofs = [];
|
|
3446
|
+
const decoders = [];
|
|
3447
|
+
const innerTargets = [];
|
|
3448
|
+
const innerDatas = [];
|
|
3449
|
+
const values = [];
|
|
3450
|
+
const leaves = [];
|
|
3451
|
+
for (const [index, action] of input.actions.entries()) {
|
|
3452
|
+
const label = `${method} args.actions[${index}]`;
|
|
3453
|
+
const leaf = findArtifactLeaf(input.artifact, action.query, label);
|
|
3454
|
+
const projected = projectLeafWithProof(input.artifact, leaf, label);
|
|
3455
|
+
proofs.push(projected.proof);
|
|
3456
|
+
decoders.push(projected.decoder);
|
|
3457
|
+
innerTargets.push(projected.target);
|
|
3458
|
+
innerDatas.push(action.data);
|
|
3459
|
+
values.push(action.value);
|
|
3460
|
+
leaves.push(projected);
|
|
3461
|
+
}
|
|
3462
|
+
return {
|
|
3463
|
+
proofs,
|
|
3464
|
+
decoders,
|
|
3465
|
+
innerTargets,
|
|
3466
|
+
innerDatas,
|
|
3467
|
+
values,
|
|
3468
|
+
leaves
|
|
3469
|
+
};
|
|
3470
|
+
}
|
|
3471
|
+
function parseManageVaultWithVerificationRequest(request, method) {
|
|
3472
|
+
rejectContext(request, method);
|
|
3473
|
+
const args = requestArgs(request, method);
|
|
3474
|
+
rejectExtraKeys(args, ["manager", "proofs", "decoders", "innerTargets", "innerDatas", "values"], method);
|
|
3475
|
+
const proofs = bytes32MatrixArg(args, "proofs", method);
|
|
3476
|
+
const decoders = addressArrayArg(args, "decoders", method);
|
|
3477
|
+
const innerTargets = addressArrayArg(args, "innerTargets", method);
|
|
3478
|
+
const innerDatas = hexArrayArg(args, "innerDatas", method);
|
|
3479
|
+
const values = uint256Array(args, "values");
|
|
3480
|
+
const length = proofs.length;
|
|
3481
|
+
for (const [field, value] of [
|
|
3482
|
+
["decoders", decoders],
|
|
3483
|
+
["innerTargets", innerTargets],
|
|
3484
|
+
["innerDatas", innerDatas],
|
|
3485
|
+
["values", values]
|
|
3486
|
+
]) {
|
|
3487
|
+
if (value.length !== length) {
|
|
3488
|
+
throw new Error(`Panoptic ${method} args.${field} length must match args.proofs length.`);
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
if (length === 0) {
|
|
3492
|
+
throw new Error(`Panoptic ${method} args.proofs must include at least one proof.`);
|
|
3493
|
+
}
|
|
3494
|
+
return {
|
|
3495
|
+
manager: normalizePanopticAddress(args.manager, `${method} args.manager`),
|
|
3496
|
+
proofs,
|
|
3497
|
+
decoders,
|
|
3498
|
+
innerTargets,
|
|
3499
|
+
innerDatas,
|
|
3500
|
+
values
|
|
3501
|
+
};
|
|
3502
|
+
}
|
|
3503
|
+
function parseFindLeafRequest(request, method) {
|
|
3504
|
+
rejectContext(request, method);
|
|
3505
|
+
const args = requestArgs(request, method);
|
|
3506
|
+
rejectExtraKeys(
|
|
3507
|
+
args,
|
|
3508
|
+
["artifact", "action", "description", "functionSignature", "functionSelector", "target"],
|
|
3509
|
+
method
|
|
3510
|
+
);
|
|
3511
|
+
return {
|
|
3512
|
+
artifact: recordValue(args.artifact, `args.artifact`),
|
|
3513
|
+
query: parseLeafQuery(args, method, "args")
|
|
3514
|
+
};
|
|
3515
|
+
}
|
|
3516
|
+
function parseBuildManageArgsRequest(request, method) {
|
|
3517
|
+
rejectContext(request, method);
|
|
3518
|
+
const args = requestArgs(request, method);
|
|
3519
|
+
rejectExtraKeys(args, ["artifact", "actions"], method);
|
|
3520
|
+
return {
|
|
3521
|
+
artifact: recordValue(args.artifact, `args.artifact`),
|
|
3522
|
+
actions: arrayValue(args.actions, "args.actions").map((item, index) => {
|
|
3523
|
+
const action = recordValue(item, `args.actions[${index}]`);
|
|
3524
|
+
rejectExtraKeys(
|
|
3525
|
+
action,
|
|
3526
|
+
["action", "description", "functionSignature", "functionSelector", "target", "data", "value"],
|
|
3527
|
+
method
|
|
3528
|
+
);
|
|
3529
|
+
return {
|
|
3530
|
+
query: parseLeafQuery(action, method, `args.actions[${index}]`),
|
|
3531
|
+
data: normalizePanopticHex(action.data, `${method} args.actions[${index}].data`),
|
|
3532
|
+
value: action.value === void 0 ? BigInt(0) : decimalValue(action.value, `args.actions[${index}].value`)
|
|
3533
|
+
};
|
|
3534
|
+
})
|
|
3535
|
+
};
|
|
3536
|
+
}
|
|
3537
|
+
function parseLeafQuery(args, method, label) {
|
|
3538
|
+
const query = {
|
|
3539
|
+
...args.action === void 0 ? {} : { action: stringValue(args.action, `${label}.action`) },
|
|
3540
|
+
...args.description === void 0 ? {} : { description: stringValue(args.description, `${label}.description`) },
|
|
3541
|
+
...args.functionSignature === void 0 ? {} : { functionSignature: stringValue(args.functionSignature, `${label}.functionSignature`) },
|
|
3542
|
+
...args.functionSelector === void 0 ? {} : { functionSelector: normalizePanopticHex(args.functionSelector, `${method} ${label}.functionSelector`) },
|
|
3543
|
+
...args.target === void 0 ? {} : { target: normalizePanopticAddress(args.target, `${method} ${label}.target`) }
|
|
3544
|
+
};
|
|
3545
|
+
if (Object.keys(query).length === 0) {
|
|
3546
|
+
throw new Error(`Panoptic ${method} ${label} must include at least one leaf selector.`);
|
|
3547
|
+
}
|
|
3548
|
+
return query;
|
|
3549
|
+
}
|
|
3550
|
+
function findArtifactLeaf(artifact, query, method) {
|
|
3551
|
+
const leaves = artifactLeafs(artifact, method);
|
|
3552
|
+
const matches = leaves.filter((leaf) => leafMatches(leaf, query, method));
|
|
3553
|
+
if (matches.length === 0) {
|
|
3554
|
+
throw new Error(`Panoptic ${method} could not find a matching Merkle leaf.`);
|
|
3555
|
+
}
|
|
3556
|
+
if (matches.length > 1) {
|
|
3557
|
+
throw new Error(`Panoptic ${method} found multiple matching Merkle leaves; provide a more specific selector.`);
|
|
3558
|
+
}
|
|
3559
|
+
return matches[0];
|
|
3560
|
+
}
|
|
3561
|
+
function artifactLeafs(artifact, method) {
|
|
3562
|
+
const rawLeaves = artifact.leafs ?? artifact.uniqueLeafs ?? (isJsonRecord3(artifact.artifact) ? artifact.artifact.leafs : void 0);
|
|
3563
|
+
return arrayValue(rawLeaves, `${method} artifact.leafs`).map(
|
|
3564
|
+
(item, index) => recordValue(item, `${method} artifact.leafs[${index}]`)
|
|
3565
|
+
);
|
|
3566
|
+
}
|
|
3567
|
+
function leafMatches(leaf, query, method) {
|
|
3568
|
+
if (query.action !== void 0 && leafString(leaf, "Action", method) !== query.action) return false;
|
|
3569
|
+
if (query.description !== void 0 && leafString(leaf, "Description", method) !== query.description) return false;
|
|
3570
|
+
if (query.functionSignature !== void 0 && leafString(leaf, "FunctionSignature", method) !== query.functionSignature)
|
|
3571
|
+
return false;
|
|
3572
|
+
if (query.functionSelector !== void 0 && normalizePanopticHex(leaf.FunctionSelector, `${method} leaf.FunctionSelector`) !== query.functionSelector)
|
|
3573
|
+
return false;
|
|
3574
|
+
if (query.target !== void 0 && normalizePanopticAddress(leaf.TargetAddress, `${method} leaf.TargetAddress`) !== query.target)
|
|
3575
|
+
return false;
|
|
3576
|
+
return true;
|
|
3577
|
+
}
|
|
3578
|
+
function projectLeafWithProof(artifact, leaf, method) {
|
|
3579
|
+
const action = leafString(leaf, "Action", method);
|
|
3580
|
+
const leafDigest = normalizePanopticHex(leaf.LeafDigest, `${method} leaf.LeafDigest`);
|
|
3581
|
+
return {
|
|
3582
|
+
action,
|
|
3583
|
+
description: leafString(leaf, "Description", method),
|
|
3584
|
+
leafDigest,
|
|
3585
|
+
decoder: normalizePanopticAddress(leaf.DecoderAndSanitizerAddress, `${method} leaf.DecoderAndSanitizerAddress`),
|
|
3586
|
+
target: normalizePanopticAddress(leaf.TargetAddress, `${method} leaf.TargetAddress`),
|
|
3587
|
+
functionSignature: leafString(leaf, "FunctionSignature", method),
|
|
3588
|
+
functionSelector: normalizePanopticHex(leaf.FunctionSelector, `${method} leaf.FunctionSelector`),
|
|
3589
|
+
canSendValue: leaf.CanSendValue === true,
|
|
3590
|
+
proof: proofForLeaf(artifact, action, leafDigest, method)
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
function proofForLeaf(artifact, action, leafDigest, method) {
|
|
3594
|
+
const byAction = isJsonRecord3(artifact.proofsByAction) ? artifact.proofsByAction[action] : void 0;
|
|
3595
|
+
const byDigest = isJsonRecord3(artifact.proofsByDigest) ? artifact.proofsByDigest[leafDigest] : void 0;
|
|
3596
|
+
const proof = byAction ?? byDigest;
|
|
3597
|
+
return proof === void 0 ? [] : arrayValue(proof, `${method} proof`).map((item, index) => bytes32Value(item, `${method} proof[${index}]`));
|
|
3598
|
+
}
|
|
3599
|
+
function leafString(leaf, field, method) {
|
|
3600
|
+
return stringValue(leaf[field], `${method} leaf.${field}`);
|
|
3601
|
+
}
|
|
3602
|
+
function bytes32Value(value, label) {
|
|
3603
|
+
const hex = normalizePanopticHex(value, label);
|
|
3604
|
+
if (hex.length !== 66) {
|
|
3605
|
+
throw new Error(`Panoptic ${label} must be bytes32.`);
|
|
3606
|
+
}
|
|
3607
|
+
return hex;
|
|
3608
|
+
}
|
|
3609
|
+
function bytes32MatrixArg(args, fieldName, method) {
|
|
3610
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
3611
|
+
(row, rowIndex) => arrayValue(row, `args.${fieldName}[${rowIndex}]`).map((item, index) => {
|
|
3612
|
+
const proof = normalizePanopticHex(item, `${method} args.${fieldName}[${rowIndex}][${index}]`);
|
|
3613
|
+
if (proof.length !== 66) {
|
|
3614
|
+
throw new Error(`Panoptic ${method} args.${fieldName}[${rowIndex}][${index}] must be bytes32.`);
|
|
3615
|
+
}
|
|
3616
|
+
return proof;
|
|
3617
|
+
})
|
|
3618
|
+
);
|
|
3619
|
+
}
|
|
3620
|
+
function addressArrayArg(args, fieldName, method) {
|
|
3621
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
3622
|
+
(item, index) => normalizePanopticAddress(item, `${method} args.${fieldName}[${index}]`)
|
|
3623
|
+
);
|
|
3624
|
+
}
|
|
3625
|
+
function hexArrayArg(args, fieldName, method) {
|
|
3626
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
3627
|
+
(item, index) => normalizePanopticHex(item, `${method} args.${fieldName}[${index}]`)
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
function uint256Array(args, fieldName) {
|
|
3631
|
+
return arrayValue(args[fieldName], `args.${fieldName}`).map(
|
|
3632
|
+
(item, index) => decimalValue(item, `args.${fieldName}[${index}]`)
|
|
3633
|
+
);
|
|
3634
|
+
}
|
|
3635
|
+
function isJsonRecord3(value) {
|
|
3636
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3639
|
+
// src/internal/panoptic/fragments/panoptic.ts
|
|
3640
|
+
var PANOPTIC_DISPATCH_SELECTOR = "0xc25813aa";
|
|
3641
|
+
var MAX_EXISTING_POSITION_IDS = 64;
|
|
3642
|
+
var UINT128_MAX2 = (BigInt(1) << BigInt(128)) - BigInt(1);
|
|
3643
|
+
var INT24_MIN2 = -(BigInt(1) << BigInt(23));
|
|
3644
|
+
var INT24_MAX2 = (BigInt(1) << BigInt(23)) - BigInt(1);
|
|
3645
|
+
var DISPATCH_EXPLICIT_ABI = [
|
|
3646
|
+
{
|
|
3647
|
+
type: "function",
|
|
3648
|
+
name: "dispatch",
|
|
3649
|
+
stateMutability: "nonpayable",
|
|
3650
|
+
inputs: [
|
|
3651
|
+
{ name: "positionIdList", type: "uint256[]" },
|
|
3652
|
+
{ name: "finalPositionIdList", type: "uint256[]" },
|
|
3653
|
+
{ name: "positionSizes", type: "uint128[]" },
|
|
3654
|
+
{ name: "tickAndSpreadLimits", type: "int24[3][]" },
|
|
3655
|
+
{ name: "usePremiaAsCollateral", type: "bool" },
|
|
3656
|
+
{ name: "builderCode", type: "uint256" }
|
|
3657
|
+
],
|
|
3658
|
+
outputs: []
|
|
3659
|
+
}
|
|
3660
|
+
];
|
|
3661
|
+
async function dispatchCalldataParts({ deps, request, method }) {
|
|
3662
|
+
const input = parseDispatchRequest(request, method);
|
|
3663
|
+
const sdkV2 = await deps.sdkV2();
|
|
3664
|
+
const buildOpenPositionCalldata = requireSdkFunction(sdkV2, "buildOpenPositionCalldata", "@panoptic-eng/sdk/v2");
|
|
3665
|
+
const poolAddress2 = requireString(input.poolAddress, `${method} args.poolAddress`);
|
|
3666
|
+
const split = splitDispatchCalldata(
|
|
3667
|
+
await buildOpenPositionCalldata(buildOpenPositionParams(input, poolAddress2)),
|
|
3668
|
+
method
|
|
3669
|
+
);
|
|
3670
|
+
return {
|
|
3671
|
+
functionName: "dispatch",
|
|
3672
|
+
userProvidedData: split.userProvidedData,
|
|
3673
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3674
|
+
calldata: split.calldata
|
|
3675
|
+
};
|
|
3676
|
+
}
|
|
3677
|
+
async function dispatchFragment({ deps, request, options, method }) {
|
|
3678
|
+
void options;
|
|
3679
|
+
const input = parseDispatchRequest(request, method);
|
|
3680
|
+
const sdkV2 = await deps.sdkV2();
|
|
3681
|
+
const buildOpenPositionCalldata = requireSdkFunction(sdkV2, "buildOpenPositionCalldata", "@panoptic-eng/sdk/v2");
|
|
3682
|
+
const targetAddress = input.poolAddress;
|
|
3683
|
+
const split = splitDispatchCalldata(
|
|
3684
|
+
await buildOpenPositionCalldata(buildOpenPositionParams(input, input.poolAddress)),
|
|
3685
|
+
method
|
|
3686
|
+
);
|
|
3687
|
+
if (split.target && split.target !== targetAddress) {
|
|
3688
|
+
throw new Error(`Panoptic ${method} SDK returned a target that does not match args.poolAddress.`);
|
|
3689
|
+
}
|
|
3690
|
+
return makeDynamicJobFragment({
|
|
3691
|
+
target: targetAddress,
|
|
3692
|
+
userProvidedData: split.userProvidedData,
|
|
3693
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3694
|
+
value: "0"
|
|
3695
|
+
});
|
|
3696
|
+
}
|
|
3697
|
+
async function dispatchExplicitCalldataParts({ deps, request, method }) {
|
|
3698
|
+
const input = parseExplicitDispatchRequest(request, method);
|
|
3699
|
+
const split = splitDispatchCalldata(await encodeExplicitDispatchCalldata(deps, input), method);
|
|
3700
|
+
return {
|
|
3701
|
+
functionName: "dispatch",
|
|
3702
|
+
userProvidedData: split.userProvidedData,
|
|
3703
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3704
|
+
calldata: split.calldata,
|
|
3705
|
+
value: "0"
|
|
3706
|
+
};
|
|
3707
|
+
}
|
|
3708
|
+
async function dispatchExplicitFragment({ deps, request, options, method }) {
|
|
3709
|
+
void options;
|
|
3710
|
+
const input = parseExplicitDispatchRequest(request, method);
|
|
3711
|
+
const split = splitDispatchCalldata(await encodeExplicitDispatchCalldata(deps, input), method);
|
|
3712
|
+
return makeDynamicJobFragment({
|
|
3713
|
+
target: input.poolAddress,
|
|
3714
|
+
userProvidedData: split.userProvidedData,
|
|
3715
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3716
|
+
value: "0"
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
async function encodeExplicitDispatchCalldata(deps, input) {
|
|
3720
|
+
const encodeFunctionData = requireSdkFunction(await deps.viem(), "encodeFunctionData", "viem");
|
|
3721
|
+
return encodeFunctionData({
|
|
3722
|
+
abi: DISPATCH_EXPLICIT_ABI,
|
|
3723
|
+
functionName: "dispatch",
|
|
3724
|
+
args: [
|
|
3725
|
+
input.positionIdList,
|
|
3726
|
+
input.finalPositionIdList,
|
|
3727
|
+
input.positionSizes,
|
|
3728
|
+
input.tickAndSpreadLimits,
|
|
3729
|
+
input.usePremiaAsCollateral,
|
|
3730
|
+
input.builderCode
|
|
3731
|
+
]
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
function parseDispatchRequest(request, method) {
|
|
3735
|
+
rejectContext(request, method);
|
|
3736
|
+
const args = requestArgs(request, method);
|
|
3737
|
+
rejectExtraKeys(args, dispatchKeys, method);
|
|
3738
|
+
return parseDispatchCommon(args, method);
|
|
3739
|
+
}
|
|
3740
|
+
function parseExplicitDispatchRequest(request, method) {
|
|
3741
|
+
rejectContext(request, method);
|
|
3742
|
+
const args = requestArgs(request, method);
|
|
3743
|
+
rejectExtraKeys(args, explicitDispatchKeys, method);
|
|
3744
|
+
const positionIdList = positionIdsArg(args, "positionIdList", method);
|
|
3745
|
+
const positionSizes = uint128ArrayArg(args, "positionSizes", method);
|
|
3746
|
+
const tickAndSpreadLimits = int24TripleArrayArg(args.tickAndSpreadLimits, `${method} args.tickAndSpreadLimits`);
|
|
3747
|
+
if (positionSizes.length !== positionIdList.length) {
|
|
3748
|
+
throw new Error(`Panoptic ${method} args.positionSizes length must match args.positionIdList length.`);
|
|
3749
|
+
}
|
|
3750
|
+
if (tickAndSpreadLimits.length !== positionIdList.length) {
|
|
3751
|
+
throw new Error(`Panoptic ${method} args.tickAndSpreadLimits length must match args.positionIdList length.`);
|
|
3752
|
+
}
|
|
3753
|
+
return {
|
|
3754
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
3755
|
+
positionIdList,
|
|
3756
|
+
finalPositionIdList: uint256ArrayArg(args, "finalPositionIdList"),
|
|
3757
|
+
positionSizes,
|
|
3758
|
+
tickAndSpreadLimits,
|
|
3759
|
+
usePremiaAsCollateral: requiredBooleanArg(args.usePremiaAsCollateral, `${method} args.usePremiaAsCollateral`),
|
|
3760
|
+
builderCode: optionalUint256Arg(args, "builderCode") ?? BigInt(0)
|
|
3761
|
+
};
|
|
3762
|
+
}
|
|
3763
|
+
function parseDispatchCommon(args, method) {
|
|
3764
|
+
return {
|
|
3765
|
+
poolAddress: normalizePanopticAddress(args.poolAddress, `${method} args.poolAddress`),
|
|
3766
|
+
existingPositionIds: positionIdsArg(args, "existingPositionIds", method),
|
|
3767
|
+
tokenId: uint256Arg(args, "tokenId"),
|
|
3768
|
+
positionSize: uint128Arg(args, "positionSize"),
|
|
3769
|
+
tickLimitLow: int24Arg(args, "tickLimitLow"),
|
|
3770
|
+
tickLimitHigh: int24Arg(args, "tickLimitHigh"),
|
|
3771
|
+
spreadLimit: optionalInt24Arg(args, "spreadLimit"),
|
|
3772
|
+
swapAtMint: optionalBooleanArg2(args, "swapAtMint", method),
|
|
3773
|
+
usePremiaAsCollateral: optionalBooleanArg2(args, "usePremiaAsCollateral", method),
|
|
3774
|
+
builderCode: optionalUint256Arg(args, "builderCode")
|
|
3775
|
+
};
|
|
3776
|
+
}
|
|
3777
|
+
function buildOpenPositionParams(input, poolAddress2) {
|
|
3778
|
+
return {
|
|
3779
|
+
poolAddress: poolAddress2,
|
|
3780
|
+
existingPositionIds: input.existingPositionIds,
|
|
3781
|
+
tokenId: input.tokenId,
|
|
3782
|
+
positionSize: input.positionSize,
|
|
3783
|
+
tickLimitLow: input.tickLimitLow,
|
|
3784
|
+
tickLimitHigh: input.tickLimitHigh,
|
|
3785
|
+
spreadLimit: input.spreadLimit,
|
|
3786
|
+
swapAtMint: input.swapAtMint,
|
|
3787
|
+
usePremiaAsCollateral: input.usePremiaAsCollateral,
|
|
3788
|
+
builderCode: input.builderCode
|
|
3789
|
+
};
|
|
3790
|
+
}
|
|
3791
|
+
function positionIdsArg(args, fieldName, method) {
|
|
3792
|
+
const positionIds = uint256ArrayArg(args, fieldName);
|
|
3793
|
+
if (positionIds.length > MAX_EXISTING_POSITION_IDS) {
|
|
3794
|
+
throw new Error(`Panoptic ${method} args.${fieldName} must contain at most ${MAX_EXISTING_POSITION_IDS} items.`);
|
|
3795
|
+
}
|
|
3796
|
+
return positionIds;
|
|
3797
|
+
}
|
|
3798
|
+
function splitDispatchCalldata(value, method) {
|
|
3799
|
+
return splitCalldata(value, method, { expectedSelector: PANOPTIC_DISPATCH_SELECTOR });
|
|
3800
|
+
}
|
|
3801
|
+
function optionalBooleanArg2(args, fieldName, method) {
|
|
3802
|
+
const value = args[fieldName];
|
|
3803
|
+
if (value === void 0) {
|
|
3804
|
+
return void 0;
|
|
3805
|
+
}
|
|
3806
|
+
if (typeof value !== "boolean") {
|
|
3807
|
+
throw new Error(`Panoptic ${method} args.${fieldName} must be a boolean.`);
|
|
3808
|
+
}
|
|
3809
|
+
return value;
|
|
3810
|
+
}
|
|
3811
|
+
function requiredBooleanArg(value, label) {
|
|
3812
|
+
if (typeof value !== "boolean") {
|
|
3813
|
+
throw new Error(`Panoptic ${label} must be a boolean.`);
|
|
3814
|
+
}
|
|
3815
|
+
return value;
|
|
3816
|
+
}
|
|
3817
|
+
function uint128ArrayArg(args, fieldName, method) {
|
|
3818
|
+
const values = uint256ArrayArg(args, fieldName);
|
|
3819
|
+
for (const [index, value] of values.entries()) {
|
|
3820
|
+
if (value > UINT128_MAX2) {
|
|
3821
|
+
throw new Error(`Panoptic ${method} args.${fieldName}[${index}] exceeds uint128 range.`);
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
return values;
|
|
3825
|
+
}
|
|
3826
|
+
function int24TripleArrayArg(value, label) {
|
|
3827
|
+
if (!Array.isArray(value)) {
|
|
3828
|
+
throw new Error(`Panoptic ${label} must be an array.`);
|
|
3829
|
+
}
|
|
3830
|
+
return value.map((row, rowIndex) => {
|
|
3831
|
+
if (!Array.isArray(row) || row.length !== 3) {
|
|
3832
|
+
throw new Error(`Panoptic ${label}[${rowIndex}] must be an int24 triple.`);
|
|
3833
|
+
}
|
|
3834
|
+
return row.map((item, index) => signedInt24Value(item, `${label}[${rowIndex}][${index}]`));
|
|
3835
|
+
});
|
|
3836
|
+
}
|
|
3837
|
+
function signedInt24Value(value, label) {
|
|
3838
|
+
if (typeof value !== "string" || !/^-?(0|[1-9][0-9]*)$/.test(value)) {
|
|
3839
|
+
throw new Error(`Panoptic ${label} must be a signed decimal string.`);
|
|
3840
|
+
}
|
|
3841
|
+
const parsed = BigInt(value);
|
|
3842
|
+
if (parsed < INT24_MIN2 || parsed > INT24_MAX2) {
|
|
3843
|
+
throw new Error(`Panoptic ${label} exceeds int24 range.`);
|
|
3844
|
+
}
|
|
3845
|
+
return parsed;
|
|
3846
|
+
}
|
|
3847
|
+
var dispatchKeys = [
|
|
3848
|
+
"poolAddress",
|
|
3849
|
+
"existingPositionIds",
|
|
3850
|
+
"tokenId",
|
|
3851
|
+
"positionSize",
|
|
3852
|
+
"tickLimitLow",
|
|
3853
|
+
"tickLimitHigh",
|
|
3854
|
+
"spreadLimit",
|
|
3855
|
+
"swapAtMint",
|
|
3856
|
+
"usePremiaAsCollateral",
|
|
3857
|
+
"builderCode"
|
|
3858
|
+
];
|
|
3859
|
+
var explicitDispatchKeys = [
|
|
3860
|
+
"poolAddress",
|
|
3861
|
+
"positionIdList",
|
|
3862
|
+
"finalPositionIdList",
|
|
3863
|
+
"positionSizes",
|
|
3864
|
+
"tickAndSpreadLimits",
|
|
3865
|
+
"usePremiaAsCollateral",
|
|
3866
|
+
"builderCode"
|
|
3867
|
+
];
|
|
3868
|
+
|
|
3869
|
+
// src/internal/panoptic/fragments/permit2.ts
|
|
3870
|
+
var PERMIT2_APPROVE_ABI = [
|
|
3871
|
+
{
|
|
3872
|
+
type: "function",
|
|
3873
|
+
name: "approve",
|
|
3874
|
+
stateMutability: "nonpayable",
|
|
3875
|
+
inputs: [
|
|
3876
|
+
{ name: "token", type: "address" },
|
|
3877
|
+
{ name: "spender", type: "address" },
|
|
3878
|
+
{ name: "amount", type: "uint160" },
|
|
3879
|
+
{ name: "expiration", type: "uint48" }
|
|
3880
|
+
],
|
|
3881
|
+
outputs: []
|
|
3882
|
+
}
|
|
3883
|
+
];
|
|
3884
|
+
var PERMIT2_APPROVE_SELECTOR = "0x87517c45";
|
|
3885
|
+
async function approveFragment2({ deps, method, request, options }) {
|
|
3886
|
+
void options;
|
|
3887
|
+
const input = parseApproveRequest2(request, method);
|
|
3888
|
+
const encodeFunctionData = requireSdkFunction(await deps.viem(), "encodeFunctionData", "viem");
|
|
3889
|
+
const calldata = await encodeFunctionData({
|
|
3890
|
+
abi: PERMIT2_APPROVE_ABI,
|
|
3891
|
+
functionName: "approve",
|
|
3892
|
+
args: [input.token, input.spender, input.amount, input.expiration]
|
|
3893
|
+
});
|
|
3894
|
+
const split = splitCalldata(calldata, method, {
|
|
3895
|
+
expectedSelector: PERMIT2_APPROVE_SELECTOR,
|
|
3896
|
+
staticArgWords: 2
|
|
3897
|
+
});
|
|
3898
|
+
assertUserProvidedData(
|
|
3899
|
+
split.userProvidedData,
|
|
3900
|
+
`${PERMIT2_APPROVE_SELECTOR}${addressAbiWord(input.token)}${addressAbiWord(input.spender)}`,
|
|
3901
|
+
method
|
|
3902
|
+
);
|
|
3903
|
+
return makeDynamicJobFragment({
|
|
3904
|
+
target: input.permit2,
|
|
3905
|
+
userProvidedData: split.userProvidedData,
|
|
3906
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3907
|
+
value: "0"
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
function parseApproveRequest2(request, method) {
|
|
3911
|
+
rejectContext(request, method);
|
|
3912
|
+
const args = requestArgs(request, method);
|
|
3913
|
+
rejectExtraKeys(args, ["permit2", "token", "spender", "amount", "expiration"], method);
|
|
3914
|
+
return {
|
|
3915
|
+
permit2: normalizePanopticAddress(args.permit2, `${method} args.permit2`),
|
|
3916
|
+
token: normalizePanopticAddress(args.token, `${method} args.token`),
|
|
3917
|
+
spender: normalizePanopticAddress(args.spender, `${method} args.spender`),
|
|
3918
|
+
amount: uint160Arg(args, "amount"),
|
|
3919
|
+
expiration: uint48Arg(args, "expiration")
|
|
3920
|
+
};
|
|
3921
|
+
}
|
|
3922
|
+
|
|
3923
|
+
// src/internal/panoptic/fragments/uniswap.ts
|
|
3924
|
+
var UNIVERSAL_ROUTER_EXECUTE_SELECTOR = "0x24856bc3";
|
|
3925
|
+
var UNIVERSAL_ROUTER_EXECUTE_DEADLINE_SELECTOR = "0x3593564c";
|
|
3926
|
+
var V3_SWAP_EXACT_IN_COMMAND = "0x00";
|
|
3927
|
+
var V3_EXACT_IN_INPUT_ABI = [
|
|
3928
|
+
{ name: "recipient", type: "address" },
|
|
3929
|
+
{ name: "amountIn", type: "uint256" },
|
|
3930
|
+
{ name: "amountOutMinimum", type: "uint256" },
|
|
3931
|
+
{ name: "path", type: "bytes" },
|
|
3932
|
+
{ name: "payerIsUser", type: "bool" }
|
|
3933
|
+
];
|
|
3934
|
+
var UNIVERSAL_ROUTER_EXECUTE_ABI = [
|
|
3935
|
+
{
|
|
3936
|
+
type: "function",
|
|
3937
|
+
name: "execute",
|
|
3938
|
+
stateMutability: "payable",
|
|
3939
|
+
inputs: [
|
|
3940
|
+
{ name: "commands", type: "bytes" },
|
|
3941
|
+
{ name: "inputs", type: "bytes[]" }
|
|
3942
|
+
],
|
|
3943
|
+
outputs: []
|
|
3944
|
+
}
|
|
3945
|
+
];
|
|
3946
|
+
var UNIVERSAL_ROUTER_EXECUTE_DEADLINE_ABI = [
|
|
3947
|
+
{
|
|
3948
|
+
type: "function",
|
|
3949
|
+
name: "execute",
|
|
3950
|
+
stateMutability: "payable",
|
|
3951
|
+
inputs: [
|
|
3952
|
+
{ name: "commands", type: "bytes" },
|
|
3953
|
+
{ name: "inputs", type: "bytes[]" },
|
|
3954
|
+
{ name: "deadline", type: "uint256" }
|
|
3955
|
+
],
|
|
3956
|
+
outputs: []
|
|
3957
|
+
}
|
|
3958
|
+
];
|
|
3959
|
+
async function buildV3ExactInExecuteCalldataParts({ deps, request, method, options }) {
|
|
3960
|
+
void options;
|
|
3961
|
+
const input = parseV3ExactInRequest(request, method);
|
|
3962
|
+
const calldata = await buildV3ExactInCalldata(deps, input);
|
|
3963
|
+
const split = splitCalldata(calldata, method, {
|
|
3964
|
+
expectedSelector: input.deadline === void 0 ? UNIVERSAL_ROUTER_EXECUTE_SELECTOR : UNIVERSAL_ROUTER_EXECUTE_DEADLINE_SELECTOR
|
|
3965
|
+
});
|
|
3966
|
+
return {
|
|
3967
|
+
functionName: input.deadline === void 0 ? "execute(bytes,bytes[])" : "execute(bytes,bytes[],uint256)",
|
|
3968
|
+
calldata: split.calldata,
|
|
3969
|
+
userProvidedData: split.userProvidedData,
|
|
3970
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3971
|
+
value: "0"
|
|
3972
|
+
};
|
|
3973
|
+
}
|
|
3974
|
+
async function buildV3ExactInExecuteFragment({ deps, request, method, options }) {
|
|
3975
|
+
void options;
|
|
3976
|
+
const input = parseV3ExactInRequest(request, method);
|
|
3977
|
+
if (!input.router) {
|
|
3978
|
+
throw new Error(`Panoptic ${method} requires args.router.`);
|
|
3979
|
+
}
|
|
3980
|
+
const calldata = await buildV3ExactInCalldata(deps, input);
|
|
3981
|
+
const split = splitCalldata(calldata, method, {
|
|
3982
|
+
expectedSelector: input.deadline === void 0 ? UNIVERSAL_ROUTER_EXECUTE_SELECTOR : UNIVERSAL_ROUTER_EXECUTE_DEADLINE_SELECTOR
|
|
3983
|
+
});
|
|
3984
|
+
return makeDynamicJobFragment({
|
|
3985
|
+
target: input.router,
|
|
3986
|
+
userProvidedData: split.userProvidedData,
|
|
3987
|
+
strategyProvidedData: split.strategyProvidedData,
|
|
3988
|
+
value: "0"
|
|
3989
|
+
});
|
|
3990
|
+
}
|
|
3991
|
+
async function buildV3ExactInCalldata(deps, input) {
|
|
3992
|
+
const viem = await deps.viem();
|
|
3993
|
+
const encodeAbiParameters = requireSdkFunction(viem, "encodeAbiParameters", "viem");
|
|
3994
|
+
const encodeFunctionData = requireSdkFunction(viem, "encodeFunctionData", "viem");
|
|
3995
|
+
const path = encodeV3Path(input.tokenIn, input.fee, input.tokenOut);
|
|
3996
|
+
const exactInInput = await encodeAbiParameters(V3_EXACT_IN_INPUT_ABI, [
|
|
3997
|
+
input.recipient,
|
|
3998
|
+
input.amountIn,
|
|
3999
|
+
input.amountOutMin,
|
|
4000
|
+
path,
|
|
4001
|
+
input.payerIsUser
|
|
4002
|
+
]);
|
|
4003
|
+
if (input.deadline === void 0) {
|
|
4004
|
+
return encodeFunctionData({
|
|
4005
|
+
abi: UNIVERSAL_ROUTER_EXECUTE_ABI,
|
|
4006
|
+
functionName: "execute",
|
|
4007
|
+
args: [V3_SWAP_EXACT_IN_COMMAND, [exactInInput]]
|
|
4008
|
+
});
|
|
4009
|
+
}
|
|
4010
|
+
return encodeFunctionData({
|
|
4011
|
+
abi: UNIVERSAL_ROUTER_EXECUTE_DEADLINE_ABI,
|
|
4012
|
+
functionName: "execute",
|
|
4013
|
+
args: [V3_SWAP_EXACT_IN_COMMAND, [exactInInput], input.deadline]
|
|
4014
|
+
});
|
|
4015
|
+
}
|
|
4016
|
+
function parseV3ExactInRequest(request, method) {
|
|
4017
|
+
rejectContext(request, method);
|
|
4018
|
+
const args = requestArgs(request, method);
|
|
4019
|
+
rejectExtraKeys(
|
|
4020
|
+
args,
|
|
4021
|
+
["router", "tokenIn", "tokenOut", "fee", "recipient", "amountIn", "amountOutMin", "payerIsUser", "deadline"],
|
|
4022
|
+
method
|
|
4023
|
+
);
|
|
4024
|
+
return {
|
|
4025
|
+
...args.router === void 0 ? {} : { router: normalizePanopticAddress(args.router, `${method} args.router`) },
|
|
4026
|
+
tokenIn: normalizePanopticAddress(args.tokenIn, `${method} args.tokenIn`),
|
|
4027
|
+
tokenOut: normalizePanopticAddress(args.tokenOut, `${method} args.tokenOut`),
|
|
4028
|
+
fee: uint24Arg(args.fee, `${method} args.fee`),
|
|
4029
|
+
recipient: normalizePanopticAddress(args.recipient, `${method} args.recipient`),
|
|
4030
|
+
amountIn: decimalValue(args.amountIn, "args.amountIn"),
|
|
4031
|
+
amountOutMin: decimalValue(args.amountOutMin, "args.amountOutMin"),
|
|
4032
|
+
payerIsUser: booleanValue(args.payerIsUser, "args.payerIsUser"),
|
|
4033
|
+
deadline: optionalDecimalArg(args, "deadline")
|
|
4034
|
+
};
|
|
4035
|
+
}
|
|
4036
|
+
function uint24Arg(value, label) {
|
|
4037
|
+
const parsed = decimalValue(value, label);
|
|
4038
|
+
if (parsed > BigInt(16777215)) {
|
|
4039
|
+
throw new Error(`Panoptic ${label} exceeds uint24 range.`);
|
|
4040
|
+
}
|
|
4041
|
+
return parsed;
|
|
4042
|
+
}
|
|
4043
|
+
function encodeV3Path(tokenIn, fee, tokenOut) {
|
|
4044
|
+
return `0x${tokenIn.slice(2)}${fee.toString(16).padStart(6, "0")}${tokenOut.slice(2)}`.toLowerCase();
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
// src/internal/panoptic/fragments/weth.ts
|
|
4048
|
+
var WETH_DEPOSIT_SELECTOR = "0xd0e30db0";
|
|
4049
|
+
var WETH_WITHDRAW_SELECTOR = "0x2e1a7d4d";
|
|
4050
|
+
function depositCalldataParts({ request, method }) {
|
|
4051
|
+
const input = parseAmountRequest(request, method);
|
|
4052
|
+
return {
|
|
4053
|
+
functionName: "deposit",
|
|
4054
|
+
calldata: WETH_DEPOSIT_SELECTOR,
|
|
4055
|
+
userProvidedData: WETH_DEPOSIT_SELECTOR,
|
|
4056
|
+
strategyProvidedData: "0x",
|
|
4057
|
+
value: input.amount.toString(10)
|
|
4058
|
+
};
|
|
4059
|
+
}
|
|
4060
|
+
function withdrawCalldataParts({ request, method }) {
|
|
4061
|
+
const input = parseAmountRequest(request, method);
|
|
4062
|
+
const strategyProvidedData = `0x${uint256AbiWord(input.amount)}`;
|
|
4063
|
+
return {
|
|
4064
|
+
functionName: "withdraw",
|
|
4065
|
+
calldata: `${WETH_WITHDRAW_SELECTOR}${strategyProvidedData.slice(2)}`,
|
|
4066
|
+
userProvidedData: WETH_WITHDRAW_SELECTOR,
|
|
4067
|
+
strategyProvidedData,
|
|
4068
|
+
value: "0"
|
|
4069
|
+
};
|
|
4070
|
+
}
|
|
4071
|
+
function hypovaultWethDepositInnerCall({ request, method }) {
|
|
4072
|
+
const input = parseWethTargetAmountRequest(request, method);
|
|
4073
|
+
return {
|
|
4074
|
+
functionName: "deposit",
|
|
4075
|
+
target: input.weth,
|
|
4076
|
+
data: WETH_DEPOSIT_SELECTOR,
|
|
4077
|
+
value: input.amount.toString(10)
|
|
4078
|
+
};
|
|
4079
|
+
}
|
|
4080
|
+
function hypovaultWethWithdrawInnerCall({ request, method }) {
|
|
4081
|
+
const input = parseWethTargetAmountRequest(request, method);
|
|
4082
|
+
const data = `${WETH_WITHDRAW_SELECTOR}${uint256AbiWord(input.amount)}`;
|
|
4083
|
+
return {
|
|
4084
|
+
functionName: "withdraw",
|
|
4085
|
+
target: input.weth,
|
|
4086
|
+
data,
|
|
4087
|
+
value: "0"
|
|
4088
|
+
};
|
|
4089
|
+
}
|
|
4090
|
+
function parseAmountRequest(request, method) {
|
|
4091
|
+
rejectContext(request, method);
|
|
4092
|
+
const args = requestArgs(request, method);
|
|
4093
|
+
rejectExtraKeys(args, ["amount"], method);
|
|
4094
|
+
return { amount: uint256Arg(args, "amount") };
|
|
4095
|
+
}
|
|
4096
|
+
function parseWethTargetAmountRequest(request, method) {
|
|
4097
|
+
rejectContext(request, method);
|
|
4098
|
+
const args = requestArgs(request, method);
|
|
4099
|
+
rejectExtraKeys(args, ["weth", "amount"], method);
|
|
4100
|
+
return {
|
|
4101
|
+
weth: normalizePanopticAddress(args.weth, `${method} args.weth`),
|
|
4102
|
+
amount: uint256Arg(args, "amount")
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
4105
|
+
|
|
4106
|
+
// src/internal/panoptic/dynamicJobs/renderExecuteJob.ts
|
|
4107
|
+
function renderExecuteJob({ request, method }) {
|
|
4108
|
+
const { fragments } = parseRenderExecuteJobRequest(request, method);
|
|
4109
|
+
return {
|
|
4110
|
+
functionName: "executeJob(address[],bytes[],bytes[])",
|
|
4111
|
+
typesArray: ["address[]", "bytes[]", "bytes[]"],
|
|
4112
|
+
valuesArray: [
|
|
4113
|
+
fragments.map((fragment) => fragment.target),
|
|
4114
|
+
fragments.map((fragment) => fragment.userProvidedData),
|
|
4115
|
+
fragments.map((fragment) => fragment.strategyProvidedData)
|
|
4116
|
+
]
|
|
4117
|
+
};
|
|
4118
|
+
}
|
|
4119
|
+
function parseRenderExecuteJobRequest(request, method) {
|
|
4120
|
+
const args = requestArgs(request, method);
|
|
4121
|
+
rejectExtraKeys(args, ["fragments"], method);
|
|
4122
|
+
if (!Array.isArray(args.fragments)) {
|
|
4123
|
+
throw new Error(`Panoptic ${method} args.fragments must be an array.`);
|
|
4124
|
+
}
|
|
4125
|
+
if (args.fragments.length === 0) {
|
|
4126
|
+
throw new Error(`Panoptic ${method} args.fragments must include at least one fragment.`);
|
|
4127
|
+
}
|
|
4128
|
+
if (args.fragments.length > 64) {
|
|
4129
|
+
throw new Error(`Panoptic ${method} args.fragments exceeds maximum array length 64.`);
|
|
4130
|
+
}
|
|
4131
|
+
return {
|
|
4132
|
+
fragments: args.fragments.map(
|
|
4133
|
+
(fragment, index) => validateDynamicJobFragment(fragment, `${method} args.fragments[${index}]`)
|
|
4134
|
+
)
|
|
4135
|
+
};
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4138
|
+
// src/internal/panoptic/handlers.ts
|
|
4139
|
+
var RPC_HANDLERS = Object.freeze({
|
|
4140
|
+
"account.getAccountCollateral": getAccountCollateral,
|
|
4141
|
+
"account.getAccountSummaryBasic": getAccountSummaryBasic,
|
|
4142
|
+
"account.getAccountSummaryRisk": getAccountSummaryRisk,
|
|
4143
|
+
"account.getLiquidationPrices": getLiquidationPrices,
|
|
4144
|
+
"account.getNetLiquidationValue": getNetLiquidationValue,
|
|
4145
|
+
"account.getNetLiquidationValues": getNetLiquidationValues,
|
|
4146
|
+
"account.getOpenPositionIds": getOpenPositionIds,
|
|
4147
|
+
"account.getPosition": getPosition,
|
|
4148
|
+
"account.getPositions": getPositions,
|
|
4149
|
+
"greeks.getPositionGreeks": getPositionGreeks,
|
|
4150
|
+
"hypovault.buildVaultManagerInputAtBlock": buildVaultManagerInputAtBlock,
|
|
4151
|
+
"hypovault.getEpochContext": getEpochContext,
|
|
4152
|
+
"hypovault.getOpenPositionIds": getOpenPositionIds2,
|
|
4153
|
+
"hypovault.getPositionsHashStatus": getPositionsHashStatus,
|
|
4154
|
+
"hypovault.verifyVaultOpenTokenIdsAtBlock": verifyVaultOpenTokenIdsAtBlock,
|
|
4155
|
+
"pool.fetchPoolId": fetchPoolId,
|
|
4156
|
+
"pool.getOracleState": getOracleState,
|
|
4157
|
+
"pool.getPool": getPool,
|
|
4158
|
+
"pool.getPoolMetadata": getPoolMetadata,
|
|
4159
|
+
"pool.getRiskParameters": getRiskParameters,
|
|
4160
|
+
"pool.getUtilization": getUtilization,
|
|
4161
|
+
"uniswap.checkRouterApproval": checkRouterApproval,
|
|
4162
|
+
"uniswap.quoteSwapExactInViaRouter": quoteSwapExactInViaRouter,
|
|
4163
|
+
"uniswap.quoteSwapExactOutViaRouter": quoteSwapExactOutViaRouter,
|
|
4164
|
+
"uniswap.resolveSwapRoute": resolveSwapRoute
|
|
4165
|
+
});
|
|
4166
|
+
var LOCAL_HANDLERS = Object.freeze({
|
|
4167
|
+
"collateral.depositFragment": depositFragment,
|
|
4168
|
+
"collateral.withdrawFragment": withdrawFragment,
|
|
4169
|
+
"collateral.withdrawWithPositionsFragment": withdrawWithPositionsFragment,
|
|
4170
|
+
"dynamicJobs.renderExecuteJob": renderExecuteJob,
|
|
4171
|
+
"erc20.approveFragment": approveFragment,
|
|
4172
|
+
"greeks.calculateAccountGreeksPure": calculateAccountGreeksPure,
|
|
4173
|
+
"greeks.calculatePositionGreeks": calculatePositionGreeks,
|
|
4174
|
+
"hypovault.fulfillDepositsFragment": fulfillDepositsFragment,
|
|
4175
|
+
"hypovault.fulfillWithdrawalsFragment": fulfillWithdrawalsFragment,
|
|
4176
|
+
"hypovault.manageCalldataParts": manageCalldataParts,
|
|
4177
|
+
"hypovault.manageFragment": manageFragment,
|
|
4178
|
+
"hypovault.wethDepositInnerCall": hypovaultWethDepositInnerCall,
|
|
4179
|
+
"hypovault.wethWithdrawInnerCall": hypovaultWethWithdrawInnerCall,
|
|
4180
|
+
"merkle.buildManageArgs": buildManageArgs,
|
|
4181
|
+
"merkle.findLeaf": findLeaf,
|
|
4182
|
+
"merkle.manageVaultWithVerificationFragment": manageVaultWithVerificationFragment,
|
|
4183
|
+
"panoptic.dispatchCalldataParts": dispatchCalldataParts,
|
|
4184
|
+
"panoptic.dispatchExplicitCalldataParts": dispatchExplicitCalldataParts,
|
|
4185
|
+
"panoptic.dispatchExplicitFragment": dispatchExplicitFragment,
|
|
4186
|
+
"panoptic.dispatchFragment": dispatchFragment,
|
|
4187
|
+
"permit2.approveFragment": approveFragment2,
|
|
4188
|
+
"pool.getPricesAtTick": getPricesAtTick,
|
|
4189
|
+
"pool.getTickSpacing": getTickSpacing,
|
|
4190
|
+
"uniswap.buildV3ExactInExecuteCalldataParts": buildV3ExactInExecuteCalldataParts,
|
|
4191
|
+
"uniswap.buildV3ExactInExecuteFragment": buildV3ExactInExecuteFragment,
|
|
4192
|
+
"weth.depositCalldataParts": depositCalldataParts,
|
|
4193
|
+
"weth.withdrawCalldataParts": withdrawCalldataParts
|
|
4194
|
+
});
|
|
4195
|
+
var HANDLERS = Object.freeze({
|
|
4196
|
+
...RPC_HANDLERS,
|
|
4197
|
+
...LOCAL_HANDLERS
|
|
4198
|
+
});
|
|
4199
|
+
var STABLE_PANOPTIC_METHOD_NAMES = Object.freeze(Object.keys(HANDLERS).sort());
|
|
4200
|
+
function getPanopticHandler(method) {
|
|
4201
|
+
return Object.prototype.hasOwnProperty.call(HANDLERS, method) ? HANDLERS[method] : void 0;
|
|
4202
|
+
}
|
|
4203
|
+
function getPanopticHandlerNames() {
|
|
4204
|
+
return [...STABLE_PANOPTIC_METHOD_NAMES].sort();
|
|
4205
|
+
}
|
|
4206
|
+
async function executePanopticHandler(input) {
|
|
4207
|
+
const runHandler = () => Promise.resolve(
|
|
4208
|
+
input.handler({
|
|
4209
|
+
deps: input.deps,
|
|
4210
|
+
method: input.method,
|
|
4211
|
+
request: input.request,
|
|
4212
|
+
options: input.options || {},
|
|
4213
|
+
operationOptions: input.operationOptions
|
|
4214
|
+
})
|
|
4215
|
+
);
|
|
4216
|
+
const rawResult = Object.prototype.hasOwnProperty.call(RPC_HANDLERS, input.method) ? await runPanopticOperation(`Panoptic handler ${input.method}`, runHandler, input.operationOptions) : await runHandler();
|
|
4217
|
+
const result = projectPanopticSerializableValue(rawResult, input.responseLimits, `${input.method} result`);
|
|
4218
|
+
return panopticSuccess(result);
|
|
4219
|
+
}
|
|
4220
|
+
|
|
4221
|
+
// src/internal/panopticRuntime.ts
|
|
4222
|
+
var PANOPTIC_RUNTIME_METHOD_NAMES = Object.freeze(getPanopticHandlerNames());
|
|
4223
|
+
var RENAMED_METHODS = /* @__PURE__ */ new Map([
|
|
4224
|
+
["dynamicJobs.renderRegisteredExecuteJob", "dynamicJobs.renderExecuteJob"],
|
|
4225
|
+
["hypovault.encodeFulfillDeposits", "hypovault.fulfillDepositsFragment"],
|
|
4226
|
+
["hypovault.encodeFulfillWithdrawals", "hypovault.fulfillWithdrawalsFragment"],
|
|
4227
|
+
["router.checkApproval", "uniswap.checkRouterApproval"],
|
|
4228
|
+
["panoptic.dispatchArgs", "panoptic.dispatchCalldataParts"]
|
|
4229
|
+
]);
|
|
4230
|
+
var UNSUPPORTED_PLANNED_METHODS = /* @__PURE__ */ new Map([
|
|
4231
|
+
["greeks.getAccountGreeks", "requires a serializable storage snapshot DTO"],
|
|
4232
|
+
["hypovault.resolveVaultHistoricalCandidatesByPool", "requires host-owned subgraph paging and reconciliation policy"],
|
|
4233
|
+
["merkle.encodeManageVaultWithMerkleVerification", "requires Merkle artifact provenance and nested target policy"]
|
|
4234
|
+
]);
|
|
4235
|
+
for (const method of PANOPTIC_RUNTIME_METHOD_NAMES) {
|
|
4236
|
+
if (!getPanopticHandler(method)) {
|
|
4237
|
+
throw new Error(`Panoptic stable runtime method is not backed by a handler: ${method}`);
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
async function callNodePanoptic(method, request, options = {}) {
|
|
4241
|
+
const handler = getPanopticHandler(method);
|
|
4242
|
+
if (handler) {
|
|
4243
|
+
return executePanopticHandler({
|
|
4244
|
+
method,
|
|
4245
|
+
handler,
|
|
4246
|
+
request,
|
|
4247
|
+
deps: createPanopticDependencies(),
|
|
4248
|
+
options,
|
|
4249
|
+
operationOptions: options.operation
|
|
4250
|
+
});
|
|
4251
|
+
}
|
|
4252
|
+
if (isLegacyCalldataMethod(method)) {
|
|
4253
|
+
throw new Error(
|
|
4254
|
+
`Panoptic runtime method is not part of the stable DynamicJobs RuntimeAdapter API: ${method}. Use protocol fragment namespaces instead.`
|
|
4255
|
+
);
|
|
4256
|
+
}
|
|
4257
|
+
const renamedMethod = RENAMED_METHODS.get(method);
|
|
4258
|
+
if (renamedMethod) {
|
|
4259
|
+
throw new Error(
|
|
4260
|
+
`Panoptic runtime method has been renamed for the stable DynamicJobs RuntimeAdapter API: ${method}. Use ${renamedMethod}.`
|
|
4261
|
+
);
|
|
4262
|
+
}
|
|
4263
|
+
const unsupportedReason = UNSUPPORTED_PLANNED_METHODS.get(method);
|
|
4264
|
+
if (unsupportedReason) {
|
|
4265
|
+
throw new Error(
|
|
4266
|
+
`Panoptic runtime method is not part of the stable DynamicJobs RuntimeAdapter API: ${method} (${unsupportedReason}).`
|
|
4267
|
+
);
|
|
4268
|
+
}
|
|
4269
|
+
throw new Error(`Unsupported Panoptic runtime method: ${method}`);
|
|
4270
|
+
}
|
|
4271
|
+
function createNodePanopticAdapter(options = {}) {
|
|
4272
|
+
return (method, request) => callNodePanoptic(method, request, options);
|
|
4273
|
+
}
|
|
4274
|
+
function isLegacyCalldataMethod(method) {
|
|
4275
|
+
return method.startsWith("calldata.");
|
|
4276
|
+
}
|
|
4277
|
+
|
|
718
4278
|
// src/node.ts
|
|
719
|
-
function loadWasmSync(input, imports = {}) {
|
|
4279
|
+
function loadWasmSync(input, imports = {}, options = {}) {
|
|
720
4280
|
return instantiate(new WebAssembly.Module(input), imports, {
|
|
721
4281
|
getFetch: getNodeFetch,
|
|
722
|
-
getCcxt
|
|
4282
|
+
getCcxt,
|
|
4283
|
+
callPanoptic: createNodePanopticAdapter(options.panoptic)
|
|
723
4284
|
});
|
|
724
4285
|
}
|
|
725
|
-
async function loadWasm(input, imports = {}) {
|
|
4286
|
+
async function loadWasm(input, imports = {}, options = {}) {
|
|
726
4287
|
const module = typeof input === "string" ? await compileFromString(input) : await WebAssembly.compile(input);
|
|
727
4288
|
return instantiate(module, imports, {
|
|
728
4289
|
getFetch: getNodeFetch,
|
|
729
|
-
getCcxt
|
|
4290
|
+
getCcxt,
|
|
4291
|
+
callPanoptic: createNodePanopticAdapter(options.panoptic)
|
|
730
4292
|
});
|
|
731
4293
|
}
|
|
732
4294
|
async function compileFromString(input) {
|