@panoptic-eng/sdk 1.0.60 → 1.0.62

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.
Files changed (34) hide show
  1. package/dist/{chainDeployments-CmDzAmZ3.js → chainDeployments-BhXMBZ4B.js} +50 -12
  2. package/dist/cow/index.js +1207 -484
  3. package/dist/cow/index.js.map +1 -1
  4. package/dist/{cow-CHb343la.js → cow-DTi3GjQz.js} +1 -1
  5. package/dist/deployments.d.ts +9 -1
  6. package/dist/deployments.d.ts.map +1 -1
  7. package/dist/deployments.js +50 -12
  8. package/dist/deployments.js.map +1 -1
  9. package/dist/index.d.ts +587 -75
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +577 -357
  12. package/dist/index.js.map +1 -1
  13. package/dist/{irm-BIaLQ-0n.js → irm-BDlcUNgJ.js} +2 -2
  14. package/dist/panoptic/v2/index.d.ts +169 -3
  15. package/dist/panoptic/v2/index.d.ts.map +1 -1
  16. package/dist/panoptic/v2/index.js +658 -107
  17. package/dist/panoptic/v2/index.js.map +1 -1
  18. package/dist/panoptic/v2/react-public.d.ts +177 -3
  19. package/dist/panoptic/v2/react-public.d.ts.map +1 -1
  20. package/dist/panoptic/v2/react-public.js +674 -113
  21. package/dist/panoptic/v2/react-public.js.map +1 -1
  22. package/dist/{rates-COAJpKRd.js → rates-BwZnK0tG.js} +498 -482
  23. package/dist/{router-B2fj4_X7.js → router-Y1OxL9Nt.js} +2 -2
  24. package/dist/{router-DliBF9FK.js → router-jMP7fVno.js} +2 -2
  25. package/dist/{transactionFees-CNbjAigT.js → transactionFees-aXQlx-lq.js} +11 -6
  26. package/dist/uniswap/index.js +724 -1
  27. package/dist/uniswap/index.js.map +1 -1
  28. package/dist/{v2-C3n8n1_i.js → v2-B27ILZl4.js} +518 -202
  29. package/dist/vault-transaction-fees.d.ts +1 -0
  30. package/dist/vault-transaction-fees.d.ts.map +1 -1
  31. package/dist/vault-transaction-fees.js +59 -16
  32. package/dist/vault-transaction-fees.js.map +1 -1
  33. package/dist/{writes-BTkqc_rn.js → writes-B8NGXzUG.js} +219 -38
  34. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import Decimal from "decimal.js";
2
- import { BaseError, ContractFunctionRevertedError, decodeAbiParameters, decodeEventLog, encodeAbiParameters, encodeFunctionData, encodePacked, erc20Abi, getAbiItem, isAddressEqual, keccak256, maxUint256, parseAbi, toFunctionSelector, zeroAddress } from "viem";
2
+ import { BaseError, ContractFunctionRevertedError, decodeAbiParameters, decodeErrorResult, decodeEventLog, encodeAbiParameters, encodeFunctionData, encodePacked, erc20Abi, getAbiItem, isAddressEqual, keccak256, maxUint256, parseAbi, toFunctionSelector, zeroAddress } from "viem";
3
3
 
4
4
  //#region src/uniswap/estimateLpFees.ts
5
5
  const D$1 = Decimal.clone({ precision: 60 });
@@ -230,6 +230,483 @@ var PanopticError = class extends Error {
230
230
  }
231
231
  };
232
232
 
