@panoptic-eng/sdk 1.0.13 → 1.0.15

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.
@@ -1,7 +1,7 @@
1
1
  import { Address } from "viem";
2
2
  import { ReactNode } from "react";
3
3
  import { Config } from "wagmi";
4
- import * as react_jsx_runtime16 from "react/jsx-runtime";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
5
5
 
6
6
  //#region src/test/test-utils.d.ts
7
7
  declare const spawnAnvil: (args?: AnvilArgs) => Promise<void>;
@@ -236,7 +236,7 @@ declare const ReactTestWrapper: ({
236
236
  }: {
237
237
  children?: ReactNode;
238
238
  wagmiConfig: Config;
239
- }) => react_jsx_runtime16.JSX.Element;
239
+ }) => react_jsx_runtime0.JSX.Element;
240
240
 
241
241
  //#endregion
242
242
  //#region src/test/test-accounts.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["spawnAnvil","AnvilArgs","Promise","killAnvilProcess","killAllAnvilProcesses","Record","ReactNode","Config","ReactTestWrapper","children","wagmiConfig","react_jsx_runtime16","JSX","Element","Address","alice","bob","charlie"],"sources":["../../src/test/test-utils.d.ts","../../src/test/react-test-utils.d.ts","../../src/test/test-accounts.d.ts"],"sourcesContent":null,"mappings":";;;;;;cAAqBA,oBAAoBC,cAAcC;cAClCC,oCAAoCD;cACpCE,6BAA6BF;KAC7CD,SAAAA;;;AAHL;;;EAAkD,QAAKC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAO;AAC9D;AACA;AAAgE;;;;ACAhE;;EAG6C,eAHHO,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;EAAQ;;;;AAGL;;;;ACJ7C;EACqBO,kBAAKF,CAAAA,EAAAA,MAAO,GAAA,MAAA,GAAA,SAAA;EACZG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eFkGJZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCnGIG;;;;aACNF;eACEC;MACiBI,mBAAAA,CAAAC,GAAAA,CAAIC;;;;cCJjBE,OAAOD;cACPE,KAAKF;cACLG,SAASH"}
1
+ {"version":3,"file":"index.d.ts","names":["spawnAnvil","AnvilArgs","Promise","killAnvilProcess","killAllAnvilProcesses","Record","ReactNode","Config","ReactTestWrapper","children","wagmiConfig","react_jsx_runtime0","JSX","Element","Address","alice","bob","charlie"],"sources":["../../src/test/test-utils.d.ts","../../src/test/react-test-utils.d.ts","../../src/test/test-accounts.d.ts"],"sourcesContent":null,"mappings":";;;;;;cAAqBA,oBAAoBC,cAAcC;cAClCC,oCAAoCD;cACpCE,6BAA6BF;KAC7CD,SAAAA;;;AAHL;;;EAAkD,QAAKC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAAO;AAC9D;AACA;AAAgE;;;;ACAhE;;EAG6C,eAHHO,CAAAA,EAAAA,OAAAA,GAAAA,SAAAA;EAAQ;;;;AAGL;;;;ACJ7C;EACqBO,kBAAKF,CAAAA,EAAAA,MAAO,GAAA,MAAA,GAAA,SAAA;EACZG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eFkGJZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCnGIG;;;;aACNF;eACEC;MACiBI,kBAAAA,CAAAC,GAAAA,CAAIC;;;;cCJjBE,OAAOD;cACPE,KAAKF;cACLG,SAASH"}
@@ -1,5 +1,5 @@
1
1
  import "../position-C3Ca4itE.js";
2
- import "../writes-uU8w6eAC.js";
2
+ import "../writes-BlCi23qF.js";
3
3
  import { AmountExceedsUint128Error, InvalidSwapTokenError, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoterUnavailableError, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V4_ADDRESSES, UnsupportedChainError, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait } from "../router-Dd4tGu9L.js";
4
4
 
5
5
  export { AmountExceedsUint128Error, InvalidSwapTokenError, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoterUnavailableError, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V4_ADDRESSES, UnsupportedChainError, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait };
