@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.
@@ -1,8 +1,8 @@
1
- import { UniswapV3PoolAbi, applyOwedInterest, getAccountBuyingPower, getAccountCollateral, getNetLiquidationValue, panopticQueryAbi, readBlockAndAggregate, requireReturnData } from "./irm-BwOG1LRv.js";
2
- import { AccountInsolventError, ChunkLimitError, DEFAULT_VEGOID, InvalidHistoryRangeError, MulticallResultMissingError, NotEnoughTokensError, PanopticError, PanopticValidationError, SafeModeError, StaleDataError, StorageDataNotFoundError, UnhealthyPoolError, WrongUniswapPoolError, addLegToTokenId, applyMintBufferPerToken, availableToBorrow, collateralTrackerV2Abi, countLegs, decodeAllLegs, decodeLeftRightSigned, decodeLeftRightUnsigned, decodePositionBalance, decodeTokenId, getBlockMeta, getClosedPositionsKey, getPendingPositionsKey, getPool, getPoolMetaKey, getPoolMetadata, getPositionMetaKey, getPositionsKey, getTrackedChunksKey, getTrackedPositionIds, isPanopticErrorType, jsonSerializer, mintableAfterBuffer, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticGuardianAbi, panopticLiquidatorAbi, panopticPoolV2Abi, panopticQueryAbi$1, parsePanopticError, riskEngineAbi, riskEngineMulticall, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, stateViewAbi, uniswapV3PoolAbi } from "./rates-B9HaWnEM.js";
1
+ import { UniswapV3PoolAbi, applyOwedInterest, getAccountBuyingPower, getAccountCollateral, getNetLiquidationValue, panopticQueryAbi$1 as panopticQueryAbi, readBlockAndAggregate, requireReturnData } from "./irm-CGuYhr-C.js";
2
+ import { AccountInsolventError, ChunkLimitError, DEFAULT_VEGOID, InvalidHistoryRangeError, MulticallResultMissingError, NotEnoughTokensError, PanopticError, PanopticValidationError, SafeModeError, StaleDataError, StorageDataNotFoundError, UnhealthyPoolError, WrongUniswapPoolError, addLegToTokenId, applyMintBufferPerToken, availableToBorrow, collateralTrackerV2Abi, countLegs, decodeAllLegs, decodeLeftRightSigned, decodeLeftRightUnsigned, decodePositionBalance, decodeTokenId, getBlockMeta, getClosedPositionsKey, getPendingPositionsKey, getPool, getPoolMetaKey, getPoolMetadata, getPoolTokensForSimulation, getPositionMetaKey, getPositionsKey, getTrackedChunksKey, getTrackedPositionIds, isPanopticErrorType, jsonSerializer, mintableAfterBuffer, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticGuardianAbi, panopticLiquidatorAbi, panopticPoolV2Abi, panopticQueryAbi as panopticQueryAbi$1, parsePanopticError, riskEngineAbi, riskEngineMulticall, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, simulateWithTokenFlow, stateViewAbi, uniswapV3PoolAbi } from "./tokenFlow-6Ec9Hz48.js";
3
3
  import { MAX_TICK, MAX_TRACKED_CHUNKS, MIN_TICK, NO_LOWER_LIQUIDATION_TICK, NO_UPPER_LIQUIDATION_TICK, WAD, calculatePositionDelta, calculatePositionDeltaDebtOnly, calculatePositionGamma, calculatePositionValue, getLegLiquidityRange, priceToTick, sqrtPriceX96ToTick, tickLimits, tickToPriceDecimalScaled, tickToSqrtPriceX96, toVaultFrameAtTick } from "./greeks-CEv-Uex1.js";
4
- import { buildBatchDispatchArgs, buildProtectedSettlePlan, buildSettleSequenceCalls, buildUniqueCredit, buildUniqueLoan, createTokenIdBuilder, ensureUniqueTokenId, getCurrentPositionSizes, getPoolTokensForSimulation, loadCheckpoint, resolveTokenIndex, simulateDispatch, simulateOpenPosition, simulateWithTokenFlow } from "./writes-CeRXSZwj.js";
5
- import { feesFromFeeGrowthDelta, getLpPositionFunding, getMaxLpPositionSize, getPriceHistory, preparePositionGamma, quoteSwapExactOutViaRouter, quoteSwapExactOutViaV3Router } from "./router-KwjvMN_z.js";
4
+ import { buildBatchDispatchArgs, buildProtectedSettlePlan, buildSettleSequenceCalls, buildUniqueCredit, buildUniqueLoan, createTokenIdBuilder, ensureUniqueTokenId, getCurrentPositionSizes, loadCheckpoint, resolveTokenIndex, simulateDispatch, simulateOpenPosition } from "./writes-DKpVWZkE.js";
5
+ import { feesFromFeeGrowthDelta, getLpPositionFunding, getMaxLpPositionSize, getPriceHistory, preparePositionGamma, quoteSwapExactOutViaRouter, quoteSwapExactOutViaV3Router } from "./router-DL_cDCzG.js";
6
6
  import { ContractFunctionExecutionError, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, getAddress, hexToString, isAddress, isAddressEqual, isHex, keccak256, parseEventLogs, trim, zeroAddress } from "viem";