233
+ //#endregion
234
+ //#region src/panoptic/v2/errors/contract.ts
235
+ /**
236
+ * The account is not solvent enough to perform the desired action.
237
+ * @see Errors.sol:9
238
+ */
239
+ var AccountInsolventError = class extends PanopticError {
240
+ name = "AccountInsolventError";
241
+ constructor(solvent, numberOfTicks, cause) {
242
+ super(`Account insolvent: solvent=${solvent}, numberOfTicks=${numberOfTicks}`, cause);
243
+ this.solvent = solvent;
244
+ this.numberOfTicks = numberOfTicks;
245
+ }
246
+ };
247
+ /**
248
+ * Position is still solvent and cannot be liquidated.
249
+ * @see Errors.sol:84
250
+ */
251
+ var NotMarginCalledError = class extends PanopticError {
252
+ name = "NotMarginCalledError";
253
+ constructor(cause) {
254
+ super("Position is still solvent and cannot be liquidated", cause);
255
+ }
256
+ };
257
+ /**
258
+ * The user does not own enough assets to open/close a position.
259
+ * @see Errors.sol:78
260
+ */
261
+ var NotEnoughTokensError = class extends PanopticError {
262
+ name = "NotEnoughTokensError";
263
+ constructor(tokenAddress, assetsRequested, assetBalance, cause) {
264
+ super(`Not enough tokens: requested=${assetsRequested}, balance=${assetBalance}, token=${tokenAddress}`, cause);
265
+ this.tokenAddress = tokenAddress;
266
+ this.assetsRequested = assetsRequested;
267
+ this.assetBalance = assetBalance;
268
+ }
269
+ };
270
+ /**
271
+ * There is not enough available liquidity in the chunk for a long leg.
272
+ * @see Errors.sol:75
273
+ */
274
+ var NotEnoughLiquidityInChunkError = class extends PanopticError {
275
+ name = "NotEnoughLiquidityInChunkError";
276
+ constructor(cause) {
277
+ super("Not enough liquidity in chunk for long leg creation or short leg closure", cause);
278
+ }
279
+ };
280
+ /**
281
+ * There is not enough available liquidity to fulfill a credit.
282
+ * @see Errors.sol:47
283
+ */
284
+ var InsufficientCreditLiquidityError = class extends PanopticError {
285
+ name = "InsufficientCreditLiquidityError";
286
+ constructor(cause) {
287
+ super("Insufficient credit liquidity available in the PanopticPool", cause);
288
+ }
289
+ };
290
+ /**
291
+ * The amount deposited is larger than the maximum permitted.
292
+ * @see Errors.sol:25
293
+ */
294
+ var DepositTooLargeError = class extends PanopticError {
295
+ name = "DepositTooLargeError";
296
+ constructor(cause) {
297
+ super("Deposit amount exceeds maximum permitted", cause);
298
+ }
299
+ };
300
+ /**
301
+ * Attempted to withdraw/redeem less than a single asset.
302
+ * @see Errors.sol:16
303
+ */
304
+ var BelowMinimumRedemptionError = class extends PanopticError {
305
+ name = "BelowMinimumRedemptionError";
306
+ constructor(cause) {
307
+ super("Redemption amount below minimum threshold", cause);
308
+ }
309
+ };
310
+ /**
311
+ * Attempted to withdraw/redeem more than available.
312
+ * @see Errors.sol:35
313
+ */
314
+ var ExceedsMaximumRedemptionError = class extends PanopticError {
315
+ name = "ExceedsMaximumRedemptionError";
316
+ constructor(cause) {
317
+ super("Redemption exceeds maximum available (liquidity, shares, or open positions)", cause);
318
+ }
319
+ };
320
+ /**
321
+ * Mints/burns of a position returns no collateral requirement.
322
+ * @see Errors.sol:141
323
+ */
324
+ var ZeroCollateralRequirementError = class extends PanopticError {
325
+ name = "ZeroCollateralRequirementError";
326
+ constructor(cause) {
327
+ super("Position mint/burn returned zero collateral requirement", cause);
328
+ }
329
+ };
330
+ /**
331
+ * The TokenId provided is malformed or invalid.
332
+ * @see Errors.sol:54
333
+ */
334
+ var InvalidTokenIdParameterError = class extends PanopticError {
335
+ name = "InvalidTokenIdParameterError";
336
+ /**
337
+ * Parameter type meanings:
338
+ * 0=poolId, 1=ratio, 2=tokenType, 3=riskPartner, 4=strike, 5=width, 6=duplicateChunk
339
+ */
340
+ constructor(parameterType, cause) {
341
+ const paramNames = [
342
+ "poolId",
343
+ "ratio",
344
+ "tokenType",
345
+ "riskPartner",
346
+ "strike",
347
+ "width",
348
+ "duplicateChunk"
349
+ ];
350
+ const paramName = paramNames[Number(parameterType)] ?? `unknown(${parameterType})`;
351
+ super(`Invalid TokenId parameter: ${paramName}`, cause);
352
+ this.parameterType = parameterType;
353
+ }
354
+ };
355
+ /**
356
+ * Position is not owned by the user and has positionSize=0.
357
+ * @see Errors.sol:96
358
+ */
359
+ var PositionNotOwnedError = class extends PanopticError {
360
+ name = "PositionNotOwnedError";
361
+ constructor(cause) {
362
+ super("Position is not owned by the user", cause);
363
+ }
364
+ };
365
+ /**
366
+ * The maximum token deltas for a position exceed limits.
367
+ * @see Errors.sol:99
368
+ */
369
+ var PositionTooLargeError = class extends PanopticError {
370
+ name = "PositionTooLargeError";
371
+ constructor(cause) {
372
+ super("Position size exceeds maximum allowed token deltas", cause);
373
+ }
374
+ };
375
+ /**
376
+ * User has open positions, so they cannot transfer collateral shares.
377
+ * @see Errors.sol:93
378
+ */
379
+ var PositionCountNotZeroError = class extends PanopticError {
380
+ name = "PositionCountNotZeroError";
381
+ constructor(cause) {
382
+ super("Cannot transfer collateral shares while positions are open", cause);
383
+ }
384
+ };
385
+ /**
386
+ * The list of provided TokenIds has a duplicate entry.
387
+ * @see Errors.sol:28
388
+ */
389
+ var DuplicateTokenIdError = class extends PanopticError {
390
+ name = "DuplicateTokenIdError";
391
+ constructor(cause) {
392
+ super("Duplicate TokenId in provided list", cause);
393
+ }
394
+ };
395
+ /**
396
+ * The supplied tokenId has no valid legs.
397
+ * @see Errors.sol:144
398
+ */
399
+ var TokenIdHasZeroLegsError = class extends PanopticError {
400
+ name = "TokenIdHasZeroLegsError";
401
+ constructor(cause) {
402
+ super("TokenId has no valid legs", cause);
403
+ }
404
+ };
405
+ /**
406
+ * Position would exceed maximum legs open for account.
407
+ * @see Errors.sol:112
408
+ */
409
+ var TooManyLegsOpenError = class extends PanopticError {
410
+ name = "TooManyLegsOpenError";
411
+ constructor(cause) {
412
+ super("Position would exceed maximum allowed legs open", cause);
413
+ }
414
+ };
415
+ /**
416
+ * The provided list of option positions is incorrect or invalid.
417
+ * @see Errors.sol:38
418
+ */
419
+ var InputListFailError = class extends PanopticError {
420
+ name = "InputListFailError";
421
+ constructor(cause) {
422
+ super("Invalid position list provided", cause);
423
+ }
424
+ };
425
+ /**
426
+ * Tick is not between MIN_TICK and MAX_TICK.
427
+ * @see Errors.sol:41
428
+ */
429
+ var InvalidTickError = class extends PanopticError {
430
+ name = "InvalidTickError";
431
+ constructor(cause) {
432
+ super("Tick is outside valid range (MIN_TICK to MAX_TICK)", cause);
433
+ }
434
+ };
435
+ /**
436
+ * The tick range is invalid (not initializable or exceeds bounds).
437
+ * @see Errors.sol:120
438
+ */
439
+ var InvalidTickBoundError = class extends PanopticError {
440
+ name = "InvalidTickBoundError";
441
+ constructor(cause) {
442
+ super("Tick range is invalid (not initializable multiples of tickSpacing or exceeds bounds)", cause);
443
+ }
444
+ };
445
+ /**
446
+ * The current tick has fallen outside the slippage range.
447
+ * @see Errors.sol:102
448
+ */
449
+ var PriceBoundFailError = class extends PanopticError {
450
+ name = "PriceBoundFailError";
451
+ constructor(currentTick, cause) {
452
+ super(`Price moved outside slippage bounds (currentTick=${currentTick})`, cause);
453
+ this.currentTick = currentTick;
454
+ }
455
+ };
456
+ /**
457
+ * The price impact of the trade is too large.
458
+ * @see Errors.sol:105
459
+ */
460
+ var PriceImpactTooLargeError = class extends PanopticError {
461
+ name = "PriceImpactTooLargeError";
462
+ constructor(cause) {
463
+ super("Price impact of trade exceeds maximum allowed", cause);
464
+ }
465
+ };
466
+ /**
467
+ * Mints/burns of zero-liquidity chunks are not supported.
468
+ * @see Errors.sol:19
469
+ */
470
+ var ChunkHasZeroLiquidityError = class extends PanopticError {
471
+ name = "ChunkHasZeroLiquidityError";
472
+ constructor(cause) {
473
+ super("Cannot mint/burn chunk with zero liquidity", cause);
474
+ }
475
+ };
476
+ /**
477
+ * Liquidity in a chunk is above 2^128.
478
+ * @see Errors.sol:44
479
+ */
480
+ var LiquidityTooHighError = class extends PanopticError {
481
+ name = "LiquidityTooHighError";
482
+ constructor(cause) {
483
+ super("Liquidity exceeds maximum (2^128)", cause);
484
+ }
485
+ };
486
+ /**
487
+ * Net liquidity is zero due to small positions.
488
+ * @see Errors.sol:63
489
+ */
490
+ var NetLiquidityZeroError = class extends PanopticError {
491
+ name = "NetLiquidityZeroError";
492
+ constructor(cause) {
493
+ super("Net liquidity is zero, cannot compute liquidity spread", cause);
494
+ }
495
+ };
496
+ /**
497
+ * Effective liquidity above threshold during long mint or short burn.
498
+ * @see Errors.sol:32
499
+ */
500
+ var EffectiveLiquidityAboveThresholdError = class extends PanopticError {
501
+ name = "EffectiveLiquidityAboveThresholdError";
502
+ constructor(cause) {
503
+ super("Effective liquidity above spread threshold", cause);
504
+ }
505
+ };
506
+ /**
507
+ * An oracle price is too far from another or the current tick.
508
+ * @see Errors.sol:109
509
+ */
510
+ var StaleOracleError = class extends PanopticError {
511
+ name = "StaleOracleError";
512
+ constructor(cause) {
513
+ super("Oracle price deviation too high (potential manipulation safeguard)", cause);
514
+ }
515
+ };
516
+ /**
517
+ * None of the legs in a position are force-exercisable.
518
+ * @see Errors.sol:66
519
+ */
520
+ var NoLegsExercisableError = class extends PanopticError {
521
+ name = "NoLegsExercisableError";
522
+ constructor(cause) {
523
+ super("No legs are force-exercisable (all are short or ATM long)", cause);
524
+ }
525
+ };
526
+ /**
527
+ * The leg is not long, so premium cannot be settled.
528
+ * @see Errors.sol:69
529
+ */
530
+ var NotALongLegError = class extends PanopticError {
531
+ name = "NotALongLegError";
532
+ constructor(cause) {
533
+ super("Cannot settle premium for non-long leg", cause);
534
+ }
535
+ };
536
+ /**
537
+ * The Uniswap Pool has not been created.
538
+ * @see Errors.sol:90
539
+ */
540
+ var PoolNotInitializedError = class extends PanopticError {
541
+ name = "PoolNotInitializedError";
542
+ constructor(cause) {
543
+ super("Uniswap pool not initialized", cause);
544
+ }
545
+ };
546
+ /**
547
+ * Smart contract has already been initialized.
548
+ * @see Errors.sol:22
549
+ */
550
+ var AlreadyInitializedError = class extends PanopticError {
551
+ name = "AlreadyInitializedError";
552
+ constructor(cause) {
553
+ super("Contract already initialized", cause);
554
+ }
555
+ };
556
+ /**
557
+ * The supplied poolId does not match the poolId for that Uniswap Pool.
558
+ * @see Errors.sol:132
559
+ */
560
+ var WrongPoolIdError = class extends PanopticError {
561
+ name = "WrongPoolIdError";
562
+ constructor(cause) {
563
+ super("Pool ID mismatch", cause);
564
+ }
565
+ };
566
+ /**
567
+ * The poolId's don't match (SFPM).
568
+ * @see Errors.sol:135
569
+ */
570
+ var WrongUniswapPoolError = class extends PanopticError {
571
+ name = "WrongUniswapPoolError";
572
+ constructor(cause) {
573
+ super("Uniswap pool mismatch", cause);
574
+ }
575
+ };
576
+ /**
577
+ * The caller is not the Panoptic Pool.
578
+ * @see Errors.sol:87
579
+ */
580
+ var NotPanopticPoolError = class extends PanopticError {
581
+ name = "NotPanopticPoolError";
582
+ constructor(cause) {
583
+ super("Caller is not the Panoptic Pool", cause);
584
+ }
585
+ };
586
+ /**
587
+ * Can only be called by the guardian.
588
+ * @see Errors.sol:81
589
+ */
590
+ var NotGuardianError = class extends PanopticError {
591
+ name = "NotGuardianError";
592
+ constructor(cause) {
593
+ super("Caller is not the guardian", cause);
594
+ }
595
+ };
596
+ /**
597
+ * Can only be called by the Builder.
598
+ * @see Errors.sol:72
599
+ */
600
+ var NotBuilderError = class extends PanopticError {
601
+ name = "NotBuilderError";
602
+ constructor(cause) {
603
+ super("Caller is not the builder", cause);
604
+ }
605
+ };
606
+ /**
607
+ * Invalid builder code.
608
+ * @see Errors.sol:50
609
+ */
610
+ var InvalidBuilderCodeError = class extends PanopticError {
611
+ name = "InvalidBuilderCodeError";
612
+ constructor(cause) {
613
+ super("Invalid builder code", cause);
614
+ }
615
+ };
616
+ /**
617
+ * Mint or swap callback from invalid address.
618
+ * @see Errors.sol:57
619
+ */
620
+ var InvalidUniswapCallbackError = class extends PanopticError {
621
+ name = "InvalidUniswapCallbackError";
622
+ constructor(cause) {
623
+ super("Invalid Uniswap callback (address mismatch)", cause);
624
+ }
625
+ };
626
+ /**
627
+ * Unlock callback from non-canonical pool manager.
628
+ * @see Errors.sol:123
629
+ */
630
+ var UnauthorizedUniswapCallbackError = class extends PanopticError {
631
+ name = "UnauthorizedUniswapCallbackError";
632
+ constructor(cause) {
633
+ super("Unauthorized Uniswap V4 callback", cause);
634
+ }
635
+ };
636
+ /**
637
+ * ERC20 or SFPM (ERC1155) token transfer did not complete successfully.
638
+ * @see Errors.sol:115
639
+ */
640
+ var TransferFailedError = class extends PanopticError {
641
+ name = "TransferFailedError";
642
+ constructor(token, from, amount, balance, cause) {
643
+ super(`Transfer failed: token=${token}, from=${from}, amount=${amount}, balance=${balance}`, cause);
644
+ this.token = token;
645
+ this.from = from;
646
+ this.amount = amount;
647
+ this.balance = balance;
648
+ }
649
+ };
650
+ /**
651
+ * Casting error (e.g., uint128(uint256(a)) fails).
652
+ * @see Errors.sol:13
653
+ */
654
+ var CastingError = class extends PanopticError {
655
+ name = "CastingError";
656
+ constructor(cause) {
657
+ super("Numeric casting overflow", cause);
658
+ }
659
+ };
660
+ /**
661
+ * Underflow or overflow in library operation.
662
+ * @see Errors.sol:126
663
+ */
664
+ var UnderOverFlowError = class extends PanopticError {
665
+ name = "UnderOverFlowError";
666
+ constructor(cause) {
667
+ super("Arithmetic underflow or overflow", cause);
668
+ }
669
+ };
670
+ /**
671
+ * Reentrancy check triggered.
672
+ * @see Errors.sol:129
673
+ */
674
+ var ReentrancyError = class extends PanopticError {
675
+ name = "ReentrancyError";
676
+ constructor(cause) {
677
+ super("Reentrancy detected", cause);
678
+ }
679
+ };
680
+ /**
681
+ * Pool deployment via CREATE2 failed.
682
+ */
683
+ var CreateFailError = class extends PanopticError {
684
+ name = "CreateFailError";
685
+ constructor(cause) {
686
+ super("Pool deployment failed (CREATE2)", cause);
687
+ }
688
+ };
689
+ /**
690
+ * Zero address was supplied as a parameter.
691
+ * @see Errors.sol:138
692
+ */
693
+ var ZeroAddressError = class extends PanopticError {
694
+ name = "ZeroAddressError";
695
+ constructor(cause) {
696
+ super("Zero address supplied", cause);
697
+ }
698
+ };
699
+ /**
700
+ * Length mismatch between positionIdList and positionBalanceArray.
701
+ * @see Errors.sol:60
702
+ */
703
+ var LengthMismatchError = class extends PanopticError {
704
+ name = "LengthMismatchError";
705
+ constructor(cause) {
706
+ super("Array length mismatch", cause);
707
+ }
708
+ };
709
+
233
710
  //#endregion
