@panoptic-eng/sdk 1.0.37 → 1.0.39

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.
Files changed (74) hide show
  1. package/dist/cow/index.d.ts +804 -6
  2. package/dist/cow/index.d.ts.map +1 -0
  3. package/dist/cow/index.js +5268 -5
  4. package/dist/cow/index.js.map +1 -0
  5. package/dist/{cow-aX6of9TS.js → cow-tRUtAUZy.js} +2 -3
  6. package/dist/deployments.d.ts +3 -2
  7. package/dist/deployments.d.ts.map +1 -1
  8. package/dist/deployments.js +4 -0
  9. package/dist/deployments.js.map +1 -1
  10. package/dist/{position-C8rkkKhi.js → getTrackedPositionIds-ms3W9dYB.js} +1085 -34
  11. package/dist/greeks-GysWXct-.js +1 -2
  12. package/dist/index.d.ts +5907 -39
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +12192 -2117
  15. package/dist/index.js.map +1 -1
  16. package/dist/{irm-DnM96-X4.js → irm-SPC2KxLA.js} +6 -3
  17. package/dist/panoptic/v2/greeks/index.d.ts +277 -3
  18. package/dist/panoptic/v2/greeks/index.d.ts.map +1 -0
  19. package/dist/panoptic/v2/greeks/index.js +620 -2
  20. package/dist/panoptic/v2/greeks/index.js.map +1 -0
  21. package/dist/panoptic/v2/index.d.ts +14633 -8
  22. package/dist/panoptic/v2/index.d.ts.map +1 -0
  23. package/dist/panoptic/v2/index.js +27875 -8
  24. package/dist/panoptic/v2/index.js.map +1 -0
  25. package/dist/panoptic/v2/react-public.d.ts +14797 -17
  26. package/dist/panoptic/v2/react-public.d.ts.map +1 -1
  27. package/dist/panoptic/v2/react-public.js +29503 -89
  28. package/dist/panoptic/v2/react-public.js.map +1 -1
  29. package/dist/{router-DcoU2KmV.js → router-BTfbaRfg.js} +2 -3
  30. package/dist/{router-CS86ptMu.js → router-mLWy0MD9.js} +3 -4
  31. package/dist/test/index.d.ts +1 -1
  32. package/dist/test/index.js +2 -2
  33. package/dist/transactionFees-C_Qx07mx.js +174 -0
  34. package/dist/uniswap/index.d.ts +813 -79
  35. package/dist/uniswap/index.d.ts.map +1 -1
  36. package/dist/uniswap/index.js +5884 -13
  37. package/dist/uniswap/index.js.map +1 -1
  38. package/dist/{v2-D0dEatKb.js → v2-DG7qG6di.js} +3266 -2675
  39. package/dist/vault-transaction-fees.d.ts +63 -0
  40. package/dist/vault-transaction-fees.d.ts.map +1 -0
  41. package/dist/vault-transaction-fees.js +175 -0
  42. package/dist/vault-transaction-fees.js.map +1 -0
  43. package/dist/{writes-AupZCK4M.js → writes-Xp9Wa8GQ.js} +325 -1292
  44. package/package.json +8 -3
  45. package/dist/cow/types.d.ts +0 -3
  46. package/dist/cow/types.js +0 -0
  47. package/dist/cow-aX6of9TS.js.map +0 -1
  48. package/dist/greeks-GysWXct-.js.map +0 -1
  49. package/dist/index-CURXeKNy.d.ts +0 -9706
  50. package/dist/index-CURXeKNy.d.ts.map +0 -1
  51. package/dist/index-Cp-nCeV2.d.ts +0 -276
  52. package/dist/index-Cp-nCeV2.d.ts.map +0 -1
  53. package/dist/index-Zvu-rJpV.d.ts +0 -261
  54. package/dist/index-Zvu-rJpV.d.ts.map +0 -1
  55. package/dist/irm-CmgC1Mqi.d.ts +0 -5694
  56. package/dist/irm-CmgC1Mqi.d.ts.map +0 -1
  57. package/dist/irm-DnM96-X4.js.map +0 -1
  58. package/dist/position-BqIgubs5.d.ts +0 -199
  59. package/dist/position-BqIgubs5.d.ts.map +0 -1
  60. package/dist/position-C8rkkKhi.js.map +0 -1
  61. package/dist/quote-BxQkPBRg.d.ts +0 -718
  62. package/dist/quote-BxQkPBRg.d.ts.map +0 -1
  63. package/dist/router-CS86ptMu.js.map +0 -1
  64. package/dist/router-DcoU2KmV.js.map +0 -1
  65. package/dist/simulation-zM6-YUaw.d.ts +0 -258
  66. package/dist/simulation-zM6-YUaw.d.ts.map +0 -1
  67. package/dist/tx-CbDQ58Io.d.ts +0 -367
  68. package/dist/tx-CbDQ58Io.d.ts.map +0 -1
  69. package/dist/types-BHdnurYr.d.ts +0 -128
  70. package/dist/types-BHdnurYr.d.ts.map +0 -1
  71. package/dist/types-D_jcYss-.d.ts +0 -248
  72. package/dist/types-D_jcYss-.d.ts.map +0 -1
  73. package/dist/v2-D0dEatKb.js.map +0 -1
  74. package/dist/writes-AupZCK4M.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { PanopticError } from "./position-C8rkkKhi.js";