7
7
  import Decimal from "decimal.js";
8
8
  import { multicall } from "viem/actions";
@@ -5546,6 +5546,72 @@ async function getHedgeLimits({ client, poolAddress, account, positionIds, asset
5546
5546
  };
5547
5547
  }
5548
5548
 
5549
+ //#endregion
5550
+ //#region src/panoptic/v2/reads/legCapacity.ts
5551
+ async function getAccountLegCapacity({ client, poolAddress, account, positionIds, blockNumber }) {
5552
+ if (new Set(positionIds).size !== positionIds.length) throw new Error("Leg capacity requires distinct open positions");
5553
+ const metadata = await getPoolMetadata({
5554
+ client,
5555
+ poolAddress
5556
+ });
5557
+ const [maximumLegs, currentLegs, full] = await riskEngineMulticall(client, {
5558
+ contracts: [
5559
+ {
5560
+ address: metadata.riskEngineAddress,
5561
+ abi: riskEngineAbi,
5562
+ functionName: "MAX_OPEN_LEGS"
5563
+ },
5564
+ {
5565
+ address: poolAddress,
5566
+ abi: panopticPoolV2Abi,
5567
+ functionName: "numberOfLegs",
5568
+ args: [account]
5569
+ },
5570
+ {
5571
+ address: poolAddress,
5572
+ abi: panopticPoolV2Abi,
5573
+ functionName: "getFullPositionsData",
5574
+ args: [
5575
+ account,
5576
+ false,
5577
+ positionIds
5578
+ ]
5579
+ }
5580
+ ],
5581
+ allowFailure: false,
5582
+ blockNumber
5583
+ });
5584
+ const decodedLegs = positionIds.reduce((sum$1, id) => sum$1 + BigInt(decodeTokenId(id).legs.length), 0n);
5585
+ if (decodedLegs !== currentLegs || full[2].length !== positionIds.length || full[2].some((balance) => (balance & (1n << 128n) - 1n) === 0n)) throw new Error("Account leg snapshot does not match the complete open position list");
5586
+ return {
5587
+ maximumLegs: BigInt(maximumLegs),
5588
+ currentLegs: BigInt(currentLegs),
5589
+ positionIds,
5590
+ blockNumber
5591
+ };
5592
+ }
5593
+ /** Validate peak active legs in dispatch order, including existing-position resizes. */
5594
+ function fitsAccountLegCapacity({ capacity, tokenIds, positionSizes }) {
5595
+ if (tokenIds.length !== positionSizes.length) return false;
5596
+ const active = new Set(capacity.positionIds);
5597
+ let count = capacity.currentLegs;
5598
+ if (count > capacity.maximumLegs) return false;
5599
+ for (let i = 0; i < tokenIds.length; i += 1) {
5600
+ const id = tokenIds[i];
5601
+ const size = positionSizes[i];
5602
+ if (id === void 0 || size === void 0 || size < 0n) return false;
5603
+ const legs = BigInt(decodeTokenId(id).legs.length);
5604
+ if (legs === 0n) return false;
5605
+ if (size === 0n && active.delete(id)) count -= legs;
5606
+ if (size > 0n && !active.has(id)) {
5607
+ active.add(id);
5608
+ count += legs;
5609
+ }
5610
+ if (count > capacity.maximumLegs) return false;
5611
+ }
5612
+ return true;
5613
+ }
5614
+
5549
5615
  //#endregion
5550
5616
  //#region src/panoptic/v2/reads/positionMintFunding.ts
5551
5617
  const Q96 = 1n << 96n;
