@panoptic-eng/sdk 1.0.62 → 1.0.63
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/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/panoptic/v2/index.d.ts +2 -0
- package/dist/panoptic/v2/index.d.ts.map +1 -1
- package/dist/panoptic/v2/index.js +2 -1
- package/dist/panoptic/v2/index.js.map +1 -1
- package/dist/panoptic/v2/react-public.d.ts +2 -0
- package/dist/panoptic/v2/react-public.d.ts.map +1 -1
- package/dist/panoptic/v2/react-public.js +2 -1
- package/dist/panoptic/v2/react-public.js.map +1 -1
- package/dist/providers-1WdiaRbY.js +54 -0
- package/dist/{router-Y1OxL9Nt.js → router-Dejb6MWu.js} +136 -9
- package/dist/{router-jMP7fVno.js → router-pm9PDlyH.js} +1 -1
- package/dist/rpc/index.d.ts +112 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +242 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +1 -14
- package/dist/test/index.js.map +1 -1
- package/dist/uniswap/index.d.ts +310 -215
- package/dist/uniswap/index.d.ts.map +1 -1
- package/dist/uniswap/index.js +253 -20
- package/dist/uniswap/index.js.map +1 -1
- package/dist/{v2-B27ILZl4.js → v2-ccGPXWvq.js} +6 -131
- package/package.json +5 -1
- /package/dist/{cow-DTi3GjQz.js → cow-BsSaoahK.js} +0 -0
- /package/dist/{writes-B8NGXzUG.js → writes--fM_8ggw.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StateViewAbi, getAccountCollateral, panopticQueryAbi$1 as panopticQueryAbi, readBlockAndAggregate, requireReturnData } from "./irm-BDlcUNgJ.js";
|
|
2
2
|
import { AccountInsolventError, ChunkLimitError, DEFAULT_VEGOID, InvalidHistoryRangeError, MulticallResultMissingError, NotEnoughTokensError, PanopticError, PanopticValidationError, SafeModeError, StaleDataError, StorageDataNotFoundError, UnhealthyPoolError, WrongUniswapPoolError, applyMintBufferPerToken, availableToBorrow, collateralTrackerV2Abi, decodeLeftRightSigned, decodeLeftRightUnsigned, decodePositionBalance, getBlockMeta, getClosedPositionsKey, getPendingPositionsKey, getPool, getPoolMetaKey, getPoolMetadata, getPositionMetaKey, getPositionsKey, getTrackedChunksKey, getTrackedPositionIds, isPanopticErrorType, jsonSerializer, mintableAfterBuffer, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticGuardianAbi, panopticLiquidatorAbi, panopticPoolV2Abi, panopticQueryAbi as panopticQueryAbi$1, parsePanopticError, riskEngineAbi, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, stateViewAbi, uniswapV3PoolAbi } from "./rates-BwZnK0tG.js";
|
|
3
3
|
import { MAX_TICK, MAX_TRACKED_CHUNKS, MIN_TICK, NO_LOWER_LIQUIDATION_TICK, NO_UPPER_LIQUIDATION_TICK, WAD, calculatePositionDelta, calculatePositionDeltaDebtOnly, calculatePositionGamma, calculatePositionValue, priceToTick, sqrtPriceX96ToTick, tickLimits, tickToPriceDecimalScaled, tickToSqrtPriceX96, toVaultFrameAtTick } from "./greeks-CNi1-cnp.js";
|
|
4
|
-
import { addLegToTokenId, buildBatchDispatchArgs, buildUniqueCredit, buildUniqueLoan, countLegs, createTokenIdBuilder, decodeAllLegs, decodeTokenId, getPoolTokensForSimulation, loadCheckpoint, resolveTokenIndex, simulateDispatch, simulateOpenPosition, simulateWithTokenFlow } from "./writes
|
|
5
|
-
import { getLpPositionFunding, getMaxLpPositionSize } from "./router-
|
|
4
|
+
import { addLegToTokenId, buildBatchDispatchArgs, buildUniqueCredit, buildUniqueLoan, countLegs, createTokenIdBuilder, decodeAllLegs, decodeTokenId, getPoolTokensForSimulation, loadCheckpoint, resolveTokenIndex, simulateDispatch, simulateOpenPosition, simulateWithTokenFlow } from "./writes--fM_8ggw.js";
|
|
5
|
+
import { getLpPositionFunding, getMaxLpPositionSize, preparePositionGamma } from "./router-Dejb6MWu.js";
|
|
6
6
|
import { BaseError, ContractFunctionExecutionError, ContractFunctionRevertedError, ExecutionRevertedError, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, getAddress, hexToString, keccak256, parseAbi, parseEventLogs, toHex, trim, zeroAddress } from "viem";
|
|
7
7
|
import { multicall } from "viem/actions";
|
|
8
8
|
import Decimal from "decimal.js";
|
|
@@ -4691,9 +4691,9 @@ async function readTokenText(client, blockNumber, calls) {
|
|
|
4691
4691
|
});
|
|
4692
4692
|
return asString.map((result, index) => {
|
|
4693
4693
|
if (result.status === "success") return result.result;
|
|
4694
|
-
const fallback = asBytes32[index];
|
|
4695
|
-
if (fallback.status !== "success") throw fallback.error;
|
|
4696
|
-
return hexToString(trim(fallback.result, { dir: "right" }));
|
|
4694
|
+
const fallback$1 = asBytes32[index];
|
|
4695
|
+
if (fallback$1.status !== "success") throw fallback$1.error;
|
|
4696
|
+
return hexToString(trim(fallback$1.result, { dir: "right" }));
|
|
4697
4697
|
});
|
|
4698
4698
|
}
|
|
4699
4699
|
/**
|
|
@@ -9903,131 +9903,6 @@ function marketRiskFromValues({ lower, current, upper }) {
|
|
|
9903
9903
|
};
|
|
9904
9904
|
}
|
|
9905
9905
|
|
|
9906
|
-
//#endregion
|
|
9907
|
-
//#region src/panoptic/v2/greeks/positionVolatility.ts
|
|
9908
|
-
const Precision = Decimal.clone({ precision: 80 });
|
|
9909
|
-
const Q96 = 1n << 96n;
|
|
9910
|
-
const YEAR_SECONDS = new Precision(31536e3);
|
|
9911
|
-
/** The premium-free position curve, expressed in one quote token's human units. */
|
|
9912
|
-
function preparePositionGamma({ tokenId, positionSize, quoteIsToken0, quoteDecimals }) {
|
|
9913
|
-
if (positionSize <= 0n || positionSize >= 1n << 128n) throw new RangeError("Invalid position size");
|
|
9914
|
-
if (!Number.isInteger(quoteDecimals) || quoteDecimals < 0 || quoteDecimals > 255) throw new RangeError("Invalid quote decimals");
|
|
9915
|
-
const decoded = decodeTokenId(tokenId);
|
|
9916
|
-
const chunks = decoded.legs.flatMap((leg) => {
|
|
9917
|
-
if (leg.width === 0n) return [];
|
|
9918
|
-
const width = leg.width * decoded.tickSpacing;
|
|
9919
|
-
const lowerTick = leg.strike - width / 2n;
|
|
9920
|
-
const upperTick = leg.strike + (width + 1n) / 2n;
|
|
9921
|
-
if (lowerTick < -887272n || upperTick > 887272n || lowerTick >= upperTick) throw new RangeError("Invalid position range");
|
|
9922
|
-
const lower = tickToSqrtPriceX96(lowerTick);
|
|
9923
|
-
const upper = tickToSqrtPriceX96(upperTick);
|
|
9924
|
-
const amount = positionSize * leg.optionRatio;
|
|
9925
|
-
const liquidity = leg.asset === 0n ? amount * (lower * upper / Q96) / (upper - lower) : amount * Q96 / (upper - lower);
|
|
9926
|
-
if (liquidity >= 1n << 128n) throw new RangeError("Liquidity exceeds uint128");
|
|
9927
|
-
return [{
|
|
9928
|
-
lowerTick: Number(lowerTick),
|
|
9929
|
-
upperTick: Number(upperTick),
|
|
9930
|
-
liquidity,
|
|
9931
|
-
isLong: leg.isLong
|
|
9932
|
-
}];
|
|
9933
|
-
});
|
|
9934
|
-
const scale = new Precision(10).pow(quoteDecimals);
|
|
9935
|
-
const atTick = (tick) => {
|
|
9936
|
-
const netLiquidity = chunks.reduce((sum$1, chunk) => tick >= BigInt(chunk.lowerTick) && tick < BigInt(chunk.upperTick) ? sum$1 + (chunk.isLong ? -chunk.liquidity : chunk.liquidity) : sum$1, 0n);
|
|
9937
|
-
const sqrt = new Precision(tickToSqrtPriceX96(tick).toString()).div(Q96.toString());
|
|
9938
|
-
const gamma = new Precision(netLiquidity.toString()).neg().div(2).div(scale);
|
|
9939
|
-
return quoteIsToken0 ? gamma.div(sqrt) : gamma.mul(sqrt);
|
|
9940
|
-
};
|
|
9941
|
-
const inRange = (low, high) => {
|
|
9942
|
-
if (low > high) throw new RangeError("Invalid candle range");
|
|
9943
|
-
const ticks = new Set([low, high]);
|
|
9944
|
-
for (const chunk of chunks) for (const boundary of [BigInt(chunk.lowerTick), BigInt(chunk.upperTick)]) {
|
|
9945
|
-
if (boundary >= low && boundary <= high) ticks.add(boundary);
|
|
9946
|
-
if (boundary - 1n >= low && boundary - 1n <= high) ticks.add(boundary - 1n);
|
|
9947
|
-
}
|
|
9948
|
-
return [...ticks].map(atTick);
|
|
9949
|
-
};
|
|
9950
|
-
return {
|
|
9951
|
-
chunks,
|
|
9952
|
-
atTick,
|
|
9953
|
-
inRange
|
|
9954
|
-
};
|
|
9955
|
-
}
|
|
9956
|
-
/** Historical whole-position diagnostics, with signs retained independently of eligibility. */
|
|
9957
|
-
function calculatePositionVolatilityMetrics({ observations, netPremium, baseFees, quoteDecimals }) {
|
|
9958
|
-
if (observations.length < 2) throw new RangeError("At least two price observations are required");
|
|
9959
|
-
if (!Number.isInteger(quoteDecimals) || quoteDecimals < 0 || quoteDecimals > 255) throw new RangeError("Invalid quote decimals");
|
|
9960
|
-
const points = observations.map((point) => ({
|
|
9961
|
-
...point,
|
|
9962
|
-
price: new Precision(point.price),
|
|
9963
|
-
gamma: new Precision(point.gamma),
|
|
9964
|
-
rangeGammas: (point.rangeGammas ?? []).map((gamma) => new Precision(gamma))
|
|
9965
|
-
}));
|
|
9966
|
-
for (const point of points) if (!point.price.isFinite() || point.price.lte(0) || !point.gamma.isFinite() || point.rangeGammas.some((gamma) => !gamma.isFinite())) throw new RangeError("Invalid price or gamma observation");
|
|
9967
|
-
const quantum = new Precision(10).pow(-quoteDecimals);
|
|
9968
|
-
const gammas = points.flatMap((point) => [point.gamma, ...point.rangeGammas]);
|
|
9969
|
-
const peak = gammas.reduce((max, gamma) => Precision.max(max, gamma.abs()), new Precision(0));
|
|
9970
|
-
const tolerance = Precision.max(quantum, peak.mul("1e-12"));
|
|
9971
|
-
const positive = gammas.some((gamma) => gamma.gt(tolerance));
|
|
9972
|
-
const negative = gammas.some((gamma) => gamma.lt(tolerance.neg()));
|
|
9973
|
-
const gammaSign = positive && negative ? "changing" : positive ? "positive" : negative ? "negative" : "zero";
|
|
9974
|
-
let exposure = new Precision(0);
|
|
9975
|
-
let signedConvexity = new Precision(0);
|
|
9976
|
-
let absoluteConvexity = new Precision(0);
|
|
9977
|
-
let years = new Precision(0);
|
|
9978
|
-
for (let i = 1; i < points.length; i++) {
|
|
9979
|
-
const previous = points[i - 1];
|
|
9980
|
-
const point = points[i];
|
|
9981
|
-
const seconds = point.timestamp - previous.timestamp;
|
|
9982
|
-
if (seconds <= 0n) throw new RangeError("Observations must have increasing timestamps");
|
|
9983
|
-
const elapsed = new Precision(seconds.toString()).div(YEAR_SECONDS);
|
|
9984
|
-
const squaredReturn = point.price.div(previous.price).ln().pow(2);
|
|
9985
|
-
exposure = exposure.plus(previous.gamma.abs().mul(elapsed));
|
|
9986
|
-
signedConvexity = signedConvexity.plus(previous.gamma.mul(squaredReturn).div(2));
|
|
9987
|
-
absoluteConvexity = absoluteConvexity.plus(previous.gamma.abs().mul(squaredReturn).div(2));
|
|
9988
|
-
years = years.plus(elapsed);
|
|
9989
|
-
}
|
|
9990
|
-
const sufficientExposure = exposure.gt(tolerance.mul(years).mul(100));
|
|
9991
|
-
const premium = netPremium === null ? null : new Precision(netPremium);
|
|
9992
|
-
const fees = baseFees == null ? null : new Precision(baseFees);
|
|
9993
|
-
if (premium !== null && !premium.isFinite() || fees !== null && !fees.isFinite()) throw new RangeError("Invalid accounting amount");
|
|
9994
|
-
const consistent = (amount) => gammaSign === "positive" ? amount.lte(quantum) : gammaSign === "negative" && amount.gte(quantum.neg());
|
|
9995
|
-
const reason = !sufficientExposure ? "insufficient-exposure" : gammaSign === "changing" ? "changing-sign" : premium === null ? "premium-unavailable" : !consistent(premium) ? "inconsistent-premium-direction" : null;
|
|
9996
|
-
const equivalent = (amount) => amount.abs().mul(2).div(exposure).sqrt().toString();
|
|
9997
|
-
const coverage = (amount) => absoluteConvexity.gt(quantum) ? amount.abs().div(absoluteConvexity).toString() : null;
|
|
9998
|
-
const eligibleFees = sufficientExposure && fees !== null && consistent(fees);
|
|
9999
|
-
return {
|
|
10000
|
-
gammaSign,
|
|
10001
|
-
exposure: exposure.toString(),
|
|
10002
|
-
signedConvexity: signedConvexity.toString(),
|
|
10003
|
-
absoluteConvexity: absoluteConvexity.toString(),
|
|
10004
|
-
netPremium: premium?.toString() ?? null,
|
|
10005
|
-
estimatedHedgedResult: premium?.plus(signedConvexity).toString() ?? null,
|
|
10006
|
-
weightedRealizedVolatility: sufficientExposure ? equivalent(absoluteConvexity) : null,
|
|
10007
|
-
premiumEquivalentVolatility: reason === null && premium !== null ? equivalent(premium) : null,
|
|
10008
|
-
premiumToConvexity: reason === null && premium !== null ? coverage(premium) : null,
|
|
10009
|
-
baseFees: fees?.toString() ?? null,
|
|
10010
|
-
feeEquivalentVolatility: eligibleFees ? equivalent(fees) : null,
|
|
10011
|
-
feeToConvexity: eligibleFees ? coverage(fees) : null,
|
|
10012
|
-
comparisonReason: reason
|
|
10013
|
-
};
|
|
10014
|
-
}
|
|
10015
|
-
/** Quote-value signed cumulative token increments, excluding revaluation of previous accrual. */
|
|
10016
|
-
function valuePositionAccrual({ snapshots, quoteIsToken0, quoteDecimals }) {
|
|
10017
|
-
let previous0 = 0n;
|
|
10018
|
-
let previous1 = 0n;
|
|
10019
|
-
let total = new Precision(0);
|
|
10020
|
-
for (const snapshot of snapshots) {
|
|
10021
|
-
const amount0 = new Precision((snapshot.token0 - previous0).toString());
|
|
10022
|
-
const amount1 = new Precision((snapshot.token1 - previous1).toString());
|
|
10023
|
-
const price = new Precision("1.0001").pow(snapshot.tick.toString());
|
|
10024
|
-
total = total.plus(quoteIsToken0 ? amount0.plus(amount1.div(price)) : amount1.plus(amount0.mul(price)));
|
|
10025
|
-
previous0 = snapshot.token0;
|
|
10026
|
-
previous1 = snapshot.token1;
|
|
10027
|
-
}
|
|
10028
|
-
return total.div(new Precision(10).pow(quoteDecimals));
|
|
10029
|
-
}
|
|
10030
|
-
|
|
10031
9906
|
//#endregion
|
|
10032
9907
|
//#region src/panoptic/v2/reads/collateralCurve.ts
|
|
10033
9908
|
/** Native-token margin inputs, independent of the tick used to display the curve. */
|
|
@@ -10436,4 +10311,4 @@ async function getPositionVolatilityHistory({ client, poolAddress, account, toke
|
|
|
10436
10311
|
}
|
|
10437
10312
|
|
|
10438
10313
|
//#endregion
|
|
10439
|
-
export { DEFAULT_MIN_SWAP_RATIO_BPS, DEFAULT_RECONNECT_CONFIG, MARKET_INDICATOR_PERIODS, REQUIRED_BASE_ERROR_SENTINEL, STRIKE_LADDER_TARGET_STRIKES, VARIANCE_RATIO_LAG, addPendingPosition, addTrackedChunks, apportion, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertLpPositionFunded, assertTradeable, buildCreditWrappedDispatch, buildSfpmSwapCalldata, buildSfpmSwapPlan, buildTemporaryLoanRecoveryDispatch, buildTokenShortfallRecoveryDispatch, calculateAccountGreeksPure, calculateMarketIndicator,
|
|
10314
|
+
export { DEFAULT_MIN_SWAP_RATIO_BPS, DEFAULT_RECONNECT_CONFIG, MARKET_INDICATOR_PERIODS, REQUIRED_BASE_ERROR_SENTINEL, STRIKE_LADDER_TARGET_STRIKES, VARIANCE_RATIO_LAG, addPendingPosition, addTrackedChunks, apportion, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertLpPositionFunded, assertTradeable, buildCreditWrappedDispatch, buildSfpmSwapCalldata, buildSfpmSwapPlan, buildTemporaryLoanRecoveryDispatch, buildTokenShortfallRecoveryDispatch, calculateAccountGreeksPure, calculateMarketIndicator, calculateSpreadWad, calculateVarianceProfile, checkCollateralAcrossTicks, classifyStrategyGroups, classifyStrike, cleanupStalePendingPositions, clearPendingPositions, clearTrackedChunks, clearTradeHistory, collateralCurveTicks, collateralRuleKindFor, computeV4PoolId, confirmPendingPosition, convertToAssets, convertToShares, createEventPoller, createEventSubscription, createFlowNeutralTokenId, decodePanopticTokenURI, emptyLiquidateParams, encodePoolKeyBytes, encodeV3PoolKeyBytes, ensureSfpmV3PoolInitialized, estimateBlockNumbers, estimateCollateralBreakdown, estimateCollateralRequired, failPendingPosition, feeGrowthInsideX128, feesFromFeeGrowthDelta, fetchSfpmV3PoolId, fetchUniswapFeeData, getAccountBuyingPower, getAccountGreeks, getAccountHistory, getChunkLiquidities, getChunkSpreads, getClosedPositions, getCollateralCurve, getCollateralCurveInputs, getCollateralRequiredBase, getCollateralSharePrices, getCollateralTotalAssetsBatch, getDeltaHedgeParams, getEnforcedTickLimits, getExecutableLpMaxSize, getFactoryConstructMetadata, getFactoryOwnerOf, getFactoryTokenURI, getGuardianUnlockState, getHedgeLimits, getItmAmounts, getMarginBuffer, getMaxPositionSize, getMaxRedeem, getMaxWithdrawable, getNativeTokenPrice, getNotEnoughTokensError, getOpenPositionPreview, getPanopticPoolAddress, getPanopticPoolFromPoolId, getPendingPositions, getPoolCollateralAddresses, getPoolLiquidities, getPortfolioValue, getPositionChunkData, getPositionEnrichmentData, getPositionValueCurve, getPositionVolatilityHistory, getPriceHistory, getRealizedPnL, getRequiredCreditForITM, getSafeMode, getStreamiaHistory, getSyncStatus, getTrackedChunks, getTradeHistory, getUniswapFeeHistory, getUniswapV3LpPositionState, getUniswapV3PoolFromId, getUniswapV3PoolInfo, getUniswapV3PoolLiquidities, getUniswapV4LpPositionState, getUniswapV4PoolBasicState, getUniswapV4PoolInfo, getUniswapV4PoolKeyFromId, getUniswapV4PoolLiquidities, interpolateBlocks, isGasError, isNonceError, isRetryableRpcError, isolateGroupTokenId, ladderStrikeSequence, logReturns, marketPnlInQuote, marketRiskFromValues, marketScenario, minePoolAddress, minePoolAddressLocalAsync, multicallRead, netLiquidationValueInQuote, optimizeTokenIdRiskPartners, parseCollateralLog, parsePoolLog, positionValueKey, positionValueTicks, prepareIndicatorCandles, preparePositionValueCurve, previewDeposit, previewMint, previewRedeem, previewWithdraw, quoteLiquidation, quoteOneTokenFlow, quoteSfpmSwap, quoteTemporaryLoanRecovery, quoteTokenShortfallRecovery, realizedBeta, removeTrackedChunks, resolveBlockNumbers, resolveLadderStrike, resolvePanopticPoolFromPoolId, resolveUniswapV4PoolKey, saveClosedPosition, scaleCollateralRequired, scanChunks, screenAccountExact, simulateBatchDispatch, simulateClosePosition, simulateDeployNewPool, simulateDeposit, simulateForceExercise, simulateLiquidate, simulateSFPMBurn, simulateSFPMMint, simulateSwapExactIn, simulateSwapExactOut, simulateWithdraw, slippageBpsToTickDistance, watchEvents };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panoptic-eng/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.63",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/panoptic-labs/panoptic-sdk.git"
|
|
@@ -43,6 +43,10 @@
|
|
|
43
43
|
"types": "./dist/vault-transaction-fees.d.ts",
|
|
44
44
|
"import": "./dist/vault-transaction-fees.js"
|
|
45
45
|
},
|
|
46
|
+
"./rpc": {
|
|
47
|
+
"types": "./dist/rpc/index.d.ts",
|
|
48
|
+
"import": "./dist/rpc/index.js"
|
|
49
|
+
},
|
|
46
50
|
"./test": {
|
|
47
51
|
"types": "./dist/test/index.d.ts",
|
|
48
52
|
"import": "./dist/test/index.js"
|
|
File without changes
|
|
File without changes
|