@@ -609,6 +609,7 @@ const jsonSerializer = {
609
609
 
610
610
  //#endregion
611
611
  //#region src/panoptic/v2/sync/snapshotRecovery.ts
612
+ const LOG_SCAN_WINDOW = 10000n;
612
613
  /**
613
614
  * Recover position snapshot from the last dispatch transaction.
614
615
  * This is the primary recovery method - it finds the most recent dispatch()
@@ -621,6 +622,67 @@ async function recoverSnapshot(params) {
621
622
  const { client, poolAddress, account, toBlock } = params;
622
623
  const latestBlock = toBlock ?? await client.getBlockNumber();
623
624
  const searchFromBlock = params.fromBlock ?? 0n;
625
+ if (latestBlock < searchFromBlock) return null;
626
+ try {
627
+ const events = await getSnapshotEventsForWindow({
628
+ client,
629
+ poolAddress,
630
+ account,
631
+ fromBlock: searchFromBlock,
632
+ toBlock: latestBlock
633
+ });
634
+ return await recoverSnapshotFromEvents({
635
+ client,
636
+ account,
637
+ events
638
+ });
639
+ } catch (error) {
640
+ if (!isRangeLimitError(error)) throw error;
641
+ }
642
+ let windowToBlock = latestBlock;
643
+ while (true) {
644
+ const windowFromBlock = windowToBlock - searchFromBlock + 1n > LOG_SCAN_WINDOW ? windowToBlock - LOG_SCAN_WINDOW + 1n : searchFromBlock;
645
+ const events = await getSnapshotEventsForWindow({
646
+ client,
647
+ poolAddress,
648
+ account,
649
+ fromBlock: windowFromBlock,
650
+ toBlock: windowToBlock
651
+ });
652
+ const snapshot = await recoverSnapshotFromEvents({
653
+ client,
654
+ account,
655
+ events
656
+ });
657
+ if (snapshot) return snapshot;
658
+ if (windowFromBlock === searchFromBlock) break;
659
+ windowToBlock = windowFromBlock - 1n;
660
+ }
661
+ return null;
662
+ }
663
+ /**
664
+ * Detect provider errors that indicate the requested getLogs block range was
665
+ * too wide (so the caller should retry with smaller windows). Covers the common
666
+ * phrasings used by Alchemy, Infura, and other JSON-RPC providers.
667
+ */
668
+ function isRangeLimitError(error) {
669
+ const parts = [];
670
+ let current = error;
671
+ let depth = 0;
672
+ while (current && typeof current === "object" && depth < 5) {
673
+ const obj = current;
674
+ if (typeof obj.message === "string") parts.push(obj.message);
675
+ if (typeof obj.details === "string") parts.push(obj.details);
676
+ current = obj.cause;
677
+ depth += 1;
678
+ }
679
+ if (typeof error === "string") parts.push(error);
680
+ const message = parts.join(" ").toLowerCase();
681
+ if (!message) return false;
682
+ return message.includes("block range") || message.includes("range is too large") || message.includes("range too large") || message.includes("query returned more than") || message.includes("too many results") || message.includes("log response size exceeded") || message.includes("exceeds the limit") || message.includes("range") && message.includes("limit");
683
+ }
684
+ async function getSnapshotEventsForWindow(params) {
685
+ const { client, poolAddress, account, fromBlock, toBlock } = params;
624
686
  const [mintEvents, burnEvents, forceExerciseEvents, liquidationEvents] = await Promise.all([
625
687
  client.getLogs({
626
688
  address: poolAddress,
@@ -646,8 +708,8 @@ async function recoverSnapshot(params) {
646
708
  ]
647
709
  },
648
710
  args: { recipient: account },
649
- fromBlock: searchFromBlock,
650
- toBlock: latestBlock
711
+ fromBlock,
712
+ toBlock
651
713
  }),
652
714
  client.getLogs({
653
715
  address: poolAddress,
@@ -678,8 +740,8 @@ async function recoverSnapshot(params) {
678
740
  ]
679
741
  },
680
742
  args: { recipient: account },
681
- fromBlock: searchFromBlock,
682
- toBlock: latestBlock
743
+ fromBlock,
744
+ toBlock
683
745
  }),
684
746
  client.getLogs({
685
747
  address: poolAddress,
@@ -710,8 +772,8 @@ async function recoverSnapshot(params) {
710
772
  ]
711
773
  },
712
774
  args: { user: account },
713
- fromBlock: searchFromBlock,
714
- toBlock: latestBlock
775
+ fromBlock,
776
+ toBlock
715
777
  }),
716
778
  client.getLogs({
717
779
  address: poolAddress,
@@ -737,16 +799,20 @@ async function recoverSnapshot(params) {
737
799
  ]
738
800
  },
739
801
  args: { liquidatee: account },
740
- fromBlock: searchFromBlock,
741
- toBlock: latestBlock
802
+ fromBlock,
803
+ toBlock
742
804
  })
