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