1
+ import { PanopticError } from "./getTrackedPositionIds-ms3W9dYB.js";
2
2
  import { BaseError, ContractFunctionRevertedError, encodeAbiParameters, encodeFunctionData, encodePacked, zeroAddress } from "viem";
3
3
 
4
4
  //#region src/uniswap/v4/router/errors.ts
@@ -309,5 +309,4 @@ function isRevert(err) {
309
309
  }
310
310
 
311
311
  //#endregion
312
- export { AmountExceedsUint128Error, InvalidSwapTokenError, MSG_SENDER, MissingSweepRecipientError, QuoterUnavailableError, UNISWAP_V3_ADDRESSES, UnsupportedChainError, V3_SWAP_EXACT_IN, buildV3SwapExecuteArgs, buildV3SwapExecuteCalldata, encodeV3Path, getUniswapV3Addresses, quoteV3ExactIn, universalRouterAbi };
313
- //# sourceMappingURL=router-DcoU2KmV.js.map
312
+ export { AmountExceedsUint128Error, InvalidSwapTokenError, MSG_SENDER, MissingSweepRecipientError, QuoterUnavailableError, UNISWAP_V3_ADDRESSES, UnsupportedChainError, V3_SWAP_EXACT_IN, buildV3SwapExecuteArgs, buildV3SwapExecuteCalldata, encodeV3Path, getUniswapV3Addresses, quoteV3ExactIn, universalRouterAbi };
@@ -1,5 +1,5 @@
1
- import { PanopticError, getBlockMeta$1 as getBlockMeta, getPool, submitWrite } from "./position-C8rkkKhi.js";
2
- import { AmountExceedsUint128Error, InvalidSwapTokenError, MissingSweepRecipientError, QuoterUnavailableError, UnsupportedChainError, universalRouterAbi } from "./router-DcoU2KmV.js";
1
+ import { PanopticError, getBlockMeta, getPool, submitWrite } from "./getTrackedPositionIds-ms3W9dYB.js";
2
+ import { AmountExceedsUint128Error, InvalidSwapTokenError, MissingSweepRecipientError, QuoterUnavailableError, UnsupportedChainError, universalRouterAbi } from "./router-BTfbaRfg.js";
3
3
  import { BaseError, ContractFunctionRevertedError, encodeAbiParameters, encodeFunctionData, encodePacked, erc20Abi, isAddressEqual, maxUint256, zeroAddress } from "viem";
4
4
 
5
5
  //#region src/uniswap/v4/addresses.ts
@@ -977,5 +977,4 @@ async function swapExactOutViaRouterAndWait(params) {
977
977
  }
978
978
 
979
979
  //#endregion
980
- export { PERMIT2_ADDRESS, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V4_ADDRESSES, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait };
981
- //# sourceMappingURL=router-CS86ptMu.js.map
980
+ export { PERMIT2_ADDRESS, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V4_ADDRESSES, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait };
@@ -1,7 +1,7 @@
1
- import { Address } from "viem";
2
1
  import { ReactNode } from "react";
