@panoptic-eng/sdk 1.0.59 → 1.0.61

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.
@@ -7606,359 +7606,85 @@ async function getBlockMeta(params) {
7606
7606
  }
7607
7607
 
7608
7608
  //#endregion
7609
- //#region src/panoptic/v2/writes/utils.ts
7609
+ //#region src/panoptic/v2/errors/base.ts
7610
7610
  /**
7611
- * Decode PositionBalance packed data.
7611
+ * Base error class for the Panoptic v2 SDK.
7612
+ * @module v2/errors/base
7613
+ */
7614
+ /**
7615
+ * Base error class for all Panoptic SDK errors.
7616
+ * All errors thrown by the SDK extend this class.
7612
7617
  *
7613
- * Layout (from LSB to MSB):
7614
- * - positionSize: bits 0-127 (uint128)
7615
- * - poolUtilization0: bits 128-143 (uint16)
7616
- * - poolUtilization1: bits 144-159 (uint16)
7617
- * - tickAtMint: bits 160-183 (int24)
7618
- * - timestampAtMint: bits 184-215 (uint32)
7619
- * - blockAtMint: bits 216-254 (uint39)
7620
- * - swapAtMint: bit 255 (bool)
7618
+ * @example
7619
+ * ```typescript
7620
+ * try {
7621
+ * await openPosition(config, params)
7622
+ * } catch (error) {
7623
+ * if (error instanceof PanopticError) {
7624
+ * console.log('Panoptic error:', error.name, error.message)
7625
+ * console.log('Original cause:', error.cause)
7626
+ * }
7627
+ * }
7628
+ * ```
7621
7629
  */
7622
- function decodePositionBalance$1(balanceData) {
7623
- const positionSize = balanceData & (1n << 128n) - 1n;
7624
- const poolUtilization0 = balanceData >> 128n & 0xffffn;
7625
- const poolUtilization1 = balanceData >> 144n & 0xffffn;
7626
- let tickAtMint = balanceData >> 160n & 0xffffffn;
7627
- if (tickAtMint > 0x7fffffn) tickAtMint = tickAtMint - 0x1000000n;
7628
- const timestampAtMint = balanceData >> 184n & 0xffffffffn;
7629
- const blockAtMint = balanceData >> 216n & (1n << 39n) - 1n;
7630
- const swapAtMint = balanceData >> 255n === 1n;
7631
- return {
7632
- positionSize,
7633
- poolUtilization0,
7634
- poolUtilization1,
7635
- tickAtMint,
7636
- timestampAtMint,
7637
- blockAtMint,
7638
- swapAtMint
7639
- };
7640
- }
7630
+ var PanopticError = class extends Error {
7631
+ name = "PanopticError";
7632
+ /** The Solidity error name (e.g. 'PriceBoundFail', 'InputListFail'). Set by the parser. */
7633
+ errorName;
7634
+ /**
7635
+ * Creates a new PanopticError.
7636
+ *
7637
+ * @param message - Human-readable error message
7638
+ * @param cause - Optional underlying error that caused this error
7639
+ */
7640
+ constructor(message, cause) {
7641
+ super(message);
7642
+ this.cause = cause;
7643
+ if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
7644
+ Object.setPrototypeOf(this, new.target.prototype);
7645
+ }
7646
+ };
7647
+
7648
+ //#endregion
7649
+ //#region src/panoptic/v2/errors/contract.ts
7641
7650
  /**
7642
- * Decode LeftRightSigned packed value.
7651
+ * The account is not solvent enough to perform the desired action.
7652
+ * @see Errors.sol:9
7643
7653
  */
7644
- function decodeLeftRightSigned(value) {
7645
- let right = value & (1n << 128n) - 1n;
7646
- let left = value >> 128n;
7647
- if (right >= 1n << 127n) right = right - (1n << 128n);
7648
- if (left >= 1n << 127n) left = left - (1n << 128n);
7649
- return {
7650
- right,
7651
- left
7652
- };
7653
- }
7654
+ var AccountInsolventError = class extends PanopticError {
7655
+ name = "AccountInsolventError";
7656
+ constructor(solvent, numberOfTicks, cause) {
7657
+ super(`Account insolvent: solvent=${solvent}, numberOfTicks=${numberOfTicks}`, cause);
7658
+ this.solvent = solvent;
7659
+ this.numberOfTicks = numberOfTicks;
7660
+ }
7661
+ };
7654
7662
  /**
7655
- * Decode LeftRightUnsigned packed value.
7663
+ * Position is still solvent and cannot be liquidated.
7664
+ * @see Errors.sol:84
7656
7665
  */
7657
- function decodeLeftRightUnsigned(value) {
7658
- const right = value & (1n << 128n) - 1n;
7659
- const left = value >> 128n;
7660
- return {
7661
- right,
7662
- left
7663
- };
7664
- }
7666
+ var NotMarginCalledError = class extends PanopticError {
7667
+ name = "NotMarginCalledError";
7668
+ constructor(cause) {
7669
+ super("Position is still solvent and cannot be liquidated", cause);
7670
+ }
7671
+ };
7665
7672
  /**
7666
- * Parse Panoptic events from transaction logs.
7667
- *
7668
- * @param logs - The transaction logs
7669
- * @returns Parsed Panoptic events
7673
+ * The user does not own enough assets to open/close a position.
7674
+ * @see Errors.sol:78
7670
7675
  */