@@ -10526,4 +10592,4 @@ async function getPositionVolatilityHistory({ client, poolAddress, account, toke
10526
10592
  }
10527
10593
 
10528
10594
  //#endregion
10529
- export { DEFAULT_MIN_SWAP_RATIO_BPS, DEFAULT_RECONNECT_CONFIG, MARKET_INDICATOR_PERIODS, REQUIRED_BASE_ERROR_SENTINEL, STRIKE_LADDER_TARGET_STRIKES, VARIANCE_RATIO_LAG, addPendingPosition, addTrackedChunks, apportion, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertLpPositionFunded, assertTradeable, buildCreditWrappedDispatch, buildSfpmSwapCalldata, buildSfpmSwapPlan, buildTemporaryLoanRecoveryDispatch, buildTokenShortfallRecoveryDispatch, calculateAccountGreeksPure, calculateMarketIndicator, calculateSpreadWad, calculateVarianceProfile, checkCollateralAcrossTicks, classifyStrategyGroups, classifyStrike, cleanupStalePendingPositions, clearPendingPositions, clearTrackedChunks, clearTradeHistory, collateralCurveTicks, collateralRuleKindFor, computeV4PoolId, confirmPendingPosition, convertToAssets, convertToShares, createEventPoller, createEventSubscription, createFlowNeutralTokenId, decodePanopticTokenURI, emptyLiquidateParams, encodePoolKeyBytes, encodeV3PoolKeyBytes, ensureSfpmV3PoolInitialized, estimateBlockNumbers, estimateCloseZapSwap, estimateCollateralBreakdown, estimateCollateralRequired, failPendingPosition, feeGrowthInsideX128, fetchPoolSwaps, fetchSfpmV3PoolId, fetchUniswapFeeData, getAccountGreeks, getAccountHistory, getChunkLiquidities, getChunkSpreads, getClosePositionTransferEstimate, getClosedPositions, getCollateralCurve, getCollateralCurveInputs, getCollateralRequiredBase, getCollateralSharePrices, getCollateralTotalAssetsBatch, getDeltaHedgeParams, getEnforcedTickLimits, getExecutableLpMaxSize, getFactoryConstructMetadata, getFactoryOwnerOf, getFactoryTokenURI, getGuardianUnlockState, getHedgeLimits, getItmAmounts, getMarginBuffer, getMaxPositionSize, getMaxRedeem, getMaxWithdrawable, getNativeTokenPrice, getNotEnoughTokensError, getOpenPositionPreview, getPanopticPoolAddress, getPanopticPoolFromPoolId, getPendingPositions, getPoolLiquidities, getPortfolioValue, getPositionChunkData, getPositionEnrichmentData, getPositionMintFunding, getPositionVolatilityHistory, getRealizedPnL, getRequiredCreditForITM, getSafeMode, getStreamiaHistory, getSyncStatus, getTrackedChunks, getTradeHistory, getUniswapFeeHistory, getUniswapV3PoolFromId, getUniswapV3PoolInfo, getUniswapV3PoolLiquidities, getUniswapV4PoolBasicState, getUniswapV4PoolInfo, getUniswapV4PoolKeyFromId, getUniswapV4PoolLiquidities, interpolateBlocks, isGasError, isNonceError, isRetryableRpcError, isolateGroupTokenId, ladderStrikeSequence, logReturns, marketPnlInQuote, marketRiskFromValues, marketScenario, minePoolAddress, minePoolAddressLocalAsync, multicallRead, netLiquidationValueInQuote, optimizeTokenIdRiskPartners, parseCollateralLog, parsePoolLog, parseStreamedKey, parseStreamedSwap, parseSwapLog, prepareIndicatorCandles, previewDeposit, previewMint, previewRedeem, previewWithdraw, quoteLiquidation, quoteOneTokenFlow, quoteSfpmSwap, quoteTemporaryLoanRecovery, quoteTokenShortfallRecovery, quoteTokenShortfallSwap, realizedBeta, removeTrackedChunks, resolveBlockNumbers, resolveLadderStrike, resolvePanopticPoolFromPoolId, resolveUniswapV4PoolKey, saveClosedPosition, scaleCollateralRequired, scanChunks, screenAccountExact, simulateBatchDispatch, simulateClosePosition, simulateClosePremiumProtection, simulateDeployNewPool, simulateDeposit, simulateForceExercise, simulateLiquidate, simulateSFPMBurn, simulateSFPMMint, simulateSwapExactIn, simulateSwapExactOut, simulateWithdraw, slippageBpsToTickDistance, streamPoolSwaps, subscribePoolSwaps, watchEvents, watchPoolSwaps };
10595
+ export { DEFAULT_MIN_SWAP_RATIO_BPS, DEFAULT_RECONNECT_CONFIG, MARKET_INDICATOR_PERIODS, REQUIRED_BASE_ERROR_SENTINEL, STRIKE_LADDER_TARGET_STRIKES, VARIANCE_RATIO_LAG, addPendingPosition, addTrackedChunks, apportion, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertLpPositionFunded, assertTradeable, buildCreditWrappedDispatch, buildSfpmSwapCalldata, buildSfpmSwapPlan, buildTemporaryLoanRecoveryDispatch, buildTokenShortfallRecoveryDispatch, calculateAccountGreeksPure, calculateMarketIndicator, calculateSpreadWad, calculateVarianceProfile, checkCollateralAcrossTicks, classifyStrategyGroups, classifyStrike, cleanupStalePendingPositions, clearPendingPositions, clearTrackedChunks, clearTradeHistory, collateralCurveTicks, collateralRuleKindFor, computeV4PoolId, confirmPendingPosition, convertToAssets, convertToShares, createEventPoller, createEventSubscription, createFlowNeutralTokenId, decodePanopticTokenURI, emptyLiquidateParams, encodePoolKeyBytes, encodeV3PoolKeyBytes, ensureSfpmV3PoolInitialized, estimateBlockNumbers, estimateCloseZapSwap, estimateCollateralBreakdown, estimateCollateralRequired, failPendingPosition, feeGrowthInsideX128, fetchPoolSwaps, fetchSfpmV3PoolId, fetchUniswapFeeData, fitsAccountLegCapacity, getAccountGreeks, getAccountHistory, getAccountLegCapacity, getChunkLiquidities, getChunkSpreads, getClosePositionTransferEstimate, getClosedPositions, getCollateralCurve, getCollateralCurveInputs, getCollateralRequiredBase, getCollateralSharePrices, getCollateralTotalAssetsBatch, getDeltaHedgeParams, getEnforcedTickLimits, getExecutableLpMaxSize, getFactoryConstructMetadata, getFactoryOwnerOf, getFactoryTokenURI, getGuardianUnlockState, getHedgeLimits, getItmAmounts, getMarginBuffer, getMaxPositionSize, getMaxRedeem, getMaxWithdrawable, getNativeTokenPrice, getNotEnoughTokensError, getOpenPositionPreview, getPanopticPoolAddress, getPanopticPoolFromPoolId, getPendingPositions, getPoolLiquidities, getPortfolioValue, getPositionChunkData, getPositionEnrichmentData, getPositionMintFunding, getPositionVolatilityHistory, getRealizedPnL, getRequiredCreditForITM, getSafeMode, getStreamiaHistory, getSyncStatus, getTrackedChunks, getTradeHistory, getUniswapFeeHistory, getUniswapV3PoolFromId, getUniswapV3PoolInfo, getUniswapV3PoolLiquidities, getUniswapV4PoolBasicState, getUniswapV4PoolInfo, getUniswapV4PoolKeyFromId, getUniswapV4PoolLiquidities, interpolateBlocks, isGasError, isNonceError, isRetryableRpcError, isolateGroupTokenId, ladderStrikeSequence, logReturns, marketPnlInQuote, marketRiskFromValues, marketScenario, minePoolAddress, minePoolAddressLocalAsync, multicallRead, netLiquidationValueInQuote, optimizeTokenIdRiskPartners, parseCollateralLog, parsePoolLog, parseStreamedKey, parseStreamedSwap, parseSwapLog, prepareIndicatorCandles, previewDeposit, previewMint, previewRedeem, previewWithdraw, quoteLiquidation, quoteOneTokenFlow, quoteSfpmSwap, quoteTemporaryLoanRecovery, quoteTokenShortfallRecovery, quoteTokenShortfallSwap, realizedBeta, removeTrackedChunks, resolveBlockNumbers, resolveLadderStrike, resolvePanopticPoolFromPoolId, resolveUniswapV4PoolKey, saveClosedPosition, scaleCollateralRequired, scanChunks, screenAccountExact, simulateBatchDispatch, simulateClosePosition, simulateClosePremiumProtection, simulateDeployNewPool, simulateDeposit, simulateForceExercise, simulateLiquidate, simulateSFPMBurn, simulateSFPMMint, simulateSwapExactIn, simulateSwapExactOut, simulateWithdraw, slippageBpsToTickDistance, streamPoolSwaps, subscribePoolSwaps, watchEvents, watchPoolSwaps };
@@ -5,16 +5,21 @@ declare const MIN_VAULT_PRIORITY_FEE_PER_GAS = 100000000n;
5
5
  declare const MAX_VAULT_PRIORITY_FEE_PER_GAS = 3000000000n;
6
6
  declare const MAX_STALE_DELTA_HEDGE_PRIORITY_FEE_PER_GAS = 8000000000n;
7
7
  declare const MAX_VAULT_TRANSACTION_GAS_COST = 15000000000000000n;
8
+ type VaultTransactionFeePolicy = Readonly<{
9
+ maxTransactionGasCost: bigint;
10
+ marketPriorityFees: boolean;
11
+ }>;
8
12
  type VaultTransactionFeeQuote = {
9
13
  currentBaseFeePerGas?: bigint;
10
14
  maxFeePerGas: bigint;
11
15
  maxPriorityFeePerGas: bigint;
12
16
  minimumMaxFeePerGas: bigint;
13
17
  minimumPriorityFeePerGas?: bigint;
14
- source: 'fee_history' | 'viem_fallback' | 'rpc_priority_fee' | 'fee_history_p25';
18
+ source: 'fee_history' | 'viem_fallback' | 'rpc_priority_fee' | 'fee_history_p25' | 'adaptive_hedge';
15
19
  };
16
20
  type VaultDeltaHedgeFeeQuote = VaultTransactionFeeQuote & {
17
21
  rawPriorityFeePerGas: bigint;
22
+ competitivePriorityFeePerGas?: bigint;
18
23
  };
19
24
  type VaultSignedTransactionFeeCaps = {
20
25
  chainId?: number;
@@ -47,11 +52,13 @@ declare class VaultTransactionGasCostLimitError extends Error {
47
52
  constructor({
48
53
  gasLimit,
49
54
  maximumAffordableFeePerGas,
50
- minimumRequiredFeePerGas
55
+ minimumRequiredFeePerGas,
56
+ maximumGasCost
51
57
  }: {
52
58
  gasLimit: bigint;
53
59
  maximumAffordableFeePerGas: bigint;
54
60
  minimumRequiredFeePerGas: bigint;
61
+ maximumGasCost?: bigint;
55
62
  });
56
63
  }
57
64
  declare class VaultTransactionReplacementLimitError extends Error {
@@ -78,17 +85,19 @@ declare function getVaultTransactionReplacementFeeQuote({
78
85
  historicalQuote,
79
86
  gasLimit,
80
87
  finalReplacement,
81
- staleBoundsReplacement
88
+ staleBoundsReplacement,
89
+ feePolicy
82
90
  }: {
83
91
  originalQuote: Pick<VaultTransactionFeeQuote, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
84
92
  historicalQuote: VaultDeltaHedgeFeeQuote;
85
93
  gasLimit: bigint;
86
94
  finalReplacement?: boolean;
87
95
  staleBoundsReplacement?: boolean;
96
+ feePolicy?: VaultTransactionFeePolicy;
88
97
  }): VaultDeltaHedgeFeeQuote;
89
- declare function applyVaultTransactionGasCostLimit(quote: VaultTransactionFeeQuote, gasLimit: bigint): VaultTransactionFeeQuote;
98
+ declare function applyVaultTransactionGasCostLimit(quote: VaultTransactionFeeQuote, gasLimit: bigint, feePolicy?: VaultTransactionFeePolicy): VaultTransactionFeeQuote;
90
99
  declare function bufferVaultTransactionGasEstimate(gasEstimate: bigint): bigint;
91
- declare function validateVaultSignedTransactionFeeCaps(feeCaps: VaultSignedTransactionFeeCaps, quote?: VaultTransactionFeeQuote): VaultSignedTransactionFeeValidationResult;
100
+ declare function validateVaultSignedTransactionFeeCaps(feeCaps: VaultSignedTransactionFeeCaps, quote?: VaultTransactionFeeQuote, feePolicy?: VaultTransactionFeePolicy): VaultSignedTransactionFeeValidationResult;
92
101
  /**
93
102
  * Resolve explicit EIP-1559 fees for operator-controlled vault transactions.
94
103
  *
@@ -105,5 +114,5 @@ declare function getVaultDeltaHedgeHistoricalFeeQuote<chain extends Chain | unde
105
114
  * back immediately to the rolling historical p25 quote.
106
115
  */
107
116
  declare function getVaultDeltaHedgeInitialFeeQuote<chain extends Chain | undefined>(client: Client<Transport, chain>): Promise<VaultDeltaHedgeFeeQuote>; //#endregion
108
- export { 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, VaultDeltaHedgeFeeQuote, VaultSignedTransactionFeeCaps, VaultSignedTransactionFeeValidationResult, VaultTransactionFeeEstimationError, VaultTransactionFeeQuote, VaultTransactionGasCostLimitError, VaultTransactionReplacementLimitError, applyVaultTransactionGasCostLimit, bufferVaultTransactionGasEstimate, getVaultDeltaHedgeHistoricalFeeQuote, getVaultDeltaHedgeInitialFeeQuote, getVaultTransactionFeeQuote, getVaultTransactionReplacementFeeQuote, validateVaultSignedTransactionFeeCaps };
117
+ export { 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, VaultDeltaHedgeFeeQuote, VaultSignedTransactionFeeCaps, VaultSignedTransactionFeeValidationResult, VaultTransactionFeeEstimationError, VaultTransactionFeePolicy, VaultTransactionFeeQuote, VaultTransactionGasCostLimitError, VaultTransactionReplacementLimitError, applyVaultTransactionGasCostLimit, bufferVaultTransactionGasEstimate, getVaultDeltaHedgeHistoricalFeeQuote, getVaultDeltaHedgeInitialFeeQuote, getVaultTransactionFeeQuote, getVaultTransactionReplacementFeeQuote, validateVaultSignedTransactionFeeCaps };
109
118
  //# sourceMappingURL=vault-transaction-fees.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vault-transaction-fees.d.ts","names":["Chain","Client","Transport","MIN_VAULT_PRIORITY_FEE_PER_GAS","MAX_VAULT_PRIORITY_FEE_PER_GAS","MAX_STALE_DELTA_HEDGE_PRIORITY_FEE_PER_GAS","MAX_VAULT_TRANSACTION_GAS_COST","VaultTransactionFeeQuote","VaultDeltaHedgeFeeQuote","VaultSignedTransactionFeeCaps","VaultSignedTransactionFeeValidationResult","VaultTransactionFeeEstimationError","feeHistoryError","fallbackError","Error","VaultTransactionGasCostLimitError","gasLimit","maximumAffordableFeePerGas","minimumRequiredFeePerGas","VaultTransactionReplacementLimitError","code","requiredMaxFeePerGas","requiredMaxPriorityFeePerGas","FeeHistorySnapshot","FallbackFeeEstimate","getChainPriorityFeeFloor","clampPriorityFee","resolveFeeHistoryQuote","baseFeePerGas","reward","minimumPriorityFeePerGas","resolveDeltaHedgeFeeHistoryQuote","resolveRpcPriorityFeeQuote","rawPriorityFeePerGas","getVaultTransactionReplacementFeeQuote","originalQuote","historicalQuote","finalReplacement","staleBoundsReplacement","Pick","resolveFallbackQuote","estimatedMaxFeePerGas","estimatedPriorityFeePerGas","applyVaultTransactionGasCostLimit","bufferVaultTransactionGasEstimate","validateVaultSignedTransactionFeeCaps","resolveVaultTransactionFeeQuote","readFeeHistory","readFallbackEstimate","Promise","getVaultTransactionFeeQuote","chain","getVaultDeltaHedgeHistoricalFeeQuote","resolveVaultDeltaHedgeInitialFeeQuote","readRpcQuote","readHistoricalQuote","getVaultDeltaHedgeInitialFeeQuote","__transactionFeeTestUtils"],"sources":["../src/hypoVault/transactionFees.d.ts"],"sourcesContent":null,"mappings":";;;cACqBG,8BAAAA;cACAC,8BAAAA;AADAD,cAEAE,0CAAAA,GAF8B,WAAA;AAC9BD,cAEAE,8BAAAA,GAF8B,kBAAA;AAC9BD,KAETE,wBAAAA,GAFSF;EACAC,oBAAAA,CAAAA,EAAAA,MAAAA;EACTC,YAAAA,EAAAA,MAAAA;EAQAC,oBAAAA,EAAAA,MAAuB;EAGvBC,mBAAAA,EAAAA,MAAAA;EAMAC,wBAAAA,CAAAA,EAAAA,MAAAA;EAOSC,MAAAA,EAAAA,aAAAA,GAAAA,eAAkC,GAAA,kBAAA,GAAA,iBAAA;CAAA;AAGrCC,K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ION_GAS_COST","REPLACEMENT_FEE_BUMP_NUMERATOR","REPLACEMENT_FEE_BUMP_DENOMINATOR","VaultTransactionFeePolicy","Readonly","VaultTransactionFeeQuote","VaultDeltaHedgeFeeQuote","VaultSignedTransactionFeeCaps","VaultSignedTransactionFeeValidationResult","VaultTransactionFeeEstimationError","feeHistoryError","fallbackError","Error","VaultTransactionGasCostLimitError","gasLimit","maximumAffordableFeePerGas","minimumRequiredFeePerGas","maximumGasCost","VaultTransactionReplacementLimitError","code","requiredMaxFeePerGas","requiredMaxPriorityFeePerGas","FeeHistorySnapshot","FallbackFeeEstimate","getChainPriorityFeeFloor","clampPriorityFee","resolveFeeHistoryQuote","baseFeePerGas","reward","minimumPriorityFeePerGas","resolveDeltaHedgeFeeHistoryQuote","resolveRpcPriorityFeeQuote","rawPriorityFeePerGas","getVaultTransactionReplacementFeeQuote","originalQuote","historicalQuote","finalReplacement","staleBoundsReplacement","feePolicy","Pick","resolveFallbackQuote","estimatedMaxFeePerGas","estimatedPriorityFeePerGas","applyVaultTransactionGasCostLimit","bufferVaultTransactionGasEstimate","validateVaultSignedTransactionFeeCaps","resolveVaultTransactionFeeQuote","readFeeHistory","readFallbackEstimate","Promise","getVaultTransactionFeeQuote","chain","getVaultDeltaHedgeHistoricalFeeQuote","resolveVaultDeltaHedgeInitialFeeQuote","readRpcQuote","readHistoricalQuote","getVaultDeltaHedgeInitialFeeQuote","__transactionFeeTestUtils"],"sources":["../src/hypoVault/transactionFees.d.ts"],"sourcesContent":null,"mappings":";;;cACqBG,8BAAAA;cACAC,8BAAAA;AADAD,cAEAE,0CAAAA,GAF8B,WAAA;AAC9BD,cAEAE,8BAAAA,GAF8B,kBAAA;AAKvCG,KAAAA,yBAAAA,GAA4BC,QAAAA,CAAAA;EAI5BC,qBAAAA,EAAAA,MAAwB;EAQxBC,kBAAAA,EAAAA,OAAuB;AAInC,CAAA,CAAA;AAMYE,KAlBAH,wBAAAA,GAkBAG;EAOSC,oBAAAA,CAAAA,EAA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RequiredFeePerGas;
488
- constructor({ gasLimit, maximumAffordableFeePerGas, minimumRequiredFeePerGas }) {
489
- super(`Vault transaction cannot fit the ${MAX_VAULT_TRANSACTION_GAS_COST.toString()} wei gas-cost limit: gasLimit=${gasLimit.toString()}, maximumAffordableFeePerGas=${maximumAffordableFeePerGas.toString()}, minimumRequiredFeePerGas=${minimumRequiredFeePerGas.toString()}`);
488
+ constructor({ gasLimit, maximumAffordableFeePerGas, minimumRequiredFeePerGas, maximumGasCost = MAX_VAULT_TRANSACTION_GAS_COST }) {
489
+ super(`Vault transaction cannot fit the ${maximumGasCost.toString()} wei gas-cost limit: gasLimit=${gasLimit.toString()}, maximumAffordableFeePerGas=${maximumAffordableFeePerGas.toString()}, minimumRequiredFeePerGas=${minimumRequiredFeePerGas.toString()}`);
490
490
  this.name = "VaultTransactionGasCostLimitError";
491
491
  this.gasLimit = gasLimit;
492
492
  this.maximumAffordableFeePerGas = maximumAffordableFeePerGas;
@@ -507,6 +507,11 @@ var VaultTransactionReplacementLimitError = class extends Error {
507
507
  this.maximumAffordableFeePerGas = maximumAffordableFeePerGas;
508
508
  }
509
509
  };
510
+ function resolveMaximumGasCost(feePolicy) {
511
+ const maximum = feePolicy?.maxTransactionGasCost ?? MAX_VAULT_TRANSACTION_GAS_COST;
512
+ if (maximum <= 0n) throw new Error("Vault transaction gas budget must be positive");
513
+ return maximum;
514
+ }
510
515
  function ceilMultiplyFraction(value, numerator, denominator) {
511
516
  return (value * numerator + denominator - 1n) / denominator;
512
517
  }
@@ -581,30 +586,32 @@ function resolveRpcPriorityFeeQuote({ baseFeePerGas, rawPriorityFeePerGas, minim
581
586
  source: "rpc_priority_fee"
582
587
  };
583
588
  }
584
- function getVaultTransactionReplacementFeeQuote({ originalQuote, historicalQuote, gasLimit, finalReplacement = false, staleBoundsReplacement = false }) {
589
+ function getVaultTransactionReplacementFeeQuote({ originalQuote, historicalQuote, gasLimit, finalReplacement = false, staleBoundsReplacement = false, feePolicy }) {
585
590
  if (gasLimit <= 0n) throw new Error(`Vault transaction gas limit must be positive, received ${gasLimit.toString()}`);
586
- 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);
591
+ 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);
587
592
  const bumpedMaxFee = ceilMultiplyFraction(originalQuote.maxFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR);
588
593
  const escalatingPriorityFee = historicalQuote.maxPriorityFeePerGas > bumpedPriorityFee ? historicalQuote.maxPriorityFeePerGas : bumpedPriorityFee;
589
- const priorityFeeLimit = staleBoundsReplacement ? MAX_STALE_DELTA_HEDGE_PRIORITY_FEE_PER_GAS : finalReplacement ? MAX_VAULT_PRIORITY_FEE_PER_GAS : MAX_DELTA_HEDGE_PRIORITY_FEE_PER_GAS;
590
- const desiredMaxPriorityFeePerGas = finalReplacement ? MAX_VAULT_PRIORITY_FEE_PER_GAS : staleBoundsReplacement ? bumpedPriorityFee : escalatingPriorityFee;
594
+ const maximumGasCost = resolveMaximumGasCost(feePolicy);
595
+ 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;
596
+ const desiredMaxPriorityFeePerGas = feePolicy?.marketPriorityFees ? escalatingPriorityFee : finalReplacement ? MAX_VAULT_PRIORITY_FEE_PER_GAS : staleBoundsReplacement ? bumpedPriorityFee : escalatingPriorityFee;
591
597
  const requiredReplacementPriorityFee = ceilMultiplyFraction(originalQuote.maxPriorityFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR);
592
598
  const requiredMaxPriorityFeePerGas = desiredMaxPriorityFeePerGas < priorityFeeLimit ? desiredMaxPriorityFeePerGas : priorityFeeLimit;
593
599
  if (requiredMaxPriorityFeePerGas < requiredReplacementPriorityFee) throw new VaultTransactionReplacementLimitError({
594
- code: "PriorityFeeCapExceeded",
600
+ code: feePolicy?.marketPriorityFees ? "GasCostCapExceeded" : "PriorityFeeCapExceeded",
595
601
  gasLimit,
596
602
  requiredMaxFeePerGas: originalQuote.maxFeePerGas,
597
603
  requiredMaxPriorityFeePerGas: requiredReplacementPriorityFee,
598
- maximumAffordableFeePerGas: MAX_VAULT_TRANSACTION_GAS_COST / gasLimit
604
+ maximumAffordableFeePerGas: maximumGasCost / gasLimit
599
605
  });
600
- const bufferedBaseFee = historicalQuote.minimumMaxFeePerGas - (historicalQuote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
606
+ const bufferedBaseFee = feePolicy?.marketPriorityFees ? historicalQuote.maxFeePerGas - historicalQuote.maxPriorityFeePerGas : historicalQuote.minimumMaxFeePerGas - (historicalQuote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
601
607
  const currentMarketMaxFee = bufferedBaseFee + requiredMaxPriorityFeePerGas;
602
608
  const desiredMaxFeePerGas = currentMarketMaxFee > bumpedMaxFee ? currentMarketMaxFee : bumpedMaxFee;
603
- const maximumAffordableFeePerGas = MAX_VAULT_TRANSACTION_GAS_COST / gasLimit;
604
- if (bumpedMaxFee > maximumAffordableFeePerGas || requiredMaxPriorityFeePerGas > maximumAffordableFeePerGas) throw new VaultTransactionReplacementLimitError({
609
+ const maximumAffordableFeePerGas = maximumGasCost / gasLimit;
610
+ const minimumMarketFeePerGas = (historicalQuote.currentBaseFeePerGas ?? bufferedBaseFee) + requiredMaxPriorityFeePerGas;
611
+ if (bumpedMaxFee > maximumAffordableFeePerGas || requiredMaxPriorityFeePerGas > maximumAffordableFeePerGas || feePolicy?.marketPriorityFees && minimumMarketFeePerGas > maximumAffordableFeePerGas) throw new VaultTransactionReplacementLimitError({
605
612
  code: "GasCostCapExceeded",
606
613
  gasLimit,
607
- requiredMaxFeePerGas: bumpedMaxFee,
614
+ requiredMaxFeePerGas: feePolicy?.marketPriorityFees && minimumMarketFeePerGas > bumpedMaxFee ? minimumMarketFeePerGas : bumpedMaxFee,
608
615
  requiredMaxPriorityFeePerGas,
609
616
  maximumAffordableFeePerGas
610
617
  });
@@ -627,13 +634,15 @@ function resolveFallbackQuote({ maxFeePerGas: estimatedMaxFeePerGas, maxPriority
627
634
  source: "viem_fallback"
628
635
  };
629
636
  }
630
- function applyVaultTransactionGasCostLimit(quote, gasLimit) {
637
+ function applyVaultTransactionGasCostLimit(quote, gasLimit, feePolicy) {
631
638
  if (gasLimit <= 0n) throw new Error(`Vault transaction gas limit must be positive, received ${gasLimit.toString()}`);
632
- const maximumAffordableFeePerGas = MAX_VAULT_TRANSACTION_GAS_COST / gasLimit;
639
+ const maximumGasCost = resolveMaximumGasCost(feePolicy);
640
+ const maximumAffordableFeePerGas = maximumGasCost / gasLimit;
633
641
  if (maximumAffordableFeePerGas < quote.minimumMaxFeePerGas) throw new VaultTransactionGasCostLimitError({
634
642
  gasLimit,
635
643
  maximumAffordableFeePerGas,
636
- minimumRequiredFeePerGas: quote.minimumMaxFeePerGas
644
+ minimumRequiredFeePerGas: quote.minimumMaxFeePerGas,
645
+ maximumGasCost
637
646
  });
638
647
  if (quote.maxFeePerGas <= maximumAffordableFeePerGas) return quote;
639
648
  const bufferedBaseFee = quote.minimumMaxFeePerGas - (quote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
@@ -648,8 +657,9 @@ function bufferVaultTransactionGasEstimate(gasEstimate) {
648
657
  if (gasEstimate <= 0n) throw new Error(`Vault transaction gas estimate must be positive, received ${gasEstimate.toString()}`);
649
658
  return ceilMultiplyFraction(gasEstimate, GAS_ESTIMATE_BUFFER_NUMERATOR, GAS_ESTIMATE_BUFFER_DENOMINATOR);
650
659
  }
651
- function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
660
+ function validateVaultSignedTransactionFeeCaps(feeCaps, quote, feePolicy) {
652
661
  const { chainId, gasLimit, maxFeePerGas, maxPriorityFeePerGas } = feeCaps;
662
+ const maximumGasCost = resolveMaximumGasCost(feePolicy);
653
663
  const minimumPriorityFeePerGas = quote?.minimumPriorityFeePerGas ?? getChainPriorityFeeFloor(chainId) ?? MIN_VAULT_PRIORITY_FEE_PER_GAS;
654
664
  if (maxFeePerGas === null || maxPriorityFeePerGas === null) return {
655
665
  valid: false,
@@ -666,15 +676,15 @@ function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
666
676
  code: "PriorityFeeTooLow",
667
677
  reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must be at least ${minimumPriorityFeePerGas.toString()} wei.`
668
678
  };
669
- if (maxPriorityFeePerGas > MAX_VAULT_PRIORITY_FEE_PER_GAS) return {
679
+ if (!feePolicy?.marketPriorityFees && maxPriorityFeePerGas > MAX_VAULT_PRIORITY_FEE_PER_GAS) return {
670
680
  valid: false,
671
681
  code: "PriorityFeeTooHigh",
672
682
  reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must not exceed ${MAX_VAULT_PRIORITY_FEE_PER_GAS.toString()} wei (3 gwei).`
673
683
  };
674
- if (gasLimit !== void 0 && gasLimit !== null && gasLimit * maxFeePerGas > MAX_VAULT_TRANSACTION_GAS_COST) return {
684
+ if (gasLimit !== void 0 && gasLimit !== null && gasLimit * maxFeePerGas > maximumGasCost) return {
675
685
  valid: false,
676
686
  code: "GasCostTooHigh",
677
- reason: `Signed transaction maximum gas cost (${(gasLimit * maxFeePerGas).toString()} wei) must not exceed ${MAX_VAULT_TRANSACTION_GAS_COST.toString()} wei (0.015 ETH).`
687
+ reason: `Signed transaction maximum gas cost (${(gasLimit * maxFeePerGas).toString()} wei) must not exceed ${maximumGasCost.toString()} wei.`
678
688
  };
679
689
  if (quote !== void 0) {
680
690
  const feeRequirementDescription = quote.currentBaseFeePerGas === void 0 ? "buffered next-block base fee" : "current base fee";