3
2
  import { Config } from "wagmi";
4
3
  import * as react_jsx_runtime0 from "react/jsx-runtime";
4
+ import { Address } from "viem";
5
5
 
6
6
  //#region src/test/test-utils.d.ts
7
7
  declare const spawnAnvil: (args?: AnvilArgs) => Promise<void>;
@@ -1,7 +1,7 @@
1
- import { useEffect } from "react";
2
- import { WagmiProvider, useConnect } from "wagmi";
3
1
  import { exec, execSync, spawn } from "node:child_process";
4
2
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
+ import { useEffect } from "react";
4
+ import { WagmiProvider, useConnect } from "wagmi";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
 
7
7
  //#region src/test/test-utils.ts
@@ -0,0 +1,174 @@
1
+ import { estimateFeesPerGas, getFeeHistory } from "viem/actions";
2
+
3
+ //#region src/hypoVault/transactionFees.ts
4
+ const MIN_VAULT_PRIORITY_FEE_PER_GAS = 100000000n;
5
+ const MAX_VAULT_PRIORITY_FEE_PER_GAS = 3000000000n;
6
+ const MAX_VAULT_TRANSACTION_GAS_COST = 15000000000000000n;
7
+ const FEE_HISTORY_BLOCK_COUNT = 20;
8
+ const FEE_HISTORY_REWARD_PERCENTILES = [90];
9
+ const BASE_FEE_BUFFER_NUMERATOR = 1125n;
10
+ const BASE_FEE_BUFFER_DENOMINATOR = 1000n;
11
+ const GAS_ESTIMATE_BUFFER_NUMERATOR = 3n;
12
+ const GAS_ESTIMATE_BUFFER_DENOMINATOR = 2n;
13
+ var VaultTransactionFeeEstimationError = class extends Error {
14
+ feeHistoryError;
15
+ fallbackError;
16
+ constructor({ feeHistoryError, fallbackError }) {
17
+ super("Unable to estimate EIP-1559 fees for vault transaction");
18
+ this.name = "VaultTransactionFeeEstimationError";
19
+ this.feeHistoryError = feeHistoryError;
20
+ this.fallbackError = fallbackError;
21
+ }
22
+ };
23
+ var VaultTransactionGasCostLimitError = class extends Error {
24
+ gasLimit;
25
+ maximumAffordableFeePerGas;
26
+ minimumRequiredFeePerGas;
27
+ constructor({ gasLimit, maximumAffordableFeePerGas, minimumRequiredFeePerGas }) {
28
+ 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()}`);
29
+ this.name = "VaultTransactionGasCostLimitError";
30
+ this.gasLimit = gasLimit;
31
+ this.maximumAffordableFeePerGas = maximumAffordableFeePerGas;
32
+ this.minimumRequiredFeePerGas = minimumRequiredFeePerGas;
33
+ }
34
+ };
35
+ function ceilMultiplyFraction(value, numerator, denominator) {
36
+ return (value * numerator + denominator - 1n) / denominator;
37
+ }
38
+ function medianBigInt(values) {
39
+ if (values.length === 0) return void 0;
40
+ const sorted = [...values].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
41
+ const upperMiddleIndex = Math.floor(sorted.length / 2);
42
+ const upperMiddle = sorted[upperMiddleIndex];
43
+ if (upperMiddle === void 0) return void 0;
44
+ if (sorted.length % 2 === 1) return upperMiddle;
45
+ const lowerMiddle = sorted[upperMiddleIndex - 1];
46
+ return lowerMiddle === void 0 ? void 0 : (lowerMiddle + upperMiddle) / 2n;
47
+ }
48
+ function clampPriorityFee(priorityFee) {
49
+ if (priorityFee < MIN_VAULT_PRIORITY_FEE_PER_GAS) return MIN_VAULT_PRIORITY_FEE_PER_GAS;
50
+ if (priorityFee > MAX_VAULT_PRIORITY_FEE_PER_GAS) return MAX_VAULT_PRIORITY_FEE_PER_GAS;
51
+ return priorityFee;
52
+ }
53
+ function resolveFeeHistoryQuote({ baseFeePerGas, reward }) {
54
+ const latestBaseFeeIndex = baseFeePerGas.length - 2;
55
+ if (latestBaseFeeIndex < 0 || reward === void 0 || reward.length === 0) return null;
56
+ const p90Rewards = reward.flatMap((blockRewards) => {
57
+ const p90 = blockRewards[0];
58
+ return p90 === void 0 ? [] : [p90];
59
+ });
60
+ const sampledPriorityFee = medianBigInt(p90Rewards);
61
+ if (sampledPriorityFee === void 0) return null;
62
+ const maxPriorityFeePerGas = clampPriorityFee(sampledPriorityFee);
63
+ const bufferedBaseFee = ceilMultiplyFraction(baseFeePerGas[latestBaseFeeIndex], BASE_FEE_BUFFER_NUMERATOR, BASE_FEE_BUFFER_DENOMINATOR);
64
+ return {
65
+ maxFeePerGas: bufferedBaseFee + maxPriorityFeePerGas,
66
+ maxPriorityFeePerGas,
67
+ minimumMaxFeePerGas: bufferedBaseFee + MIN_VAULT_PRIORITY_FEE_PER_GAS,
68
+ source: "fee_history"
69
+ };
70
+ }
71
+ function resolveFallbackQuote({ maxFeePerGas: estimatedMaxFeePerGas, maxPriorityFeePerGas: estimatedPriorityFeePerGas }) {
72
+ const maxPriorityFeePerGas = clampPriorityFee(estimatedPriorityFeePerGas);
73
+ const estimatedBaseFeeAllowance = estimatedMaxFeePerGas > estimatedPriorityFeePerGas ? estimatedMaxFeePerGas - estimatedPriorityFeePerGas : 0n;
74
+ return {
75
+ maxFeePerGas: estimatedBaseFeeAllowance + maxPriorityFeePerGas,
76
+ maxPriorityFeePerGas,
77
+ minimumMaxFeePerGas: estimatedBaseFeeAllowance + MIN_VAULT_PRIORITY_FEE_PER_GAS,
78
+ source: "viem_fallback"
79
+ };
80
+ }
81
+ function applyVaultTransactionGasCostLimit(quote, gasLimit) {
82
+ if (gasLimit <= 0n) throw new Error(`Vault transaction gas limit must be positive, received ${gasLimit.toString()}`);
83
+ const maximumAffordableFeePerGas = MAX_VAULT_TRANSACTION_GAS_COST / gasLimit;
84
+ if (maximumAffordableFeePerGas < quote.minimumMaxFeePerGas) throw new VaultTransactionGasCostLimitError({
85
+ gasLimit,
86
+ maximumAffordableFeePerGas,
87
+ minimumRequiredFeePerGas: quote.minimumMaxFeePerGas
88
+ });
89
+ if (quote.maxFeePerGas <= maximumAffordableFeePerGas) return quote;
90
+ const bufferedBaseFee = quote.minimumMaxFeePerGas - MIN_VAULT_PRIORITY_FEE_PER_GAS;
91
+ const affordablePriorityFee = maximumAffordableFeePerGas - bufferedBaseFee;
92
+ return {
93
+ ...quote,
94
+ maxFeePerGas: maximumAffordableFeePerGas,
95
+ maxPriorityFeePerGas: quote.maxPriorityFeePerGas < affordablePriorityFee ? quote.maxPriorityFeePerGas : affordablePriorityFee
96
+ };
97
+ }
98
+ function bufferVaultTransactionGasEstimate(gasEstimate) {
99
+ if (gasEstimate <= 0n) throw new Error(`Vault transaction gas estimate must be positive, received ${gasEstimate.toString()}`);
100
+ return ceilMultiplyFraction(gasEstimate, GAS_ESTIMATE_BUFFER_NUMERATOR, GAS_ESTIMATE_BUFFER_DENOMINATOR);
101
+ }
102
+ function validateVaultSignedTransactionFeeCaps(feeCaps, quote) {
103
+ const { gasLimit, maxFeePerGas, maxPriorityFeePerGas } = feeCaps;
104
+ if (maxFeePerGas === null || maxPriorityFeePerGas === null) return {
105
+ valid: false,
106
+ code: "MissingEip1559Fees",
107
+ reason: "Signed transaction must include EIP-1559 max fee and priority fee caps."
108
+ };
109
+ if (maxPriorityFeePerGas > maxFeePerGas) return {
110
+ valid: false,
111
+ code: "InvalidFeeCaps",
112
+ reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) cannot exceed maxFeePerGas (${maxFeePerGas.toString()} wei).`
113
+ };
114
+ if (maxPriorityFeePerGas < MIN_VAULT_PRIORITY_FEE_PER_GAS) return {
115
+ valid: false,
116
+ code: "PriorityFeeTooLow",
117
+ reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must be at least ${MIN_VAULT_PRIORITY_FEE_PER_GAS.toString()} wei (0.1 gwei).`
118
+ };
119
+ if (maxPriorityFeePerGas > MAX_VAULT_PRIORITY_FEE_PER_GAS) return {
120
+ valid: false,
121
+ code: "PriorityFeeTooHigh",
122
+ reason: `Signed transaction maxPriorityFeePerGas (${maxPriorityFeePerGas.toString()} wei) must not exceed ${MAX_VAULT_PRIORITY_FEE_PER_GAS.toString()} wei (3 gwei).`
123
+ };
124
+ if (gasLimit !== void 0 && gasLimit !== null && gasLimit * maxFeePerGas > MAX_VAULT_TRANSACTION_GAS_COST) return {
125
+ valid: false,
126
+ code: "GasCostTooHigh",
127
+ reason: `Signed transaction maximum gas cost (${(gasLimit * maxFeePerGas).toString()} wei) must not exceed ${MAX_VAULT_TRANSACTION_GAS_COST.toString()} wei (0.015 ETH).`
128
+ };
129
+ if (quote !== void 0 && maxFeePerGas < quote.minimumMaxFeePerGas) return {
130
+ valid: false,
131
+ code: "MaxFeeTooLow",
132
+ 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.`
133
+ };
134
+ return { valid: true };
135
+ }
136
+ async function resolveVaultTransactionFeeQuote({ readFeeHistory, readFallbackEstimate }) {
137
+ let feeHistoryError;
138
+ try {
139
+ const quote = resolveFeeHistoryQuote(await readFeeHistory());
140
+ if (quote !== null) return quote;
141
+ feeHistoryError = new Error("eth_feeHistory returned incomplete base fee or reward data");
142
+ } catch (error) {
143
+ feeHistoryError = error;
144
+ }
145
+ try {
146
+ return resolveFallbackQuote(await readFallbackEstimate());
147
+ } catch (fallbackError) {
148
+ throw new VaultTransactionFeeEstimationError({
149
+ feeHistoryError,
150
+ fallbackError
151
+ });
152
+ }
153
+ }
154
+ /**
155
+ * Resolve explicit EIP-1559 fees for operator-controlled vault transactions.
156
+ *
157
+ * The normal path follows the median p90 priority fee from the last 20 blocks,
158
+ * with a 0.1 gwei floor and 3 gwei ceiling. If fee history is unavailable,
159
+ * Viem's estimate is used while preserving those bounds and its original
160
+ * base-fee allowance.
161
+ */
162
+ async function getVaultTransactionFeeQuote(client) {
163
+ return resolveVaultTransactionFeeQuote({
164
+ readFeeHistory: () => getFeeHistory(client, {
165
+ blockCount: FEE_HISTORY_BLOCK_COUNT,
166
+ blockTag: "latest",
167
+ rewardPercentiles: FEE_HISTORY_REWARD_PERCENTILES
168
+ }),
169
+ readFallbackEstimate: () => estimateFeesPerGas(client)
170
+ });
171
+ }
172
+
173
+ //#endregion
174
+ export { MAX_VAULT_PRIORITY_FEE_PER_GAS, MAX_VAULT_TRANSACTION_GAS_COST, MIN_VAULT_PRIORITY_FEE_PER_GAS, VaultTransactionFeeEstimationError, VaultTransactionGasCostLimitError, applyVaultTransactionGasCostLimit, bufferVaultTransactionGasEstimate, getVaultTransactionFeeQuote, validateVaultSignedTransactionFeeCaps };