7671
- function parsePanopticEvents(logs) {
7672
- const events = [];
7673
- for (const log of logs) {
7674
- const baseEvent = {
7675
- blockNumber: log.blockNumber ?? 0n,
7676
- blockHash: log.blockHash ?? "0x0000000000000000000000000000000000000000000000000000000000000000",
7677
- transactionHash: log.transactionHash ?? "0x",
7678
- logIndex: BigInt(log.logIndex ?? 0)
7679
- };
7680
- try {
7681
- const poolEvent = decodeEventLog({
7682
- abi: panopticPoolV2Abi,
7683
- data: log.data,
7684
- topics: log.topics
7685
- });
7686
- if (poolEvent.eventName === "OptionMinted") {
7687
- const args = poolEvent.args;
7688
- const balance = decodePositionBalance$1(args.balanceData);
7689
- events.push({
7690
- type: "OptionMinted",
7691
- ...baseEvent,
7692
- recipient: args.recipient,
7693
- tokenId: args.tokenId,
7694
- positionSize: balance.positionSize,
7695
- poolUtilization0: balance.poolUtilization0,
7696
- poolUtilization1: balance.poolUtilization1,
7697
- tickAtMint: balance.tickAtMint,
7698
- timestampAtMint: balance.timestampAtMint,
7699
- blockAtMint: balance.blockAtMint,
7700
- swapAtMint: balance.swapAtMint
7701
- });
7702
- } else if (poolEvent.eventName === "OptionBurnt") {
7703
- const args = poolEvent.args;
7704
- events.push({
7705
- type: "OptionBurnt",
7706
- ...baseEvent,
7707
- recipient: args.recipient,
7708
- tokenId: args.tokenId,
7709
- positionSize: args.positionSize,
7710
- premiaByLeg: [
7711
- args.premiaByLeg[0] ?? 0n,
7712
- args.premiaByLeg[1] ?? 0n,
7713
- args.premiaByLeg[2] ?? 0n,
7714
- args.premiaByLeg[3] ?? 0n
7715
- ]
7716
- });
7717
- } else if (poolEvent.eventName === "AccountLiquidated") {
7718
- const args = poolEvent.args;
7719
- const { right, left } = decodeLeftRightSigned(args.bonusAmounts);
7720
- events.push({
7721
- type: "AccountLiquidated",
7722
- ...baseEvent,
7723
- liquidator: args.liquidator,
7724
- liquidatee: args.liquidatee,
7725
- bonusAmount0: right,
7726
- bonusAmount1: left
7727
- });
7728
- } else if (poolEvent.eventName === "ForcedExercised") {
7729
- const args = poolEvent.args;
7730
- const { right, left } = decodeLeftRightSigned(args.exerciseFee);
7731
- events.push({
7732
- type: "ForcedExercised",
7733
- ...baseEvent,
7734
- exercisor: args.exercisor,
7735
- user: args.user,
7736
- tokenId: args.tokenId,
7737
- exerciseFee0: right,
7738
- exerciseFee1: left
7739
- });
7740
- } else if (poolEvent.eventName === "PremiumSettled") {
7741
- const args = poolEvent.args;
7742
- const { right, left } = decodeLeftRightSigned(args.settledAmounts);
7743
- events.push({
7744
- type: "PremiumSettled",
7745
- ...baseEvent,
7746
- user: args.user,
7747
- tokenId: args.tokenId,
7748
- legIndex: args.legIndex,
7749
- settledAmount0: right,
7750
- settledAmount1: left
7751
- });
7752
- }
7753
- } catch {
7754
- try {
7755
- const collateralEvent = decodeEventLog({
7756
- abi: collateralTrackerV2Abi,
7757
- data: log.data,
7758
- topics: log.topics
7759
- });
7760
- if (collateralEvent.eventName === "Deposit") {
7761
- const args = collateralEvent.args;
7762
- events.push({
7763
- type: "Deposit",
7764
- ...baseEvent,
7765
- sender: args.sender,
7766
- owner: args.owner,
7767
- assets: args.assets,
7768
- shares: args.shares
7769
- });
7770
- } else if (collateralEvent.eventName === "Withdraw") {
7771
- const args = collateralEvent.args;
7772
- events.push({
7773
- type: "Withdraw",
7774
- ...baseEvent,
7775
- sender: args.sender,
7776
- receiver: args.receiver,
7777
- owner: args.owner,
7778
- assets: args.assets,
7779
- shares: args.shares
7780
- });
7781
- }
7782
- } catch {}
7783
- }
7676
+ var NotEnoughTokensError = class extends PanopticError {
7677
+ name = "NotEnoughTokensError";
7678
+ constructor(tokenAddress, assetsRequested, assetBalance, cause) {
7679
+ super(`Not enough tokens: requested=${assetsRequested}, balance=${assetBalance}, token=${tokenAddress}`, cause);
7680
+ this.tokenAddress = tokenAddress;
7681
+ this.assetsRequested = assetsRequested;
7682
+ this.assetBalance = assetBalance;
7784
7683
  }
7785
- return events;
7786
- }
7684
+ };
7787
7685
  /**
7788
- * Create a TxResult from a transaction hash.
7789
- *
7790
- * @param client - The public client
7791
- * @param hash - The transaction hash
7792
- * @returns TxResult with wait function
7793
- */
7794
- function createTxResult(client, hash) {
7795
- return {
7796
- hash,
7797
- wait: async (confirmations) => {
7798
- const receipt = await client.waitForTransactionReceipt({
7799
- hash,
7800
- confirmations: confirmations !== void 0 ? Number(confirmations) : void 0
7801
- });
7802
- const events = parsePanopticEvents(receipt.logs);
7803
- return {
7804
- hash: receipt.transactionHash,
7805
- blockNumber: receipt.blockNumber,
7806
- blockHash: receipt.blockHash,
7807
- gasUsed: receipt.gasUsed,
7808
- status: receipt.status === "success" ? "success" : "reverted",
7809
- events
7810
- };
7811
- }
7812
- };
7813
- }
7814
- /**
7815
- * Submit a write operation, supporting both direct wallet submission
7816
- * and custom broadcaster paths with gas overrides.
7817
- *
7818
- * Normal path (no broadcaster): calls walletClient.writeContract() with gas overrides.
7819
- * Broadcaster path: prepareTransactionRequest → apply overrides → signTransaction → broadcast.
7820
- *
7821
- * @param params - Submit write parameters
7822
- * @returns TxResult
7823
- */
7824
- async function submitWrite(params) {
7825
- const { client, walletClient, account, address, abi, functionName, args, value, txOverrides } = params;
7826
- const broadcaster = txOverrides?.broadcaster;
7827
- if (broadcaster) {
7828
- const data = encodeFunctionData({
7829
- abi,
7830
- functionName,
7831
- args
7832
- });
7833
- const broadcastAccount = walletClient.account ?? account;
7834
- const request = await walletClient.prepareTransactionRequest({
7835
- account: broadcastAccount,
7836
- to: address,
7837
- chain: walletClient.chain,
7838
- data,
7839
- ...value !== void 0 && { value },
7840
- ...txOverrides?.maxFeePerGas !== void 0 && { maxFeePerGas: txOverrides.maxFeePerGas },
7841
- ...txOverrides?.maxPriorityFeePerGas !== void 0 && { maxPriorityFeePerGas: txOverrides.maxPriorityFeePerGas },
7842
- ...txOverrides?.gas !== void 0 && { gas: txOverrides.gas },
7843
- ...txOverrides?.nonce !== void 0 && { nonce: Number(txOverrides.nonce) }
7844
- });
7845
- const signedTx = await walletClient.signTransaction({
7846
- ...request,
7847
- account: broadcastAccount
7848
- });
7849
- const hash$1 = await broadcaster.broadcast(signedTx);
7850
- return createTxResult(client, hash$1);
7851
- }
7852
- const gasOverrides = {};
7853
- if (txOverrides?.maxFeePerGas !== void 0) gasOverrides.maxFeePerGas = txOverrides.maxFeePerGas;
7854
- if (txOverrides?.maxPriorityFeePerGas !== void 0) gasOverrides.maxPriorityFeePerGas = txOverrides.maxPriorityFeePerGas;
7855
- if (txOverrides?.nonce !== void 0) gasOverrides.nonce = Number(txOverrides.nonce);
7856
- const resolvedAccount = walletClient.account ?? account;
7857
- if (txOverrides?.gas !== void 0) gasOverrides.gas = txOverrides.gas;
7858
- else {
7859
- const estimated = await client.estimateContractGas({
7860
- address,
7861
- abi,
7862
- functionName,
7863
- args,
7864
- account: resolvedAccount,
7865
- ...value !== void 0 && { value }
7866
- });
7867
- gasOverrides.gas = estimated * 120n / 100n;
7868
- }
7869
- const hash = await walletClient.writeContract({
7870
- address,
7871
- abi,
7872
- functionName,
7873
- args,
7874
- account: resolvedAccount,
7875
- chain: walletClient.chain,
7876
- ...value !== void 0 && { value },
7877
- ...gasOverrides
7878
- });
7879
- return createTxResult(client, hash);
7880
- }
7881
-
7882
- //#endregion
7883
- //#region src/panoptic/v2/errors/base.ts
7884
- /**
7885
- * Base error class for the Panoptic v2 SDK.
7886
- * @module v2/errors/base
7887
- */
7888
- /**
7889
- * Base error class for all Panoptic SDK errors.
7890
- * All errors thrown by the SDK extend this class.
7891
- *
7892
- * @example
7893
- * ```typescript
7894
- * try {
7895
- * await openPosition(config, params)
7896
- * } catch (error) {
7897
- * if (error instanceof PanopticError) {
7898
- * console.log('Panoptic error:', error.name, error.message)
7899
- * console.log('Original cause:', error.cause)
7900
- * }
7901
- * }
7902
- * ```
7903
- */
7904
- var PanopticError = class extends Error {
7905
- name = "PanopticError";
7906
- /** The Solidity error name (e.g. 'PriceBoundFail', 'InputListFail'). Set by the parser. */
7907
- errorName;
7908
- /**
7909
- * Creates a new PanopticError.
7910
- *
7911
- * @param message - Human-readable error message
7912
- * @param cause - Optional underlying error that caused this error
7913
- */
7914
- constructor(message, cause) {
7915
- super(message);
7916
- this.cause = cause;
7917
- if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
7918
- Object.setPrototypeOf(this, new.target.prototype);
7919
- }
7920
- };
7921
-
7922
- //#endregion
7923
- //#region src/panoptic/v2/errors/contract.ts
7924
- /**
7925
- * The account is not solvent enough to perform the desired action.
7926
- * @see Errors.sol:9
7927
- */
7928
- var AccountInsolventError = class extends PanopticError {
7929
- name = "AccountInsolventError";
7930
- constructor(solvent, numberOfTicks, cause) {
7931
- super(`Account insolvent: solvent=${solvent}, numberOfTicks=${numberOfTicks}`, cause);
7932
- this.solvent = solvent;
7933
- this.numberOfTicks = numberOfTicks;
7934
- }
7935
- };
7936
- /**
7937
- * Position is still solvent and cannot be liquidated.
7938
- * @see Errors.sol:84
7939
- */
7940
- var NotMarginCalledError = class extends PanopticError {
7941
- name = "NotMarginCalledError";
7942
- constructor(cause) {
7943
- super("Position is still solvent and cannot be liquidated", cause);
7944
- }
7945
- };
7946
- /**
7947
- * The user does not own enough assets to open/close a position.
7948
- * @see Errors.sol:78
7949
- */
7950
- var NotEnoughTokensError = class extends PanopticError {
7951
- name = "NotEnoughTokensError";
7952
- constructor(tokenAddress, assetsRequested, assetBalance, cause) {
7953
- super(`Not enough tokens: requested=${assetsRequested}, balance=${assetBalance}, token=${tokenAddress}`, cause);
7954
- this.tokenAddress = tokenAddress;
7955
- this.assetsRequested = assetsRequested;
7956
- this.assetBalance = assetBalance;
7957
- }
7958
- };
7959
- /**
7960
- * There is not enough available liquidity in the chunk for a long leg.
7961
- * @see Errors.sol:75
7686
+ * There is not enough available liquidity in the chunk for a long leg.
7687
+ * @see Errors.sol:75
7962
7688
  */
7963
7689
  var NotEnoughLiquidityInChunkError = class extends PanopticError {
7964
7690
  name = "NotEnoughLiquidityInChunkError";
@@ -9084,162 +8810,452 @@ function parsePanopticError(error) {
9084
8810
  const match = matchSelectorToErrorName(selector);
9085
8811
  if (match) return buildParsedError(match, [], error);
9086
8812
  }
9087
- return null;
8813
+ return null;
8814
+ }
8815
+ }
8816
+ /**
8817
+ * Walk the cause chain looking for a viem ContractFunctionRevertedError
8818
+ * that already has decoded `.data` (an object with `errorName` and `args`).
8819
+ * This happens when the ABI passed to simulateContract includes the error definitions.
8820
+ */
8821
+ function extractViemDecodedError(error) {
8822
+ if (!error || typeof error !== "object") return null;
8823
+ if (error instanceof BaseError) {
8824
+ let found = null;
8825
+ error.walk((e) => {
8826
+ if (found) return false;
8827
+ const node = e;
8828
+ if (node.data && typeof node.data === "object" && "errorName" in node.data && typeof node.data.errorName === "string") {
8829
+ const data = node.data;
8830
+ found = {
8831
+ errorName: data.errorName,
8832
+ args: data.args ?? []
8833
+ };
8834
+ return true;
8835
+ }
8836
+ return false;
8837
+ });
8838
+ return found;
8839
+ }
8840
+ let current = error;
8841
+ for (let i = 0; i < 10 && current; i++) {
8842
+ if (current.data && typeof current.data === "object" && "errorName" in current.data && typeof current.data.errorName === "string") {
8843
+ const data = current.data;
8844
+ return {
8845
+ errorName: data.errorName,
8846
+ args: data.args ?? []
8847
+ };
8848
+ }
8849
+ current = current.cause && typeof current.cause === "object" ? current.cause : null;
8850
+ }
8851
+ return null;
8852
+ }
8853
+ /**
8854
+ * Build a ParsedError from a decoded error name and args.
8855
+ */
8856
+ function buildParsedError(errorName, args, originalError) {
8857
+ const constructor = errorConstructors[errorName];
8858
+ const cause = originalError instanceof Error ? originalError : void 0;
8859
+ if (!constructor) {
8860
+ const unknownError = new PanopticError(`Unknown contract error: ${errorName}`);
8861
+ unknownError.errorName = errorName;
8862
+ return {
8863
+ error: unknownError,
8864
+ errorName,
8865
+ args
8866
+ };
8867
+ }
8868
+ const typedError = constructor(args, cause);
8869
+ typedError.errorName = errorName;
8870
+ return {
8871
+ error: typedError,
8872
+ errorName,
8873
+ args
8874
+ };
8875
+ }
8876
+ /**
8877
+ * Match a 4-byte selector against the panoptic errors ABI.
8878
+ * Used as fallback when we only have the selector (no encoded args).
8879
+ */
8880
+ function matchSelectorToErrorName(selector) {
8881
+ for (const item of panopticErrorsAbi) {
8882
+ if (item.type !== "error") continue;
8883
+ const computed = toFunctionSelector(`${item.name}(${item.inputs.map((i) => i.type).join(",")})`);
8884
+ if (computed === selector) return item.name;
8885
+ }
8886
+ return null;
8887
+ }
8888
+ /**
8889
+ * Extract error data from various error formats.
8890
+ *
8891
+ * Strategy:
8892
+ * 1. Use viem's BaseError.walk() to traverse the full cause chain and find
8893
+ * hex data on any node (handles arbitrary nesting depth for multicall etc.)
8894
+ * 2. Fall back to manual cause-chain walk for non-viem errors
8895
+ * 3. Last resort: extract selector from error message (loses args)
8896
+ */
8897
+ function extractErrorData(error) {
8898
+ if (!error) return null;
8899
+ if (typeof error === "string" && error.startsWith("0x")) return error;
8900
+ if (typeof error !== "object") return null;
8901
+ if (error instanceof BaseError) {
8902
+ let foundData = null;
8903
+ error.walk((e) => {
8904
+ if (foundData) return false;
8905
+ const node = e;
8906
+ if (typeof node.raw === "string" && node.raw.startsWith("0x") && node.raw.length > 10) {
8907
+ foundData = node.raw;
8908
+ return true;
8909
+ }
8910
+ if (node.data && typeof node.data === "string" && node.data.startsWith("0x")) {
8911
+ foundData = node.data;
8912
+ return true;
8913
+ }
8914
+ if (node.data && typeof node.data === "object") {
8915
+ const nested = node.data;
8916
+ if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) {
8917
+ foundData = nested.data;
8918
+ return true;
8919
+ }
8920
+ }
8921
+ return false;
8922
+ });
8923
+ if (foundData) return foundData;
8924
+ error.walk((e) => {
8925
+ if (foundData) return false;
8926
+ const node = e;
8927
+ if (node.signature && typeof node.signature === "string" && node.signature.startsWith("0x")) {
8928
+ foundData = node.signature;
8929
+ return true;
8930
+ }
8931
+ return false;
8932
+ });
8933
+ if (foundData) return foundData;
8934
+ }
8935
+ let current = error;
8936
+ const maxDepth = 10;
8937
+ for (let i = 0; i < maxDepth && current; i++) {
8938
+ if (typeof current.raw === "string" && current.raw.startsWith("0x") && current.raw.length > 10) return current.raw;
8939
+ if (current.data && typeof current.data === "string" && current.data.startsWith("0x")) return current.data;
8940
+ if (current.data && typeof current.data === "object") {
8941
+ const nested = current.data;
8942
+ if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) return nested.data;
8943
+ }
8944
+ if (current.error && typeof current.error === "object") {
8945
+ const rpcError = current.error;
8946
+ if (rpcError.data && typeof rpcError.data === "string" && rpcError.data.startsWith("0x")) return rpcError.data;
8947
+ }
8948
+ current = current.cause && typeof current.cause === "object" ? current.cause : null;
8949
+ }
8950
+ const obj = error;
8951
+ if (obj.message && typeof obj.message === "string") {
8952
+ const signatureMatch = obj.message.match(/signature:?\s*["']?(0x[a-fA-F0-9]{8,})/i);
8953
+ if (signatureMatch) return signatureMatch[1];
8954
+ }
8955
+ return null;
8956
+ }
8957
+ /**
8958
+ * Check if an error is a specific Panoptic error type.
8959
+ *
8960
+ * @param error - The error to check
8961
+ * @param errorClass - The error class to check against
8962
+ * @returns True if the error is an instance of the specified class
8963
+ *
8964
+ * @example
8965
+ * ```typescript
8966
+ * const parsed = parsePanopticError(error)
8967
+ * if (parsed && isPanopticErrorType(parsed.error, AccountInsolventError)) {
8968
+ * console.log('Account is insolvent!')
8969
+ * }
8970
+ * ```
8971
+ */
8972
+ function isPanopticErrorType(error, errorClass) {
8973
+ return error instanceof errorClass;
8974
+ }
8975
+
8976
+ //#endregion
8977
+ //#region src/panoptic/v2/writes/utils.ts
8978
+ /**
8979
+ * Decode PositionBalance packed data.
8980
+ *
8981
+ * Layout (from LSB to MSB):
8982
+ * - positionSize: bits 0-127 (uint128)
8983
+ * - poolUtilization0: bits 128-143 (uint16)
8984
+ * - poolUtilization1: bits 144-159 (uint16)
8985
+ * - tickAtMint: bits 160-183 (int24)
8986
+ * - timestampAtMint: bits 184-215 (uint32)
8987
+ * - blockAtMint: bits 216-254 (uint39)
8988
+ * - swapAtMint: bit 255 (bool)
8989
+ */
8990
+ function decodePositionBalance$1(balanceData) {
8991
+ const positionSize = balanceData & (1n << 128n) - 1n;
8992
+ const poolUtilization0 = balanceData >> 128n & 0xffffn;
8993
+ const poolUtilization1 = balanceData >> 144n & 0xffffn;
8994
+ let tickAtMint = balanceData >> 160n & 0xffffffn;
8995
+ if (tickAtMint > 0x7fffffn) tickAtMint = tickAtMint - 0x1000000n;
8996
+ const timestampAtMint = balanceData >> 184n & 0xffffffffn;
8997
+ const blockAtMint = balanceData >> 216n & (1n << 39n) - 1n;
8998
+ const swapAtMint = balanceData >> 255n === 1n;
8999
+ return {
9000
+ positionSize,
9001
+ poolUtilization0,
9002
+ poolUtilization1,
9003
+ tickAtMint,
9004
+ timestampAtMint,
9005
+ blockAtMint,
9006
+ swapAtMint
9007
+ };
9008
+ }
9009
+ /**
9010
+ * Decode LeftRightSigned packed value.
9011
+ */
9012
+ function decodeLeftRightSigned(value) {
9013
+ let right = value & (1n << 128n) - 1n;
9014
+ let left = value >> 128n;
9015
+ if (right >= 1n << 127n) right = right - (1n << 128n);
9016
+ if (left >= 1n << 127n) left = left - (1n << 128n);
9017
+ return {
9018
+ right,
9019
+ left
9020
+ };
9021
+ }
9022
+ /**
9023
+ * Decode LeftRightUnsigned packed value.
9024
+ */
9025
+ function decodeLeftRightUnsigned(value) {
9026
+ const right = value & (1n << 128n) - 1n;
9027
+ const left = value >> 128n;
9028
+ return {
9029
+ right,
9030
+ left
9031
+ };
9032
+ }
9033
+ /**
9034
+ * Parse Panoptic events from transaction logs.
9035
+ *
9036
+ * @param logs - The transaction logs
9037
+ * @returns Parsed Panoptic events
9038
+ */
9039
+ function parsePanopticEvents(logs) {
9040
+ const events = [];
9041
+ for (const log of logs) {
9042
+ const baseEvent = {
9043
+ blockNumber: log.blockNumber ?? 0n,
9044
+ blockHash: log.blockHash ?? "0x0000000000000000000000000000000000000000000000000000000000000000",
9045
+ transactionHash: log.transactionHash ?? "0x",
9046
+ logIndex: BigInt(log.logIndex ?? 0)
9047
+ };
9048
+ try {
9049
+ const poolEvent = decodeEventLog({
9050
+ abi: panopticPoolV2Abi,
9051
+ data: log.data,
9052
+ topics: log.topics
9053
+ });
9054
+ if (poolEvent.eventName === "OptionMinted") {
9055
+ const args = poolEvent.args;
9056
+ const balance = decodePositionBalance$1(args.balanceData);
9057
+ events.push({
9058
+ type: "OptionMinted",
9059
+ ...baseEvent,
9060
+ recipient: args.recipient,
9061
+ tokenId: args.tokenId,
9062
+ positionSize: balance.positionSize,
9063
+ poolUtilization0: balance.poolUtilization0,
9064
+ poolUtilization1: balance.poolUtilization1,
9065
+ tickAtMint: balance.tickAtMint,
9066
+ timestampAtMint: balance.timestampAtMint,
9067
+ blockAtMint: balance.blockAtMint,
9068
+ swapAtMint: balance.swapAtMint
9069
+ });
9070
+ } else if (poolEvent.eventName === "OptionBurnt") {
9071
+ const args = poolEvent.args;
9072
+ events.push({
9073
+ type: "OptionBurnt",
9074
+ ...baseEvent,
9075
+ recipient: args.recipient,
9076
+ tokenId: args.tokenId,
9077
+ positionSize: args.positionSize,
9078
+ premiaByLeg: [
9079
+ args.premiaByLeg[0] ?? 0n,
9080
+ args.premiaByLeg[1] ?? 0n,
9081
+ args.premiaByLeg[2] ?? 0n,
9082
+ args.premiaByLeg[3] ?? 0n
9083
+ ]
9084
+ });
9085
+ } else if (poolEvent.eventName === "AccountLiquidated") {
9086
+ const args = poolEvent.args;
9087
+ const { right, left } = decodeLeftRightSigned(args.bonusAmounts);
9088
+ events.push({
9089
+ type: "AccountLiquidated",
9090
+ ...baseEvent,
9091
+ liquidator: args.liquidator,
9092
+ liquidatee: args.liquidatee,
9093
+ bonusAmount0: right,
9094
+ bonusAmount1: left
9095
+ });
9096
+ } else if (poolEvent.eventName === "ForcedExercised") {
9097
+ const args = poolEvent.args;
9098
+ const { right, left } = decodeLeftRightSigned(args.exerciseFee);
9099
+ events.push({
9100
+ type: "ForcedExercised",
9101
+ ...baseEvent,
9102
+ exercisor: args.exercisor,
9103
+ user: args.user,
9104
+ tokenId: args.tokenId,
9105
+ exerciseFee0: right,
9106
+ exerciseFee1: left
9107
+ });
9108
+ } else if (poolEvent.eventName === "PremiumSettled") {
9109
+ const args = poolEvent.args;
9110
+ const { right, left } = decodeLeftRightSigned(args.settledAmounts);
9111
+ events.push({
9112
+ type: "PremiumSettled",
9113
+ ...baseEvent,
9114
+ user: args.user,
9115
+ tokenId: args.tokenId,
9116
+ legIndex: args.legIndex,
9117
+ settledAmount0: right,
9118
+ settledAmount1: left
9119
+ });
9120
+ }
9121
+ } catch {
9122
+ try {
9123
+ const collateralEvent = decodeEventLog({
9124
+ abi: collateralTrackerV2Abi,
9125
+ data: log.data,
9126
+ topics: log.topics
9127
+ });
9128
+ if (collateralEvent.eventName === "Deposit") {
9129
+ const args = collateralEvent.args;
9130
+ events.push({
9131
+ type: "Deposit",
9132
+ ...baseEvent,
9133
+ sender: args.sender,
9134
+ owner: args.owner,
9135
+ assets: args.assets,
9136
+ shares: args.shares
9137
+ });
9138
+ } else if (collateralEvent.eventName === "Withdraw") {
9139
+ const args = collateralEvent.args;
9140
+ events.push({
9141
+ type: "Withdraw",
9142
+ ...baseEvent,
9143
+ sender: args.sender,
9144
+ receiver: args.receiver,
9145
+ owner: args.owner,
9146
+ assets: args.assets,
9147
+ shares: args.shares
9148
+ });
9149
+ }
9150
+ } catch {}
9151
+ }
9088
9152
  }
9153
+ return events;
9089
9154
  }
9090
9155
  /**
9091
- * Walk the cause chain looking for a viem ContractFunctionRevertedError
9092
- * that already has decoded `.data` (an object with `errorName` and `args`).
9093
- * This happens when the ABI passed to simulateContract includes the error definitions.
9156
+ * Create a TxResult from a transaction hash.
9157
+ *
9158
+ * @param client - The public client
9159
+ * @param hash - The transaction hash
9160
+ * @returns TxResult with wait function
9094
9161
  */
9095
- function extractViemDecodedError(error) {
9096
- if (!error || typeof error !== "object") return null;
9097
- if (error instanceof BaseError) {
9098
- let found = null;
9099
- error.walk((e) => {
9100
- if (found) return false;
9101
- const node = e;
9102
- if (node.data && typeof node.data === "object" && "errorName" in node.data && typeof node.data.errorName === "string") {
9103
- const data = node.data;
9104
- found = {
9105
- errorName: data.errorName,
9106
- args: data.args ?? []
9107
- };
9108
- return true;
9109
- }
9110
- return false;
9111
- });
9112
- return found;
9113
- }
9114
- let current = error;
9115
- for (let i = 0; i < 10 && current; i++) {
9116
- if (current.data && typeof current.data === "object" && "errorName" in current.data && typeof current.data.errorName === "string") {
9117
- const data = current.data;
9162
+ function createTxResult(client, hash) {
9163
+ return {
9164
+ hash,
9165
+ wait: async (confirmations) => {
9166
+ const receipt = await client.waitForTransactionReceipt({
9167
+ hash,
9168
+ confirmations: confirmations !== void 0 ? Number(confirmations) : void 0
9169
+ });
9170
+ const events = parsePanopticEvents(receipt.logs);
9118
9171
  return {
9119
- errorName: data.errorName,
9120
- args: data.args ?? []
9172
+ hash: receipt.transactionHash,
9173
+ blockNumber: receipt.blockNumber,
9174
+ blockHash: receipt.blockHash,
9175
+ gasUsed: receipt.gasUsed,
9176
+ status: receipt.status === "success" ? "success" : "reverted",
9177
+ events
9121
9178
  };
9122
9179
  }
9123
- current = current.cause && typeof current.cause === "object" ? current.cause : null;
9124
- }
9125
- return null;
9126
- }
9127
- /**
9128
- * Build a ParsedError from a decoded error name and args.
9129
- */
9130
- function buildParsedError(errorName, args, originalError) {
9131
- const constructor = errorConstructors[errorName];
9132
- const cause = originalError instanceof Error ? originalError : void 0;
9133
- if (!constructor) {
9134
- const unknownError = new PanopticError(`Unknown contract error: ${errorName}`);
9135
- unknownError.errorName = errorName;
9136
- return {
9137
- error: unknownError,
9138
- errorName,
9139
- args
9140
- };
9141
- }
9142
- const typedError = constructor(args, cause);
9143
- typedError.errorName = errorName;
9144
- return {
9145
- error: typedError,
9146
- errorName,
9147
- args
9148
9180
  };
9149
9181
  }
9150
9182
  /**
9151
- * Match a 4-byte selector against the panoptic errors ABI.
9152
- * Used as fallback when we only have the selector (no encoded args).
9183
+ * Submit a write operation, supporting both direct wallet submission
9184
+ * and custom broadcaster paths with gas overrides.
9185
+ *
9186
+ * Normal path (no broadcaster): calls walletClient.writeContract() with gas overrides.
9187
+ * Broadcaster path: prepareTransactionRequest → apply overrides → signTransaction → broadcast.
9188
+ *
9189
+ * @param params - Submit write parameters
9190
+ * @returns TxResult
9153
9191
  */
9154
- function matchSelectorToErrorName(selector) {
9155
- for (const item of panopticErrorsAbi) {
9156
- if (item.type !== "error") continue;
9157
- const computed = toFunctionSelector(`${item.name}(${item.inputs.map((i) => i.type).join(",")})`);
9158
- if (computed === selector) return item.name;
9192
+ async function submitWrite(params) {
9193
+ try {
9194
+ return await submitWriteRequest({
9195
+ ...params,
9196
+ abi: [...params.abi, ...panopticErrorsAbi]
9197
+ });
9198
+ } catch (error) {
9199
+ if (error instanceof PanopticError) throw error;
9200
+ throw parsePanopticError(error)?.error ?? error;
9159
9201
  }
9160
- return null;
9161
9202
  }
9162
- /**
9163
- * Extract error data from various error formats.
9164
- *
9165
- * Strategy:
9166
- * 1. Use viem's BaseError.walk() to traverse the full cause chain and find
9167
- * hex data on any node (handles arbitrary nesting depth for multicall etc.)
9168
- * 2. Fall back to manual cause-chain walk for non-viem errors
9169
- * 3. Last resort: extract selector from error message (loses args)
9170
- */
9171
- function extractErrorData(error) {
9172
- if (!error) return null;
9173
- if (typeof error === "string" && error.startsWith("0x")) return error;
9174
- if (typeof error !== "object") return null;
9175
- if (error instanceof BaseError) {
9176
- let foundData = null;
9177
- error.walk((e) => {
9178
- if (foundData) return false;
9179
- const node = e;
9180
- if (node.data && typeof node.data === "string" && node.data.startsWith("0x")) {
9181
- foundData = node.data;
9182
- return true;
9183
- }
9184
- if (node.data && typeof node.data === "object") {
9185
- const nested = node.data;
9186
- if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) {
9187
- foundData = nested.data;
9188
- return true;
9189
- }
9190
- }
9191
- return false;
9203
+ async function submitWriteRequest(params) {
9204
+ const { client, walletClient, account, address, abi, functionName, args, value, txOverrides } = params;
9205
+ const broadcaster = txOverrides?.broadcaster;
9206
+ if (broadcaster) {
9207
+ const data = encodeFunctionData({
9208
+ abi,
9209
+ functionName,
9210
+ args
9192
9211
  });
9193
- if (foundData) return foundData;
9194
- error.walk((e) => {
9195
- if (foundData) return false;
9196
- const node = e;
9197
- if (node.signature && typeof node.signature === "string" && node.signature.startsWith("0x")) {
9198
- foundData = node.signature;
9199
- return true;
9200
- }
9201
- return false;
9212
+ const broadcastAccount = walletClient.account ?? account;
9213
+ const request = await walletClient.prepareTransactionRequest({
9214
+ account: broadcastAccount,
9215
+ to: address,
9216
+ chain: walletClient.chain,
9217
+ data,
9218
+ ...value !== void 0 && { value },
9219
+ ...txOverrides?.maxFeePerGas !== void 0 && { maxFeePerGas: txOverrides.maxFeePerGas },
9220
+ ...txOverrides?.maxPriorityFeePerGas !== void 0 && { maxPriorityFeePerGas: txOverrides.maxPriorityFeePerGas },
9221
+ ...txOverrides?.gas !== void 0 && { gas: txOverrides.gas },
9222
+ ...txOverrides?.nonce !== void 0 && { nonce: Number(txOverrides.nonce) }
9202
9223
  });
9203
- if (foundData) return foundData;
9204
- }
9205
- let current = error;
9206
- const maxDepth = 10;
9207
- for (let i = 0; i < maxDepth && current; i++) {
9208
- if (current.data && typeof current.data === "string" && current.data.startsWith("0x")) return current.data;
9209
- if (current.data && typeof current.data === "object") {
9210
- const nested = current.data;
9211
- if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) return nested.data;
9212
- }
9213
- if (current.error && typeof current.error === "object") {
9214
- const rpcError = current.error;
9215
- if (rpcError.data && typeof rpcError.data === "string" && rpcError.data.startsWith("0x")) return rpcError.data;
9216
- }
9217
- current = current.cause && typeof current.cause === "object" ? current.cause : null;
9224
+ const signedTx = await walletClient.signTransaction({
9225
+ ...request,
9226
+ account: broadcastAccount
9227
+ });
9228
+ const hash$1 = await broadcaster.broadcast(signedTx);
9229
+ return createTxResult(client, hash$1);
9218
9230
  }
9219
- const obj = error;
9220
- if (obj.message && typeof obj.message === "string") {
9221
- const signatureMatch = obj.message.match(/signature:\s*(0x[a-fA-F0-9]{8,})/i);
9222
- if (signatureMatch) return signatureMatch[1];
9231
+ const gasOverrides = {};
9232
+ if (txOverrides?.maxFeePerGas !== void 0) gasOverrides.maxFeePerGas = txOverrides.maxFeePerGas;
9233
+ if (txOverrides?.maxPriorityFeePerGas !== void 0) gasOverrides.maxPriorityFeePerGas = txOverrides.maxPriorityFeePerGas;
9234
+ if (txOverrides?.nonce !== void 0) gasOverrides.nonce = Number(txOverrides.nonce);
9235
+ const resolvedAccount = walletClient.account ?? account;
9236
+ if (txOverrides?.gas !== void 0) gasOverrides.gas = txOverrides.gas;
9237
+ else {
9238
+ const estimated = await client.estimateContractGas({
9239
+ address,
9240
+ abi,
9241
+ functionName,
9242
+ args,
9243
+ account: resolvedAccount,
9244
+ ...value !== void 0 && { value }
9245
+ });
9246
+ gasOverrides.gas = estimated * 120n / 100n;
9223
9247
  }
9224
- return null;
9225
- }
9226
- /**
9227
- * Check if an error is a specific Panoptic error type.
9228
- *
9229
- * @param error - The error to check
9230
- * @param errorClass - The error class to check against
9231
- * @returns True if the error is an instance of the specified class
9232
- *
9233
- * @example
9234
- * ```typescript
9235
- * const parsed = parsePanopticError(error)
9236
- * if (parsed && isPanopticErrorType(parsed.error, AccountInsolventError)) {
9237
- * console.log('Account is insolvent!')
9238
- * }
9239
- * ```
9240
- */
9241
- function isPanopticErrorType(error, errorClass) {
9242
- return error instanceof errorClass;
9248
+ const hash = await walletClient.writeContract({
9249
+ address,
9250
+ abi,
9251
+ functionName,
9252
+ args,
9253
+ account: resolvedAccount,
9254
+ chain: walletClient.chain,
9255
+ ...value !== void 0 && { value },
9256
+ ...gasOverrides
9257
+ });
9258
+ return createTxResult(client, hash);
9243
9259
  }
9244
9260
 
9245
9261
  //#endregion
@@ -11948,4 +11964,4 @@ function formatPerSecondRateWadAsAprPct(ratePerSecondWad, precision) {
11948
11964
  }
11949
11965
 
11950
11966
  //#endregion
11951
- export { AccountInsolventError, AlreadyInitializedError, BatchValidationError, BelowMinimumRedemptionError, CastingError, ChunkHasZeroLiquidityError, ChunkLimitError, CrossPoolError, DEFAULT_MAX_SPREAD, DEFAULT_MINT_BUFFER, DEFAULT_VEGOID, DepositTooLargeError, DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError, InputListFailError, InsufficientCreditLiquidityError, InvalidBuilderCodeError, InvalidHistoryRangeError, InvalidTickBoundError, InvalidTickError, InvalidTickLimitsError, InvalidTokenIdParameterError, InvalidUniswapCallbackError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LengthMismatchError, LiquidityTooHighError, LoanSlotExhaustedError, MINT_BUFFER, MINT_BUFFER_DENOMINATOR, MaxRetriesExceededError, MissingPositionIdsError, MulticallNoDataError, MulticallResultFailedError, MulticallResultMissingError, NetLiquidityZeroError, NetworkMismatchError, NoLegsExercisableError, NoLoanPositionsError, NotALongLegError, NotBuilderError, NotEnoughLiquidityInChunkError, NotEnoughTokensError, NotGuardianError, NotMarginCalledError, NotPanopticPoolError, OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError, PanopticValidationError, PoolNotInitializedError, PositionCountNotZeroError, PositionNotOwnedError, PositionSnapshotNotFoundError, PositionTooLargeError, PriceBoundFailError, PriceImpactTooLargeError, ProviderLagError, ReentrancyError, RpcError, RpcResponseError, STANDARD_TICK_WIDTHS, STRIKE_CONVERSION_FACTOR, SafeModeError, StaleDataError, StaleOracleError, StorageDataNotFoundError, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, TokenIdHasZeroLegsError, TooManyLegsOpenError, TransferFailedError, UnauthorizedUniswapCallbackError, UnderOverFlowError, UnhealthyPoolError, UnsafePremiumSettlementError, WrongPoolIdError, WrongUniswapPoolError, ZeroAddressError, ZeroCollateralRequirementError, annualizePerSecondRateWad, applyMintBuffer, applyMintBufferPerToken, availableToBorrow, clearTrackedPositions, collateralTrackerV2Abi, createFileStorage, createMemoryStorage, createTxResult, decodeAllDispatchCalldata, decodeDispatchCalldata, decodeLeftRightSigned, decodeLeftRightUnsigned, decodeOraclePack, decodeOracleRiskParameters, decodeOracleTiming, decodePosition, decodePositionBalance$1 as decodePositionBalance, decodeTickSpacing, diagnoseOracleSafeMode, fetchPoolId, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatRateWad, formatTokenAmount, formatTokenAmountSigned, formatTokenDelta, formatTokenFlow, formatWad, formatWadPercent, formatWadSigned, getBlockMeta, getClosedPositionsKey, getOpenPositionIds, getOracleRiskParameters, getOracleState, getPendingPositionsKey, getPool, getPoolCurrentTick, getPoolMetaKey, getPoolMetadata, getPoolPrefix, getPosition, getPositionGreeks, getPositionMetaKey, getPositions, getPositionsKey, getRiskParameters, getSchemaVersionKey, getSyncCheckpointKey, getTrackedChunksKey, getTrackedPositionIds, getUtilization, isPanopticErrorType, isPositionTracked, jsonSerializer, mintableAfterBuffer, oracleEpochAt, panopticErrorsAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticGuardianAbi, panopticLiquidatorAbi, panopticPoolV2Abi, panopticQueryAbi as panopticQueryAbi$1, parsePanopticError, parseTokenAmount, parseWad, recoverSnapshot, recoverSnapshotFromTx, riskEngineAbi, selectDispatchForAccount, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, stateViewAbi, submitWrite, uniswapV3PoolAbi, validateBuilderCode };
11967
+ export { AccountInsolventError, AlreadyInitializedError, BatchValidationError, BelowMinimumRedemptionError, CastingError, ChunkHasZeroLiquidityError, ChunkLimitError, CrossPoolError, DEFAULT_MAX_SPREAD, DEFAULT_MINT_BUFFER, DEFAULT_VEGOID, DepositTooLargeError, DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError, InputListFailError, InsufficientCreditLiquidityError, InvalidBuilderCodeError, InvalidHistoryRangeError, InvalidTickBoundError, InvalidTickError, InvalidTickLimitsError, InvalidTokenIdParameterError, InvalidUniswapCallbackError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LengthMismatchError, LiquidityTooHighError, LoanSlotExhaustedError, MINT_BUFFER, MINT_BUFFER_DENOMINATOR, MaxRetriesExceededError, MissingPositionIdsError, MulticallNoDataError, MulticallResultFailedError, MulticallResultMissingError, NetLiquidityZeroError, NetworkMismatchError, NoLegsExercisableError, NoLoanPositionsError, NotALongLegError, NotBuilderError, NotEnoughLiquidityInChunkError, NotEnoughTokensError, NotGuardianError, NotMarginCalledError, NotPanopticPoolError, OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError, PanopticValidationError, PoolNotInitializedError, PositionCountNotZeroError, PositionNotOwnedError, PositionSnapshotNotFoundError, PositionTooLargeError, PriceBoundFailError, PriceImpactTooLargeError, ProviderLagError, ReentrancyError, RpcError, RpcResponseError, STANDARD_TICK_WIDTHS, STRIKE_CONVERSION_FACTOR, SafeModeError, StaleDataError, StaleOracleError, StorageDataNotFoundError, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, TokenIdHasZeroLegsError, TooManyLegsOpenError, TransferFailedError, UnauthorizedUniswapCallbackError, UnderOverFlowError, UnhealthyPoolError, UnsafePremiumSettlementError, WrongPoolIdError, WrongUniswapPoolError, ZeroAddressError, ZeroCollateralRequirementError, annualizePerSecondRateWad, applyMintBuffer, applyMintBufferPerToken, availableToBorrow, clearTrackedPositions, collateralTrackerV2Abi, createFileStorage, createMemoryStorage, createTxResult, decodeAllDispatchCalldata, decodeDispatchCalldata, decodeLeftRightSigned, decodeLeftRightUnsigned, decodeOraclePack, decodeOracleRiskParameters, decodeOracleTiming, decodePosition, decodePositionBalance$1 as decodePositionBalance, decodeTickSpacing, diagnoseOracleSafeMode, fetchPoolId, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatRateWad, formatTokenAmount, formatTokenAmountSigned, formatTokenDelta, formatTokenFlow, formatWad, formatWadPercent, formatWadSigned, getBlockMeta, getClosedPositionsKey, getOpenPositionIds, getOracleRiskParameters, getOracleState, getPendingPositionsKey, getPool, getPoolCurrentTick, getPoolMetaKey, getPoolMetadata, getPoolPrefix, getPosition, getPositionGreeks, getPositionMetaKey, getPositions, getPositionsKey, getRiskParameters, getSchemaVersionKey, getSyncCheckpointKey, getTrackedChunksKey, getTrackedPositionIds, getUtilization, isPanopticErrorType, isPositionTracked, jsonSerializer, mintableAfterBuffer, oracleEpochAt, panopticErrorsAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticGuardianAbi, panopticLiquidatorAbi, panopticPoolV2Abi, panopticQueryAbi, parsePanopticError, parseTokenAmount, parseWad, recoverSnapshot, recoverSnapshotFromTx, riskEngineAbi, selectDispatchForAccount, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, stateViewAbi, submitWrite, uniswapV3PoolAbi, validateBuilderCode };