234
711
  //#region src/generated.ts
235
712
  const collateralTrackerV2Abi = [
@@ -3606,6 +4083,241 @@ const combinedAbi = [
3606
4083
  ...riskEngineAbi,
3607
4084
  ...panopticErrorsAbi
3608
4085
  ];
4086
+ /**
4087
+ * Map of error names to error constructors.
4088
+ */
4089
+ const errorConstructors = {
4090
+ AccountInsolvent: (args, cause) => new AccountInsolventError(args[0], args[1], cause),
4091
+ NotMarginCalled: (_args, cause) => new NotMarginCalledError(cause),
4092
+ CreateFail: (_args, cause) => new CreateFailError(cause),
4093
+ NotEnoughTokens: (args, cause) => new NotEnoughTokensError(args[0], args[1], args[2], cause),
4094
+ NotEnoughLiquidityInChunk: (_args, cause) => new NotEnoughLiquidityInChunkError(cause),
4095
+ InsufficientCreditLiquidity: (_args, cause) => new InsufficientCreditLiquidityError(cause),
4096
+ DepositTooLarge: (_args, cause) => new DepositTooLargeError(cause),
4097
+ BelowMinimumRedemption: (_args, cause) => new BelowMinimumRedemptionError(cause),
4098
+ ExceedsMaximumRedemption: (_args, cause) => new ExceedsMaximumRedemptionError(cause),
4099
+ ZeroCollateralRequirement: (_args, cause) => new ZeroCollateralRequirementError(cause),
4100
+ InvalidTokenIdParameter: (args, cause) => new InvalidTokenIdParameterError(args[0], cause),
4101
+ PositionNotOwned: (_args, cause) => new PositionNotOwnedError(cause),
4102
+ PositionTooLarge: (_args, cause) => new PositionTooLargeError(cause),
4103
+ PositionCountNotZero: (_args, cause) => new PositionCountNotZeroError(cause),
4104
+ DuplicateTokenId: (_args, cause) => new DuplicateTokenIdError(cause),
4105
+ TokenIdHasZeroLegs: (_args, cause) => new TokenIdHasZeroLegsError(cause),
4106
+ TooManyLegsOpen: (_args, cause) => new TooManyLegsOpenError(cause),
4107
+ InputListFail: (_args, cause) => new InputListFailError(cause),
4108
+ InvalidTick: (_args, cause) => new InvalidTickError(cause),
4109
+ InvalidTickBound: (_args, cause) => new InvalidTickBoundError(cause),
4110
+ PriceBoundFail: (args, cause) => new PriceBoundFailError(args[0], cause),
4111
+ PriceImpactTooLarge: (_args, cause) => new PriceImpactTooLargeError(cause),
4112
+ ChunkHasZeroLiquidity: (_args, cause) => new ChunkHasZeroLiquidityError(cause),
4113
+ LiquidityTooHigh: (_args, cause) => new LiquidityTooHighError(cause),
4114
+ NetLiquidityZero: (_args, cause) => new NetLiquidityZeroError(cause),
4115
+ EffectiveLiquidityAboveThreshold: (_args, cause) => new EffectiveLiquidityAboveThresholdError(cause),
4116
+ StaleOracle: (_args, cause) => new StaleOracleError(cause),
4117
+ NoLegsExercisable: (_args, cause) => new NoLegsExercisableError(cause),
4118
+ NotALongLeg: (_args, cause) => new NotALongLegError(cause),
4119
+ PoolNotInitialized: (_args, cause) => new PoolNotInitializedError(cause),
4120
+ AlreadyInitialized: (_args, cause) => new AlreadyInitializedError(cause),
4121
+ WrongPoolId: (_args, cause) => new WrongPoolIdError(cause),
4122
+ WrongUniswapPool: (_args, cause) => new WrongUniswapPoolError(cause),
4123
+ NotPanopticPool: (_args, cause) => new NotPanopticPoolError(cause),
4124
+ NotGuardian: (_args, cause) => new NotGuardianError(cause),
4125
+ NotBuilder: (_args, cause) => new NotBuilderError(cause),
4126
+ InvalidBuilderCode: (_args, cause) => new InvalidBuilderCodeError(cause),
4127
+ InvalidUniswapCallback: (_args, cause) => new InvalidUniswapCallbackError(cause),
4128
+ UnauthorizedUniswapCallback: (_args, cause) => new UnauthorizedUniswapCallbackError(cause),
4129
+ TransferFailed: (args, cause) => new TransferFailedError(args[0], args[1], args[2], args[3], cause),
4130
+ CastingError: (_args, cause) => new CastingError(cause),
4131
+ UnderOverFlow: (_args, cause) => new UnderOverFlowError(cause),
4132
+ Reentrancy: (_args, cause) => new ReentrancyError(cause),
4133
+ ZeroAddress: (_args, cause) => new ZeroAddressError(cause),
4134
+ LengthMismatch: (_args, cause) => new LengthMismatchError(cause)
4135
+ };
4136
+ /**
4137
+ * Parse a raw contract error into a typed SDK error.
4138
+ *
4139
+ * This function attempts to decode the error data from a failed contract call
4140
+ * and return a typed error instance with extracted parameters.
4141
+ *
4142
+ * @param error - The raw error from a failed contract call
4143
+ * @returns Parsed error with typed error instance, or null if parsing fails
4144
+ *
4145
+ * @example
4146
+ * ```typescript
4147
+ * try {
4148
+ * await contract.openPosition(...)
4149
+ * } catch (rawError) {
4150
+ * const parsed = parsePanopticError(rawError)
4151
+ * if (parsed) {
4152
+ * console.log('Error:', parsed.errorName)
4153
+ * if (parsed.error instanceof AccountInsolventError) {
4154
+ * console.log('Solvent value:', parsed.error.solvent)
4155
+ * }
4156
+ * }
4157
+ * }
4158
+ * ```
4159
+ */
4160
+ function parsePanopticError(error) {
4161
+ const viemDecoded = extractViemDecodedError(error);
4162
+ if (viemDecoded) return buildParsedError(viemDecoded.errorName, viemDecoded.args, error);
4163
+ const errorData = extractErrorData(error);
4164
+ if (!errorData) return null;
4165
+ try {
4166
+ const decoded = decodeErrorResult({
4167
+ abi: combinedAbi,
4168
+ data: errorData
4169
+ });
4170
+ return buildParsedError(decoded.errorName, decoded.args ?? [], error);
4171
+ } catch {
4172
+ if (errorData.length >= 10) {
4173
+ const selector = errorData.slice(0, 10);
4174
+ const match = matchSelectorToErrorName(selector);
4175
+ if (match) return buildParsedError(match, [], error);
4176
+ }
4177
+ return null;
4178
+ }
4179
+ }
4180
+ /**
4181
+ * Walk the cause chain looking for a viem ContractFunctionRevertedError
4182
+ * that already has decoded `.data` (an object with `errorName` and `args`).
4183
+ * This happens when the ABI passed to simulateContract includes the error definitions.
4184
+ */
4185
+ function extractViemDecodedError(error) {
4186
+ if (!error || typeof error !== "object") return null;
4187
+ if (error instanceof BaseError) {
4188
+ let found = null;
4189
+ error.walk((e) => {
4190
+ if (found) return false;
4191
+ const node = e;
4192
+ if (node.data && typeof node.data === "object" && "errorName" in node.data && typeof node.data.errorName === "string") {
4193
+ const data = node.data;
4194
+ found = {
4195
+ errorName: data.errorName,
4196
+ args: data.args ?? []
4197
+ };
4198
+ return true;
4199
+ }
4200
+ return false;
4201
+ });
4202
+ return found;
4203
+ }
4204
+ let current = error;
4205
+ for (let i = 0; i < 10 && current; i++) {
4206
+ if (current.data && typeof current.data === "object" && "errorName" in current.data && typeof current.data.errorName === "string") {
4207
+ const data = current.data;
4208
+ return {
4209
+ errorName: data.errorName,
4210
+ args: data.args ?? []
4211
+ };
4212
+ }
4213
+ current = current.cause && typeof current.cause === "object" ? current.cause : null;
4214
+ }
4215
+ return null;
4216
+ }
4217
+ /**
4218
+ * Build a ParsedError from a decoded error name and args.
4219
+ */
4220
+ function buildParsedError(errorName, args, originalError) {
4221
+ const constructor = errorConstructors[errorName];
4222
+ const cause = originalError instanceof Error ? originalError : void 0;
4223
+ if (!constructor) {
4224
+ const unknownError = new PanopticError(`Unknown contract error: ${errorName}`);
4225
+ unknownError.errorName = errorName;
4226
+ return {
4227
+ error: unknownError,
4228
+ errorName,
4229
+ args
4230
+ };
4231
+ }
4232
+ const typedError = constructor(args, cause);
4233
+ typedError.errorName = errorName;
4234
+ return {
4235
+ error: typedError,
4236
+ errorName,
4237
+ args
4238
+ };
4239
+ }
4240
+ /**
4241
+ * Match a 4-byte selector against the panoptic errors ABI.
4242
+ * Used as fallback when we only have the selector (no encoded args).
4243
+ */
4244
+ function matchSelectorToErrorName(selector) {
4245
+ for (const item of panopticErrorsAbi) {
4246
+ if (item.type !== "error") continue;
4247
+ const computed = toFunctionSelector(`${item.name}(${item.inputs.map((i) => i.type).join(",")})`);
4248
+ if (computed === selector) return item.name;
4249
+ }
4250
+ return null;
4251
+ }
4252
+ /**
4253
+ * Extract error data from various error formats.
4254
+ *
4255
+ * Strategy:
4256
+ * 1. Use viem's BaseError.walk() to traverse the full cause chain and find
4257
+ * hex data on any node (handles arbitrary nesting depth for multicall etc.)
4258
+ * 2. Fall back to manual cause-chain walk for non-viem errors
4259
+ * 3. Last resort: extract selector from error message (loses args)
4260
+ */
4261
+ function extractErrorData(error) {
4262
+ if (!error) return null;
4263
+ if (typeof error === "string" && error.startsWith("0x")) return error;
4264
+ if (typeof error !== "object") return null;
4265
+ if (error instanceof BaseError) {
4266
+ let foundData = null;
4267
+ error.walk((e) => {
4268
+ if (foundData) return false;
4269
+ const node = e;
4270
+ if (typeof node.raw === "string" && node.raw.startsWith("0x") && node.raw.length > 10) {
4271
+ foundData = node.raw;
4272
+ return true;
4273
+ }
4274
+ if (node.data && typeof node.data === "string" && node.data.startsWith("0x")) {
4275
+ foundData = node.data;
4276
+ return true;
4277
+ }
4278
+ if (node.data && typeof node.data === "object") {
4279
+ const nested = node.data;
4280
+ if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) {
4281
+ foundData = nested.data;
4282
+ return true;
4283
+ }
4284
+ }
4285
+ return false;
4286
+ });
4287
+ if (foundData) return foundData;
4288
+ error.walk((e) => {
4289
+ if (foundData) return false;
4290
+ const node = e;
4291
+ if (node.signature && typeof node.signature === "string" && node.signature.startsWith("0x")) {
4292
+ foundData = node.signature;
4293
+ return true;
4294
+ }
4295
+ return false;
4296
+ });
4297
+ if (foundData) return foundData;
4298
+ }
4299
+ let current = error;
4300
+ const maxDepth = 10;
4301
+ for (let i = 0; i < maxDepth && current; i++) {
4302
+ if (typeof current.raw === "string" && current.raw.startsWith("0x") && current.raw.length > 10) return current.raw;
4303
+ if (current.data && typeof current.data === "string" && current.data.startsWith("0x")) return current.data;
4304
+ if (current.data && typeof current.data === "object") {
4305
+ const nested = current.data;
4306
+ if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) return nested.data;
4307
+ }
4308
+ if (current.error && typeof current.error === "object") {
4309
+ const rpcError = current.error;
4310
+ if (rpcError.data && typeof rpcError.data === "string" && rpcError.data.startsWith("0x")) return rpcError.data;
4311
+ }
4312
+ current = current.cause && typeof current.cause === "object" ? current.cause : null;
4313
+ }
4314
+ const obj = error;
4315
+ if (obj.message && typeof obj.message === "string") {
4316
+ const signatureMatch = obj.message.match(/signature:?\s*["']?(0x[a-fA-F0-9]{8,})/i);
4317
+ if (signatureMatch) return signatureMatch[1];
4318
+ }
4319
+ return null;
4320
+ }
3609
4321
 
3610
4322
  //#endregion
3611
4323
  //#region src/panoptic/v2/tokenId/constants.ts
@@ -5625,6 +6337,17 @@ function createTxResult(client, hash) {
5625
6337
  * @returns TxResult
5626
6338
  */
5627
6339
  async function submitWrite(params) {
6340
+ try {
6341
+ return await submitWriteRequest({
6342
+ ...params,
6343
+ abi: [...params.abi, ...panopticErrorsAbi]
6344
+ });
6345
+ } catch (error) {
6346
+ if (error instanceof PanopticError) throw error;
6347
+ throw parsePanopticError(error)?.error ?? error;
6348
+ }
6349
+ }
6350
+ async function submitWriteRequest(params) {
5628
6351
  const { client, walletClient, account, address, abi, functionName, args, value, txOverrides } = params;
5629
6352
  const broadcaster = txOverrides?.broadcaster;
5630
6353
  if (broadcaster) {