@panoptic-eng/sdk 1.0.72 → 1.0.73
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-DMLTQhqt.js → cow-12OtZc7G.js} +1 -1
- package/dist/index.d.ts +1101 -663
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8545 -4122
- package/dist/index.js.map +1 -1
- package/dist/{irm-BI9so_9s.js → irm-BntFNP1P.js} +81 -3
- package/dist/{rates-BOGkyjVy.js → rates-c9XVKm3m.js} +1128 -504
- package/dist/{router-CL6snZVH.js → router-lUA1kp8A.js} +1 -2
- package/dist/safe/index.d.ts +166 -0
- package/dist/safe/index.d.ts.map +1 -0
- package/dist/safe/index.js +278 -0
- package/dist/safe/index.js.map +1 -0
- package/dist/{v2-DIrXTXMw.js → v2-xSELV6jf.js} +13 -91
- package/dist/{writes-BNNd0vjF.js → writes-_ZxthOkP.js} +5 -629
- package/dist/zodiac/index.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MulticallNoDataError, MulticallResultFailedError, MulticallResultMissingError, PanopticValidationError, collateralTrackerV2Abi, decodeLeftRightUnsigned, getBlockMeta, getPool, getPositions, panopticPoolV2Abi, riskEngineAbi } from "./rates-
|
|
1
|
+
import { MulticallNoDataError, MulticallResultFailedError, MulticallResultMissingError, PanopticValidationError, collateralTrackerV2Abi, decodeLeftRightUnsigned, decodeTokenId, getBlockMeta, getPool, getPositions, panopticPoolV2Abi, riskEngineAbi } from "./rates-c9XVKm3m.js";
|
|
2
2
|
import { NO_LOWER_LIQUIDATION_TICK, NO_UPPER_LIQUIDATION_TICK, tickToSqrtPriceX96 } from "./greeks-CEv-Uex1.js";
|
|
3
|
-
import { decodeFunctionResult, encodeFunctionData } from "viem";
|
|
3
|
+
import { decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
4
4
|
import { call, multicall } from "viem/actions";
|
|
5
5
|
|
|
6
6
|
//#region src/abis/multicall3.ts
|
|
@@ -2781,6 +2781,84 @@ async function getLiquidationPrices(params) {
|
|
|
2781
2781
|
};
|
|
2782
2782
|
}
|
|
2783
2783
|
|
|
2784
|
+
//#endregion
|
|
2785
|
+
//#region src/panoptic/v2/reads/positionValueCurve.ts
|
|
2786
|
+
const abi = parseAbi(["function computeNetLiquidationValue(uint256[] positionIdList, uint256 shortPremium, uint256 longPremium, uint256[] positionBalanceArray, int24[] atTicks) pure returns (int256[] value0, int256[] value1)"]);
|
|
2787
|
+
/** Stable identity for a position-dependent curve; streamia and spot are separate inputs. */
|
|
2788
|
+
function positionValueKey(positions) {
|
|
2789
|
+
return [...positions].sort((a, b) => a.tokenId < b.tokenId ? -1 : a.tokenId > b.tokenId ? 1 : 0).map(({ tokenId, positionSize }) => `${tokenId}:${positionSize}`).join(",");
|
|
2790
|
+
}
|
|
2791
|
+
/** All changes in the curve's active liquidity, independent of the current market tick. */
|
|
2792
|
+
function positionValueTicks(positions) {
|
|
2793
|
+
const ticks = new Set([-887272n, 887272n]);
|
|
2794
|
+
for (const { tokenId, positionSize } of positions) {
|
|
2795
|
+
if (tokenId < 0n || tokenId >= 1n << 256n || positionSize <= 0n || positionSize >= 1n << 128n) throw new RangeError("Invalid position id or size");
|
|
2796
|
+
const { legs, tickSpacing } = decodeTokenId(tokenId);
|
|
2797
|
+
for (const leg of legs) {
|
|
2798
|
+
if (leg.width === 0n) continue;
|
|
2799
|
+
const width = leg.width * tickSpacing;
|
|
2800
|
+
const lower = leg.strike - width / 2n;
|
|
2801
|
+
const upper = leg.strike + (width + 1n) / 2n;
|
|
2802
|
+
if (lower < -887272n || upper > 887272n || lower >= upper) throw new RangeError("Invalid position range");
|
|
2803
|
+
ticks.add(lower);
|
|
2804
|
+
ticks.add(upper);
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
return [...ticks].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
2808
|
+
}
|
|
2809
|
+
/** Read the immutable, premium-free part of NLV from the deployed pure calculation. */
|
|
2810
|
+
async function getPositionValueCurve({ client, queryAddress, positions }) {
|
|
2811
|
+
const ticks = positionValueTicks(positions);
|
|
2812
|
+
const [values0, values1] = await client.readContract({
|
|
2813
|
+
address: queryAddress,
|
|
2814
|
+
abi,
|
|
2815
|
+
functionName: "computeNetLiquidationValue",
|
|
2816
|
+
args: [
|
|
2817
|
+
positions.map((p) => p.tokenId),
|
|
2818
|
+
0n,
|
|
2819
|
+
0n,
|
|
2820
|
+
positions.map((p) => p.positionSize),
|
|
2821
|
+
ticks.map(Number)
|
|
2822
|
+
]
|
|
2823
|
+
});
|
|
2824
|
+
return ticks.map((tick, i) => ({
|
|
2825
|
+
tick,
|
|
2826
|
+
value0: values0[i],
|
|
2827
|
+
value1: values1[i]
|
|
2828
|
+
}));
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* Between leg boundaries, token0 is affine in inverse sqrt price and token1 in sqrt price.
|
|
2832
|
+
* Endpoint interpolation differs from contract integer rounding by at most a few wei per leg.
|
|
2833
|
+
*/
|
|
2834
|
+
function preparePositionValueCurve(curve) {
|
|
2835
|
+
if (curve.length < 2) throw new RangeError("Incomplete position value curve");
|
|
2836
|
+
for (let i = 0; i < curve.length; i++) if (curve[i].tick < -887272n || curve[i].tick > 887272n || i > 0 && curve[i].tick <= curve[i - 1].tick) throw new RangeError("Invalid position value curve ticks");
|
|
2837
|
+
const points = curve.map((point) => ({
|
|
2838
|
+
...point,
|
|
2839
|
+
sqrt: tickToSqrtPriceX96(point.tick)
|
|
2840
|
+
}));
|
|
2841
|
+
return (tick) => {
|
|
2842
|
+
if (tick < points[0].tick || tick > points[points.length - 1].tick) throw new RangeError("Tick outside position value curve");
|
|
2843
|
+
let lo = 0;
|
|
2844
|
+
let hi = points.length - 1;
|
|
2845
|
+
while (hi - lo > 1) {
|
|
2846
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
2847
|
+
if (points[mid].tick <= tick) lo = mid;
|
|
2848
|
+
else hi = mid;
|
|
2849
|
+
}
|
|
2850
|
+
const left = points[lo];
|
|
2851
|
+
const right = points[hi];
|
|
2852
|
+
const sqrt = tickToSqrtPriceX96(tick);
|
|
2853
|
+
const numerator = sqrt - left.sqrt;
|
|
2854
|
+
const denominator = right.sqrt - left.sqrt;
|
|
2855
|
+
return {
|
|
2856
|
+
value0: left.value0 + (right.value0 - left.value0) * numerator * right.sqrt / (denominator * sqrt),
|
|
2857
|
+
value1: left.value1 + (right.value1 - left.value1) * numerator / denominator
|
|
2858
|
+
};
|
|
2859
|
+
};
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2784
2862
|
//#endregion
|
|
2785
2863
|
//#region src/panoptic/v2/reads/collateral.ts
|
|
2786
2864
|
const SECONDS_PER_YEAR$1 = 31536000n;
|
|
@@ -3225,4 +3303,4 @@ async function getIrmCurve(params) {
|
|
|
3225
3303
|
}
|
|
3226
3304
|
|
|
3227
3305
|
//#endregion
|
|
3228
|
-
export { BORROW_INDEX_BITS, BPS_SCALE, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, MULTICALL3_ADDRESS, Multicall3Abi, RATE_AT_TARGET_BITS, SECONDS_PER_YEAR, UNREALIZED_INTEREST_BITS, UniswapV3PoolAbi, WAD as WAD$1, applyOwedInterest, deriveSupplyRatePerSecWad, getAccountBuyingPower, getAccountCollateral, getAccountSummaryBasic, getAccountSummaryRisk, getCollateralAddresses, getCollateralData, getCurrentRates, getInterestState, getIrmCurrent, getIrmCurve, getLiquidationPrices, getNetLiquidationValue, getNetLiquidationValues, getPoolCollateralAddresses, isLiquidatable, packMarketState, panopticQueryAbi as panopticQueryAbi$1, ratePerSecWadToAprPct, readBlockAndAggregate, requireReturnData, utilizationBpsToWad, utilizationPctToWad };
|
|
3306
|
+
export { BORROW_INDEX_BITS, BPS_SCALE, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, MULTICALL3_ADDRESS, Multicall3Abi, RATE_AT_TARGET_BITS, SECONDS_PER_YEAR, UNREALIZED_INTEREST_BITS, UniswapV3PoolAbi, WAD as WAD$1, applyOwedInterest, deriveSupplyRatePerSecWad, getAccountBuyingPower, getAccountCollateral, getAccountSummaryBasic, getAccountSummaryRisk, getCollateralAddresses, getCollateralData, getCurrentRates, getInterestState, getIrmCurrent, getIrmCurve, getLiquidationPrices, getNetLiquidationValue, getNetLiquidationValues, getPoolCollateralAddresses, getPositionValueCurve, isLiquidatable, packMarketState, panopticQueryAbi as panopticQueryAbi$1, positionValueKey, positionValueTicks, preparePositionValueCurve, ratePerSecWadToAprPct, readBlockAndAggregate, requireReturnData, utilizationBpsToWad, utilizationPctToWad };
|