@panoptic-eng/sdk 1.0.27 → 1.0.28
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/dist/cow/index.d.ts +5 -5
- package/dist/cow/index.js +3 -3
- package/dist/cow/types.d.ts +2 -2
- package/dist/{cow-CbyBBJa8.js → cow-Boc-39-Y.js} +2 -2
- package/dist/{cow-CbyBBJa8.js.map → cow-Boc-39-Y.js.map} +1 -1
- package/dist/index-B3JZRUNo.d.ts +9084 -0
- package/dist/index-B3JZRUNo.d.ts.map +1 -0
- package/dist/{index-Bs35Gs9h.d.ts → index-CDCAju5o.d.ts} +2 -2
- package/dist/{index-Bs35Gs9h.d.ts.map → index-CDCAju5o.d.ts.map} +1 -1
- package/dist/{index-cqnrR3RH.d.ts → index-DQS8Luef.d.ts} +4 -4
- package/dist/{index-cqnrR3RH.d.ts.map → index-DQS8Luef.d.ts.map} +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/{irm-CUQhUGHI.js → irm-B0Bgj0z8.js} +3 -3
- package/dist/{irm-CUQhUGHI.js.map → irm-B0Bgj0z8.js.map} +1 -1
- package/dist/{irm-DsuOZAXj.d.ts → irm-BNtE1Dmg.d.ts} +2 -2
- package/dist/{irm-DsuOZAXj.d.ts.map → irm-BNtE1Dmg.d.ts.map} +1 -1
- package/dist/{types-CnfCBl2B.d.ts → oracle-BnpPVG8V.d.ts} +4 -244
- package/dist/oracle-BnpPVG8V.d.ts.map +1 -0
- package/dist/panoptic/v2/greeks/index.d.ts +2 -2
- package/dist/panoptic/v2/index.d.ts +8 -9956
- package/dist/panoptic/v2/index.js +5 -11281
- package/dist/panoptic/v2/react-public.d.ts +886 -0
- package/dist/panoptic/v2/react-public.d.ts.map +1 -0
- package/dist/panoptic/v2/react-public.js +3854 -0
- package/dist/panoptic/v2/react-public.js.map +1 -0
- package/dist/{position-C8du80mE.d.ts → position-Bmd_3nzI.d.ts} +1 -1
- package/dist/{position-C8du80mE.d.ts.map → position-Bmd_3nzI.d.ts.map} +1 -1
- package/dist/{position-B7cJsaOz.js → position-R0IGLpQS.js} +2 -2
- package/dist/{position-B7cJsaOz.js.map → position-R0IGLpQS.js.map} +1 -1
- package/dist/{router-CFs84CaF.js → router-NPhQUNh4.js} +2 -2
- package/dist/{router-CFs84CaF.js.map → router-NPhQUNh4.js.map} +1 -1
- package/dist/{simulation-DMPUACvp.d.ts → simulation-CUqERC5Y.d.ts} +2 -2
- package/dist/{simulation-DMPUACvp.d.ts.map → simulation-CUqERC5Y.d.ts.map} +1 -1
- package/dist/test/index.d.ts +2 -2
- package/dist/test/index.d.ts.map +1 -1
- package/dist/{tx-D4uNr1_K.d.ts → tx-BXXqhBHn.d.ts} +1 -1
- package/dist/{tx-D4uNr1_K.d.ts.map → tx-BXXqhBHn.d.ts.map} +1 -1
- package/dist/{types-CRev1pDq.d.ts → types-DgWfno7q.d.ts} +2 -2
- package/dist/{types-CRev1pDq.d.ts.map → types-DgWfno7q.d.ts.map} +1 -1
- package/dist/types-VeWdNN0j.d.ts +247 -0
- package/dist/types-VeWdNN0j.d.ts.map +1 -0
- package/dist/uniswap/index.d.ts +5 -4
- package/dist/uniswap/index.d.ts.map +1 -1
- package/dist/uniswap/index.js +3 -3
- package/dist/v2-CkOo7vW2.js +7438 -0
- package/dist/v2-CkOo7vW2.js.map +1 -0
- package/dist/{writes-GvVYh9PQ.js → writes-Dhzpw0dq.js} +3 -3
- package/dist/{writes-GvVYh9PQ.js.map → writes-Dhzpw0dq.js.map} +1 -1
- package/package.json +5 -1
- package/dist/panoptic/v2/index.d.ts.map +0 -1
- package/dist/panoptic/v2/index.js.map +0 -1
- package/dist/types-CnfCBl2B.d.ts.map +0 -1
|
@@ -0,0 +1,3854 @@
|
|
|
1
|
+
import { BORROW_INDEX_BITS, BPS_SCALE, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, RATE_AT_TARGET_BITS, SECONDS_PER_YEAR, UNREALIZED_INTEREST_BITS, annualizePerSecondRateWad, deriveSupplyRatePerSecWad, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatRateWad$1 as formatRateWad, formatTokenAmount$1 as formatTokenAmount, formatTokenAmountSigned$1 as formatTokenAmountSigned, formatTokenDelta$1 as formatTokenDelta, formatTokenFlow$1 as formatTokenFlow, formatWad$1 as formatWad, formatWadPercent$1 as formatWadPercent, formatWadSigned$1 as formatWadSigned, getAccountCollateral$1 as getAccountCollateral, getAccountSummaryBasic$1 as getAccountSummaryBasic, getAccountSummaryRisk$1 as getAccountSummaryRisk, getChainDeployment, getCollateralAddresses$1 as getCollateralAddresses, getCollateralData$1 as getCollateralData, getCurrentRates$1 as getCurrentRates, getInterestState$1 as getInterestState, getIrmCurrent, getIrmCurve, getLiquidationPrices$1 as getLiquidationPrices, getNetLiquidationValue$1 as getNetLiquidationValue, getNetLiquidationValues$1 as getNetLiquidationValues, isLiquidatable$1 as isLiquidatable, isSupportedChain, packMarketState, parseTokenAmount$1 as parseTokenAmount, parseWad$1 as parseWad, ratePerSecWadToAprPct, requireChainDeployment, utilizationBpsToWad, utilizationPctToWad } from "../../irm-B0Bgj0z8.js";
|
|
2
|
+
import { AccountInsolventError$1 as AccountInsolventError, AlreadyInitializedError$1 as AlreadyInitializedError, BatchValidationError$1 as BatchValidationError, BelowMinimumRedemptionError$1 as BelowMinimumRedemptionError, CastingError$1 as CastingError, ChunkHasZeroLiquidityError$1 as ChunkHasZeroLiquidityError, ChunkLimitError$1 as ChunkLimitError, CrossPoolError$1 as CrossPoolError, DEFAULT_MAX_SPREAD$1 as DEFAULT_MAX_SPREAD, DEFAULT_VEGOID$1 as DEFAULT_VEGOID, DepositTooLargeError$1 as DepositTooLargeError, DuplicateTokenIdError$1 as DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError$1 as EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError$1 as ExceedsMaximumRedemptionError, InputListFailError$1 as InputListFailError, InsufficientCreditLiquidityError$1 as InsufficientCreditLiquidityError, InvalidBuilderCodeError$1 as InvalidBuilderCodeError, InvalidHistoryRangeError$1 as InvalidHistoryRangeError, InvalidTickBoundError$1 as InvalidTickBoundError, InvalidTickError$1 as InvalidTickError, InvalidTokenIdParameterError$1 as InvalidTokenIdParameterError, InvalidUniswapCallbackError$1 as InvalidUniswapCallbackError, LEG_BITS$1 as LEG_BITS, LEG_LIMITS$1 as LEG_LIMITS, LEG_MASKS$1 as LEG_MASKS, LengthMismatchError$1 as LengthMismatchError, LiquidityTooHighError$1 as LiquidityTooHighError, LoanSlotExhaustedError$1 as LoanSlotExhaustedError, MaxRetriesExceededError$1 as MaxRetriesExceededError, MissingPositionIdsError$1 as MissingPositionIdsError, NetLiquidityZeroError$1 as NetLiquidityZeroError, NetworkMismatchError$1 as NetworkMismatchError, NoLegsExercisableError$1 as NoLegsExercisableError, NotALongLegError$1 as NotALongLegError, NotBuilderError$1 as NotBuilderError, NotEnoughLiquidityInChunkError$1 as NotEnoughLiquidityInChunkError, NotEnoughTokensError$1 as NotEnoughTokensError, NotGuardianError$1 as NotGuardianError, NotMarginCalledError$1 as NotMarginCalledError, NotPanopticPoolError$1 as NotPanopticPoolError, OracleRateLimitedError$1 as OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError$1 as PanopticHelperNotDeployedError, PanopticValidationError$1 as PanopticValidationError, PoolNotInitializedError$1 as PoolNotInitializedError, PositionCountNotZeroError$1 as PositionCountNotZeroError, PositionNotOwnedError$1 as PositionNotOwnedError, PositionSnapshotNotFoundError$1 as PositionSnapshotNotFoundError, PositionTooLargeError$1 as PositionTooLargeError, PriceBoundFailError$1 as PriceBoundFailError, PriceImpactTooLargeError$1 as PriceImpactTooLargeError, ProviderLagError$1 as ProviderLagError, ReentrancyError$1 as ReentrancyError, RpcError$1 as RpcError, RpcResponseError$1 as RpcResponseError, STANDARD_TICK_WIDTHS$1 as STANDARD_TICK_WIDTHS, SafeModeError$1 as SafeModeError, StaleDataError$1 as StaleDataError, StaleOracleError$1 as StaleOracleError, SwapTokenMismatchError$1 as SwapTokenMismatchError, SyncTimeoutError$1 as SyncTimeoutError, TOKEN_ID_BITS$1 as TOKEN_ID_BITS, TokenIdHasZeroLegsError$1 as TokenIdHasZeroLegsError, TooManyLegsOpenError$1 as TooManyLegsOpenError, TransferFailedError$1 as TransferFailedError, UnauthorizedUniswapCallbackError$1 as UnauthorizedUniswapCallbackError, UnderOverFlowError$1 as UnderOverFlowError, UnhealthyPoolError$1 as UnhealthyPoolError, WrongPoolIdError$1 as WrongPoolIdError, WrongUniswapPoolError$1 as WrongUniswapPoolError, ZeroAddressError$1 as ZeroAddressError, ZeroCollateralRequirementError$1 as ZeroCollateralRequirementError, collateralTrackerV2Abi, decodeLeftRightSigned$1 as decodeLeftRightSigned, decodeLeftRightUnsigned$1 as decodeLeftRightUnsigned, fetchPoolId, getBlockMeta$1 as getBlockMeta, getOracleState, getPool, getPoolMetadata, getPosition$1 as getPosition, getPositionGreeks$1 as getPositionGreeks, getPositions$1 as getPositions, getRiskParameters, getUtilization, isPanopticErrorType$1 as isPanopticErrorType, panopticPoolV2Abi, parsePanopticError$1 as parsePanopticError, validateBuilderCode } from "../../position-R0IGLpQS.js";
|
|
3
|
+
import { BPS_DENOMINATOR, MAX_TICK, MAX_TRACKED_CHUNKS, MIN_TICK, ORACLE_EPOCH_SECONDS, REORG_DEPTH, SCHEMA_VERSION, STORAGE_PREFIX, UTILIZATION_DENOMINATOR, WAD, ZERO_COLLATERAL, ZERO_VALUATION, calculatePortfolioDelta, calculatePortfolioGamma, calculatePortfolioGreeks, calculatePortfolioValue, calculatePositionDelta, calculatePositionDeltaDebtOnly, calculatePositionDeltaWithSwap, calculatePositionGamma, calculatePositionGreeks, calculatePositionValue, formatPriceRange, formatTick, formatTickRange, getLegDelta, getLegDeltaInVaultFrame, getLegGamma, getLegNetValueWidth0, getLegValue, getPricesAtTick, getTickSpacing, isCall, isDefinedRisk, priceToTick, roundToTickSpacing, sqrtPriceX96ToPriceDecimalScaled, sqrtPriceX96ToTick, tickLimits, tickToPrice, tickToPriceDecimalScaled, tickToSqrtPriceX96, toVaultFrameAtTick } from "../../greeks-GysWXct-.js";
|
|
4
|
+
import { approveErc20ForCow, cancelCowOrder, checkCowApproval, getCowOrderStatus, isCowSupportedChain, quoteCowSwap, signAndSubmitCowOrder } from "../../cow-Boc-39-Y.js";
|
|
5
|
+
import { addLegToTokenId$1 as addLegToTokenId, approve$1 as approve, approveAndWait$1 as approveAndWait, approvePool$1 as approvePool, assertCanBurn$1 as assertCanBurn, assertCanForceExercise$1 as assertCanForceExercise, assertCanLiquidate$1 as assertCanLiquidate, assertCanMint$1 as assertCanMint, assertFresh$1 as assertFresh, assertHealthy$1 as assertHealthy, assertTradeable$1 as assertTradeable, borrow$1 as borrow, borrowAndWait$1 as borrowAndWait, buildBatchDispatchArgs$1 as buildBatchDispatchArgs, buildOpenPositionCalldata$1 as buildOpenPositionCalldata, buildUniqueLoan$1 as buildUniqueLoan, calculateResyncBlock$1 as calculateResyncBlock, cancelTransaction$1 as cancelTransaction, checkApproval$1 as checkApproval, clearCheckpoint$1 as clearCheckpoint, clearTrackedPositions$1 as clearTrackedPositions, closePosition$1 as closePosition, closePositionAndWait$1 as closePositionAndWait, countLegs$1 as countLegs, createFileStorage$1 as createFileStorage, createMemoryStorage$1 as createMemoryStorage, createNonceManager$1 as createNonceManager, createTokenIdBuilder$1 as createTokenIdBuilder, decodeAllDispatchCalldata$1 as decodeAllDispatchCalldata, decodeAllLegs$1 as decodeAllLegs, decodeDispatchCalldata$1 as decodeDispatchCalldata, decodeLeg$1 as decodeLeg, decodePoolId$1 as decodePoolId, decodeTickSpacing$2 as decodeTickSpacing, decodeTokenId$1 as decodeTokenId, decodeVegoid$1 as decodeVegoid, deployNewPool$1 as deployNewPool, deployNewPoolAndWait$1 as deployNewPoolAndWait, deposit$1 as deposit, depositAndWait$1 as depositAndWait, detectReorg$1 as detectReorg, dispatch$1 as dispatch, dispatchAndWait$1 as dispatchAndWait, encodeLeg$1 as encodeLeg, encodePoolId$1 as encodePoolId, encodeV4PoolId$1 as encodeV4PoolId, executeBatchDispatch$1 as executeBatchDispatch, executeBatchDispatchAndWait$1 as executeBatchDispatchAndWait, forceExercise$1 as forceExercise, forceExerciseAndWait$1 as forceExerciseAndWait, getAssetIndex$1 as getAssetIndex, getClosedPositionsKey$1 as getClosedPositionsKey, getOpenPositionIds$1 as getOpenPositionIds, getPendingPositionsKey$1 as getPendingPositionsKey, getPoolMetaKey$1 as getPoolMetaKey, getPoolPrefix$1 as getPoolPrefix, getPositionMetaKey$1 as getPositionMetaKey, getPositionsKey$1 as getPositionsKey, getSchemaVersionKey$1 as getSchemaVersionKey, getSyncCheckpointKey$1 as getSyncCheckpointKey, getTrackedChunksKey$1 as getTrackedChunksKey, getTrackedPositionIds$1 as getTrackedPositionIds, hasLoanOrCredit$1 as hasLoanOrCredit, hasLongLeg$1 as hasLongLeg, isCredit$1 as isCredit, isCreditLeg$1 as isCreditLeg, isGasError$1 as isGasError, isInputListFailError$1 as isInputListFailError, isLoan$1 as isLoan, isLoanLeg$1 as isLoanLeg, isNonceError$1 as isNonceError, isPositionTracked$1 as isPositionTracked, isRetryableRpcError$1 as isRetryableRpcError, isShortOnly$1 as isShortOnly, isSpread$1 as isSpread, jsonSerializer$1 as jsonSerializer, liquidate$1 as liquidate, liquidateAndWait$1 as liquidateAndWait, loadCheckpoint$1 as loadCheckpoint, mint$1 as mint, mintAndWait$1 as mintAndWait, openPosition$1 as openPosition, openPositionAndWait$1 as openPositionAndWait, pokeOracle$1 as pokeOracle, pokeOracleAndWait$1 as pokeOracleAndWait, previewBorrow$1 as previewBorrow, previewUnwrap$1 as previewUnwrap, previewWrap$1 as previewWrap, publicBroadcaster$1 as publicBroadcaster, recoverSnapshot$1 as recoverSnapshot, recoverSnapshotFromTx$1 as recoverSnapshotFromTx, redeem$1 as redeem, redeemAndWait$1 as redeemAndWait, repay$1 as repay, repayAndWait$1 as repayAndWait, resolveTokenIndex$1 as resolveTokenIndex, rollPosition$1 as rollPosition, rollPositionAndWait$1 as rollPositionAndWait, saveCheckpoint$1 as saveCheckpoint, selectDispatchForAccount$1 as selectDispatchForAccount, settleAccumulatedPremia$1 as settleAccumulatedPremia, settleAccumulatedPremiaAndWait$1 as settleAccumulatedPremiaAndWait, simulateOpenPosition$1 as simulateOpenPosition, smartRepay$1 as smartRepay, smartRepayAndWait$1 as smartRepayAndWait, speedUpTransaction$1 as speedUpTransaction, supply$1 as supply, supplyAndWait$1 as supplyAndWait, swapExactIn$1 as swapExactIn, swapExactInAndWait$1 as swapExactInAndWait, swapExactOut$1 as swapExactOut, swapExactOutAndWait$1 as swapExactOutAndWait, syncPositions$1 as syncPositions, unsupply$1 as unsupply, unsupplyAndWait$1 as unsupplyAndWait, unwrapWeth$1 as unwrapWeth, unwrapWethAndWait$1 as unwrapWethAndWait, unwrapXstock$1 as unwrapXstock, unwrapXstockAndWait$1 as unwrapXstockAndWait, validateBatch$1 as validateBatch, validatePoolId$1 as validatePoolId, verifyBlockContinuity$1 as verifyBlockContinuity, wethWrapAbi$1 as wethWrapAbi, withdraw$1 as withdraw, withdrawAndWait$1 as withdrawAndWait, withdrawWithPositions$1 as withdrawWithPositions, withdrawWithPositionsAndWait$1 as withdrawWithPositionsAndWait, wrapEth$1 as wrapEth, wrapEthAndWait$1 as wrapEthAndWait, wrapXstock$1 as wrapXstock, wrapXstockAndWait$1 as wrapXstockAndWait, xstockWrapperAbi$1 as xstockWrapperAbi } from "../../writes-Dhzpw0dq.js";
|
|
6
|
+
import { DEFAULT_RECONNECT_CONFIG, REQUIRED_BASE_ERROR_SENTINEL, addPendingPosition, addTrackedChunks, calculateAccountGreeksPure, calculateSpreadWad, checkCollateralAcrossTicks, cleanupStalePendingPositions, clearPendingPositions, clearTrackedChunks, clearTradeHistory, computeV4PoolId, confirmPendingPosition, convertToAssets, convertToShares, createEventPoller, createEventSubscription, createFlowNeutralTokenId, createPoolFormatters, decodePanopticTokenURI, encodePoolKeyBytes, encodeV3PoolKeyBytes, estimateBlockNumbers, estimateCollateralRequired, failPendingPosition, formatBlockNumber, formatBps, formatCompact, formatDatetime, formatDuration, formatDurationSeconds, formatFeeTier, formatGas, formatGwei, formatPoolIdHex, formatRatioPercent, formatTimestamp, formatTimestampLocale, formatTokenIdHex, formatTokenIdShort, formatTxHash, formatUtilization, formatWei, getAccountBuyingPower, getAccountGreeks, getAccountHistory, getAccountPremia, getChunkLiquidities, getChunkSpreads, getClosedPositions, getCollateralSharePrices, getCollateralTotalAssetsBatch, getDeltaHedgeParams, getEnforcedTickLimits, getFactoryConstructMetadata, getFactoryOwnerOf, getFactoryTokenURI, getGuardianUnlockState, getItmAmounts, getMarginBuffer, getMaxPositionSize, getMaxWithdrawable, getNativeTokenPrice, getOpenPositionPreview, getPanopticPoolAddress, getPanopticPoolFromPoolId, getPendingPositions, getPoolDeploymentBlock, getPoolDisplayId, getPoolLiquidities, getPortfolioValue, getPositionChunkData, getPositionEnrichmentData, getPositionsWithPremia, getPriceHistory, getRealizedPnL, getRequiredCreditForITM, getSafeMode, getStreamiaHistory, getSyncStatus, getTokenListId, getTrackedChunks, getTradeHistory, getUniswapFeeHistory, getUniswapV3PoolFromId, getUniswapV3PoolInfo, getUniswapV3PoolLiquidities, getUniswapV4PoolBasicState, getUniswapV4PoolInfo, getUniswapV4PoolKeyFromId, getUniswapV4PoolLiquidities, interpolateBlocks, minePoolAddress, minePoolAddressLocalAsync, multicallRead, optimizeTokenIdRiskPartners, parseBps, parseCollateralLog, parsePoolLog, parseTokenListId, previewDeposit, previewMint, previewRedeem, previewWithdraw, reconstructFromEvents, removeTrackedChunks, resolveBlockNumbers, resolvePanopticPoolFromPoolId, resolveUniswapV4PoolKey, saveClosedPosition, scanChunks, simulateBatchDispatch, simulateClosePosition, simulateDeployNewPool, simulateDeposit, simulateDispatch, simulateForceExercise, simulateLiquidate, simulateSFPMBurn, simulateSFPMMint, simulateSettle, simulateSwapExactIn, simulateSwapExactOut, simulateWithdraw, truncateAddress, watchEvents } from "../../v2-CkOo7vW2.js";
|
|
7
|
+
import { approveErc20ForPermit2, approveRouterViaPermit2, checkRouterApproval, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, swapExactInViaRouter, swapExactOutViaRouter } from "../../router-NPhQUNh4.js";
|
|
8
|
+
import { zeroAddress } from "viem";
|
|
9
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
10
|
+
import { keepPreviousData, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
|
|
13
|
+
//#region src/panoptic/v2/react/cacheScopes.ts
|
|
14
|
+
/**
|
|
15
|
+
* Stable cache-scope helpers for React query keys.
|
|
16
|
+
* @module v2/react/cacheScopes
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_CLIENT_CACHE_SCOPE = "default-client";
|
|
19
|
+
const DEFAULT_STORAGE_CACHE_SCOPE = "default-storage";
|
|
20
|
+
function getClientCacheScope(scope) {
|
|
21
|
+
return scope ?? DEFAULT_CLIENT_CACHE_SCOPE;
|
|
22
|
+
}
|
|
23
|
+
function getStorageCacheScope(scope) {
|
|
24
|
+
return scope ?? DEFAULT_STORAGE_CACHE_SCOPE;
|
|
25
|
+
}
|
|
26
|
+
function getClientCacheScopeKey(client, scope) {
|
|
27
|
+
return getClientCacheScope(scope);
|
|
28
|
+
}
|
|
29
|
+
function getStorageCacheScopeKey(storage, scope) {
|
|
30
|
+
return getStorageCacheScope(scope);
|
|
31
|
+
}
|
|
32
|
+
function getAtTickCacheKey(atTick) {
|
|
33
|
+
return atTick === void 0 ? "latest" : atTick.toString();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/panoptic/v2/react/provider.tsx
|
|
38
|
+
const PanopticContext = createContext(null);
|
|
39
|
+
/**
|
|
40
|
+
* Context provider for Panoptic v2 SDK hooks.
|
|
41
|
+
*
|
|
42
|
+
* Wraps children with shared publicClient, walletClient, account, chainId, and storage.
|
|
43
|
+
* Does NOT include QueryClientProvider — you must provide your own.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* <QueryClientProvider client={queryClient}>
|
|
48
|
+
* <PanopticProvider
|
|
49
|
+
* publicClient={publicClient}
|
|
50
|
+
* walletClient={walletClient}
|
|
51
|
+
* account={address}
|
|
52
|
+
* chainId={1n}
|
|
53
|
+
* >
|
|
54
|
+
* <App />
|
|
55
|
+
* </PanopticProvider>
|
|
56
|
+
* </QueryClientProvider>
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
function PanopticProvider({ children,...value }) {
|
|
60
|
+
return /* @__PURE__ */ jsx(PanopticContext.Provider, {
|
|
61
|
+
value,
|
|
62
|
+
children
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Access the Panoptic SDK context.
|
|
67
|
+
*
|
|
68
|
+
* @throws Error if used outside PanopticProvider
|
|
69
|
+
* @returns PanopticContextValue
|
|
70
|
+
*/
|
|
71
|
+
function usePanopticContext() {
|
|
72
|
+
const ctx = useContext(PanopticContext);
|
|
73
|
+
if (!ctx) throw new Error("usePanopticContext must be used within a PanopticProvider");
|
|
74
|
+
return ctx;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Internal hook that requires storage adapter.
|
|
78
|
+
*
|
|
79
|
+
* @throws Error if storage not provided in context
|
|
80
|
+
* @returns StorageAdapter guaranteed non-undefined
|
|
81
|
+
*/
|
|
82
|
+
function useRequireStorage() {
|
|
83
|
+
const { storage } = usePanopticContext();
|
|
84
|
+
if (!storage) throw new Error("storage is required. Provide a StorageAdapter via PanopticProvider.");
|
|
85
|
+
return storage;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/panoptic/v2/react/queryKeys.ts
|
|
90
|
+
/**
|
|
91
|
+
* Query key factory for Panoptic v2 SDK data.
|
|
92
|
+
*
|
|
93
|
+
* Use with TanStack Query or SWR for cache key consistency.
|
|
94
|
+
* All keys are arrays for proper cache matching and invalidation.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* import { useQuery } from '@tanstack/react-query'
|
|
99
|
+
* import { queryKeys, getPool } from 'panoptic-v2-sdk'
|
|
100
|
+
*
|
|
101
|
+
* function usePool(config: PanopticConfig) {
|
|
102
|
+
* return useQuery({
|
|
103
|
+
* queryKey: queryKeys.pool(config.chainId, config.poolAddress),
|
|
104
|
+
* queryFn: () => getPool(config),
|
|
105
|
+
* })
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
const queryKeys = {
|
|
110
|
+
all: ["panoptic-v2"],
|
|
111
|
+
pool: (chainId, poolAddress) => [
|
|
112
|
+
...queryKeys.all,
|
|
113
|
+
"pool",
|
|
114
|
+
chainId.toString(),
|
|
115
|
+
poolAddress
|
|
116
|
+
],
|
|
117
|
+
utilization: (chainId, poolAddress) => [
|
|
118
|
+
...queryKeys.all,
|
|
119
|
+
"utilization",
|
|
120
|
+
chainId.toString(),
|
|
121
|
+
poolAddress
|
|
122
|
+
],
|
|
123
|
+
oracle: (chainId, poolAddress) => [
|
|
124
|
+
...queryKeys.all,
|
|
125
|
+
"oracle",
|
|
126
|
+
chainId.toString(),
|
|
127
|
+
poolAddress
|
|
128
|
+
],
|
|
129
|
+
safeMode: (chainId, poolAddress) => [
|
|
130
|
+
...queryKeys.all,
|
|
131
|
+
"safeMode",
|
|
132
|
+
chainId.toString(),
|
|
133
|
+
poolAddress
|
|
134
|
+
],
|
|
135
|
+
guardianUnlock: (chainId, poolAddress) => [
|
|
136
|
+
...queryKeys.all,
|
|
137
|
+
"guardianUnlock",
|
|
138
|
+
chainId.toString(),
|
|
139
|
+
poolAddress
|
|
140
|
+
],
|
|
141
|
+
riskParameters: (chainId, poolAddress) => [
|
|
142
|
+
...queryKeys.all,
|
|
143
|
+
"riskParameters",
|
|
144
|
+
chainId.toString(),
|
|
145
|
+
poolAddress
|
|
146
|
+
],
|
|
147
|
+
rates: (chainId, poolAddress) => [
|
|
148
|
+
...queryKeys.all,
|
|
149
|
+
"rates",
|
|
150
|
+
chainId.toString(),
|
|
151
|
+
poolAddress
|
|
152
|
+
],
|
|
153
|
+
position: (chainId, poolAddress, tokenId) => [
|
|
154
|
+
...queryKeys.all,
|
|
155
|
+
"position",
|
|
156
|
+
chainId.toString(),
|
|
157
|
+
poolAddress,
|
|
158
|
+
tokenId.toString()
|
|
159
|
+
],
|
|
160
|
+
positions: (chainId, poolAddress, account) => [
|
|
161
|
+
...queryKeys.all,
|
|
162
|
+
"positions",
|
|
163
|
+
chainId.toString(),
|
|
164
|
+
poolAddress,
|
|
165
|
+
account
|
|
166
|
+
],
|
|
167
|
+
trackedPositionIds: (chainId, poolAddress, account) => [
|
|
168
|
+
...queryKeys.all,
|
|
169
|
+
"trackedPositionIds",
|
|
170
|
+
chainId.toString(),
|
|
171
|
+
poolAddress,
|
|
172
|
+
account
|
|
173
|
+
],
|
|
174
|
+
syncStatus: (chainId, poolAddress, account) => [
|
|
175
|
+
...queryKeys.all,
|
|
176
|
+
"syncStatus",
|
|
177
|
+
chainId.toString(),
|
|
178
|
+
poolAddress,
|
|
179
|
+
account
|
|
180
|
+
],
|
|
181
|
+
accountCollateral: (chainId, poolAddress, account) => [
|
|
182
|
+
...queryKeys.all,
|
|
183
|
+
"accountCollateral",
|
|
184
|
+
chainId.toString(),
|
|
185
|
+
poolAddress,
|
|
186
|
+
account
|
|
187
|
+
],
|
|
188
|
+
accountSummaryBasic: (chainId, poolAddress, account) => [
|
|
189
|
+
...queryKeys.all,
|
|
190
|
+
"accountSummaryBasic",
|
|
191
|
+
chainId.toString(),
|
|
192
|
+
poolAddress,
|
|
193
|
+
account
|
|
194
|
+
],
|
|
195
|
+
accountSummaryRisk: (chainId, poolAddress, account) => [
|
|
196
|
+
...queryKeys.all,
|
|
197
|
+
"accountSummaryRisk",
|
|
198
|
+
chainId.toString(),
|
|
199
|
+
poolAddress,
|
|
200
|
+
account
|
|
201
|
+
],
|
|
202
|
+
isLiquidatable: (chainId, poolAddress, account) => [
|
|
203
|
+
...queryKeys.all,
|
|
204
|
+
"isLiquidatable",
|
|
205
|
+
chainId.toString(),
|
|
206
|
+
poolAddress,
|
|
207
|
+
account
|
|
208
|
+
],
|
|
209
|
+
liquidationPrices: (chainId, poolAddress, account) => [
|
|
210
|
+
...queryKeys.all,
|
|
211
|
+
"liquidationPrices",
|
|
212
|
+
chainId.toString(),
|
|
213
|
+
poolAddress,
|
|
214
|
+
account
|
|
215
|
+
],
|
|
216
|
+
netLiquidationValue: (chainId, poolAddress, account, atTick) => [
|
|
217
|
+
...queryKeys.all,
|
|
218
|
+
"netLiquidationValue",
|
|
219
|
+
chainId.toString(),
|
|
220
|
+
poolAddress,
|
|
221
|
+
account,
|
|
222
|
+
atTick.toString()
|
|
223
|
+
],
|
|
224
|
+
chunkSpreads: (chainId, poolAddress) => [
|
|
225
|
+
...queryKeys.all,
|
|
226
|
+
"chunkSpreads",
|
|
227
|
+
chainId.toString(),
|
|
228
|
+
poolAddress
|
|
229
|
+
],
|
|
230
|
+
closedPositions: (chainId, poolAddress, account) => [
|
|
231
|
+
...queryKeys.all,
|
|
232
|
+
"closedPositions",
|
|
233
|
+
chainId.toString(),
|
|
234
|
+
poolAddress,
|
|
235
|
+
account
|
|
236
|
+
],
|
|
237
|
+
tradeHistory: (chainId, poolAddress, account) => [
|
|
238
|
+
...queryKeys.all,
|
|
239
|
+
"tradeHistory",
|
|
240
|
+
chainId.toString(),
|
|
241
|
+
poolAddress,
|
|
242
|
+
account
|
|
243
|
+
],
|
|
244
|
+
realizedPnL: (chainId, poolAddress, account) => [
|
|
245
|
+
...queryKeys.all,
|
|
246
|
+
"realizedPnL",
|
|
247
|
+
chainId.toString(),
|
|
248
|
+
poolAddress,
|
|
249
|
+
account
|
|
250
|
+
],
|
|
251
|
+
positionGreeks: (chainId, poolAddress, tokenId) => [
|
|
252
|
+
...queryKeys.all,
|
|
253
|
+
"positionGreeks",
|
|
254
|
+
chainId.toString(),
|
|
255
|
+
poolAddress,
|
|
256
|
+
tokenId.toString()
|
|
257
|
+
],
|
|
258
|
+
accountGreeks: (chainId, poolAddress, account) => [
|
|
259
|
+
...queryKeys.all,
|
|
260
|
+
"accountGreeks",
|
|
261
|
+
chainId.toString(),
|
|
262
|
+
poolAddress,
|
|
263
|
+
account
|
|
264
|
+
],
|
|
265
|
+
collateralEstimate: (chainId, poolAddress, account, tokenId) => [
|
|
266
|
+
...queryKeys.all,
|
|
267
|
+
"collateralEstimate",
|
|
268
|
+
chainId.toString(),
|
|
269
|
+
poolAddress,
|
|
270
|
+
account,
|
|
271
|
+
tokenId.toString()
|
|
272
|
+
],
|
|
273
|
+
maxPositionSize: (chainId, poolAddress, account, tokenId) => [
|
|
274
|
+
...queryKeys.all,
|
|
275
|
+
"maxPositionSize",
|
|
276
|
+
chainId.toString(),
|
|
277
|
+
poolAddress,
|
|
278
|
+
account,
|
|
279
|
+
tokenId.toString()
|
|
280
|
+
],
|
|
281
|
+
maxWithdrawable: (chainId, collateralTrackerAddress, positionIdList, totalAssets, account) => [
|
|
282
|
+
...queryKeys.all,
|
|
283
|
+
chainId.toString(),
|
|
284
|
+
"maxWithdrawable",
|
|
285
|
+
collateralTrackerAddress,
|
|
286
|
+
positionIdList.map(String).join(","),
|
|
287
|
+
totalAssets.toString(),
|
|
288
|
+
account
|
|
289
|
+
],
|
|
290
|
+
approval: (chainId, token, owner, spender) => [
|
|
291
|
+
...queryKeys.all,
|
|
292
|
+
"approval",
|
|
293
|
+
chainId.toString(),
|
|
294
|
+
token,
|
|
295
|
+
owner,
|
|
296
|
+
spender
|
|
297
|
+
],
|
|
298
|
+
erc4626Preview: (chainId, tracker, operation, amount) => [
|
|
299
|
+
...queryKeys.all,
|
|
300
|
+
"erc4626Preview",
|
|
301
|
+
chainId.toString(),
|
|
302
|
+
tracker,
|
|
303
|
+
operation,
|
|
304
|
+
amount.toString()
|
|
305
|
+
],
|
|
306
|
+
marginBuffer: (chainId, poolAddress, account) => [
|
|
307
|
+
...queryKeys.all,
|
|
308
|
+
"marginBuffer",
|
|
309
|
+
chainId.toString(),
|
|
310
|
+
poolAddress,
|
|
311
|
+
account
|
|
312
|
+
],
|
|
313
|
+
accountPremia: (chainId, poolAddress, account) => [
|
|
314
|
+
...queryKeys.all,
|
|
315
|
+
"accountPremia",
|
|
316
|
+
chainId.toString(),
|
|
317
|
+
poolAddress,
|
|
318
|
+
account
|
|
319
|
+
],
|
|
320
|
+
positionsWithPremia: (chainId, poolAddress, account) => [
|
|
321
|
+
...queryKeys.all,
|
|
322
|
+
"positionsWithPremia",
|
|
323
|
+
chainId.toString(),
|
|
324
|
+
poolAddress,
|
|
325
|
+
account
|
|
326
|
+
],
|
|
327
|
+
collateralData: (chainId, poolAddress) => [
|
|
328
|
+
...queryKeys.all,
|
|
329
|
+
"collateralData",
|
|
330
|
+
chainId.toString(),
|
|
331
|
+
poolAddress
|
|
332
|
+
],
|
|
333
|
+
poolLiquidities: (chainId, poolAddress) => [
|
|
334
|
+
...queryKeys.all,
|
|
335
|
+
"poolLiquidities",
|
|
336
|
+
chainId.toString(),
|
|
337
|
+
poolAddress
|
|
338
|
+
],
|
|
339
|
+
optimizeRiskPartners: (chainId, poolAddress, tokenId) => [
|
|
340
|
+
...queryKeys.all,
|
|
341
|
+
"optimizeRiskPartners",
|
|
342
|
+
chainId.toString(),
|
|
343
|
+
poolAddress,
|
|
344
|
+
tokenId.toString()
|
|
345
|
+
],
|
|
346
|
+
priceHistory: (chainId, poolAddress, timestampsHash) => [
|
|
347
|
+
...queryKeys.all,
|
|
348
|
+
"priceHistory",
|
|
349
|
+
chainId.toString(),
|
|
350
|
+
poolAddress,
|
|
351
|
+
timestampsHash
|
|
352
|
+
],
|
|
353
|
+
streamiaHistory: (chainId, poolAddress, rangeHash) => [
|
|
354
|
+
...queryKeys.all,
|
|
355
|
+
"streamiaHistory",
|
|
356
|
+
chainId.toString(),
|
|
357
|
+
poolAddress,
|
|
358
|
+
rangeHash
|
|
359
|
+
],
|
|
360
|
+
uniswapFeeHistory: (chainId, poolAddress, rangeHash) => [
|
|
361
|
+
...queryKeys.all,
|
|
362
|
+
"uniswapFeeHistory",
|
|
363
|
+
chainId.toString(),
|
|
364
|
+
poolAddress,
|
|
365
|
+
rangeHash
|
|
366
|
+
],
|
|
367
|
+
requiredCreditForITM: (chainId, poolAddress, account, tokenId) => [
|
|
368
|
+
...queryKeys.all,
|
|
369
|
+
"requiredCreditForITM",
|
|
370
|
+
chainId.toString(),
|
|
371
|
+
poolAddress,
|
|
372
|
+
account,
|
|
373
|
+
tokenId.toString()
|
|
374
|
+
],
|
|
375
|
+
flowNeutralTokenId: (chainId, poolAddress, tokenId) => [
|
|
376
|
+
...queryKeys.all,
|
|
377
|
+
"flowNeutralTokenId",
|
|
378
|
+
chainId.toString(),
|
|
379
|
+
poolAddress,
|
|
380
|
+
tokenId.toString()
|
|
381
|
+
],
|
|
382
|
+
interestState: (chainId, poolAddress, account) => [
|
|
383
|
+
...queryKeys.all,
|
|
384
|
+
"interestState",
|
|
385
|
+
chainId.toString(),
|
|
386
|
+
poolAddress,
|
|
387
|
+
account
|
|
388
|
+
]
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/panoptic/v2/react/hooks/reads.ts
|
|
393
|
+
function usePool(poolAddress, options) {
|
|
394
|
+
const { publicClient, chainId, clientScope, stateViewAddress } = usePanopticContext();
|
|
395
|
+
return useQuery({
|
|
396
|
+
queryKey: [
|
|
397
|
+
...queryKeys.pool(chainId, poolAddress),
|
|
398
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
399
|
+
stateViewAddress
|
|
400
|
+
],
|
|
401
|
+
queryFn: () => getPool({
|
|
402
|
+
client: publicClient,
|
|
403
|
+
poolAddress,
|
|
404
|
+
chainId,
|
|
405
|
+
stateViewAddress
|
|
406
|
+
}),
|
|
407
|
+
enabled: options?.enabled,
|
|
408
|
+
refetchInterval: options?.refetchInterval,
|
|
409
|
+
staleTime: options?.staleTime,
|
|
410
|
+
gcTime: options?.gcTime
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function useUtilization(poolAddress, options) {
|
|
414
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
415
|
+
return useQuery({
|
|
416
|
+
queryKey: [...queryKeys.utilization(chainId, poolAddress), getClientCacheScopeKey(publicClient, clientScope)],
|
|
417
|
+
queryFn: () => getUtilization({
|
|
418
|
+
client: publicClient,
|
|
419
|
+
poolAddress
|
|
420
|
+
}),
|
|
421
|
+
enabled: options?.enabled,
|
|
422
|
+
refetchInterval: options?.refetchInterval,
|
|
423
|
+
staleTime: options?.staleTime,
|
|
424
|
+
gcTime: options?.gcTime
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
function useOracleState(poolAddress, options) {
|
|
428
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
429
|
+
return useQuery({
|
|
430
|
+
queryKey: [...queryKeys.oracle(chainId, poolAddress), getClientCacheScopeKey(publicClient, clientScope)],
|
|
431
|
+
queryFn: () => getOracleState({
|
|
432
|
+
client: publicClient,
|
|
433
|
+
poolAddress
|
|
434
|
+
}),
|
|
435
|
+
enabled: options?.enabled,
|
|
436
|
+
refetchInterval: options?.refetchInterval,
|
|
437
|
+
staleTime: options?.staleTime,
|
|
438
|
+
gcTime: options?.gcTime
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
function useRiskParameters(poolAddress, options) {
|
|
442
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
443
|
+
return useQuery({
|
|
444
|
+
queryKey: [...queryKeys.riskParameters(chainId, poolAddress), getClientCacheScopeKey(publicClient, clientScope)],
|
|
445
|
+
queryFn: () => getRiskParameters({
|
|
446
|
+
client: publicClient,
|
|
447
|
+
poolAddress
|
|
448
|
+
}),
|
|
449
|
+
enabled: options?.enabled,
|
|
450
|
+
refetchInterval: options?.refetchInterval,
|
|
451
|
+
staleTime: options?.staleTime,
|
|
452
|
+
gcTime: options?.gcTime
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
function useCurrentRates(poolAddress, options) {
|
|
456
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
457
|
+
return useQuery({
|
|
458
|
+
queryKey: [...queryKeys.rates(chainId, poolAddress), getClientCacheScopeKey(publicClient, clientScope)],
|
|
459
|
+
queryFn: () => getCurrentRates({
|
|
460
|
+
client: publicClient,
|
|
461
|
+
poolAddress
|
|
462
|
+
}),
|
|
463
|
+
enabled: options?.enabled,
|
|
464
|
+
refetchInterval: options?.refetchInterval,
|
|
465
|
+
staleTime: options?.staleTime,
|
|
466
|
+
gcTime: options?.gcTime
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function useSafeMode(poolAddress, options) {
|
|
470
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
471
|
+
return useQuery({
|
|
472
|
+
queryKey: [...queryKeys.safeMode(chainId, poolAddress), getClientCacheScopeKey(publicClient, clientScope)],
|
|
473
|
+
queryFn: () => getSafeMode({
|
|
474
|
+
client: publicClient,
|
|
475
|
+
poolAddress
|
|
476
|
+
}),
|
|
477
|
+
enabled: options?.enabled,
|
|
478
|
+
refetchInterval: options?.refetchInterval,
|
|
479
|
+
staleTime: options?.staleTime,
|
|
480
|
+
gcTime: options?.gcTime
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* React hook for the Guardian pending-unlock state of a pool.
|
|
485
|
+
*
|
|
486
|
+
* Reads `unlockEta` + `isPoolUnlockReady` from the PanopticGuardian so the UI
|
|
487
|
+
* can surface the unlock timelock while a pool is locked (close-only). Gate it
|
|
488
|
+
* via `options.enabled` so it only runs when the pool is actually locked.
|
|
489
|
+
*
|
|
490
|
+
* @param poolAddress - The PanopticPool address
|
|
491
|
+
* @param options - Optional react-query settings (enabled, refetchInterval, staleTime, gcTime)
|
|
492
|
+
* @returns A react-query result whose `data` is a `GuardianUnlockState`
|
|
493
|
+
*/
|
|
494
|
+
function useGuardianUnlockState(poolAddress, options) {
|
|
495
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
496
|
+
return useQuery({
|
|
497
|
+
queryKey: [...queryKeys.guardianUnlock(chainId, poolAddress), getClientCacheScopeKey(publicClient, clientScope)],
|
|
498
|
+
queryFn: () => getGuardianUnlockState({
|
|
499
|
+
client: publicClient,
|
|
500
|
+
poolAddress
|
|
501
|
+
}),
|
|
502
|
+
enabled: options?.enabled,
|
|
503
|
+
refetchInterval: options?.refetchInterval,
|
|
504
|
+
staleTime: options?.staleTime,
|
|
505
|
+
gcTime: options?.gcTime
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
function useCollateralData(poolAddress, tokenIndex, options) {
|
|
509
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
510
|
+
return useQuery({
|
|
511
|
+
queryKey: [
|
|
512
|
+
...queryKeys.collateralData(chainId, poolAddress),
|
|
513
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
514
|
+
tokenIndex
|
|
515
|
+
],
|
|
516
|
+
queryFn: () => getCollateralData({
|
|
517
|
+
client: publicClient,
|
|
518
|
+
poolAddress,
|
|
519
|
+
tokenIndex
|
|
520
|
+
}),
|
|
521
|
+
enabled: options?.enabled,
|
|
522
|
+
refetchInterval: options?.refetchInterval,
|
|
523
|
+
staleTime: options?.staleTime,
|
|
524
|
+
gcTime: options?.gcTime
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
function usePoolLiquidities(poolAddress, params, options) {
|
|
528
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
529
|
+
return useQuery({
|
|
530
|
+
queryKey: [
|
|
531
|
+
...queryKeys.poolLiquidities(chainId, poolAddress),
|
|
532
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
533
|
+
params.queryAddress,
|
|
534
|
+
params.startTick,
|
|
535
|
+
params.nTicks
|
|
536
|
+
],
|
|
537
|
+
queryFn: () => getPoolLiquidities({
|
|
538
|
+
client: publicClient,
|
|
539
|
+
poolAddress,
|
|
540
|
+
queryAddress: params.queryAddress,
|
|
541
|
+
startTick: params.startTick,
|
|
542
|
+
nTicks: params.nTicks
|
|
543
|
+
}),
|
|
544
|
+
enabled: options?.enabled,
|
|
545
|
+
refetchInterval: options?.refetchInterval,
|
|
546
|
+
staleTime: options?.staleTime,
|
|
547
|
+
gcTime: options?.gcTime
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function useChunkSpreads(poolAddress, params, options) {
|
|
551
|
+
const { publicClient, chainId, clientScope, storageScope } = usePanopticContext();
|
|
552
|
+
const storage = useRequireStorage();
|
|
553
|
+
return useQuery({
|
|
554
|
+
queryKey: [
|
|
555
|
+
...queryKeys.chunkSpreads(chainId, poolAddress),
|
|
556
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
557
|
+
params.sfpmAddress,
|
|
558
|
+
getStorageCacheScopeKey(storage, storageScope)
|
|
559
|
+
],
|
|
560
|
+
queryFn: () => getChunkSpreads({
|
|
561
|
+
client: publicClient,
|
|
562
|
+
chainId,
|
|
563
|
+
poolAddress,
|
|
564
|
+
sfpmAddress: params.sfpmAddress,
|
|
565
|
+
storage
|
|
566
|
+
}),
|
|
567
|
+
enabled: options?.enabled,
|
|
568
|
+
refetchInterval: options?.refetchInterval,
|
|
569
|
+
staleTime: options?.staleTime,
|
|
570
|
+
gcTime: options?.gcTime
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
function usePosition(poolAddress, owner, tokenId, options) {
|
|
574
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
575
|
+
return useQuery({
|
|
576
|
+
queryKey: [
|
|
577
|
+
...queryKeys.position(chainId, poolAddress, tokenId),
|
|
578
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
579
|
+
owner
|
|
580
|
+
],
|
|
581
|
+
queryFn: () => getPosition({
|
|
582
|
+
client: publicClient,
|
|
583
|
+
poolAddress,
|
|
584
|
+
owner,
|
|
585
|
+
tokenId
|
|
586
|
+
}),
|
|
587
|
+
enabled: options?.enabled,
|
|
588
|
+
refetchInterval: options?.refetchInterval,
|
|
589
|
+
staleTime: options?.staleTime,
|
|
590
|
+
gcTime: options?.gcTime
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
function usePositions(poolAddress, tokenIds, owner, options) {
|
|
594
|
+
const ctx = usePanopticContext();
|
|
595
|
+
const resolvedOwner = owner ?? ctx.account;
|
|
596
|
+
return useQuery({
|
|
597
|
+
queryKey: [
|
|
598
|
+
...queryKeys.positions(ctx.chainId, poolAddress, resolvedOwner ?? ""),
|
|
599
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
600
|
+
tokenIds
|
|
601
|
+
],
|
|
602
|
+
queryFn: () => {
|
|
603
|
+
if (!resolvedOwner) throw new Error("owner required for getPositions");
|
|
604
|
+
return getPositions({
|
|
605
|
+
client: ctx.publicClient,
|
|
606
|
+
poolAddress,
|
|
607
|
+
owner: resolvedOwner,
|
|
608
|
+
tokenIds
|
|
609
|
+
});
|
|
610
|
+
},
|
|
611
|
+
enabled: (options?.enabled ?? true) && !!resolvedOwner,
|
|
612
|
+
refetchInterval: options?.refetchInterval,
|
|
613
|
+
staleTime: options?.staleTime,
|
|
614
|
+
gcTime: options?.gcTime
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
function usePositionGreeks(poolAddress, tokenId, owner, options) {
|
|
618
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
619
|
+
return useQuery({
|
|
620
|
+
queryKey: [
|
|
621
|
+
...queryKeys.positionGreeks(chainId, poolAddress, tokenId),
|
|
622
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
623
|
+
owner
|
|
624
|
+
],
|
|
625
|
+
queryFn: () => getPositionGreeks({
|
|
626
|
+
client: publicClient,
|
|
627
|
+
poolAddress,
|
|
628
|
+
tokenId,
|
|
629
|
+
owner
|
|
630
|
+
}),
|
|
631
|
+
enabled: options?.enabled,
|
|
632
|
+
refetchInterval: options?.refetchInterval,
|
|
633
|
+
staleTime: options?.staleTime,
|
|
634
|
+
gcTime: options?.gcTime
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
function useAccountCollateral(poolAddress, account, options) {
|
|
638
|
+
const ctx = usePanopticContext();
|
|
639
|
+
const resolvedAccount = account ?? ctx.account;
|
|
640
|
+
return useQuery({
|
|
641
|
+
queryKey: [...queryKeys.accountCollateral(ctx.chainId, poolAddress, resolvedAccount ?? ""), getClientCacheScopeKey(ctx.publicClient, ctx.clientScope)],
|
|
642
|
+
queryFn: () => {
|
|
643
|
+
if (!resolvedAccount) throw new Error("account required for getAccountCollateral");
|
|
644
|
+
return getAccountCollateral({
|
|
645
|
+
client: ctx.publicClient,
|
|
646
|
+
poolAddress,
|
|
647
|
+
account: resolvedAccount
|
|
648
|
+
});
|
|
649
|
+
},
|
|
650
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
651
|
+
refetchInterval: options?.refetchInterval,
|
|
652
|
+
staleTime: options?.staleTime,
|
|
653
|
+
gcTime: options?.gcTime
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
function useInterestState(poolAddress, account, options) {
|
|
657
|
+
const ctx = usePanopticContext();
|
|
658
|
+
const resolvedAccount = account ?? ctx.account;
|
|
659
|
+
return useQuery({
|
|
660
|
+
queryKey: [...queryKeys.interestState(ctx.chainId, poolAddress, resolvedAccount ?? ""), getClientCacheScopeKey(ctx.publicClient, ctx.clientScope)],
|
|
661
|
+
queryFn: () => {
|
|
662
|
+
if (!resolvedAccount) throw new Error("account required for getInterestState");
|
|
663
|
+
return getInterestState({
|
|
664
|
+
client: ctx.publicClient,
|
|
665
|
+
poolAddress,
|
|
666
|
+
account: resolvedAccount
|
|
667
|
+
});
|
|
668
|
+
},
|
|
669
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
670
|
+
refetchInterval: options?.refetchInterval,
|
|
671
|
+
staleTime: options?.staleTime,
|
|
672
|
+
gcTime: options?.gcTime
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
function useAccountSummaryBasic(poolAddress, tokenIds, account, options) {
|
|
676
|
+
const ctx = usePanopticContext();
|
|
677
|
+
const resolvedAccount = account ?? ctx.account;
|
|
678
|
+
return useQuery({
|
|
679
|
+
queryKey: [
|
|
680
|
+
...queryKeys.accountSummaryBasic(ctx.chainId, poolAddress, resolvedAccount ?? ""),
|
|
681
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
682
|
+
tokenIds
|
|
683
|
+
],
|
|
684
|
+
queryFn: () => {
|
|
685
|
+
if (!resolvedAccount) throw new Error("account required for getAccountSummaryBasic");
|
|
686
|
+
return getAccountSummaryBasic({
|
|
687
|
+
client: ctx.publicClient,
|
|
688
|
+
poolAddress,
|
|
689
|
+
account: resolvedAccount,
|
|
690
|
+
chainId: ctx.chainId,
|
|
691
|
+
tokenIds
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
695
|
+
refetchInterval: options?.refetchInterval,
|
|
696
|
+
staleTime: options?.staleTime,
|
|
697
|
+
gcTime: options?.gcTime
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
function useAccountSummaryRisk(poolAddress, tokenIds, queryAddress, account, options) {
|
|
701
|
+
const ctx = usePanopticContext();
|
|
702
|
+
const resolvedAccount = account ?? ctx.account;
|
|
703
|
+
return useQuery({
|
|
704
|
+
queryKey: [
|
|
705
|
+
...queryKeys.accountSummaryRisk(ctx.chainId, poolAddress, resolvedAccount),
|
|
706
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
707
|
+
tokenIds,
|
|
708
|
+
queryAddress,
|
|
709
|
+
options?.atTick,
|
|
710
|
+
options?.includePendingPremium
|
|
711
|
+
],
|
|
712
|
+
queryFn: () => getAccountSummaryRisk({
|
|
713
|
+
client: ctx.publicClient,
|
|
714
|
+
poolAddress,
|
|
715
|
+
account: resolvedAccount,
|
|
716
|
+
chainId: ctx.chainId,
|
|
717
|
+
tokenIds,
|
|
718
|
+
queryAddress,
|
|
719
|
+
atTick: options?.atTick,
|
|
720
|
+
includePendingPremium: options?.includePendingPremium
|
|
721
|
+
}),
|
|
722
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
723
|
+
refetchInterval: options?.refetchInterval,
|
|
724
|
+
staleTime: options?.staleTime,
|
|
725
|
+
gcTime: options?.gcTime
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
function useNetLiquidationValue(poolAddress, tokenIds, queryAddress, account, options) {
|
|
729
|
+
const ctx = usePanopticContext();
|
|
730
|
+
const resolvedAccount = account ?? ctx.account;
|
|
731
|
+
return useQuery({
|
|
732
|
+
queryKey: [
|
|
733
|
+
...queryKeys.all,
|
|
734
|
+
"netLiquidationValue",
|
|
735
|
+
ctx.chainId.toString(),
|
|
736
|
+
poolAddress,
|
|
737
|
+
resolvedAccount,
|
|
738
|
+
getAtTickCacheKey(options?.atTick),
|
|
739
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
740
|
+
tokenIds,
|
|
741
|
+
queryAddress
|
|
742
|
+
],
|
|
743
|
+
queryFn: () => getNetLiquidationValue({
|
|
744
|
+
client: ctx.publicClient,
|
|
745
|
+
poolAddress,
|
|
746
|
+
account: resolvedAccount,
|
|
747
|
+
tokenIds,
|
|
748
|
+
atTick: options?.atTick,
|
|
749
|
+
queryAddress
|
|
750
|
+
}),
|
|
751
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
752
|
+
refetchInterval: options?.refetchInterval,
|
|
753
|
+
staleTime: options?.staleTime,
|
|
754
|
+
gcTime: options?.gcTime
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
function useNetLiquidationValues(poolAddress, tokenIds, queryAddress, atTicks, account, options) {
|
|
758
|
+
const ctx = usePanopticContext();
|
|
759
|
+
const resolvedAccount = account ?? ctx.account;
|
|
760
|
+
return useQuery({
|
|
761
|
+
queryKey: [
|
|
762
|
+
...queryKeys.all,
|
|
763
|
+
"netLiquidationValues",
|
|
764
|
+
ctx.chainId.toString(),
|
|
765
|
+
poolAddress,
|
|
766
|
+
resolvedAccount,
|
|
767
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
768
|
+
tokenIds,
|
|
769
|
+
queryAddress,
|
|
770
|
+
atTicks
|
|
771
|
+
],
|
|
772
|
+
queryFn: () => getNetLiquidationValues({
|
|
773
|
+
client: ctx.publicClient,
|
|
774
|
+
poolAddress,
|
|
775
|
+
account: resolvedAccount,
|
|
776
|
+
tokenIds,
|
|
777
|
+
atTicks,
|
|
778
|
+
queryAddress
|
|
779
|
+
}),
|
|
780
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount && atTicks.length > 0,
|
|
781
|
+
refetchInterval: options?.refetchInterval,
|
|
782
|
+
staleTime: options?.staleTime,
|
|
783
|
+
gcTime: options?.gcTime
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
function useLiquidationPrices(poolAddress, tokenIds, queryAddress, account, options) {
|
|
787
|
+
const ctx = usePanopticContext();
|
|
788
|
+
const resolvedAccount = account ?? ctx.account;
|
|
789
|
+
return useQuery({
|
|
790
|
+
queryKey: [
|
|
791
|
+
...queryKeys.liquidationPrices(ctx.chainId, poolAddress, resolvedAccount),
|
|
792
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
793
|
+
tokenIds,
|
|
794
|
+
queryAddress
|
|
795
|
+
],
|
|
796
|
+
queryFn: () => getLiquidationPrices({
|
|
797
|
+
client: ctx.publicClient,
|
|
798
|
+
poolAddress,
|
|
799
|
+
account: resolvedAccount,
|
|
800
|
+
tokenIds,
|
|
801
|
+
queryAddress
|
|
802
|
+
}),
|
|
803
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
804
|
+
refetchInterval: options?.refetchInterval,
|
|
805
|
+
staleTime: options?.staleTime,
|
|
806
|
+
gcTime: options?.gcTime
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function useAccountGreeks(poolAddress, account, options) {
|
|
810
|
+
const ctx = usePanopticContext();
|
|
811
|
+
const storage = useRequireStorage();
|
|
812
|
+
const resolvedAccount = account ?? ctx.account;
|
|
813
|
+
return useQuery({
|
|
814
|
+
queryKey: [
|
|
815
|
+
...queryKeys.accountGreeks(ctx.chainId, poolAddress, resolvedAccount),
|
|
816
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
817
|
+
getStorageCacheScopeKey(storage, ctx.storageScope)
|
|
818
|
+
],
|
|
819
|
+
queryFn: () => getAccountGreeks({
|
|
820
|
+
client: ctx.publicClient,
|
|
821
|
+
chainId: ctx.chainId,
|
|
822
|
+
poolAddress,
|
|
823
|
+
account: resolvedAccount,
|
|
824
|
+
storage
|
|
825
|
+
}),
|
|
826
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
827
|
+
refetchInterval: options?.refetchInterval,
|
|
828
|
+
staleTime: options?.staleTime,
|
|
829
|
+
gcTime: options?.gcTime
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
function useMarginBuffer(poolAddress, tokenIds, queryAddress, account, options) {
|
|
833
|
+
const ctx = usePanopticContext();
|
|
834
|
+
const resolvedAccount = account ?? ctx.account;
|
|
835
|
+
return useQuery({
|
|
836
|
+
queryKey: [
|
|
837
|
+
...queryKeys.marginBuffer(ctx.chainId, poolAddress, resolvedAccount),
|
|
838
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
839
|
+
tokenIds,
|
|
840
|
+
queryAddress
|
|
841
|
+
],
|
|
842
|
+
queryFn: () => getMarginBuffer({
|
|
843
|
+
client: ctx.publicClient,
|
|
844
|
+
poolAddress,
|
|
845
|
+
account: resolvedAccount,
|
|
846
|
+
tokenIds,
|
|
847
|
+
queryAddress
|
|
848
|
+
}),
|
|
849
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
850
|
+
refetchInterval: options?.refetchInterval,
|
|
851
|
+
staleTime: options?.staleTime,
|
|
852
|
+
gcTime: options?.gcTime
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
function useIsLiquidatable(poolAddress, tokenIds, queryAddress, account, options) {
|
|
856
|
+
const ctx = usePanopticContext();
|
|
857
|
+
const resolvedAccount = account ?? ctx.account;
|
|
858
|
+
return useQuery({
|
|
859
|
+
queryKey: [
|
|
860
|
+
...queryKeys.isLiquidatable(ctx.chainId, poolAddress, resolvedAccount),
|
|
861
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
862
|
+
tokenIds,
|
|
863
|
+
queryAddress
|
|
864
|
+
],
|
|
865
|
+
queryFn: () => isLiquidatable({
|
|
866
|
+
client: ctx.publicClient,
|
|
867
|
+
poolAddress,
|
|
868
|
+
account: resolvedAccount,
|
|
869
|
+
tokenIds,
|
|
870
|
+
queryAddress
|
|
871
|
+
}),
|
|
872
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
873
|
+
refetchInterval: options?.refetchInterval,
|
|
874
|
+
staleTime: options?.staleTime,
|
|
875
|
+
gcTime: options?.gcTime
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
function useAccountPremia(poolAddress, tokenIds, account, options) {
|
|
879
|
+
const ctx = usePanopticContext();
|
|
880
|
+
const resolvedAccount = account ?? ctx.account;
|
|
881
|
+
return useQuery({
|
|
882
|
+
queryKey: [
|
|
883
|
+
...queryKeys.accountPremia(ctx.chainId, poolAddress, resolvedAccount),
|
|
884
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
885
|
+
tokenIds
|
|
886
|
+
],
|
|
887
|
+
queryFn: () => getAccountPremia({
|
|
888
|
+
client: ctx.publicClient,
|
|
889
|
+
poolAddress,
|
|
890
|
+
account: resolvedAccount,
|
|
891
|
+
tokenIds
|
|
892
|
+
}),
|
|
893
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
894
|
+
refetchInterval: options?.refetchInterval,
|
|
895
|
+
staleTime: options?.staleTime,
|
|
896
|
+
gcTime: options?.gcTime
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
function usePositionsWithPremia(poolAddress, tokenIds, account, options) {
|
|
900
|
+
const ctx = usePanopticContext();
|
|
901
|
+
const resolvedAccount = account ?? ctx.account;
|
|
902
|
+
return useQuery({
|
|
903
|
+
queryKey: [
|
|
904
|
+
...queryKeys.positionsWithPremia(ctx.chainId, poolAddress, resolvedAccount),
|
|
905
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
906
|
+
tokenIds
|
|
907
|
+
],
|
|
908
|
+
queryFn: () => getPositionsWithPremia({
|
|
909
|
+
client: ctx.publicClient,
|
|
910
|
+
poolAddress,
|
|
911
|
+
account: resolvedAccount,
|
|
912
|
+
tokenIds
|
|
913
|
+
}),
|
|
914
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
915
|
+
refetchInterval: options?.refetchInterval,
|
|
916
|
+
staleTime: options?.staleTime,
|
|
917
|
+
gcTime: options?.gcTime
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
function usePreviewDeposit(poolAddress, tokenIndex, amount, options) {
|
|
921
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
922
|
+
return useQuery({
|
|
923
|
+
queryKey: [
|
|
924
|
+
...queryKeys.erc4626Preview(chainId, poolAddress, "deposit", amount),
|
|
925
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
926
|
+
tokenIndex
|
|
927
|
+
],
|
|
928
|
+
queryFn: () => previewDeposit({
|
|
929
|
+
client: publicClient,
|
|
930
|
+
poolAddress,
|
|
931
|
+
tokenIndex,
|
|
932
|
+
amount
|
|
933
|
+
}),
|
|
934
|
+
enabled: options?.enabled,
|
|
935
|
+
refetchInterval: options?.refetchInterval,
|
|
936
|
+
staleTime: options?.staleTime,
|
|
937
|
+
gcTime: options?.gcTime
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
function usePreviewWithdraw(poolAddress, tokenIndex, amount, options) {
|
|
941
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
942
|
+
return useQuery({
|
|
943
|
+
queryKey: [
|
|
944
|
+
...queryKeys.erc4626Preview(chainId, poolAddress, "withdraw", amount),
|
|
945
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
946
|
+
tokenIndex
|
|
947
|
+
],
|
|
948
|
+
queryFn: () => previewWithdraw({
|
|
949
|
+
client: publicClient,
|
|
950
|
+
poolAddress,
|
|
951
|
+
tokenIndex,
|
|
952
|
+
amount
|
|
953
|
+
}),
|
|
954
|
+
enabled: options?.enabled,
|
|
955
|
+
refetchInterval: options?.refetchInterval,
|
|
956
|
+
staleTime: options?.staleTime,
|
|
957
|
+
gcTime: options?.gcTime
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
function usePreviewMint(poolAddress, tokenIndex, amount, options) {
|
|
961
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
962
|
+
return useQuery({
|
|
963
|
+
queryKey: [
|
|
964
|
+
...queryKeys.erc4626Preview(chainId, poolAddress, "mint", amount),
|
|
965
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
966
|
+
tokenIndex
|
|
967
|
+
],
|
|
968
|
+
queryFn: () => previewMint({
|
|
969
|
+
client: publicClient,
|
|
970
|
+
poolAddress,
|
|
971
|
+
tokenIndex,
|
|
972
|
+
amount
|
|
973
|
+
}),
|
|
974
|
+
enabled: options?.enabled,
|
|
975
|
+
refetchInterval: options?.refetchInterval,
|
|
976
|
+
staleTime: options?.staleTime,
|
|
977
|
+
gcTime: options?.gcTime
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
function usePreviewRedeem(poolAddress, tokenIndex, amount, options) {
|
|
981
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
982
|
+
return useQuery({
|
|
983
|
+
queryKey: [
|
|
984
|
+
...queryKeys.erc4626Preview(chainId, poolAddress, "redeem", amount),
|
|
985
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
986
|
+
tokenIndex
|
|
987
|
+
],
|
|
988
|
+
queryFn: () => previewRedeem({
|
|
989
|
+
client: publicClient,
|
|
990
|
+
poolAddress,
|
|
991
|
+
tokenIndex,
|
|
992
|
+
amount
|
|
993
|
+
}),
|
|
994
|
+
enabled: options?.enabled,
|
|
995
|
+
refetchInterval: options?.refetchInterval,
|
|
996
|
+
staleTime: options?.staleTime,
|
|
997
|
+
gcTime: options?.gcTime
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
function useEstimateCollateralRequired(poolAddress, tokenId, positionSize, queryAddress, account, options) {
|
|
1001
|
+
const ctx = usePanopticContext();
|
|
1002
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1003
|
+
return useQuery({
|
|
1004
|
+
queryKey: [
|
|
1005
|
+
...queryKeys.collateralEstimate(ctx.chainId, poolAddress, resolvedAccount, tokenId),
|
|
1006
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
1007
|
+
positionSize,
|
|
1008
|
+
queryAddress,
|
|
1009
|
+
options?.atTick
|
|
1010
|
+
],
|
|
1011
|
+
queryFn: () => estimateCollateralRequired({
|
|
1012
|
+
client: ctx.publicClient,
|
|
1013
|
+
poolAddress,
|
|
1014
|
+
account: resolvedAccount,
|
|
1015
|
+
tokenId,
|
|
1016
|
+
positionSize,
|
|
1017
|
+
queryAddress,
|
|
1018
|
+
atTick: options?.atTick
|
|
1019
|
+
}),
|
|
1020
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
1021
|
+
refetchInterval: options?.refetchInterval,
|
|
1022
|
+
staleTime: options?.staleTime,
|
|
1023
|
+
gcTime: options?.gcTime
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
function useFlowNeutralTokenId(poolAddress, tokenId, positionSize, account, options) {
|
|
1027
|
+
const ctx = usePanopticContext();
|
|
1028
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1029
|
+
const neutralizeITM = options?.neutralizeITM ?? true;
|
|
1030
|
+
const swapAtMint = options?.swapAtMint ?? true;
|
|
1031
|
+
const referenceSize = options?.referenceSize;
|
|
1032
|
+
const queryAddress = options?.queryAddress;
|
|
1033
|
+
return useQuery({
|
|
1034
|
+
queryKey: [
|
|
1035
|
+
...queryKeys.flowNeutralTokenId(ctx.chainId, poolAddress, tokenId),
|
|
1036
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
1037
|
+
resolvedAccount ?? "",
|
|
1038
|
+
positionSize.toString(),
|
|
1039
|
+
(options?.existingPositionIds ?? []).map(String).join(","),
|
|
1040
|
+
neutralizeITM,
|
|
1041
|
+
swapAtMint,
|
|
1042
|
+
positionSize,
|
|
1043
|
+
options?.existingPositionIds,
|
|
1044
|
+
(referenceSize ?? 0n).toString(),
|
|
1045
|
+
referenceSize,
|
|
1046
|
+
queryAddress ?? ""
|
|
1047
|
+
],
|
|
1048
|
+
queryFn: () => {
|
|
1049
|
+
if (!resolvedAccount) throw new Error("account required for createFlowNeutralTokenId");
|
|
1050
|
+
return createFlowNeutralTokenId({
|
|
1051
|
+
client: ctx.publicClient,
|
|
1052
|
+
poolAddress,
|
|
1053
|
+
account: resolvedAccount,
|
|
1054
|
+
tokenId,
|
|
1055
|
+
positionSize,
|
|
1056
|
+
existingPositionIds: options?.existingPositionIds,
|
|
1057
|
+
swapAtMint,
|
|
1058
|
+
referenceSize,
|
|
1059
|
+
queryAddress
|
|
1060
|
+
});
|
|
1061
|
+
},
|
|
1062
|
+
enabled: (options?.enabled ?? true) && neutralizeITM && !!resolvedAccount && tokenId !== 0n && positionSize > 0n,
|
|
1063
|
+
refetchInterval: options?.refetchInterval
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
function useMaxPositionSize(poolAddress, tokenId, queryAddress, account, options) {
|
|
1067
|
+
const ctx = usePanopticContext();
|
|
1068
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1069
|
+
return useQuery({
|
|
1070
|
+
queryKey: [
|
|
1071
|
+
...queryKeys.maxPositionSize(ctx.chainId, poolAddress, resolvedAccount ?? "", tokenId),
|
|
1072
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
1073
|
+
queryAddress,
|
|
1074
|
+
options?.existingPositionIds?.map(String).join(",") ?? "",
|
|
1075
|
+
options?.existingPositionIds,
|
|
1076
|
+
options?.swapAtMint ?? false,
|
|
1077
|
+
options?.precisionPct ?? 1,
|
|
1078
|
+
options?.usePremiaAsCollateral ?? false
|
|
1079
|
+
],
|
|
1080
|
+
queryFn: () => {
|
|
1081
|
+
if (!resolvedAccount) throw new Error("account required for getMaxPositionSize");
|
|
1082
|
+
return getMaxPositionSize({
|
|
1083
|
+
client: ctx.publicClient,
|
|
1084
|
+
poolAddress,
|
|
1085
|
+
account: resolvedAccount,
|
|
1086
|
+
tokenId,
|
|
1087
|
+
queryAddress,
|
|
1088
|
+
existingPositionIds: options?.existingPositionIds,
|
|
1089
|
+
swapAtMint: options?.swapAtMint,
|
|
1090
|
+
precisionPct: options?.precisionPct,
|
|
1091
|
+
usePremiaAsCollateral: options?.usePremiaAsCollateral
|
|
1092
|
+
});
|
|
1093
|
+
},
|
|
1094
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
1095
|
+
refetchInterval: options?.refetchInterval,
|
|
1096
|
+
placeholderData: keepPreviousData
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
function useOptimizeRiskPartners(poolAddress, tokenId, queryAddress, atTick, options) {
|
|
1100
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1101
|
+
return useQuery({
|
|
1102
|
+
queryKey: [
|
|
1103
|
+
...queryKeys.optimizeRiskPartners(chainId, poolAddress, tokenId),
|
|
1104
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1105
|
+
queryAddress,
|
|
1106
|
+
getAtTickCacheKey(atTick)
|
|
1107
|
+
],
|
|
1108
|
+
queryFn: () => optimizeTokenIdRiskPartners({
|
|
1109
|
+
client: publicClient,
|
|
1110
|
+
poolAddress,
|
|
1111
|
+
tokenId,
|
|
1112
|
+
queryAddress,
|
|
1113
|
+
atTick
|
|
1114
|
+
}),
|
|
1115
|
+
enabled: options?.enabled,
|
|
1116
|
+
refetchInterval: options?.refetchInterval,
|
|
1117
|
+
placeholderData: keepPreviousData
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
function useMaxWithdrawable(collateralTrackerAddress, positionIdList, totalAssets, account, options) {
|
|
1121
|
+
const ctx = usePanopticContext();
|
|
1122
|
+
const client = options?.client ?? ctx.publicClient;
|
|
1123
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1124
|
+
return useQuery({
|
|
1125
|
+
queryKey: [...queryKeys.maxWithdrawable(ctx.chainId, collateralTrackerAddress, positionIdList, totalAssets, resolvedAccount ?? ""), getClientCacheScopeKey(client, ctx.clientScope)],
|
|
1126
|
+
queryFn: () => {
|
|
1127
|
+
if (!resolvedAccount) throw new Error("account required for getMaxWithdrawable");
|
|
1128
|
+
return getMaxWithdrawable({
|
|
1129
|
+
client,
|
|
1130
|
+
collateralTrackerAddress,
|
|
1131
|
+
account: resolvedAccount,
|
|
1132
|
+
positionIdList,
|
|
1133
|
+
totalAssets
|
|
1134
|
+
});
|
|
1135
|
+
},
|
|
1136
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount && totalAssets > 0n,
|
|
1137
|
+
refetchInterval: options?.refetchInterval,
|
|
1138
|
+
staleTime: options?.staleTime,
|
|
1139
|
+
gcTime: options?.gcTime
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
function useOpenPositionPreview(poolAddress, account, existingPositionIds, tokenId, positionSize, queryAddress, tickLimitLow, tickLimitHigh, options) {
|
|
1143
|
+
const ctx = usePanopticContext();
|
|
1144
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1145
|
+
return useQuery({
|
|
1146
|
+
queryKey: [
|
|
1147
|
+
...queryKeys.all,
|
|
1148
|
+
"openPositionPreview",
|
|
1149
|
+
ctx.chainId.toString(),
|
|
1150
|
+
poolAddress,
|
|
1151
|
+
resolvedAccount,
|
|
1152
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
1153
|
+
tokenId.toString(),
|
|
1154
|
+
positionSize.toString(),
|
|
1155
|
+
existingPositionIds.map(String).join(","),
|
|
1156
|
+
queryAddress,
|
|
1157
|
+
tickLimitLow.toString(),
|
|
1158
|
+
tickLimitHigh.toString(),
|
|
1159
|
+
options?.spreadLimit?.toString(),
|
|
1160
|
+
options?.swapAtMint,
|
|
1161
|
+
options?.usePremiaAsCollateral,
|
|
1162
|
+
options?.blockNumber?.toString()
|
|
1163
|
+
],
|
|
1164
|
+
queryFn: () => getOpenPositionPreview({
|
|
1165
|
+
client: ctx.publicClient,
|
|
1166
|
+
poolAddress,
|
|
1167
|
+
account: resolvedAccount,
|
|
1168
|
+
existingPositionIds,
|
|
1169
|
+
tokenId,
|
|
1170
|
+
positionSize,
|
|
1171
|
+
queryAddress,
|
|
1172
|
+
tickLimitLow,
|
|
1173
|
+
tickLimitHigh,
|
|
1174
|
+
spreadLimit: options?.spreadLimit,
|
|
1175
|
+
swapAtMint: options?.swapAtMint,
|
|
1176
|
+
usePremiaAsCollateral: options?.usePremiaAsCollateral,
|
|
1177
|
+
chainId: ctx.chainId,
|
|
1178
|
+
blockNumber: options?.blockNumber
|
|
1179
|
+
}),
|
|
1180
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount && tokenId !== 0n,
|
|
1181
|
+
staleTime: options?.staleTime ?? 0
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
function useTrackedPositionIds(poolAddress, account, options) {
|
|
1185
|
+
const ctx = usePanopticContext();
|
|
1186
|
+
const storage = useRequireStorage();
|
|
1187
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1188
|
+
return useQuery({
|
|
1189
|
+
queryKey: [...queryKeys.trackedPositionIds(ctx.chainId, poolAddress, resolvedAccount), getStorageCacheScopeKey(storage, ctx.storageScope)],
|
|
1190
|
+
queryFn: () => getTrackedPositionIds({
|
|
1191
|
+
chainId: ctx.chainId,
|
|
1192
|
+
poolAddress,
|
|
1193
|
+
account: resolvedAccount,
|
|
1194
|
+
storage
|
|
1195
|
+
}),
|
|
1196
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
1197
|
+
refetchInterval: options?.refetchInterval,
|
|
1198
|
+
staleTime: options?.staleTime,
|
|
1199
|
+
gcTime: options?.gcTime
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
function useTradeHistory(poolAddress, account, options) {
|
|
1203
|
+
const ctx = usePanopticContext();
|
|
1204
|
+
const storage = useRequireStorage();
|
|
1205
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1206
|
+
return useQuery({
|
|
1207
|
+
queryKey: [...queryKeys.tradeHistory(ctx.chainId, poolAddress, resolvedAccount), getStorageCacheScopeKey(storage, ctx.storageScope)],
|
|
1208
|
+
queryFn: () => getTradeHistory({
|
|
1209
|
+
chainId: ctx.chainId,
|
|
1210
|
+
poolAddress,
|
|
1211
|
+
account: resolvedAccount,
|
|
1212
|
+
storage
|
|
1213
|
+
}),
|
|
1214
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
1215
|
+
refetchInterval: options?.refetchInterval,
|
|
1216
|
+
staleTime: options?.staleTime,
|
|
1217
|
+
gcTime: options?.gcTime
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
function useRealizedPnL(poolAddress, account, options) {
|
|
1221
|
+
const ctx = usePanopticContext();
|
|
1222
|
+
const storage = useRequireStorage();
|
|
1223
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1224
|
+
return useQuery({
|
|
1225
|
+
queryKey: [...queryKeys.realizedPnL(ctx.chainId, poolAddress, resolvedAccount), getStorageCacheScopeKey(storage, ctx.storageScope)],
|
|
1226
|
+
queryFn: () => getRealizedPnL({
|
|
1227
|
+
chainId: ctx.chainId,
|
|
1228
|
+
poolAddress,
|
|
1229
|
+
account: resolvedAccount,
|
|
1230
|
+
storage
|
|
1231
|
+
}),
|
|
1232
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
1233
|
+
refetchInterval: options?.refetchInterval,
|
|
1234
|
+
staleTime: options?.staleTime,
|
|
1235
|
+
gcTime: options?.gcTime
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
function useClosedPositions(poolAddress, account, options) {
|
|
1239
|
+
const ctx = usePanopticContext();
|
|
1240
|
+
const storage = useRequireStorage();
|
|
1241
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1242
|
+
return useQuery({
|
|
1243
|
+
queryKey: [...queryKeys.closedPositions(ctx.chainId, poolAddress, resolvedAccount), getStorageCacheScopeKey(storage, ctx.storageScope)],
|
|
1244
|
+
queryFn: () => getClosedPositions({
|
|
1245
|
+
chainId: ctx.chainId,
|
|
1246
|
+
poolAddress,
|
|
1247
|
+
account: resolvedAccount,
|
|
1248
|
+
storage
|
|
1249
|
+
}),
|
|
1250
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
1251
|
+
refetchInterval: options?.refetchInterval,
|
|
1252
|
+
staleTime: options?.staleTime,
|
|
1253
|
+
gcTime: options?.gcTime
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
function useSyncStatus(poolAddress, account, options) {
|
|
1257
|
+
const ctx = usePanopticContext();
|
|
1258
|
+
const storage = useRequireStorage();
|
|
1259
|
+
const resolvedAccount = account ?? ctx.account;
|
|
1260
|
+
return useQuery({
|
|
1261
|
+
queryKey: [
|
|
1262
|
+
...queryKeys.syncStatus(ctx.chainId, poolAddress, resolvedAccount),
|
|
1263
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope),
|
|
1264
|
+
getStorageCacheScopeKey(storage, ctx.storageScope)
|
|
1265
|
+
],
|
|
1266
|
+
queryFn: () => getSyncStatus({
|
|
1267
|
+
client: ctx.publicClient,
|
|
1268
|
+
chainId: ctx.chainId,
|
|
1269
|
+
poolAddress,
|
|
1270
|
+
account: resolvedAccount,
|
|
1271
|
+
storage
|
|
1272
|
+
}),
|
|
1273
|
+
enabled: (options?.enabled ?? true) && !!resolvedAccount,
|
|
1274
|
+
refetchInterval: options?.refetchInterval,
|
|
1275
|
+
staleTime: options?.staleTime,
|
|
1276
|
+
gcTime: options?.gcTime
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
function usePanopticPoolAddress(params, options) {
|
|
1280
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
1281
|
+
return useQuery({
|
|
1282
|
+
queryKey: [
|
|
1283
|
+
...queryKeys.all,
|
|
1284
|
+
"factory",
|
|
1285
|
+
"getPanopticPool",
|
|
1286
|
+
params?.factoryAddress,
|
|
1287
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1288
|
+
params
|
|
1289
|
+
],
|
|
1290
|
+
queryFn: () => {
|
|
1291
|
+
if (!params) throw new PanopticValidationError("params is required");
|
|
1292
|
+
return getPanopticPoolAddress({
|
|
1293
|
+
client: publicClient,
|
|
1294
|
+
...params
|
|
1295
|
+
});
|
|
1296
|
+
},
|
|
1297
|
+
enabled: (options?.enabled ?? true) && params !== void 0,
|
|
1298
|
+
refetchInterval: options?.refetchInterval,
|
|
1299
|
+
staleTime: options?.staleTime,
|
|
1300
|
+
gcTime: options?.gcTime
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
function useFactoryTokenURI(params, options) {
|
|
1304
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
1305
|
+
return useQuery({
|
|
1306
|
+
queryKey: [
|
|
1307
|
+
...queryKeys.all,
|
|
1308
|
+
"factory",
|
|
1309
|
+
"tokenURI",
|
|
1310
|
+
params?.factoryAddress,
|
|
1311
|
+
params?.tokenId?.toString(),
|
|
1312
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1313
|
+
params
|
|
1314
|
+
],
|
|
1315
|
+
queryFn: () => {
|
|
1316
|
+
if (!params) throw new PanopticValidationError("params is required");
|
|
1317
|
+
return getFactoryTokenURI({
|
|
1318
|
+
client: publicClient,
|
|
1319
|
+
...params
|
|
1320
|
+
});
|
|
1321
|
+
},
|
|
1322
|
+
enabled: (options?.enabled ?? true) && params !== void 0,
|
|
1323
|
+
refetchInterval: options?.refetchInterval,
|
|
1324
|
+
staleTime: options?.staleTime,
|
|
1325
|
+
gcTime: options?.gcTime
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
function useFactoryOwnerOf(params, options) {
|
|
1329
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
1330
|
+
return useQuery({
|
|
1331
|
+
queryKey: [
|
|
1332
|
+
...queryKeys.all,
|
|
1333
|
+
"factory",
|
|
1334
|
+
"ownerOf",
|
|
1335
|
+
params?.factoryAddress,
|
|
1336
|
+
params?.tokenId?.toString(),
|
|
1337
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1338
|
+
params
|
|
1339
|
+
],
|
|
1340
|
+
queryFn: () => {
|
|
1341
|
+
if (!params) throw new PanopticValidationError("params is required");
|
|
1342
|
+
return getFactoryOwnerOf({
|
|
1343
|
+
client: publicClient,
|
|
1344
|
+
...params
|
|
1345
|
+
});
|
|
1346
|
+
},
|
|
1347
|
+
enabled: (options?.enabled ?? true) && params !== void 0,
|
|
1348
|
+
refetchInterval: options?.refetchInterval,
|
|
1349
|
+
staleTime: options?.staleTime,
|
|
1350
|
+
gcTime: options?.gcTime
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
function useMinePoolAddress() {
|
|
1354
|
+
return useMutation({ mutationFn: (params) => minePoolAddressLocalAsync(params) });
|
|
1355
|
+
}
|
|
1356
|
+
function useFactoryConstructMetadata(params, options) {
|
|
1357
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
1358
|
+
return useQuery({
|
|
1359
|
+
queryKey: [
|
|
1360
|
+
...queryKeys.all,
|
|
1361
|
+
"factory",
|
|
1362
|
+
"constructMetadata",
|
|
1363
|
+
params?.factoryAddress,
|
|
1364
|
+
params?.panopticPoolAddress,
|
|
1365
|
+
params?.symbol0,
|
|
1366
|
+
params?.symbol1,
|
|
1367
|
+
params?.fee?.toString(),
|
|
1368
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1369
|
+
params
|
|
1370
|
+
],
|
|
1371
|
+
queryFn: () => {
|
|
1372
|
+
if (!params) throw new PanopticValidationError("params is required");
|
|
1373
|
+
return getFactoryConstructMetadata({
|
|
1374
|
+
client: publicClient,
|
|
1375
|
+
...params
|
|
1376
|
+
});
|
|
1377
|
+
},
|
|
1378
|
+
enabled: (options?.enabled ?? true) && params !== void 0,
|
|
1379
|
+
refetchInterval: options?.refetchInterval,
|
|
1380
|
+
staleTime: options?.staleTime,
|
|
1381
|
+
gcTime: options?.gcTime
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
function useSimulateDeployNewPool(params, options) {
|
|
1385
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
1386
|
+
return useQuery({
|
|
1387
|
+
queryKey: [
|
|
1388
|
+
...queryKeys.all,
|
|
1389
|
+
"factory",
|
|
1390
|
+
"simulateDeployNewPool",
|
|
1391
|
+
params?.factoryAddress,
|
|
1392
|
+
params?.account,
|
|
1393
|
+
params?.salt?.toString(),
|
|
1394
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1395
|
+
params
|
|
1396
|
+
],
|
|
1397
|
+
queryFn: () => {
|
|
1398
|
+
if (!params) throw new PanopticValidationError("params is required");
|
|
1399
|
+
return simulateDeployNewPool({
|
|
1400
|
+
client: publicClient,
|
|
1401
|
+
...params
|
|
1402
|
+
});
|
|
1403
|
+
},
|
|
1404
|
+
enabled: (options?.enabled ?? true) && params !== void 0,
|
|
1405
|
+
refetchInterval: options?.refetchInterval,
|
|
1406
|
+
staleTime: options?.staleTime,
|
|
1407
|
+
gcTime: options?.gcTime
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Build a stable string cache key from time range params (no object references).
|
|
1412
|
+
*/
|
|
1413
|
+
function buildRangeHash(timeRange) {
|
|
1414
|
+
const pinnedSuffix = timeRange.pinnedBlocks?.length ? `-pin:${timeRange.pinnedBlocks.join(",")}` : "";
|
|
1415
|
+
return timeRange.mode === "timestamps" ? `ts:${timeRange.startTimestamp}-${timeRange.endTimestamp ?? "now"}-${timeRange.points}-${timeRange.resolution ?? "exact"}${pinnedSuffix}` : `blk:${timeRange.startBlock}-${timeRange.endBlock ?? "latest"}-${timeRange.points}${pinnedSuffix}`;
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Resolve a PriceHistoryTimeRange to start/end block numbers.
|
|
1419
|
+
*/
|
|
1420
|
+
async function resolveTimeRange(client, timeRange) {
|
|
1421
|
+
if (timeRange.mode === "timestamps") {
|
|
1422
|
+
const resolver = timeRange.resolution === "estimate" ? estimateBlockNumbers : resolveBlockNumbers;
|
|
1423
|
+
if (timeRange.endTimestamp !== void 0) {
|
|
1424
|
+
const resolved = await resolver({
|
|
1425
|
+
client,
|
|
1426
|
+
timestamps: [timeRange.startTimestamp, timeRange.endTimestamp]
|
|
1427
|
+
});
|
|
1428
|
+
return {
|
|
1429
|
+
startBlock: resolved[0],
|
|
1430
|
+
endBlock: resolved[1]
|
|
1431
|
+
};
|
|
1432
|
+
} else {
|
|
1433
|
+
const [resolved, latest] = await Promise.all([resolver({
|
|
1434
|
+
client,
|
|
1435
|
+
timestamps: [timeRange.startTimestamp]
|
|
1436
|
+
}), client.getBlockNumber()]);
|
|
1437
|
+
return {
|
|
1438
|
+
startBlock: resolved[0],
|
|
1439
|
+
endBlock: latest
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
} else return {
|
|
1443
|
+
startBlock: timeRange.startBlock,
|
|
1444
|
+
endBlock: timeRange.endBlock ?? await client.getBlockNumber()
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Hook to fetch historical price data (tick + sqrtPriceX96) for a pool.
|
|
1449
|
+
*
|
|
1450
|
+
* Supports two modes:
|
|
1451
|
+
* - **timestamps**: Resolves start/end timestamps to blocks (2 RPC binary searches),
|
|
1452
|
+
* then interpolates the blocks in between (pure math).
|
|
1453
|
+
* - **blocks**: Uses start/end blocks directly, interpolates in between.
|
|
1454
|
+
* Zero resolution overhead.
|
|
1455
|
+
*
|
|
1456
|
+
* In both cases, the actual price reads are O(points) slot0 calls.
|
|
1457
|
+
* Reads at different historical blocks cannot be coalesced into one multicall.
|
|
1458
|
+
*
|
|
1459
|
+
* @param poolConfig - Pool version config (V3 pool address or V4 StateView + poolId)
|
|
1460
|
+
* @param timeRange - Time range specification (timestamps or blocks)
|
|
1461
|
+
* @param options - Query options (enabled, refetchInterval, staleTime, gcTime)
|
|
1462
|
+
*/
|
|
1463
|
+
function usePriceHistory(poolConfig, timeRange, options) {
|
|
1464
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1465
|
+
const poolKey = poolConfig.version === "v3" ? poolConfig.poolAddress : poolConfig.poolId;
|
|
1466
|
+
const rangeHash = buildRangeHash(timeRange);
|
|
1467
|
+
return useQuery({
|
|
1468
|
+
queryKey: [...queryKeys.priceHistory(chainId, poolKey, rangeHash), getClientCacheScopeKey(publicClient, clientScope)],
|
|
1469
|
+
queryFn: async () => {
|
|
1470
|
+
const { startBlock, endBlock } = await resolveTimeRange(publicClient, timeRange);
|
|
1471
|
+
let blockNumbers = interpolateBlocks(startBlock, endBlock, timeRange.points);
|
|
1472
|
+
if (timeRange.pinnedBlocks?.length) {
|
|
1473
|
+
const blockSet = new Set(blockNumbers.map(String));
|
|
1474
|
+
const extras = timeRange.pinnedBlocks.filter((b) => b >= startBlock && b <= endBlock && !blockSet.has(String(b)));
|
|
1475
|
+
if (extras.length > 0) blockNumbers = [...blockNumbers, ...extras].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1476
|
+
}
|
|
1477
|
+
return getPriceHistory({
|
|
1478
|
+
client: publicClient,
|
|
1479
|
+
blockNumbers,
|
|
1480
|
+
poolConfig
|
|
1481
|
+
});
|
|
1482
|
+
},
|
|
1483
|
+
enabled: (options?.enabled ?? true) && timeRange.points > 0,
|
|
1484
|
+
staleTime: options?.staleTime ?? Infinity,
|
|
1485
|
+
gcTime: options?.gcTime ?? 60 * 6e4,
|
|
1486
|
+
refetchInterval: options?.refetchInterval ?? false,
|
|
1487
|
+
refetchOnWindowFocus: false,
|
|
1488
|
+
refetchOnReconnect: false
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Hook to fetch historical streamia (streaming premia + Uniswap fee) data for a position.
|
|
1493
|
+
*
|
|
1494
|
+
* @param panopticPoolAddress - PanopticPool contract address
|
|
1495
|
+
* @param account - Account whose position to query
|
|
1496
|
+
* @param tokenId - The encoded tokenId
|
|
1497
|
+
* @param legs - Decoded legs with pre-computed liquidity
|
|
1498
|
+
* @param poolConfig - Pool version config (V3 pool address or V4 StateView + poolId)
|
|
1499
|
+
* @param timeRange - Time range specification (timestamps or blocks)
|
|
1500
|
+
* @param options - Query options + optional includeUniswapFees and settledEvents
|
|
1501
|
+
*/
|
|
1502
|
+
function useStreamiaHistory(panopticPoolAddress, account, tokenId, legs, poolConfig, timeRange, options) {
|
|
1503
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1504
|
+
const poolKey = poolConfig.version === "v3" ? poolConfig.poolAddress : poolConfig.poolId;
|
|
1505
|
+
const rangeHash = buildRangeHash(timeRange);
|
|
1506
|
+
const legsKey = legs.map((l) => `${l.lowerTick}:${l.upperTick}:${l.liquidity}`).join(",");
|
|
1507
|
+
const includeUniswapFees = options?.includeUniswapFees ?? true;
|
|
1508
|
+
const settledEventsKey = options?.settledEvents ? options.settledEvents.map((e) => `${e.blockNumber}:${e.settled0}:${e.settled1}`).join(",") : "";
|
|
1509
|
+
return useQuery({
|
|
1510
|
+
queryKey: [
|
|
1511
|
+
...queryKeys.streamiaHistory(chainId, poolKey, rangeHash),
|
|
1512
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1513
|
+
panopticPoolAddress,
|
|
1514
|
+
account,
|
|
1515
|
+
tokenId.toString(),
|
|
1516
|
+
legsKey,
|
|
1517
|
+
includeUniswapFees,
|
|
1518
|
+
settledEventsKey
|
|
1519
|
+
],
|
|
1520
|
+
queryFn: async () => {
|
|
1521
|
+
const { startBlock, endBlock } = await resolveTimeRange(publicClient, timeRange);
|
|
1522
|
+
let blockNumbers = interpolateBlocks(startBlock, endBlock, timeRange.points);
|
|
1523
|
+
if (timeRange.pinnedBlocks?.length) {
|
|
1524
|
+
const pinSet = new Set(blockNumbers.map(String));
|
|
1525
|
+
const pins = timeRange.pinnedBlocks.filter((b) => b >= startBlock && b <= endBlock && !pinSet.has(String(b)));
|
|
1526
|
+
if (pins.length) blockNumbers = [...blockNumbers, ...pins].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1527
|
+
}
|
|
1528
|
+
return getStreamiaHistory({
|
|
1529
|
+
client: publicClient,
|
|
1530
|
+
panopticPoolAddress,
|
|
1531
|
+
account,
|
|
1532
|
+
tokenId,
|
|
1533
|
+
blockNumbers,
|
|
1534
|
+
legs,
|
|
1535
|
+
poolConfig,
|
|
1536
|
+
includeUniswapFees: options?.includeUniswapFees,
|
|
1537
|
+
settledEvents: options?.settledEvents
|
|
1538
|
+
});
|
|
1539
|
+
},
|
|
1540
|
+
enabled: (options?.enabled ?? true) && timeRange.points > 0,
|
|
1541
|
+
staleTime: options?.staleTime ?? Infinity,
|
|
1542
|
+
gcTime: options?.gcTime ?? 60 * 6e4,
|
|
1543
|
+
refetchInterval: options?.refetchInterval ?? false,
|
|
1544
|
+
refetchOnWindowFocus: false,
|
|
1545
|
+
refetchOnReconnect: false
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Hook to fetch historical Uniswap fee data for a set of liquidity legs.
|
|
1550
|
+
*
|
|
1551
|
+
* @param legs - Decoded legs with pre-computed liquidity
|
|
1552
|
+
* @param poolConfig - Pool version config (V3 pool address or V4 StateView + poolId)
|
|
1553
|
+
* @param timeRange - Time range specification (timestamps or blocks)
|
|
1554
|
+
* @param options - Query options (enabled, refetchInterval, staleTime, gcTime)
|
|
1555
|
+
*/
|
|
1556
|
+
function useUniswapFeeHistory(legs, poolConfig, timeRange, options) {
|
|
1557
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1558
|
+
const poolKey = poolConfig.version === "v3" ? poolConfig.poolAddress : poolConfig.poolId;
|
|
1559
|
+
const rangeHash = buildRangeHash(timeRange);
|
|
1560
|
+
const legsKey = legs.map((l) => `${l.lowerTick}:${l.upperTick}:${l.liquidity}`).join(",");
|
|
1561
|
+
return useQuery({
|
|
1562
|
+
queryKey: [
|
|
1563
|
+
...queryKeys.uniswapFeeHistory(chainId, poolKey, rangeHash),
|
|
1564
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
1565
|
+
legsKey
|
|
1566
|
+
],
|
|
1567
|
+
queryFn: async () => {
|
|
1568
|
+
const { startBlock, endBlock } = await resolveTimeRange(publicClient, timeRange);
|
|
1569
|
+
let blockNumbers = interpolateBlocks(startBlock, endBlock, timeRange.points);
|
|
1570
|
+
if (timeRange.pinnedBlocks?.length) {
|
|
1571
|
+
const pinSet = new Set(blockNumbers.map(String));
|
|
1572
|
+
const pins = timeRange.pinnedBlocks.filter((b) => b >= startBlock && b <= endBlock && !pinSet.has(String(b)));
|
|
1573
|
+
if (pins.length) blockNumbers = [...blockNumbers, ...pins].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1574
|
+
}
|
|
1575
|
+
return getUniswapFeeHistory({
|
|
1576
|
+
client: publicClient,
|
|
1577
|
+
blockNumbers,
|
|
1578
|
+
legs,
|
|
1579
|
+
poolConfig
|
|
1580
|
+
});
|
|
1581
|
+
},
|
|
1582
|
+
enabled: (options?.enabled ?? true) && timeRange.points > 0 && legs.length > 0,
|
|
1583
|
+
staleTime: options?.staleTime ?? Infinity,
|
|
1584
|
+
gcTime: options?.gcTime ?? 60 * 6e4,
|
|
1585
|
+
refetchInterval: options?.refetchInterval ?? false,
|
|
1586
|
+
refetchOnWindowFocus: false,
|
|
1587
|
+
refetchOnReconnect: false
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
/**
|
|
1591
|
+
* Reads basic on-chain info (token0, token1, fee, tickSpacing, slot0, liquidity) from a Uniswap V3 pool.
|
|
1592
|
+
* @param poolAddress - The Uniswap V3 pool contract address.
|
|
1593
|
+
* @param options - Optional React Query options (`enabled`, `staleTime`, `gcTime`, `refetchInterval`).
|
|
1594
|
+
* @returns React Query result resolving to the pool info object.
|
|
1595
|
+
*/
|
|
1596
|
+
function useUniswapV3PoolInfo(poolAddress, options) {
|
|
1597
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1598
|
+
return useQuery({
|
|
1599
|
+
queryKey: [
|
|
1600
|
+
...queryKeys.all,
|
|
1601
|
+
"uniswapV3PoolInfo",
|
|
1602
|
+
chainId.toString(),
|
|
1603
|
+
poolAddress,
|
|
1604
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1605
|
+
],
|
|
1606
|
+
queryFn: () => getUniswapV3PoolInfo({
|
|
1607
|
+
client: publicClient,
|
|
1608
|
+
poolAddress
|
|
1609
|
+
}),
|
|
1610
|
+
enabled: (options?.enabled ?? true) && !!poolAddress,
|
|
1611
|
+
refetchInterval: options?.refetchInterval,
|
|
1612
|
+
staleTime: options?.staleTime,
|
|
1613
|
+
gcTime: options?.gcTime
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Reads per-tick active liquidity from a Uniswap V3 pool via PanopticQuery's `getTickNetsV3`.
|
|
1618
|
+
* @param poolAddress - The Uniswap V3 pool contract address.
|
|
1619
|
+
* @param queryAddress - The PanopticQuery helper contract address.
|
|
1620
|
+
* @param args - Tick window: `startTick` (inclusive) and `nTicks` count to scan.
|
|
1621
|
+
* @param options - Optional React Query options (`enabled`, `staleTime`, `gcTime`, `refetchInterval`).
|
|
1622
|
+
* @returns React Query result resolving to `{ ticks, liquidityNets }` parallel arrays.
|
|
1623
|
+
*/
|
|
1624
|
+
function useUniswapV3PoolLiquidities(poolAddress, queryAddress, args, options) {
|
|
1625
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1626
|
+
return useQuery({
|
|
1627
|
+
queryKey: [
|
|
1628
|
+
...queryKeys.all,
|
|
1629
|
+
"uniswapV3PoolLiquidities",
|
|
1630
|
+
chainId.toString(),
|
|
1631
|
+
poolAddress,
|
|
1632
|
+
queryAddress,
|
|
1633
|
+
args?.startTick,
|
|
1634
|
+
args?.nTicks,
|
|
1635
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1636
|
+
],
|
|
1637
|
+
queryFn: () => {
|
|
1638
|
+
if (!poolAddress || !queryAddress || !args) throw new PanopticValidationError("useUniswapV3PoolLiquidities: missing required args");
|
|
1639
|
+
const { startTick, nTicks } = args;
|
|
1640
|
+
return getUniswapV3PoolLiquidities({
|
|
1641
|
+
client: publicClient,
|
|
1642
|
+
poolAddress,
|
|
1643
|
+
queryAddress,
|
|
1644
|
+
startTick,
|
|
1645
|
+
nTicks
|
|
1646
|
+
});
|
|
1647
|
+
},
|
|
1648
|
+
enabled: (options?.enabled ?? true) && !!poolAddress && !!queryAddress && !!args,
|
|
1649
|
+
refetchInterval: options?.refetchInterval,
|
|
1650
|
+
staleTime: options?.staleTime,
|
|
1651
|
+
gcTime: options?.gcTime
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Resolves a Uniswap V4 PoolKey from a poolId hash by scanning `Initialize` event logs on the PoolManager.
|
|
1656
|
+
* PoolKey is immutable, so results are cached indefinitely within the session by default.
|
|
1657
|
+
* @param poolManager - The Uniswap V4 PoolManager contract address.
|
|
1658
|
+
* @param poolId - The 32-byte poolId hash.
|
|
1659
|
+
* @param args - Optional `fromBlock` and `chunkSize` for log paging.
|
|
1660
|
+
* @param options - Optional React Query options (`enabled`, `staleTime`, `gcTime`, `refetchInterval`).
|
|
1661
|
+
* @returns React Query result resolving to the resolved `UniswapV4PoolKey`.
|
|
1662
|
+
*/
|
|
1663
|
+
function useResolveUniswapV4PoolKey(poolManager, poolId, args, options) {
|
|
1664
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1665
|
+
return useQuery({
|
|
1666
|
+
queryKey: [
|
|
1667
|
+
...queryKeys.all,
|
|
1668
|
+
"uniswapV4PoolKey",
|
|
1669
|
+
chainId.toString(),
|
|
1670
|
+
poolManager,
|
|
1671
|
+
poolId,
|
|
1672
|
+
args?.fromBlock?.toString(),
|
|
1673
|
+
args?.chunkSize?.toString(),
|
|
1674
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1675
|
+
],
|
|
1676
|
+
queryFn: () => resolveUniswapV4PoolKey({
|
|
1677
|
+
client: publicClient,
|
|
1678
|
+
poolManager,
|
|
1679
|
+
poolId,
|
|
1680
|
+
fromBlock: args?.fromBlock,
|
|
1681
|
+
chunkSize: args?.chunkSize
|
|
1682
|
+
}),
|
|
1683
|
+
enabled: (options?.enabled ?? true) && !!poolManager && !!poolId,
|
|
1684
|
+
staleTime: options?.staleTime ?? Infinity,
|
|
1685
|
+
gcTime: options?.gcTime,
|
|
1686
|
+
refetchInterval: options?.refetchInterval
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Reads basic on-chain state (slot0, liquidity) for a Uniswap V4 pool via the StateView contract.
|
|
1691
|
+
* @param stateViewAddress - The Uniswap V4 StateView contract address.
|
|
1692
|
+
* @param poolId - The 32-byte poolId hash.
|
|
1693
|
+
* @param options - Optional React Query options (`enabled`, `staleTime`, `gcTime`, `refetchInterval`).
|
|
1694
|
+
* @returns React Query result resolving to the pool's basic state.
|
|
1695
|
+
*/
|
|
1696
|
+
function useUniswapV4PoolBasicState(stateViewAddress, poolId, options) {
|
|
1697
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1698
|
+
return useQuery({
|
|
1699
|
+
queryKey: [
|
|
1700
|
+
...queryKeys.all,
|
|
1701
|
+
"uniswapV4PoolBasicState",
|
|
1702
|
+
chainId.toString(),
|
|
1703
|
+
stateViewAddress,
|
|
1704
|
+
poolId,
|
|
1705
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1706
|
+
],
|
|
1707
|
+
queryFn: () => getUniswapV4PoolBasicState({
|
|
1708
|
+
client: publicClient,
|
|
1709
|
+
stateViewAddress,
|
|
1710
|
+
poolId
|
|
1711
|
+
}),
|
|
1712
|
+
enabled: (options?.enabled ?? true) && !!stateViewAddress && !!poolId,
|
|
1713
|
+
refetchInterval: options?.refetchInterval,
|
|
1714
|
+
staleTime: options?.staleTime,
|
|
1715
|
+
gcTime: options?.gcTime
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Reads full pool info (slot0, liquidity, and PoolKey-derived metadata) for a Uniswap V4 pool via the StateView contract.
|
|
1720
|
+
* @param stateViewAddress - The Uniswap V4 StateView contract address.
|
|
1721
|
+
* @param poolKey - The pool's `UniswapV4PoolKey` (currency0, currency1, fee, tickSpacing, hooks).
|
|
1722
|
+
* @param options - Optional React Query options (`enabled`, `staleTime`, `gcTime`, `refetchInterval`).
|
|
1723
|
+
* @returns React Query result resolving to the full pool info object.
|
|
1724
|
+
*/
|
|
1725
|
+
function useUniswapV4PoolInfo(stateViewAddress, poolKey, options) {
|
|
1726
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1727
|
+
return useQuery({
|
|
1728
|
+
queryKey: [
|
|
1729
|
+
...queryKeys.all,
|
|
1730
|
+
"uniswapV4PoolInfo",
|
|
1731
|
+
chainId.toString(),
|
|
1732
|
+
stateViewAddress,
|
|
1733
|
+
poolKey?.currency0,
|
|
1734
|
+
poolKey?.currency1,
|
|
1735
|
+
poolKey?.fee,
|
|
1736
|
+
poolKey?.tickSpacing,
|
|
1737
|
+
poolKey?.hooks,
|
|
1738
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1739
|
+
],
|
|
1740
|
+
queryFn: () => getUniswapV4PoolInfo({
|
|
1741
|
+
client: publicClient,
|
|
1742
|
+
stateViewAddress,
|
|
1743
|
+
poolKey
|
|
1744
|
+
}),
|
|
1745
|
+
enabled: (options?.enabled ?? true) && !!stateViewAddress && !!poolKey,
|
|
1746
|
+
refetchInterval: options?.refetchInterval,
|
|
1747
|
+
staleTime: options?.staleTime,
|
|
1748
|
+
gcTime: options?.gcTime
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Reads per-tick active liquidity from a Uniswap V4 pool via PanopticQuery's `getTickNetsV4`.
|
|
1753
|
+
* @param queryAddress - The PanopticQuery helper contract address.
|
|
1754
|
+
* @param poolManager - The Uniswap V4 PoolManager contract address.
|
|
1755
|
+
* @param poolId - The 32-byte poolId hash.
|
|
1756
|
+
* @param args - `tickSpacing`, `startTick` (inclusive), and `nTicks` count to scan.
|
|
1757
|
+
* @param options - Optional React Query options (`enabled`, `staleTime`, `gcTime`, `refetchInterval`).
|
|
1758
|
+
* @returns React Query result resolving to `{ ticks, liquidityNets }` parallel arrays.
|
|
1759
|
+
*/
|
|
1760
|
+
function useUniswapV4PoolLiquidities(queryAddress, poolManager, poolId, args, options) {
|
|
1761
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1762
|
+
return useQuery({
|
|
1763
|
+
queryKey: [
|
|
1764
|
+
...queryKeys.all,
|
|
1765
|
+
"uniswapV4PoolLiquidities",
|
|
1766
|
+
chainId.toString(),
|
|
1767
|
+
queryAddress,
|
|
1768
|
+
poolManager,
|
|
1769
|
+
poolId,
|
|
1770
|
+
args?.tickSpacing,
|
|
1771
|
+
args?.startTick,
|
|
1772
|
+
args?.nTicks,
|
|
1773
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1774
|
+
],
|
|
1775
|
+
queryFn: () => {
|
|
1776
|
+
if (!queryAddress || !poolManager || !poolId || !args) throw new PanopticValidationError("useUniswapV4PoolLiquidities: missing required args");
|
|
1777
|
+
const { tickSpacing, startTick, nTicks } = args;
|
|
1778
|
+
return getUniswapV4PoolLiquidities({
|
|
1779
|
+
client: publicClient,
|
|
1780
|
+
queryAddress,
|
|
1781
|
+
poolManager,
|
|
1782
|
+
poolId,
|
|
1783
|
+
tickSpacing,
|
|
1784
|
+
startTick,
|
|
1785
|
+
nTicks
|
|
1786
|
+
});
|
|
1787
|
+
},
|
|
1788
|
+
enabled: (options?.enabled ?? true) && !!queryAddress && !!poolManager && !!poolId && !!args,
|
|
1789
|
+
refetchInterval: options?.refetchInterval,
|
|
1790
|
+
staleTime: options?.staleTime,
|
|
1791
|
+
gcTime: options?.gcTime
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
function useNativeTokenPrice(panopticPoolAddress, token0Decimals, token1Decimals, nativeIsToken0, options) {
|
|
1795
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
1796
|
+
return useQuery({
|
|
1797
|
+
queryKey: [
|
|
1798
|
+
...queryKeys.all,
|
|
1799
|
+
"nativeTokenPrice",
|
|
1800
|
+
chainId,
|
|
1801
|
+
panopticPoolAddress,
|
|
1802
|
+
token0Decimals,
|
|
1803
|
+
token1Decimals,
|
|
1804
|
+
nativeIsToken0,
|
|
1805
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1806
|
+
],
|
|
1807
|
+
queryFn: () => getNativeTokenPrice({
|
|
1808
|
+
client: publicClient,
|
|
1809
|
+
panopticPoolAddress,
|
|
1810
|
+
token0Decimals,
|
|
1811
|
+
token1Decimals,
|
|
1812
|
+
nativeIsToken0
|
|
1813
|
+
}),
|
|
1814
|
+
enabled: (options?.enabled ?? true) && panopticPoolAddress !== void 0,
|
|
1815
|
+
refetchInterval: options?.refetchInterval ?? 3e4,
|
|
1816
|
+
staleTime: options?.staleTime,
|
|
1817
|
+
gcTime: options?.gcTime
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
function usePreviewBorrow(poolAddress, params, options) {
|
|
1821
|
+
const ctx = usePanopticContext();
|
|
1822
|
+
return useQuery({
|
|
1823
|
+
queryKey: [
|
|
1824
|
+
...queryKeys.all,
|
|
1825
|
+
"previewBorrow",
|
|
1826
|
+
ctx.chainId,
|
|
1827
|
+
poolAddress,
|
|
1828
|
+
params?.account,
|
|
1829
|
+
params?.token,
|
|
1830
|
+
params?.amount?.toString(),
|
|
1831
|
+
params?.slippageBps?.toString(),
|
|
1832
|
+
params?.existingPositionIds?.map(String).join(","),
|
|
1833
|
+
getClientCacheScopeKey(ctx.publicClient, ctx.clientScope)
|
|
1834
|
+
],
|
|
1835
|
+
queryFn: () => previewBorrow({
|
|
1836
|
+
client: ctx.publicClient,
|
|
1837
|
+
poolAddress,
|
|
1838
|
+
chainId: ctx.chainId,
|
|
1839
|
+
account: params.account,
|
|
1840
|
+
token: params.token,
|
|
1841
|
+
amount: params.amount,
|
|
1842
|
+
slippageBps: params.slippageBps,
|
|
1843
|
+
existingPositionIds: params.existingPositionIds
|
|
1844
|
+
}),
|
|
1845
|
+
enabled: (options?.enabled ?? true) && !!params && params.amount > 0n,
|
|
1846
|
+
staleTime: options?.staleTime ?? 1e4,
|
|
1847
|
+
gcTime: options?.gcTime,
|
|
1848
|
+
placeholderData: keepPreviousData
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Validate whether a builder code maps to a deployed builder wallet.
|
|
1853
|
+
*
|
|
1854
|
+
* Returns `{ data: true }` for valid codes, `{ data: false }` for invalid.
|
|
1855
|
+
* Disabled when `builderCode` is `undefined` or `0n`.
|
|
1856
|
+
*/
|
|
1857
|
+
function useValidateBuilderCode(poolAddress, builderCode, options) {
|
|
1858
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
1859
|
+
return useQuery({
|
|
1860
|
+
queryKey: [
|
|
1861
|
+
"validateBuilderCode",
|
|
1862
|
+
poolAddress,
|
|
1863
|
+
String(builderCode),
|
|
1864
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
1865
|
+
],
|
|
1866
|
+
queryFn: () => {
|
|
1867
|
+
if (builderCode === void 0) throw new Error("builderCode is undefined");
|
|
1868
|
+
return validateBuilderCode({
|
|
1869
|
+
client: publicClient,
|
|
1870
|
+
poolAddress,
|
|
1871
|
+
builderCode
|
|
1872
|
+
});
|
|
1873
|
+
},
|
|
1874
|
+
enabled: (options?.enabled ?? true) && builderCode !== void 0 && builderCode !== 0n,
|
|
1875
|
+
staleTime: options?.staleTime ?? 6e4,
|
|
1876
|
+
gcTime: options?.gcTime
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
//#endregion
|
|
1881
|
+
//#region src/panoptic/v2/react/mutationEffects.ts
|
|
1882
|
+
/**
|
|
1883
|
+
* Returns query keys that should be invalidated after a mutation.
|
|
1884
|
+
*
|
|
1885
|
+
* Use with TanStack Query's `queryClient.invalidateQueries()` or SWR's `mutate()`.
|
|
1886
|
+
*
|
|
1887
|
+
* @example
|
|
1888
|
+
* ```typescript
|
|
1889
|
+
* import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
1890
|
+
* import { mutationEffects, openPosition } from 'panoptic-v2-sdk'
|
|
1891
|
+
*
|
|
1892
|
+
* function useOpenPosition(config: WriteConfig) {
|
|
1893
|
+
* const queryClient = useQueryClient()
|
|
1894
|
+
*
|
|
1895
|
+
* return useMutation({
|
|
1896
|
+
* mutationFn: (params) => openPosition(config, params),
|
|
1897
|
+
* onSuccess: () => {
|
|
1898
|
+
* const keysToInvalidate = mutationEffects.openPosition({
|
|
1899
|
+
* chainId: config.chainId,
|
|
1900
|
+
* poolAddress: config.poolAddress,
|
|
1901
|
+
* account: config.walletClient.account.address,
|
|
1902
|
+
* })
|
|
1903
|
+
*
|
|
1904
|
+
* for (const key of keysToInvalidate) {
|
|
1905
|
+
* queryClient.invalidateQueries({ queryKey: key })
|
|
1906
|
+
* }
|
|
1907
|
+
* },
|
|
1908
|
+
* })
|
|
1909
|
+
* }
|
|
1910
|
+
* ```
|
|
1911
|
+
*/
|
|
1912
|
+
const mutationEffects = {
|
|
1913
|
+
openPosition: (params) => {
|
|
1914
|
+
const { chainId, poolAddress, account } = params;
|
|
1915
|
+
return [
|
|
1916
|
+
queryKeys.pool(chainId, poolAddress),
|
|
1917
|
+
queryKeys.utilization(chainId, poolAddress),
|
|
1918
|
+
queryKeys.positions(chainId, poolAddress, account),
|
|
1919
|
+
queryKeys.trackedPositionIds(chainId, poolAddress, account),
|
|
1920
|
+
queryKeys.accountCollateral(chainId, poolAddress, account),
|
|
1921
|
+
queryKeys.accountSummaryBasic(chainId, poolAddress, account),
|
|
1922
|
+
queryKeys.accountSummaryRisk(chainId, poolAddress, account),
|
|
1923
|
+
queryKeys.isLiquidatable(chainId, poolAddress, account),
|
|
1924
|
+
queryKeys.liquidationPrices(chainId, poolAddress, account),
|
|
1925
|
+
queryKeys.accountGreeks(chainId, poolAddress, account),
|
|
1926
|
+
queryKeys.chunkSpreads(chainId, poolAddress)
|
|
1927
|
+
];
|
|
1928
|
+
},
|
|
1929
|
+
closePosition: (params) => {
|
|
1930
|
+
const { chainId, poolAddress, account, tokenId } = params;
|
|
1931
|
+
const keys = [
|
|
1932
|
+
queryKeys.pool(chainId, poolAddress),
|
|
1933
|
+
queryKeys.utilization(chainId, poolAddress),
|
|
1934
|
+
queryKeys.positions(chainId, poolAddress, account),
|
|
1935
|
+
queryKeys.trackedPositionIds(chainId, poolAddress, account),
|
|
1936
|
+
queryKeys.accountCollateral(chainId, poolAddress, account),
|
|
1937
|
+
queryKeys.accountSummaryBasic(chainId, poolAddress, account),
|
|
1938
|
+
queryKeys.accountSummaryRisk(chainId, poolAddress, account),
|
|
1939
|
+
queryKeys.isLiquidatable(chainId, poolAddress, account),
|
|
1940
|
+
queryKeys.liquidationPrices(chainId, poolAddress, account),
|
|
1941
|
+
queryKeys.accountGreeks(chainId, poolAddress, account),
|
|
1942
|
+
queryKeys.closedPositions(chainId, poolAddress, account),
|
|
1943
|
+
queryKeys.tradeHistory(chainId, poolAddress, account),
|
|
1944
|
+
queryKeys.realizedPnL(chainId, poolAddress, account),
|
|
1945
|
+
queryKeys.chunkSpreads(chainId, poolAddress)
|
|
1946
|
+
];
|
|
1947
|
+
if (tokenId !== void 0) {
|
|
1948
|
+
keys.push(queryKeys.position(chainId, poolAddress, tokenId));
|
|
1949
|
+
keys.push(queryKeys.positionGreeks(chainId, poolAddress, tokenId));
|
|
1950
|
+
}
|
|
1951
|
+
return keys;
|
|
1952
|
+
},
|
|
1953
|
+
forceExercise: (params) => {
|
|
1954
|
+
const { chainId, poolAddress, account, tokenId } = params;
|
|
1955
|
+
const keys = [
|
|
1956
|
+
queryKeys.pool(chainId, poolAddress),
|
|
1957
|
+
queryKeys.utilization(chainId, poolAddress),
|
|
1958
|
+
queryKeys.accountCollateral(chainId, poolAddress, account),
|
|
1959
|
+
queryKeys.accountSummaryBasic(chainId, poolAddress, account),
|
|
1960
|
+
queryKeys.accountSummaryRisk(chainId, poolAddress, account),
|
|
1961
|
+
queryKeys.chunkSpreads(chainId, poolAddress)
|
|
1962
|
+
];
|
|
1963
|
+
if (tokenId !== void 0) keys.push(queryKeys.position(chainId, poolAddress, tokenId));
|
|
1964
|
+
return keys;
|
|
1965
|
+
},
|
|
1966
|
+
liquidate: (params) => {
|
|
1967
|
+
const { chainId, poolAddress, account } = params;
|
|
1968
|
+
return [
|
|
1969
|
+
queryKeys.pool(chainId, poolAddress),
|
|
1970
|
+
queryKeys.utilization(chainId, poolAddress),
|
|
1971
|
+
queryKeys.positions(chainId, poolAddress, account),
|
|
1972
|
+
queryKeys.trackedPositionIds(chainId, poolAddress, account),
|
|
1973
|
+
queryKeys.accountCollateral(chainId, poolAddress, account),
|
|
1974
|
+
queryKeys.accountSummaryBasic(chainId, poolAddress, account),
|
|
1975
|
+
queryKeys.accountSummaryRisk(chainId, poolAddress, account),
|
|
1976
|
+
queryKeys.isLiquidatable(chainId, poolAddress, account),
|
|
1977
|
+
queryKeys.liquidationPrices(chainId, poolAddress, account),
|
|
1978
|
+
queryKeys.accountGreeks(chainId, poolAddress, account),
|
|
1979
|
+
queryKeys.closedPositions(chainId, poolAddress, account),
|
|
1980
|
+
queryKeys.chunkSpreads(chainId, poolAddress)
|
|
1981
|
+
];
|
|
1982
|
+
},
|
|
1983
|
+
settleAccumulatedPremia: (params) => {
|
|
1984
|
+
const { chainId, poolAddress, account, tokenId } = params;
|
|
1985
|
+
const keys = [
|
|
1986
|
+
queryKeys.accountCollateral(chainId, poolAddress, account),
|
|
1987
|
+
queryKeys.accountSummaryBasic(chainId, poolAddress, account),
|
|
1988
|
+
queryKeys.accountSummaryRisk(chainId, poolAddress, account)
|
|
1989
|
+
];
|
|
1990
|
+
if (tokenId !== void 0) keys.push(queryKeys.position(chainId, poolAddress, tokenId));
|
|
1991
|
+
return keys;
|
|
1992
|
+
},
|
|
1993
|
+
deposit: (params) => {
|
|
1994
|
+
const { chainId, poolAddress, account } = params;
|
|
1995
|
+
return [
|
|
1996
|
+
queryKeys.accountCollateral(chainId, poolAddress, account),
|
|
1997
|
+
queryKeys.accountSummaryBasic(chainId, poolAddress, account),
|
|
1998
|
+
queryKeys.accountSummaryRisk(chainId, poolAddress, account),
|
|
1999
|
+
queryKeys.isLiquidatable(chainId, poolAddress, account),
|
|
2000
|
+
queryKeys.liquidationPrices(chainId, poolAddress, account)
|
|
2001
|
+
];
|
|
2002
|
+
},
|
|
2003
|
+
withdraw: (params) => {
|
|
2004
|
+
const { chainId, poolAddress, account } = params;
|
|
2005
|
+
return [
|
|
2006
|
+
queryKeys.accountCollateral(chainId, poolAddress, account),
|
|
2007
|
+
queryKeys.accountSummaryBasic(chainId, poolAddress, account),
|
|
2008
|
+
queryKeys.accountSummaryRisk(chainId, poolAddress, account),
|
|
2009
|
+
queryKeys.isLiquidatable(chainId, poolAddress, account),
|
|
2010
|
+
queryKeys.liquidationPrices(chainId, poolAddress, account)
|
|
2011
|
+
];
|
|
2012
|
+
},
|
|
2013
|
+
mint: (params) => {
|
|
2014
|
+
return mutationEffects.deposit(params);
|
|
2015
|
+
},
|
|
2016
|
+
redeem: (params) => {
|
|
2017
|
+
return mutationEffects.withdraw(params);
|
|
2018
|
+
},
|
|
2019
|
+
approve: (chainId, token, owner, spender) => {
|
|
2020
|
+
return [queryKeys.approval(chainId, token, owner, spender)];
|
|
2021
|
+
},
|
|
2022
|
+
pokeOracle: (params) => {
|
|
2023
|
+
const { chainId, poolAddress } = params;
|
|
2024
|
+
return [queryKeys.oracle(chainId, poolAddress), queryKeys.safeMode(chainId, poolAddress)];
|
|
2025
|
+
}
|
|
2026
|
+
};
|
|
2027
|
+
|
|
2028
|
+
//#endregion
|
|
2029
|
+
//#region src/panoptic/v2/react/hooks/writes.ts
|
|
2030
|
+
function requireWallet$2(inputs) {
|
|
2031
|
+
if (!inputs.walletClient || !inputs.account) throw new Error("walletClient and account are required. Provide them via PanopticProvider.");
|
|
2032
|
+
return {
|
|
2033
|
+
walletClient: inputs.walletClient,
|
|
2034
|
+
account: inputs.account
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
function createWalletMutationContext(inputs) {
|
|
2038
|
+
return { signerAccount: requireWallet$2(inputs).account };
|
|
2039
|
+
}
|
|
2040
|
+
function invalidateKeys(queryClient, keysToInvalidate) {
|
|
2041
|
+
const seen = new Set();
|
|
2042
|
+
for (const key of keysToInvalidate) {
|
|
2043
|
+
const serialized = JSON.stringify(key);
|
|
2044
|
+
if (seen.has(serialized)) continue;
|
|
2045
|
+
seen.add(serialized);
|
|
2046
|
+
queryClient.invalidateQueries({ queryKey: key });
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function useApprove() {
|
|
2050
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2051
|
+
const queryClient = useQueryClient();
|
|
2052
|
+
return useMutation({
|
|
2053
|
+
onMutate: () => createWalletMutationContext({
|
|
2054
|
+
walletClient,
|
|
2055
|
+
account
|
|
2056
|
+
}),
|
|
2057
|
+
mutationFn: (params) => {
|
|
2058
|
+
const wallet = requireWallet$2({
|
|
2059
|
+
walletClient,
|
|
2060
|
+
account
|
|
2061
|
+
});
|
|
2062
|
+
return approve({
|
|
2063
|
+
client: publicClient,
|
|
2064
|
+
...wallet,
|
|
2065
|
+
...params
|
|
2066
|
+
});
|
|
2067
|
+
},
|
|
2068
|
+
onSuccess: (_data, params, context) => {
|
|
2069
|
+
if (!context) return;
|
|
2070
|
+
invalidateKeys(queryClient, mutationEffects.approve(chainId, params.tokenAddress, context.signerAccount, params.spenderAddress));
|
|
2071
|
+
}
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
function useApprovePool(poolAddress) {
|
|
2075
|
+
const { publicClient, walletClient, account } = usePanopticContext();
|
|
2076
|
+
const queryClient = useQueryClient();
|
|
2077
|
+
return useMutation({
|
|
2078
|
+
onMutate: () => createWalletMutationContext({
|
|
2079
|
+
walletClient,
|
|
2080
|
+
account
|
|
2081
|
+
}),
|
|
2082
|
+
mutationFn: (params) => {
|
|
2083
|
+
const wallet = requireWallet$2({
|
|
2084
|
+
walletClient,
|
|
2085
|
+
account
|
|
2086
|
+
});
|
|
2087
|
+
return approvePool({
|
|
2088
|
+
client: publicClient,
|
|
2089
|
+
...wallet,
|
|
2090
|
+
poolAddress,
|
|
2091
|
+
...params
|
|
2092
|
+
});
|
|
2093
|
+
},
|
|
2094
|
+
onSuccess: () => {
|
|
2095
|
+
queryClient.invalidateQueries({ queryKey: [...queryKeys.all, "approval"] });
|
|
2096
|
+
}
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
function useDeposit(poolAddress) {
|
|
2100
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2101
|
+
const queryClient = useQueryClient();
|
|
2102
|
+
return useMutation({
|
|
2103
|
+
onMutate: () => createWalletMutationContext({
|
|
2104
|
+
walletClient,
|
|
2105
|
+
account
|
|
2106
|
+
}),
|
|
2107
|
+
mutationFn: (params) => {
|
|
2108
|
+
const wallet = requireWallet$2({
|
|
2109
|
+
walletClient,
|
|
2110
|
+
account
|
|
2111
|
+
});
|
|
2112
|
+
return deposit({
|
|
2113
|
+
client: publicClient,
|
|
2114
|
+
...wallet,
|
|
2115
|
+
...params
|
|
2116
|
+
});
|
|
2117
|
+
},
|
|
2118
|
+
onSuccess: (_data, _params, context) => {
|
|
2119
|
+
if (!context) return;
|
|
2120
|
+
invalidateKeys(queryClient, mutationEffects.deposit({
|
|
2121
|
+
chainId,
|
|
2122
|
+
poolAddress,
|
|
2123
|
+
account: context.signerAccount
|
|
2124
|
+
}));
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
function useWithdraw(poolAddress) {
|
|
2129
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2130
|
+
const queryClient = useQueryClient();
|
|
2131
|
+
return useMutation({
|
|
2132
|
+
onMutate: () => createWalletMutationContext({
|
|
2133
|
+
walletClient,
|
|
2134
|
+
account
|
|
2135
|
+
}),
|
|
2136
|
+
mutationFn: (params) => {
|
|
2137
|
+
const wallet = requireWallet$2({
|
|
2138
|
+
walletClient,
|
|
2139
|
+
account
|
|
2140
|
+
});
|
|
2141
|
+
return withdraw({
|
|
2142
|
+
client: publicClient,
|
|
2143
|
+
...wallet,
|
|
2144
|
+
...params
|
|
2145
|
+
});
|
|
2146
|
+
},
|
|
2147
|
+
onSuccess: (_data, _params, context) => {
|
|
2148
|
+
if (!context) return;
|
|
2149
|
+
invalidateKeys(queryClient, mutationEffects.withdraw({
|
|
2150
|
+
chainId,
|
|
2151
|
+
poolAddress,
|
|
2152
|
+
account: context.signerAccount
|
|
2153
|
+
}));
|
|
2154
|
+
}
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Wrap an underlying xStock into its ERC4626 wrapper (`deposit`). Requires a
|
|
2159
|
+
* prior approval of the underlying to the wrapper (use {@link useApprove}).
|
|
2160
|
+
* Invalidates SDK queries so balances refetch.
|
|
2161
|
+
*/
|
|
2162
|
+
function useWrapXstock() {
|
|
2163
|
+
const { publicClient, walletClient, account } = usePanopticContext();
|
|
2164
|
+
const queryClient = useQueryClient();
|
|
2165
|
+
return useMutation({
|
|
2166
|
+
onMutate: () => createWalletMutationContext({
|
|
2167
|
+
walletClient,
|
|
2168
|
+
account
|
|
2169
|
+
}),
|
|
2170
|
+
mutationFn: (params) => {
|
|
2171
|
+
const wallet = requireWallet$2({
|
|
2172
|
+
walletClient,
|
|
2173
|
+
account
|
|
2174
|
+
});
|
|
2175
|
+
return wrapXstock({
|
|
2176
|
+
client: publicClient,
|
|
2177
|
+
...wallet,
|
|
2178
|
+
...params
|
|
2179
|
+
});
|
|
2180
|
+
},
|
|
2181
|
+
onSuccess: () => {
|
|
2182
|
+
queryClient.invalidateQueries({ queryKey: [...queryKeys.all] });
|
|
2183
|
+
}
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
/**
|
|
2187
|
+
* Unwrap wrapper shares back into the underlying xStock (`redeem`). Burns the
|
|
2188
|
+
* owner's own shares — no approval needed.
|
|
2189
|
+
*/
|
|
2190
|
+
function useUnwrapXstock() {
|
|
2191
|
+
const { publicClient, walletClient, account } = usePanopticContext();
|
|
2192
|
+
const queryClient = useQueryClient();
|
|
2193
|
+
return useMutation({
|
|
2194
|
+
onMutate: () => createWalletMutationContext({
|
|
2195
|
+
walletClient,
|
|
2196
|
+
account
|
|
2197
|
+
}),
|
|
2198
|
+
mutationFn: (params) => {
|
|
2199
|
+
const wallet = requireWallet$2({
|
|
2200
|
+
walletClient,
|
|
2201
|
+
account
|
|
2202
|
+
});
|
|
2203
|
+
return unwrapXstock({
|
|
2204
|
+
client: publicClient,
|
|
2205
|
+
...wallet,
|
|
2206
|
+
...params
|
|
2207
|
+
});
|
|
2208
|
+
},
|
|
2209
|
+
onSuccess: () => {
|
|
2210
|
+
queryClient.invalidateQueries({ queryKey: [...queryKeys.all] });
|
|
2211
|
+
}
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Wrap native ETH into WETH (`deposit` payable). No approval needed.
|
|
2216
|
+
* Invalidates SDK queries so balances refetch.
|
|
2217
|
+
*/
|
|
2218
|
+
function useWrapEth() {
|
|
2219
|
+
const { publicClient, walletClient, account } = usePanopticContext();
|
|
2220
|
+
const queryClient = useQueryClient();
|
|
2221
|
+
return useMutation({
|
|
2222
|
+
onMutate: () => createWalletMutationContext({
|
|
2223
|
+
walletClient,
|
|
2224
|
+
account
|
|
2225
|
+
}),
|
|
2226
|
+
mutationFn: (params) => {
|
|
2227
|
+
const wallet = requireWallet$2({
|
|
2228
|
+
walletClient,
|
|
2229
|
+
account
|
|
2230
|
+
});
|
|
2231
|
+
return wrapEth({
|
|
2232
|
+
client: publicClient,
|
|
2233
|
+
...wallet,
|
|
2234
|
+
...params
|
|
2235
|
+
});
|
|
2236
|
+
},
|
|
2237
|
+
onSuccess: () => {
|
|
2238
|
+
queryClient.invalidateQueries({ queryKey: [...queryKeys.all] });
|
|
2239
|
+
}
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Unwrap WETH back into native ETH (`withdraw`). Burns the caller's own WETH —
|
|
2244
|
+
* no approval needed. Invalidates SDK queries so balances refetch.
|
|
2245
|
+
*/
|
|
2246
|
+
function useUnwrapWeth() {
|
|
2247
|
+
const { publicClient, walletClient, account } = usePanopticContext();
|
|
2248
|
+
const queryClient = useQueryClient();
|
|
2249
|
+
return useMutation({
|
|
2250
|
+
onMutate: () => createWalletMutationContext({
|
|
2251
|
+
walletClient,
|
|
2252
|
+
account
|
|
2253
|
+
}),
|
|
2254
|
+
mutationFn: (params) => {
|
|
2255
|
+
const wallet = requireWallet$2({
|
|
2256
|
+
walletClient,
|
|
2257
|
+
account
|
|
2258
|
+
});
|
|
2259
|
+
return unwrapWeth({
|
|
2260
|
+
client: publicClient,
|
|
2261
|
+
...wallet,
|
|
2262
|
+
...params
|
|
2263
|
+
});
|
|
2264
|
+
},
|
|
2265
|
+
onSuccess: () => {
|
|
2266
|
+
queryClient.invalidateQueries({ queryKey: [...queryKeys.all] });
|
|
2267
|
+
}
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
function useMintShares(poolAddress) {
|
|
2271
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2272
|
+
const queryClient = useQueryClient();
|
|
2273
|
+
return useMutation({
|
|
2274
|
+
onMutate: () => createWalletMutationContext({
|
|
2275
|
+
walletClient,
|
|
2276
|
+
account
|
|
2277
|
+
}),
|
|
2278
|
+
mutationFn: (params) => {
|
|
2279
|
+
const wallet = requireWallet$2({
|
|
2280
|
+
walletClient,
|
|
2281
|
+
account
|
|
2282
|
+
});
|
|
2283
|
+
return mint({
|
|
2284
|
+
client: publicClient,
|
|
2285
|
+
...wallet,
|
|
2286
|
+
...params
|
|
2287
|
+
});
|
|
2288
|
+
},
|
|
2289
|
+
onSuccess: (_data, _params, context) => {
|
|
2290
|
+
if (!context) return;
|
|
2291
|
+
invalidateKeys(queryClient, mutationEffects.mint({
|
|
2292
|
+
chainId,
|
|
2293
|
+
poolAddress,
|
|
2294
|
+
account: context.signerAccount
|
|
2295
|
+
}));
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
function useRedeem(poolAddress) {
|
|
2300
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2301
|
+
const queryClient = useQueryClient();
|
|
2302
|
+
return useMutation({
|
|
2303
|
+
onMutate: () => createWalletMutationContext({
|
|
2304
|
+
walletClient,
|
|
2305
|
+
account
|
|
2306
|
+
}),
|
|
2307
|
+
mutationFn: (params) => {
|
|
2308
|
+
const wallet = requireWallet$2({
|
|
2309
|
+
walletClient,
|
|
2310
|
+
account
|
|
2311
|
+
});
|
|
2312
|
+
return redeem({
|
|
2313
|
+
client: publicClient,
|
|
2314
|
+
...wallet,
|
|
2315
|
+
...params
|
|
2316
|
+
});
|
|
2317
|
+
},
|
|
2318
|
+
onSuccess: (_data, _params, context) => {
|
|
2319
|
+
if (!context) return;
|
|
2320
|
+
invalidateKeys(queryClient, mutationEffects.redeem({
|
|
2321
|
+
chainId,
|
|
2322
|
+
poolAddress,
|
|
2323
|
+
account: context.signerAccount
|
|
2324
|
+
}));
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
function useWithdrawWithPositions(poolAddress) {
|
|
2329
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2330
|
+
const queryClient = useQueryClient();
|
|
2331
|
+
return useMutation({
|
|
2332
|
+
onMutate: () => createWalletMutationContext({
|
|
2333
|
+
walletClient,
|
|
2334
|
+
account
|
|
2335
|
+
}),
|
|
2336
|
+
mutationFn: (params) => {
|
|
2337
|
+
const wallet = requireWallet$2({
|
|
2338
|
+
walletClient,
|
|
2339
|
+
account
|
|
2340
|
+
});
|
|
2341
|
+
return withdrawWithPositions({
|
|
2342
|
+
client: publicClient,
|
|
2343
|
+
...wallet,
|
|
2344
|
+
...params
|
|
2345
|
+
});
|
|
2346
|
+
},
|
|
2347
|
+
onSuccess: (_data, _params, context) => {
|
|
2348
|
+
if (!context) return;
|
|
2349
|
+
invalidateKeys(queryClient, mutationEffects.withdraw({
|
|
2350
|
+
chainId,
|
|
2351
|
+
poolAddress,
|
|
2352
|
+
account: context.signerAccount
|
|
2353
|
+
}));
|
|
2354
|
+
}
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
function useOpenPosition(poolAddress) {
|
|
2358
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2359
|
+
const queryClient = useQueryClient();
|
|
2360
|
+
return useMutation({
|
|
2361
|
+
onMutate: () => createWalletMutationContext({
|
|
2362
|
+
walletClient,
|
|
2363
|
+
account
|
|
2364
|
+
}),
|
|
2365
|
+
mutationFn: (params) => {
|
|
2366
|
+
const wallet = requireWallet$2({
|
|
2367
|
+
walletClient,
|
|
2368
|
+
account
|
|
2369
|
+
});
|
|
2370
|
+
return openPosition({
|
|
2371
|
+
client: publicClient,
|
|
2372
|
+
...wallet,
|
|
2373
|
+
poolAddress,
|
|
2374
|
+
...params
|
|
2375
|
+
});
|
|
2376
|
+
},
|
|
2377
|
+
onSuccess: (_data, _params, context) => {
|
|
2378
|
+
if (!context) return;
|
|
2379
|
+
invalidateKeys(queryClient, mutationEffects.openPosition({
|
|
2380
|
+
chainId,
|
|
2381
|
+
poolAddress,
|
|
2382
|
+
account: context.signerAccount
|
|
2383
|
+
}));
|
|
2384
|
+
}
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2387
|
+
function useClosePosition(poolAddress) {
|
|
2388
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2389
|
+
const queryClient = useQueryClient();
|
|
2390
|
+
return useMutation({
|
|
2391
|
+
onMutate: () => createWalletMutationContext({
|
|
2392
|
+
walletClient,
|
|
2393
|
+
account
|
|
2394
|
+
}),
|
|
2395
|
+
mutationFn: (params) => {
|
|
2396
|
+
const wallet = requireWallet$2({
|
|
2397
|
+
walletClient,
|
|
2398
|
+
account
|
|
2399
|
+
});
|
|
2400
|
+
return closePosition({
|
|
2401
|
+
client: publicClient,
|
|
2402
|
+
...wallet,
|
|
2403
|
+
poolAddress,
|
|
2404
|
+
...params
|
|
2405
|
+
});
|
|
2406
|
+
},
|
|
2407
|
+
onSuccess: (_data, params, context) => {
|
|
2408
|
+
if (!context) return;
|
|
2409
|
+
invalidateKeys(queryClient, mutationEffects.closePosition({
|
|
2410
|
+
chainId,
|
|
2411
|
+
poolAddress,
|
|
2412
|
+
account: context.signerAccount,
|
|
2413
|
+
tokenId: params.tokenId
|
|
2414
|
+
}));
|
|
2415
|
+
}
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
function useRollPosition(poolAddress) {
|
|
2419
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2420
|
+
const queryClient = useQueryClient();
|
|
2421
|
+
return useMutation({
|
|
2422
|
+
onMutate: () => createWalletMutationContext({
|
|
2423
|
+
walletClient,
|
|
2424
|
+
account
|
|
2425
|
+
}),
|
|
2426
|
+
mutationFn: (params) => {
|
|
2427
|
+
const wallet = requireWallet$2({
|
|
2428
|
+
walletClient,
|
|
2429
|
+
account
|
|
2430
|
+
});
|
|
2431
|
+
return rollPosition({
|
|
2432
|
+
client: publicClient,
|
|
2433
|
+
...wallet,
|
|
2434
|
+
poolAddress,
|
|
2435
|
+
...params
|
|
2436
|
+
});
|
|
2437
|
+
},
|
|
2438
|
+
onSuccess: (_data, _params, context) => {
|
|
2439
|
+
if (!context) return;
|
|
2440
|
+
invalidateKeys(queryClient, mutationEffects.openPosition({
|
|
2441
|
+
chainId,
|
|
2442
|
+
poolAddress,
|
|
2443
|
+
account: context.signerAccount
|
|
2444
|
+
}));
|
|
2445
|
+
}
|
|
2446
|
+
});
|
|
2447
|
+
}
|
|
2448
|
+
function useLiquidate(poolAddress) {
|
|
2449
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2450
|
+
const queryClient = useQueryClient();
|
|
2451
|
+
return useMutation({
|
|
2452
|
+
onMutate: () => createWalletMutationContext({
|
|
2453
|
+
walletClient,
|
|
2454
|
+
account
|
|
2455
|
+
}),
|
|
2456
|
+
mutationFn: (params) => {
|
|
2457
|
+
const wallet = requireWallet$2({
|
|
2458
|
+
walletClient,
|
|
2459
|
+
account
|
|
2460
|
+
});
|
|
2461
|
+
return liquidate({
|
|
2462
|
+
client: publicClient,
|
|
2463
|
+
...wallet,
|
|
2464
|
+
poolAddress,
|
|
2465
|
+
...params
|
|
2466
|
+
});
|
|
2467
|
+
},
|
|
2468
|
+
onSuccess: (_data, params, context) => {
|
|
2469
|
+
if (!context) return;
|
|
2470
|
+
invalidateKeys(queryClient, [...mutationEffects.liquidate({
|
|
2471
|
+
chainId,
|
|
2472
|
+
poolAddress,
|
|
2473
|
+
account: context.signerAccount
|
|
2474
|
+
}), ...mutationEffects.liquidate({
|
|
2475
|
+
chainId,
|
|
2476
|
+
poolAddress,
|
|
2477
|
+
account: params.liquidatee
|
|
2478
|
+
})]);
|
|
2479
|
+
}
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
function useForceExercise(poolAddress) {
|
|
2483
|
+
const { publicClient, chainId, walletClient, account, storage } = usePanopticContext();
|
|
2484
|
+
const queryClient = useQueryClient();
|
|
2485
|
+
return useMutation({
|
|
2486
|
+
onMutate: () => createWalletMutationContext({
|
|
2487
|
+
walletClient,
|
|
2488
|
+
account
|
|
2489
|
+
}),
|
|
2490
|
+
mutationFn: (params) => {
|
|
2491
|
+
const wallet = requireWallet$2({
|
|
2492
|
+
walletClient,
|
|
2493
|
+
account
|
|
2494
|
+
});
|
|
2495
|
+
return forceExerciseAndWait({
|
|
2496
|
+
client: publicClient,
|
|
2497
|
+
...wallet,
|
|
2498
|
+
poolAddress,
|
|
2499
|
+
...params,
|
|
2500
|
+
storage,
|
|
2501
|
+
chainId
|
|
2502
|
+
});
|
|
2503
|
+
},
|
|
2504
|
+
onSuccess: (_data, params, context) => {
|
|
2505
|
+
if (!context) return;
|
|
2506
|
+
invalidateKeys(queryClient, [...mutationEffects.forceExercise({
|
|
2507
|
+
chainId,
|
|
2508
|
+
poolAddress,
|
|
2509
|
+
account: context.signerAccount
|
|
2510
|
+
}), ...mutationEffects.forceExercise({
|
|
2511
|
+
chainId,
|
|
2512
|
+
poolAddress,
|
|
2513
|
+
account: params.user
|
|
2514
|
+
})]);
|
|
2515
|
+
}
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
function useSettleAccumulatedPremia(poolAddress) {
|
|
2519
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2520
|
+
const queryClient = useQueryClient();
|
|
2521
|
+
return useMutation({
|
|
2522
|
+
onMutate: () => createWalletMutationContext({
|
|
2523
|
+
walletClient,
|
|
2524
|
+
account
|
|
2525
|
+
}),
|
|
2526
|
+
mutationFn: (params) => {
|
|
2527
|
+
const wallet = requireWallet$2({
|
|
2528
|
+
walletClient,
|
|
2529
|
+
account
|
|
2530
|
+
});
|
|
2531
|
+
return settleAccumulatedPremia({
|
|
2532
|
+
client: publicClient,
|
|
2533
|
+
...wallet,
|
|
2534
|
+
poolAddress,
|
|
2535
|
+
...params
|
|
2536
|
+
});
|
|
2537
|
+
},
|
|
2538
|
+
onSuccess: (_data, _params, context) => {
|
|
2539
|
+
if (!context) return;
|
|
2540
|
+
invalidateKeys(queryClient, mutationEffects.settleAccumulatedPremia({
|
|
2541
|
+
chainId,
|
|
2542
|
+
poolAddress,
|
|
2543
|
+
account: context.signerAccount
|
|
2544
|
+
}));
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
}
|
|
2548
|
+
function usePokeOracle(poolAddress) {
|
|
2549
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2550
|
+
const queryClient = useQueryClient();
|
|
2551
|
+
return useMutation({
|
|
2552
|
+
onMutate: () => createWalletMutationContext({
|
|
2553
|
+
walletClient,
|
|
2554
|
+
account
|
|
2555
|
+
}),
|
|
2556
|
+
mutationFn: (params) => {
|
|
2557
|
+
const wallet = requireWallet$2({
|
|
2558
|
+
walletClient,
|
|
2559
|
+
account
|
|
2560
|
+
});
|
|
2561
|
+
return pokeOracle({
|
|
2562
|
+
client: publicClient,
|
|
2563
|
+
...wallet,
|
|
2564
|
+
poolAddress,
|
|
2565
|
+
...params
|
|
2566
|
+
});
|
|
2567
|
+
},
|
|
2568
|
+
onSuccess: () => {
|
|
2569
|
+
invalidateKeys(queryClient, mutationEffects.pokeOracle({
|
|
2570
|
+
chainId,
|
|
2571
|
+
poolAddress
|
|
2572
|
+
}));
|
|
2573
|
+
}
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
function useDispatch(poolAddress) {
|
|
2577
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2578
|
+
const queryClient = useQueryClient();
|
|
2579
|
+
return useMutation({
|
|
2580
|
+
onMutate: () => createWalletMutationContext({
|
|
2581
|
+
walletClient,
|
|
2582
|
+
account
|
|
2583
|
+
}),
|
|
2584
|
+
mutationFn: (params) => {
|
|
2585
|
+
const wallet = requireWallet$2({
|
|
2586
|
+
walletClient,
|
|
2587
|
+
account
|
|
2588
|
+
});
|
|
2589
|
+
return dispatch({
|
|
2590
|
+
client: publicClient,
|
|
2591
|
+
...wallet,
|
|
2592
|
+
poolAddress,
|
|
2593
|
+
...params
|
|
2594
|
+
});
|
|
2595
|
+
},
|
|
2596
|
+
onSuccess: (_data, _params, context) => {
|
|
2597
|
+
if (!context) return;
|
|
2598
|
+
invalidateKeys(queryClient, mutationEffects.openPosition({
|
|
2599
|
+
chainId,
|
|
2600
|
+
poolAddress,
|
|
2601
|
+
account: context.signerAccount
|
|
2602
|
+
}));
|
|
2603
|
+
}
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
function useBatchDispatch(poolAddress) {
|
|
2607
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2608
|
+
const queryClient = useQueryClient();
|
|
2609
|
+
return useMutation({
|
|
2610
|
+
onMutate: () => createWalletMutationContext({
|
|
2611
|
+
walletClient,
|
|
2612
|
+
account
|
|
2613
|
+
}),
|
|
2614
|
+
mutationFn: (params) => {
|
|
2615
|
+
const wallet = requireWallet$2({
|
|
2616
|
+
walletClient,
|
|
2617
|
+
account
|
|
2618
|
+
});
|
|
2619
|
+
return executeBatchDispatch({
|
|
2620
|
+
client: publicClient,
|
|
2621
|
+
...wallet,
|
|
2622
|
+
poolAddress,
|
|
2623
|
+
...params
|
|
2624
|
+
});
|
|
2625
|
+
},
|
|
2626
|
+
onSuccess: (_data, params, context) => {
|
|
2627
|
+
if (!context) return;
|
|
2628
|
+
const closedTokenIds = params.items.filter((i) => i.kind === "burn").map((i) => i.tokenId);
|
|
2629
|
+
const keys = [...mutationEffects.openPosition({
|
|
2630
|
+
chainId,
|
|
2631
|
+
poolAddress,
|
|
2632
|
+
account: context.signerAccount
|
|
2633
|
+
}), ...closedTokenIds.flatMap((tokenId) => mutationEffects.closePosition({
|
|
2634
|
+
chainId,
|
|
2635
|
+
poolAddress,
|
|
2636
|
+
account: context.signerAccount,
|
|
2637
|
+
tokenId
|
|
2638
|
+
}))];
|
|
2639
|
+
invalidateKeys(queryClient, keys);
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2643
|
+
function useDeployNewPool() {
|
|
2644
|
+
const { publicClient, walletClient, account } = usePanopticContext();
|
|
2645
|
+
const queryClient = useQueryClient();
|
|
2646
|
+
return useMutation({
|
|
2647
|
+
onMutate: () => createWalletMutationContext({
|
|
2648
|
+
walletClient,
|
|
2649
|
+
account
|
|
2650
|
+
}),
|
|
2651
|
+
mutationFn: (params) => {
|
|
2652
|
+
const wallet = requireWallet$2({
|
|
2653
|
+
walletClient,
|
|
2654
|
+
account
|
|
2655
|
+
});
|
|
2656
|
+
return deployNewPool({
|
|
2657
|
+
client: publicClient,
|
|
2658
|
+
...wallet,
|
|
2659
|
+
...params
|
|
2660
|
+
});
|
|
2661
|
+
},
|
|
2662
|
+
onSuccess: () => {
|
|
2663
|
+
queryClient.invalidateQueries({ queryKey: [...queryKeys.all, "factory"] });
|
|
2664
|
+
}
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
function useSwapExactOut(poolAddress) {
|
|
2668
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2669
|
+
const queryClient = useQueryClient();
|
|
2670
|
+
return useMutation({
|
|
2671
|
+
onMutate: () => createWalletMutationContext({
|
|
2672
|
+
walletClient,
|
|
2673
|
+
account
|
|
2674
|
+
}),
|
|
2675
|
+
mutationFn: (params) => {
|
|
2676
|
+
const wallet = requireWallet$2({
|
|
2677
|
+
walletClient,
|
|
2678
|
+
account
|
|
2679
|
+
});
|
|
2680
|
+
return swapExactOut({
|
|
2681
|
+
client: publicClient,
|
|
2682
|
+
...wallet,
|
|
2683
|
+
poolAddress,
|
|
2684
|
+
chainId,
|
|
2685
|
+
...params
|
|
2686
|
+
});
|
|
2687
|
+
},
|
|
2688
|
+
onSuccess: (_data, _params, context) => {
|
|
2689
|
+
if (!context) return;
|
|
2690
|
+
invalidateKeys(queryClient, mutationEffects.deposit({
|
|
2691
|
+
chainId,
|
|
2692
|
+
poolAddress,
|
|
2693
|
+
account: context.signerAccount
|
|
2694
|
+
}));
|
|
2695
|
+
}
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
function useSupply(poolAddress) {
|
|
2699
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2700
|
+
const queryClient = useQueryClient();
|
|
2701
|
+
return useMutation({
|
|
2702
|
+
onMutate: () => createWalletMutationContext({
|
|
2703
|
+
walletClient,
|
|
2704
|
+
account
|
|
2705
|
+
}),
|
|
2706
|
+
mutationFn: (params) => {
|
|
2707
|
+
const wallet = requireWallet$2({
|
|
2708
|
+
walletClient,
|
|
2709
|
+
account
|
|
2710
|
+
});
|
|
2711
|
+
return supply({
|
|
2712
|
+
client: publicClient,
|
|
2713
|
+
...wallet,
|
|
2714
|
+
poolAddress,
|
|
2715
|
+
chainId,
|
|
2716
|
+
...params
|
|
2717
|
+
});
|
|
2718
|
+
},
|
|
2719
|
+
onSuccess: (_data, _params, context) => {
|
|
2720
|
+
if (!context) return;
|
|
2721
|
+
invalidateKeys(queryClient, mutationEffects.deposit({
|
|
2722
|
+
chainId,
|
|
2723
|
+
poolAddress,
|
|
2724
|
+
account: context.signerAccount
|
|
2725
|
+
}));
|
|
2726
|
+
}
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
function useUnsupply(poolAddress) {
|
|
2730
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2731
|
+
const queryClient = useQueryClient();
|
|
2732
|
+
return useMutation({
|
|
2733
|
+
onMutate: () => createWalletMutationContext({
|
|
2734
|
+
walletClient,
|
|
2735
|
+
account
|
|
2736
|
+
}),
|
|
2737
|
+
mutationFn: (params) => {
|
|
2738
|
+
const wallet = requireWallet$2({
|
|
2739
|
+
walletClient,
|
|
2740
|
+
account
|
|
2741
|
+
});
|
|
2742
|
+
return unsupply({
|
|
2743
|
+
client: publicClient,
|
|
2744
|
+
...wallet,
|
|
2745
|
+
poolAddress,
|
|
2746
|
+
chainId,
|
|
2747
|
+
...params
|
|
2748
|
+
});
|
|
2749
|
+
},
|
|
2750
|
+
onSuccess: (_data, _params, context) => {
|
|
2751
|
+
if (!context) return;
|
|
2752
|
+
invalidateKeys(queryClient, mutationEffects.withdraw({
|
|
2753
|
+
chainId,
|
|
2754
|
+
poolAddress,
|
|
2755
|
+
account: context.signerAccount
|
|
2756
|
+
}));
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
function useBorrow(poolAddress) {
|
|
2761
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2762
|
+
const queryClient = useQueryClient();
|
|
2763
|
+
return useMutation({
|
|
2764
|
+
onMutate: () => createWalletMutationContext({
|
|
2765
|
+
walletClient,
|
|
2766
|
+
account
|
|
2767
|
+
}),
|
|
2768
|
+
mutationFn: (params) => {
|
|
2769
|
+
const wallet = requireWallet$2({
|
|
2770
|
+
walletClient,
|
|
2771
|
+
account
|
|
2772
|
+
});
|
|
2773
|
+
return borrow({
|
|
2774
|
+
client: publicClient,
|
|
2775
|
+
...wallet,
|
|
2776
|
+
poolAddress,
|
|
2777
|
+
chainId,
|
|
2778
|
+
...params
|
|
2779
|
+
});
|
|
2780
|
+
},
|
|
2781
|
+
onSuccess: (_data, _params, context) => {
|
|
2782
|
+
if (!context) return;
|
|
2783
|
+
invalidateKeys(queryClient, mutationEffects.openPosition({
|
|
2784
|
+
chainId,
|
|
2785
|
+
poolAddress,
|
|
2786
|
+
account: context.signerAccount
|
|
2787
|
+
}));
|
|
2788
|
+
}
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
function useRepay(poolAddress) {
|
|
2792
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2793
|
+
const queryClient = useQueryClient();
|
|
2794
|
+
return useMutation({
|
|
2795
|
+
onMutate: () => createWalletMutationContext({
|
|
2796
|
+
walletClient,
|
|
2797
|
+
account
|
|
2798
|
+
}),
|
|
2799
|
+
mutationFn: (params) => {
|
|
2800
|
+
const wallet = requireWallet$2({
|
|
2801
|
+
walletClient,
|
|
2802
|
+
account
|
|
2803
|
+
});
|
|
2804
|
+
return repay({
|
|
2805
|
+
client: publicClient,
|
|
2806
|
+
...wallet,
|
|
2807
|
+
poolAddress,
|
|
2808
|
+
chainId,
|
|
2809
|
+
...params
|
|
2810
|
+
});
|
|
2811
|
+
},
|
|
2812
|
+
onSuccess: (_data, params, context) => {
|
|
2813
|
+
if (!context) return;
|
|
2814
|
+
invalidateKeys(queryClient, mutationEffects.closePosition({
|
|
2815
|
+
chainId,
|
|
2816
|
+
poolAddress,
|
|
2817
|
+
account: context.signerAccount,
|
|
2818
|
+
tokenId: params.loanTokenId
|
|
2819
|
+
}));
|
|
2820
|
+
}
|
|
2821
|
+
});
|
|
2822
|
+
}
|
|
2823
|
+
function useSmartRepay(poolAddress) {
|
|
2824
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2825
|
+
const queryClient = useQueryClient();
|
|
2826
|
+
return useMutation({
|
|
2827
|
+
onMutate: () => createWalletMutationContext({
|
|
2828
|
+
walletClient,
|
|
2829
|
+
account
|
|
2830
|
+
}),
|
|
2831
|
+
mutationFn: (params) => {
|
|
2832
|
+
const wallet = requireWallet$2({
|
|
2833
|
+
walletClient,
|
|
2834
|
+
account
|
|
2835
|
+
});
|
|
2836
|
+
return smartRepay({
|
|
2837
|
+
client: publicClient,
|
|
2838
|
+
...wallet,
|
|
2839
|
+
poolAddress,
|
|
2840
|
+
chainId,
|
|
2841
|
+
...params
|
|
2842
|
+
});
|
|
2843
|
+
},
|
|
2844
|
+
onSuccess: (_data, _params, context) => {
|
|
2845
|
+
if (!context) return;
|
|
2846
|
+
invalidateKeys(queryClient, mutationEffects.closePosition({
|
|
2847
|
+
chainId,
|
|
2848
|
+
poolAddress,
|
|
2849
|
+
account: context.signerAccount
|
|
2850
|
+
}));
|
|
2851
|
+
}
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
function useSwapExactIn(poolAddress) {
|
|
2855
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
2856
|
+
const queryClient = useQueryClient();
|
|
2857
|
+
return useMutation({
|
|
2858
|
+
onMutate: () => createWalletMutationContext({
|
|
2859
|
+
walletClient,
|
|
2860
|
+
account
|
|
2861
|
+
}),
|
|
2862
|
+
mutationFn: (params) => {
|
|
2863
|
+
const wallet = requireWallet$2({
|
|
2864
|
+
walletClient,
|
|
2865
|
+
account
|
|
2866
|
+
});
|
|
2867
|
+
return swapExactIn({
|
|
2868
|
+
client: publicClient,
|
|
2869
|
+
...wallet,
|
|
2870
|
+
poolAddress,
|
|
2871
|
+
chainId,
|
|
2872
|
+
...params
|
|
2873
|
+
});
|
|
2874
|
+
},
|
|
2875
|
+
onSuccess: (_data, _params, context) => {
|
|
2876
|
+
if (!context) return;
|
|
2877
|
+
invalidateKeys(queryClient, mutationEffects.deposit({
|
|
2878
|
+
chainId,
|
|
2879
|
+
poolAddress,
|
|
2880
|
+
account: context.signerAccount
|
|
2881
|
+
}));
|
|
2882
|
+
}
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
//#endregion
|
|
2887
|
+
//#region src/panoptic/v2/react/hooks/simulations.ts
|
|
2888
|
+
function useSimulateOpenPosition(poolAddress, params) {
|
|
2889
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
2890
|
+
return useQuery({
|
|
2891
|
+
queryKey: [
|
|
2892
|
+
...queryKeys.all,
|
|
2893
|
+
"sim",
|
|
2894
|
+
"openPosition",
|
|
2895
|
+
poolAddress,
|
|
2896
|
+
params?.tokenId?.toString(),
|
|
2897
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
2898
|
+
params
|
|
2899
|
+
],
|
|
2900
|
+
queryFn: () => simulateOpenPosition({
|
|
2901
|
+
client: publicClient,
|
|
2902
|
+
poolAddress,
|
|
2903
|
+
...params
|
|
2904
|
+
}),
|
|
2905
|
+
enabled: params !== void 0,
|
|
2906
|
+
staleTime: 0
|
|
2907
|
+
});
|
|
2908
|
+
}
|
|
2909
|
+
function useSimulateClosePosition(poolAddress, params) {
|
|
2910
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
2911
|
+
return useQuery({
|
|
2912
|
+
queryKey: [
|
|
2913
|
+
...queryKeys.all,
|
|
2914
|
+
"sim",
|
|
2915
|
+
"closePosition",
|
|
2916
|
+
poolAddress,
|
|
2917
|
+
params?.tokenId?.toString(),
|
|
2918
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
2919
|
+
params
|
|
2920
|
+
],
|
|
2921
|
+
queryFn: () => simulateClosePosition({
|
|
2922
|
+
client: publicClient,
|
|
2923
|
+
poolAddress,
|
|
2924
|
+
...params
|
|
2925
|
+
}),
|
|
2926
|
+
enabled: params !== void 0,
|
|
2927
|
+
staleTime: 0
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
function useSimulateDeposit(params) {
|
|
2931
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
2932
|
+
return useQuery({
|
|
2933
|
+
queryKey: [
|
|
2934
|
+
...queryKeys.all,
|
|
2935
|
+
"sim",
|
|
2936
|
+
"deposit",
|
|
2937
|
+
params?.collateralTrackerAddress,
|
|
2938
|
+
params?.assets?.toString(),
|
|
2939
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
2940
|
+
params
|
|
2941
|
+
],
|
|
2942
|
+
queryFn: () => simulateDeposit({
|
|
2943
|
+
client: publicClient,
|
|
2944
|
+
...params
|
|
2945
|
+
}),
|
|
2946
|
+
enabled: params !== void 0,
|
|
2947
|
+
staleTime: 0
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
function useSimulateWithdraw(params) {
|
|
2951
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
2952
|
+
return useQuery({
|
|
2953
|
+
queryKey: [
|
|
2954
|
+
...queryKeys.all,
|
|
2955
|
+
"sim",
|
|
2956
|
+
"withdraw",
|
|
2957
|
+
params?.collateralTrackerAddress,
|
|
2958
|
+
params?.assets?.toString(),
|
|
2959
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
2960
|
+
params
|
|
2961
|
+
],
|
|
2962
|
+
queryFn: () => simulateWithdraw({
|
|
2963
|
+
client: publicClient,
|
|
2964
|
+
...params
|
|
2965
|
+
}),
|
|
2966
|
+
enabled: params !== void 0,
|
|
2967
|
+
staleTime: 0
|
|
2968
|
+
});
|
|
2969
|
+
}
|
|
2970
|
+
function useSimulateLiquidate(poolAddress, params) {
|
|
2971
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
2972
|
+
return useQuery({
|
|
2973
|
+
queryKey: [
|
|
2974
|
+
...queryKeys.all,
|
|
2975
|
+
"sim",
|
|
2976
|
+
"liquidate",
|
|
2977
|
+
poolAddress,
|
|
2978
|
+
params?.liquidatee,
|
|
2979
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
2980
|
+
params
|
|
2981
|
+
],
|
|
2982
|
+
queryFn: () => simulateLiquidate({
|
|
2983
|
+
client: publicClient,
|
|
2984
|
+
poolAddress,
|
|
2985
|
+
...params
|
|
2986
|
+
}),
|
|
2987
|
+
enabled: params !== void 0,
|
|
2988
|
+
staleTime: 0
|
|
2989
|
+
});
|
|
2990
|
+
}
|
|
2991
|
+
function useSimulateForceExercise(poolAddress, params) {
|
|
2992
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
2993
|
+
return useQuery({
|
|
2994
|
+
queryKey: [
|
|
2995
|
+
...queryKeys.all,
|
|
2996
|
+
"sim",
|
|
2997
|
+
"forceExercise",
|
|
2998
|
+
poolAddress,
|
|
2999
|
+
params?.user,
|
|
3000
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3001
|
+
params
|
|
3002
|
+
],
|
|
3003
|
+
queryFn: () => simulateForceExercise({
|
|
3004
|
+
client: publicClient,
|
|
3005
|
+
poolAddress,
|
|
3006
|
+
...params
|
|
3007
|
+
}),
|
|
3008
|
+
enabled: params !== void 0,
|
|
3009
|
+
staleTime: 0
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
function useSimulateSettle(poolAddress, params) {
|
|
3013
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
3014
|
+
return useQuery({
|
|
3015
|
+
queryKey: [
|
|
3016
|
+
...queryKeys.all,
|
|
3017
|
+
"sim",
|
|
3018
|
+
"settle",
|
|
3019
|
+
poolAddress,
|
|
3020
|
+
params?.account,
|
|
3021
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3022
|
+
params
|
|
3023
|
+
],
|
|
3024
|
+
queryFn: () => simulateSettle({
|
|
3025
|
+
client: publicClient,
|
|
3026
|
+
poolAddress,
|
|
3027
|
+
...params
|
|
3028
|
+
}),
|
|
3029
|
+
enabled: params !== void 0,
|
|
3030
|
+
staleTime: 0
|
|
3031
|
+
});
|
|
3032
|
+
}
|
|
3033
|
+
function useSimulateBatchDispatch(poolAddress, params) {
|
|
3034
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
3035
|
+
return useQuery({
|
|
3036
|
+
queryKey: [
|
|
3037
|
+
...queryKeys.all,
|
|
3038
|
+
"sim",
|
|
3039
|
+
"batchDispatch",
|
|
3040
|
+
poolAddress,
|
|
3041
|
+
params?.account,
|
|
3042
|
+
params?.items?.length,
|
|
3043
|
+
JSON.stringify(params?.items?.map((i) => `${i.kind}:${i.tokenId.toString()}`)),
|
|
3044
|
+
JSON.stringify(params?.existingPositionIds?.map(String)),
|
|
3045
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3046
|
+
params
|
|
3047
|
+
],
|
|
3048
|
+
queryFn: () => simulateBatchDispatch({
|
|
3049
|
+
client: publicClient,
|
|
3050
|
+
poolAddress,
|
|
3051
|
+
...params
|
|
3052
|
+
}),
|
|
3053
|
+
enabled: params !== void 0 && params.items !== void 0,
|
|
3054
|
+
staleTime: 0
|
|
3055
|
+
});
|
|
3056
|
+
}
|
|
3057
|
+
function useSimulateDispatch(poolAddress, params) {
|
|
3058
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
3059
|
+
return useQuery({
|
|
3060
|
+
queryKey: [
|
|
3061
|
+
...queryKeys.all,
|
|
3062
|
+
"sim",
|
|
3063
|
+
"dispatch",
|
|
3064
|
+
poolAddress,
|
|
3065
|
+
JSON.stringify(params?.positionIdList?.map(String)),
|
|
3066
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3067
|
+
params
|
|
3068
|
+
],
|
|
3069
|
+
queryFn: () => simulateDispatch({
|
|
3070
|
+
client: publicClient,
|
|
3071
|
+
poolAddress,
|
|
3072
|
+
...params
|
|
3073
|
+
}),
|
|
3074
|
+
enabled: params !== void 0,
|
|
3075
|
+
staleTime: 0
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
function useSimulateSFPMMint(params) {
|
|
3079
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
3080
|
+
return useQuery({
|
|
3081
|
+
queryKey: [
|
|
3082
|
+
...queryKeys.all,
|
|
3083
|
+
"sim",
|
|
3084
|
+
"sfpmMint",
|
|
3085
|
+
params?.sfpmAddress,
|
|
3086
|
+
params?.tokenId?.toString(),
|
|
3087
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3088
|
+
params
|
|
3089
|
+
],
|
|
3090
|
+
queryFn: () => {
|
|
3091
|
+
if (!params) throw new Error("params required for simulateSFPMMint");
|
|
3092
|
+
return simulateSFPMMint({
|
|
3093
|
+
client: publicClient,
|
|
3094
|
+
...params
|
|
3095
|
+
});
|
|
3096
|
+
},
|
|
3097
|
+
enabled: params !== void 0,
|
|
3098
|
+
staleTime: 0
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
function useSimulateSFPMBurn(params) {
|
|
3102
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
3103
|
+
return useQuery({
|
|
3104
|
+
queryKey: [
|
|
3105
|
+
...queryKeys.all,
|
|
3106
|
+
"sim",
|
|
3107
|
+
"sfpmBurn",
|
|
3108
|
+
params?.sfpmAddress,
|
|
3109
|
+
params?.tokenId?.toString(),
|
|
3110
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3111
|
+
params
|
|
3112
|
+
],
|
|
3113
|
+
queryFn: () => {
|
|
3114
|
+
if (!params) throw new Error("params required for simulateSFPMBurn");
|
|
3115
|
+
return simulateSFPMBurn({
|
|
3116
|
+
client: publicClient,
|
|
3117
|
+
...params
|
|
3118
|
+
});
|
|
3119
|
+
},
|
|
3120
|
+
enabled: params !== void 0,
|
|
3121
|
+
staleTime: 0
|
|
3122
|
+
});
|
|
3123
|
+
}
|
|
3124
|
+
function useSimulateSwapExactOut(poolAddress, params) {
|
|
3125
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
3126
|
+
return useQuery({
|
|
3127
|
+
queryKey: [
|
|
3128
|
+
...queryKeys.all,
|
|
3129
|
+
"sim",
|
|
3130
|
+
"swapExactOut",
|
|
3131
|
+
poolAddress,
|
|
3132
|
+
params?.tokenOut,
|
|
3133
|
+
params?.amountOut?.toString(),
|
|
3134
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3135
|
+
params
|
|
3136
|
+
],
|
|
3137
|
+
queryFn: () => simulateSwapExactOut({
|
|
3138
|
+
client: publicClient,
|
|
3139
|
+
poolAddress,
|
|
3140
|
+
...params
|
|
3141
|
+
}),
|
|
3142
|
+
enabled: params !== void 0,
|
|
3143
|
+
staleTime: 0
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
function useSimulateSwapExactIn(poolAddress, params) {
|
|
3147
|
+
const { publicClient, clientScope } = usePanopticContext();
|
|
3148
|
+
return useQuery({
|
|
3149
|
+
queryKey: [
|
|
3150
|
+
...queryKeys.all,
|
|
3151
|
+
"sim",
|
|
3152
|
+
"swapExactIn",
|
|
3153
|
+
poolAddress,
|
|
3154
|
+
params?.tokenIn,
|
|
3155
|
+
params?.amountIn?.toString(),
|
|
3156
|
+
getClientCacheScopeKey(publicClient, clientScope),
|
|
3157
|
+
params
|
|
3158
|
+
],
|
|
3159
|
+
queryFn: () => simulateSwapExactIn({
|
|
3160
|
+
client: publicClient,
|
|
3161
|
+
poolAddress,
|
|
3162
|
+
...params
|
|
3163
|
+
}),
|
|
3164
|
+
enabled: params !== void 0,
|
|
3165
|
+
staleTime: 0
|
|
3166
|
+
});
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
//#endregion
|
|
3170
|
+
//#region src/panoptic/v2/react/hooks/uniswapRouter.ts
|
|
3171
|
+
function requireWallet$1(walletClient, account) {
|
|
3172
|
+
if (!walletClient || !account) throw new PanopticError("walletClient and account are required. Provide them via PanopticProvider.");
|
|
3173
|
+
return {
|
|
3174
|
+
walletClient,
|
|
3175
|
+
account
|
|
3176
|
+
};
|
|
3177
|
+
}
|
|
3178
|
+
/**
|
|
3179
|
+
* Quote an exact-in spot swap via the Universal Router (V4Quoter-backed).
|
|
3180
|
+
* Returns a `SimulationResult`, matching `useSimulateSwapExactIn`'s shape.
|
|
3181
|
+
*/
|
|
3182
|
+
function useQuoteSwapExactInViaRouter(poolAddress, params) {
|
|
3183
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
3184
|
+
return useQuery({
|
|
3185
|
+
queryKey: [
|
|
3186
|
+
...queryKeys.all,
|
|
3187
|
+
"uniswapRouter",
|
|
3188
|
+
"quote",
|
|
3189
|
+
chainId,
|
|
3190
|
+
poolAddress,
|
|
3191
|
+
params?.tokenIn,
|
|
3192
|
+
params?.amountIn?.toString(),
|
|
3193
|
+
params?.slippageBps?.toString(),
|
|
3194
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
3195
|
+
],
|
|
3196
|
+
queryFn: () => quoteSwapExactInViaRouter({
|
|
3197
|
+
client: publicClient,
|
|
3198
|
+
poolAddress,
|
|
3199
|
+
chainId,
|
|
3200
|
+
...params
|
|
3201
|
+
}),
|
|
3202
|
+
enabled: params !== void 0,
|
|
3203
|
+
staleTime: 0
|
|
3204
|
+
});
|
|
3205
|
+
}
|
|
3206
|
+
/**
|
|
3207
|
+
* Quote an exact-out spot swap via the Universal Router (V4Quoter-backed).
|
|
3208
|
+
* Returns a `SimulationResult` carrying the required input + `amountInMaximum`.
|
|
3209
|
+
*/
|
|
3210
|
+
function useQuoteSwapExactOutViaRouter(poolAddress, params) {
|
|
3211
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
3212
|
+
return useQuery({
|
|
3213
|
+
queryKey: [
|
|
3214
|
+
...queryKeys.all,
|
|
3215
|
+
"uniswapRouter",
|
|
3216
|
+
"quoteExactOut",
|
|
3217
|
+
chainId,
|
|
3218
|
+
poolAddress,
|
|
3219
|
+
params?.tokenIn,
|
|
3220
|
+
params?.amountOut?.toString(),
|
|
3221
|
+
params?.slippageBps?.toString(),
|
|
3222
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
3223
|
+
],
|
|
3224
|
+
queryFn: () => quoteSwapExactOutViaRouter({
|
|
3225
|
+
client: publicClient,
|
|
3226
|
+
poolAddress,
|
|
3227
|
+
chainId,
|
|
3228
|
+
...params
|
|
3229
|
+
}),
|
|
3230
|
+
enabled: params !== void 0,
|
|
3231
|
+
staleTime: 0
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
/**
|
|
3235
|
+
* Check the ERC20 → Permit2 → Universal Router allowance chain.
|
|
3236
|
+
*/
|
|
3237
|
+
function useCheckRouterApproval(params) {
|
|
3238
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
3239
|
+
return useQuery({
|
|
3240
|
+
queryKey: [
|
|
3241
|
+
...queryKeys.all,
|
|
3242
|
+
"uniswapRouter",
|
|
3243
|
+
"approval",
|
|
3244
|
+
chainId,
|
|
3245
|
+
params?.tokenIn,
|
|
3246
|
+
params?.owner,
|
|
3247
|
+
params?.amount?.toString(),
|
|
3248
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
3249
|
+
],
|
|
3250
|
+
queryFn: () => checkRouterApproval({
|
|
3251
|
+
client: publicClient,
|
|
3252
|
+
chainId,
|
|
3253
|
+
...params
|
|
3254
|
+
}),
|
|
3255
|
+
enabled: params !== void 0,
|
|
3256
|
+
staleTime: 0
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
/**
|
|
3260
|
+
* Execute an exact-in spot swap via the Universal Router.
|
|
3261
|
+
*/
|
|
3262
|
+
function useSwapExactInViaRouter(poolAddress) {
|
|
3263
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
3264
|
+
const queryClient = useQueryClient();
|
|
3265
|
+
return useMutation({
|
|
3266
|
+
mutationFn: (params) => {
|
|
3267
|
+
const wallet = requireWallet$1(walletClient, account);
|
|
3268
|
+
return swapExactInViaRouter({
|
|
3269
|
+
client: publicClient,
|
|
3270
|
+
...wallet,
|
|
3271
|
+
poolAddress,
|
|
3272
|
+
chainId,
|
|
3273
|
+
...params
|
|
3274
|
+
});
|
|
3275
|
+
},
|
|
3276
|
+
onSuccess: () => {
|
|
3277
|
+
if (!account) return;
|
|
3278
|
+
for (const key of mutationEffects.deposit({
|
|
3279
|
+
chainId,
|
|
3280
|
+
poolAddress,
|
|
3281
|
+
account
|
|
3282
|
+
})) queryClient.invalidateQueries({ queryKey: key });
|
|
3283
|
+
}
|
|
3284
|
+
});
|
|
3285
|
+
}
|
|
3286
|
+
/**
|
|
3287
|
+
* Execute an exact-out spot swap via the Universal Router.
|
|
3288
|
+
*/
|
|
3289
|
+
function useSwapExactOutViaRouter(poolAddress) {
|
|
3290
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
3291
|
+
const queryClient = useQueryClient();
|
|
3292
|
+
return useMutation({
|
|
3293
|
+
mutationFn: (params) => {
|
|
3294
|
+
const wallet = requireWallet$1(walletClient, account);
|
|
3295
|
+
return swapExactOutViaRouter({
|
|
3296
|
+
client: publicClient,
|
|
3297
|
+
...wallet,
|
|
3298
|
+
poolAddress,
|
|
3299
|
+
chainId,
|
|
3300
|
+
...params
|
|
3301
|
+
});
|
|
3302
|
+
},
|
|
3303
|
+
onSuccess: () => {
|
|
3304
|
+
if (!account) return;
|
|
3305
|
+
for (const key of mutationEffects.deposit({
|
|
3306
|
+
chainId,
|
|
3307
|
+
poolAddress,
|
|
3308
|
+
account
|
|
3309
|
+
})) queryClient.invalidateQueries({ queryKey: key });
|
|
3310
|
+
}
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
/**
|
|
3314
|
+
* Step 1 approval mutation: ERC20 → Permit2.
|
|
3315
|
+
*/
|
|
3316
|
+
function useApproveErc20ForPermit2() {
|
|
3317
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
3318
|
+
return useMutation({ mutationFn: (params) => {
|
|
3319
|
+
const wallet = requireWallet$1(walletClient, account);
|
|
3320
|
+
return approveErc20ForPermit2({
|
|
3321
|
+
client: publicClient,
|
|
3322
|
+
...wallet,
|
|
3323
|
+
chainId,
|
|
3324
|
+
...params
|
|
3325
|
+
});
|
|
3326
|
+
} });
|
|
3327
|
+
}
|
|
3328
|
+
/**
|
|
3329
|
+
* Step 2 approval mutation: Permit2 → Universal Router.
|
|
3330
|
+
*/
|
|
3331
|
+
function useApproveRouterViaPermit2() {
|
|
3332
|
+
const { publicClient, chainId, walletClient, account } = usePanopticContext();
|
|
3333
|
+
return useMutation({ mutationFn: (params) => {
|
|
3334
|
+
const wallet = requireWallet$1(walletClient, account);
|
|
3335
|
+
return approveRouterViaPermit2({
|
|
3336
|
+
client: publicClient,
|
|
3337
|
+
...wallet,
|
|
3338
|
+
chainId,
|
|
3339
|
+
...params
|
|
3340
|
+
});
|
|
3341
|
+
} });
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
//#endregion
|
|
3345
|
+
//#region src/panoptic/v2/react/hooks/cowSwap.ts
|
|
3346
|
+
function requireWallet(walletClient, account) {
|
|
3347
|
+
if (!walletClient || !account) throw new PanopticError("walletClient and account are required. Provide them via PanopticProvider.");
|
|
3348
|
+
return {
|
|
3349
|
+
walletClient,
|
|
3350
|
+
account
|
|
3351
|
+
};
|
|
3352
|
+
}
|
|
3353
|
+
/** How often open-order status is re-polled (ms). */
|
|
3354
|
+
const ORDER_POLL_INTERVAL_MS = 5e3;
|
|
3355
|
+
/** How often quotes refresh (ms) — CoW quotes go stale quickly. */
|
|
3356
|
+
const QUOTE_REFETCH_INTERVAL_MS = 15e3;
|
|
3357
|
+
/**
|
|
3358
|
+
* Placeholder order owner for quotes when no wallet is connected — the order
|
|
3359
|
+
* book accepts any non-zero `from` for quoting (verification happens at order
|
|
3360
|
+
* submission, which always uses the real account).
|
|
3361
|
+
*/
|
|
3362
|
+
const QUOTE_STUB_FROM = "0x0000000000000000000000000000000000000001";
|
|
3363
|
+
/**
|
|
3364
|
+
* Quote a swap via the CoW order book. The connected account (or a stub when
|
|
3365
|
+
* disconnected) is used as the order owner (`from`); disabled while the chain
|
|
3366
|
+
* has no order book.
|
|
3367
|
+
*/
|
|
3368
|
+
function useQuoteCowSwap(params) {
|
|
3369
|
+
const { publicClient, chainId, account, clientScope } = usePanopticContext();
|
|
3370
|
+
return useQuery({
|
|
3371
|
+
queryKey: [
|
|
3372
|
+
...queryKeys.all,
|
|
3373
|
+
"cowSwap",
|
|
3374
|
+
"quote",
|
|
3375
|
+
chainId,
|
|
3376
|
+
params?.sellToken,
|
|
3377
|
+
params?.buyToken,
|
|
3378
|
+
params?.kind,
|
|
3379
|
+
params?.amount?.toString(),
|
|
3380
|
+
params?.slippageBps?.toString(),
|
|
3381
|
+
account,
|
|
3382
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
3383
|
+
],
|
|
3384
|
+
queryFn: () => quoteCowSwap({
|
|
3385
|
+
chainId,
|
|
3386
|
+
from: account ?? QUOTE_STUB_FROM,
|
|
3387
|
+
...params
|
|
3388
|
+
}),
|
|
3389
|
+
enabled: params !== void 0 && isCowSupportedChain(chainId),
|
|
3390
|
+
staleTime: 0,
|
|
3391
|
+
refetchInterval: QUOTE_REFETCH_INTERVAL_MS
|
|
3392
|
+
});
|
|
3393
|
+
}
|
|
3394
|
+
/** Check the ERC20 → GPv2VaultRelayer allowance for the sell token. */
|
|
3395
|
+
function useCheckCowApproval(params) {
|
|
3396
|
+
const { publicClient, chainId, clientScope } = usePanopticContext();
|
|
3397
|
+
return useQuery({
|
|
3398
|
+
queryKey: [
|
|
3399
|
+
...queryKeys.all,
|
|
3400
|
+
"cowSwap",
|
|
3401
|
+
"approval",
|
|
3402
|
+
chainId,
|
|
3403
|
+
params?.sellToken,
|
|
3404
|
+
params?.owner,
|
|
3405
|
+
params?.amount?.toString(),
|
|
3406
|
+
getClientCacheScopeKey(publicClient, clientScope)
|
|
3407
|
+
],
|
|
3408
|
+
queryFn: () => checkCowApproval({
|
|
3409
|
+
client: publicClient,
|
|
3410
|
+
...params
|
|
3411
|
+
}),
|
|
3412
|
+
enabled: params !== void 0,
|
|
3413
|
+
staleTime: 0
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
/** Approval mutation: ERC20 → GPv2VaultRelayer (single step, no Permit2). */
|
|
3417
|
+
function useApproveErc20ForCow() {
|
|
3418
|
+
const { publicClient, walletClient, account } = usePanopticContext();
|
|
3419
|
+
const queryClient = useQueryClient();
|
|
3420
|
+
return useMutation({
|
|
3421
|
+
mutationFn: (params) => {
|
|
3422
|
+
const wallet = requireWallet(walletClient, account);
|
|
3423
|
+
return approveErc20ForCow({
|
|
3424
|
+
client: publicClient,
|
|
3425
|
+
...wallet,
|
|
3426
|
+
...params
|
|
3427
|
+
});
|
|
3428
|
+
},
|
|
3429
|
+
onSuccess: () => {
|
|
3430
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
3431
|
+
...queryKeys.all,
|
|
3432
|
+
"cowSwap",
|
|
3433
|
+
"approval"
|
|
3434
|
+
] });
|
|
3435
|
+
}
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* Sign an order (EIP-712) and post it to the order book. Resolves with the
|
|
3440
|
+
* order UID — not a tx hash; settlement is asynchronous.
|
|
3441
|
+
*/
|
|
3442
|
+
function useSubmitCowOrder() {
|
|
3443
|
+
const { chainId, walletClient, account } = usePanopticContext();
|
|
3444
|
+
return useMutation({ mutationFn: (params) => {
|
|
3445
|
+
const wallet = requireWallet(walletClient, account);
|
|
3446
|
+
return signAndSubmitCowOrder({
|
|
3447
|
+
...wallet,
|
|
3448
|
+
chainId,
|
|
3449
|
+
...params
|
|
3450
|
+
});
|
|
3451
|
+
} });
|
|
3452
|
+
}
|
|
3453
|
+
/**
|
|
3454
|
+
* Poll an order's lifecycle state every few seconds while it is open; polling
|
|
3455
|
+
* stops automatically once the order reaches a terminal state.
|
|
3456
|
+
*/
|
|
3457
|
+
function useCowOrderStatus(orderUid) {
|
|
3458
|
+
const { chainId } = usePanopticContext();
|
|
3459
|
+
return useQuery({
|
|
3460
|
+
queryKey: [
|
|
3461
|
+
...queryKeys.all,
|
|
3462
|
+
"cowSwap",
|
|
3463
|
+
"orderStatus",
|
|
3464
|
+
chainId,
|
|
3465
|
+
orderUid
|
|
3466
|
+
],
|
|
3467
|
+
queryFn: () => getCowOrderStatus({
|
|
3468
|
+
chainId,
|
|
3469
|
+
orderUid
|
|
3470
|
+
}),
|
|
3471
|
+
enabled: orderUid !== void 0,
|
|
3472
|
+
refetchInterval: (query) => {
|
|
3473
|
+
const status = query.state.data?.status;
|
|
3474
|
+
return status === void 0 || status === "open" || status === "presignaturePending" ? ORDER_POLL_INTERVAL_MS : false;
|
|
3475
|
+
}
|
|
3476
|
+
});
|
|
3477
|
+
}
|
|
3478
|
+
/** Off-chain (signed, free) order cancellation mutation. */
|
|
3479
|
+
function useCancelCowOrder() {
|
|
3480
|
+
const { chainId, walletClient, account } = usePanopticContext();
|
|
3481
|
+
return useMutation({ mutationFn: (params) => {
|
|
3482
|
+
const wallet = requireWallet(walletClient, account);
|
|
3483
|
+
return cancelCowOrder({
|
|
3484
|
+
...wallet,
|
|
3485
|
+
chainId,
|
|
3486
|
+
...params
|
|
3487
|
+
});
|
|
3488
|
+
} });
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3491
|
+
//#endregion
|
|
3492
|
+
//#region src/panoptic/v2/react/hooks/sync.ts
|
|
3493
|
+
/**
|
|
3494
|
+
* Hook for syncing positions with progress tracking.
|
|
3495
|
+
*/
|
|
3496
|
+
function useSyncPositions(poolAddress) {
|
|
3497
|
+
const { publicClient, chainId } = usePanopticContext();
|
|
3498
|
+
const storage = useRequireStorage();
|
|
3499
|
+
const account = usePanopticContext().account;
|
|
3500
|
+
const queryClient = useQueryClient();
|
|
3501
|
+
const [progress, setProgress] = useState(null);
|
|
3502
|
+
const mutation = useMutation({
|
|
3503
|
+
mutationFn: async (params) => {
|
|
3504
|
+
if (!account) throw new Error("account is required for sync");
|
|
3505
|
+
const result = await syncPositions({
|
|
3506
|
+
client: publicClient,
|
|
3507
|
+
chainId,
|
|
3508
|
+
poolAddress,
|
|
3509
|
+
account,
|
|
3510
|
+
storage,
|
|
3511
|
+
fromBlock: params?.fromBlock,
|
|
3512
|
+
toBlock: params?.toBlock,
|
|
3513
|
+
onUpdate: setProgress
|
|
3514
|
+
});
|
|
3515
|
+
return result;
|
|
3516
|
+
},
|
|
3517
|
+
onSuccess: () => {
|
|
3518
|
+
if (!account) return;
|
|
3519
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.trackedPositionIds(chainId, poolAddress, account) });
|
|
3520
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.syncStatus(chainId, poolAddress, account) });
|
|
3521
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.positions(chainId, poolAddress, account) });
|
|
3522
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.closedPositions(chainId, poolAddress, account) });
|
|
3523
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.tradeHistory(chainId, poolAddress, account) });
|
|
3524
|
+
}
|
|
3525
|
+
});
|
|
3526
|
+
return {
|
|
3527
|
+
...mutation,
|
|
3528
|
+
progress
|
|
3529
|
+
};
|
|
3530
|
+
}
|
|
3531
|
+
/**
|
|
3532
|
+
* Hook for adding a pending position (optimistic update).
|
|
3533
|
+
*/
|
|
3534
|
+
function useAddPendingPosition(poolAddress) {
|
|
3535
|
+
const { chainId } = usePanopticContext();
|
|
3536
|
+
const storage = useRequireStorage();
|
|
3537
|
+
const account = usePanopticContext().account;
|
|
3538
|
+
const queryClient = useQueryClient();
|
|
3539
|
+
return useMutation({
|
|
3540
|
+
mutationFn: (position) => {
|
|
3541
|
+
if (!account) throw new Error("account is required");
|
|
3542
|
+
return addPendingPosition({
|
|
3543
|
+
chainId,
|
|
3544
|
+
poolAddress,
|
|
3545
|
+
account,
|
|
3546
|
+
storage,
|
|
3547
|
+
position
|
|
3548
|
+
});
|
|
3549
|
+
},
|
|
3550
|
+
onSuccess: () => {
|
|
3551
|
+
if (!account) return;
|
|
3552
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.trackedPositionIds(chainId, poolAddress, account) });
|
|
3553
|
+
}
|
|
3554
|
+
});
|
|
3555
|
+
}
|
|
3556
|
+
/**
|
|
3557
|
+
* Hook for confirming a pending position.
|
|
3558
|
+
*/
|
|
3559
|
+
function useConfirmPendingPosition(poolAddress) {
|
|
3560
|
+
const { chainId } = usePanopticContext();
|
|
3561
|
+
const storage = useRequireStorage();
|
|
3562
|
+
const account = usePanopticContext().account;
|
|
3563
|
+
const queryClient = useQueryClient();
|
|
3564
|
+
return useMutation({
|
|
3565
|
+
mutationFn: (tokenId) => {
|
|
3566
|
+
if (!account) throw new Error("account is required");
|
|
3567
|
+
return confirmPendingPosition({
|
|
3568
|
+
chainId,
|
|
3569
|
+
poolAddress,
|
|
3570
|
+
account,
|
|
3571
|
+
storage,
|
|
3572
|
+
tokenId
|
|
3573
|
+
});
|
|
3574
|
+
},
|
|
3575
|
+
onSuccess: () => {
|
|
3576
|
+
if (!account) return;
|
|
3577
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.trackedPositionIds(chainId, poolAddress, account) });
|
|
3578
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.positions(chainId, poolAddress, account) });
|
|
3579
|
+
}
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
/**
|
|
3583
|
+
* Hook for marking a pending position as failed.
|
|
3584
|
+
*/
|
|
3585
|
+
function useFailPendingPosition(poolAddress) {
|
|
3586
|
+
const { chainId } = usePanopticContext();
|
|
3587
|
+
const storage = useRequireStorage();
|
|
3588
|
+
const account = usePanopticContext().account;
|
|
3589
|
+
const queryClient = useQueryClient();
|
|
3590
|
+
return useMutation({
|
|
3591
|
+
mutationFn: (txHash) => {
|
|
3592
|
+
if (!account) throw new Error("account is required");
|
|
3593
|
+
return failPendingPosition({
|
|
3594
|
+
chainId,
|
|
3595
|
+
poolAddress,
|
|
3596
|
+
account,
|
|
3597
|
+
storage,
|
|
3598
|
+
txHash
|
|
3599
|
+
});
|
|
3600
|
+
},
|
|
3601
|
+
onSuccess: () => {
|
|
3602
|
+
if (!account) return;
|
|
3603
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.trackedPositionIds(chainId, poolAddress, account) });
|
|
3604
|
+
}
|
|
3605
|
+
});
|
|
3606
|
+
}
|
|
3607
|
+
/**
|
|
3608
|
+
* Hook for clearing all tracked positions.
|
|
3609
|
+
*/
|
|
3610
|
+
function useClearTrackedPositions(poolAddress) {
|
|
3611
|
+
const { chainId } = usePanopticContext();
|
|
3612
|
+
const storage = useRequireStorage();
|
|
3613
|
+
const account = usePanopticContext().account;
|
|
3614
|
+
const queryClient = useQueryClient();
|
|
3615
|
+
return useMutation({
|
|
3616
|
+
mutationFn: () => {
|
|
3617
|
+
if (!account) throw new Error("account is required");
|
|
3618
|
+
return clearTrackedPositions({
|
|
3619
|
+
chainId,
|
|
3620
|
+
poolAddress,
|
|
3621
|
+
account,
|
|
3622
|
+
storage
|
|
3623
|
+
});
|
|
3624
|
+
},
|
|
3625
|
+
onSuccess: () => {
|
|
3626
|
+
if (!account) return;
|
|
3627
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.trackedPositionIds(chainId, poolAddress, account) });
|
|
3628
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.positions(chainId, poolAddress, account) });
|
|
3629
|
+
}
|
|
3630
|
+
});
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3633
|
+
//#endregion
|
|
3634
|
+
//#region src/panoptic/v2/react/hooks/events.ts
|
|
3635
|
+
/**
|
|
3636
|
+
* Watch events via WebSocket. Returns cleanup automatically on unmount.
|
|
3637
|
+
*/
|
|
3638
|
+
function useWatchEvents(poolAddress, eventTypes, onEvent, options) {
|
|
3639
|
+
const { publicClient } = usePanopticContext();
|
|
3640
|
+
const onEventRef = useRef(onEvent);
|
|
3641
|
+
onEventRef.current = onEvent;
|
|
3642
|
+
const onErrorRef = useRef(options?.onError);
|
|
3643
|
+
onErrorRef.current = options?.onError;
|
|
3644
|
+
const eventTypesKey = eventTypes?.join(",");
|
|
3645
|
+
useEffect(() => {
|
|
3646
|
+
if (options?.enabled === false) return;
|
|
3647
|
+
const unwatch = watchEvents({
|
|
3648
|
+
client: publicClient,
|
|
3649
|
+
poolAddress,
|
|
3650
|
+
eventTypes,
|
|
3651
|
+
collateralTracker0: options?.collateralTracker0,
|
|
3652
|
+
collateralTracker1: options?.collateralTracker1,
|
|
3653
|
+
riskEngineAddress: options?.riskEngineAddress,
|
|
3654
|
+
sfpmAddress: options?.sfpmAddress,
|
|
3655
|
+
poolManagerAddress: options?.poolManagerAddress,
|
|
3656
|
+
onLogs: (events) => onEventRef.current(events),
|
|
3657
|
+
onError: (error) => onErrorRef.current?.(error)
|
|
3658
|
+
});
|
|
3659
|
+
return unwatch;
|
|
3660
|
+
}, [
|
|
3661
|
+
publicClient,
|
|
3662
|
+
poolAddress,
|
|
3663
|
+
options?.enabled,
|
|
3664
|
+
options?.collateralTracker0,
|
|
3665
|
+
options?.collateralTracker1,
|
|
3666
|
+
options?.riskEngineAddress,
|
|
3667
|
+
options?.sfpmAddress,
|
|
3668
|
+
options?.poolManagerAddress,
|
|
3669
|
+
eventTypesKey
|
|
3670
|
+
]);
|
|
3671
|
+
}
|
|
3672
|
+
/**
|
|
3673
|
+
* Create a resilient event subscription with auto-reconnect.
|
|
3674
|
+
*/
|
|
3675
|
+
function useEventSubscription(poolAddress, eventTypes, onEvent, options) {
|
|
3676
|
+
const { publicClient } = usePanopticContext();
|
|
3677
|
+
const onEventRef = useRef(onEvent);
|
|
3678
|
+
onEventRef.current = onEvent;
|
|
3679
|
+
const onErrorRef = useRef(options?.onError);
|
|
3680
|
+
onErrorRef.current = options?.onError;
|
|
3681
|
+
const onReconnectRef = useRef(options?.onReconnect);
|
|
3682
|
+
onReconnectRef.current = options?.onReconnect;
|
|
3683
|
+
const onConnectedRef = useRef(options?.onConnected);
|
|
3684
|
+
onConnectedRef.current = options?.onConnected;
|
|
3685
|
+
const eventTypesKey = eventTypes?.join(",");
|
|
3686
|
+
useEffect(() => {
|
|
3687
|
+
if (options?.enabled === false) return;
|
|
3688
|
+
const handle = createEventSubscription({
|
|
3689
|
+
client: publicClient,
|
|
3690
|
+
poolAddress,
|
|
3691
|
+
eventTypes,
|
|
3692
|
+
collateralTracker0: options?.collateralTracker0,
|
|
3693
|
+
collateralTracker1: options?.collateralTracker1,
|
|
3694
|
+
riskEngineAddress: options?.riskEngineAddress,
|
|
3695
|
+
sfpmAddress: options?.sfpmAddress,
|
|
3696
|
+
poolManagerAddress: options?.poolManagerAddress,
|
|
3697
|
+
onLogs: (events) => onEventRef.current(events),
|
|
3698
|
+
onError: (error) => onErrorRef.current?.(error),
|
|
3699
|
+
onReconnect: (attempt, delay) => onReconnectRef.current?.(attempt, delay),
|
|
3700
|
+
onConnected: () => onConnectedRef.current?.()
|
|
3701
|
+
});
|
|
3702
|
+
handle.start();
|
|
3703
|
+
return () => handle.stop();
|
|
3704
|
+
}, [
|
|
3705
|
+
publicClient,
|
|
3706
|
+
poolAddress,
|
|
3707
|
+
options?.enabled,
|
|
3708
|
+
options?.collateralTracker0,
|
|
3709
|
+
options?.collateralTracker1,
|
|
3710
|
+
options?.riskEngineAddress,
|
|
3711
|
+
options?.sfpmAddress,
|
|
3712
|
+
options?.poolManagerAddress,
|
|
3713
|
+
eventTypesKey
|
|
3714
|
+
]);
|
|
3715
|
+
}
|
|
3716
|
+
/**
|
|
3717
|
+
* Create an HTTP polling event fetcher.
|
|
3718
|
+
*/
|
|
3719
|
+
function useEventPoller(poolAddress, eventTypes, onEvent, options) {
|
|
3720
|
+
const { publicClient } = usePanopticContext();
|
|
3721
|
+
const onEventRef = useRef(onEvent);
|
|
3722
|
+
onEventRef.current = onEvent;
|
|
3723
|
+
const onErrorRef = useRef(options?.onError);
|
|
3724
|
+
onErrorRef.current = options?.onError;
|
|
3725
|
+
const eventTypesKey = eventTypes?.join(",");
|
|
3726
|
+
useEffect(() => {
|
|
3727
|
+
if (options?.enabled === false) return;
|
|
3728
|
+
const poller = createEventPoller({
|
|
3729
|
+
client: publicClient,
|
|
3730
|
+
poolAddress,
|
|
3731
|
+
eventTypes,
|
|
3732
|
+
collateralTracker0: options?.collateralTracker0,
|
|
3733
|
+
collateralTracker1: options?.collateralTracker1,
|
|
3734
|
+
riskEngineAddress: options?.riskEngineAddress,
|
|
3735
|
+
sfpmAddress: options?.sfpmAddress,
|
|
3736
|
+
poolManagerAddress: options?.poolManagerAddress,
|
|
3737
|
+
intervalMs: options?.intervalMs,
|
|
3738
|
+
onLogs: (events) => onEventRef.current(events),
|
|
3739
|
+
onError: (error) => onErrorRef.current?.(error)
|
|
3740
|
+
});
|
|
3741
|
+
poller.start();
|
|
3742
|
+
return () => poller.stop();
|
|
3743
|
+
}, [
|
|
3744
|
+
publicClient,
|
|
3745
|
+
poolAddress,
|
|
3746
|
+
options?.enabled,
|
|
3747
|
+
options?.intervalMs,
|
|
3748
|
+
options?.collateralTracker0,
|
|
3749
|
+
options?.collateralTracker1,
|
|
3750
|
+
options?.riskEngineAddress,
|
|
3751
|
+
options?.sfpmAddress,
|
|
3752
|
+
options?.poolManagerAddress,
|
|
3753
|
+
eventTypesKey
|
|
3754
|
+
]);
|
|
3755
|
+
}
|
|
3756
|
+
/**
|
|
3757
|
+
* Confirms a transaction by watching for its corresponding on-chain event.
|
|
3758
|
+
*
|
|
3759
|
+
* An event log only exists in a confirmed (non-reverted) transaction, so
|
|
3760
|
+
* matching on `transactionHash` is sufficient proof of 1-block inclusion.
|
|
3761
|
+
* This bypasses the N-block confirmation wait of `useWaitForTransactionReceipt`,
|
|
3762
|
+
* making it faster on chains with high confirmation counts (e.g. Base = 150 blocks).
|
|
3763
|
+
*
|
|
3764
|
+
* Use alongside `useWaitForTransactionReceipt` (confirmations: 1) for revert
|
|
3765
|
+
* detection — reverted transactions emit no events.
|
|
3766
|
+
*
|
|
3767
|
+
* @example
|
|
3768
|
+
* ```tsx
|
|
3769
|
+
* const confirmation = useTxEventConfirmation({
|
|
3770
|
+
* txHash: write.data,
|
|
3771
|
+
* poolAddress,
|
|
3772
|
+
* eventType: 'OptionMinted',
|
|
3773
|
+
* enabled: write.data !== undefined,
|
|
3774
|
+
* })
|
|
3775
|
+
*
|
|
3776
|
+
* useEffect(() => {
|
|
3777
|
+
* if (confirmation.isSuccess) onSuccess?.()
|
|
3778
|
+
* }, [confirmation.isSuccess])
|
|
3779
|
+
* ```
|
|
3780
|
+
*/
|
|
3781
|
+
function useTxEventConfirmation({ txHash, poolAddress = zeroAddress, collateralTrackerAddress, eventType, enabled = true, intervalMs = 3000n }) {
|
|
3782
|
+
const { publicClient } = usePanopticContext();
|
|
3783
|
+
const [data, setData] = useState();
|
|
3784
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
3785
|
+
const txHashRef = useRef(txHash);
|
|
3786
|
+
txHashRef.current = txHash;
|
|
3787
|
+
const confirmedRef = useRef(false);
|
|
3788
|
+
const pollerRef = useRef(null);
|
|
3789
|
+
useEffect(() => {
|
|
3790
|
+
confirmedRef.current = false;
|
|
3791
|
+
setData(void 0);
|
|
3792
|
+
if (!txHash || !enabled) {
|
|
3793
|
+
pollerRef.current?.stop();
|
|
3794
|
+
pollerRef.current = null;
|
|
3795
|
+
setIsLoading(false);
|
|
3796
|
+
return;
|
|
3797
|
+
}
|
|
3798
|
+
setIsLoading(true);
|
|
3799
|
+
let cancelled = false;
|
|
3800
|
+
publicClient.getBlockNumber().then((currentBlock) => {
|
|
3801
|
+
if (cancelled) return;
|
|
3802
|
+
const fromBlock = currentBlock > 0n ? currentBlock - 1n : 0n;
|
|
3803
|
+
const poller = createEventPoller({
|
|
3804
|
+
client: publicClient,
|
|
3805
|
+
poolAddress,
|
|
3806
|
+
collateralTracker0: collateralTrackerAddress,
|
|
3807
|
+
eventTypes: [eventType],
|
|
3808
|
+
intervalMs,
|
|
3809
|
+
fromBlock,
|
|
3810
|
+
onLogs: (events) => {
|
|
3811
|
+
const hash = txHashRef.current;
|
|
3812
|
+
if (!hash || confirmedRef.current) return;
|
|
3813
|
+
const match = events.find((e) => e.transactionHash === hash);
|
|
3814
|
+
if (match) {
|
|
3815
|
+
confirmedRef.current = true;
|
|
3816
|
+
pollerRef.current?.stop();
|
|
3817
|
+
pollerRef.current = null;
|
|
3818
|
+
setIsLoading(false);
|
|
3819
|
+
setData(match);
|
|
3820
|
+
}
|
|
3821
|
+
}
|
|
3822
|
+
});
|
|
3823
|
+
pollerRef.current = poller;
|
|
3824
|
+
poller.start();
|
|
3825
|
+
}).catch(() => {
|
|
3826
|
+
if (cancelled || confirmedRef.current) return;
|
|
3827
|
+
pollerRef.current?.stop();
|
|
3828
|
+
pollerRef.current = null;
|
|
3829
|
+
setIsLoading(false);
|
|
3830
|
+
});
|
|
3831
|
+
return () => {
|
|
3832
|
+
cancelled = true;
|
|
3833
|
+
pollerRef.current?.stop();
|
|
3834
|
+
pollerRef.current = null;
|
|
3835
|
+
};
|
|
3836
|
+
}, [
|
|
3837
|
+
txHash,
|
|
3838
|
+
enabled,
|
|
3839
|
+
publicClient,
|
|
3840
|
+
poolAddress,
|
|
3841
|
+
collateralTrackerAddress,
|
|
3842
|
+
eventType,
|
|
3843
|
+
intervalMs
|
|
3844
|
+
]);
|
|
3845
|
+
return {
|
|
3846
|
+
data,
|
|
3847
|
+
isLoading: isLoading && data === void 0,
|
|
3848
|
+
isSuccess: data !== void 0
|
|
3849
|
+
};
|
|
3850
|
+
}
|
|
3851
|
+
|
|
3852
|
+
//#endregion
|
|
3853
|
+
export { AccountInsolventError, AlreadyInitializedError, BORROW_INDEX_BITS, BPS_DENOMINATOR, BPS_SCALE, BatchValidationError, BelowMinimumRedemptionError, CastingError, ChunkHasZeroLiquidityError, ChunkLimitError, CrossPoolError, DEFAULT_MAX_SPREAD, DEFAULT_RECONNECT_CONFIG, DEFAULT_VEGOID, DepositTooLargeError, DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError, InputListFailError, InsufficientCreditLiquidityError, InvalidBuilderCodeError, InvalidHistoryRangeError, InvalidTickBoundError, InvalidTickError, InvalidTokenIdParameterError, InvalidUniswapCallbackError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LengthMismatchError, LiquidityTooHighError, LoanSlotExhaustedError, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, MAX_TICK, MAX_TRACKED_CHUNKS, MIN_TICK, MaxRetriesExceededError, MissingPositionIdsError, NetLiquidityZeroError, NetworkMismatchError, NoLegsExercisableError, NotALongLegError, NotBuilderError, NotEnoughLiquidityInChunkError, NotEnoughTokensError, NotGuardianError, NotMarginCalledError, NotPanopticPoolError, ORACLE_EPOCH_SECONDS, OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError, PanopticProvider, PanopticValidationError, PoolNotInitializedError, PositionCountNotZeroError, PositionNotOwnedError, PositionSnapshotNotFoundError, PositionTooLargeError, PriceBoundFailError, PriceImpactTooLargeError, ProviderLagError, RATE_AT_TARGET_BITS, REORG_DEPTH, REQUIRED_BASE_ERROR_SENTINEL, ReentrancyError, RpcError, RpcResponseError, SCHEMA_VERSION, SECONDS_PER_YEAR, STANDARD_TICK_WIDTHS, STORAGE_PREFIX, SafeModeError, StaleDataError, StaleOracleError, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, TokenIdHasZeroLegsError, TooManyLegsOpenError, TransferFailedError, UNREALIZED_INTEREST_BITS, UTILIZATION_DENOMINATOR, UnauthorizedUniswapCallbackError, UnderOverFlowError, UnhealthyPoolError, WAD, WrongPoolIdError, WrongUniswapPoolError, ZERO_COLLATERAL, ZERO_VALUATION, ZeroAddressError, ZeroCollateralRequirementError, addLegToTokenId, addPendingPosition, addTrackedChunks, annualizePerSecondRateWad, approve, approveAndWait, approvePool, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertTradeable, borrow, borrowAndWait, buildBatchDispatchArgs, buildOpenPositionCalldata, buildUniqueLoan, calculateAccountGreeksPure, calculatePortfolioDelta, calculatePortfolioGamma, calculatePortfolioGreeks, calculatePortfolioValue, calculatePositionDelta, calculatePositionDeltaDebtOnly, calculatePositionDeltaWithSwap, calculatePositionGamma, calculatePositionGreeks, calculatePositionValue, calculateResyncBlock, calculateSpreadWad, cancelTransaction, checkApproval, checkCollateralAcrossTicks, cleanupStalePendingPositions, clearCheckpoint, clearPendingPositions, clearTrackedChunks, clearTrackedPositions, clearTradeHistory, closePosition, closePositionAndWait, collateralTrackerV2Abi, computeV4PoolId, confirmPendingPosition, convertToAssets, convertToShares, countLegs, createEventPoller, createEventSubscription, createFileStorage, createFlowNeutralTokenId, createMemoryStorage, createNonceManager, createPoolFormatters, createTokenIdBuilder, decodeAllDispatchCalldata, decodeAllLegs, decodeDispatchCalldata, decodeLeftRightSigned, decodeLeftRightUnsigned, decodeLeg, decodePanopticTokenURI, decodePoolId, decodeTickSpacing, decodeTokenId, decodeVegoid, deployNewPool, deployNewPoolAndWait, deposit, depositAndWait, deriveSupplyRatePerSecWad, detectReorg, dispatch, dispatchAndWait, encodeLeg, encodePoolId, encodePoolKeyBytes, encodeV3PoolKeyBytes, encodeV4PoolId, estimateBlockNumbers, estimateCollateralRequired, executeBatchDispatch, executeBatchDispatchAndWait, failPendingPosition, fetchPoolId, forceExercise, forceExerciseAndWait, formatBlockNumber, formatBps, formatCompact, formatDatetime, formatDuration, formatDurationSeconds, formatFeeTier, formatGas, formatGwei, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatPoolIdHex, formatPriceRange, formatRateWad, formatRatioPercent, formatTick, formatTickRange, formatTimestamp, formatTimestampLocale, formatTokenAmount, formatTokenAmountSigned, formatTokenDelta, formatTokenFlow, formatTokenIdHex, formatTokenIdShort, formatTxHash, formatUtilization, formatWad, formatWadPercent, formatWadSigned, formatWei, getAccountBuyingPower, getAccountCollateral, getAccountGreeks, getAccountHistory, getAccountPremia, getAccountSummaryBasic, getAccountSummaryRisk, getAssetIndex, getBlockMeta, getChainDeployment, getChunkLiquidities, getChunkSpreads, getClosedPositions, getClosedPositionsKey, getCollateralAddresses, getCollateralData, getCollateralSharePrices, getCollateralTotalAssetsBatch, getCurrentRates, getDeltaHedgeParams, getEnforcedTickLimits, getFactoryConstructMetadata, getFactoryOwnerOf, getFactoryTokenURI, getGuardianUnlockState, getInterestState, getIrmCurrent, getIrmCurve, getItmAmounts, getLegDelta, getLegDeltaInVaultFrame, getLegGamma, getLegNetValueWidth0, getLegValue, getLiquidationPrices, getMarginBuffer, getMaxPositionSize, getMaxWithdrawable, getNativeTokenPrice, getNetLiquidationValue, getNetLiquidationValues, getOpenPositionIds, getOpenPositionPreview, getOracleState, getPanopticPoolAddress, getPanopticPoolFromPoolId, getPendingPositions, getPendingPositionsKey, getPool, getPoolDeploymentBlock, getPoolDisplayId, getPoolLiquidities, getPoolMetaKey, getPoolMetadata, getPoolPrefix, getPortfolioValue, getPosition, getPositionChunkData, getPositionEnrichmentData, getPositionGreeks, getPositionMetaKey, getPositions, getPositionsKey, getPositionsWithPremia, getPriceHistory, getPricesAtTick, getRealizedPnL, getRequiredCreditForITM, getRiskParameters, getSafeMode, getSchemaVersionKey, getStreamiaHistory, getSyncCheckpointKey, getSyncStatus, getTickSpacing, getTokenListId, getTrackedChunks, getTrackedChunksKey, getTrackedPositionIds, getTradeHistory, getUniswapFeeHistory, getUniswapV3PoolFromId, getUniswapV3PoolInfo, getUniswapV3PoolLiquidities, getUniswapV4PoolBasicState, getUniswapV4PoolInfo, getUniswapV4PoolKeyFromId, getUniswapV4PoolLiquidities, getUtilization, hasLoanOrCredit, hasLongLeg, interpolateBlocks, isCall, isCowSupportedChain, isCredit, isCreditLeg, isDefinedRisk, isGasError, isInputListFailError, isLiquidatable, isLoan, isLoanLeg, isNonceError, isPanopticErrorType, isPositionTracked, isRetryableRpcError, isShortOnly, isSpread, isSupportedChain, jsonSerializer, liquidate, liquidateAndWait, loadCheckpoint, minePoolAddress, mint, mintAndWait, multicallRead, mutationEffects, openPosition, openPositionAndWait, optimizeTokenIdRiskPartners, packMarketState, panopticPoolV2Abi, parseBps, parseCollateralLog, parsePanopticError, parsePoolLog, parseTokenAmount, parseTokenListId, parseWad, pokeOracle, pokeOracleAndWait, previewBorrow, previewDeposit, previewMint, previewRedeem, previewUnwrap, previewWithdraw, previewWrap, priceToTick, publicBroadcaster, queryKeys, ratePerSecWadToAprPct, reconstructFromEvents, recoverSnapshot, recoverSnapshotFromTx, redeem, redeemAndWait, removeTrackedChunks, repay, repayAndWait, requireChainDeployment, resolveBlockNumbers, resolvePanopticPoolFromPoolId, resolveTokenIndex, resolveUniswapV4PoolKey, rollPosition, rollPositionAndWait, roundToTickSpacing, saveCheckpoint, saveClosedPosition, scanChunks, selectDispatchForAccount, settleAccumulatedPremia, settleAccumulatedPremiaAndWait, simulateBatchDispatch, simulateClosePosition, simulateDeployNewPool, simulateDeposit, simulateDispatch, simulateForceExercise, simulateLiquidate, simulateOpenPosition, simulateSFPMBurn, simulateSFPMMint, simulateSettle, simulateSwapExactIn, simulateSwapExactOut, simulateWithdraw, smartRepay, smartRepayAndWait, speedUpTransaction, sqrtPriceX96ToPriceDecimalScaled, sqrtPriceX96ToTick, supply, supplyAndWait, swapExactIn, swapExactInAndWait, swapExactOut, swapExactOutAndWait, syncPositions, tickLimits, tickToPrice, tickToPriceDecimalScaled, tickToSqrtPriceX96, toVaultFrameAtTick, truncateAddress, unsupply, unsupplyAndWait, unwrapWeth, unwrapWethAndWait, unwrapXstock, unwrapXstockAndWait, useAccountCollateral, useAccountGreeks, useAccountPremia, useAccountSummaryBasic, useAccountSummaryRisk, useAddPendingPosition, useApprove, useApproveErc20ForCow, useApproveErc20ForPermit2, useApprovePool, useApproveRouterViaPermit2, useBatchDispatch as useBatchDispatchHook, useBorrow as useBorrowHook, useCancelCowOrder, useCheckCowApproval, useCheckRouterApproval, useChunkSpreads, useClearTrackedPositions, useClosePosition as useClosePositionHook, useClosedPositions, useCollateralData, useConfirmPendingPosition, useCowOrderStatus, useCurrentRates, useDeployNewPool as useDeployNewPoolHook, useDeposit as useDepositHook, useDispatch as useDispatchHook, useEstimateCollateralRequired, useEventPoller, useEventSubscription, useFactoryConstructMetadata, useFactoryOwnerOf, useFactoryTokenURI, useFailPendingPosition, useFlowNeutralTokenId, useForceExercise as useForceExerciseHook, useGuardianUnlockState, useInterestState, useIsLiquidatable, useLiquidate as useLiquidateHook, useLiquidationPrices, useMarginBuffer, useMaxPositionSize, useMaxWithdrawable, useMinePoolAddress as useMinePoolAddressHook, useMintShares, useNativeTokenPrice, useNetLiquidationValue, useNetLiquidationValues, useOpenPosition as useOpenPositionHook, useOpenPositionPreview, useOptimizeRiskPartners, useOracleState, usePanopticContext, usePanopticPoolAddress, usePokeOracle as usePokeOracleHook, usePool, usePoolLiquidities, usePosition, usePositionGreeks, usePositions, usePositionsWithPremia, usePreviewBorrow, usePreviewDeposit, usePreviewMint, usePreviewRedeem, usePreviewWithdraw, usePriceHistory, useQuoteCowSwap, useQuoteSwapExactInViaRouter, useQuoteSwapExactOutViaRouter, useRealizedPnL, useRedeem as useRedeemHook, useRepay as useRepayHook, useResolveUniswapV4PoolKey, useRiskParameters, useRollPosition as useRollPositionHook, useSafeMode, useSettleAccumulatedPremia as useSettleAccumulatedPremiaHook, useSimulateBatchDispatch, useSimulateClosePosition, useSimulateDeployNewPool, useSimulateDeposit, useSimulateDispatch, useSimulateForceExercise, useSimulateLiquidate, useSimulateOpenPosition, useSimulateSFPMBurn, useSimulateSFPMMint, useSimulateSettle, useSimulateSwapExactIn, useSimulateSwapExactOut, useSimulateWithdraw, useSmartRepay as useSmartRepayHook, useStreamiaHistory, useSubmitCowOrder, useSupply as useSupplyHook, useSwapExactIn, useSwapExactInViaRouter, useSwapExactOut, useSwapExactOutViaRouter, useSyncPositions, useSyncStatus, useTrackedPositionIds, useTradeHistory, useTxEventConfirmation, useUniswapFeeHistory, useUniswapV3PoolInfo, useUniswapV3PoolLiquidities, useUniswapV4PoolBasicState, useUniswapV4PoolInfo, useUniswapV4PoolLiquidities, useUnsupply as useUnsupplyHook, useUnwrapWeth, useUnwrapXstock, useUtilization, useValidateBuilderCode, useWatchEvents, useWithdraw as useWithdrawHook, useWithdrawWithPositions as useWithdrawWithPositionsHook, useWrapEth, useWrapXstock, utilizationBpsToWad, utilizationPctToWad, validateBatch, validateBuilderCode, validatePoolId, verifyBlockContinuity, watchEvents, wethWrapAbi, withdraw, withdrawAndWait, withdrawWithPositions, withdrawWithPositionsAndWait, wrapEth, wrapEthAndWait, wrapXstock, wrapXstockAndWait, xstockWrapperAbi };
|
|
3854
|
+
//# sourceMappingURL=react-public.js.map
|