743
805
  ]);
744
- const allEvents = [
806
+ return [
745
807
  ...mintEvents,
746
808
  ...burnEvents,
747
809
  ...forceExerciseEvents,
748
810
  ...liquidationEvents
749
- ].sort((a, b) => {
811
+ ];
812
+ }
813
+ async function recoverSnapshotFromEvents(params) {
814
+ const { client, account, events } = params;
815
+ const allEvents = events.filter(isSnapshotCandidateEvent).sort((a, b) => {
750
816
  const blockDiff = Number(b.blockNumber - a.blockNumber);
751
817
  if (blockDiff !== 0) return blockDiff;
752
818
  return Number(b.logIndex - a.logIndex);
@@ -772,6 +838,9 @@ async function recoverSnapshot(params) {
772
838
  } catch {}
773
839
  return null;
774
840
  }
841
+ function isSnapshotCandidateEvent(event) {
842
+ return event.transactionHash !== null && event.blockNumber !== null && event.logIndex !== null;
843
+ }
775
844
  /**
776
845
  * Recover position snapshot from a specific dispatch transaction hash.
777
846
  *
@@ -4368,4 +4437,4 @@ async function smartRepayAndWait(params) {
4368
4437
 
4369
4438
  //#endregion
4370
4439
  export { addLegToTokenId, approve, approveAndWait, approvePool, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertTradeable, borrow, borrowAndWait, buildBatchDispatchArgs, buildOpenPositionCalldata, buildUniqueLoan, calculateResyncBlock, cancelTransaction, checkApproval, clearCheckpoint, clearTrackedPositions, closePosition, closePositionAndWait, countLegs, createFileStorage, createMemoryStorage, createNonceManager, createTokenIdBuilder, decodeAllLegs, decodeDispatchCalldata, decodeLeg, decodePoolId, decodeTickSpacing as decodeTickSpacing$1, decodeTokenId, decodeVegoid, deployNewPool, deployNewPoolAndWait, deposit, depositAndWait, detectReorg, dispatch, dispatchAndWait, encodeLeg, encodePoolId, encodeV4PoolId, executeBatchDispatch, executeBatchDispatchAndWait, forceExercise, forceExerciseAndWait, getAssetIndex, getClosedPositionsKey, getOpenPositionIds, getPendingPositionsKey, getPoolMetaKey, getPoolPrefix, getPositionMetaKey, getPositionsKey, getSchemaVersionKey, getSyncCheckpointKey, getTrackedChunksKey, getTrackedPositionIds, hasLoanOrCredit, hasLongLeg, isCredit, isCreditLeg, isGasError, isInputListFailError, isLoan, isLoanLeg, isNonceError, isPositionTracked, isRetryableRpcError, isShortOnly, isSpread, jsonSerializer, liquidate, liquidateAndWait, loadCheckpoint, mint, mintAndWait, openPosition, openPositionAndWait, pokeOracle, pokeOracleAndWait, previewBorrow, previewUnwrap, previewWrap, publicBroadcaster, recoverSnapshot, recoverSnapshotFromTx, redeem, redeemAndWait, repay, repayAndWait, resolveTokenIndex, rollPosition, rollPositionAndWait, saveCheckpoint, settleAccumulatedPremia, settleAccumulatedPremiaAndWait, simulateOpenPosition, simulateWithTokenFlow, smartRepay, smartRepayAndWait, speedUpTransaction, supply, supplyAndWait, swapExactIn, swapExactInAndWait, swapExactOut, swapExactOutAndWait, syncPositions, unsupply, unsupplyAndWait, unwrapWeth, unwrapWethAndWait, unwrapXstock, unwrapXstockAndWait, validateBatch, validatePoolId, verifyBlockContinuity, wethWrapAbi, withdraw, withdrawAndWait, withdrawWithPositions, withdrawWithPositionsAndWait, wrapEth, wrapEthAndWait, wrapXstock, wrapXstockAndWait, xstockWrapperAbi };
4371
- //# sourceMappingURL=writes-uU8w6eAC.js.map
4440
+ //# sourceMappingURL=writes-BlCi23qF.js.map