@panoptic-eng/sdk 1.0.40 → 1.0.41
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.map +1 -1
- package/dist/cow/index.js +4 -0
- package/dist/cow/index.js.map +1 -1
- package/dist/index.d.ts +40 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -3
- package/dist/index.js.map +1 -1
- package/dist/panoptic/v2/index.d.ts +117 -11
- package/dist/panoptic/v2/index.d.ts.map +1 -1
- package/dist/panoptic/v2/index.js +1589 -1367
- package/dist/panoptic/v2/index.js.map +1 -1
- package/dist/panoptic/v2/react-public.d.ts +117 -11
- package/dist/panoptic/v2/react-public.d.ts.map +1 -1
- package/dist/panoptic/v2/react-public.js +1822 -1600
- package/dist/panoptic/v2/react-public.js.map +1 -1
- package/dist/{transactionFees-C_Qx07mx.js → transactionFees-DUm6ilXB.js} +106 -2
- package/dist/uniswap/index.js +4 -0
- package/dist/uniswap/index.js.map +1 -1
- package/dist/{v2-DG7qG6di.js → v2-ChGyiigb.js} +224 -33
- package/dist/vault-transaction-fees.d.ts +41 -3
- package/dist/vault-transaction-fees.d.ts.map +1 -1
- package/dist/vault-transaction-fees.js +106 -2
- package/dist/vault-transaction-fees.js.map +1 -1
- package/dist/{writes-Xp9Wa8GQ.js → writes-_gfkBizf.js} +35 -4
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hexToBigInt } from "viem";
|
|
2
|
+
import { estimateFeesPerGas, getBlock, getFeeHistory } from "viem/actions";
|
|
2
3
|
|
|
3
4
|
//#region src/hypoVault/transactionFees.ts
|
|
4
5
|
const MIN_VAULT_PRIORITY_FEE_PER_GAS = 100000000n;
|
|
@@ -6,8 +7,11 @@ const MAX_VAULT_PRIORITY_FEE_PER_GAS = 3000000000n;
|
|
|
6
7
|
const MAX_VAULT_TRANSACTION_GAS_COST = 15000000000000000n;
|
|
7
8
|
const FEE_HISTORY_BLOCK_COUNT = 20;
|
|
8
9
|
const FEE_HISTORY_REWARD_PERCENTILES = [90];
|
|
10
|
+
const DELTA_HEDGE_FEE_HISTORY_REWARD_PERCENTILES = [25];
|
|
9
11
|
const BASE_FEE_BUFFER_NUMERATOR = 1125n;
|
|
10
12
|
const BASE_FEE_BUFFER_DENOMINATOR = 1000n;
|
|
13
|
+
const REPLACEMENT_FEE_BUMP_NUMERATOR = 1125n;
|
|
14
|
+
const REPLACEMENT_FEE_BUMP_DENOMINATOR = 1000n;
|
|
11
15
|
const GAS_ESTIMATE_BUFFER_NUMERATOR = 3n;
|
|
12
16
|
const GAS_ESTIMATE_BUFFER_DENOMINATOR = 2n;
|
|
13
17
|
var VaultTransactionFeeEstimationError = class extends Error {
|
|
@@ -32,6 +36,20 @@ var VaultTransactionGasCostLimitError = class extends Error {
|
|
|
32
36
|
this.minimumRequiredFeePerGas = minimumRequiredFeePerGas;
|
|
33
37
|
}
|
|
34
38
|
};
|
|
39
|
+
var VaultTransactionReplacementLimitError = class extends Error {
|
|
40
|
+
code;
|
|
41
|
+
requiredMaxFeePerGas;
|
|
42
|
+
requiredMaxPriorityFeePerGas;
|
|
43
|
+
maximumAffordableFeePerGas;
|
|
44
|
+
constructor({ code, gasLimit, requiredMaxFeePerGas, requiredMaxPriorityFeePerGas, maximumAffordableFeePerGas }) {
|
|
45
|
+
super(`Vault transaction replacement blocked by ${code}: gasLimit=${gasLimit.toString()}, requiredMaxFeePerGas=${requiredMaxFeePerGas.toString()}, requiredMaxPriorityFeePerGas=${requiredMaxPriorityFeePerGas.toString()}, maximumAffordableFeePerGas=${maximumAffordableFeePerGas.toString()}`);
|
|
46
|
+
this.name = "VaultTransactionReplacementLimitError";
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.requiredMaxFeePerGas = requiredMaxFeePerGas;
|
|
49
|
+
this.requiredMaxPriorityFeePerGas = requiredMaxPriorityFeePerGas;
|
|
50
|
+
this.maximumAffordableFeePerGas = maximumAffordableFeePerGas;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
35
53
|
function ceilMultiplyFraction(value, numerator, denominator) {
|
|
36
54
|
return (value * numerator + denominator - 1n) / denominator;
|
|
37
55
|
}
|
|
@@ -68,6 +86,57 @@ function resolveFeeHistoryQuote({ baseFeePerGas, reward }) {
|
|
|
68
86
|
source: "fee_history"
|
|
69
87
|
};
|
|
70
88
|
}
|
|
89
|
+
function resolveDeltaHedgeFeeHistoryQuote({ baseFeePerGas, reward }) {
|
|
90
|
+
const latestBaseFeeIndex = baseFeePerGas.length - 2;
|
|
91
|
+
if (latestBaseFeeIndex < 0 || reward === void 0 || reward.length === 0) return null;
|
|
92
|
+
const p25Rewards = reward.flatMap((blockRewards) => {
|
|
93
|
+
const p25 = blockRewards[0];
|
|
94
|
+
return p25 === void 0 ? [] : [p25];
|
|
95
|
+
});
|
|
96
|
+
const rawPriorityFeePerGas = medianBigInt(p25Rewards);
|
|
97
|
+
if (rawPriorityFeePerGas === void 0) return null;
|
|
98
|
+
const maxPriorityFeePerGas = clampPriorityFee(rawPriorityFeePerGas);
|
|
99
|
+
const bufferedBaseFee = ceilMultiplyFraction(baseFeePerGas[latestBaseFeeIndex], BASE_FEE_BUFFER_NUMERATOR, BASE_FEE_BUFFER_DENOMINATOR);
|
|
100
|
+
return {
|
|
101
|
+
maxFeePerGas: bufferedBaseFee + maxPriorityFeePerGas,
|
|
102
|
+
maxPriorityFeePerGas,
|
|
103
|
+
minimumMaxFeePerGas: bufferedBaseFee + MIN_VAULT_PRIORITY_FEE_PER_GAS,
|
|
104
|
+
rawPriorityFeePerGas,
|
|
105
|
+
source: "fee_history_p25"
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function resolveRpcPriorityFeeQuote({ baseFeePerGas, rawPriorityFeePerGas }) {
|
|
109
|
+
const bufferedBaseFee = ceilMultiplyFraction(baseFeePerGas, BASE_FEE_BUFFER_NUMERATOR, BASE_FEE_BUFFER_DENOMINATOR);
|
|
110
|
+
return {
|
|
111
|
+
maxFeePerGas: bufferedBaseFee + rawPriorityFeePerGas,
|
|
112
|
+
maxPriorityFeePerGas: rawPriorityFeePerGas,
|
|
113
|
+
minimumMaxFeePerGas: bufferedBaseFee + rawPriorityFeePerGas,
|
|
114
|
+
rawPriorityFeePerGas,
|
|
115
|
+
source: "rpc_priority_fee"
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function getVaultTransactionReplacementFeeQuote({ originalQuote, historicalQuote, gasLimit }) {
|
|
119
|
+
if (gasLimit <= 0n) throw new Error(`Vault transaction gas limit must be positive, received ${gasLimit.toString()}`);
|
|
120
|
+
const bumpedPriorityFee = ceilMultiplyFraction(originalQuote.maxPriorityFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR);
|
|
121
|
+
const bumpedMaxFee = ceilMultiplyFraction(originalQuote.maxFeePerGas, REPLACEMENT_FEE_BUMP_NUMERATOR, REPLACEMENT_FEE_BUMP_DENOMINATOR);
|
|
122
|
+
const requiredMaxPriorityFeePerGas = historicalQuote.maxPriorityFeePerGas > bumpedPriorityFee ? historicalQuote.maxPriorityFeePerGas : bumpedPriorityFee;
|
|
123
|
+
const bufferedBaseFee = historicalQuote.minimumMaxFeePerGas - MIN_VAULT_PRIORITY_FEE_PER_GAS;
|
|
124
|
+
const currentMarketMaxFee = bufferedBaseFee + requiredMaxPriorityFeePerGas;
|
|
125
|
+
const requiredMaxFeePerGas = currentMarketMaxFee > bumpedMaxFee ? currentMarketMaxFee : bumpedMaxFee;
|
|
126
|
+
const maximumAffordableFeePerGas = MAX_VAULT_TRANSACTION_GAS_COST / gasLimit;
|
|
127
|
+
if (requiredMaxFeePerGas > maximumAffordableFeePerGas) throw new VaultTransactionReplacementLimitError({
|
|
128
|
+
code: "GasCostCapExceeded",
|
|
129
|
+
gasLimit,
|
|
130
|
+
requiredMaxFeePerGas,
|
|
131
|
+
requiredMaxPriorityFeePerGas,
|
|
132
|
+
maximumAffordableFeePerGas
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
...historicalQuote,
|
|
136
|
+
maxFeePerGas: requiredMaxFeePerGas,
|
|
137
|
+
maxPriorityFeePerGas: requiredMaxPriorityFeePerGas
|
|
138
|
+
};
|
|
139
|
+
}
|
|
71
140
|
function resolveFallbackQuote({ maxFeePerGas: estimatedMaxFeePerGas, maxPriorityFeePerGas: estimatedPriorityFeePerGas }) {
|
|
72
141
|
const maxPriorityFeePerGas = clampPriorityFee(estimatedPriorityFeePerGas);
|
|
73
142
|
const estimatedBaseFeeAllowance = estimatedMaxFeePerGas > estimatedPriorityFeePerGas ? estimatedMaxFeePerGas - estimatedPriorityFeePerGas : 0n;
|
|
@@ -169,6 +238,41 @@ async function getVaultTransactionFeeQuote(client) {
|
|
|
169
238
|
readFallbackEstimate: () => estimateFeesPerGas(client)
|
|
170
239
|
});
|
|
171
240
|
}
|
|
241
|
+
async function getVaultDeltaHedgeHistoricalFeeQuote(client) {
|
|
242
|
+
const feeHistory = await getFeeHistory(client, {
|
|
243
|
+
blockCount: FEE_HISTORY_BLOCK_COUNT,
|
|
244
|
+
blockTag: "latest",
|
|
245
|
+
rewardPercentiles: DELTA_HEDGE_FEE_HISTORY_REWARD_PERCENTILES
|
|
246
|
+
});
|
|
247
|
+
const quote = resolveDeltaHedgeFeeHistoryQuote(feeHistory);
|
|
248
|
+
if (quote === null) throw new Error("eth_feeHistory returned incomplete p25 base fee or reward data");
|
|
249
|
+
return quote;
|
|
250
|
+
}
|
|
251
|
+
async function resolveVaultDeltaHedgeInitialFeeQuote({ readRpcQuote, readHistoricalQuote }) {
|
|
252
|
+
try {
|
|
253
|
+
return resolveRpcPriorityFeeQuote(await readRpcQuote());
|
|
254
|
+
} catch {
|
|
255
|
+
return readHistoricalQuote();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Resolve the first fee quote for a delta hedge from the connected RPC's
|
|
260
|
+
* eth_maxPriorityFeePerGas recommendation. A failed RPC recommendation falls
|
|
261
|
+
* back immediately to the rolling historical p25 quote.
|
|
262
|
+
*/
|
|
263
|
+
async function getVaultDeltaHedgeInitialFeeQuote(client) {
|
|
264
|
+
return resolveVaultDeltaHedgeInitialFeeQuote({
|
|
265
|
+
readRpcQuote: async () => {
|
|
266
|
+
const [rawPriorityFee, latestBlock] = await Promise.all([client.request({ method: "eth_maxPriorityFeePerGas" }), getBlock(client, { blockTag: "latest" })]);
|
|
267
|
+
if (latestBlock.baseFeePerGas === null) throw new Error("Latest block does not include an EIP-1559 base fee");
|
|
268
|
+
return {
|
|
269
|
+
baseFeePerGas: latestBlock.baseFeePerGas,
|
|
270
|
+
rawPriorityFeePerGas: hexToBigInt(rawPriorityFee)
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
readHistoricalQuote: () => getVaultDeltaHedgeHistoricalFeeQuote(client)
|
|
274
|
+
});
|
|
275
|
+
}
|
|
172
276
|
|
|
173
277
|
//#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 };
|
|
278
|
+
export { MAX_VAULT_PRIORITY_FEE_PER_GAS, MAX_VAULT_TRANSACTION_GAS_COST, MIN_VAULT_PRIORITY_FEE_PER_GAS, VaultTransactionFeeEstimationError, VaultTransactionGasCostLimitError, VaultTransactionReplacementLimitError, applyVaultTransactionGasCostLimit, bufferVaultTransactionGasEstimate, getVaultDeltaHedgeHistoricalFeeQuote, getVaultDeltaHedgeInitialFeeQuote, getVaultTransactionFeeQuote, getVaultTransactionReplacementFeeQuote, validateVaultSignedTransactionFeeCaps };
|
package/dist/uniswap/index.js
CHANGED
|
@@ -5315,6 +5315,10 @@ const OPTION_BURNT_EVENT = getAbiItem({
|
|
|
5315
5315
|
name: "OptionBurnt"
|
|
5316
5316
|
});
|
|
5317
5317
|
|
|
5318
|
+
//#endregion
|
|
5319
|
+
//#region src/panoptic/v2/reads/positionSizes.ts
|
|
5320
|
+
const BIT_MASK_128 = (1n << 128n) - 1n;
|
|
5321
|
+
|
|
5318
5322
|
//#endregion
|
|
5319
5323
|
//#region src/panoptic/v2/simulations/tokenFlow.ts
|
|
5320
5324
|
/**
|