@panoptic-eng/sdk 1.0.74 → 1.0.76
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 +7 -0
- package/dist/cow/index.d.ts.map +1 -1
- package/dist/cow/index.js.map +1 -1
- package/dist/{cow-DRZqTpih.js → cow-CniZtok-.js} +1 -1
- package/dist/index.d.ts +331 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +909 -38
- package/dist/index.js.map +1 -1
- package/dist/{irm-BwOG1LRv.js → irm-CGuYhr-C.js} +2 -2
- package/dist/panoptic/v2/index.d.ts +46 -1
- package/dist/panoptic/v2/index.d.ts.map +1 -1
- package/dist/panoptic/v2/index.js +120 -4
- package/dist/panoptic/v2/index.js.map +1 -1
- package/dist/panoptic/v2/react-public.d.ts +46 -1
- package/dist/panoptic/v2/react-public.d.ts.map +1 -1
- package/dist/panoptic/v2/react-public.js +120 -4
- package/dist/panoptic/v2/react-public.js.map +1 -1
- package/dist/{router-KwjvMN_z.js → router-DL_cDCzG.js} +1 -1
- package/dist/{rates-B9HaWnEM.js → tokenFlow-6Ec9Hz48.js} +286 -2
- package/dist/{transactionFees-CqaoQFF-.js → transactionFees-DtoFzBvZ.js} +30 -20
- package/dist/uniswap/index.d.ts +7 -0
- package/dist/uniswap/index.d.ts.map +1 -1
- package/dist/uniswap/index.js.map +1 -1
- package/dist/{v2-DlmRqBju.js → v2-t8LiEkav.js} +71 -5
- package/dist/vault-transaction-fees.d.ts +15 -6
- package/dist/vault-transaction-fees.d.ts.map +1 -1
- package/dist/vault-transaction-fees.js +29 -19
- package/dist/vault-transaction-fees.js.map +1 -1
- package/dist/{writes-CeRXSZwj.js → writes-DKpVWZkE.js} +2 -236
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseError, ContractFunctionRevertedError, concat, decodeAbiParameters, decodeErrorResult, decodeEventLog, decodeFunctionData, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, encodePacked, erc20Abi, getAddress, hexToBigInt, keccak256, maxUint256, parseAbi, toBytes, toFunctionSelector, toHex, zeroAddress, zeroHash } from "viem";
|
|
1
|
+
import { BaseError, ContractFunctionRevertedError, concat, decodeAbiParameters, decodeErrorResult, decodeEventLog, decodeFunctionData, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, encodePacked, erc20Abi, getAddress, hexToBigInt, keccak256, maxUint256, parseAbi, parseTransaction, toBytes, toFunctionSelector, toHex, zeroAddress, zeroHash } from "viem";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import Decimal from "decimal.js";
|
|
4
4
|
import { call, estimateFeesPerGas, getBlock, getBlockNumber, getFeeHistory, readContract, simulateContract, writeContract } from "viem/actions";
|
|
@@ -25971,7 +25971,7 @@ const NO_UPPER_LIQUIDATION_TICK = (1n << 23n) - 1n;
|
|
|
25971
25971
|
|
|
25972
25972
|
//#endregion
|
|
25973
25973
|
//#region src/panoptic/v2/formatters/tick.ts
|
|
25974
|
-
const Q192$
|
|
25974
|
+
const Q192$4 = 1n << 192n;
|
|
25975
25975
|
function tickToSqrtPriceX96(tick) {
|
|
25976
25976
|
if (tick < MIN_TICK || tick > MAX_TICK) throw new RangeError("Tick out of bounds");
|
|
25977
25977
|
const absTick = tick < 0n ? -tick : tick;
|
|
@@ -26006,7 +26006,7 @@ const MAX_SQRT_PRICE_X96 = tickToSqrtPriceX96(MAX_TICK);
|
|
|
26006
26006
|
//#endregion
|
|
26007
26007
|
//#region src/uniswap/lpGreeks.ts
|
|
26008
26008
|
const Q96$2 = 1n << 96n;
|
|
26009
|
-
const Q192$
|
|
26009
|
+
const Q192$3 = 1n << 192n;
|
|
26010
26010
|
/**
|
|
26011
26011
|
* Compute the token0/token1 amounts backing `liquidity` over `[sqrtA, sqrtB]`
|
|
26012
26012
|
* at the current price `sqrtP`, mirroring Uniswap's `LiquidityAmounts`
|
|
@@ -26072,7 +26072,7 @@ function getLegTokenInventory(leg, currentTick, positionSize, tickSpacing, token
|
|
|
26072
26072
|
//#region src/panoptic/v2/greeks/index.ts
|
|
26073
26073
|
/** Fixed-point scale constants for sqrtPriceX96 arithmetic */
|
|
26074
26074
|
const Q96 = 1n << 96n;
|
|
26075
|
-
const Q192 = 1n << 192n;
|
|
26075
|
+
const Q192$2 = 1n << 192n;
|
|
26076
26076
|
/**
|
|
26077
26077
|
* Convert tick to quote-denominated tick based on asset direction.
|
|
26078
26078
|
*
|
|
@@ -26164,7 +26164,7 @@ function getLegDelta(leg, currentTick, positionSize, poolTickSpacing, mintTick,
|
|
|
26164
26164
|
const signedStrike = leg.asset === 0n ? leg.strike : -leg.strike;
|
|
26165
26165
|
const sqrtKraw = tickToSqrtPriceX96(signedStrike);
|
|
26166
26166
|
const KrawX192 = sqrtKraw * sqrtKraw;
|
|
26167
|
-
const notional = divTrunc(m * KrawX192, Q192);
|
|
26167
|
+
const notional = divTrunc(m * KrawX192, Q192$2);
|
|
26168
26168
|
return -notional;
|
|
26169
26169
|
}
|
|
26170
26170
|
if (halfWidthTick === 0n) {
|
|
@@ -26193,8 +26193,8 @@ function getLegDelta(leg, currentTick, positionSize, poolTickSpacing, mintTick,
|
|
|
26193
26193
|
const sqrtKR = tickToSqrtPriceX96(qStrikeTick + halfWidthTick);
|
|
26194
26194
|
const sqrtR = tickToSqrtPriceX96(halfWidthTick);
|
|
26195
26195
|
const rX192 = sqrtR * sqrtR;
|
|
26196
|
-
const numerator = m * (sqrtKR - sqrtP) * Q192;
|
|
26197
|
-
const denominator = sqrtP * (rX192 - Q192);
|
|
26196
|
+
const numerator = m * (sqrtKR - sqrtP) * Q192$2;
|
|
26197
|
+
const denominator = sqrtP * (rX192 - Q192$2);
|
|
26198
26198
|
vDelta = divTrunc(numerator, denominator);
|
|
26199
26199
|
}
|
|
26200
26200
|
const isPut = !isCall(leg.tokenType, isAssetToken0);
|
|
@@ -26217,7 +26217,7 @@ function getLegDelta(leg, currentTick, positionSize, poolTickSpacing, mintTick,
|
|
|
26217
26217
|
const sqrtKPmX96 = sqrtK * Q96 / sqrtPm;
|
|
26218
26218
|
const diff = sqrtR - sqrtKPmX96;
|
|
26219
26219
|
const diffSqX192 = diff * diff;
|
|
26220
|
-
return divTrunc(m * diffSqX192, rX192 - Q192);
|
|
26220
|
+
return divTrunc(m * diffSqX192, rX192 - Q192$2);
|
|
26221
26221
|
}
|
|
26222
26222
|
})();
|
|
26223
26223
|
return definedRisk ? debtDelta + vDelta : debtDelta + vDelta + itmDelta;
|
|
@@ -28921,7 +28921,8 @@ const UsdcPlpVaultMainnetProdConfig = {
|
|
|
28921
28921
|
}] },
|
|
28922
28922
|
deltaHedge: {
|
|
28923
28923
|
deltaThresholdBps: 1500n,
|
|
28924
|
-
maxHedgeSlots:
|
|
28924
|
+
maxHedgeSlots: 5,
|
|
28925
|
+
executionPolicy: "volatility-capture",
|
|
28925
28926
|
timedRehedge: {
|
|
28926
28927
|
elapsedMinutes: 1440,
|
|
28927
28928
|
jitterMinutes: 60,
|
|
@@ -33328,7 +33329,7 @@ function preparePriceHistory(history) {
|
|
|
33328
33329
|
price
|
|
33329
33330
|
}]] : [];
|
|
33330
33331
|
})).values()].sort((a, b) => a.timestampSec - b.timestampSec);
|
|
33331
|
-
const priceAt = (timestamp) => {
|
|
33332
|
+
const priceAt$1 = (timestamp) => {
|
|
33332
33333
|
const rightIndex = points.findIndex((point) => point.timestampSec >= timestamp);
|
|
33333
33334
|
const right = points[rightIndex];
|
|
33334
33335
|
if (right === void 0) return null;
|
|
@@ -33340,20 +33341,20 @@ function preparePriceHistory(history) {
|
|
|
33340
33341
|
return {
|
|
33341
33342
|
first: points[0]?.timestampSec,
|
|
33342
33343
|
last: points[points.length - 1]?.timestampSec,
|
|
33343
|
-
priceAt,
|
|
33344
|
+
priceAt: priceAt$1,
|
|
33344
33345
|
points
|
|
33345
33346
|
};
|
|
33346
33347
|
}
|
|
33347
33348
|
/** Largest sampled move from each eligible interval opening; equal extremes use the first. */
|
|
33348
33349
|
function calculateMaxSignedPriceChanges(periods, history) {
|
|
33349
|
-
const { priceAt, points } = preparePriceHistory(history);
|
|
33350
|
+
const { priceAt: priceAt$1, points } = preparePriceHistory(history);
|
|
33350
33351
|
return periods.flatMap((period) => {
|
|
33351
33352
|
let maximum = new Precision$2(0);
|
|
33352
33353
|
const intervals = period.activeIntervals ?? [period];
|
|
33353
33354
|
if (intervals.length === 0) return [];
|
|
33354
33355
|
for (const interval of intervals) {
|
|
33355
|
-
const start = priceAt(interval.startTimestampSec);
|
|
33356
|
-
const end = priceAt(interval.endTimestampSec);
|
|
33356
|
+
const start = priceAt$1(interval.startTimestampSec);
|
|
33357
|
+
const end = priceAt$1(interval.endTimestampSec);
|
|
33357
33358
|
if (start === null || end === null) return [];
|
|
33358
33359
|
let intervalMaximum = new Precision$2(0);
|
|
33359
33360
|
for (const point of points) {
|
|
@@ -33383,7 +33384,7 @@ function calculateMeanMaxAbsolutePriceChange(periods, history) {
|
|
|
33383
33384
|
}
|
|
33384
33385
|
/** Non-overlapping seven-day observations, anchored to the first available share-price snapshot. */
|
|
33385
33386
|
function calculateWeeklyVaultReturns(history) {
|
|
33386
|
-
const { first, last, priceAt } = preparePriceHistory(history.map((point) => ({
|
|
33387
|
+
const { first, last, priceAt: priceAt$1 } = preparePriceHistory(history.map((point) => ({
|
|
33387
33388
|
timestampSec: point.timestampSec,
|
|
33388
33389
|
price: point.sharePrice
|
|
33389
33390
|
})));
|
|
@@ -33391,8 +33392,8 @@ function calculateWeeklyVaultReturns(history) {
|
|
|
33391
33392
|
const weeks = [];
|
|
33392
33393
|
for (let start = first; start + WEEK <= last; start += WEEK) {
|
|
33393
33394
|
const end = start + WEEK;
|
|
33394
|
-
const startPrice = priceAt(start);
|
|
33395
|
-
const endPrice = priceAt(end);
|
|
33395
|
+
const startPrice = priceAt$1(start);
|
|
33396
|
+
const endPrice = priceAt$1(end);
|
|
33396
33397
|
if (startPrice === null || endPrice === null) continue;
|
|
33397
33398
|
const factor = endPrice.div(startPrice);
|
|
33398
33399
|
weeks.push({
|
|
@@ -34882,6 +34883,7 @@ const HypoVaultManagerConfigSchema = z.object({
|
|
|
34882
34883
|
targetDeltaBps: z.bigint().nonnegative().max(10000n).optional(),
|
|
34883
34884
|
deltaThresholdBps: z.bigint().positive().optional(),
|
|
34884
34885
|
maxHedgeSlots: z.number().int().positive().optional(),
|
|
34886
|
+
executionPolicy: z.literal("volatility-capture").optional(),
|
|
34885
34887
|
timedRehedge: timedRehedgeSchema.optional()
|
|
34886
34888
|
}).optional(),
|
|
34887
34889
|
alerts: z.object({ outOfRangeEnabled: z.boolean().optional() }).optional(),
|
|
@@ -35137,7 +35139,7 @@ function mulDiv({ value, numerator, denominator }) {
|
|
|
35137
35139
|
function getMinQueuedDepositEpoch({ queuedDeposits }) {
|
|
35138
35140
|
const eligible = queuedDeposits.filter((deposit) => deposit.amount > 0n).map((deposit) => deposit.epoch);
|
|
35139
35141
|
if (eligible.length === 0) return null;
|
|
35140
|
-
return eligible.reduce((min, epoch) => epoch < min ? epoch : min);
|
|
35142
|
+
return eligible.reduce((min$1, epoch) => epoch < min$1 ? epoch : min$1);
|
|
35141
35143
|
}
|
|
35142
35144
|
function calculateClaimableSharesFromQueuedDeposits({ queuedDeposits, depositEpochStates, currentDepositEpoch }) {
|
|
35143
35145
|
const epochStatesByEpoch = new Map(depositEpochStates.map((state) => [state.epoch, state]));
|
|
@@ -36306,8 +36308,8 @@ var VaultTransactionGasCostLimitError = class extends Error {
|
|
|
36306
36308
|
gasLimit;
|
|
36307
36309
|
maximumAffordableFeePerGas;
|
|
36308
36310
|
minimumRequiredFeePerGas;
|
|
36309
|
-
constructor({ gasLimit, maximumAffordableFeePerGas, minimumRequiredFeePerGas }) {
|
|
36310
|
-
super(`Vault transaction cannot fit the ${
|
|
36311
|
+
constructor({ gasLimit, maximumAffordableFeePerGas, minimumRequiredFeePerGas, maximumGasCost = MAX_VAULT_TRANSACTION_GAS_COST }) {
|
|
36312
|
+
super(`Vault transaction cannot fit the ${maximumGasCost.toString()} wei gas-cost limit: gasLimit=${gasLimit.toString()}, maximumAffordableFeePerGas=${maximumAffordableFeePerGas.toString()}, minimumRequiredFeePerGas=${minimumRequiredFeePerGas.toString()}`);
|
|
36311
36313
|
this.name = "VaultTransactionGasCostLimitError";
|
|
36312
36314
|
this.gasLimit = gasLimit;
|
|
36313
36315
|
this.maximumAffordableFeePerGas = maximumAffordableFeePerGas;
|
|
@@ -36328,6 +36330,11 @@ var VaultTransactionReplacementLimitError = class extends Error {
|
|
|
36328
36330
|
this.maximumAffordableFeePerGas = maximumAffordableFeePerGas;
|
|
36329
36331
|
}
|
|
36330
36332
|
};
|
|
36333
|
+
function resolveMaximumGasCost(feePolicy) {
|
|
36334
|
+
const maximum = feePolicy?.maxTransactionGasCost ?? MAX_VAULT_TRANSACTION_GAS_COST;
|
|
36335
|
+
if (maximum <= 0n) throw new Error("Vault transaction gas budget must be positive");
|
|
36336
|
+
return maximum;
|
|
36337
|
+
}
|
|
36331
36338
|
function ceilMultiplyFraction(value, numerator, denominator) {
|
|
36332
36339
|
return (value * numerator + denominator - 1n) / denominator;
|
|
36333
36340
|
}
|
|
@@ -36402,30 +36409,32 @@ function resolveRpcPriorityFeeQuote({ baseFeePerGas, rawPriorityFeePerGas, minim
|
|
|
36402
36409
|
source: "rpc_priority_fee"
|
|
36403
36410
|
};
|
|
36404
36411
|
}
|
|
36405
|
-
function getVaultTransactionReplacementFeeQuote({ originalQuote, historicalQuote, gasLimit, finalReplacement = false, staleBoundsReplacement = false }) {
|
|
36412
|
+
function getVaultTransactionReplacementFeeQuote({ originalQuote, historicalQuote, gasLimit, finalReplacement = false, staleBoundsReplacement = false, feePolicy }) {
|
|
36406
36413
|
if (gasLimit <= 0n) throw new Error(`Vault transaction gas limit must be positive, received ${gasLimit.toString()}`);
|
|
36407
|
-
const bumpedPriorityFee = staleBoundsReplacement ? ceilMultiplyFraction(originalQuote.maxPriorityFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR) : ceilMultiplyFraction(originalQuote.maxPriorityFeePerGas, DELTA_HEDGE_PRIORITY_FEE_BUMP_NUMERATOR, DELTA_HEDGE_PRIORITY_FEE_BUMP_DENOMINATOR);
|
|
36414
|
+
const bumpedPriorityFee = staleBoundsReplacement || feePolicy?.marketPriorityFees ? ceilMultiplyFraction(originalQuote.maxPriorityFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR) : ceilMultiplyFraction(originalQuote.maxPriorityFeePerGas, DELTA_HEDGE_PRIORITY_FEE_BUMP_NUMERATOR, DELTA_HEDGE_PRIORITY_FEE_BUMP_DENOMINATOR);
|
|
36408
36415
|
const bumpedMaxFee = ceilMultiplyFraction(originalQuote.maxFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR);
|
|
36409
36416
|
const escalatingPriorityFee = historicalQuote.maxPriorityFeePerGas > bumpedPriorityFee ? historicalQuote.maxPriorityFeePerGas : bumpedPriorityFee;
|
|
36410
|
-
const
|
|
36411
|
-
const
|
|
36417
|
+
const maximumGasCost = resolveMaximumGasCost(feePolicy);
|
|
36418
|
+
const priorityFeeLimit = feePolicy?.marketPriorityFees ? maximumGasCost / gasLimit : staleBoundsReplacement ? MAX_STALE_DELTA_HEDGE_PRIORITY_FEE_PER_GAS : finalReplacement ? MAX_VAULT_PRIORITY_FEE_PER_GAS : MAX_DELTA_HEDGE_PRIORITY_FEE_PER_GAS;
|
|
36419
|
+
const desiredMaxPriorityFeePerGas = feePolicy?.marketPriorityFees ? escalatingPriorityFee : finalReplacement ? MAX_VAULT_PRIORITY_FEE_PER_GAS : staleBoundsReplacement ? bumpedPriorityFee : escalatingPriorityFee;
|
|
36412
36420
|
const requiredReplacementPriorityFee = ceilMultiplyFraction(originalQuote.maxPriorityFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR);
|
|
36413
36421
|
const requiredMaxPriorityFeePerGas = desiredMaxPriorityFeePerGas < priorityFeeLimit ? desiredMaxPriorityFeePerGas : priorityFeeLimit;
|
|
36414
36422
|
if (requiredMaxPriorityFeePerGas < requiredReplacementPriorityFee) throw new VaultTransactionReplacementLimitError({
|
|
36415
|
-
code: "PriorityFeeCapExceeded",
|
|
36423
|
+
code: feePolicy?.marketPriorityFees ? "GasCostCapExceeded" : "PriorityFeeCapExceeded",
|
|
36416
36424
|
gasLimit,
|
|
36417
36425
|
requiredMaxFeePerGas: originalQuote.maxFeePerGas,
|
|
36418
36426
|
requiredMaxPriorityFeePerGas: requiredReplacementPriorityFee,
|
|
36419
|
-
maximumAffordableFeePerGas:
|
|
36427
|
+
maximumAffordableFeePerGas: maximumGasCost / gasLimit
|
|
36420
36428
|
});
|
|
36421
|
-
const bufferedBaseFee = historicalQuote.minimumMaxFeePerGas - (historicalQuote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
|
|
36429
|
+
const bufferedBaseFee = feePolicy?.marketPriorityFees ? historicalQuote.maxFeePerGas - historicalQuote.maxPriorityFeePerGas : historicalQuote.minimumMaxFeePerGas - (historicalQuote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
|
|
36422
36430
|
const currentMarketMaxFee = bufferedBaseFee + requiredMaxPriorityFeePerGas;
|
|
36423
36431
|
const desiredMaxFeePerGas = currentMarketMaxFee > bumpedMaxFee ? currentMarketMaxFee : bumpedMaxFee;
|
|
36424
|
-
const maximumAffordableFeePerGas =
|
|
36425
|
-
|
|
36432
|
+
const maximumAffordableFeePerGas = maximumGasCost / gasLimit;
|
|
36433
|
+
const minimumMarketFeePerGas = (historicalQuote.currentBaseFeePerGas ?? bufferedBaseFee) + requiredMaxPriorityFeePerGas;
|
|
36434
|
+
if (bumpedMaxFee > maximumAffordableFeePerGas || requiredMaxPriorityFeePerGas > maximumAffordableFeePerGas || feePolicy?.marketPriorityFees && minimumMarketFeePerGas > maximumAffordableFeePerGas) throw new VaultTransactionReplacementLimitError({
|
|
36426
36435
|
code: "GasCostCapExceeded",
|
|
36427
36436
|
gasLimit,
|
|
36428
|
-
requiredMaxFeePerGas: bumpedMaxFee,
|
|
36437
|
+
requiredMaxFeePerGas: feePolicy?.marketPriorityFees && minimumMarketFeePerGas > bumpedMaxFee ? minimumMarketFeePerGas : bumpedMaxFee,
|
|
36429
36438
|
requiredMaxPriorityFeePerGas,
|
|
36430
36439
|
maximumAffordableFeePerGas
|
|
36431
36440
|
});
|
|
@@ -36448,13 +36457,15 @@ function resolveFallbackQuote({ maxFeePerGas: estimatedMaxFeePerGas, maxPriority
|
|
|
36448
36457
|
source: "viem_fallback"
|
|
36449
36458
|
};
|
|
36450
36459
|
}
|
|
36451
|
-
function applyVaultTransactionGasCostLimit(quote, gasLimit) {
|
|
36460
|
+
function applyVaultTransactionGasCostLimit(quote, gasLimit, feePolicy) {
|
|
36452
36461
|
if (gasLimit <= 0n) throw new Error(`Vault transaction gas limit must be positive, received ${gasLimit.toString()}`);
|
|
36453
|
-
const
|
|
36462
|
+
const maximumGasCost = resolveMaximumGasCost(feePolicy);
|
|
36463
|
+
const maximumAffordableFeePerGas = maximumGasCost / gasLimit;
|
|
36454
36464
|
if (maximumAffordableFeePerGas < quote.minimumMaxFeePerGas) throw new VaultTransactionGasCostLimitError({
|
|
36455
36465
|
gasLimit,
|
|
36456
36466
|
maximumAffordableFeePerGas,
|
|
36457
|
-
minimumRequiredFeePerGas: quote.minimumMaxFeePerGas
|
|
36467
|
+
minimumRequiredFeePerGas: quote.minimumMaxFeePerGas,
|
|
36468
|
+
maximumGasCost
|
|
36458
36469
|
});
|
|
36459
36470
|
if (quote.maxFeePerGas <= maximumAffordableFeePerGas) return quote;
|
|
36460
36471
|
const bufferedBaseFee = quote.minimumMaxFeePerGas - (quote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
|
|
@@ -36469,8 +36480,9 @@ function bufferVaultTransactionGasEstimate(gasEstimate) {
|
|
|
36469
36480
|
if (gasEstimate <= 0n) throw new Error(`Vault transaction gas estimate must be positive, received ${gasEstimate.toString()}`);
|
|
36470
36481
|
return ceilMultiplyFraction(gasEstimate, GAS_ESTIMATE_BUFFER_NUMERATOR, GAS_ESTIMATE_BUFFER_DENOMINATOR);
|
|
36471
36482
|
}
|
|
36472
|
-
function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
|
|
36483
|
+
function validateVaultSignedTransactionFeeCaps(feeCaps, quote, feePolicy) {
|
|
36473
36484
|
const { chainId, gasLimit, maxFeePerGas, maxPriorityFeePerGas } = feeCaps;
|
|
36485
|
+
const maximumGasCost = resolveMaximumGasCost(feePolicy);
|
|
36474
36486
|
const minimumPriorityFeePerGas = quote?.minimumPriorityFeePerGas ?? getChainPriorityFeeFloor(chainId) ?? MIN_VAULT_PRIORITY_FEE_PER_GAS;
|
|
36475
36487
|
if (maxFeePerGas === null || maxPriorityFeePerGas === null) return {
|
|
36476
36488
|
valid: false,
|
|
@@ -36487,15 +36499,15 @@ function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
|
|
|
36487
36499
|
code: "PriorityFeeTooLow",
|
|
36488
36500
|
reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must be at least ${minimumPriorityFeePerGas.toString()} wei.`
|
|
36489
36501
|
};
|
|
36490
|
-
if (maxPriorityFeePerGas > MAX_VAULT_PRIORITY_FEE_PER_GAS) return {
|
|
36502
|
+
if (!feePolicy?.marketPriorityFees && maxPriorityFeePerGas > MAX_VAULT_PRIORITY_FEE_PER_GAS) return {
|
|
36491
36503
|
valid: false,
|
|
36492
36504
|
code: "PriorityFeeTooHigh",
|
|
36493
36505
|
reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must not exceed ${MAX_VAULT_PRIORITY_FEE_PER_GAS.toString()} wei (3 gwei).`
|
|
36494
36506
|
};
|
|
36495
|
-
if (gasLimit !== void 0 && gasLimit !== null && gasLimit * maxFeePerGas >
|
|
36507
|
+
if (gasLimit !== void 0 && gasLimit !== null && gasLimit * maxFeePerGas > maximumGasCost) return {
|
|
36496
36508
|
valid: false,
|
|
36497
36509
|
code: "GasCostTooHigh",
|
|
36498
|
-
reason: `Signed transaction maximum gas cost (${(gasLimit * maxFeePerGas).toString()} wei) must not exceed ${
|
|
36510
|
+
reason: `Signed transaction maximum gas cost (${(gasLimit * maxFeePerGas).toString()} wei) must not exceed ${maximumGasCost.toString()} wei.`
|
|
36499
36511
|
};
|
|
36500
36512
|
if (quote !== void 0) {
|
|
36501
36513
|
const feeRequirementDescription = quote.currentBaseFeePerGas === void 0 ? "buffered next-block base fee" : "current base fee";
|
|
@@ -36922,6 +36934,118 @@ function formatPerSecondRateWadAsAprPct(ratePerSecondWad, precision) {
|
|
|
36922
36934
|
return formatWadPercent(annualizePerSecondRateWad(ratePerSecondWad), precision);
|
|
36923
36935
|
}
|
|
36924
36936
|
|
|
36937
|
+
//#endregion
|
|
36938
|
+
//#region src/hypoVault/adaptiveHedgeFees.ts
|
|
36939
|
+
const SHOCK_LOOKBACK_SECONDS = 600n;
|
|
36940
|
+
const SHOCK_LATCH_SECONDS = 1200n;
|
|
36941
|
+
const VOLUSDC_INCIDENT_GAS_ENVELOPE = 1250000000000000000n;
|
|
36942
|
+
const VOLUSDC_HEDGE_FEE_POLICY = Object.freeze({
|
|
36943
|
+
maxTransactionGasCost: VOLUSDC_INCIDENT_GAS_ENVELOPE * 8n / 9n,
|
|
36944
|
+
marketPriorityFees: true
|
|
36945
|
+
});
|
|
36946
|
+
function resolveHedgeShock({ sqrtPriceX96, previousSqrtPriceX96, timestamp, activeUntil = 0n, priceAssetIndex }) {
|
|
36947
|
+
if (sqrtPriceX96 <= 0n || previousSqrtPriceX96 <= 0n) throw new Error("Shock detection requires positive pool prices");
|
|
36948
|
+
const previous$1 = previousSqrtPriceX96 ** 2n;
|
|
36949
|
+
const current = sqrtPriceX96 ** 2n;
|
|
36950
|
+
const difference = current > previous$1 ? current - previous$1 : previous$1 - current;
|
|
36951
|
+
const denominator = priceAssetIndex === 0n ? previous$1 : current;
|
|
36952
|
+
const shocked = difference * 10000n >= denominator * 200n;
|
|
36953
|
+
const nextActiveUntil = shocked ? timestamp + SHOCK_LATCH_SECONDS : activeUntil;
|
|
36954
|
+
return {
|
|
36955
|
+
shocked,
|
|
36956
|
+
activeUntil: nextActiveUntil,
|
|
36957
|
+
active: timestamp < nextActiveUntil
|
|
36958
|
+
};
|
|
36959
|
+
}
|
|
36960
|
+
async function getHedgeShock({ client, poolAddress, activeUntil, priceAssetIndex }) {
|
|
36961
|
+
const blockTimeMs = client.chain?.blockTime;
|
|
36962
|
+
if (blockTimeMs === void 0 || !Number.isSafeInteger(blockTimeMs) || blockTimeMs <= 0) throw new Error("Shock detection requires a valid network block time");
|
|
36963
|
+
const averageBlockTimeMs = BigInt(blockTimeMs);
|
|
36964
|
+
const lookbackBlocks = (SHOCK_LOOKBACK_SECONDS * 1000n + averageBlockTimeMs - 1n) / averageBlockTimeMs;
|
|
36965
|
+
const block = await getBlock(client, { blockTag: "latest" });
|
|
36966
|
+
const metadata = await getPoolMetadata({
|
|
36967
|
+
client,
|
|
36968
|
+
poolAddress
|
|
36969
|
+
});
|
|
36970
|
+
if (metadata.isV4) throw new Error("Adaptive hedge fees require a Uniswap v3 market");
|
|
36971
|
+
const previousBlock = block.number > lookbackBlocks ? block.number - lookbackBlocks : 0n;
|
|
36972
|
+
const address = metadata.underlyingPoolId;
|
|
36973
|
+
const [current, previous$1] = await Promise.all([readContract(client, {
|
|
36974
|
+
address,
|
|
36975
|
+
abi: uniswapV3PoolAbi,
|
|
36976
|
+
functionName: "slot0",
|
|
36977
|
+
blockNumber: block.number
|
|
36978
|
+
}), readContract(client, {
|
|
36979
|
+
address,
|
|
36980
|
+
abi: uniswapV3PoolAbi,
|
|
36981
|
+
functionName: "slot0",
|
|
36982
|
+
blockNumber: previousBlock
|
|
36983
|
+
})]);
|
|
36984
|
+
return {
|
|
36985
|
+
...resolveHedgeShock({
|
|
36986
|
+
sqrtPriceX96: current[0],
|
|
36987
|
+
previousSqrtPriceX96: previous$1[0],
|
|
36988
|
+
timestamp: block.timestamp,
|
|
36989
|
+
activeUntil,
|
|
36990
|
+
priceAssetIndex
|
|
36991
|
+
}),
|
|
36992
|
+
blockNumber: block.number,
|
|
36993
|
+
blockHash: block.hash,
|
|
36994
|
+
timestamp: block.timestamp
|
|
36995
|
+
};
|
|
36996
|
+
}
|
|
36997
|
+
function resolveAdaptiveHedgeFeeQuote({ baseFeePerGas, rewards, urgent }) {
|
|
36998
|
+
if (rewards.length === 0 || rewards.some((reward) => reward < 0n) || baseFeePerGas < 0n) throw new Error("Incomplete adaptive hedge fee history");
|
|
36999
|
+
const sorted = [...rewards].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
37000
|
+
const upper = sorted[Math.floor(sorted.length / 2)];
|
|
37001
|
+
if (upper === void 0) throw new Error("Missing adaptive hedge fee median");
|
|
37002
|
+
const lower = sorted[Math.max(0, Math.floor((sorted.length - 1) / 2))] ?? upper;
|
|
37003
|
+
const rawPriorityFeePerGas = (lower + upper) / 2n;
|
|
37004
|
+
const floor = urgent ? 3000000000n : 100000000n;
|
|
37005
|
+
const maxPriorityFeePerGas = rawPriorityFeePerGas > floor ? rawPriorityFeePerGas : floor;
|
|
37006
|
+
const maxFeePerGas = baseFeePerGas * 2n + maxPriorityFeePerGas;
|
|
37007
|
+
return {
|
|
37008
|
+
currentBaseFeePerGas: baseFeePerGas,
|
|
37009
|
+
rawPriorityFeePerGas,
|
|
37010
|
+
maxPriorityFeePerGas,
|
|
37011
|
+
maxFeePerGas,
|
|
37012
|
+
minimumMaxFeePerGas: baseFeePerGas + maxPriorityFeePerGas,
|
|
37013
|
+
minimumPriorityFeePerGas: maxPriorityFeePerGas,
|
|
37014
|
+
source: "adaptive_hedge"
|
|
37015
|
+
};
|
|
37016
|
+
}
|
|
37017
|
+
async function getAdaptiveHedgeFeeQuote(client, urgent) {
|
|
37018
|
+
const history = await getFeeHistory(client, {
|
|
37019
|
+
blockCount: 5,
|
|
37020
|
+
blockTag: "latest",
|
|
37021
|
+
rewardPercentiles: urgent ? [75, 90] : [75]
|
|
37022
|
+
});
|
|
37023
|
+
const baseFeePerGas = history.baseFeePerGas.at(-2);
|
|
37024
|
+
const rewards = history.reward?.flatMap((row) => {
|
|
37025
|
+
const value = row[urgent ? 1 : 0];
|
|
37026
|
+
return value === void 0 ? [] : [value];
|
|
37027
|
+
});
|
|
37028
|
+
if (baseFeePerGas === void 0 || history.baseFeePerGas.length !== 6 || history.reward?.length !== 5 || rewards === void 0 || rewards.length !== 5) throw new Error("Incomplete adaptive hedge fee history");
|
|
37029
|
+
const quote = resolveAdaptiveHedgeFeeQuote({
|
|
37030
|
+
baseFeePerGas,
|
|
37031
|
+
rewards,
|
|
37032
|
+
urgent
|
|
37033
|
+
});
|
|
37034
|
+
if (!urgent) return quote;
|
|
37035
|
+
const competitiveRewards = history.reward?.flatMap((row) => row[0] === void 0 ? [] : [row[0]]);
|
|
37036
|
+
if (competitiveRewards === void 0 || competitiveRewards.length !== 5) throw new Error("Incomplete competitive hedge fee history");
|
|
37037
|
+
const competitive = resolveAdaptiveHedgeFeeQuote({
|
|
37038
|
+
baseFeePerGas,
|
|
37039
|
+
rewards: competitiveRewards,
|
|
37040
|
+
urgent: true
|
|
37041
|
+
});
|
|
37042
|
+
if (competitive.maxPriorityFeePerGas > quote.maxPriorityFeePerGas) throw new Error("Inconsistent competitive hedge fee history");
|
|
37043
|
+
return {
|
|
37044
|
+
...quote,
|
|
37045
|
+
competitivePriorityFeePerGas: competitive.maxPriorityFeePerGas
|
|
37046
|
+
};
|
|
37047
|
+
}
|
|
37048
|
+
|
|
36925
37049
|
//#endregion
|
|
36926
37050
|
//#region src/hypoVault/analytics/donations.ts
|
|
36927
37051
|
const Precision$1 = Decimal.clone({ precision: 60 });
|
|
@@ -37482,6 +37606,753 @@ async function fetchVaultPositionExposureHistory(params) {
|
|
|
37482
37606
|
};
|
|
37483
37607
|
}
|
|
37484
37608
|
|
|
37609
|
+
//#endregion
|
|
37610
|
+
//#region src/hypoVault/budgetedHedgeFees.ts
|
|
37611
|
+
function selectBudgetedHedgeFees({ quote, gasLimit, feePolicy, originalQuote }) {
|
|
37612
|
+
const baseFee = quote.currentBaseFeePerGas;
|
|
37613
|
+
const floor = quote.competitivePriorityFeePerGas;
|
|
37614
|
+
if (quote.source !== "adaptive_hedge" || !feePolicy.marketPriorityFees || gasLimit <= 0n || feePolicy.maxTransactionGasCost <= 0n || baseFee === void 0 || baseFee < 0n || floor === void 0 || floor < 0n || floor > quote.maxPriorityFeePerGas) throw new Error("Incomplete budgeted hedge fee authority");
|
|
37615
|
+
const bump = (value) => (value * REPLACEMENT_FEE_BUMP_NUMERATOR + REPLACEMENT_FEE_BUMP_DENOMINATOR - 1n) / REPLACEMENT_FEE_BUMP_DENOMINATOR;
|
|
37616
|
+
const hardMaximum = feePolicy.maxTransactionGasCost / gasLimit;
|
|
37617
|
+
const maximumAffordableFeePerGas = originalQuote === void 0 ? hardMaximum * REPLACEMENT_FEE_BUMP_DENOMINATOR / REPLACEMENT_FEE_BUMP_NUMERATOR : hardMaximum;
|
|
37618
|
+
const minimumPriorityFeePerGas = originalQuote === void 0 || floor >= bump(originalQuote.maxPriorityFeePerGas) ? floor : bump(originalQuote.maxPriorityFeePerGas);
|
|
37619
|
+
const minimumRequiredFeePerGas = originalQuote === void 0 || baseFee * 2n + minimumPriorityFeePerGas >= bump(originalQuote.maxFeePerGas) ? baseFee * 2n + minimumPriorityFeePerGas : bump(originalQuote.maxFeePerGas);
|
|
37620
|
+
if (minimumRequiredFeePerGas > maximumAffordableFeePerGas) return {
|
|
37621
|
+
status: "wait",
|
|
37622
|
+
maximumAffordableFeePerGas,
|
|
37623
|
+
minimumRequiredFeePerGas,
|
|
37624
|
+
minimumPriorityFeePerGas
|
|
37625
|
+
};
|
|
37626
|
+
const target = quote.maxPriorityFeePerGas > minimumPriorityFeePerGas ? quote.maxPriorityFeePerGas : minimumPriorityFeePerGas;
|
|
37627
|
+
const tipRoom = maximumAffordableFeePerGas - 2n * baseFee;
|
|
37628
|
+
const selectedTip = target < tipRoom ? target : tipRoom;
|
|
37629
|
+
const desiredMaxFee = 2n * baseFee + selectedTip;
|
|
37630
|
+
const maxFeePerGas = desiredMaxFee >= minimumRequiredFeePerGas ? desiredMaxFee : minimumRequiredFeePerGas;
|
|
37631
|
+
return {
|
|
37632
|
+
status: "ready",
|
|
37633
|
+
quote: {
|
|
37634
|
+
...quote,
|
|
37635
|
+
maxFeePerGas,
|
|
37636
|
+
maxPriorityFeePerGas: selectedTip,
|
|
37637
|
+
minimumMaxFeePerGas: baseFee + selectedTip,
|
|
37638
|
+
minimumPriorityFeePerGas: selectedTip
|
|
37639
|
+
},
|
|
37640
|
+
feePolicy: Object.freeze({
|
|
37641
|
+
...feePolicy,
|
|
37642
|
+
maxTransactionGasCost: originalQuote === void 0 ? gasLimit * maximumAffordableFeePerGas : feePolicy.maxTransactionGasCost
|
|
37643
|
+
})
|
|
37644
|
+
};
|
|
37645
|
+
}
|
|
37646
|
+
|
|
37647
|
+
//#endregion
|
|
37648
|
+
//#region src/hypoVault/hedgeGain.ts
|
|
37649
|
+
const D = Decimal.clone({ precision: 110 });
|
|
37650
|
+
const Q192$1 = new D(2).pow(192);
|
|
37651
|
+
const decimal = (value) => new D(value.toString());
|
|
37652
|
+
function priceAt(sqrtPriceX96, numeraireIndex) {
|
|
37653
|
+
if (sqrtPriceX96 <= 0n) throw new RangeError("Hedge valuation requires a positive price");
|
|
37654
|
+
const squared = decimal(sqrtPriceX96).pow(2);
|
|
37655
|
+
return numeraireIndex === 0n ? Q192$1.div(squared) : squared.div(Q192$1);
|
|
37656
|
+
}
|
|
37657
|
+
function prepareBook(book) {
|
|
37658
|
+
const quoteIndex = Number(book.numeraireIndex);
|
|
37659
|
+
const assetIndex = 1 - quoteIndex;
|
|
37660
|
+
const points = book.curve.filter(({ tick }) => tick > -887272n && tick < 887272n).map(({ tick, value0, value1 }) => {
|
|
37661
|
+
const values = [value0 + book.balances[0], value1 + book.balances[1]];
|
|
37662
|
+
return {
|
|
37663
|
+
price: priceAt(tickToSqrtPriceX96(tick), book.numeraireIndex),
|
|
37664
|
+
quote: decimal(values[quoteIndex]),
|
|
37665
|
+
asset: decimal(values[assetIndex])
|
|
37666
|
+
};
|
|
37667
|
+
}).sort((a, b) => a.price.cmp(b.price));
|
|
37668
|
+
if (points.length < 2) throw new RangeError("Incomplete option value curve");
|
|
37669
|
+
const first = points[0];
|
|
37670
|
+
const last = points[points.length - 1];
|
|
37671
|
+
if (first === void 0 || last === void 0) throw new RangeError("Missing curve endpoints");
|
|
37672
|
+
const segments = points.slice(1).map((right, index) => {
|
|
37673
|
+
const left = points[index];
|
|
37674
|
+
if (left === void 0 || !left.price.lt(right.price)) throw new RangeError("Invalid option value curve");
|
|
37675
|
+
const lo = left.price.sqrt();
|
|
37676
|
+
const hi = right.price.sqrt();
|
|
37677
|
+
const quoteSlope = right.quote.minus(left.quote).div(hi.minus(lo));
|
|
37678
|
+
const assetSlope = right.asset.minus(left.asset).div(new D(1).div(hi).minus(new D(1).div(lo)));
|
|
37679
|
+
return {
|
|
37680
|
+
lo,
|
|
37681
|
+
hi,
|
|
37682
|
+
a: left.quote.minus(quoteSlope.mul(lo)),
|
|
37683
|
+
b: quoteSlope.plus(assetSlope),
|
|
37684
|
+
c: left.asset.minus(assetSlope.div(lo))
|
|
37685
|
+
};
|
|
37686
|
+
});
|
|
37687
|
+
const valueAt = (sqrtPriceX96) => {
|
|
37688
|
+
const price = priceAt(sqrtPriceX96, book.numeraireIndex);
|
|
37689
|
+
const x = price.sqrt();
|
|
37690
|
+
const segment = segments.find((candidate) => x.gte(candidate.lo) && x.lte(candidate.hi));
|
|
37691
|
+
if (segment !== void 0) return segment.a.plus(segment.b.mul(x)).plus(segment.c.mul(price));
|
|
37692
|
+
const endpoint = price.lt(first.price) ? first : last;
|
|
37693
|
+
return endpoint.quote.plus(endpoint.asset.mul(price));
|
|
37694
|
+
};
|
|
37695
|
+
const minimum = () => {
|
|
37696
|
+
if (last.asset.lt(0)) return void 0;
|
|
37697
|
+
let value = first.quote;
|
|
37698
|
+
for (const point of points) value = D.min(value, point.quote.plus(point.asset.mul(point.price)));
|
|
37699
|
+
for (const segment of segments) {
|
|
37700
|
+
if (segment.c.lte(0)) continue;
|
|
37701
|
+
const x = segment.b.neg().div(segment.c.mul(2));
|
|
37702
|
+
if (x.gt(segment.lo) && x.lt(segment.hi)) value = D.min(value, segment.a.plus(segment.b.mul(x)).plus(segment.c.mul(x.pow(2))));
|
|
37703
|
+
}
|
|
37704
|
+
return value;
|
|
37705
|
+
};
|
|
37706
|
+
return {
|
|
37707
|
+
valueAt,
|
|
37708
|
+
minimum
|
|
37709
|
+
};
|
|
37710
|
+
}
|
|
37711
|
+
function valueFrozenHedgeBook(book, sqrtPriceX96 = book.sqrtPriceX96) {
|
|
37712
|
+
return BigInt(prepareBook(book).valueAt(sqrtPriceX96).floor().toFixed(0));
|
|
37713
|
+
}
|
|
37714
|
+
/** Current price protection; future interest, liquidation and execution are not guaranteed. */
|
|
37715
|
+
function estimateProtectedHedgeGain({ before, after, anchor, roundingReserve }) {
|
|
37716
|
+
if (roundingReserve < 0n) throw new RangeError("Negative hedge rounding reserve");
|
|
37717
|
+
if (before.numeraireIndex !== after.numeraireIndex) throw new RangeError("Hedge books must use the same numeraire");
|
|
37718
|
+
if (anchor === void 0) return {
|
|
37719
|
+
valid: false,
|
|
37720
|
+
protectedGain: 0n,
|
|
37721
|
+
reason: "Missing confirmed gain anchor"
|
|
37722
|
+
};
|
|
37723
|
+
const current = prepareBook(before);
|
|
37724
|
+
const proposed = prepareBook(after);
|
|
37725
|
+
const beforeFloor = current.minimum();
|
|
37726
|
+
const afterFloor = proposed.minimum();
|
|
37727
|
+
if (beforeFloor === void 0 || afterFloor === void 0) return {
|
|
37728
|
+
valid: false,
|
|
37729
|
+
protectedGain: 0n,
|
|
37730
|
+
reason: "Unbounded hedge price tail"
|
|
37731
|
+
};
|
|
37732
|
+
if (proposed.valueAt(before.sqrtPriceX96).gt(current.valueAt(before.sqrtPriceX96).plus(decimal(roundingReserve)))) return {
|
|
37733
|
+
valid: false,
|
|
37734
|
+
protectedGain: 0n,
|
|
37735
|
+
reason: "Unfunded post-hedge value increase"
|
|
37736
|
+
};
|
|
37737
|
+
const anchorMark = current.valueAt(anchor.sqrtPriceX96);
|
|
37738
|
+
const basis = D.max(beforeFloor, anchorMark, decimal(anchor.actualValue));
|
|
37739
|
+
const gain = D.max(0, afterFloor.minus(basis).minus(decimal(roundingReserve)));
|
|
37740
|
+
return {
|
|
37741
|
+
valid: true,
|
|
37742
|
+
protectedGain: BigInt(gain.floor().toFixed(0)),
|
|
37743
|
+
floorAfter: BigInt(afterFloor.floor().toFixed(0)),
|
|
37744
|
+
basis: BigInt(basis.ceil().toFixed(0)),
|
|
37745
|
+
negativeCarry: BigInt(D.max(0, decimal(anchor.actualValue).minus(anchorMark)).ceil().toFixed(0))
|
|
37746
|
+
};
|
|
37747
|
+
}
|
|
37748
|
+
/** Round the two-thirds allowance down and convert at the most expensive allowed gas-asset price. */
|
|
37749
|
+
function getProtectedHedgeGasBudget({ protectedGain, gasAlreadyPaid, numeraireIndex, gasAssetIndex, sqrtPriceLowerX96, sqrtPriceUpperX96 }) {
|
|
37750
|
+
if (protectedGain < 0n || gasAlreadyPaid < 0n || sqrtPriceLowerX96 <= 0n || sqrtPriceUpperX96 < sqrtPriceLowerX96) throw new RangeError("Invalid protected hedge gas budget");
|
|
37751
|
+
const allowance = protectedGain * 2n / 3n;
|
|
37752
|
+
const remaining = allowance > gasAlreadyPaid ? allowance - gasAlreadyPaid : 0n;
|
|
37753
|
+
const budget = numeraireIndex === gasAssetIndex ? remaining : numeraireIndex === 0n ? remaining * sqrtPriceLowerX96 ** 2n / (1n << 192n) : remaining * (1n << 192n) / sqrtPriceUpperX96 ** 2n;
|
|
37754
|
+
const maximum = VOLUSDC_HEDGE_FEE_POLICY.maxTransactionGasCost;
|
|
37755
|
+
return {
|
|
37756
|
+
allowance,
|
|
37757
|
+
remaining,
|
|
37758
|
+
maxTransactionGasCost: budget < maximum ? budget : maximum
|
|
37759
|
+
};
|
|
37760
|
+
}
|
|
37761
|
+
|
|
37762
|
+
//#endregion
|
|
37763
|
+
//#region src/panoptic/v2/simulations/tokenFlow.ts
|
|
37764
|
+
/**
|
|
37765
|
+
* PanopticPool getAssetsOf ABI.
|
|
37766
|
+
* Returns collateral assets (shares converted to underlying) for an account.
|
|
37767
|
+
*/
|
|
37768
|
+
const getAssetsOfAbi = [{
|
|
37769
|
+
type: "function",
|
|
37770
|
+
name: "getAssetsOf",
|
|
37771
|
+
inputs: [{
|
|
37772
|
+
name: "account",
|
|
37773
|
+
type: "address"
|
|
37774
|
+
}],
|
|
37775
|
+
outputs: [{
|
|
37776
|
+
name: "assets0",
|
|
37777
|
+
type: "uint256"
|
|
37778
|
+
}, {
|
|
37779
|
+
name: "assets1",
|
|
37780
|
+
type: "uint256"
|
|
37781
|
+
}],
|
|
37782
|
+
stateMutability: "view"
|
|
37783
|
+
}];
|
|
37784
|
+
/**
|
|
37785
|
+
* PanopticPool multicall ABI (inherited from Uniswap).
|
|
37786
|
+
* Uses delegatecall, preserving msg.sender throughout the chain.
|
|
37787
|
+
*/
|
|
37788
|
+
const multicallAbi = [{
|
|
37789
|
+
type: "function",
|
|
37790
|
+
name: "multicall",
|
|
37791
|
+
inputs: [{
|
|
37792
|
+
name: "data",
|
|
37793
|
+
type: "bytes[]"
|
|
37794
|
+
}],
|
|
37795
|
+
outputs: [{
|
|
37796
|
+
name: "results",
|
|
37797
|
+
type: "bytes[]"
|
|
37798
|
+
}],
|
|
37799
|
+
stateMutability: "nonpayable"
|
|
37800
|
+
}, ...panopticErrorsAbi];
|
|
37801
|
+
const collateralTrackersByClient = new WeakMap();
|
|
37802
|
+
const readCollateralTrackers = (client, poolAddress) => {
|
|
37803
|
+
const collateralTrackersByPool = collateralTrackersByClient.get(client) ?? new Map();
|
|
37804
|
+
collateralTrackersByClient.set(client, collateralTrackersByPool);
|
|
37805
|
+
const cached = collateralTrackersByPool.get(poolAddress);
|
|
37806
|
+
if (cached) return cached;
|
|
37807
|
+
const trackers = client.multicall({
|
|
37808
|
+
contracts: [{
|
|
37809
|
+
address: poolAddress,
|
|
37810
|
+
abi: panopticPoolV2Abi,
|
|
37811
|
+
functionName: "collateralToken0"
|
|
37812
|
+
}, {
|
|
37813
|
+
address: poolAddress,
|
|
37814
|
+
abi: panopticPoolV2Abi,
|
|
37815
|
+
functionName: "collateralToken1"
|
|
37816
|
+
}],
|
|
37817
|
+
allowFailure: false
|
|
37818
|
+
});
|
|
37819
|
+
collateralTrackersByPool.set(poolAddress, trackers);
|
|
37820
|
+
trackers.catch(() => collateralTrackersByPool.delete(poolAddress));
|
|
37821
|
+
return trackers;
|
|
37822
|
+
};
|
|
37823
|
+
const readInterestOwed = async (client, poolAddress, user, blockNumber) => {
|
|
37824
|
+
try {
|
|
37825
|
+
const [tracker0, tracker1] = await readCollateralTrackers(client, poolAddress);
|
|
37826
|
+
const read = {
|
|
37827
|
+
abi: collateralTrackerV2Abi,
|
|
37828
|
+
functionName: "owedInterest",
|
|
37829
|
+
args: [user]
|
|
37830
|
+
};
|
|
37831
|
+
const [interestOwed0, interestOwed1] = await client.multicall({
|
|
37832
|
+
contracts: [{
|
|
37833
|
+
...read,
|
|
37834
|
+
address: tracker0
|
|
37835
|
+
}, {
|
|
37836
|
+
...read,
|
|
37837
|
+
address: tracker1
|
|
37838
|
+
}],
|
|
37839
|
+
allowFailure: false,
|
|
37840
|
+
blockNumber
|
|
37841
|
+
});
|
|
37842
|
+
return {
|
|
37843
|
+
interestOwed0,
|
|
37844
|
+
interestOwed1
|
|
37845
|
+
};
|
|
37846
|
+
} catch {
|
|
37847
|
+
return void 0;
|
|
37848
|
+
}
|
|
37849
|
+
};
|
|
37850
|
+
/**
|
|
37851
|
+
* Simulate a contract call and measure token flow using PanopticPool.multicall.
|
|
37852
|
+
*
|
|
37853
|
+
* This function uses PanopticPool's inherited multicall (delegatecall-based) to chain:
|
|
37854
|
+
* 1. getAssetsOf(user) - read collateral assets before
|
|
37855
|
+
* 2. getCurrentTick() - read pool tick before
|
|
37856
|
+
* 3. Execute the target call (e.g., dispatch)
|
|
37857
|
+
* 4. getCurrentTick() - read pool tick after
|
|
37858
|
+
* 5. getAssetsOf(user) - read collateral assets after
|
|
37859
|
+
*
|
|
37860
|
+
* ## Why PanopticPool.multicall instead of Multicall3?
|
|
37861
|
+
* - Measures **collateral assets** (shares → underlying), not raw wallet balances
|
|
37862
|
+
* - Uses **delegatecall**, preserving msg.sender throughout the chain
|
|
37863
|
+
* - Single contract interaction with PanopticPool
|
|
37864
|
+
* - Correctly reflects what happens during position operations
|
|
37865
|
+
*
|
|
37866
|
+
* ## Same-Block Guarantee
|
|
37867
|
+
* All operations execute within a single eth_call, ensuring atomic consistency.
|
|
37868
|
+
*
|
|
37869
|
+
* @param params - Simulation parameters
|
|
37870
|
+
* @returns Token flow result
|
|
37871
|
+
*
|
|
37872
|
+
* @example
|
|
37873
|
+
* ```typescript
|
|
37874
|
+
* const callData = encodeFunctionData({
|
|
37875
|
+
* abi: panopticPoolV2Abi,
|
|
37876
|
+
* functionName: 'dispatch',
|
|
37877
|
+
* args: [positionIdList, finalPositionIdList, positionSizes, tickAndSpreadLimits, false, 0n],
|
|
37878
|
+
* })
|
|
37879
|
+
*
|
|
37880
|
+
* const result = await simulateWithTokenFlow({
|
|
37881
|
+
* client,
|
|
37882
|
+
* poolAddress,
|
|
37883
|
+
* user: userAddress,
|
|
37884
|
+
* callData,
|
|
37885
|
+
* })
|
|
37886
|
+
*
|
|
37887
|
+
* if (result.success) {
|
|
37888
|
+
* console.log('Token 0 change:', result.tokenFlow.delta0)
|
|
37889
|
+
* console.log('Token 1 change:', result.tokenFlow.delta1)
|
|
37890
|
+
* }
|
|
37891
|
+
* ```
|
|
37892
|
+
*/
|
|
37893
|
+
async function simulateWithTokenFlow(params) {
|
|
37894
|
+
const { client, poolAddress, user, callData, blockNumber, postCallData, preCallData } = params;
|
|
37895
|
+
const getAssetsOfCallData = encodeFunctionData({
|
|
37896
|
+
abi: getAssetsOfAbi,
|
|
37897
|
+
functionName: "getAssetsOf",
|
|
37898
|
+
args: [user]
|
|
37899
|
+
});
|
|
37900
|
+
const getCurrentTickCallData = encodeFunctionData({
|
|
37901
|
+
abi: panopticPoolV2Abi,
|
|
37902
|
+
functionName: "getCurrentTick"
|
|
37903
|
+
});
|
|
37904
|
+
const preLen = preCallData?.length ?? 0;
|
|
37905
|
+
const multicallData = [
|
|
37906
|
+
getAssetsOfCallData,
|
|
37907
|
+
getCurrentTickCallData,
|
|
37908
|
+
...preCallData ?? [],
|
|
37909
|
+
callData,
|
|
37910
|
+
getCurrentTickCallData,
|
|
37911
|
+
getAssetsOfCallData,
|
|
37912
|
+
...postCallData ?? []
|
|
37913
|
+
];
|
|
37914
|
+
try {
|
|
37915
|
+
const [{ result }, interestOwed] = await Promise.all([client.simulateContract({
|
|
37916
|
+
address: poolAddress,
|
|
37917
|
+
abi: multicallAbi,
|
|
37918
|
+
functionName: "multicall",
|
|
37919
|
+
args: [multicallData],
|
|
37920
|
+
account: user,
|
|
37921
|
+
blockNumber
|
|
37922
|
+
}), readInterestOwed(client, poolAddress, user, blockNumber)]);
|
|
37923
|
+
const decodeAssets = (data) => {
|
|
37924
|
+
const decoded = decodeFunctionResult({
|
|
37925
|
+
abi: getAssetsOfAbi,
|
|
37926
|
+
functionName: "getAssetsOf",
|
|
37927
|
+
data
|
|
37928
|
+
});
|
|
37929
|
+
return {
|
|
37930
|
+
assets0: decoded[0],
|
|
37931
|
+
assets1: decoded[1]
|
|
37932
|
+
};
|
|
37933
|
+
};
|
|
37934
|
+
const decodeTick = (data) => {
|
|
37935
|
+
return BigInt(decodeFunctionResult({
|
|
37936
|
+
abi: panopticPoolV2Abi,
|
|
37937
|
+
functionName: "getCurrentTick",
|
|
37938
|
+
data
|
|
37939
|
+
}));
|
|
37940
|
+
};
|
|
37941
|
+
const assetsBefore = decodeAssets(result[0]);
|
|
37942
|
+
const tickBefore = decodeTick(result[1]);
|
|
37943
|
+
const tickAfter = decodeTick(result[3 + preLen]);
|
|
37944
|
+
const assetsAfter = decodeAssets(result[4 + preLen]);
|
|
37945
|
+
const preCallResults = preLen > 0 ? result.slice(2, 2 + preLen) : void 0;
|
|
37946
|
+
const postCallResults = postCallData && postCallData.length > 0 ? result.slice(5 + preLen) : void 0;
|
|
37947
|
+
const delta0 = assetsAfter.assets0 - assetsBefore.assets0;
|
|
37948
|
+
const delta1 = assetsAfter.assets1 - assetsBefore.assets1;
|
|
37949
|
+
let gasEstimate = 0n;
|
|
37950
|
+
try {
|
|
37951
|
+
if (params.estimateGas !== false) gasEstimate = await client.estimateGas({
|
|
37952
|
+
account: user,
|
|
37953
|
+
to: poolAddress,
|
|
37954
|
+
data: callData,
|
|
37955
|
+
blockNumber
|
|
37956
|
+
});
|
|
37957
|
+
} catch {}
|
|
37958
|
+
return {
|
|
37959
|
+
success: true,
|
|
37960
|
+
tokenFlow: {
|
|
37961
|
+
delta0,
|
|
37962
|
+
delta1,
|
|
37963
|
+
balanceBefore0: assetsBefore.assets0,
|
|
37964
|
+
balanceBefore1: assetsBefore.assets1,
|
|
37965
|
+
balanceAfter0: assetsAfter.assets0,
|
|
37966
|
+
balanceAfter1: assetsAfter.assets1,
|
|
37967
|
+
tickBefore,
|
|
37968
|
+
tickAfter,
|
|
37969
|
+
...interestOwed
|
|
37970
|
+
},
|
|
37971
|
+
gasEstimate,
|
|
37972
|
+
postCallResults,
|
|
37973
|
+
preCallResults
|
|
37974
|
+
};
|
|
37975
|
+
} catch (error) {
|
|
37976
|
+
return {
|
|
37977
|
+
success: false,
|
|
37978
|
+
error: error instanceof Error ? error.message : "Simulation failed",
|
|
37979
|
+
rawError: error instanceof Error ? error : void 0,
|
|
37980
|
+
gasEstimate: 0n
|
|
37981
|
+
};
|
|
37982
|
+
}
|
|
37983
|
+
}
|
|
37984
|
+
|
|
37985
|
+
//#endregion
|
|
37986
|
+
//#region src/hypoVault/hedgeGainQuote.ts
|
|
37987
|
+
const MASK128 = (1n << 128n) - 1n;
|
|
37988
|
+
const Q192 = 1n << 192n;
|
|
37989
|
+
const ceilDiv = (value, divisor) => (value + divisor - 1n) / divisor;
|
|
37990
|
+
const max = (a, b) => a > b ? a : b;
|
|
37991
|
+
const min = (a, b) => a < b ? a : b;
|
|
37992
|
+
const assetsAbi = [{
|
|
37993
|
+
type: "function",
|
|
37994
|
+
name: "getAssetsOf",
|
|
37995
|
+
stateMutability: "view",
|
|
37996
|
+
inputs: [{
|
|
37997
|
+
name: "account",
|
|
37998
|
+
type: "address"
|
|
37999
|
+
}],
|
|
38000
|
+
outputs: [{ type: "uint256" }, { type: "uint256" }]
|
|
38001
|
+
}];
|
|
38002
|
+
function fullPositions(data, ids) {
|
|
38003
|
+
const [shortPremium, longPremium, balances] = decodeFunctionResult({
|
|
38004
|
+
abi: panopticPoolV2Abi,
|
|
38005
|
+
functionName: "getFullPositionsData",
|
|
38006
|
+
data
|
|
38007
|
+
});
|
|
38008
|
+
if (balances.length !== ids.length) throw new Error("Incomplete hedge position balances");
|
|
38009
|
+
const positions = ids.map((tokenId, index) => {
|
|
38010
|
+
const packed = balances[index];
|
|
38011
|
+
if (packed === void 0 || (packed & MASK128) === 0n) throw new Error("Missing active hedge position");
|
|
38012
|
+
return {
|
|
38013
|
+
tokenId,
|
|
38014
|
+
positionSize: packed & MASK128
|
|
38015
|
+
};
|
|
38016
|
+
});
|
|
38017
|
+
return {
|
|
38018
|
+
positions,
|
|
38019
|
+
premium: [(shortPremium & MASK128) - (longPremium & MASK128), (shortPremium >> 128n) - (longPremium >> 128n)]
|
|
38020
|
+
};
|
|
38021
|
+
}
|
|
38022
|
+
async function readVaultHedgeBook({ client, poolAddress, account, queryAddress, numeraire, fromBlock, blockNumber, metadata: prefetchedMetadata }) {
|
|
38023
|
+
const block = await client.getBlock({ blockNumber });
|
|
38024
|
+
const metadata = prefetchedMetadata ?? await getPoolMetadata({
|
|
38025
|
+
client,
|
|
38026
|
+
poolAddress
|
|
38027
|
+
});
|
|
38028
|
+
const gasAsset = getChainDeployment(client.chain?.id ?? 0)?.sfpmSwap?.weth;
|
|
38029
|
+
const tokens = [metadata.token0Asset, metadata.token1Asset];
|
|
38030
|
+
const quoteIndex = tokens.findIndex((token) => token.toLowerCase() === numeraire.toLowerCase());
|
|
38031
|
+
const gasIndex = tokens.findIndex((token) => token.toLowerCase() === gasAsset?.toLowerCase());
|
|
38032
|
+
if (metadata.isV4 || quoteIndex !== 0 && quoteIndex !== 1 || gasIndex !== 0 && gasIndex !== 1) throw new Error("Protected hedge fees require a supported native-gas v3 pair");
|
|
38033
|
+
const numeraireIndex = quoteIndex === 0 ? 0n : 1n;
|
|
38034
|
+
const gasAssetIndex = gasIndex === 0 ? 0n : 1n;
|
|
38035
|
+
if (numeraireIndex === gasAssetIndex) throw new Error("Hedge numeraire must differ from gas asset");
|
|
38036
|
+
if ((gasIndex === 0 ? metadata.token0Decimals : metadata.token1Decimals) !== 18n) throw new Error("Native gas conversion requires an eighteen-decimal wrapped asset");
|
|
38037
|
+
const ids = await getOpenPositionIds({
|
|
38038
|
+
client,
|
|
38039
|
+
chainId: BigInt(client.chain?.id ?? 0),
|
|
38040
|
+
poolAddress,
|
|
38041
|
+
account,
|
|
38042
|
+
fromBlock,
|
|
38043
|
+
toBlock: block.number
|
|
38044
|
+
});
|
|
38045
|
+
if (ids === null || ids.length === 0 || new Set(ids).size !== ids.length) throw new Error("Missing complete option book");
|
|
38046
|
+
const fullCall = encodeFunctionData({
|
|
38047
|
+
abi: panopticPoolV2Abi,
|
|
38048
|
+
functionName: "getFullPositionsData",
|
|
38049
|
+
args: [
|
|
38050
|
+
account,
|
|
38051
|
+
true,
|
|
38052
|
+
ids
|
|
38053
|
+
]
|
|
38054
|
+
});
|
|
38055
|
+
const [results, nativeBalance] = await Promise.all([client.multicall({
|
|
38056
|
+
contracts: [
|
|
38057
|
+
{
|
|
38058
|
+
address: poolAddress,
|
|
38059
|
+
abi: panopticPoolV2Abi,
|
|
38060
|
+
functionName: "getFullPositionsData",
|
|
38061
|
+
args: [
|
|
38062
|
+
account,
|
|
38063
|
+
true,
|
|
38064
|
+
ids
|
|
38065
|
+
]
|
|
38066
|
+
},
|
|
38067
|
+
{
|
|
38068
|
+
address: poolAddress,
|
|
38069
|
+
abi: panopticPoolV2Abi,
|
|
38070
|
+
functionName: "numberOfLegs",
|
|
38071
|
+
args: [account]
|
|
38072
|
+
},
|
|
38073
|
+
{
|
|
38074
|
+
address: poolAddress,
|
|
38075
|
+
abi: assetsAbi,
|
|
38076
|
+
functionName: "getAssetsOf",
|
|
38077
|
+
args: [account]
|
|
38078
|
+
},
|
|
38079
|
+
{
|
|
38080
|
+
address: metadata.underlyingPoolId,
|
|
38081
|
+
abi: uniswapV3PoolAbi,
|
|
38082
|
+
functionName: "slot0"
|
|
38083
|
+
},
|
|
38084
|
+
{
|
|
38085
|
+
address: metadata.token0Asset,
|
|
38086
|
+
abi: erc20Abi,
|
|
38087
|
+
functionName: "balanceOf",
|
|
38088
|
+
args: [account]
|
|
38089
|
+
},
|
|
38090
|
+
{
|
|
38091
|
+
address: metadata.token1Asset,
|
|
38092
|
+
abi: erc20Abi,
|
|
38093
|
+
functionName: "balanceOf",
|
|
38094
|
+
args: [account]
|
|
38095
|
+
}
|
|
38096
|
+
],
|
|
38097
|
+
blockNumber: block.number,
|
|
38098
|
+
allowFailure: false
|
|
38099
|
+
}), client.getBalance({
|
|
38100
|
+
address: account,
|
|
38101
|
+
blockNumber: block.number
|
|
38102
|
+
})]);
|
|
38103
|
+
const [full, legCount, collateral, spot, wallet0, wallet1] = results;
|
|
38104
|
+
const positions = ids.map((tokenId, index) => ({
|
|
38105
|
+
tokenId,
|
|
38106
|
+
positionSize: (full[2][index] ?? 0n) & MASK128
|
|
38107
|
+
}));
|
|
38108
|
+
if (full[2].length !== ids.length || positions.some((position) => position.positionSize === 0n) || positions.reduce((count, position) => count + BigInt(decodeTokenId(position.tokenId).legs.length), 0n) !== legCount) throw new Error("Incomplete hedge book leg count");
|
|
38109
|
+
const premium = [(full[0] & MASK128) - (full[1] & MASK128), (full[0] >> 128n) - (full[1] >> 128n)];
|
|
38110
|
+
const wallet = [wallet0 + (gasIndex === 0 ? nativeBalance : 0n), wallet1 + (gasIndex === 1 ? nativeBalance : 0n)];
|
|
38111
|
+
const curve = await getPositionValueCurve({
|
|
38112
|
+
client,
|
|
38113
|
+
queryAddress,
|
|
38114
|
+
positions
|
|
38115
|
+
});
|
|
38116
|
+
const book = {
|
|
38117
|
+
curve,
|
|
38118
|
+
balances: [collateral[0] + wallet[0] + premium[0], collateral[1] + wallet[1] + premium[1]],
|
|
38119
|
+
sqrtPriceX96: spot[0],
|
|
38120
|
+
numeraireIndex
|
|
38121
|
+
};
|
|
38122
|
+
return {
|
|
38123
|
+
book,
|
|
38124
|
+
blockNumber: block.number,
|
|
38125
|
+
blockHash: block.hash,
|
|
38126
|
+
timestamp: block.timestamp,
|
|
38127
|
+
metadata,
|
|
38128
|
+
account,
|
|
38129
|
+
poolAddress,
|
|
38130
|
+
queryAddress,
|
|
38131
|
+
positions,
|
|
38132
|
+
collateral,
|
|
38133
|
+
wallet,
|
|
38134
|
+
nativeBalance,
|
|
38135
|
+
fullCall,
|
|
38136
|
+
gasAssetIndex
|
|
38137
|
+
};
|
|
38138
|
+
}
|
|
38139
|
+
async function quoteProtectedVaultHedge({ client, snapshot, dispatchData, anchor }) {
|
|
38140
|
+
const decoded = decodeFunctionData({
|
|
38141
|
+
abi: panopticPoolV2Abi,
|
|
38142
|
+
data: dispatchData
|
|
38143
|
+
});
|
|
38144
|
+
if (decoded.functionName !== "dispatch") throw new Error("Protected gain requires a dispatch");
|
|
38145
|
+
const [operations, finalIds, sizes, limits, usePremia] = decoded.args;
|
|
38146
|
+
if (usePremia || new Set(operations).size !== operations.length || operations.length !== sizes.length || sizes.length !== limits.length) throw new Error("Unsupported protected hedge dispatch");
|
|
38147
|
+
const existing = new Map(snapshot.positions.map((position) => [position.tokenId, position.positionSize]));
|
|
38148
|
+
const expected = new Map(existing);
|
|
38149
|
+
const reserve = [0n, 0n];
|
|
38150
|
+
let lower = snapshot.book.sqrtPriceX96;
|
|
38151
|
+
let upper = lower;
|
|
38152
|
+
let direction;
|
|
38153
|
+
let swapCount = 0;
|
|
38154
|
+
for (const [index, tokenId] of operations.entries()) {
|
|
38155
|
+
const size = sizes[index];
|
|
38156
|
+
const limit = limits[index];
|
|
38157
|
+
const { legs, tickSpacing } = decodeTokenId(tokenId);
|
|
38158
|
+
const leg = legs[0];
|
|
38159
|
+
if (size === void 0 || limit === void 0 || legs.length !== 1 || leg === void 0 || leg.width !== 0n || leg.isLong) throw new Error("Only standalone loan hedges can authorize protected gain");
|
|
38160
|
+
const prior = existing.get(tokenId);
|
|
38161
|
+
if (prior !== void 0 && size !== 0n || prior === void 0 && size === 0n) throw new Error("Unsupported hedge resize or missing burn");
|
|
38162
|
+
if (size === 0n) expected.delete(tokenId);
|
|
38163
|
+
else expected.set(tokenId, size);
|
|
38164
|
+
if (limit[0] <= limit[1]) continue;
|
|
38165
|
+
const lo = tickToSqrtPriceX96(BigInt(limit[1]));
|
|
38166
|
+
const hi = tickToSqrtPriceX96(BigInt(limit[0]));
|
|
38167
|
+
if (snapshot.book.sqrtPriceX96 < lo || snapshot.book.sqrtPriceX96 > hi) throw new Error("Hedge execution bounds are stale");
|
|
38168
|
+
lower = min(lower, lo);
|
|
38169
|
+
upper = max(upper, hi);
|
|
38170
|
+
const borrowIndex = leg.tokenType === 0n ? 0n : 1n;
|
|
38171
|
+
const counterIndex = borrowIndex === 0n ? 1n : 0n;
|
|
38172
|
+
const outgoing = size === 0n ? counterIndex : borrowIndex;
|
|
38173
|
+
if (direction !== void 0 && direction !== outgoing) throw new Error("Opposing swaps require a separate execution bound");
|
|
38174
|
+
direction = outgoing;
|
|
38175
|
+
const principal = -getLegTokenInventory({
|
|
38176
|
+
...leg,
|
|
38177
|
+
width: 2n
|
|
38178
|
+
}, borrowIndex === 0n ? 887272n : -887272n, size === 0n ? prior ?? 0n : size, tickSpacing, borrowIndex) + 2n;
|
|
38179
|
+
const convert = (sqrt) => borrowIndex === 0n ? ceilDiv(principal * sqrt ** 2n, Q192) : ceilDiv(principal * Q192, sqrt ** 2n);
|
|
38180
|
+
const current = convert(snapshot.book.sqrtPriceX96);
|
|
38181
|
+
const minimum = min(convert(lo), convert(hi));
|
|
38182
|
+
const maximum = max(convert(lo), convert(hi));
|
|
38183
|
+
const drift = size === 0n ? maximum - current : current - minimum;
|
|
38184
|
+
reserve[Number(counterIndex)] += drift + ceilDiv(maximum * snapshot.metadata.fee, 1000000n - snapshot.metadata.fee) + 2n;
|
|
38185
|
+
swapCount++;
|
|
38186
|
+
}
|
|
38187
|
+
if (swapCount === 0 || finalIds.length !== expected.size || new Set(finalIds).size !== finalIds.length || finalIds.some((id) => !expected.has(id))) throw new Error("Incomplete final protected hedge book");
|
|
38188
|
+
const finalCall = encodeFunctionData({
|
|
38189
|
+
abi: panopticPoolV2Abi,
|
|
38190
|
+
functionName: "getFullPositionsData",
|
|
38191
|
+
args: [
|
|
38192
|
+
snapshot.account,
|
|
38193
|
+
true,
|
|
38194
|
+
finalIds
|
|
38195
|
+
]
|
|
38196
|
+
});
|
|
38197
|
+
const result = await simulateWithTokenFlow({
|
|
38198
|
+
client,
|
|
38199
|
+
poolAddress: snapshot.poolAddress,
|
|
38200
|
+
user: snapshot.account,
|
|
38201
|
+
callData: dispatchData,
|
|
38202
|
+
blockNumber: snapshot.blockNumber,
|
|
38203
|
+
estimateGas: false,
|
|
38204
|
+
preCallData: [snapshot.fullCall],
|
|
38205
|
+
postCallData: [finalCall]
|
|
38206
|
+
});
|
|
38207
|
+
const flow = result.tokenFlow;
|
|
38208
|
+
const pre = result.preCallResults?.[0];
|
|
38209
|
+
const post = result.postCallResults?.[0];
|
|
38210
|
+
if (!result.success || flow === void 0 || pre === void 0 || post === void 0) throw result.rawError ?? new Error(result.error ?? "Missing exact hedge cashflow quote");
|
|
38211
|
+
if (flow.balanceBefore0 !== snapshot.collateral[0] || flow.balanceBefore1 !== snapshot.collateral[1]) throw new Error("Hedge quote does not match its confirmed snapshot");
|
|
38212
|
+
const before = fullPositions(pre, snapshot.positions.map((position) => position.tokenId));
|
|
38213
|
+
const after = fullPositions(post, finalIds);
|
|
38214
|
+
if (after.positions.some((position) => expected.get(position.tokenId) !== position.positionSize)) throw new Error("Hedge quote changed an unexpected position");
|
|
38215
|
+
const afterBook = {
|
|
38216
|
+
...snapshot.book,
|
|
38217
|
+
curve: await getPositionValueCurve({
|
|
38218
|
+
client,
|
|
38219
|
+
queryAddress: snapshot.queryAddress,
|
|
38220
|
+
positions: after.positions
|
|
38221
|
+
}),
|
|
38222
|
+
balances: [flow.balanceAfter0 + snapshot.wallet[0] + after.premium[0] - reserve[0], flow.balanceAfter1 + snapshot.wallet[1] + after.premium[1] - reserve[1]]
|
|
38223
|
+
};
|
|
38224
|
+
const beforeBook = {
|
|
38225
|
+
...snapshot.book,
|
|
38226
|
+
balances: [flow.balanceBefore0 + snapshot.wallet[0] + before.premium[0], flow.balanceBefore1 + snapshot.wallet[1] + before.premium[1]]
|
|
38227
|
+
};
|
|
38228
|
+
const decimals = snapshot.book.numeraireIndex === 0n ? snapshot.metadata.token0Decimals : snapshot.metadata.token1Decimals;
|
|
38229
|
+
const roundingReserve = 10n ** (decimals > 2n ? decimals - 2n : 0n);
|
|
38230
|
+
return {
|
|
38231
|
+
...estimateProtectedHedgeGain({
|
|
38232
|
+
before: beforeBook,
|
|
38233
|
+
after: afterBook,
|
|
38234
|
+
anchor,
|
|
38235
|
+
roundingReserve
|
|
38236
|
+
}),
|
|
38237
|
+
sqrtPriceLowerX96: lower,
|
|
38238
|
+
sqrtPriceUpperX96: upper,
|
|
38239
|
+
executionReserve: reserve
|
|
38240
|
+
};
|
|
38241
|
+
}
|
|
38242
|
+
async function getVaultHedgeAccountActivity({ client, snapshot, fromBlock }) {
|
|
38243
|
+
const addresses = [
|
|
38244
|
+
snapshot.metadata.collateralToken0Address,
|
|
38245
|
+
snapshot.metadata.collateralToken1Address,
|
|
38246
|
+
snapshot.metadata.token0Asset,
|
|
38247
|
+
snapshot.metadata.token1Asset
|
|
38248
|
+
];
|
|
38249
|
+
const [mints, burns, incoming, outgoing] = await Promise.all([
|
|
38250
|
+
client.getContractEvents({
|
|
38251
|
+
address: snapshot.poolAddress,
|
|
38252
|
+
abi: panopticPoolV2Abi,
|
|
38253
|
+
eventName: "OptionMinted",
|
|
38254
|
+
args: { recipient: snapshot.account },
|
|
38255
|
+
fromBlock,
|
|
38256
|
+
toBlock: snapshot.blockNumber
|
|
38257
|
+
}),
|
|
38258
|
+
client.getContractEvents({
|
|
38259
|
+
address: snapshot.poolAddress,
|
|
38260
|
+
abi: panopticPoolV2Abi,
|
|
38261
|
+
eventName: "OptionBurnt",
|
|
38262
|
+
args: { recipient: snapshot.account },
|
|
38263
|
+
fromBlock,
|
|
38264
|
+
toBlock: snapshot.blockNumber
|
|
38265
|
+
}),
|
|
38266
|
+
client.getContractEvents({
|
|
38267
|
+
address: addresses,
|
|
38268
|
+
abi: erc20Abi,
|
|
38269
|
+
eventName: "Transfer",
|
|
38270
|
+
args: { to: snapshot.account },
|
|
38271
|
+
fromBlock,
|
|
38272
|
+
toBlock: snapshot.blockNumber
|
|
38273
|
+
}),
|
|
38274
|
+
client.getContractEvents({
|
|
38275
|
+
address: addresses,
|
|
38276
|
+
abi: erc20Abi,
|
|
38277
|
+
eventName: "Transfer",
|
|
38278
|
+
args: { from: snapshot.account },
|
|
38279
|
+
fromBlock,
|
|
38280
|
+
toBlock: snapshot.blockNumber
|
|
38281
|
+
})
|
|
38282
|
+
]);
|
|
38283
|
+
return [
|
|
38284
|
+
...mints,
|
|
38285
|
+
...burns,
|
|
38286
|
+
...incoming.filter((log) => (log.args.value ?? 0n) > 0n),
|
|
38287
|
+
...outgoing.filter((log) => (log.args.value ?? 0n) > 0n)
|
|
38288
|
+
].reduce((latest, log) => log.blockNumber !== null && (latest === void 0 || log.blockNumber > latest) ? log.blockNumber : latest, void 0);
|
|
38289
|
+
}
|
|
38290
|
+
async function valueVaultHedgeGas({ client, snapshot, blockNumber, gasCost }) {
|
|
38291
|
+
const spot = await client.readContract({
|
|
38292
|
+
address: snapshot.metadata.underlyingPoolId,
|
|
38293
|
+
abi: uniswapV3PoolAbi,
|
|
38294
|
+
functionName: "slot0",
|
|
38295
|
+
blockNumber
|
|
38296
|
+
});
|
|
38297
|
+
return snapshot.gasAssetIndex === 0n ? ceilDiv(gasCost * spot[0] ** 2n, Q192) : ceilDiv(gasCost * Q192, spot[0] ** 2n);
|
|
38298
|
+
}
|
|
38299
|
+
|
|
38300
|
+
//#endregion
|
|
38301
|
+
//#region src/hypoVault/signingFeePolicy.ts
|
|
38302
|
+
function authorizationIdentity(list = []) {
|
|
38303
|
+
return list.map((authorization) => [
|
|
38304
|
+
authorization.address.toLowerCase(),
|
|
38305
|
+
authorization.chainId,
|
|
38306
|
+
authorization.nonce,
|
|
38307
|
+
authorization.yParity ?? (authorization.v === 27n ? 0 : authorization.v === 28n ? 1 : void 0),
|
|
38308
|
+
authorization.r.toLowerCase(),
|
|
38309
|
+
authorization.s.toLowerCase()
|
|
38310
|
+
].join(":")).join("|");
|
|
38311
|
+
}
|
|
38312
|
+
/** Enforce an immutable intent budget on the actual serialized transaction before broadcast. */
|
|
38313
|
+
function withVaultTransactionFeePolicy(account, policy, intent) {
|
|
38314
|
+
if (account.type !== "local") throw new Error("Adaptive vault fees require a local transaction signer");
|
|
38315
|
+
const authority = Object.freeze({ ...policy });
|
|
38316
|
+
const expected = intent === void 0 ? void 0 : Object.freeze({
|
|
38317
|
+
...intent,
|
|
38318
|
+
authorization: authorizationIdentity(intent.authorizationList)
|
|
38319
|
+
});
|
|
38320
|
+
const signTransaction = async (transaction, options) => {
|
|
38321
|
+
const serialized = await account.signTransaction(transaction, options);
|
|
38322
|
+
const signed = parseTransaction(serialized);
|
|
38323
|
+
if (signed.gas === void 0 || signed.gas <= 0n) throw new Error("Vault signed transaction is missing a positive gas limit");
|
|
38324
|
+
if (expected !== void 0 && (signed.chainId !== expected.chainId || signed.to?.toLowerCase() !== expected.to.toLowerCase() || (signed.data ?? "0x").toLowerCase() !== expected.data.toLowerCase() || (signed.value ?? 0n) !== expected.value || signed.gas !== expected.gasLimit || expected.nonce !== void 0 && signed.nonce !== expected.nonce || expected.maxFeePerGas !== void 0 && signed.maxFeePerGas !== expected.maxFeePerGas || expected.maxPriorityFeePerGas !== void 0 && signed.maxPriorityFeePerGas !== expected.maxPriorityFeePerGas || authorizationIdentity(signed.authorizationList) !== expected.authorization)) throw new Error("Vault signed transaction does not match its gas-budget intent");
|
|
38325
|
+
const validation = validateVaultSignedTransactionFeeCaps({
|
|
38326
|
+
chainId: signed.chainId,
|
|
38327
|
+
gasLimit: signed.gas,
|
|
38328
|
+
maxFeePerGas: signed.maxFeePerGas ?? null,
|
|
38329
|
+
maxPriorityFeePerGas: signed.maxPriorityFeePerGas ?? null
|
|
38330
|
+
}, void 0, authority);
|
|
38331
|
+
if (!validation.valid) throw new Error(validation.reason);
|
|
38332
|
+
return serialized;
|
|
38333
|
+
};
|
|
38334
|
+
return {
|
|
38335
|
+
...account,
|
|
38336
|
+
signTransaction
|
|
38337
|
+
};
|
|
38338
|
+
}
|
|
38339
|
+
|
|
38340
|
+
//#endregion
|
|
38341
|
+
//#region src/hypoVault/signingPreflight.ts
|
|
38342
|
+
/** Validate execution after signing, before the signed bytes can be broadcast. */
|
|
38343
|
+
function withVaultTransactionPreflight(account, preflight) {
|
|
38344
|
+
if (account.type !== "local") throw new Error("Post-sign vault preflight requires a local transaction signer");
|
|
38345
|
+
const signTransaction = async (transaction, options) => {
|
|
38346
|
+
const serialized = await account.signTransaction(transaction, options);
|
|
38347
|
+
await preflight();
|
|
38348
|
+
return serialized;
|
|
38349
|
+
};
|
|
38350
|
+
return {
|
|
38351
|
+
...account,
|
|
38352
|
+
signTransaction
|
|
38353
|
+
};
|
|
38354
|
+
}
|
|
38355
|
+
|
|
37485
38356
|
//#endregion
|
|
37486
38357
|
//#region src/panoptic/v2/reads/irm.ts
|
|
37487
38358
|
const WAD = 10n ** 18n;
|
|
@@ -37644,5 +38515,5 @@ async function getIrmCurve(params) {
|
|
|
37644
38515
|
}
|
|
37645
38516
|
|
|
37646
38517
|
//#endregion
|
|
37647
|
-
export { BASE_CHAIN_ID, BASE_DEPLOYMENT, BASE_ETH_USDC_5BPS_MARKET, BASE_HYPOVAULT_ADDRESSES, BASE_HYPOVAULT_CORE_ADDRESSES, BASE_HYPOVAULT_MANAGER_ADDRESSES, BASE_HYPOVAULT_MANAGER_TURNKEY_SIGNERS, BASE_PANOPTIC_POOL_ADDRESSES, BASE_PANOPTIC_V2_ADDRESSES, BORROW_INDEX_BITS, BPS_SCALE, BaseUSDCPLPStrategistLeaves, BaseUSDCPLPVaultPoolInfos, BaseWETHPLPStrategistLeaves, BaseWETHPLPVaultPoolInfos, CHAIN_DEPLOYMENTS, CollateralTrackerAbi, CollateralTrackerV1_1Abi, Erc1155Abi, Erc20Abi, HypoVaultAbi, HypoVaultManagerConfigSchema, HypoVaultManagerWithMerkleVerificationAbi, MAINNET_CHAIN_ID, MAINNET_DEPLOYMENT, MAINNET_ETH_USDC_5BPS_V3_PANOPTIC_POOL_ADDRESSES, MAINNET_PANOPTIC_V2_ADDRESSES, MAINNET_RISK_ENGINES, MAINNET_USDC_PLP_COMPILED_POOL_POLICY, MAINNET_USDC_PLP_POOL_POLICY, MAINNET_USDC_REPLACEMENT_ARTIFACTS, MAINNET_V3_AUTHORIZATION_BLOCK, MAINNET_WETH_PLP_COMPILED_POOL_POLICY, MAINNET_WETH_PLP_POOL_POLICY, MAINNET_WETH_REPLACEMENT_ARTIFACTS, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, MAX_STALE_DELTA_HEDGE_PRIORITY_FEE_PER_GAS, MAX_VAULT_PRIORITY_FEE_PER_GAS, MAX_VAULT_TRANSACTION_GAS_COST, MIN_VAULT_PRIORITY_FEE_PER_GAS, MainnetLegacyUSDCPLPStrategistLeaves, MainnetLegacyWETHPLPStrategistLeaves, MainnetUSDCPLPLegacyVaultPoolInfos, MainnetUSDCPLPPreviousStrategistLeaves, MainnetUSDCPLPPreviousVaultPoolInfos, MainnetUSDCPLPStrategistLeaves, MainnetUSDCPLPV3AuthorizedStrategistLeaves, MainnetUSDCPLPV3AuthorizedVaultPoolInfos, MainnetUSDCPLPVaultPoolInfos, MainnetWETHPLPLegacyVaultPoolInfos, MainnetWETHPLPPreviousStrategistLeaves, MainnetWETHPLPPreviousVaultPoolInfos, MainnetWETHPLPStrategistLeaves, MainnetWETHPLPV3AuthorizedStrategistLeaves, MainnetWETHPLPV3AuthorizedVaultPoolInfos, MainnetWETHPLPVaultPoolInfos, Multicall3Abi, NonFungiblePositionManagerAbi, PanopticFactoryV3Abi, PanopticFactoryV4Abi, PanopticHelperAbi, PanopticPoolAbi, PanopticPoolV1_1Abi, PanopticQueryV1_1Abi, PanopticVaultAccountantAbi, PanopticVaultAccountantManagerInputAbi, PoolManagerAbi, RATE_AT_TARGET_BITS, ROBINHOOD_CHAIN_ID, ROBINHOOD_DEPLOYMENT, ROBINHOOD_HYPOVAULT_ADDRESSES, ROBINHOOD_HYPOVAULT_CORE_ADDRESSES, ROBINHOOD_HYPOVAULT_MANAGER_ADDRESSES, ROBINHOOD_HYPOVAULT_MANAGER_TURNKEY_SIGNERS, ROBINHOOD_PANOPTIC_POOL_ADDRESSES, ROBINHOOD_PANOPTIC_V2_ADDRESSES, ROBINHOOD_RISK_ENGINES, ROBINHOOD_SPY_USDG_30BPS_MARKET, ROBINHOOD_SPY_USDG_30BPS_PANOPTIC_POOL_ADDRESSES, ROBINHOOD_SPY_USDG_30BPS_POOL_DEPLOYMENT_BLOCK, ROBINHOOD_SPY_USDG_30BPS_POOL_INFO, ROBINHOOD_SPY_USDG_5BPS_MARKET, ROBINHOOD_SPY_USDG_5BPS_PANOPTIC_POOL_ADDRESSES, ROBINHOOD_SPY_USDG_5BPS_POOL_DEPLOYMENT_BLOCK, ROBINHOOD_SPY_USDG_5BPS_POOL_INFO, ROBINHOOD_SPY_USDG_MARKET, ROBINHOOD_SPY_USDG_POOL_DEPLOYMENT_BLOCK, ROBINHOOD_SPY_USDG_POOL_INFO, ROBINHOOD_USDG_30BPS_MANAGE_ROOT, ROBINHOOD_USDG_30BPS_POOL_HASH, ROBINHOOD_USDG_5BPS_POOL_HASH, ROBINHOOD_USDG_PLP_30BPS_COMPILED_POOL_POLICY, ROBINHOOD_USDG_PLP_30BPS_POOL_POLICY, ROBINHOOD_USDG_PLP_5BPS_COMPILED_POOL_POLICY, ROBINHOOD_USDG_PLP_5BPS_POOL_POLICY, ROBINHOOD_USDG_PLP_COMPILED_POOL_POLICY, ROBINHOOD_USDG_PLP_POOL_POLICY, ROBINHOOD_USDG_REPLACEMENT_ARTIFACTS, ROBINHOOD_USDG_VAULT_DEPLOYMENT_BLOCK, RescueDistributorAbi, RobinhoodUSDGPLP30bpsStrategistLeaves, RobinhoodUSDGPLP30bpsVaultPoolInfos, RobinhoodUSDGPLP5bpsStrategistLeaves, RobinhoodUSDGPLP5bpsVaultPoolInfos, RobinhoodUSDGPLPStrategistLeaves, RobinhoodUSDGPLPVaultPoolInfos, SECONDS_PER_YEAR, SEPOLIA_CHAIN_ID, SEPOLIA_DEPLOYMENT, SEPOLIA_ETH_USDC_5BPS_MARKET, SEPOLIA_HYPOVAULT_ADDRESSES, SEPOLIA_HYPOVAULT_CORE_ADDRESSES, SEPOLIA_HYPOVAULT_MANAGER_ADDRESSES, SEPOLIA_HYPOVAULT_MANAGER_TURNKEY_SIGNERS, SEPOLIA_PANOPTIC_POOL_ADDRESSES, SEPOLIA_PANOPTIC_V2_ADDRESSES, SemiFungiblePositionManagerAbi, SemiFungiblePositionManagerV1_1Abi, SepoliaUSDCPLPStrategistLeaves, SepoliaUSDCPLPVaultPoolInfos, SepoliaWETHPLPStrategistLeaves, SepoliaWETHPLPVaultPoolInfos, Simple7702AccountAbi, StateViewAbi, TRUSTED_VAULT_SHARE_PRICE_STATUSES, UNREALIZED_INTEREST_BITS, UniswapHelperAbi, UniswapHelperV1_1Abi, UniswapMigratorAbi, UniswapV3FactoryAbi, UniswapV3PoolAbi, UsdcPlpVaultBaseProdConfig, UsdcPlpVaultMainnetLegacyConfig, UsdcPlpVaultMainnetProdConfig, UsdcPlpVaultSepoliaDevConfig, UsdcPlpVaultSepoliaProdConfig, UsdgPlpVaultRobinhoodProdConfig, VAULT_DISPLAY_NAMES_PER_CHAIN, VAULT_DISPLAY_NAME_RESOLVERS_PER_CHAIN, VaultApyPreInceptionBlockError, VaultTransactionFeeEstimationError, VaultTransactionGasCostLimitError, VaultTransactionReplacementLimitError, WAD, WETHAbi, WethPlpVaultBaseProdConfig, WethPlpVaultMainnetLegacyConfig, WethPlpVaultMainnetProdConfig, WethPlpVaultSepoliaDevConfig, WethPlpVaultSepoliaProdConfig, adjustUnderlyingIdleBalance, adjustVaultSharePricesForDonations, annualizePerSecondRateWad, applyVaultTransactionGasCostLimit, bufferVaultTransactionGasEstimate, buildClaimVaultShareCalldatas, buildExecuteDepositCalldatas, buildExecuteWithdrawalCalldatas, buildManageArgs, buildManagerInput, buildManagerInputAtBlock, buildRequestWithdrawalCalldatas, buildVaultManagerInput, buildVaultManagerInputAtBlock, buildWeeklyVaultReturnHistogram, builderFactoryAbi, builderWalletAbi, calculateAnnualizedApyPct, calculateAssetsFromShares, calculateAvailableShares, calculateClaimableAssetsFromQueuedWithdrawals, calculateClaimableSharesFromQueuedDeposits, calculateFixedPortfolioScenarios, calculateLongOptionNotionalPct, calculateMaxSignedPriceChanges, calculateMeanMaxAbsolutePriceChange, calculateSharesFromAssets, calculateVaultNetLendingApyPctFromTrackerInputs, calculateVaultNetLendingYieldUnderlyingFromTrackerInputs, calculateWeeklyVaultReturns, cancelDeposit, chainToHypoVaultGraphQlAPI, clearVaultApyStrategyOverride, collateralTrackerV2Abi as collateralTrackerAbi, collateralTrackerV2Abi, computeSharePriceFromNavSnapshot, convertJsonTreeToArray, createVaultSharePriceProcessor, deriveSupplyRatePerSecWad, deriveVaultApyTimeseriesFromSharePrices, donationRetainedFactor, encodeApproveFunctionData, encodeCancelDepositFunctionData, encodeDepositFunctionData, encodeExecuteDepositFunctionData, encodeExecuteWithdrawalFunctionData, encodeExecuteWithdrawalMulticallFunctionData, encodeFulfillDepositsFunctionData, encodeFulfillWithdrawalsFunctionData, encodeRequestDepositFunctionData, encodeRequestWithdrawalFunctionData, encodeRequestWithdrawalMulticallFunctionData, encodeWithdrawFunctionData, estimateFixedPortfolioPremium, executeWithdrawal, executeWithdrawalMulticall, fetchFirstDepositTimestampByVaultId, fetchFixedVaultPortfolio, fetchHypoVaultRoles, fetchVaultLendingAllocation, fetchVaultNetLendingApyPct, fetchVaultNetLendingApyTrackerInputs, fetchVaultNetLendingYieldUnderlying, fetchVaultPositionActivity, fetchVaultPositionExposureHistory, fetchVaultSharePriceSnapshot, fetchVaultSharePriceSnapshotWithCandidateRecovery, filterActiveVaultWeeks, findLeaf, findLeafForTarget, findLeafForTargetAndSignature, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, generateProof, getAaveHoldings, getAlchemyRpcUrl, getAlchemyWsRpcUrl, getCancelDepositContractConfig, getChainDeployment, getEthUsdcMarket, getExecuteWithdrawalContractConfig, getExecuteWithdrawalMulticallContractConfig, getHypoVaultConfigForVault, getHypoVaultGraphQLClient, getIrmCurrent, getIrmCurve, getLendingAllocationRows, getMainnetV3AuthorizationArtifactsAtBlock, getMainnetV3AuthorizationGenerations, getMainnetVaultManagerRootAtBlock, getMainnetVaultManagerRootHistory, getMainnetVaultPoolConfigurationAtBlock, getMainnetVaultPoolConfigurationHistory, getMinQueuedDepositEpoch, getMorphoHoldings, getProofsFromDigests, getProofsUsingTree, getRequestDepositContractConfig, getRequestWithdrawalContractConfig, getRequestWithdrawalMulticallContractConfig, getRobinhoodSpyUsdgAuthorizationGenerations, getSpyUsdgMarket, getStaleOracleOverrideBytecodeForAccountant, getStaleOracleStateOverrideForAccountant, getStkAaveHoldings, getVaultApyErrorMessage, getVaultApyStrategy, getVaultCandidatePoolInfos, getVaultDeltaHedgeHistoricalFeeQuote, getVaultDeltaHedgeInitialFeeQuote, getVaultDonationSources, getVaultDonationTransfers, getVaultManagerRootAtBlock, getVaultManagerRootHistory, getVaultPoolConfigurationAtBlock, getVaultPoolConfigurationHistory, getVaultPoolInfos, getVaultTransactionFeeQuote, getVaultTransactionReplacementFeeQuote, hashRobinhoodSpyUsdgPoolInfos, isExpectedHistoricalReadMiss, isIncorrectPositionListReadError, isStaleOraclePriceError, isStaleOraclePriceReadError, isSupportedChain, isTrustedVaultSharePriceStatus, packMarketState, panopticFactoryV4Abi as panopticFactoryAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticLiquidatorAbi, panopticPoolV2Abi as panopticPoolAbi, panopticPoolV2Abi, panopticQueryAbi, parseCustomError, parseMinimalProxyImplementation, prepareFixedPoolValue, qualifyVaultWeeks, ratePerSecWadToAprPct, recoverVaultCandidateTokenIdsByPool, requestDeposit, requestWithdrawal, requestWithdrawalMulticall, requireChainDeployment, resolveMainnetV3AuthorizationArtifacts, resolvePositionScanFromBlock, resolveRobinhoodSpyUsdgAuthorizationArtifacts, resolveRobinhoodSpyUsdgAuthorizationState, resolveVaultDisplayName, resolveVaultHistoricalCandidatesByPool, resolveVaultPoolInfosAtBlock, resolveVaultTokenIdsByPool, riskEngineAbi, semiFungiblePositionManagerV4Abi as semiFungiblePositionManagerAbi, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, setVaultApyStrategyOverride, simulateCancelDeposit, simulateExecuteWithdrawal, simulateExecuteWithdrawalMulticall, simulateRequestDeposit, simulateRequestWithdrawal, simulateRequestWithdrawalMulticall, statusForVaultSharePriceSnapshot, updatePositionSnapshot, useCancelDeposit, useClaimVaultShares, useErc20Balance, useExecuteWithdrawal, useRequestDeposit, useRequestWithdrawal, utilizationBpsToWad, utilizationPctToWad, validateVaultSignedTransactionFeeCaps, valueDonationInUnderlying, valueVaultDonationBlock, verifyVaultOpenTokenIdsAtBlock };
|
|
38518
|
+
export { BASE_CHAIN_ID, BASE_DEPLOYMENT, BASE_ETH_USDC_5BPS_MARKET, BASE_HYPOVAULT_ADDRESSES, BASE_HYPOVAULT_CORE_ADDRESSES, BASE_HYPOVAULT_MANAGER_ADDRESSES, BASE_HYPOVAULT_MANAGER_TURNKEY_SIGNERS, BASE_PANOPTIC_POOL_ADDRESSES, BASE_PANOPTIC_V2_ADDRESSES, BORROW_INDEX_BITS, BPS_SCALE, BaseUSDCPLPStrategistLeaves, BaseUSDCPLPVaultPoolInfos, BaseWETHPLPStrategistLeaves, BaseWETHPLPVaultPoolInfos, CHAIN_DEPLOYMENTS, CollateralTrackerAbi, CollateralTrackerV1_1Abi, Erc1155Abi, Erc20Abi, HypoVaultAbi, HypoVaultManagerConfigSchema, HypoVaultManagerWithMerkleVerificationAbi, MAINNET_CHAIN_ID, MAINNET_DEPLOYMENT, MAINNET_ETH_USDC_5BPS_V3_PANOPTIC_POOL_ADDRESSES, MAINNET_PANOPTIC_V2_ADDRESSES, MAINNET_RISK_ENGINES, MAINNET_USDC_PLP_COMPILED_POOL_POLICY, MAINNET_USDC_PLP_POOL_POLICY, MAINNET_USDC_REPLACEMENT_ARTIFACTS, MAINNET_V3_AUTHORIZATION_BLOCK, MAINNET_WETH_PLP_COMPILED_POOL_POLICY, MAINNET_WETH_PLP_POOL_POLICY, MAINNET_WETH_REPLACEMENT_ARTIFACTS, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, MAX_STALE_DELTA_HEDGE_PRIORITY_FEE_PER_GAS, MAX_VAULT_PRIORITY_FEE_PER_GAS, MAX_VAULT_TRANSACTION_GAS_COST, MIN_VAULT_PRIORITY_FEE_PER_GAS, MainnetLegacyUSDCPLPStrategistLeaves, MainnetLegacyWETHPLPStrategistLeaves, MainnetUSDCPLPLegacyVaultPoolInfos, MainnetUSDCPLPPreviousStrategistLeaves, MainnetUSDCPLPPreviousVaultPoolInfos, MainnetUSDCPLPStrategistLeaves, MainnetUSDCPLPV3AuthorizedStrategistLeaves, MainnetUSDCPLPV3AuthorizedVaultPoolInfos, MainnetUSDCPLPVaultPoolInfos, MainnetWETHPLPLegacyVaultPoolInfos, MainnetWETHPLPPreviousStrategistLeaves, MainnetWETHPLPPreviousVaultPoolInfos, MainnetWETHPLPStrategistLeaves, MainnetWETHPLPV3AuthorizedStrategistLeaves, MainnetWETHPLPV3AuthorizedVaultPoolInfos, MainnetWETHPLPVaultPoolInfos, Multicall3Abi, NonFungiblePositionManagerAbi, PanopticFactoryV3Abi, PanopticFactoryV4Abi, PanopticHelperAbi, PanopticPoolAbi, PanopticPoolV1_1Abi, PanopticQueryV1_1Abi, PanopticVaultAccountantAbi, PanopticVaultAccountantManagerInputAbi, PoolManagerAbi, RATE_AT_TARGET_BITS, ROBINHOOD_CHAIN_ID, ROBINHOOD_DEPLOYMENT, ROBINHOOD_HYPOVAULT_ADDRESSES, ROBINHOOD_HYPOVAULT_CORE_ADDRESSES, ROBINHOOD_HYPOVAULT_MANAGER_ADDRESSES, ROBINHOOD_HYPOVAULT_MANAGER_TURNKEY_SIGNERS, ROBINHOOD_PANOPTIC_POOL_ADDRESSES, ROBINHOOD_PANOPTIC_V2_ADDRESSES, ROBINHOOD_RISK_ENGINES, ROBINHOOD_SPY_USDG_30BPS_MARKET, ROBINHOOD_SPY_USDG_30BPS_PANOPTIC_POOL_ADDRESSES, ROBINHOOD_SPY_USDG_30BPS_POOL_DEPLOYMENT_BLOCK, ROBINHOOD_SPY_USDG_30BPS_POOL_INFO, ROBINHOOD_SPY_USDG_5BPS_MARKET, ROBINHOOD_SPY_USDG_5BPS_PANOPTIC_POOL_ADDRESSES, ROBINHOOD_SPY_USDG_5BPS_POOL_DEPLOYMENT_BLOCK, ROBINHOOD_SPY_USDG_5BPS_POOL_INFO, ROBINHOOD_SPY_USDG_MARKET, ROBINHOOD_SPY_USDG_POOL_DEPLOYMENT_BLOCK, ROBINHOOD_SPY_USDG_POOL_INFO, ROBINHOOD_USDG_30BPS_MANAGE_ROOT, ROBINHOOD_USDG_30BPS_POOL_HASH, ROBINHOOD_USDG_5BPS_POOL_HASH, ROBINHOOD_USDG_PLP_30BPS_COMPILED_POOL_POLICY, ROBINHOOD_USDG_PLP_30BPS_POOL_POLICY, ROBINHOOD_USDG_PLP_5BPS_COMPILED_POOL_POLICY, ROBINHOOD_USDG_PLP_5BPS_POOL_POLICY, ROBINHOOD_USDG_PLP_COMPILED_POOL_POLICY, ROBINHOOD_USDG_PLP_POOL_POLICY, ROBINHOOD_USDG_REPLACEMENT_ARTIFACTS, ROBINHOOD_USDG_VAULT_DEPLOYMENT_BLOCK, RescueDistributorAbi, RobinhoodUSDGPLP30bpsStrategistLeaves, RobinhoodUSDGPLP30bpsVaultPoolInfos, RobinhoodUSDGPLP5bpsStrategistLeaves, RobinhoodUSDGPLP5bpsVaultPoolInfos, RobinhoodUSDGPLPStrategistLeaves, RobinhoodUSDGPLPVaultPoolInfos, SECONDS_PER_YEAR, SEPOLIA_CHAIN_ID, SEPOLIA_DEPLOYMENT, SEPOLIA_ETH_USDC_5BPS_MARKET, SEPOLIA_HYPOVAULT_ADDRESSES, SEPOLIA_HYPOVAULT_CORE_ADDRESSES, SEPOLIA_HYPOVAULT_MANAGER_ADDRESSES, SEPOLIA_HYPOVAULT_MANAGER_TURNKEY_SIGNERS, SEPOLIA_PANOPTIC_POOL_ADDRESSES, SEPOLIA_PANOPTIC_V2_ADDRESSES, SemiFungiblePositionManagerAbi, SemiFungiblePositionManagerV1_1Abi, SepoliaUSDCPLPStrategistLeaves, SepoliaUSDCPLPVaultPoolInfos, SepoliaWETHPLPStrategistLeaves, SepoliaWETHPLPVaultPoolInfos, Simple7702AccountAbi, StateViewAbi, TRUSTED_VAULT_SHARE_PRICE_STATUSES, UNREALIZED_INTEREST_BITS, UniswapHelperAbi, UniswapHelperV1_1Abi, UniswapMigratorAbi, UniswapV3FactoryAbi, UniswapV3PoolAbi, UsdcPlpVaultBaseProdConfig, UsdcPlpVaultMainnetLegacyConfig, UsdcPlpVaultMainnetProdConfig, UsdcPlpVaultSepoliaDevConfig, UsdcPlpVaultSepoliaProdConfig, UsdgPlpVaultRobinhoodProdConfig, VAULT_DISPLAY_NAMES_PER_CHAIN, VAULT_DISPLAY_NAME_RESOLVERS_PER_CHAIN, VOLUSDC_HEDGE_FEE_POLICY, VOLUSDC_INCIDENT_GAS_ENVELOPE, VaultApyPreInceptionBlockError, VaultTransactionFeeEstimationError, VaultTransactionGasCostLimitError, VaultTransactionReplacementLimitError, WAD, WETHAbi, WethPlpVaultBaseProdConfig, WethPlpVaultMainnetLegacyConfig, WethPlpVaultMainnetProdConfig, WethPlpVaultSepoliaDevConfig, WethPlpVaultSepoliaProdConfig, adjustUnderlyingIdleBalance, adjustVaultSharePricesForDonations, annualizePerSecondRateWad, applyVaultTransactionGasCostLimit, bufferVaultTransactionGasEstimate, buildClaimVaultShareCalldatas, buildExecuteDepositCalldatas, buildExecuteWithdrawalCalldatas, buildManageArgs, buildManagerInput, buildManagerInputAtBlock, buildRequestWithdrawalCalldatas, buildVaultManagerInput, buildVaultManagerInputAtBlock, buildWeeklyVaultReturnHistogram, builderFactoryAbi, builderWalletAbi, calculateAnnualizedApyPct, calculateAssetsFromShares, calculateAvailableShares, calculateClaimableAssetsFromQueuedWithdrawals, calculateClaimableSharesFromQueuedDeposits, calculateFixedPortfolioScenarios, calculateLongOptionNotionalPct, calculateMaxSignedPriceChanges, calculateMeanMaxAbsolutePriceChange, calculateSharesFromAssets, calculateVaultNetLendingApyPctFromTrackerInputs, calculateVaultNetLendingYieldUnderlyingFromTrackerInputs, calculateWeeklyVaultReturns, cancelDeposit, chainToHypoVaultGraphQlAPI, clearVaultApyStrategyOverride, collateralTrackerV2Abi as collateralTrackerAbi, collateralTrackerV2Abi, computeSharePriceFromNavSnapshot, convertJsonTreeToArray, createVaultSharePriceProcessor, deriveSupplyRatePerSecWad, deriveVaultApyTimeseriesFromSharePrices, donationRetainedFactor, encodeApproveFunctionData, encodeCancelDepositFunctionData, encodeDepositFunctionData, encodeExecuteDepositFunctionData, encodeExecuteWithdrawalFunctionData, encodeExecuteWithdrawalMulticallFunctionData, encodeFulfillDepositsFunctionData, encodeFulfillWithdrawalsFunctionData, encodeRequestDepositFunctionData, encodeRequestWithdrawalFunctionData, encodeRequestWithdrawalMulticallFunctionData, encodeWithdrawFunctionData, estimateFixedPortfolioPremium, estimateProtectedHedgeGain, executeWithdrawal, executeWithdrawalMulticall, fetchFirstDepositTimestampByVaultId, fetchFixedVaultPortfolio, fetchHypoVaultRoles, fetchVaultLendingAllocation, fetchVaultNetLendingApyPct, fetchVaultNetLendingApyTrackerInputs, fetchVaultNetLendingYieldUnderlying, fetchVaultPositionActivity, fetchVaultPositionExposureHistory, fetchVaultSharePriceSnapshot, fetchVaultSharePriceSnapshotWithCandidateRecovery, filterActiveVaultWeeks, findLeaf, findLeafForTarget, findLeafForTargetAndSignature, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, generateProof, getAaveHoldings, getAdaptiveHedgeFeeQuote, getAlchemyRpcUrl, getAlchemyWsRpcUrl, getCancelDepositContractConfig, getChainDeployment, getEthUsdcMarket, getExecuteWithdrawalContractConfig, getExecuteWithdrawalMulticallContractConfig, getHedgeShock, getHypoVaultConfigForVault, getHypoVaultGraphQLClient, getIrmCurrent, getIrmCurve, getLendingAllocationRows, getMainnetV3AuthorizationArtifactsAtBlock, getMainnetV3AuthorizationGenerations, getMainnetVaultManagerRootAtBlock, getMainnetVaultManagerRootHistory, getMainnetVaultPoolConfigurationAtBlock, getMainnetVaultPoolConfigurationHistory, getMinQueuedDepositEpoch, getMorphoHoldings, getProofsFromDigests, getProofsUsingTree, getProtectedHedgeGasBudget, getRequestDepositContractConfig, getRequestWithdrawalContractConfig, getRequestWithdrawalMulticallContractConfig, getRobinhoodSpyUsdgAuthorizationGenerations, getSpyUsdgMarket, getStaleOracleOverrideBytecodeForAccountant, getStaleOracleStateOverrideForAccountant, getStkAaveHoldings, getVaultApyErrorMessage, getVaultApyStrategy, getVaultCandidatePoolInfos, getVaultDeltaHedgeHistoricalFeeQuote, getVaultDeltaHedgeInitialFeeQuote, getVaultDonationSources, getVaultDonationTransfers, getVaultHedgeAccountActivity, getVaultManagerRootAtBlock, getVaultManagerRootHistory, getVaultPoolConfigurationAtBlock, getVaultPoolConfigurationHistory, getVaultPoolInfos, getVaultTransactionFeeQuote, getVaultTransactionReplacementFeeQuote, hashRobinhoodSpyUsdgPoolInfos, isExpectedHistoricalReadMiss, isIncorrectPositionListReadError, isStaleOraclePriceError, isStaleOraclePriceReadError, isSupportedChain, isTrustedVaultSharePriceStatus, packMarketState, panopticFactoryV4Abi as panopticFactoryAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticLiquidatorAbi, panopticPoolV2Abi as panopticPoolAbi, panopticPoolV2Abi, panopticQueryAbi, parseCustomError, parseMinimalProxyImplementation, prepareFixedPoolValue, qualifyVaultWeeks, quoteProtectedVaultHedge, ratePerSecWadToAprPct, readVaultHedgeBook, recoverVaultCandidateTokenIdsByPool, requestDeposit, requestWithdrawal, requestWithdrawalMulticall, requireChainDeployment, resolveAdaptiveHedgeFeeQuote, resolveHedgeShock, resolveMainnetV3AuthorizationArtifacts, resolvePositionScanFromBlock, resolveRobinhoodSpyUsdgAuthorizationArtifacts, resolveRobinhoodSpyUsdgAuthorizationState, resolveVaultDisplayName, resolveVaultHistoricalCandidatesByPool, resolveVaultPoolInfosAtBlock, resolveVaultTokenIdsByPool, riskEngineAbi, selectBudgetedHedgeFees, semiFungiblePositionManagerV4Abi as semiFungiblePositionManagerAbi, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, setVaultApyStrategyOverride, simulateCancelDeposit, simulateExecuteWithdrawal, simulateExecuteWithdrawalMulticall, simulateRequestDeposit, simulateRequestWithdrawal, simulateRequestWithdrawalMulticall, statusForVaultSharePriceSnapshot, updatePositionSnapshot, useCancelDeposit, useClaimVaultShares, useErc20Balance, useExecuteWithdrawal, useRequestDeposit, useRequestWithdrawal, utilizationBpsToWad, utilizationPctToWad, validateVaultSignedTransactionFeeCaps, valueDonationInUnderlying, valueFrozenHedgeBook, valueVaultDonationBlock, valueVaultHedgeGas, verifyVaultOpenTokenIdsAtBlock, withVaultTransactionFeePolicy, withVaultTransactionPreflight };
|
|
37648
38519
|
//# sourceMappingURL=index.js.map
|