@panoptic-eng/sdk 1.0.56 → 1.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -31748,12 +31748,15 @@ function medianBigInt(values) {
31748
31748
  const lowerMiddle = sorted[upperMiddleIndex - 1];
31749
31749
  return lowerMiddle === void 0 ? void 0 : (lowerMiddle + upperMiddle) / 2n;
31750
31750
  }
31751
- function clampPriorityFee(priorityFee) {
31752
- if (priorityFee < MIN_VAULT_PRIORITY_FEE_PER_GAS) return MIN_VAULT_PRIORITY_FEE_PER_GAS;
31751
+ function getChainPriorityFeeFloor(chainId) {
31752
+ return chainId === ROBINHOOD_CHAIN_ID ? 0n : void 0;
31753
+ }
31754
+ function clampPriorityFee(priorityFee, minimumPriorityFeePerGas = MIN_VAULT_PRIORITY_FEE_PER_GAS) {
31755
+ if (priorityFee < minimumPriorityFeePerGas) return minimumPriorityFeePerGas;
31753
31756
  if (priorityFee > MAX_VAULT_PRIORITY_FEE_PER_GAS) return MAX_VAULT_PRIORITY_FEE_PER_GAS;
31754
31757
  return priorityFee;
31755
31758
  }
31756
- function resolveFeeHistoryQuote({ baseFeePerGas, reward }) {
31759
+ function resolveFeeHistoryQuote({ baseFeePerGas, reward, minimumPriorityFeePerGas }) {
31757
31760
  const latestBaseFeeIndex = baseFeePerGas.length - 2;
31758
31761
  if (latestBaseFeeIndex < 0 || reward === void 0 || reward.length === 0) return null;
31759
31762
  const p90Rewards = reward.flatMap((blockRewards) => {
@@ -31762,16 +31765,18 @@ function resolveFeeHistoryQuote({ baseFeePerGas, reward }) {
31762
31765
  });
31763
31766
  const sampledPriorityFee = medianBigInt(p90Rewards);
31764
31767
  if (sampledPriorityFee === void 0) return null;
31765
- const maxPriorityFeePerGas = clampPriorityFee(sampledPriorityFee);
31768
+ const effectivePriorityFeeFloor = minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS;
31769
+ const maxPriorityFeePerGas = clampPriorityFee(sampledPriorityFee, effectivePriorityFeeFloor);
31766
31770
  const bufferedBaseFee = ceilMultiplyFraction(baseFeePerGas[latestBaseFeeIndex], BASE_FEE_BUFFER_NUMERATOR, BASE_FEE_BUFFER_DENOMINATOR);
31767
31771
  return {
31768
31772
  maxFeePerGas: bufferedBaseFee + maxPriorityFeePerGas,
31769
31773
  maxPriorityFeePerGas,
31770
- minimumMaxFeePerGas: bufferedBaseFee + MIN_VAULT_PRIORITY_FEE_PER_GAS,
31774
+ minimumMaxFeePerGas: bufferedBaseFee + effectivePriorityFeeFloor,
31775
+ ...minimumPriorityFeePerGas === void 0 ? {} : { minimumPriorityFeePerGas },
31771
31776
  source: "fee_history"
31772
31777
  };
31773
31778
  }
31774
- function resolveDeltaHedgeFeeHistoryQuote({ baseFeePerGas, reward }) {
31779
+ function resolveDeltaHedgeFeeHistoryQuote({ baseFeePerGas, reward, minimumPriorityFeePerGas }) {
31775
31780
  const latestBaseFeeIndex = baseFeePerGas.length - 2;
31776
31781
  if (latestBaseFeeIndex < 0 || reward === void 0 || reward.length === 0) return null;
31777
31782
  const p25Rewards = reward.flatMap((blockRewards) => {
@@ -31780,22 +31785,25 @@ function resolveDeltaHedgeFeeHistoryQuote({ baseFeePerGas, reward }) {
31780
31785
  });
31781
31786
  const rawPriorityFeePerGas = medianBigInt(p25Rewards);
31782
31787
  if (rawPriorityFeePerGas === void 0) return null;
31783
- const maxPriorityFeePerGas = clampPriorityFee(rawPriorityFeePerGas);
31788
+ const effectivePriorityFeeFloor = minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS;
31789
+ const maxPriorityFeePerGas = clampPriorityFee(rawPriorityFeePerGas, effectivePriorityFeeFloor);
31784
31790
  const bufferedBaseFee = ceilMultiplyFraction(baseFeePerGas[latestBaseFeeIndex], BASE_FEE_BUFFER_NUMERATOR, BASE_FEE_BUFFER_DENOMINATOR);
31785
31791
  return {
31786
31792
  maxFeePerGas: bufferedBaseFee + maxPriorityFeePerGas,
31787
31793
  maxPriorityFeePerGas,
31788
- minimumMaxFeePerGas: bufferedBaseFee + MIN_VAULT_PRIORITY_FEE_PER_GAS,
31794
+ minimumMaxFeePerGas: bufferedBaseFee + effectivePriorityFeeFloor,
31795
+ ...minimumPriorityFeePerGas === void 0 ? {} : { minimumPriorityFeePerGas },
31789
31796
  rawPriorityFeePerGas,
31790
31797
  source: "fee_history_p25"
31791
31798
  };
31792
31799
  }
31793
- function resolveRpcPriorityFeeQuote({ baseFeePerGas, rawPriorityFeePerGas }) {
31800
+ function resolveRpcPriorityFeeQuote({ baseFeePerGas, rawPriorityFeePerGas, minimumPriorityFeePerGas }) {
31794
31801
  const bufferedBaseFee = ceilMultiplyFraction(baseFeePerGas, BASE_FEE_BUFFER_NUMERATOR, BASE_FEE_BUFFER_DENOMINATOR);
31795
31802
  return {
31796
31803
  maxFeePerGas: bufferedBaseFee + rawPriorityFeePerGas,
31797
31804
  maxPriorityFeePerGas: rawPriorityFeePerGas,
31798
- minimumMaxFeePerGas: bufferedBaseFee + rawPriorityFeePerGas,
31805
+ minimumMaxFeePerGas: bufferedBaseFee + (minimumPriorityFeePerGas ?? rawPriorityFeePerGas),
31806
+ ...minimumPriorityFeePerGas === void 0 ? {} : { minimumPriorityFeePerGas },
31799
31807
  rawPriorityFeePerGas,
31800
31808
  source: "rpc_priority_fee"
31801
31809
  };
@@ -31816,7 +31824,7 @@ function getVaultTransactionReplacementFeeQuote({ originalQuote, historicalQuote
31816
31824
  requiredMaxPriorityFeePerGas: requiredReplacementPriorityFee,
31817
31825
  maximumAffordableFeePerGas: MAX_VAULT_TRANSACTION_GAS_COST / gasLimit
31818
31826
  });
31819
- const bufferedBaseFee = historicalQuote.minimumMaxFeePerGas - MIN_VAULT_PRIORITY_FEE_PER_GAS;
31827
+ const bufferedBaseFee = historicalQuote.minimumMaxFeePerGas - (historicalQuote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
31820
31828
  const currentMarketMaxFee = bufferedBaseFee + requiredMaxPriorityFeePerGas;
31821
31829
  const desiredMaxFeePerGas = currentMarketMaxFee > bumpedMaxFee ? currentMarketMaxFee : bumpedMaxFee;
31822
31830
  const maximumAffordableFeePerGas = MAX_VAULT_TRANSACTION_GAS_COST / gasLimit;
@@ -31834,13 +31842,15 @@ function getVaultTransactionReplacementFeeQuote({ originalQuote, historicalQuote
31834
31842
  maxPriorityFeePerGas: requiredMaxPriorityFeePerGas
31835
31843
  };
31836
31844
  }
31837
- function resolveFallbackQuote({ maxFeePerGas: estimatedMaxFeePerGas, maxPriorityFeePerGas: estimatedPriorityFeePerGas }) {
31838
- const maxPriorityFeePerGas = clampPriorityFee(estimatedPriorityFeePerGas);
31845
+ function resolveFallbackQuote({ maxFeePerGas: estimatedMaxFeePerGas, maxPriorityFeePerGas: estimatedPriorityFeePerGas, minimumPriorityFeePerGas }) {
31846
+ const effectivePriorityFeeFloor = minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS;
31847
+ const maxPriorityFeePerGas = clampPriorityFee(estimatedPriorityFeePerGas, effectivePriorityFeeFloor);
31839
31848
  const estimatedBaseFeeAllowance = estimatedMaxFeePerGas > estimatedPriorityFeePerGas ? estimatedMaxFeePerGas - estimatedPriorityFeePerGas : 0n;
31840
31849
  return {
31841
31850
  maxFeePerGas: estimatedBaseFeeAllowance + maxPriorityFeePerGas,
31842
31851
  maxPriorityFeePerGas,
31843
- minimumMaxFeePerGas: estimatedBaseFeeAllowance + MIN_VAULT_PRIORITY_FEE_PER_GAS,
31852
+ minimumMaxFeePerGas: estimatedBaseFeeAllowance + effectivePriorityFeeFloor,
31853
+ ...minimumPriorityFeePerGas === void 0 ? {} : { minimumPriorityFeePerGas },
31844
31854
  source: "viem_fallback"
31845
31855
  };
31846
31856
  }
@@ -31853,7 +31863,7 @@ function applyVaultTransactionGasCostLimit(quote, gasLimit) {
31853
31863
  minimumRequiredFeePerGas: quote.minimumMaxFeePerGas
31854
31864
  });
31855
31865
  if (quote.maxFeePerGas <= maximumAffordableFeePerGas) return quote;
31856
- const bufferedBaseFee = quote.minimumMaxFeePerGas - MIN_VAULT_PRIORITY_FEE_PER_GAS;
31866
+ const bufferedBaseFee = quote.minimumMaxFeePerGas - (quote.minimumPriorityFeePerGas ?? MIN_VAULT_PRIORITY_FEE_PER_GAS);
31857
31867
  const affordablePriorityFee = maximumAffordableFeePerGas - bufferedBaseFee;
31858
31868
  return {
31859
31869
  ...quote,
@@ -31866,7 +31876,8 @@ function bufferVaultTransactionGasEstimate(gasEstimate) {
31866
31876
  return ceilMultiplyFraction(gasEstimate, GAS_ESTIMATE_BUFFER_NUMERATOR, GAS_ESTIMATE_BUFFER_DENOMINATOR);
31867
31877
  }
31868
31878
  function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
31869
- const { gasLimit, maxFeePerGas, maxPriorityFeePerGas } = feeCaps;
31879
+ const { chainId, gasLimit, maxFeePerGas, maxPriorityFeePerGas } = feeCaps;
31880
+ const minimumPriorityFeePerGas = quote?.minimumPriorityFeePerGas ?? getChainPriorityFeeFloor(chainId) ?? MIN_VAULT_PRIORITY_FEE_PER_GAS;
31870
31881
  if (maxFeePerGas === null || maxPriorityFeePerGas === null) return {
31871
31882
  valid: false,
31872
31883
  code: "MissingEip1559Fees",
@@ -31877,10 +31888,10 @@ function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
31877
31888
  code: "InvalidFeeCaps",
31878
31889
  reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) cannot exceed maxFeePerGas (${maxFeePerGas.toString()} wei).`
31879
31890
  };
31880
- if (maxPriorityFeePerGas < MIN_VAULT_PRIORITY_FEE_PER_GAS) return {
31891
+ if (maxPriorityFeePerGas < minimumPriorityFeePerGas) return {
31881
31892
  valid: false,
31882
31893
  code: "PriorityFeeTooLow",
31883
- reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must be at least ${MIN_VAULT_PRIORITY_FEE_PER_GAS.toString()} wei (0.1 gwei).`
31894
+ reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must be at least ${minimumPriorityFeePerGas.toString()} wei.`
31884
31895
  };
31885
31896
  if (maxPriorityFeePerGas > MAX_VAULT_PRIORITY_FEE_PER_GAS) return {
31886
31897
  valid: false,
@@ -31895,21 +31906,27 @@ function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
31895
31906
  if (quote !== void 0 && maxFeePerGas < quote.minimumMaxFeePerGas) return {
31896
31907
  valid: false,
31897
31908
  code: "MaxFeeTooLow",
31898
- reason: `Signed transaction maxFeePerGas (${maxFeePerGas.toString()} wei) must be at least ${quote.minimumMaxFeePerGas.toString()} wei for the buffered next-block base fee and 0.1 gwei minimum priority fee.`
31909
+ reason: `Signed transaction maxFeePerGas (${maxFeePerGas.toString()} wei) must be at least ${quote.minimumMaxFeePerGas.toString()} wei for the buffered next-block base fee and configured minimum priority fee.`
31899
31910
  };
31900
31911
  return { valid: true };
31901
31912
  }
31902
- async function resolveVaultTransactionFeeQuote({ readFeeHistory, readFallbackEstimate }) {
31913
+ async function resolveVaultTransactionFeeQuote({ readFeeHistory, readFallbackEstimate, minimumPriorityFeePerGas }) {
31903
31914
  let feeHistoryError;
31904
31915
  try {
31905
- const quote = resolveFeeHistoryQuote(await readFeeHistory());
31916
+ const quote = resolveFeeHistoryQuote({
31917
+ ...await readFeeHistory(),
31918
+ minimumPriorityFeePerGas
31919
+ });
31906
31920
  if (quote !== null) return quote;
31907
31921
  feeHistoryError = new Error("eth_feeHistory returned incomplete base fee or reward data");
31908
31922
  } catch (error) {
31909
31923
  feeHistoryError = error;
31910
31924
  }
31911
31925
  try {
31912
- return resolveFallbackQuote(await readFallbackEstimate());
31926
+ return resolveFallbackQuote({
31927
+ ...await readFallbackEstimate(),
31928
+ minimumPriorityFeePerGas
31929
+ });
31913
31930
  } catch (fallbackError) {
31914
31931
  throw new VaultTransactionFeeEstimationError({
31915
31932
  feeHistoryError,
@@ -31921,12 +31938,13 @@ async function resolveVaultTransactionFeeQuote({ readFeeHistory, readFallbackEst
31921
31938
  * Resolve explicit EIP-1559 fees for operator-controlled vault transactions.
31922
31939
  *
31923
31940
  * The normal path follows the median p90 priority fee from the last 20 blocks,
31924
- * with a 0.1 gwei floor and 3 gwei ceiling. If fee history is unavailable,
31925
- * Viem's estimate is used while preserving those bounds and its original
31926
- * base-fee allowance.
31941
+ * with a 3 gwei ceiling and a 0.1 gwei floor except on chains that do not use
31942
+ * tips for ordering. If fee history is unavailable, Viem's estimate is used
31943
+ * while preserving those bounds and its original base-fee allowance.
31927
31944
  */
31928
31945
  async function getVaultTransactionFeeQuote(client) {
31929
31946
  return resolveVaultTransactionFeeQuote({
31947
+ minimumPriorityFeePerGas: getChainPriorityFeeFloor(client.chain?.id),
31930
31948
  readFeeHistory: () => getFeeHistory(client, {
31931
31949
  blockCount: FEE_HISTORY_BLOCK_COUNT,
31932
31950
  blockTag: "latest",
@@ -31941,13 +31959,19 @@ async function getVaultDeltaHedgeHistoricalFeeQuote(client) {
31941
31959
  blockTag: "latest",
31942
31960
  rewardPercentiles: DELTA_HEDGE_FEE_HISTORY_REWARD_PERCENTILES
31943
31961
  });
31944
- const quote = resolveDeltaHedgeFeeHistoryQuote(feeHistory);
31962
+ const quote = resolveDeltaHedgeFeeHistoryQuote({
31963
+ ...feeHistory,
31964
+ minimumPriorityFeePerGas: getChainPriorityFeeFloor(client.chain?.id)
31965
+ });
31945
31966
  if (quote === null) throw new Error("eth_feeHistory returned incomplete p25 base fee or reward data");
31946
31967
  return quote;
31947
31968
  }
31948
- async function resolveVaultDeltaHedgeInitialFeeQuote({ readRpcQuote, readHistoricalQuote }) {
31969
+ async function resolveVaultDeltaHedgeInitialFeeQuote({ readRpcQuote, readHistoricalQuote, minimumPriorityFeePerGas }) {
31949
31970
  try {
31950
- return resolveRpcPriorityFeeQuote(await readRpcQuote());
31971
+ return resolveRpcPriorityFeeQuote({
31972
+ ...await readRpcQuote(),
31973
+ minimumPriorityFeePerGas
31974
+ });
31951
31975
  } catch {
31952
31976
  return readHistoricalQuote();
31953
31977
  }
@@ -31959,6 +31983,7 @@ async function resolveVaultDeltaHedgeInitialFeeQuote({ readRpcQuote, readHistori
31959
31983
  */
31960
31984
  async function getVaultDeltaHedgeInitialFeeQuote(client) {
31961
31985
  return resolveVaultDeltaHedgeInitialFeeQuote({
31986
+ minimumPriorityFeePerGas: getChainPriorityFeeFloor(client.chain?.id),
31962
31987
  readRpcQuote: async () => {
31963
31988
  const [rawPriorityFee, latestBlock] = await Promise.all([client.request({ method: "eth_maxPriorityFeePerGas" }), getBlock(client, { blockTag: "latest" })]);
31964
31989
  if (latestBlock.baseFeePerGas === null) throw new Error("Latest block does not include an EIP-1559 base fee");