@panoptic-eng/sdk 1.0.47 → 1.0.48
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.js +48 -4
- package/dist/cow/index.js.map +1 -1
- package/dist/{cow-DIYBU1j9.js → cow-BPcuMjYR.js} +1 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +203 -162
- package/dist/index.js.map +1 -1
- package/dist/{irm-CvLqxTAo.js → irm-C7QhFiwL.js} +7 -246
- package/dist/panoptic/v2/index.d.ts +167 -32
- package/dist/panoptic/v2/index.d.ts.map +1 -1
- package/dist/panoptic/v2/index.js +1562 -930
- package/dist/panoptic/v2/index.js.map +1 -1
- package/dist/panoptic/v2/react-public.d.ts +167 -32
- package/dist/panoptic/v2/react-public.d.ts.map +1 -1
- package/dist/panoptic/v2/react-public.js +1164 -528
- package/dist/panoptic/v2/react-public.js.map +1 -1
- package/dist/{getTrackedPositionIds-CwBHzOO2.js → rates-5oQD-SuM.js} +256 -4
- package/dist/{router-OcmdMkXx.js → router-C26q7i8w.js} +2 -2
- package/dist/{router-CUlQfzoc.js → router-ClhAkKjh.js} +1 -1
- package/dist/uniswap/index.js +59 -15
- package/dist/uniswap/index.js.map +1 -1
- package/dist/{v2-DeGgMN2a.js → v2-DVcophLf.js} +1379 -2671
- package/dist/{writes-BZW7UA4N.js → writes-DBHwfbDD.js} +2855 -944
- package/dist/zodiac/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -438,6 +438,19 @@ var SwapTokenMismatchError = class extends PanopticError {
|
|
|
438
438
|
this.token1 = token1;
|
|
439
439
|
}
|
|
440
440
|
};
|
|
441
|
+
/**
|
|
442
|
+
* A premium settlement would advance the seller checkpoint while some
|
|
443
|
+
* displayed premium is still unavailable, or a required buyer cannot settle.
|
|
444
|
+
*/
|
|
445
|
+
var UnsafePremiumSettlementError = class extends PanopticError {
|
|
446
|
+
name = "UnsafePremiumSettlementError";
|
|
447
|
+
constructor(remainingForfeit, failedBuyerCount, cause) {
|
|
448
|
+
const [token0, token1] = remainingForfeit;
|
|
449
|
+
super(failedBuyerCount > 0 ? `Premium settlement blocked: ${failedBuyerCount} buyer settlement${failedBuyerCount === 1 ? "" : "s"} would fail` : `Premium settlement blocked: uncollectable premium remains (${token0}, ${token1})`, cause);
|
|
450
|
+
this.remainingForfeit = remainingForfeit;
|
|
451
|
+
this.failedBuyerCount = failedBuyerCount;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
441
454
|
|
|
442
455
|
//#endregion
|
|
443
456
|
//#region src/panoptic/v2/utils/interpolateBlocks.ts
|
|
@@ -10040,7 +10053,7 @@ function hasLoanOrCredit(tokenId) {
|
|
|
10040
10053
|
//#region src/panoptic/v2/formatters/tick.ts
|
|
10041
10054
|
const Q192$5 = 1n << 192n;
|
|
10042
10055
|
const RAW_PRICE_PRECISION = 40n;
|
|
10043
|
-
function pow10$
|
|
10056
|
+
function pow10$2(exponent) {
|
|
10044
10057
|
if (exponent < 0n) throw new RangeError("Exponent must be non-negative");
|
|
10045
10058
|
return 10n ** exponent;
|
|
10046
10059
|
}
|
|
@@ -10059,7 +10072,7 @@ function formatRatio$3(numerator, denominator, precision) {
|
|
|
10059
10072
|
if (precision < 0n) throw new RangeError("Precision must be non-negative");
|
|
10060
10073
|
const sign = numerator < 0n ? "-" : "";
|
|
10061
10074
|
const absNumerator = numerator < 0n ? -numerator : numerator;
|
|
10062
|
-
const scale = pow10$
|
|
10075
|
+
const scale = pow10$2(precision);
|
|
10063
10076
|
const scaled = (absNumerator * scale + denominator / 2n) / denominator;
|
|
10064
10077
|
const integerPart = scaled / scale;
|
|
10065
10078
|
const fractionalPart = scaled % scale;
|
|
@@ -10077,11 +10090,11 @@ function parseDecimalToFraction(value) {
|
|
|
10077
10090
|
const integerDigits = integerStr === "" ? "0" : integerStr;
|
|
10078
10091
|
const digits = `${integerDigits}${fractionalStr}`;
|
|
10079
10092
|
let numerator = BigInt(digits === "" ? "0" : digits);
|
|
10080
|
-
let denominator = pow10$
|
|
10093
|
+
let denominator = pow10$2(BigInt(fractionalStr.length));
|
|
10081
10094
|
if (exponentPart !== void 0 && exponentPart !== "") {
|
|
10082
10095
|
const exponent = BigInt(exponentPart);
|
|
10083
|
-
if (exponent > 0n) numerator *= pow10$
|
|
10084
|
-
else if (exponent < 0n) denominator *= pow10$
|
|
10096
|
+
if (exponent > 0n) numerator *= pow10$2(exponent);
|
|
10097
|
+
else if (exponent < 0n) denominator *= pow10$2(-exponent);
|
|
10085
10098
|
}
|
|
10086
10099
|
if (isNegative) numerator = -numerator;
|
|
10087
10100
|
return {
|
|
@@ -10141,12 +10154,12 @@ function adjustRatioForDecimals(numerator, denominator, decimals0, decimals1) {
|
|
|
10141
10154
|
denominator
|
|
10142
10155
|
};
|
|
10143
10156
|
if (diff > 0n) return {
|
|
10144
|
-
numerator: numerator * pow10$
|
|
10157
|
+
numerator: numerator * pow10$2(diff),
|
|
10145
10158
|
denominator
|
|
10146
10159
|
};
|
|
10147
10160
|
return {
|
|
10148
10161
|
numerator,
|
|
10149
|
-
denominator: denominator * pow10$
|
|
10162
|
+
denominator: denominator * pow10$2(-diff)
|
|
10150
10163
|
};
|
|
10151
10164
|
}
|
|
10152
10165
|
/**
|
|
@@ -10243,16 +10256,16 @@ function priceToTick(price, decimals0, decimals1) {
|
|
|
10243
10256
|
let targetNumerator = parsed.numerator;
|
|
10244
10257
|
let targetDenominator = parsed.denominator;
|
|
10245
10258
|
const diff = decimals0 - decimals1;
|
|
10246
|
-
if (diff > 0n) targetDenominator *= pow10$
|
|
10247
|
-
else if (diff < 0n) targetNumerator *= pow10$
|
|
10259
|
+
if (diff > 0n) targetDenominator *= pow10$2(diff);
|
|
10260
|
+
else if (diff < 0n) targetNumerator *= pow10$2(-diff);
|
|
10248
10261
|
let low = MIN_TICK;
|
|
10249
10262
|
let high = MAX_TICK;
|
|
10250
10263
|
while (low <= high) {
|
|
10251
10264
|
const mid = (low + high) / 2n;
|
|
10252
10265
|
const { numerator, denominator } = getRawPriceRatio(mid);
|
|
10253
|
-
const cmp = compareRatios(numerator, denominator, targetNumerator, targetDenominator);
|
|
10254
|
-
if (cmp === 0) return mid;
|
|
10255
|
-
if (cmp < 0) low = mid + 1n;
|
|
10266
|
+
const cmp$1 = compareRatios(numerator, denominator, targetNumerator, targetDenominator);
|
|
10267
|
+
if (cmp$1 === 0) return mid;
|
|
10268
|
+
if (cmp$1 < 0) low = mid + 1n;
|
|
10256
10269
|
else high = mid - 1n;
|
|
10257
10270
|
}
|
|
10258
10271
|
const floorTick = high;
|
|
@@ -10462,7 +10475,7 @@ function tickLimits(currentTick, toleranceBps) {
|
|
|
10462
10475
|
|
|
10463
10476
|
//#endregion
|
|
10464
10477
|
//#region src/panoptic/v2/tokenId/deriveUniqueTokenId.ts
|
|
10465
|
-
const POOL_ID_MASK$
|
|
10478
|
+
const POOL_ID_MASK$4 = (1n << 64n) - 1n;
|
|
10466
10479
|
const MAX_LEGS = TOKEN_ID_BITS.MAX_LEGS;
|
|
10467
10480
|
const MAX_OPTION_RATIO = LEG_LIMITS.MAX_RATIO;
|
|
10468
10481
|
const Q192$4 = 1n << 192n;
|
|
@@ -10569,7 +10582,7 @@ function scaleRatios(baseTokenId, targetPositionSize) {
|
|
|
10569
10582
|
const N = MAX_OPTION_RATIO / maxRatio;
|
|
10570
10583
|
if (N < 2n) throw new PanopticError("deriveUniqueTokenId: cannot derive a unique tokenId — all 4 leg slots used and optionRatios already near the 127 ceiling");
|
|
10571
10584
|
const newPositionSize = (targetPositionSize + N - 1n) / N;
|
|
10572
|
-
const poolId = baseTokenId & POOL_ID_MASK$
|
|
10585
|
+
const poolId = baseTokenId & POOL_ID_MASK$4;
|
|
10573
10586
|
let out = poolId;
|
|
10574
10587
|
for (const leg of legs) out = addLegToTokenId(out, {
|
|
10575
10588
|
index: leg.index,
|
|
@@ -11383,14 +11396,14 @@ function formatGwei(wei, precision) {
|
|
|
11383
11396
|
//#endregion
|
|
11384
11397
|
//#region src/panoptic/v2/tokenId/generateOverlapping.ts
|
|
11385
11398
|
const MAX_UINT64$2 = (1n << 64n) - 1n;
|
|
11386
|
-
const MAX_UINT128$
|
|
11399
|
+
const MAX_UINT128$4 = (1n << 128n) - 1n;
|
|
11387
11400
|
const Q192$3 = 1n << 192n;
|
|
11388
11401
|
const MAX_TOKEN_DECIMALS = 255n;
|
|
11389
11402
|
const MAX_DECIMAL_EXPONENT = 512n;
|
|
11390
11403
|
function invalid$1(message) {
|
|
11391
11404
|
throw new PanopticValidationError(`generateOverlappingTokenIds: ${message}`);
|
|
11392
11405
|
}
|
|
11393
|
-
function pow10(exponent) {
|
|
11406
|
+
function pow10$1(exponent) {
|
|
11394
11407
|
return 10n ** exponent;
|
|
11395
11408
|
}
|
|
11396
11409
|
function parsePriceSpacing(value, quoteDecimals) {
|
|
@@ -11403,7 +11416,7 @@ function parsePriceSpacing(value, quoteDecimals) {
|
|
|
11403
11416
|
let units = BigInt(`${integerPart}${fractionalPart}`);
|
|
11404
11417
|
let scale = BigInt(fractionalPart.length) - exponent;
|
|
11405
11418
|
if (scale < 0n) {
|
|
11406
|
-
units *= pow10(-scale);
|
|
11419
|
+
units *= pow10$1(-scale);
|
|
11407
11420
|
scale = 0n;
|
|
11408
11421
|
}
|
|
11409
11422
|
while (scale > 0n && units % 10n === 0n) {
|
|
@@ -11415,7 +11428,7 @@ function parsePriceSpacing(value, quoteDecimals) {
|
|
|
11415
11428
|
return {
|
|
11416
11429
|
units,
|
|
11417
11430
|
scale,
|
|
11418
|
-
denominator: pow10(scale)
|
|
11431
|
+
denominator: pow10$1(scale)
|
|
11419
11432
|
};
|
|
11420
11433
|
}
|
|
11421
11434
|
function formatGridPrice(multiple, spacing) {
|
|
@@ -11432,8 +11445,8 @@ function quotePriceAtTick(tick, asset, assetDecimals, quoteDecimals) {
|
|
|
11432
11445
|
let numerator = sqrtPriceX96 * sqrtPriceX96;
|
|
11433
11446
|
let denominator = Q192$3;
|
|
11434
11447
|
const decimalDifference = assetDecimals - quoteDecimals;
|
|
11435
|
-
if (decimalDifference > 0n) numerator *= pow10(decimalDifference);
|
|
11436
|
-
else if (decimalDifference < 0n) denominator *= pow10(-decimalDifference);
|
|
11448
|
+
if (decimalDifference > 0n) numerator *= pow10$1(decimalDifference);
|
|
11449
|
+
else if (decimalDifference < 0n) denominator *= pow10$1(-decimalDifference);
|
|
11437
11450
|
return {
|
|
11438
11451
|
numerator,
|
|
11439
11452
|
denominator
|
|
@@ -11450,12 +11463,12 @@ function isPriceGridStrike(strike, params, spacing, tickSpacing) {
|
|
|
11450
11463
|
}
|
|
11451
11464
|
return false;
|
|
11452
11465
|
}
|
|
11453
|
-
function ceilDiv$
|
|
11466
|
+
function ceilDiv$3(value, divisor) {
|
|
11454
11467
|
const quotient = value / divisor;
|
|
11455
11468
|
const remainder = value % divisor;
|
|
11456
11469
|
return remainder > 0n ? quotient + 1n : quotient;
|
|
11457
11470
|
}
|
|
11458
|
-
function floorDiv(value, divisor) {
|
|
11471
|
+
function floorDiv$1(value, divisor) {
|
|
11459
11472
|
const quotient = value / divisor;
|
|
11460
11473
|
const remainder = value % divisor;
|
|
11461
11474
|
return remainder < 0n ? quotient - 1n : quotient;
|
|
@@ -11483,8 +11496,8 @@ function resolveLegs(legs) {
|
|
|
11483
11496
|
function getCandidateStrikes(params, spacing, tickSpacing, halfWidth) {
|
|
11484
11497
|
const lower = MIN_TICK + halfWidth > params.currentTick - halfWidth + 1n ? MIN_TICK + halfWidth : params.currentTick - halfWidth + 1n;
|
|
11485
11498
|
const upper = MAX_TICK - halfWidth < params.currentTick + halfWidth - 1n ? MAX_TICK - halfWidth : params.currentTick + halfWidth - 1n;
|
|
11486
|
-
const firstStrike = ceilDiv$
|
|
11487
|
-
const lastStrike = floorDiv(upper, tickSpacing) * tickSpacing;
|
|
11499
|
+
const firstStrike = ceilDiv$3(lower, tickSpacing) * tickSpacing;
|
|
11500
|
+
const lastStrike = floorDiv$1(upper, tickSpacing) * tickSpacing;
|
|
11488
11501
|
const strikes = [];
|
|
11489
11502
|
for (let strike = firstStrike; strike <= lastStrike; strike += tickSpacing) if (isPriceGridStrike(strike, params, spacing, tickSpacing)) strikes.push(strike);
|
|
11490
11503
|
if (params.asset === 1n) strikes.reverse();
|
|
@@ -11524,7 +11537,7 @@ function generateOverlappingTokenIds(params) {
|
|
|
11524
11537
|
if (params.currentTick < MIN_TICK || params.currentTick > MAX_TICK) invalid$1(`currentTick must be between ${MIN_TICK} and ${MAX_TICK}`);
|
|
11525
11538
|
if (params.asset !== 0n && params.asset !== 1n) invalid$1("asset must be 0 or 1");
|
|
11526
11539
|
if (params.assetDecimals < 0n || params.assetDecimals > MAX_TOKEN_DECIMALS || params.quoteDecimals < 0n || params.quoteDecimals > MAX_TOKEN_DECIMALS) invalid$1("assetDecimals and quoteDecimals must be between 0 and 255");
|
|
11527
|
-
if (params.positionSize <= 0n || params.positionSize > MAX_UINT128$
|
|
11540
|
+
if (params.positionSize <= 0n || params.positionSize > MAX_UINT128$4) invalid$1("positionSize must be between 1 and uint128.max");
|
|
11528
11541
|
const tickSpacing = decodeTickSpacing(params.poolId);
|
|
11529
11542
|
if (tickSpacing <= 0n) invalid$1("poolId tick spacing must be positive");
|
|
11530
11543
|
const standardTickWidth = STANDARD_TICK_WIDTHS[params.timescale];
|
|
@@ -11545,15 +11558,15 @@ function generateOverlappingTokenIds(params) {
|
|
|
11545
11558
|
|
|
11546
11559
|
//#endregion
|
|
11547
11560
|
//#region src/panoptic/v2/tokenId/split.ts
|
|
11548
|
-
const POOL_ID_MASK$
|
|
11549
|
-
const MAX_UINT128$
|
|
11561
|
+
const POOL_ID_MASK$3 = (1n << TOKEN_ID_BITS.POOL_ID_SIZE) - 1n;
|
|
11562
|
+
const MAX_UINT128$3 = (1n << 128n) - 1n;
|
|
11550
11563
|
const MAX_UINT256$1 = (1n << 256n) - 1n;
|
|
11551
11564
|
function invalid(message) {
|
|
11552
11565
|
throw new PanopticValidationError(`splitTokenIdByTimescale: ${message}`);
|
|
11553
11566
|
}
|
|
11554
11567
|
function validateInput(tokenId, positionSize) {
|
|
11555
11568
|
if (tokenId < 0n || tokenId > MAX_UINT256$1) invalid("tokenId must fit in uint256");
|
|
11556
|
-
if (positionSize <= 0n || positionSize > MAX_UINT128$
|
|
11569
|
+
if (positionSize <= 0n || positionSize > MAX_UINT128$3) invalid("positionSize must be between 1 and uint128.max");
|
|
11557
11570
|
const legs = decodeAllLegs(tokenId);
|
|
11558
11571
|
if (legs.length === 0) invalid("tokenId must contain at least one active leg");
|
|
11559
11572
|
for (const [index, leg] of legs.entries()) if (leg.index !== BigInt(index)) invalid("active legs must be contiguous from index 0");
|
|
@@ -11682,7 +11695,7 @@ function splitTokenIdByTimescale(tokenId, positionSize, targetTimescale) {
|
|
|
11682
11695
|
const targetTickWidth = STANDARD_TICK_WIDTHS[targetTimescale];
|
|
11683
11696
|
if (targetTickWidth === void 0) invalid(`unknown target timescale ${String(targetTimescale)}`);
|
|
11684
11697
|
const targetWidth = (targetTickWidth + tickSpacing - 1n) / tickSpacing;
|
|
11685
|
-
const poolId = tokenId & POOL_ID_MASK$
|
|
11698
|
+
const poolId = tokenId & POOL_ID_MASK$3;
|
|
11686
11699
|
const optionLegs = legs.filter((leg) => leg.width > 0n);
|
|
11687
11700
|
const fundingLegs = legs.filter((leg) => leg.width === 0n);
|
|
11688
11701
|
const positionIdList = [];
|
|
@@ -13826,7 +13839,7 @@ async function fetchPoolId(params) {
|
|
|
13826
13839
|
//#endregion
|
|
13827
13840
|
//#region src/panoptic/v2/greeks/index.ts
|
|
13828
13841
|
/** Fixed-point scale constants for sqrtPriceX96 arithmetic */
|
|
13829
|
-
const Q96 = 1n << 96n;
|
|
13842
|
+
const Q96$1 = 1n << 96n;
|
|
13830
13843
|
const Q192$2 = 1n << 192n;
|
|
13831
13844
|
/**
|
|
13832
13845
|
* Convert tick to quote-denominated tick based on asset direction.
|
|
@@ -13974,7 +13987,7 @@ function computeOptionItm(m, qStrikeTick, qMintTick, halfWidthTick, isPut) {
|
|
|
13974
13987
|
const sqrtK = tickToSqrtPriceX96(qStrikeTick);
|
|
13975
13988
|
const sqrtPm = tickToSqrtPriceX96(qMintTick);
|
|
13976
13989
|
const rX192 = sqrtR * sqrtR;
|
|
13977
|
-
const sqrtKPmX96 = divTrunc(sqrtK * Q96, sqrtPm);
|
|
13990
|
+
const sqrtKPmX96 = divTrunc(sqrtK * Q96$1, sqrtPm);
|
|
13978
13991
|
const diff = sqrtR - sqrtKPmX96;
|
|
13979
13992
|
const diffSqX192 = diff * diff;
|
|
13980
13993
|
return divTrunc(m * diffSqX192, rX192 - Q192$2);
|
|
@@ -14046,7 +14059,7 @@ function getLegValue(leg, currentTick, mintTick, positionSize, poolTickSpacing,
|
|
|
14046
14059
|
const PX192 = sqrtP * sqrtP;
|
|
14047
14060
|
const KX192 = sqrtK * sqrtK;
|
|
14048
14061
|
const rX192 = sqrtR * sqrtR;
|
|
14049
|
-
const numerator = m * (2n * sqrtPKR * Q96 - PX192 - KX192);
|
|
14062
|
+
const numerator = m * (2n * sqrtPKR * Q96$1 - PX192 - KX192);
|
|
14050
14063
|
const denominator = rX192 - Q192$2;
|
|
14051
14064
|
v = divTrunc(numerator, denominator);
|
|
14052
14065
|
}
|
|
@@ -14154,7 +14167,7 @@ function getLegDelta(leg, currentTick, positionSize, poolTickSpacing, mintTick,
|
|
|
14154
14167
|
const sqrtK = tickToSqrtPriceX96(qStrikeTick);
|
|
14155
14168
|
const sqrtPm = tickToSqrtPriceX96(qMintTick);
|
|
14156
14169
|
const rX192 = sqrtR * sqrtR;
|
|
14157
|
-
const sqrtKPmX96 = sqrtK * Q96 / sqrtPm;
|
|
14170
|
+
const sqrtKPmX96 = sqrtK * Q96$1 / sqrtPm;
|
|
14158
14171
|
const diff = sqrtR - sqrtKPmX96;
|
|
14159
14172
|
const diffSqX192 = diff * diff;
|
|
14160
14173
|
return divTrunc(m * diffSqX192, rX192 - Q192$2);
|
|
@@ -14213,7 +14226,7 @@ function getLegGamma(leg, currentTick, positionSize, poolTickSpacing, assetIndex
|
|
|
14213
14226
|
const sqrtKPR = tickToSqrtPriceX96(qStrikeTick + qCurrentTick + halfWidthTick);
|
|
14214
14227
|
const sqrtR = tickToSqrtPriceX96(halfWidthTick);
|
|
14215
14228
|
const rX192 = sqrtR * sqrtR;
|
|
14216
|
-
const numerator = m * sqrtKPR * Q96;
|
|
14229
|
+
const numerator = m * sqrtKPR * Q96$1;
|
|
14217
14230
|
const denominator = 2n * (rX192 - Q192$2);
|
|
14218
14231
|
return divTrunc(numerator, denominator);
|
|
14219
14232
|
}
|
|
@@ -18334,7 +18347,7 @@ function maximumAmountIn(estimatedAmountIn, slippageBps) {
|
|
|
18334
18347
|
if (slippageBps < 0n) throw new PanopticError("slippageBps must be non-negative");
|
|
18335
18348
|
return (estimatedAmountIn * (BPS_DENOMINATOR$5 + slippageBps) + BPS_DENOMINATOR$5 - 1n) / BPS_DENOMINATOR$5;
|
|
18336
18349
|
}
|
|
18337
|
-
function ceilDiv(numerator, denominator) {
|
|
18350
|
+
function ceilDiv$2(numerator, denominator) {
|
|
18338
18351
|
return (numerator + denominator - 1n) / denominator;
|
|
18339
18352
|
}
|
|
18340
18353
|
function getInputAmount(tokenFlow, tokenInIndex) {
|
|
@@ -18449,7 +18462,7 @@ async function quoteTokenShortfallRecovery(params) {
|
|
|
18449
18462
|
error: new PanopticError("Insufficient source collateral for the recovery swap")
|
|
18450
18463
|
};
|
|
18451
18464
|
if (estimatedAmountOut < requiredOutput) {
|
|
18452
|
-
creditInput = estimatedAmountOut > 0n ? ceilDiv(creditInput * requiredOutput, estimatedAmountOut) + 1n : creditInput * 2n;
|
|
18465
|
+
creditInput = estimatedAmountOut > 0n ? ceilDiv$2(creditInput * requiredOutput, estimatedAmountOut) + 1n : creditInput * 2n;
|
|
18453
18466
|
continue;
|
|
18454
18467
|
}
|
|
18455
18468
|
const recoveredDispatch = buildPrefixedExactInputRecoveryDispatch({
|
|
@@ -18503,7 +18516,7 @@ async function quoteTokenShortfallRecovery(params) {
|
|
|
18503
18516
|
};
|
|
18504
18517
|
const residual = remainingShortfall.assetsRequested - remainingShortfall.assetBalance;
|
|
18505
18518
|
requiredOutput += residual > 0n ? residual : requiredOutput;
|
|
18506
|
-
creditInput = ceilDiv(creditInput * requiredOutput, estimatedAmountOut) + 1n;
|
|
18519
|
+
creditInput = ceilDiv$2(creditInput * requiredOutput, estimatedAmountOut) + 1n;
|
|
18507
18520
|
}
|
|
18508
18521
|
return {
|
|
18509
18522
|
available: false,
|
|
@@ -18559,7 +18572,7 @@ async function quoteTokenShortfallRecovery(params) {
|
|
|
18559
18572
|
const swapOutput = getOutputAmount(swapSimulation.tokenFlow, tokenOutIndex);
|
|
18560
18573
|
const sourceBalance = getBalanceBefore(swapSimulation.tokenFlow, tokenInIndex);
|
|
18561
18574
|
if (swapOutput < amountOut) {
|
|
18562
|
-
creditOutSize = swapOutput > 0n ? ceilDiv(creditOutSize * amountOut, swapOutput) + 1n : creditOutSize * 2n;
|
|
18575
|
+
creditOutSize = swapOutput > 0n ? ceilDiv$2(creditOutSize * amountOut, swapOutput) + 1n : creditOutSize * 2n;
|
|
18563
18576
|
continue;
|
|
18564
18577
|
}
|
|
18565
18578
|
if (sourceBalance < maxAmountIn) return {
|
|
@@ -18618,7 +18631,7 @@ async function quoteTokenShortfallRecovery(params) {
|
|
|
18618
18631
|
const decodedShortfall = remainingShortfall.assetsRequested - remainingShortfall.assetBalance;
|
|
18619
18632
|
const additionalAmountOut = decodedShortfall > 0n ? decodedShortfall : amountOut;
|
|
18620
18633
|
amountOut += additionalAmountOut;
|
|
18621
|
-
creditOutSize = swapOutput > 0n ? ceilDiv(creditOutSize * amountOut, swapOutput) + 1n : creditOutSize * 2n;
|
|
18634
|
+
creditOutSize = swapOutput > 0n ? ceilDiv$2(creditOutSize * amountOut, swapOutput) + 1n : creditOutSize * 2n;
|
|
18622
18635
|
}
|
|
18623
18636
|
return {
|
|
18624
18637
|
available: false,
|
|
@@ -18967,7 +18980,7 @@ async function getItmAmounts(params) {
|
|
|
18967
18980
|
*/
|
|
18968
18981
|
const FLOW_NEUTRAL_DUST_THRESHOLD = 1000n;
|
|
18969
18982
|
const Q192$1 = 1n << 192n;
|
|
18970
|
-
const POOL_ID_MASK$
|
|
18983
|
+
const POOL_ID_MASK$2 = (1n << 64n) - 1n;
|
|
18971
18984
|
/**
|
|
18972
18985
|
* Floor integer square root for bigints (Newton's method). Exact for all
|
|
18973
18986
|
* non-negative inputs — no float precision loss for values above 2^53.
|
|
@@ -19127,7 +19140,7 @@ async function createFlowNeutralTokenId(params) {
|
|
|
19127
19140
|
const measureSize = referenceSize !== void 0 && referenceSize > 0n && referenceSize < positionSize ? referenceSize : positionSize;
|
|
19128
19141
|
const legCount = countLegs(tokenId);
|
|
19129
19142
|
if (legCount >= 4n) throw new PanopticError("Cannot append neutralizing leg: tokenId already has 4 legs");
|
|
19130
|
-
const poolId = tokenId & POOL_ID_MASK$
|
|
19143
|
+
const poolId = tokenId & POOL_ID_MASK$2;
|
|
19131
19144
|
const baseLegs = decodeAllLegs(tokenId);
|
|
19132
19145
|
const prependNeutral = baseLegs.length === 1 && baseLegs[0].tokenType === baseLegs[0].asset;
|
|
19133
19146
|
let credit;
|
|
@@ -19434,7 +19447,7 @@ async function tryWithdrawSimulation(params) {
|
|
|
19434
19447
|
//#endregion
|
|
19435
19448
|
//#region src/panoptic/v2/reads/collateralBreakdown.ts
|
|
19436
19449
|
/** Mask selecting the poolId (low 64 bits) of a tokenId. */
|
|
19437
|
-
const POOL_ID_MASK = (1n << 64n) - 1n;
|
|
19450
|
+
const POOL_ID_MASK$1 = (1n << 64n) - 1n;
|
|
19438
19451
|
/** `getRequiredBase` prices at `type(uint64).max`; results scale linearly in size. */
|
|
19439
19452
|
const MAX_UINT64 = 2n ** 64n - 1n;
|
|
19440
19453
|
/** Kinds whose collateral rule is identical on-chain and must share one explanation. */
|
|
@@ -19559,7 +19572,7 @@ function isolateGroupTokenId(tokenId, legIndices) {
|
|
|
19559
19572
|
const byIndex = new Map(legs.map((leg) => [leg.index, leg]));
|
|
19560
19573
|
const ordered = [...legIndices].sort((x, y) => x < y ? -1 : x > y ? 1 : 0);
|
|
19561
19574
|
const remapped = new Map(ordered.map((old, i) => [old, BigInt(i)]));
|
|
19562
|
-
let out = tokenId & POOL_ID_MASK;
|
|
19575
|
+
let out = tokenId & POOL_ID_MASK$1;
|
|
19563
19576
|
for (const [index, oldIndex] of ordered.entries()) {
|
|
19564
19577
|
const leg = byIndex.get(oldIndex);
|
|
19565
19578
|
if (leg === void 0) throw new PanopticError(`isolateGroupTokenId: leg ${oldIndex} is not present in the tokenId`);
|
|
@@ -22430,7 +22443,7 @@ const nfpmAbi = [{
|
|
|
22430
22443
|
}],
|
|
22431
22444
|
stateMutability: "payable"
|
|
22432
22445
|
}];
|
|
22433
|
-
const MAX_UINT128$
|
|
22446
|
+
const MAX_UINT128$2 = 2n ** 128n - 1n;
|
|
22434
22447
|
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
22435
22448
|
const Q128 = 2n ** 128n;
|
|
22436
22449
|
/**
|
|
@@ -22472,8 +22485,8 @@ async function getUniswapV3LpPositionState(params) {
|
|
|
22472
22485
|
args: [{
|
|
22473
22486
|
tokenId,
|
|
22474
22487
|
recipient: owner,
|
|
22475
|
-
amount0Max: MAX_UINT128$
|
|
22476
|
-
amount1Max: MAX_UINT128$
|
|
22488
|
+
amount0Max: MAX_UINT128$2,
|
|
22489
|
+
amount1Max: MAX_UINT128$2
|
|
22477
22490
|
}],
|
|
22478
22491
|
account: owner,
|
|
22479
22492
|
blockNumber: _meta.blockNumber
|
|
@@ -24849,6 +24862,628 @@ async function executeSettleSequenceAndWait(params) {
|
|
|
24849
24862
|
return receipt;
|
|
24850
24863
|
}
|
|
24851
24864
|
|
|
24865
|
+
//#endregion
|
|
24866
|
+
//#region src/panoptic/v2/writes/protectedSettle.ts
|
|
24867
|
+
const POOL_ID_MASK = (1n << 64n) - 1n;
|
|
24868
|
+
const Q96 = 1n << 96n;
|
|
24869
|
+
const MAX_UINT128$1 = (1n << 128n) - 1n;
|
|
24870
|
+
const SETTLE_LIMITS = [
|
|
24871
|
+
-887272n,
|
|
24872
|
+
887272n,
|
|
24873
|
+
0n
|
|
24874
|
+
];
|
|
24875
|
+
function ceilDiv$1(numerator, denominator) {
|
|
24876
|
+
return (numerator + denominator - 1n) / denominator;
|
|
24877
|
+
}
|
|
24878
|
+
/** Smallest position size that creates non-zero liquidity on every poke leg. */
|
|
24879
|
+
function minimumPokeSize(legs, tickSpacing) {
|
|
24880
|
+
let requiredSize = 1n;
|
|
24881
|
+
for (const leg of legs) {
|
|
24882
|
+
const widthInTicks = leg.width * tickSpacing;
|
|
24883
|
+
const lowerTick = leg.strike - widthInTicks / 2n;
|
|
24884
|
+
const upperTick = leg.strike + (widthInTicks + 1n) / 2n;
|
|
24885
|
+
const sqrtLower = tickToSqrtPriceX96(lowerTick);
|
|
24886
|
+
const sqrtUpper = tickToSqrtPriceX96(upperTick);
|
|
24887
|
+
const delta = sqrtUpper - sqrtLower;
|
|
24888
|
+
const liquidityFactor = leg.asset === 0n ? sqrtLower * sqrtUpper / Q96 : Q96;
|
|
24889
|
+
if (liquidityFactor === 0n) return void 0;
|
|
24890
|
+
const requiredAmount = ceilDiv$1(delta, liquidityFactor);
|
|
24891
|
+
const legSize = ceilDiv$1(requiredAmount, leg.optionRatio);
|
|
24892
|
+
if (legSize > requiredSize) requiredSize = legSize;
|
|
24893
|
+
}
|
|
24894
|
+
if (requiredSize > MAX_UINT128$1) return void 0;
|
|
24895
|
+
return requiredSize;
|
|
24896
|
+
}
|
|
24897
|
+
function encodePokeToken(sourceTokenId, legs, firstRatio, assetMask) {
|
|
24898
|
+
let tokenId = sourceTokenId & POOL_ID_MASK;
|
|
24899
|
+
legs.forEach((leg, index) => {
|
|
24900
|
+
const encodedIndex = BigInt(index);
|
|
24901
|
+
tokenId = addLegToTokenId(tokenId, {
|
|
24902
|
+
index: encodedIndex,
|
|
24903
|
+
asset: assetMask >> encodedIndex & 1n,
|
|
24904
|
+
optionRatio: index === 0 ? firstRatio : leg.optionRatio,
|
|
24905
|
+
isLong: 0n,
|
|
24906
|
+
tokenType: leg.tokenType,
|
|
24907
|
+
riskPartner: encodedIndex,
|
|
24908
|
+
strike: leg.strike,
|
|
24909
|
+
width: leg.width
|
|
24910
|
+
});
|
|
24911
|
+
});
|
|
24912
|
+
return tokenId;
|
|
24913
|
+
}
|
|
24914
|
+
function buildUniquePoke(sourceTokenId, occupied) {
|
|
24915
|
+
const seenChunks = new Set();
|
|
24916
|
+
const shortChunkLegs = decodeAllLegs(sourceTokenId).filter((leg) => {
|
|
24917
|
+
if (leg.isLong || leg.width === 0n) return false;
|
|
24918
|
+
const chunkKey = `${leg.strike}:${leg.width}:${leg.tokenType}`;
|
|
24919
|
+
if (seenChunks.has(chunkKey)) return false;
|
|
24920
|
+
seenChunks.add(chunkKey);
|
|
24921
|
+
return true;
|
|
24922
|
+
});
|
|
24923
|
+
if (shortChunkLegs.length === 0) return void 0;
|
|
24924
|
+
const originalRatio = shortChunkLegs[0].optionRatio;
|
|
24925
|
+
for (let ratioOffset = 0n; ratioOffset < 127n; ratioOffset += 1n) {
|
|
24926
|
+
const firstRatio = (originalRatio - 1n + ratioOffset) % 127n + 1n;
|
|
24927
|
+
const assetVariants = 1n << BigInt(shortChunkLegs.length);
|
|
24928
|
+
for (let assetMask = 0n; assetMask < assetVariants; assetMask += 1n) {
|
|
24929
|
+
const tokenId = encodePokeToken(sourceTokenId, shortChunkLegs, firstRatio, assetMask);
|
|
24930
|
+
if (!occupied.has(tokenId)) {
|
|
24931
|
+
const size = minimumPokeSize(decodeAllLegs(tokenId), decodeTickSpacing(sourceTokenId));
|
|
24932
|
+
if (size !== void 0) return {
|
|
24933
|
+
tokenId,
|
|
24934
|
+
size
|
|
24935
|
+
};
|
|
24936
|
+
}
|
|
24937
|
+
}
|
|
24938
|
+
}
|
|
24939
|
+
throw new PanopticError("Unable to derive a collision-free protected settlement poke");
|
|
24940
|
+
}
|
|
24941
|
+
/**
|
|
24942
|
+
* Build `[poke, settle, poke]` for every target containing a width>0 short.
|
|
24943
|
+
* Pure-long and width-zero positions are settled directly.
|
|
24944
|
+
*/
|
|
24945
|
+
function buildProtectedSettlePlan(params) {
|
|
24946
|
+
const { positionIdList, finalPositionIdList, positionSizes, usePremiaAsCollateral = false, builderCode = 0n } = params;
|
|
24947
|
+
if (positionIdList.length !== positionSizes.length) throw new PanopticError("Protected settlement: positionSizes length must match positionIdList");
|
|
24948
|
+
const occupied = new Set(finalPositionIdList);
|
|
24949
|
+
const actionIds = [];
|
|
24950
|
+
const actionSizes = [];
|
|
24951
|
+
const actionLimits = [];
|
|
24952
|
+
const collectionIds = [];
|
|
24953
|
+
const collectionSizes = [];
|
|
24954
|
+
const collectionLimits = [];
|
|
24955
|
+
const pokingTokenIds = [];
|
|
24956
|
+
positionIdList.forEach((tokenId, index) => {
|
|
24957
|
+
const poke = buildUniquePoke(tokenId, occupied);
|
|
24958
|
+
if (poke === void 0) {
|
|
24959
|
+
actionIds.push(tokenId);
|
|
24960
|
+
actionSizes.push(positionSizes[index]);
|
|
24961
|
+
actionLimits.push(SETTLE_LIMITS);
|
|
24962
|
+
return;
|
|
24963
|
+
}
|
|
24964
|
+
occupied.add(poke.tokenId);
|
|
24965
|
+
pokingTokenIds.push(poke.tokenId);
|
|
24966
|
+
actionIds.push(poke.tokenId, tokenId, poke.tokenId);
|
|
24967
|
+
actionSizes.push(poke.size, positionSizes[index], 0n);
|
|
24968
|
+
actionLimits.push(SETTLE_LIMITS, SETTLE_LIMITS, SETTLE_LIMITS);
|
|
24969
|
+
collectionIds.push(poke.tokenId, poke.tokenId);
|
|
24970
|
+
collectionSizes.push(poke.size, 0n);
|
|
24971
|
+
collectionLimits.push(SETTLE_LIMITS, SETTLE_LIMITS);
|
|
24972
|
+
});
|
|
24973
|
+
const base = {
|
|
24974
|
+
finalPositionIdList: [...finalPositionIdList],
|
|
24975
|
+
usePremiaAsCollateral,
|
|
24976
|
+
builderCode
|
|
24977
|
+
};
|
|
24978
|
+
return {
|
|
24979
|
+
dispatch: {
|
|
24980
|
+
...base,
|
|
24981
|
+
positionIdList: actionIds,
|
|
24982
|
+
positionSizes: actionSizes,
|
|
24983
|
+
tickAndSpreadLimits: actionLimits
|
|
24984
|
+
},
|
|
24985
|
+
collectionDispatch: collectionIds.length === 0 ? void 0 : {
|
|
24986
|
+
...base,
|
|
24987
|
+
positionIdList: collectionIds,
|
|
24988
|
+
positionSizes: collectionSizes,
|
|
24989
|
+
tickAndSpreadLimits: collectionLimits
|
|
24990
|
+
},
|
|
24991
|
+
pokingTokenIds
|
|
24992
|
+
};
|
|
24993
|
+
}
|
|
24994
|
+
/**
|
|
24995
|
+
* Build the atomic self-settlement dispatch that temporarily pokes each
|
|
24996
|
+
* affected short chunk before settling its source position.
|
|
24997
|
+
*
|
|
24998
|
+
* @param params - Positions, current sizes, and complete held-position list.
|
|
24999
|
+
* @returns A dispatch intent ready for simulation or submission.
|
|
25000
|
+
*/
|
|
25001
|
+
function buildProtectedSettleDispatch(params) {
|
|
25002
|
+
return buildProtectedSettlePlan(params).dispatch;
|
|
25003
|
+
}
|
|
25004
|
+
|
|
25005
|
+
//#endregion
|
|
25006
|
+
//#region src/panoptic/v2/simulations/simulateSettlePremiumFrom.ts
|
|
25007
|
+
/** Soft-failure revert markers for settle premium (target-state issues, not caller errors). */
|
|
25008
|
+
const SOFT_FAILURES = [
|
|
25009
|
+
{
|
|
25010
|
+
marker: "AccountInsolvent",
|
|
25011
|
+
reason: "Target account is insolvent; premium cannot be settled"
|
|
25012
|
+
},
|
|
25013
|
+
{
|
|
25014
|
+
marker: "PositionNotOwned",
|
|
25015
|
+
reason: "Target account no longer owns the position"
|
|
25016
|
+
},
|
|
25017
|
+
{
|
|
25018
|
+
marker: "StaleOracle",
|
|
25019
|
+
reason: "Oracle price is stale; settlement temporarily unavailable"
|
|
25020
|
+
},
|
|
25021
|
+
{
|
|
25022
|
+
marker: "InputListFail",
|
|
25023
|
+
reason: "Position list is stale (target positions changed)"
|
|
25024
|
+
}
|
|
25025
|
+
];
|
|
25026
|
+
/**
|
|
25027
|
+
* Simulate settling another account's accumulated long premium via `dispatchFrom`
|
|
25028
|
+
* (equal-length `positionIdListTo`/`positionIdListToFinal` selects the settle mode).
|
|
25029
|
+
*
|
|
25030
|
+
* The measured token flow is the CALLER's collateral delta — i.e. the premium
|
|
25031
|
+
* the caller receives from the settlement (for chunks they sold).
|
|
25032
|
+
*
|
|
25033
|
+
* @param params - Simulation parameters
|
|
25034
|
+
* @returns Simulation result with settled premium data or error
|
|
25035
|
+
*/
|
|
25036
|
+
async function simulateSettlePremiumFrom(params) {
|
|
25037
|
+
const { client, poolAddress, account, user, positionIdListFrom, positionIdList, tokenId, blockNumber } = params;
|
|
25038
|
+
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
25039
|
+
const metaPromise = getBlockMeta({
|
|
25040
|
+
client,
|
|
25041
|
+
blockNumber: targetBlockNumber
|
|
25042
|
+
});
|
|
25043
|
+
const emptyTokenFlow = {
|
|
25044
|
+
delta0: 0n,
|
|
25045
|
+
delta1: 0n,
|
|
25046
|
+
balanceBefore0: 0n,
|
|
25047
|
+
balanceBefore1: 0n,
|
|
25048
|
+
balanceAfter0: 0n,
|
|
25049
|
+
balanceAfter1: 0n,
|
|
25050
|
+
tickBefore: null,
|
|
25051
|
+
tickAfter: null
|
|
25052
|
+
};
|
|
25053
|
+
const softFailure = (errorMessage) => {
|
|
25054
|
+
const match = SOFT_FAILURES.find(({ marker }) => errorMessage.includes(marker));
|
|
25055
|
+
return match ? {
|
|
25056
|
+
premium0: 0n,
|
|
25057
|
+
premium1: 0n,
|
|
25058
|
+
settled0: 0n,
|
|
25059
|
+
settled1: 0n,
|
|
25060
|
+
canSettle: false,
|
|
25061
|
+
reason: match.reason
|
|
25062
|
+
} : null;
|
|
25063
|
+
};
|
|
25064
|
+
try {
|
|
25065
|
+
const orderedList = tokenId !== void 0 ? orderListForSettle(positionIdList, tokenId) : positionIdList;
|
|
25066
|
+
const callData = encodeFunctionData({
|
|
25067
|
+
abi: panopticPoolV2Abi,
|
|
25068
|
+
functionName: "dispatchFrom",
|
|
25069
|
+
args: [
|
|
25070
|
+
positionIdListFrom,
|
|
25071
|
+
user,
|
|
25072
|
+
orderedList,
|
|
25073
|
+
orderedList,
|
|
25074
|
+
0n
|
|
25075
|
+
]
|
|
25076
|
+
});
|
|
25077
|
+
const availablePremiumCallData = encodeFunctionData({
|
|
25078
|
+
abi: panopticPoolV2Abi,
|
|
25079
|
+
functionName: "getFullPositionsData",
|
|
25080
|
+
args: [
|
|
25081
|
+
account,
|
|
25082
|
+
false,
|
|
25083
|
+
positionIdListFrom
|
|
25084
|
+
]
|
|
25085
|
+
});
|
|
25086
|
+
const buyerOwedCallData = encodeFunctionData({
|
|
25087
|
+
abi: panopticPoolV2Abi,
|
|
25088
|
+
functionName: "getFullPositionsData",
|
|
25089
|
+
args: [
|
|
25090
|
+
user,
|
|
25091
|
+
true,
|
|
25092
|
+
orderedList
|
|
25093
|
+
]
|
|
25094
|
+
});
|
|
25095
|
+
const flowResult = await simulateWithTokenFlow({
|
|
25096
|
+
client,
|
|
25097
|
+
poolAddress,
|
|
25098
|
+
user: account,
|
|
25099
|
+
callData,
|
|
25100
|
+
blockNumber: targetBlockNumber,
|
|
25101
|
+
preCallData: [availablePremiumCallData, buyerOwedCallData],
|
|
25102
|
+
postCallData: [availablePremiumCallData, buyerOwedCallData]
|
|
25103
|
+
});
|
|
25104
|
+
if (!flowResult.success || !flowResult.tokenFlow) {
|
|
25105
|
+
const errorMessage = flowResult.error || "Simulation failed";
|
|
25106
|
+
const soft = softFailure(errorMessage);
|
|
25107
|
+
if (soft) {
|
|
25108
|
+
const _meta$1 = await metaPromise;
|
|
25109
|
+
return {
|
|
25110
|
+
success: true,
|
|
25111
|
+
data: soft,
|
|
25112
|
+
gasEstimate: 0n,
|
|
25113
|
+
tokenFlow: emptyTokenFlow,
|
|
25114
|
+
_meta: _meta$1
|
|
25115
|
+
};
|
|
25116
|
+
}
|
|
25117
|
+
throw new PanopticError(errorMessage);
|
|
25118
|
+
}
|
|
25119
|
+
const _meta = await metaPromise;
|
|
25120
|
+
const tokenFlow = flowResult.tokenFlow;
|
|
25121
|
+
const decodePremia = (raw) => {
|
|
25122
|
+
const [shortPremiumPacked, longPremiumPacked] = decodeFunctionResult({
|
|
25123
|
+
abi: panopticPoolV2Abi,
|
|
25124
|
+
functionName: "getFullPositionsData",
|
|
25125
|
+
data: raw
|
|
25126
|
+
});
|
|
25127
|
+
const short = decodeLeftRightUnsigned(shortPremiumPacked);
|
|
25128
|
+
const long = decodeLeftRightUnsigned(longPremiumPacked);
|
|
25129
|
+
return {
|
|
25130
|
+
short0: short.right,
|
|
25131
|
+
short1: short.left,
|
|
25132
|
+
long0: long.right,
|
|
25133
|
+
long1: long.left
|
|
25134
|
+
};
|
|
25135
|
+
};
|
|
25136
|
+
let premium0 = 0n;
|
|
25137
|
+
let premium1 = 0n;
|
|
25138
|
+
const preRaw = flowResult.preCallResults?.[0];
|
|
25139
|
+
const postRaw = flowResult.postCallResults?.[0];
|
|
25140
|
+
if (preRaw !== void 0 && postRaw !== void 0) {
|
|
25141
|
+
const pre = decodePremia(preRaw);
|
|
25142
|
+
const post = decodePremia(postRaw);
|
|
25143
|
+
premium0 = post.short0 > pre.short0 ? post.short0 - pre.short0 : 0n;
|
|
25144
|
+
premium1 = post.short1 > pre.short1 ? post.short1 - pre.short1 : 0n;
|
|
25145
|
+
}
|
|
25146
|
+
let settled0 = 0n;
|
|
25147
|
+
let settled1 = 0n;
|
|
25148
|
+
const preBuyerRaw = flowResult.preCallResults?.[1];
|
|
25149
|
+
const postBuyerRaw = flowResult.postCallResults?.[1];
|
|
25150
|
+
if (preBuyerRaw !== void 0 && postBuyerRaw !== void 0) {
|
|
25151
|
+
const pre = decodePremia(preBuyerRaw);
|
|
25152
|
+
const post = decodePremia(postBuyerRaw);
|
|
25153
|
+
settled0 = pre.long0 > post.long0 ? pre.long0 - post.long0 : 0n;
|
|
25154
|
+
settled1 = pre.long1 > post.long1 ? pre.long1 - post.long1 : 0n;
|
|
25155
|
+
}
|
|
25156
|
+
const data = {
|
|
25157
|
+
premium0,
|
|
25158
|
+
premium1,
|
|
25159
|
+
settled0,
|
|
25160
|
+
settled1,
|
|
25161
|
+
canSettle: true
|
|
25162
|
+
};
|
|
25163
|
+
return {
|
|
25164
|
+
success: true,
|
|
25165
|
+
data,
|
|
25166
|
+
gasEstimate: flowResult.gasEstimate,
|
|
25167
|
+
tokenFlow,
|
|
25168
|
+
_meta
|
|
25169
|
+
};
|
|
25170
|
+
} catch (error) {
|
|
25171
|
+
const _meta = await metaPromise;
|
|
25172
|
+
const errorMessage = error instanceof Error ? error.message : "Simulation failed";
|
|
25173
|
+
const soft = softFailure(errorMessage);
|
|
25174
|
+
if (soft) return {
|
|
25175
|
+
success: true,
|
|
25176
|
+
data: soft,
|
|
25177
|
+
gasEstimate: 0n,
|
|
25178
|
+
tokenFlow: emptyTokenFlow,
|
|
25179
|
+
_meta
|
|
25180
|
+
};
|
|
25181
|
+
return {
|
|
25182
|
+
success: false,
|
|
25183
|
+
error: error instanceof PanopticError ? error : new PanopticError(errorMessage, error instanceof Error ? error : void 0),
|
|
25184
|
+
_meta
|
|
25185
|
+
};
|
|
25186
|
+
}
|
|
25187
|
+
}
|
|
25188
|
+
|
|
25189
|
+
//#endregion
|
|
25190
|
+
//#region src/panoptic/v2/simulations/simulateSettlePremiumBatch.ts
|
|
25191
|
+
/**
|
|
25192
|
+
* Simulate settling each target buyer's owed long premium, all at one block.
|
|
25193
|
+
*
|
|
25194
|
+
* Individual failures (insolvent buyer, stale list, …) are soft: the target
|
|
25195
|
+
* lands in the unsettleable partition instead of failing the batch. Only
|
|
25196
|
+
* unexpected errors reject.
|
|
25197
|
+
*
|
|
25198
|
+
* @param params - Simulation parameters
|
|
25199
|
+
* @returns Partitioned targets with per-target premium and totals
|
|
25200
|
+
*/
|
|
25201
|
+
async function simulateSettlePremiumBatch(params) {
|
|
25202
|
+
const { client, poolAddress, account, positionIdListFrom, targets, blockNumber } = params;
|
|
25203
|
+
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
25204
|
+
const metaPromise = getBlockMeta({
|
|
25205
|
+
client,
|
|
25206
|
+
blockNumber: targetBlockNumber
|
|
25207
|
+
});
|
|
25208
|
+
const simulations = await Promise.all(targets.map((target) => simulateSettlePremiumFrom({
|
|
25209
|
+
client,
|
|
25210
|
+
poolAddress,
|
|
25211
|
+
account,
|
|
25212
|
+
user: target.user,
|
|
25213
|
+
positionIdListFrom,
|
|
25214
|
+
positionIdList: target.positionIdList,
|
|
25215
|
+
tokenId: target.tokenId,
|
|
25216
|
+
blockNumber: targetBlockNumber
|
|
25217
|
+
})));
|
|
25218
|
+
const results = [];
|
|
25219
|
+
const settleable = [];
|
|
25220
|
+
let unsettleableCount = 0;
|
|
25221
|
+
let premium0 = 0n;
|
|
25222
|
+
let premium1 = 0n;
|
|
25223
|
+
simulations.forEach((sim, i) => {
|
|
25224
|
+
const simulation = sim.success ? sim.data : {
|
|
25225
|
+
premium0: 0n,
|
|
25226
|
+
premium1: 0n,
|
|
25227
|
+
settled0: 0n,
|
|
25228
|
+
settled1: 0n,
|
|
25229
|
+
canSettle: false,
|
|
25230
|
+
reason: sim.error.message
|
|
25231
|
+
};
|
|
25232
|
+
results.push({
|
|
25233
|
+
target: targets[i],
|
|
25234
|
+
simulation
|
|
25235
|
+
});
|
|
25236
|
+
if (simulation.canSettle) {
|
|
25237
|
+
settleable.push(targets[i]);
|
|
25238
|
+
premium0 += simulation.premium0;
|
|
25239
|
+
premium1 += simulation.premium1;
|
|
25240
|
+
} else unsettleableCount += 1;
|
|
25241
|
+
});
|
|
25242
|
+
const _meta = await metaPromise;
|
|
25243
|
+
return {
|
|
25244
|
+
results,
|
|
25245
|
+
settleable,
|
|
25246
|
+
unsettleableCount,
|
|
25247
|
+
premium0,
|
|
25248
|
+
premium1,
|
|
25249
|
+
_meta
|
|
25250
|
+
};
|
|
25251
|
+
}
|
|
25252
|
+
/**
|
|
25253
|
+
* Simulate a full settle sequence (all settles + optional close) as the one
|
|
25254
|
+
* multicall that `executeSettleSequence` submits, measuring the caller's
|
|
25255
|
+
* total token flow and gas.
|
|
25256
|
+
*
|
|
25257
|
+
* @param params - Simulation parameters
|
|
25258
|
+
* @returns Simulation result with the caller's net flow, or error
|
|
25259
|
+
*/
|
|
25260
|
+
async function simulateSettleSequence(params) {
|
|
25261
|
+
const { client, poolAddress, account, blockNumber } = params;
|
|
25262
|
+
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
25263
|
+
const metaPromise = getBlockMeta({
|
|
25264
|
+
client,
|
|
25265
|
+
blockNumber: targetBlockNumber
|
|
25266
|
+
});
|
|
25267
|
+
try {
|
|
25268
|
+
const calls = buildSettleSequenceCalls(params);
|
|
25269
|
+
const callData = encodeFunctionData({
|
|
25270
|
+
abi: panopticPoolV2Abi,
|
|
25271
|
+
functionName: "multicall",
|
|
25272
|
+
args: [calls]
|
|
25273
|
+
});
|
|
25274
|
+
const flowResult = await simulateWithTokenFlow({
|
|
25275
|
+
client,
|
|
25276
|
+
poolAddress,
|
|
25277
|
+
user: account,
|
|
25278
|
+
callData,
|
|
25279
|
+
blockNumber: targetBlockNumber
|
|
25280
|
+
});
|
|
25281
|
+
if (!flowResult.success || !flowResult.tokenFlow) throw new PanopticError(flowResult.error || "Simulation failed");
|
|
25282
|
+
const _meta = await metaPromise;
|
|
25283
|
+
const tokenFlow = flowResult.tokenFlow;
|
|
25284
|
+
return {
|
|
25285
|
+
success: true,
|
|
25286
|
+
data: {
|
|
25287
|
+
delta0: tokenFlow.delta0,
|
|
25288
|
+
delta1: tokenFlow.delta1
|
|
25289
|
+
},
|
|
25290
|
+
gasEstimate: flowResult.gasEstimate,
|
|
25291
|
+
tokenFlow,
|
|
25292
|
+
_meta
|
|
25293
|
+
};
|
|
25294
|
+
} catch (error) {
|
|
25295
|
+
const _meta = await metaPromise;
|
|
25296
|
+
const errorMessage = error instanceof Error ? error.message : "Simulation failed";
|
|
25297
|
+
return {
|
|
25298
|
+
success: false,
|
|
25299
|
+
error: error instanceof PanopticError ? error : new PanopticError(errorMessage, error instanceof Error ? error : void 0),
|
|
25300
|
+
_meta
|
|
25301
|
+
};
|
|
25302
|
+
}
|
|
25303
|
+
}
|
|
25304
|
+
|
|
25305
|
+
//#endregion
|
|
25306
|
+
//#region src/panoptic/v2/simulations/simulateSettle.ts
|
|
25307
|
+
const BIT_MASK_128 = (1n << 128n) - 1n;
|
|
25308
|
+
const multicallAbi = [{
|
|
25309
|
+
type: "function",
|
|
25310
|
+
name: "multicall",
|
|
25311
|
+
inputs: [{
|
|
25312
|
+
name: "data",
|
|
25313
|
+
type: "bytes[]"
|
|
25314
|
+
}],
|
|
25315
|
+
outputs: [{
|
|
25316
|
+
name: "results",
|
|
25317
|
+
type: "bytes[]"
|
|
25318
|
+
}],
|
|
25319
|
+
stateMutability: "nonpayable"
|
|
25320
|
+
}];
|
|
25321
|
+
function encodeDispatch(plan) {
|
|
25322
|
+
const dispatch$1 = plan.dispatch;
|
|
25323
|
+
return encodeFunctionData({
|
|
25324
|
+
abi: panopticPoolV2Abi,
|
|
25325
|
+
functionName: "dispatch",
|
|
25326
|
+
args: [
|
|
25327
|
+
dispatch$1.positionIdList,
|
|
25328
|
+
dispatch$1.finalPositionIdList,
|
|
25329
|
+
dispatch$1.positionSizes,
|
|
25330
|
+
dispatch$1.tickAndSpreadLimits.map((limits) => [
|
|
25331
|
+
Number(limits[0]),
|
|
25332
|
+
Number(limits[1]),
|
|
25333
|
+
Number(limits[2])
|
|
25334
|
+
]),
|
|
25335
|
+
dispatch$1.usePremiaAsCollateral,
|
|
25336
|
+
dispatch$1.builderCode
|
|
25337
|
+
]
|
|
25338
|
+
});
|
|
25339
|
+
}
|
|
25340
|
+
function decodeShortPremium(data) {
|
|
25341
|
+
const packed = decodeFunctionResult({
|
|
25342
|
+
abi: panopticPoolV2Abi,
|
|
25343
|
+
functionName: "getFullPositionsData",
|
|
25344
|
+
data
|
|
25345
|
+
})[0];
|
|
25346
|
+
return [packed & BIT_MASK_128, packed >> 128n];
|
|
25347
|
+
}
|
|
25348
|
+
async function remainingForfeitAfterProtection(params) {
|
|
25349
|
+
const { client, poolAddress, account, positionIdList, targets, plan, blockNumber, initial } = params;
|
|
25350
|
+
if (targets.length === 0 && plan.collectionDispatch === void 0) return [...initial];
|
|
25351
|
+
const protectionCalls = buildSettleSequenceCalls({
|
|
25352
|
+
positionIdListFrom: params.finalPositionIdList,
|
|
25353
|
+
targets,
|
|
25354
|
+
dispatch: plan.collectionDispatch
|
|
25355
|
+
});
|
|
25356
|
+
const availableCall = encodeFunctionData({
|
|
25357
|
+
abi: panopticPoolV2Abi,
|
|
25358
|
+
functionName: "getFullPositionsData",
|
|
25359
|
+
args: [
|
|
25360
|
+
account,
|
|
25361
|
+
false,
|
|
25362
|
+
positionIdList
|
|
25363
|
+
]
|
|
25364
|
+
});
|
|
25365
|
+
const totalCall = encodeFunctionData({
|
|
25366
|
+
abi: panopticPoolV2Abi,
|
|
25367
|
+
functionName: "getFullPositionsData",
|
|
25368
|
+
args: [
|
|
25369
|
+
account,
|
|
25370
|
+
true,
|
|
25371
|
+
positionIdList
|
|
25372
|
+
]
|
|
25373
|
+
});
|
|
25374
|
+
const { result } = await client.simulateContract({
|
|
25375
|
+
address: poolAddress,
|
|
25376
|
+
abi: multicallAbi,
|
|
25377
|
+
functionName: "multicall",
|
|
25378
|
+
args: [[
|
|
25379
|
+
...protectionCalls,
|
|
25380
|
+
availableCall,
|
|
25381
|
+
totalCall
|
|
25382
|
+
]],
|
|
25383
|
+
account,
|
|
25384
|
+
blockNumber
|
|
25385
|
+
});
|
|
25386
|
+
const available = decodeShortPremium(result[result.length - 2]);
|
|
25387
|
+
const total = decodeShortPremium(result[result.length - 1]);
|
|
25388
|
+
return [total[0] > available[0] ? total[0] - available[0] : 0n, total[1] > available[1] ? total[1] - available[1] : 0n];
|
|
25389
|
+
}
|
|
25390
|
+
async function simulateSettle(params) {
|
|
25391
|
+
const { client, poolAddress, account, positionIdList, finalPositionIdList = positionIdList, positionSizes: providedSizes, targets = [], usePremiaAsCollateral = false, builderCode = 0n, allowForfeit = false, blockNumber } = params;
|
|
25392
|
+
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
25393
|
+
const metaPromise = getBlockMeta({
|
|
25394
|
+
client,
|
|
25395
|
+
blockNumber: targetBlockNumber
|
|
25396
|
+
});
|
|
25397
|
+
try {
|
|
25398
|
+
if (providedSizes && providedSizes.length !== positionIdList.length) throw new PanopticError("simulateSettle: positionSizes length must match positionIdList");
|
|
25399
|
+
const positionSizes = providedSizes ?? await getCurrentPositionSizes({
|
|
25400
|
+
client,
|
|
25401
|
+
poolAddress,
|
|
25402
|
+
account,
|
|
25403
|
+
positionIdList,
|
|
25404
|
+
blockNumber: targetBlockNumber
|
|
25405
|
+
});
|
|
25406
|
+
const plan = buildProtectedSettlePlan({
|
|
25407
|
+
positionIdList,
|
|
25408
|
+
finalPositionIdList,
|
|
25409
|
+
positionSizes,
|
|
25410
|
+
usePremiaAsCollateral,
|
|
25411
|
+
builderCode
|
|
25412
|
+
});
|
|
25413
|
+
const initialForfeit = await getForfeitablePremium({
|
|
25414
|
+
client,
|
|
25415
|
+
poolAddress,
|
|
25416
|
+
account,
|
|
25417
|
+
tokenIds: positionIdList,
|
|
25418
|
+
blockNumber: targetBlockNumber
|
|
25419
|
+
});
|
|
25420
|
+
const initial = [initialForfeit.forfeit0, initialForfeit.forfeit1];
|
|
25421
|
+
if (targets.length > 0) {
|
|
25422
|
+
const buyers = await simulateSettlePremiumBatch({
|
|
25423
|
+
client,
|
|
25424
|
+
poolAddress,
|
|
25425
|
+
account,
|
|
25426
|
+
positionIdListFrom: finalPositionIdList,
|
|
25427
|
+
targets,
|
|
25428
|
+
blockNumber: targetBlockNumber
|
|
25429
|
+
});
|
|
25430
|
+
if (buyers.unsettleableCount > 0) throw new UnsafePremiumSettlementError(initial, buyers.unsettleableCount);
|
|
25431
|
+
}
|
|
25432
|
+
const remainingForfeit = await remainingForfeitAfterProtection({
|
|
25433
|
+
client,
|
|
25434
|
+
poolAddress,
|
|
25435
|
+
account,
|
|
25436
|
+
positionIdList,
|
|
25437
|
+
finalPositionIdList,
|
|
25438
|
+
targets,
|
|
25439
|
+
plan,
|
|
25440
|
+
blockNumber: targetBlockNumber,
|
|
25441
|
+
initial
|
|
25442
|
+
});
|
|
25443
|
+
if ((remainingForfeit[0] > 0n || remainingForfeit[1] > 0n) && !allowForfeit) throw new UnsafePremiumSettlementError(remainingForfeit, 0);
|
|
25444
|
+
const callData = targets.length === 0 ? encodeDispatch(plan) : encodeFunctionData({
|
|
25445
|
+
abi: panopticPoolV2Abi,
|
|
25446
|
+
functionName: "multicall",
|
|
25447
|
+
args: [buildSettleSequenceCalls({
|
|
25448
|
+
positionIdListFrom: finalPositionIdList,
|
|
25449
|
+
targets,
|
|
25450
|
+
dispatch: plan.dispatch
|
|
25451
|
+
})]
|
|
25452
|
+
});
|
|
25453
|
+
const flowResult = await simulateWithTokenFlow({
|
|
25454
|
+
client,
|
|
25455
|
+
poolAddress,
|
|
25456
|
+
user: account,
|
|
25457
|
+
callData,
|
|
25458
|
+
blockNumber: targetBlockNumber
|
|
25459
|
+
});
|
|
25460
|
+
if (!flowResult.success || !flowResult.tokenFlow) throw flowResult.rawError ?? new PanopticError(flowResult.error || "Simulation failed");
|
|
25461
|
+
const tokenFlow = flowResult.tokenFlow;
|
|
25462
|
+
return {
|
|
25463
|
+
success: true,
|
|
25464
|
+
data: {
|
|
25465
|
+
premiaReceived0: tokenFlow.delta0,
|
|
25466
|
+
premiaReceived1: tokenFlow.delta1,
|
|
25467
|
+
postCollateral0: tokenFlow.balanceAfter0,
|
|
25468
|
+
postCollateral1: tokenFlow.balanceAfter1,
|
|
25469
|
+
premiumProtected: [initial[0] - remainingForfeit[0], initial[1] - remainingForfeit[1]],
|
|
25470
|
+
remainingForfeit,
|
|
25471
|
+
usesPoke: plan.pokingTokenIds.length > 0,
|
|
25472
|
+
settledBuyerCount: targets.length
|
|
25473
|
+
},
|
|
25474
|
+
gasEstimate: flowResult.gasEstimate,
|
|
25475
|
+
tokenFlow,
|
|
25476
|
+
_meta: await metaPromise
|
|
25477
|
+
};
|
|
25478
|
+
} catch (error) {
|
|
25479
|
+
return {
|
|
25480
|
+
success: false,
|
|
25481
|
+
error: error instanceof PanopticError ? error : new PanopticError(error instanceof Error ? error.message : "Simulation failed", error instanceof Error ? error : void 0),
|
|
25482
|
+
_meta: await metaPromise
|
|
25483
|
+
};
|
|
25484
|
+
}
|
|
25485
|
+
}
|
|
25486
|
+
|
|
24852
25487
|
//#endregion
|
|
24853
25488
|
//#region src/panoptic/v2/writes/settle.ts
|
|
24854
25489
|
/**
|
|
@@ -24873,7 +25508,7 @@ async function executeSettleSequenceAndWait(params) {
|
|
|
24873
25508
|
* ```
|
|
24874
25509
|
*/
|
|
24875
25510
|
async function settleAccumulatedPremia(params) {
|
|
24876
|
-
const { client, walletClient, account, poolAddress, positionIdList, finalPositionIdList, positionSizes: providedSizes, usePremiaAsCollateral = false, builderCode = 0n, txOverrides } = params;
|
|
25511
|
+
const { client, walletClient, account, poolAddress, positionIdList, finalPositionIdList, positionSizes: providedSizes, targets = [], skipPreflight = false, allowForfeit = false, usePremiaAsCollateral = false, builderCode = 0n, txOverrides } = params;
|
|
24877
25512
|
if (providedSizes && providedSizes.length !== positionIdList.length) throw new PanopticError("settleAccumulatedPremia: positionSizes length must match positionIdList");
|
|
24878
25513
|
const positionSizes = providedSizes ?? await getCurrentPositionSizes({
|
|
24879
25514
|
client,
|
|
@@ -24881,11 +25516,39 @@ async function settleAccumulatedPremia(params) {
|
|
|
24881
25516
|
account,
|
|
24882
25517
|
positionIdList
|
|
24883
25518
|
});
|
|
24884
|
-
const
|
|
24885
|
-
|
|
24886
|
-
|
|
24887
|
-
|
|
24888
|
-
|
|
25519
|
+
const heldPositions = finalPositionIdList ?? positionIdList;
|
|
25520
|
+
if (!skipPreflight) {
|
|
25521
|
+
const simulation = await simulateSettle({
|
|
25522
|
+
client,
|
|
25523
|
+
poolAddress,
|
|
25524
|
+
account,
|
|
25525
|
+
positionIdList,
|
|
25526
|
+
finalPositionIdList: heldPositions,
|
|
25527
|
+
positionSizes,
|
|
25528
|
+
targets,
|
|
25529
|
+
usePremiaAsCollateral,
|
|
25530
|
+
builderCode,
|
|
25531
|
+
allowForfeit
|
|
25532
|
+
});
|
|
25533
|
+
if (!simulation.success) throw simulation.error;
|
|
25534
|
+
}
|
|
25535
|
+
const { dispatch: dispatch$1 } = buildProtectedSettlePlan({
|
|
25536
|
+
positionIdList,
|
|
25537
|
+
finalPositionIdList: heldPositions,
|
|
25538
|
+
positionSizes,
|
|
25539
|
+
usePremiaAsCollateral,
|
|
25540
|
+
builderCode
|
|
25541
|
+
});
|
|
25542
|
+
if (targets.length > 0) return executeSettleSequence({
|
|
25543
|
+
client,
|
|
25544
|
+
walletClient,
|
|
25545
|
+
account,
|
|
25546
|
+
poolAddress,
|
|
25547
|
+
positionIdListFrom: heldPositions,
|
|
25548
|
+
targets,
|
|
25549
|
+
dispatch: dispatch$1,
|
|
25550
|
+
txOverrides
|
|
25551
|
+
});
|
|
24889
25552
|
return submitWrite({
|
|
24890
25553
|
client,
|
|
24891
25554
|
walletClient,
|
|
@@ -24894,16 +25557,16 @@ async function settleAccumulatedPremia(params) {
|
|
|
24894
25557
|
abi: panopticPoolV2Abi,
|
|
24895
25558
|
functionName: "dispatch",
|
|
24896
25559
|
args: [
|
|
24897
|
-
positionIdList,
|
|
24898
|
-
finalPositionIdList
|
|
24899
|
-
positionSizes
|
|
24900
|
-
tickAndSpreadLimits.map((t) => [
|
|
25560
|
+
dispatch$1.positionIdList,
|
|
25561
|
+
dispatch$1.finalPositionIdList,
|
|
25562
|
+
dispatch$1.positionSizes,
|
|
25563
|
+
dispatch$1.tickAndSpreadLimits.map((t) => [
|
|
24901
25564
|
Number(t[0]),
|
|
24902
25565
|
Number(t[1]),
|
|
24903
25566
|
Number(t[2])
|
|
24904
25567
|
]),
|
|
24905
|
-
usePremiaAsCollateral,
|
|
24906
|
-
builderCode
|
|
25568
|
+
dispatch$1.usePremiaAsCollateral,
|
|
25569
|
+
dispatch$1.builderCode
|
|
24907
25570
|
],
|
|
24908
25571
|
txOverrides
|
|
24909
25572
|
});
|
|
@@ -26445,472 +27108,6 @@ async function simulateLiquidate(params) {
|
|
|
26445
27108
|
}
|
|
26446
27109
|
}
|
|
26447
27110
|
|
|
26448
|
-
//#endregion
|
|
26449
|
-
//#region src/panoptic/v2/simulations/simulateSettle.ts
|
|
26450
|
-
/** BIT_MASK_128 = (1n << 128n) - 1n */
|
|
26451
|
-
const BIT_MASK_128 = (1n << 128n) - 1n;
|
|
26452
|
-
/**
|
|
26453
|
-
* PanopticPool multicall ABI (inherited from Uniswap).
|
|
26454
|
-
*/
|
|
26455
|
-
const multicallAbi = [{
|
|
26456
|
-
type: "function",
|
|
26457
|
-
name: "multicall",
|
|
26458
|
-
inputs: [{
|
|
26459
|
-
name: "data",
|
|
26460
|
-
type: "bytes[]"
|
|
26461
|
-
}],
|
|
26462
|
-
outputs: [{
|
|
26463
|
-
name: "results",
|
|
26464
|
-
type: "bytes[]"
|
|
26465
|
-
}],
|
|
26466
|
-
stateMutability: "nonpayable"
|
|
26467
|
-
}];
|
|
26468
|
-
/**
|
|
26469
|
-
* Simulate premium settlement.
|
|
26470
|
-
*
|
|
26471
|
-
* When `tokenId` is provided, the simulation also computes forfeit amounts
|
|
26472
|
-
* by chaining the dispatch with `getFullPositionsData` reads
|
|
26473
|
-
* in a single multicall.
|
|
26474
|
-
*
|
|
26475
|
-
* @param params - Simulation parameters
|
|
26476
|
-
* @returns Simulation result with settlement data or error
|
|
26477
|
-
*/
|
|
26478
|
-
async function simulateSettle(params) {
|
|
26479
|
-
const { client, poolAddress, account, positionIdList, finalPositionIdList, positionSizes: providedSizes, tokenId, blockNumber } = params;
|
|
26480
|
-
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
26481
|
-
const metaPromise = getBlockMeta({
|
|
26482
|
-
client,
|
|
26483
|
-
blockNumber: targetBlockNumber
|
|
26484
|
-
});
|
|
26485
|
-
try {
|
|
26486
|
-
if (providedSizes && providedSizes.length !== positionIdList.length) throw new PanopticError("simulateSettle: positionSizes length must match positionIdList");
|
|
26487
|
-
const positionSizes = providedSizes ?? await getCurrentPositionSizes({
|
|
26488
|
-
client,
|
|
26489
|
-
poolAddress,
|
|
26490
|
-
account,
|
|
26491
|
-
positionIdList,
|
|
26492
|
-
blockNumber: targetBlockNumber
|
|
26493
|
-
});
|
|
26494
|
-
const tickAndSpreadLimits = positionIdList.map(() => [
|
|
26495
|
-
-887272n,
|
|
26496
|
-
887272n,
|
|
26497
|
-
0n
|
|
26498
|
-
]);
|
|
26499
|
-
const callData = encodeFunctionData({
|
|
26500
|
-
abi: panopticPoolV2Abi,
|
|
26501
|
-
functionName: "dispatch",
|
|
26502
|
-
args: [
|
|
26503
|
-
positionIdList,
|
|
26504
|
-
finalPositionIdList ?? positionIdList,
|
|
26505
|
-
positionSizes.map((s) => BigInt(s)),
|
|
26506
|
-
tickAndSpreadLimits.map((t) => [
|
|
26507
|
-
Number(t[0]),
|
|
26508
|
-
Number(t[1]),
|
|
26509
|
-
Number(t[2])
|
|
26510
|
-
]),
|
|
26511
|
-
false,
|
|
26512
|
-
0n
|
|
26513
|
-
]
|
|
26514
|
-
});
|
|
26515
|
-
const flowResult = await simulateWithTokenFlow({
|
|
26516
|
-
client,
|
|
26517
|
-
poolAddress,
|
|
26518
|
-
user: account,
|
|
26519
|
-
callData,
|
|
26520
|
-
blockNumber: targetBlockNumber
|
|
26521
|
-
});
|
|
26522
|
-
if (!flowResult.success || !flowResult.tokenFlow) throw flowResult.rawError ?? new PanopticError(flowResult.error || "Token flow simulation failed");
|
|
26523
|
-
const tokenFlow = flowResult.tokenFlow;
|
|
26524
|
-
let forfeitAmounts;
|
|
26525
|
-
if (tokenId !== void 0) forfeitAmounts = await computeForfeitAmounts({
|
|
26526
|
-
client,
|
|
26527
|
-
poolAddress,
|
|
26528
|
-
account,
|
|
26529
|
-
positionIdList,
|
|
26530
|
-
tokenId,
|
|
26531
|
-
dispatchCallData: callData,
|
|
26532
|
-
blockNumber: targetBlockNumber
|
|
26533
|
-
});
|
|
26534
|
-
const _meta = await metaPromise;
|
|
26535
|
-
const data = {
|
|
26536
|
-
premiaReceived0: tokenFlow.delta0,
|
|
26537
|
-
premiaReceived1: tokenFlow.delta1,
|
|
26538
|
-
postCollateral0: tokenFlow.balanceAfter0,
|
|
26539
|
-
postCollateral1: tokenFlow.balanceAfter1,
|
|
26540
|
-
forfeitAmounts
|
|
26541
|
-
};
|
|
26542
|
-
return {
|
|
26543
|
-
success: true,
|
|
26544
|
-
data,
|
|
26545
|
-
gasEstimate: flowResult.gasEstimate,
|
|
26546
|
-
tokenFlow,
|
|
26547
|
-
_meta
|
|
26548
|
-
};
|
|
26549
|
-
} catch (error) {
|
|
26550
|
-
const _meta = await metaPromise;
|
|
26551
|
-
return {
|
|
26552
|
-
success: false,
|
|
26553
|
-
error: error instanceof PanopticError ? error : new PanopticError(error instanceof Error ? error.message : "Simulation failed", error instanceof Error ? error : void 0),
|
|
26554
|
-
_meta
|
|
26555
|
-
};
|
|
26556
|
-
}
|
|
26557
|
-
}
|
|
26558
|
-
/**
|
|
26559
|
-
* Compute forfeit amounts by chaining dispatch + getFullPositionsData
|
|
26560
|
-
* in a single PanopticPool.multicall.
|
|
26561
|
-
*/
|
|
26562
|
-
async function computeForfeitAmounts(params) {
|
|
26563
|
-
const { client, poolAddress, account, tokenId, dispatchCallData, blockNumber } = params;
|
|
26564
|
-
const feesCallAvailable = encodeFunctionData({
|
|
26565
|
-
abi: panopticPoolV2Abi,
|
|
26566
|
-
functionName: "getFullPositionsData",
|
|
26567
|
-
args: [
|
|
26568
|
-
account,
|
|
26569
|
-
false,
|
|
26570
|
-
[tokenId]
|
|
26571
|
-
]
|
|
26572
|
-
});
|
|
26573
|
-
const feesCallTotal = encodeFunctionData({
|
|
26574
|
-
abi: panopticPoolV2Abi,
|
|
26575
|
-
functionName: "getFullPositionsData",
|
|
26576
|
-
args: [
|
|
26577
|
-
account,
|
|
26578
|
-
true,
|
|
26579
|
-
[tokenId]
|
|
26580
|
-
]
|
|
26581
|
-
});
|
|
26582
|
-
try {
|
|
26583
|
-
const { result } = await client.simulateContract({
|
|
26584
|
-
address: poolAddress,
|
|
26585
|
-
abi: multicallAbi,
|
|
26586
|
-
functionName: "multicall",
|
|
26587
|
-
args: [[
|
|
26588
|
-
dispatchCallData,
|
|
26589
|
-
feesCallAvailable,
|
|
26590
|
-
feesCallTotal
|
|
26591
|
-
]],
|
|
26592
|
-
account,
|
|
26593
|
-
blockNumber
|
|
26594
|
-
});
|
|
26595
|
-
const decodeFeesResult = (data) => {
|
|
26596
|
-
return decodeFunctionResult({
|
|
26597
|
-
abi: panopticPoolV2Abi,
|
|
26598
|
-
functionName: "getFullPositionsData",
|
|
26599
|
-
data
|
|
26600
|
-
})[0];
|
|
26601
|
-
};
|
|
26602
|
-
const availablePremium = decodeFeesResult(result[1]);
|
|
26603
|
-
const totalPremium = decodeFeesResult(result[2]);
|
|
26604
|
-
const available0 = availablePremium & BIT_MASK_128;
|
|
26605
|
-
const available1 = availablePremium >> 128n;
|
|
26606
|
-
const total0 = totalPremium & BIT_MASK_128;
|
|
26607
|
-
const total1 = totalPremium >> 128n;
|
|
26608
|
-
return [total0 - available0, total1 - available1];
|
|
26609
|
-
} catch (error) {
|
|
26610
|
-
throw new PanopticError("Forfeit amount computation failed", error instanceof Error ? error : void 0);
|
|
26611
|
-
}
|
|
26612
|
-
}
|
|
26613
|
-
|
|
26614
|
-
//#endregion
|
|
26615
|
-
//#region src/panoptic/v2/simulations/simulateSettlePremiumFrom.ts
|
|
26616
|
-
/** Soft-failure revert markers for settle premium (target-state issues, not caller errors). */
|
|
26617
|
-
const SOFT_FAILURES = [
|
|
26618
|
-
{
|
|
26619
|
-
marker: "AccountInsolvent",
|
|
26620
|
-
reason: "Target account is insolvent; premium cannot be settled"
|
|
26621
|
-
},
|
|
26622
|
-
{
|
|
26623
|
-
marker: "PositionNotOwned",
|
|
26624
|
-
reason: "Target account no longer owns the position"
|
|
26625
|
-
},
|
|
26626
|
-
{
|
|
26627
|
-
marker: "StaleOracle",
|
|
26628
|
-
reason: "Oracle price is stale; settlement temporarily unavailable"
|
|
26629
|
-
},
|
|
26630
|
-
{
|
|
26631
|
-
marker: "InputListFail",
|
|
26632
|
-
reason: "Position list is stale (target positions changed)"
|
|
26633
|
-
}
|
|
26634
|
-
];
|
|
26635
|
-
/**
|
|
26636
|
-
* Simulate settling another account's accumulated long premium via `dispatchFrom`
|
|
26637
|
-
* (equal-length `positionIdListTo`/`positionIdListToFinal` selects the settle mode).
|
|
26638
|
-
*
|
|
26639
|
-
* The measured token flow is the CALLER's collateral delta — i.e. the premium
|
|
26640
|
-
* the caller receives from the settlement (for chunks they sold).
|
|
26641
|
-
*
|
|
26642
|
-
* @param params - Simulation parameters
|
|
26643
|
-
* @returns Simulation result with settled premium data or error
|
|
26644
|
-
*/
|
|
26645
|
-
async function simulateSettlePremiumFrom(params) {
|
|
26646
|
-
const { client, poolAddress, account, user, positionIdListFrom, positionIdList, tokenId, blockNumber } = params;
|
|
26647
|
-
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
26648
|
-
const metaPromise = getBlockMeta({
|
|
26649
|
-
client,
|
|
26650
|
-
blockNumber: targetBlockNumber
|
|
26651
|
-
});
|
|
26652
|
-
const emptyTokenFlow = {
|
|
26653
|
-
delta0: 0n,
|
|
26654
|
-
delta1: 0n,
|
|
26655
|
-
balanceBefore0: 0n,
|
|
26656
|
-
balanceBefore1: 0n,
|
|
26657
|
-
balanceAfter0: 0n,
|
|
26658
|
-
balanceAfter1: 0n,
|
|
26659
|
-
tickBefore: null,
|
|
26660
|
-
tickAfter: null
|
|
26661
|
-
};
|
|
26662
|
-
const softFailure = (errorMessage) => {
|
|
26663
|
-
const match = SOFT_FAILURES.find(({ marker }) => errorMessage.includes(marker));
|
|
26664
|
-
return match ? {
|
|
26665
|
-
premium0: 0n,
|
|
26666
|
-
premium1: 0n,
|
|
26667
|
-
settled0: 0n,
|
|
26668
|
-
settled1: 0n,
|
|
26669
|
-
canSettle: false,
|
|
26670
|
-
reason: match.reason
|
|
26671
|
-
} : null;
|
|
26672
|
-
};
|
|
26673
|
-
try {
|
|
26674
|
-
const orderedList = tokenId !== void 0 ? orderListForSettle(positionIdList, tokenId) : positionIdList;
|
|
26675
|
-
const callData = encodeFunctionData({
|
|
26676
|
-
abi: panopticPoolV2Abi,
|
|
26677
|
-
functionName: "dispatchFrom",
|
|
26678
|
-
args: [
|
|
26679
|
-
positionIdListFrom,
|
|
26680
|
-
user,
|
|
26681
|
-
orderedList,
|
|
26682
|
-
orderedList,
|
|
26683
|
-
0n
|
|
26684
|
-
]
|
|
26685
|
-
});
|
|
26686
|
-
const availablePremiumCallData = encodeFunctionData({
|
|
26687
|
-
abi: panopticPoolV2Abi,
|
|
26688
|
-
functionName: "getFullPositionsData",
|
|
26689
|
-
args: [
|
|
26690
|
-
account,
|
|
26691
|
-
false,
|
|
26692
|
-
positionIdListFrom
|
|
26693
|
-
]
|
|
26694
|
-
});
|
|
26695
|
-
const buyerOwedCallData = encodeFunctionData({
|
|
26696
|
-
abi: panopticPoolV2Abi,
|
|
26697
|
-
functionName: "getFullPositionsData",
|
|
26698
|
-
args: [
|
|
26699
|
-
user,
|
|
26700
|
-
true,
|
|
26701
|
-
orderedList
|
|
26702
|
-
]
|
|
26703
|
-
});
|
|
26704
|
-
const flowResult = await simulateWithTokenFlow({
|
|
26705
|
-
client,
|
|
26706
|
-
poolAddress,
|
|
26707
|
-
user: account,
|
|
26708
|
-
callData,
|
|
26709
|
-
blockNumber: targetBlockNumber,
|
|
26710
|
-
preCallData: [availablePremiumCallData, buyerOwedCallData],
|
|
26711
|
-
postCallData: [availablePremiumCallData, buyerOwedCallData]
|
|
26712
|
-
});
|
|
26713
|
-
if (!flowResult.success || !flowResult.tokenFlow) {
|
|
26714
|
-
const errorMessage = flowResult.error || "Simulation failed";
|
|
26715
|
-
const soft = softFailure(errorMessage);
|
|
26716
|
-
if (soft) {
|
|
26717
|
-
const _meta$1 = await metaPromise;
|
|
26718
|
-
return {
|
|
26719
|
-
success: true,
|
|
26720
|
-
data: soft,
|
|
26721
|
-
gasEstimate: 0n,
|
|
26722
|
-
tokenFlow: emptyTokenFlow,
|
|
26723
|
-
_meta: _meta$1
|
|
26724
|
-
};
|
|
26725
|
-
}
|
|
26726
|
-
throw new PanopticError(errorMessage);
|
|
26727
|
-
}
|
|
26728
|
-
const _meta = await metaPromise;
|
|
26729
|
-
const tokenFlow = flowResult.tokenFlow;
|
|
26730
|
-
const decodePremia = (raw) => {
|
|
26731
|
-
const [shortPremiumPacked, longPremiumPacked] = decodeFunctionResult({
|
|
26732
|
-
abi: panopticPoolV2Abi,
|
|
26733
|
-
functionName: "getFullPositionsData",
|
|
26734
|
-
data: raw
|
|
26735
|
-
});
|
|
26736
|
-
const short = decodeLeftRightUnsigned(shortPremiumPacked);
|
|
26737
|
-
const long = decodeLeftRightUnsigned(longPremiumPacked);
|
|
26738
|
-
return {
|
|
26739
|
-
short0: short.right,
|
|
26740
|
-
short1: short.left,
|
|
26741
|
-
long0: long.right,
|
|
26742
|
-
long1: long.left
|
|
26743
|
-
};
|
|
26744
|
-
};
|
|
26745
|
-
let premium0 = 0n;
|
|
26746
|
-
let premium1 = 0n;
|
|
26747
|
-
const preRaw = flowResult.preCallResults?.[0];
|
|
26748
|
-
const postRaw = flowResult.postCallResults?.[0];
|
|
26749
|
-
if (preRaw !== void 0 && postRaw !== void 0) {
|
|
26750
|
-
const pre = decodePremia(preRaw);
|
|
26751
|
-
const post = decodePremia(postRaw);
|
|
26752
|
-
premium0 = post.short0 > pre.short0 ? post.short0 - pre.short0 : 0n;
|
|
26753
|
-
premium1 = post.short1 > pre.short1 ? post.short1 - pre.short1 : 0n;
|
|
26754
|
-
}
|
|
26755
|
-
let settled0 = 0n;
|
|
26756
|
-
let settled1 = 0n;
|
|
26757
|
-
const preBuyerRaw = flowResult.preCallResults?.[1];
|
|
26758
|
-
const postBuyerRaw = flowResult.postCallResults?.[1];
|
|
26759
|
-
if (preBuyerRaw !== void 0 && postBuyerRaw !== void 0) {
|
|
26760
|
-
const pre = decodePremia(preBuyerRaw);
|
|
26761
|
-
const post = decodePremia(postBuyerRaw);
|
|
26762
|
-
settled0 = pre.long0 > post.long0 ? pre.long0 - post.long0 : 0n;
|
|
26763
|
-
settled1 = pre.long1 > post.long1 ? pre.long1 - post.long1 : 0n;
|
|
26764
|
-
}
|
|
26765
|
-
const data = {
|
|
26766
|
-
premium0,
|
|
26767
|
-
premium1,
|
|
26768
|
-
settled0,
|
|
26769
|
-
settled1,
|
|
26770
|
-
canSettle: true
|
|
26771
|
-
};
|
|
26772
|
-
return {
|
|
26773
|
-
success: true,
|
|
26774
|
-
data,
|
|
26775
|
-
gasEstimate: flowResult.gasEstimate,
|
|
26776
|
-
tokenFlow,
|
|
26777
|
-
_meta
|
|
26778
|
-
};
|
|
26779
|
-
} catch (error) {
|
|
26780
|
-
const _meta = await metaPromise;
|
|
26781
|
-
const errorMessage = error instanceof Error ? error.message : "Simulation failed";
|
|
26782
|
-
const soft = softFailure(errorMessage);
|
|
26783
|
-
if (soft) return {
|
|
26784
|
-
success: true,
|
|
26785
|
-
data: soft,
|
|
26786
|
-
gasEstimate: 0n,
|
|
26787
|
-
tokenFlow: emptyTokenFlow,
|
|
26788
|
-
_meta
|
|
26789
|
-
};
|
|
26790
|
-
return {
|
|
26791
|
-
success: false,
|
|
26792
|
-
error: error instanceof PanopticError ? error : new PanopticError(errorMessage, error instanceof Error ? error : void 0),
|
|
26793
|
-
_meta
|
|
26794
|
-
};
|
|
26795
|
-
}
|
|
26796
|
-
}
|
|
26797
|
-
|
|
26798
|
-
//#endregion
|
|
26799
|
-
//#region src/panoptic/v2/simulations/simulateSettlePremiumBatch.ts
|
|
26800
|
-
/**
|
|
26801
|
-
* Simulate settling each target buyer's owed long premium, all at one block.
|
|
26802
|
-
*
|
|
26803
|
-
* Individual failures (insolvent buyer, stale list, …) are soft: the target
|
|
26804
|
-
* lands in the unsettleable partition instead of failing the batch. Only
|
|
26805
|
-
* unexpected errors reject.
|
|
26806
|
-
*
|
|
26807
|
-
* @param params - Simulation parameters
|
|
26808
|
-
* @returns Partitioned targets with per-target premium and totals
|
|
26809
|
-
*/
|
|
26810
|
-
async function simulateSettlePremiumBatch(params) {
|
|
26811
|
-
const { client, poolAddress, account, positionIdListFrom, targets, blockNumber } = params;
|
|
26812
|
-
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
26813
|
-
const metaPromise = getBlockMeta({
|
|
26814
|
-
client,
|
|
26815
|
-
blockNumber: targetBlockNumber
|
|
26816
|
-
});
|
|
26817
|
-
const simulations = await Promise.all(targets.map((target) => simulateSettlePremiumFrom({
|
|
26818
|
-
client,
|
|
26819
|
-
poolAddress,
|
|
26820
|
-
account,
|
|
26821
|
-
user: target.user,
|
|
26822
|
-
positionIdListFrom,
|
|
26823
|
-
positionIdList: target.positionIdList,
|
|
26824
|
-
tokenId: target.tokenId,
|
|
26825
|
-
blockNumber: targetBlockNumber
|
|
26826
|
-
})));
|
|
26827
|
-
const results = [];
|
|
26828
|
-
const settleable = [];
|
|
26829
|
-
let unsettleableCount = 0;
|
|
26830
|
-
let premium0 = 0n;
|
|
26831
|
-
let premium1 = 0n;
|
|
26832
|
-
simulations.forEach((sim, i) => {
|
|
26833
|
-
const simulation = sim.success ? sim.data : {
|
|
26834
|
-
premium0: 0n,
|
|
26835
|
-
premium1: 0n,
|
|
26836
|
-
settled0: 0n,
|
|
26837
|
-
settled1: 0n,
|
|
26838
|
-
canSettle: false,
|
|
26839
|
-
reason: sim.error.message
|
|
26840
|
-
};
|
|
26841
|
-
results.push({
|
|
26842
|
-
target: targets[i],
|
|
26843
|
-
simulation
|
|
26844
|
-
});
|
|
26845
|
-
if (simulation.canSettle) {
|
|
26846
|
-
settleable.push(targets[i]);
|
|
26847
|
-
premium0 += simulation.premium0;
|
|
26848
|
-
premium1 += simulation.premium1;
|
|
26849
|
-
} else unsettleableCount += 1;
|
|
26850
|
-
});
|
|
26851
|
-
const _meta = await metaPromise;
|
|
26852
|
-
return {
|
|
26853
|
-
results,
|
|
26854
|
-
settleable,
|
|
26855
|
-
unsettleableCount,
|
|
26856
|
-
premium0,
|
|
26857
|
-
premium1,
|
|
26858
|
-
_meta
|
|
26859
|
-
};
|
|
26860
|
-
}
|
|
26861
|
-
/**
|
|
26862
|
-
* Simulate a full settle sequence (all settles + optional close) as the one
|
|
26863
|
-
* multicall that `executeSettleSequence` submits, measuring the caller's
|
|
26864
|
-
* total token flow and gas.
|
|
26865
|
-
*
|
|
26866
|
-
* @param params - Simulation parameters
|
|
26867
|
-
* @returns Simulation result with the caller's net flow, or error
|
|
26868
|
-
*/
|
|
26869
|
-
async function simulateSettleSequence(params) {
|
|
26870
|
-
const { client, poolAddress, account, blockNumber } = params;
|
|
26871
|
-
const targetBlockNumber = blockNumber ?? await client.getBlockNumber();
|
|
26872
|
-
const metaPromise = getBlockMeta({
|
|
26873
|
-
client,
|
|
26874
|
-
blockNumber: targetBlockNumber
|
|
26875
|
-
});
|
|
26876
|
-
try {
|
|
26877
|
-
const calls = buildSettleSequenceCalls(params);
|
|
26878
|
-
const callData = encodeFunctionData({
|
|
26879
|
-
abi: panopticPoolV2Abi,
|
|
26880
|
-
functionName: "multicall",
|
|
26881
|
-
args: [calls]
|
|
26882
|
-
});
|
|
26883
|
-
const flowResult = await simulateWithTokenFlow({
|
|
26884
|
-
client,
|
|
26885
|
-
poolAddress,
|
|
26886
|
-
user: account,
|
|
26887
|
-
callData,
|
|
26888
|
-
blockNumber: targetBlockNumber
|
|
26889
|
-
});
|
|
26890
|
-
if (!flowResult.success || !flowResult.tokenFlow) throw new PanopticError(flowResult.error || "Simulation failed");
|
|
26891
|
-
const _meta = await metaPromise;
|
|
26892
|
-
const tokenFlow = flowResult.tokenFlow;
|
|
26893
|
-
return {
|
|
26894
|
-
success: true,
|
|
26895
|
-
data: {
|
|
26896
|
-
delta0: tokenFlow.delta0,
|
|
26897
|
-
delta1: tokenFlow.delta1
|
|
26898
|
-
},
|
|
26899
|
-
gasEstimate: flowResult.gasEstimate,
|
|
26900
|
-
tokenFlow,
|
|
26901
|
-
_meta
|
|
26902
|
-
};
|
|
26903
|
-
} catch (error) {
|
|
26904
|
-
const _meta = await metaPromise;
|
|
26905
|
-
const errorMessage = error instanceof Error ? error.message : "Simulation failed";
|
|
26906
|
-
return {
|
|
26907
|
-
success: false,
|
|
26908
|
-
error: error instanceof PanopticError ? error : new PanopticError(errorMessage, error instanceof Error ? error : void 0),
|
|
26909
|
-
_meta
|
|
26910
|
-
};
|
|
26911
|
-
}
|
|
26912
|
-
}
|
|
26913
|
-
|
|
26914
27111
|
//#endregion
|
|
26915
27112
|
//#region src/panoptic/v2/simulations/simulateVault.ts
|
|
26916
27113
|
/**
|
|
@@ -28916,6 +29113,441 @@ function createEventPoller(params) {
|
|
|
28916
29113
|
};
|
|
28917
29114
|
}
|
|
28918
29115
|
|
|
29116
|
+
//#endregion
|
|
29117
|
+
//#region src/panoptic/v2/strike/ladder.ts
|
|
29118
|
+
/** Target number of rungs across a leg's full range (lower tick → upper tick). */
|
|
29119
|
+
const STRIKE_LADDER_TARGET_STRIKES = 16n;
|
|
29120
|
+
/** Nice increment mantissas, in tenths (1, 2.5, 5) × 10ⁿ. */
|
|
29121
|
+
const NICE_MANTISSAS_TENTHS = [
|
|
29122
|
+
10n,
|
|
29123
|
+
25n,
|
|
29124
|
+
50n
|
|
29125
|
+
];
|
|
29126
|
+
/** Upper bound on rung hops when searching for a tick-changing step. */
|
|
29127
|
+
const MAX_STEP_ITERATIONS = 512;
|
|
29128
|
+
/** Decimal precision used when rendering exact tick prices as strings. */
|
|
29129
|
+
const PRICE_PRECISION = 30n;
|
|
29130
|
+
function floorDiv(a, b) {
|
|
29131
|
+
const q = a / b;
|
|
29132
|
+
return a % b !== 0n && a < 0n !== b < 0n ? q - 1n : q;
|
|
29133
|
+
}
|
|
29134
|
+
function floorMod(a, b) {
|
|
29135
|
+
return a - floorDiv(a, b) * b;
|
|
29136
|
+
}
|
|
29137
|
+
function ceilDiv(a, b) {
|
|
29138
|
+
return -floorDiv(-a, b);
|
|
29139
|
+
}
|
|
29140
|
+
/** round(a / b) to nearest, ties up. */
|
|
29141
|
+
function roundDiv(a, b) {
|
|
29142
|
+
return floorDiv(2n * a + b, 2n * b);
|
|
29143
|
+
}
|
|
29144
|
+
function pow10(exp) {
|
|
29145
|
+
let result = 1n;
|
|
29146
|
+
for (let i = 0n; i < exp; i++) result *= 10n;
|
|
29147
|
+
return result;
|
|
29148
|
+
}
|
|
29149
|
+
function gcd(a, b) {
|
|
29150
|
+
a = a < 0n ? -a : a;
|
|
29151
|
+
b = b < 0n ? -b : b;
|
|
29152
|
+
while (b !== 0n) [a, b] = [b, a % b];
|
|
29153
|
+
return a;
|
|
29154
|
+
}
|
|
29155
|
+
function reduce(f) {
|
|
29156
|
+
const g = gcd(f.numerator, f.denominator);
|
|
29157
|
+
return g <= 1n ? f : {
|
|
29158
|
+
numerator: f.numerator / g,
|
|
29159
|
+
denominator: f.denominator / g
|
|
29160
|
+
};
|
|
29161
|
+
}
|
|
29162
|
+
function fromBigint(n) {
|
|
29163
|
+
return {
|
|
29164
|
+
numerator: n,
|
|
29165
|
+
denominator: 1n
|
|
29166
|
+
};
|
|
29167
|
+
}
|
|
29168
|
+
function mul(a, b) {
|
|
29169
|
+
return reduce({
|
|
29170
|
+
numerator: a.numerator * b.numerator,
|
|
29171
|
+
denominator: a.denominator * b.denominator
|
|
29172
|
+
});
|
|
29173
|
+
}
|
|
29174
|
+
function add(a, b) {
|
|
29175
|
+
return reduce({
|
|
29176
|
+
numerator: a.numerator * b.denominator + b.numerator * a.denominator,
|
|
29177
|
+
denominator: a.denominator * b.denominator
|
|
29178
|
+
});
|
|
29179
|
+
}
|
|
29180
|
+
function sub(a, b) {
|
|
29181
|
+
return add(a, {
|
|
29182
|
+
numerator: -b.numerator,
|
|
29183
|
+
denominator: b.denominator
|
|
29184
|
+
});
|
|
29185
|
+
}
|
|
29186
|
+
/** -1 | 0 | 1 comparing a to b. */
|
|
29187
|
+
function cmp(a, b) {
|
|
29188
|
+
const l = a.numerator * b.denominator;
|
|
29189
|
+
const r = b.numerator * a.denominator;
|
|
29190
|
+
return l === r ? 0 : l < r ? -1 : 1;
|
|
29191
|
+
}
|
|
29192
|
+
const LADDER_MIN = fromBigint(1n);
|
|
29193
|
+
/** Largest normalised price on the ladder. Prices above are "outside". */
|
|
29194
|
+
const LADDER_MAX = fromBigint(1000000n);
|
|
29195
|
+
function parseDecimal(value) {
|
|
29196
|
+
const trimmed = value.trim();
|
|
29197
|
+
const [basePart, exponentPart] = trimmed.toLowerCase().split("e");
|
|
29198
|
+
const [integerStr, fractionalStr = ""] = basePart.split(".");
|
|
29199
|
+
let numerator = BigInt(`${integerStr === "" ? "0" : integerStr}${fractionalStr}`);
|
|
29200
|
+
let denominator = pow10(BigInt(fractionalStr.length));
|
|
29201
|
+
if (exponentPart !== void 0 && exponentPart !== "") {
|
|
29202
|
+
const exponent = BigInt(exponentPart);
|
|
29203
|
+
if (exponent > 0n) numerator *= pow10(exponent);
|
|
29204
|
+
else if (exponent < 0n) denominator *= pow10(-exponent);
|
|
29205
|
+
}
|
|
29206
|
+
if (numerator <= 0n) throw new Error("Price must be positive");
|
|
29207
|
+
return reduce({
|
|
29208
|
+
numerator,
|
|
29209
|
+
denominator
|
|
29210
|
+
});
|
|
29211
|
+
}
|
|
29212
|
+
/** Render a positive fraction as a decimal string with trailing zeros trimmed. */
|
|
29213
|
+
function fractionToDecimal(f, precision) {
|
|
29214
|
+
const scaled = f.numerator * pow10(precision) / f.denominator;
|
|
29215
|
+
const digits = scaled.toString().padStart(Number(precision) + 1, "0");
|
|
29216
|
+
const intPart = digits.slice(0, digits.length - Number(precision));
|
|
29217
|
+
const fracPart = digits.slice(digits.length - Number(precision)).replace(/0+$/, "");
|
|
29218
|
+
return fracPart.length === 0 ? intPart : `${intPart}.${fracPart}`;
|
|
29219
|
+
}
|
|
29220
|
+
/** 10^k as an exact fraction, k may be negative. */
|
|
29221
|
+
function powerOfTen(k) {
|
|
29222
|
+
return k >= 0n ? fromBigint(pow10(k)) : {
|
|
29223
|
+
numerator: 1n,
|
|
29224
|
+
denominator: pow10(-k)
|
|
29225
|
+
};
|
|
29226
|
+
}
|
|
29227
|
+
/** floor(log10(f)) for a positive fraction. */
|
|
29228
|
+
function floorLog10(f) {
|
|
29229
|
+
let e = BigInt(f.numerator.toString().length - f.denominator.toString().length);
|
|
29230
|
+
while (cmp(f, powerOfTen(e)) < 0) e -= 1n;
|
|
29231
|
+
while (cmp(f, powerOfTen(e + 1n)) >= 0) e += 1n;
|
|
29232
|
+
return e;
|
|
29233
|
+
}
|
|
29234
|
+
function orientTick(tick, orient) {
|
|
29235
|
+
return orient.asset === 0n ? tick : -tick;
|
|
29236
|
+
}
|
|
29237
|
+
/** Exact-enough price of `tick` in the caller's orientation. */
|
|
29238
|
+
function tickToOrientedPrice(tick, orient) {
|
|
29239
|
+
const price = tickToPriceDecimalScaled(orientTick(tick, orient), orient.assetDecimals, orient.quoteDecimals, PRICE_PRECISION);
|
|
29240
|
+
return parseDecimal(price);
|
|
29241
|
+
}
|
|
29242
|
+
/** Nearest integer tick for a caller-oriented decimal price. */
|
|
29243
|
+
function orientedPriceToTick(price, orient) {
|
|
29244
|
+
const t = priceToTick(price, orient.assetDecimals, orient.quoteDecimals);
|
|
29245
|
+
return orientTick(t, orient);
|
|
29246
|
+
}
|
|
29247
|
+
/**
|
|
29248
|
+
* Relative rung step for a leg: `1.0001^(round(width·tickSpacing / TARGET)) − 1`.
|
|
29249
|
+
* Rungs scale with price (they are multiples of a price-proportional increment), so
|
|
29250
|
+
* spacing them by the range's TARGET-th root yields ≈TARGET rungs across the range
|
|
29251
|
+
* regardless of how wide it is.
|
|
29252
|
+
*/
|
|
29253
|
+
function relativeStep(width, tickSpacing) {
|
|
29254
|
+
validateGeometry(width, tickSpacing);
|
|
29255
|
+
const ticks = roundDiv(width * tickSpacing, STRIKE_LADDER_TARGET_STRIKES);
|
|
29256
|
+
const ratio = parseDecimal(tickToPriceDecimalScaled(ticks < 1n ? 1n : ticks, 0n, 0n, PRICE_PRECISION));
|
|
29257
|
+
return sub(ratio, fromBigint(1n));
|
|
29258
|
+
}
|
|
29259
|
+
/** Nice increment `m × 10ⁿ` (m ∈ {1, 2.5, 5}) with the smallest log-distance to `raw`. */
|
|
29260
|
+
function niceIncrement(raw) {
|
|
29261
|
+
const e = floorLog10(raw);
|
|
29262
|
+
const scale = (tenths) => mul(fromBigint(tenths), powerOfTen(e - 1n));
|
|
29263
|
+
const candidates = [...NICE_MANTISSAS_TENTHS.map(scale), scale(100n)];
|
|
29264
|
+
let lo = candidates[0] ?? powerOfTen(e);
|
|
29265
|
+
for (const hi of candidates.slice(1)) {
|
|
29266
|
+
if (cmp(raw, hi) < 0) return cmp(mul(raw, raw), mul(lo, hi)) <= 0 ? lo : hi;
|
|
29267
|
+
lo = hi;
|
|
29268
|
+
}
|
|
29269
|
+
return lo;
|
|
29270
|
+
}
|
|
29271
|
+
/** Rung increment at normalised price `p` for the given relative step. */
|
|
29272
|
+
function incrementAt(p, rf) {
|
|
29273
|
+
return niceIncrement(mul(p, rf));
|
|
29274
|
+
}
|
|
29275
|
+
/** Normalise a price to `max(p, 1/p)` and remember whether it was inverted. */
|
|
29276
|
+
function normalise(price) {
|
|
29277
|
+
if (price.numerator >= price.denominator) return {
|
|
29278
|
+
value: price,
|
|
29279
|
+
reciprocal: false
|
|
29280
|
+
};
|
|
29281
|
+
return {
|
|
29282
|
+
value: {
|
|
29283
|
+
numerator: price.denominator,
|
|
29284
|
+
denominator: price.numerator
|
|
29285
|
+
},
|
|
29286
|
+
reciprocal: true
|
|
29287
|
+
};
|
|
29288
|
+
}
|
|
29289
|
+
/** Is `r` a multiple of `inc`? */
|
|
29290
|
+
function isMultiple(r, inc) {
|
|
29291
|
+
return r.numerator * inc.denominator % (r.denominator * inc.numerator) === 0n;
|
|
29292
|
+
}
|
|
29293
|
+
/** Smallest multiple of `inc` strictly greater than `x`. */
|
|
29294
|
+
function ceilMultipleStrict(x, inc) {
|
|
29295
|
+
const k = floorDiv(x.numerator * inc.denominator, x.denominator * inc.numerator) + 1n;
|
|
29296
|
+
return mul(fromBigint(k), inc);
|
|
29297
|
+
}
|
|
29298
|
+
/** Largest multiple of `inc` strictly smaller than `x`. */
|
|
29299
|
+
function floorMultipleStrict(x, inc) {
|
|
29300
|
+
const k = ceilDiv(x.numerator * inc.denominator, x.denominator * inc.numerator) - 1n;
|
|
29301
|
+
return mul(fromBigint(k), inc);
|
|
29302
|
+
}
|
|
29303
|
+
/**
|
|
29304
|
+
* The rung set is `{ r : r is a multiple of incrementAt(r) }`. Because the
|
|
29305
|
+
* increment grows with price, a multiple of a finer increment can land inside a
|
|
29306
|
+
* coarser band where it is no longer a rung; these helpers push such a candidate
|
|
29307
|
+
* up/down until it is a multiple of its own band's increment.
|
|
29308
|
+
*/
|
|
29309
|
+
function isRung(r, rf) {
|
|
29310
|
+
return r.numerator > 0n && isMultiple(r, incrementAt(r, rf));
|
|
29311
|
+
}
|
|
29312
|
+
function fixUp(c, rf) {
|
|
29313
|
+
for (let i = 0; i < 64 && !isRung(c, rf); i++) c = ceilMultipleStrict(c, incrementAt(c, rf));
|
|
29314
|
+
return c;
|
|
29315
|
+
}
|
|
29316
|
+
function fixDown(c, rf) {
|
|
29317
|
+
for (let i = 0; i < 64 && c.numerator > 0n && !isRung(c, rf); i++) c = floorMultipleStrict(c, incrementAt(c, rf));
|
|
29318
|
+
return c;
|
|
29319
|
+
}
|
|
29320
|
+
/** Smallest rung strictly above `x` (may exceed the ladder top). */
|
|
29321
|
+
function nextRungAbove(x, rf) {
|
|
29322
|
+
const incHere = incrementAt(x, rf);
|
|
29323
|
+
const incs = [incHere, incrementAt(add(x, incHere), rf)];
|
|
29324
|
+
let best = null;
|
|
29325
|
+
for (const inc of incs) {
|
|
29326
|
+
const c = fixUp(ceilMultipleStrict(x, inc), rf);
|
|
29327
|
+
if (cmp(c, x) > 0 && (best === null || cmp(c, best) < 0)) best = c;
|
|
29328
|
+
}
|
|
29329
|
+
if (best === null) throw new PanopticValidationError("No ladder rung above price");
|
|
29330
|
+
return best;
|
|
29331
|
+
}
|
|
29332
|
+
/** Largest rung strictly below `x` (may fall below the ladder floor). */
|
|
29333
|
+
function prevRungBelow(x, rf) {
|
|
29334
|
+
const incHere = incrementAt(x, rf);
|
|
29335
|
+
const finer = incrementAt(sub(x, incHere), rf);
|
|
29336
|
+
let best = null;
|
|
29337
|
+
for (const inc of [incHere, finer]) {
|
|
29338
|
+
const c = fixDown(floorMultipleStrict(x, inc), rf);
|
|
29339
|
+
if (c.numerator > 0n && cmp(c, x) < 0 && (best === null || cmp(c, best) > 0)) best = c;
|
|
29340
|
+
}
|
|
29341
|
+
return best ?? fromBigint(0n);
|
|
29342
|
+
}
|
|
29343
|
+
/** Nearest rung price to a normalised price, or null when above the ladder. */
|
|
29344
|
+
function nearestRungPrice(normalised, rf) {
|
|
29345
|
+
let rung;
|
|
29346
|
+
if (isRung(normalised, rf)) rung = normalised;
|
|
29347
|
+
else {
|
|
29348
|
+
const up = nextRungAbove(normalised, rf);
|
|
29349
|
+
const down = prevRungBelow(normalised, rf);
|
|
29350
|
+
if (down.numerator <= 0n) rung = up;
|
|
29351
|
+
else rung = cmp(sub(normalised, down), sub(up, normalised)) <= 0 ? down : up;
|
|
29352
|
+
}
|
|
29353
|
+
if (cmp(rung, LADDER_MIN) < 0) rung = LADDER_MIN;
|
|
29354
|
+
if (cmp(rung, LADDER_MAX) > 0) return null;
|
|
29355
|
+
return rung;
|
|
29356
|
+
}
|
|
29357
|
+
/** Step one rung up (+1) or down (-1) on the normalised ladder. Null when leaving it. */
|
|
29358
|
+
function stepRungPrice(rung, direction, rf) {
|
|
29359
|
+
const next = direction > 0n ? nextRungAbove(rung, rf) : prevRungBelow(rung, rf);
|
|
29360
|
+
if (cmp(next, LADDER_MIN) < 0 || cmp(next, LADDER_MAX) > 0) return null;
|
|
29361
|
+
return next;
|
|
29362
|
+
}
|
|
29363
|
+
/** Nominal caller-oriented price of a rung as an exact fraction. */
|
|
29364
|
+
function rungToPrice(rung) {
|
|
29365
|
+
return rung.reciprocal ? {
|
|
29366
|
+
numerator: rung.price.denominator,
|
|
29367
|
+
denominator: rung.price.numerator
|
|
29368
|
+
} : rung.price;
|
|
29369
|
+
}
|
|
29370
|
+
function rungToPriceString(rung) {
|
|
29371
|
+
return fractionToDecimal(rungToPrice(rung), PRICE_PRECISION);
|
|
29372
|
+
}
|
|
29373
|
+
function nearestRung(price, rf) {
|
|
29374
|
+
const { value, reciprocal } = normalise(price);
|
|
29375
|
+
const p = nearestRungPrice(value, rf);
|
|
29376
|
+
return p === null ? null : {
|
|
29377
|
+
price: p,
|
|
29378
|
+
reciprocal
|
|
29379
|
+
};
|
|
29380
|
+
}
|
|
29381
|
+
/**
|
|
29382
|
+
* Step a rung in the caller's price direction. For reciprocal quotes a higher
|
|
29383
|
+
* caller price is a lower normalised price, so the direction flips.
|
|
29384
|
+
*/
|
|
29385
|
+
function stepRung(rung, direction, rf) {
|
|
29386
|
+
const normalisedDir = rung.reciprocal ? direction > 0n ? -1n : 1n : direction;
|
|
29387
|
+
const p = stepRungPrice(rung.price, normalisedDir, rf);
|
|
29388
|
+
return p === null ? null : {
|
|
29389
|
+
price: p,
|
|
29390
|
+
reciprocal: rung.reciprocal
|
|
29391
|
+
};
|
|
29392
|
+
}
|
|
29393
|
+
/** Reject geometry the ladder cannot place: non-positive inputs or a span wider than the tick domain. */
|
|
29394
|
+
function validateGeometry(width, tickSpacing) {
|
|
29395
|
+
if (width <= 0n) throw new PanopticValidationError("width must be positive");
|
|
29396
|
+
if (tickSpacing <= 0n) throw new PanopticValidationError("tickSpacing must be positive");
|
|
29397
|
+
if (width * tickSpacing > MAX_TICK - MIN_TICK) throw new PanopticValidationError("width * tickSpacing exceeds the tick domain");
|
|
29398
|
+
}
|
|
29399
|
+
/** `rangeDown`/`rangeUp` exactly as `PanopticMath.getRangesFromStrike`. */
|
|
29400
|
+
function rangesFromStrike(width, tickSpacing) {
|
|
29401
|
+
const span = width * tickSpacing;
|
|
29402
|
+
return {
|
|
29403
|
+
rangeDown: span / 2n,
|
|
29404
|
+
rangeUp: ceilDiv(span, 2n)
|
|
29405
|
+
};
|
|
29406
|
+
}
|
|
29407
|
+
/**
|
|
29408
|
+
* Nearest valid strike tick to `exactTick` for `width`/`tickSpacing`.
|
|
29409
|
+
* Valid strikes satisfy `strike ≡ rangeDown (mod tickSpacing)`; the result is
|
|
29410
|
+
* shifted in whole tick spacings so the leg's ticks stay within `[MIN_TICK, MAX_TICK]`.
|
|
29411
|
+
*/
|
|
29412
|
+
function canonicalStrikeForWidth(exactTick, width, tickSpacing) {
|
|
29413
|
+
validateGeometry(width, tickSpacing);
|
|
29414
|
+
const { rangeDown, rangeUp } = rangesFromStrike(width, tickSpacing);
|
|
29415
|
+
const offset = floorMod(rangeDown, tickSpacing);
|
|
29416
|
+
let strike = roundDiv(exactTick - offset, tickSpacing) * tickSpacing + offset;
|
|
29417
|
+
while (strike - rangeDown < MIN_TICK) strike += tickSpacing;
|
|
29418
|
+
while (strike + rangeUp > MAX_TICK) strike -= tickSpacing;
|
|
29419
|
+
return strike;
|
|
29420
|
+
}
|
|
29421
|
+
function rungToStrike(rung, geom) {
|
|
29422
|
+
const nominalPrice = rungToPriceString(rung);
|
|
29423
|
+
const exactTick = orientedPriceToTick(nominalPrice, geom.orient);
|
|
29424
|
+
return {
|
|
29425
|
+
tick: canonicalStrikeForWidth(exactTick, geom.width, geom.tickSpacing),
|
|
29426
|
+
nominalPrice
|
|
29427
|
+
};
|
|
29428
|
+
}
|
|
29429
|
+
function classifyTick(tick, geom, rf) {
|
|
29430
|
+
const rung = nearestRung(tickToOrientedPrice(tick, geom.orient), rf);
|
|
29431
|
+
if (rung === null) return { kind: "outside-ladder" };
|
|
29432
|
+
const canonical = rungToStrike(rung, geom);
|
|
29433
|
+
return canonical.tick === tick ? {
|
|
29434
|
+
kind: "ladder",
|
|
29435
|
+
nominalPrice: canonical.nominalPrice
|
|
29436
|
+
} : { kind: "off-ladder" };
|
|
29437
|
+
}
|
|
29438
|
+
/**
|
|
29439
|
+
* A rung's canonical tick is only usable when that tick classifies back to the
|
|
29440
|
+
* same rung (`classifyStrike` → 'ladder'). When rungs are finer than the tick
|
|
29441
|
+
* grid two rungs can share a tick and only one of them "owns" it; return the
|
|
29442
|
+
* owner's strike, or null when this rung does not own its tick.
|
|
29443
|
+
*/
|
|
29444
|
+
function ownedStrike(rung, geom, rf) {
|
|
29445
|
+
const strike = rungToStrike(rung, geom);
|
|
29446
|
+
const cls = classifyTick(strike.tick, geom, rf);
|
|
29447
|
+
return cls.kind === "ladder" ? {
|
|
29448
|
+
tick: strike.tick,
|
|
29449
|
+
nominalPrice: cls.nominalPrice
|
|
29450
|
+
} : null;
|
|
29451
|
+
}
|
|
29452
|
+
/**
|
|
29453
|
+
* Classify a strike tick against the ladder for its width.
|
|
29454
|
+
*
|
|
29455
|
+
* - `ladder`: the tick is the canonical tick of its nearest rung → show `nominalPrice`.
|
|
29456
|
+
* - `off-ladder`: an in-range tick that is not a rung's canonical tick (e.g. real AMM
|
|
29457
|
+
* liquidity at an arbitrary strike) → show the exact price.
|
|
29458
|
+
* - `outside-ladder`: the normalised price exceeds 1,000,000 → legacy behaviour.
|
|
29459
|
+
*/
|
|
29460
|
+
function classifyStrike(params) {
|
|
29461
|
+
return classifyTick(params.tick, params, relativeStep(params.width, params.tickSpacing));
|
|
29462
|
+
}
|
|
29463
|
+
/**
|
|
29464
|
+
* Resolve a tick to a ladder strike.
|
|
29465
|
+
*
|
|
29466
|
+
* - `step` 0 (default): the ladder tick nearest to `tick` (the tick's own rung when
|
|
29467
|
+
* it owns one, otherwise the closest owned neighbour).
|
|
29468
|
+
* - `step` ±1: the nearest ladder tick strictly beyond `tick` in that price direction
|
|
29469
|
+
* (rungs finer than the tick grid can collapse onto one tick, so a single rung hop
|
|
29470
|
+
* may not move the strike).
|
|
29471
|
+
*
|
|
29472
|
+
* Returns null when the target lies outside the ladder (normalised price > 1e6).
|
|
29473
|
+
*/
|
|
29474
|
+
function resolveLadderStrike(params) {
|
|
29475
|
+
const step = params.step ?? 0n;
|
|
29476
|
+
const rf = relativeStep(params.width, params.tickSpacing);
|
|
29477
|
+
const start = nearestRung(tickToOrientedPrice(params.tick, params.orient), rf);
|
|
29478
|
+
if (start === null) return null;
|
|
29479
|
+
const startOriented = orientTick(params.tick, params.orient);
|
|
29480
|
+
if (step === 0n) {
|
|
29481
|
+
const own = ownedStrike(start, params, rf);
|
|
29482
|
+
if (own !== null) return own;
|
|
29483
|
+
let lo = start;
|
|
29484
|
+
let hi = start;
|
|
29485
|
+
for (let i = 0; i < MAX_STEP_ITERATIONS; i++) {
|
|
29486
|
+
lo = lo === null ? null : stepRung(lo, -1n, rf);
|
|
29487
|
+
hi = hi === null ? null : stepRung(hi, 1n, rf);
|
|
29488
|
+
const a = lo === null ? null : ownedStrike(lo, params, rf);
|
|
29489
|
+
const b = hi === null ? null : ownedStrike(hi, params, rf);
|
|
29490
|
+
if (a !== null && b !== null) {
|
|
29491
|
+
const da = startOriented - orientTick(a.tick, params.orient);
|
|
29492
|
+
const db = orientTick(b.tick, params.orient) - startOriented;
|
|
29493
|
+
return da <= db ? a : b;
|
|
29494
|
+
}
|
|
29495
|
+
if (a !== null) return a;
|
|
29496
|
+
if (b !== null) return b;
|
|
29497
|
+
if (lo === null && hi === null) return null;
|
|
29498
|
+
}
|
|
29499
|
+
return null;
|
|
29500
|
+
}
|
|
29501
|
+
let rung = start;
|
|
29502
|
+
for (let i = 0; i < MAX_STEP_ITERATIONS && rung !== null; i++) {
|
|
29503
|
+
const own = ownedStrike(rung, params, rf);
|
|
29504
|
+
if (own !== null) {
|
|
29505
|
+
const oriented = orientTick(own.tick, params.orient);
|
|
29506
|
+
if (step > 0n ? oriented > startOriented : oriented < startOriented) return own;
|
|
29507
|
+
}
|
|
29508
|
+
rung = stepRung(rung, step, rf);
|
|
29509
|
+
}
|
|
29510
|
+
return null;
|
|
29511
|
+
}
|
|
29512
|
+
/**
|
|
29513
|
+
* Generate up to `count` ladder strikes centred on `centerTick`, sorted by
|
|
29514
|
+
* ascending caller price and deduplicated by tick. Rungs beyond the ladder are
|
|
29515
|
+
* omitted (the result may be shorter than `count`). Returns null when the
|
|
29516
|
+
* centre itself lies outside the ladder and `[]` when `count` is 0.
|
|
29517
|
+
*/
|
|
29518
|
+
function ladderStrikeSequence(params) {
|
|
29519
|
+
const rf = relativeStep(params.width, params.tickSpacing);
|
|
29520
|
+
if (params.count <= 0) return [];
|
|
29521
|
+
const center = nearestRung(tickToOrientedPrice(params.centerTick, params.orient), rf);
|
|
29522
|
+
if (center === null) return null;
|
|
29523
|
+
const half = Math.floor(params.count / 2);
|
|
29524
|
+
const below = [];
|
|
29525
|
+
const above = [];
|
|
29526
|
+
let r = center;
|
|
29527
|
+
for (let i = 0; i < half && r !== null; i++) {
|
|
29528
|
+
r = stepRung(r, -1n, rf);
|
|
29529
|
+
if (r !== null) below.push(r);
|
|
29530
|
+
}
|
|
29531
|
+
r = center;
|
|
29532
|
+
for (let i = 0; i < params.count - half - 1 && r !== null; i++) {
|
|
29533
|
+
r = stepRung(r, 1n, rf);
|
|
29534
|
+
if (r !== null) above.push(r);
|
|
29535
|
+
}
|
|
29536
|
+
const seen = new Set();
|
|
29537
|
+
const out = [];
|
|
29538
|
+
for (const rung of [
|
|
29539
|
+
...below.reverse(),
|
|
29540
|
+
center,
|
|
29541
|
+
...above
|
|
29542
|
+
]) {
|
|
29543
|
+
const strike = ownedStrike(rung, params, rf);
|
|
29544
|
+
if (strike === null || seen.has(strike.tick)) continue;
|
|
29545
|
+
seen.add(strike.tick);
|
|
29546
|
+
out.push(strike);
|
|
29547
|
+
}
|
|
29548
|
+
return out;
|
|
29549
|
+
}
|
|
29550
|
+
|
|
28919
29551
|
//#endregion
|
|
28920
29552
|
//#region src/panoptic/v2/bot/index.ts
|
|
28921
29553
|
/**
|
|
@@ -32158,13 +32790,17 @@ function useSettleAccumulatedPremia(poolAddress) {
|
|
|
32158
32790
|
...params
|
|
32159
32791
|
});
|
|
32160
32792
|
},
|
|
32161
|
-
onSuccess: (_data,
|
|
32793
|
+
onSuccess: (_data, params, context) => {
|
|
32162
32794
|
if (!context) return;
|
|
32163
|
-
invalidateKeys(queryClient, mutationEffects.settleAccumulatedPremia({
|
|
32795
|
+
invalidateKeys(queryClient, [...mutationEffects.settleAccumulatedPremia({
|
|
32164
32796
|
chainId,
|
|
32165
32797
|
poolAddress,
|
|
32166
32798
|
account: context.signerAccount
|
|
32167
|
-
}))
|
|
32799
|
+
}), ...(params.targets ?? []).flatMap((target) => mutationEffects.settleAccumulatedPremia({
|
|
32800
|
+
chainId,
|
|
32801
|
+
poolAddress,
|
|
32802
|
+
account: target.user
|
|
32803
|
+
}))]);
|
|
32168
32804
|
}
|
|
32169
32805
|
});
|
|
32170
32806
|
}
|
|
@@ -34798,5 +35434,5 @@ function useTxEventConfirmation({ txHash, poolAddress = zeroAddress, collateralT
|
|
|
34798
35434
|
}
|
|
34799
35435
|
|
|
34800
35436
|
//#endregion
|
|
34801
|
-
export { AccountInsolventError, AlreadyInitializedError, BORROW_INDEX_BITS, BPS_DENOMINATOR, BPS_SCALE, BatchValidationError, BelowMinimumRedemptionError, CastingError, ChunkHasZeroLiquidityError, ChunkLimitError, CrossPoolError, DEFAULT_MAX_SPREAD, DEFAULT_MINT_BUFFER, DEFAULT_MIN_SWAP_RATIO_BPS, DEFAULT_RECONNECT_CONFIG, DEFAULT_VEGOID, DepositTooLargeError, DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError, InputListFailError, InsufficientCreditLiquidityError, InvalidBuilderCodeError, InvalidHistoryRangeError, InvalidTickBoundError, InvalidTickError, InvalidTokenIdParameterError, InvalidUniswapCallbackError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LengthMismatchError, LiquidityTooHighError, LoanSlotExhaustedError, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, MAX_TICK, MAX_TRACKED_CHUNKS, MINT_BUFFER, MINT_BUFFER_DENOMINATOR, MIN_TICK, MaxRetriesExceededError, MissingPositionIdsError, NO_LOWER_LIQUIDATION_TICK, NO_UPPER_LIQUIDATION_TICK, NetLiquidityZeroError, NetworkMismatchError, NoLegsExercisableError, NotALongLegError, NotBuilderError, NotEnoughLiquidityInChunkError, NotEnoughTokensError, NotGuardianError, NotMarginCalledError, NotPanopticPoolError, ORACLE_EPOCH_SECONDS, OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError, PanopticProvider, PanopticValidationError, PoolNotInitializedError, PositionCountNotZeroError, PositionNotOwnedError, PositionSnapshotNotFoundError, PositionTooLargeError, PriceBoundFailError, PriceImpactTooLargeError, ProviderLagError, RATE_AT_TARGET_BITS, REORG_DEPTH, REQUIRED_BASE_ERROR_SENTINEL, ReentrancyError, RpcError, RpcResponseError, SCHEMA_VERSION, SECONDS_PER_YEAR, STANDARD_TICK_WIDTHS, STORAGE_PREFIX, SafeModeError, StaleDataError, StaleOracleError, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, TokenIdHasZeroLegsError, TooManyLegsOpenError, TransferFailedError, UNREALIZED_INTEREST_BITS, UTILIZATION_DENOMINATOR, UnauthorizedUniswapCallbackError, UnderOverFlowError, UnhealthyPoolError, WAD, WrongPoolIdError, WrongUniswapPoolError, ZERO_COLLATERAL, ZERO_VALUATION, ZeroAddressError, ZeroCollateralRequirementError, addLegToTokenId, addPendingPosition, addTrackedChunks, annualizePerSecondRateWad, applyMintBuffer, applyMintBufferPerToken, apportion, approve, approveAndWait, approvePool, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertTradeable, borrow, borrowAndWait, buildBatchDispatchArgs, buildCreditSwapCall, buildCreditWrappedDispatch, buildOpenPositionCalldata, buildSettleSequenceCalls, buildSfpmSwapCalldata, buildSfpmSwapPlan, buildTemporaryLoanRecoveryDispatch, buildTokenShortfallRecoveryDispatch, buildUniqueCredit, buildUniqueLoan, buildUniqueWidthZeroLeg, calculateAccountGreeksPure, calculatePortfolioDelta, calculatePortfolioGamma, calculatePortfolioGreeks, calculatePortfolioValue, calculatePositionDelta, calculatePositionDeltaDebtOnly, calculatePositionDeltaWithSwap, calculatePositionGamma, calculatePositionGreeks, calculatePositionValue, calculateResyncBlock, calculateSpreadWad, cancelTransaction, checkApproval, checkCollateralAcrossTicks, classifyStrategyGroups, cleanupStalePendingPositions, clearCheckpoint, clearPendingPositions, clearTrackedChunks, clearTrackedPositions, clearTradeHistory, closePosition, closePositionAndWait, collateralRuleKindFor, collateralTrackerV2Abi, computeV4PoolId, confirmPendingPosition, convertToAssets, convertToShares, countLegs, createEventPoller, createEventSubscription, createFileStorage, createFlowNeutralTokenId, createMemoryStorage, createNonceManager, createPoolFormatters, createTokenIdBuilder, decodeAllDispatchCalldata, decodeAllLegs, decodeDispatchCalldata, decodeLeftRightSigned, decodeLeftRightUnsigned, decodeLeg, decodeOraclePack, decodeOracleRiskParameters, decodeOracleTiming, decodePanopticTokenURI, decodePoolId, decodeTickSpacing, decodeTokenId, decodeVegoid, deployNewPool, deployNewPoolAndWait, deposit, depositAndWait, deriveSupplyRatePerSecWad, deriveUniqueTokenId, detectReorg, diagnoseOracleSafeMode, dispatch, dispatchAndWait, encodeLeg, encodePoolId, encodePoolKeyBytes, encodeV3PoolKeyBytes, encodeV4PoolId, ensureSfpmV3PoolInitialized, estimateBlockNumbers, estimateCollateralBreakdown, estimateCollateralRequired, executeBatchDispatch, executeBatchDispatchAndWait, executeSettleSequence, executeSettleSequenceAndWait, failPendingPosition, feesFromFeeGrowthDelta, fetchPoolId, fetchSfpmV3PoolId, forceExercise, forceExerciseAndWait, formatBlockNumber, formatBps, formatCompact, formatDatetime, formatDuration, formatDurationSeconds, formatFeeTier, formatGas, formatGwei, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatPoolIdHex, formatPriceRange, formatRateWad, formatRatioPercent, formatTick, formatTickRange, formatTimestamp, formatTimestampLocale, formatTokenAmount, formatTokenAmountSigned, formatTokenDelta, formatTokenFlow, formatTokenIdHex, formatTokenIdShort, formatTxHash, formatUtilization, formatWad, formatWadPercent, formatWadSigned, formatWei, generateOverlappingTokenIds, getAccountBuyingPower, getAccountCollateral, getAccountGreeks, getAccountHistory, getAccountPremia, getAccountSummaryBasic, getAccountSummaryRisk, getAssetIndex, getBlockMeta, getChainDeployment, getChunkLiquidities, getChunkSpreads, getClosedPositions, getClosedPositionsKey, getCollateralAddresses, getCollateralData, getCollateralSharePrices, getCollateralTotalAssetsBatch, getCurrentRates, getDeltaHedgeParams, getEnforcedTickLimits, getFactoryConstructMetadata, getFactoryOwnerOf, getFactoryTokenURI, getForfeitablePremium, getGuardianUnlockState, getInterestState, getIrmCurrent, getIrmCurve, getItmAmounts, getLegDelta, getLegDeltaInVaultFrame, getLegGamma, getLegNetValueWidth0, getLegValue, getLiquidationPrices, getMarginBuffer, getMaxPositionSize, getMaxRedeem, getMaxWithdrawable, getNativeTokenPrice, getNetLiquidationValue, getNetLiquidationValues, getNotEnoughTokensError, getOpenPositionIds, getOpenPositionPreview, getOracleRiskParameters, getOracleState, getPanopticPoolAddress, getPanopticPoolFromPoolId, getPendingPositions, getPendingPositionsKey, getPool, getPoolDeploymentBlock, getPoolDisplayId, getPoolLiquidities, getPoolMetaKey, getPoolMetadata, getPoolPrefix, getPortfolioValue, getPosition, getPositionChunkData, getPositionEnrichmentData, getPositionGreeks, getPositionMetaKey, getPositions, getPositionsKey, getPositionsWithPremia, getPriceHistory, getPricesAtTick, getRealizedPnL, getRequiredCreditForITM, getRiskParameters, getSafeMode, getSchemaVersionKey, getStreamiaHistory, getSyncCheckpointKey, getSyncStatus, getTickSpacing, getTokenListId, getTrackedChunks, getTrackedChunksKey, getTrackedPositionIds, getTradeHistory, getUniswapFeeHistory, getUniswapV3LpPositionState, getUniswapV3PoolFromId, getUniswapV3PoolInfo, getUniswapV3PoolLiquidities, getUniswapV4LpPositionState, getUniswapV4PoolBasicState, getUniswapV4PoolInfo, getUniswapV4PoolKeyFromId, getUniswapV4PoolLiquidities, getUtilization, hasLoanOrCredit, hasLongLeg, interpolateBlocks, isCall, isCowSupportedChain, isCredit, isCreditLeg, isDefinedRisk, isGasError, isInputListFailError, isLiquidatable, isLoan, isLoanLeg, isNonceError, isPanopticErrorType, isPositionTracked, isRetryableRpcError, isShortOnly, isSpread, isSupportedChain, isolateGroupTokenId, jsonSerializer, liquidate, liquidateAndWait, loadCheckpoint, minePoolAddress, mint, mintAndWait, mintableAfterBuffer, multicallRead, mutationEffects, openPosition, openPositionAndWait, optimizeTokenIdRiskPartners, oracleEpochAt, orderListForSettle, packMarketState, panopticPoolV2Abi, parseBps, parseCollateralLog, parsePanopticError, parsePoolLog, parseTokenAmount, parseTokenListId, parseWad, planDeriveStrategy, pokeOracle, pokeOracleAndWait, previewBorrow, previewDeposit, previewMint, previewRedeem, previewUnwrap, previewWithdraw, previewWrap, priceToTick, publicBroadcaster, queryKeys, quoteOneTokenFlow, quoteSfpmSwap, quoteTemporaryLoanRecovery, quoteTokenShortfallRecovery, quoteV3ExactIn, ratePerSecWadToAprPct, reconstructFromEvents, recoverSnapshot, recoverSnapshotFromTx, redeem, redeemAndWait, removeTrackedChunks, repay, repayAndWait, requireChainDeployment, resolveBlockNumbers, resolvePanopticPoolFromPoolId, resolveTokenIndex, resolveUniswapV4PoolKey, riskEngineAbi, rollPosition, rollPositionAndWait, roundToTickSpacing, saveCheckpoint, saveClosedPosition, scanChunks, selectDispatchForAccount, settleAccumulatedPremia, settleAccumulatedPremiaAndWait, settlePremiumFrom, settlePremiumFromAndWait, simulateBatchDispatch, simulateClosePosition, simulateDeployNewPool, simulateDeposit, simulateDispatch, simulateForceExercise, simulateLiquidate, simulateOpenPosition, simulateSFPMBurn, simulateSFPMMint, simulateSettle, simulateSettlePremiumBatch, simulateSettlePremiumFrom, simulateSettleSequence, simulateSwapExactIn, simulateSwapExactOut, simulateWithTokenFlow, simulateWithdraw, slippageBpsToTickDistance, smartRepay, smartRepayAndWait, speedUpTransaction, splitTokenIdByTimescale, sqrtPriceX96ToPriceDecimalScaled, sqrtPriceX96ToTick, supply, supplyAndWait, swapExactIn, swapExactInAndWait, swapExactOut, swapExactOutAndWait, syncPositions, tickLimits, tickToPrice, tickToPriceDecimalScaled, tickToSqrtPriceX96, toVaultFrameAtTick, truncateAddress, unsupply, unsupplyAndWait, unwrapWeth, unwrapWethAndWait, unwrapXstock, unwrapXstockAndWait, useAccountCollateral, useAccountGreeks, useAccountPremia, useAccountSummaryBasic, useAccountSummaryRisk, useAddPendingPosition, useApprove, useApproveErc20ForCow, useApproveErc20ForPermit2, useApprovePool, useApproveRouterViaPermit2, useBatchDispatch as useBatchDispatchHook, useBorrow as useBorrowHook, useCancelCowOrder, useCheckCowApproval, useCheckRouterApproval, useChunkSpreads, useClearTrackedPositions, useClosePosition as useClosePositionHook, useClosedPositions, useCollateralBreakdown, useCollateralData, useConfirmPendingPosition, useCowOrderStatus, useCurrentRates, useDeployNewPool as useDeployNewPoolHook, useDeposit as useDepositHook, useDispatch as useDispatchHook, useEstimateCollateralRequired, useEventPoller, useEventSubscription, useExecuteSettleSequence, useFactoryConstructMetadata, useFactoryOwnerOf, useFactoryTokenURI, useFailPendingPosition, useFlowNeutralTokenId, useForceExercise as useForceExerciseHook, useForfeitablePremium, useGuardianUnlockState, useInterestState, useIsLiquidatable, useLiquidate as useLiquidateHook, useLiquidationPrices, useMarginBuffer, useMaxPositionSize, useMaxRedeem, useMaxWithdrawable, useMinePoolAddress as useMinePoolAddressHook, useMintShares, useNativeTokenPrice, useNetLiquidationValue, useNetLiquidationValues, useOpenPosition as useOpenPositionHook, useOpenPositionPreview, useOptimizeRiskPartners, useOracleState, usePanopticContext, usePanopticPoolAddress, usePokeOracle as usePokeOracleHook, usePool, usePoolLiquidities, usePosition, usePositionGreeks, usePositions, usePositionsWithPremia, usePreviewBorrow, usePreviewDeposit, usePreviewMint, usePreviewRedeem, usePreviewWithdraw, usePriceHistory, useQuoteCowSwap, useQuoteSwapExactInViaRouter, useQuoteSwapExactOutViaRouter, useRealizedPnL, useRedeem as useRedeemHook, useRepay as useRepayHook, useResolveUniswapV4PoolKey, useRiskParameters, useRollPosition as useRollPositionHook, useSafeMode, useSettleAccumulatedPremia as useSettleAccumulatedPremiaHook, useSettlePremiumFrom as useSettlePremiumFromHook, useSimulateBatchDispatch, useSimulateClosePosition, useSimulateDeployNewPool, useSimulateDeposit, useSimulateDispatch, useSimulateForceExercise, useSimulateLiquidate, useSimulateOpenPosition, useSimulateSFPMBurn, useSimulateSFPMMint, useSimulateSettle, useSimulateSettlePremiumBatch, useSimulateSettlePremiumFrom, useSimulateSettleSequence, useSimulateSwapExactIn, useSimulateSwapExactOut, useSimulateWithdraw, useSmartRepay as useSmartRepayHook, useStreamiaHistory, useSubmitCowOrder, useSupply as useSupplyHook, useSwapExactIn, useSwapExactInViaRouter, useSwapExactOut, useSwapExactOutViaRouter, useSyncPositions, useSyncStatus, useTrackedPositionIds, useTradeHistory, useTxEventConfirmation, useUniswapFeeHistory, useUniswapV3PoolInfo, useUniswapV3PoolLiquidities, useUniswapV4PoolBasicState, useUniswapV4PoolInfo, useUniswapV4PoolLiquidities, useUnsupply as useUnsupplyHook, useUnwrapWeth, useUnwrapXstock, useUtilization, useValidateBuilderCode, useWatchEvents, useWithdraw as useWithdrawHook, useWithdrawWithPositions as useWithdrawWithPositionsHook, useWrapEth, useWrapXstock, utilizationBpsToWad, utilizationPctToWad, validateBatch, validateBuilderCode, validatePoolId, verifyBlockContinuity, watchEvents, wethWrapAbi, withdraw, withdrawAndWait, withdrawWithPositions, withdrawWithPositionsAndWait, wrapEth, wrapEthAndWait, wrapXstock, wrapXstockAndWait, xstockWrapperAbi };
|
|
35437
|
+
export { AccountInsolventError, AlreadyInitializedError, BORROW_INDEX_BITS, BPS_DENOMINATOR, BPS_SCALE, BatchValidationError, BelowMinimumRedemptionError, CastingError, ChunkHasZeroLiquidityError, ChunkLimitError, CrossPoolError, DEFAULT_MAX_SPREAD, DEFAULT_MINT_BUFFER, DEFAULT_MIN_SWAP_RATIO_BPS, DEFAULT_RECONNECT_CONFIG, DEFAULT_VEGOID, DepositTooLargeError, DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError, InputListFailError, InsufficientCreditLiquidityError, InvalidBuilderCodeError, InvalidHistoryRangeError, InvalidTickBoundError, InvalidTickError, InvalidTokenIdParameterError, InvalidUniswapCallbackError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LengthMismatchError, LiquidityTooHighError, LoanSlotExhaustedError, MARKET_EPOCH_BITS, MARKET_EPOCH_SHIFT, MAX_TICK, MAX_TRACKED_CHUNKS, MINT_BUFFER, MINT_BUFFER_DENOMINATOR, MIN_TICK, MaxRetriesExceededError, MissingPositionIdsError, NO_LOWER_LIQUIDATION_TICK, NO_UPPER_LIQUIDATION_TICK, NetLiquidityZeroError, NetworkMismatchError, NoLegsExercisableError, NotALongLegError, NotBuilderError, NotEnoughLiquidityInChunkError, NotEnoughTokensError, NotGuardianError, NotMarginCalledError, NotPanopticPoolError, ORACLE_EPOCH_SECONDS, OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError, PanopticProvider, PanopticValidationError, PoolNotInitializedError, PositionCountNotZeroError, PositionNotOwnedError, PositionSnapshotNotFoundError, PositionTooLargeError, PriceBoundFailError, PriceImpactTooLargeError, ProviderLagError, RATE_AT_TARGET_BITS, REORG_DEPTH, REQUIRED_BASE_ERROR_SENTINEL, ReentrancyError, RpcError, RpcResponseError, SCHEMA_VERSION, SECONDS_PER_YEAR, STANDARD_TICK_WIDTHS, STORAGE_PREFIX, STRIKE_LADDER_TARGET_STRIKES, SafeModeError, StaleDataError, StaleOracleError, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, TokenIdHasZeroLegsError, TooManyLegsOpenError, TransferFailedError, UNREALIZED_INTEREST_BITS, UTILIZATION_DENOMINATOR, UnauthorizedUniswapCallbackError, UnderOverFlowError, UnhealthyPoolError, UnsafePremiumSettlementError, WAD, WrongPoolIdError, WrongUniswapPoolError, ZERO_COLLATERAL, ZERO_VALUATION, ZeroAddressError, ZeroCollateralRequirementError, addLegToTokenId, addPendingPosition, addTrackedChunks, annualizePerSecondRateWad, applyMintBuffer, applyMintBufferPerToken, apportion, approve, approveAndWait, approvePool, assertCanBurn, assertCanForceExercise, assertCanLiquidate, assertCanMint, assertFresh, assertHealthy, assertTradeable, borrow, borrowAndWait, buildBatchDispatchArgs, buildCreditSwapCall, buildCreditWrappedDispatch, buildOpenPositionCalldata, buildProtectedSettleDispatch, buildProtectedSettlePlan, buildSettleSequenceCalls, buildSfpmSwapCalldata, buildSfpmSwapPlan, buildTemporaryLoanRecoveryDispatch, buildTokenShortfallRecoveryDispatch, buildUniqueCredit, buildUniqueLoan, buildUniqueWidthZeroLeg, calculateAccountGreeksPure, calculatePortfolioDelta, calculatePortfolioGamma, calculatePortfolioGreeks, calculatePortfolioValue, calculatePositionDelta, calculatePositionDeltaDebtOnly, calculatePositionDeltaWithSwap, calculatePositionGamma, calculatePositionGreeks, calculatePositionValue, calculateResyncBlock, calculateSpreadWad, cancelTransaction, checkApproval, checkCollateralAcrossTicks, classifyStrategyGroups, classifyStrike, cleanupStalePendingPositions, clearCheckpoint, clearPendingPositions, clearTrackedChunks, clearTrackedPositions, clearTradeHistory, closePosition, closePositionAndWait, collateralRuleKindFor, collateralTrackerV2Abi, computeV4PoolId, confirmPendingPosition, convertToAssets, convertToShares, countLegs, createEventPoller, createEventSubscription, createFileStorage, createFlowNeutralTokenId, createMemoryStorage, createNonceManager, createPoolFormatters, createTokenIdBuilder, decodeAllDispatchCalldata, decodeAllLegs, decodeDispatchCalldata, decodeLeftRightSigned, decodeLeftRightUnsigned, decodeLeg, decodeOraclePack, decodeOracleRiskParameters, decodeOracleTiming, decodePanopticTokenURI, decodePoolId, decodeTickSpacing, decodeTokenId, decodeVegoid, deployNewPool, deployNewPoolAndWait, deposit, depositAndWait, deriveSupplyRatePerSecWad, deriveUniqueTokenId, detectReorg, diagnoseOracleSafeMode, dispatch, dispatchAndWait, encodeLeg, encodePoolId, encodePoolKeyBytes, encodeV3PoolKeyBytes, encodeV4PoolId, ensureSfpmV3PoolInitialized, estimateBlockNumbers, estimateCollateralBreakdown, estimateCollateralRequired, executeBatchDispatch, executeBatchDispatchAndWait, executeSettleSequence, executeSettleSequenceAndWait, failPendingPosition, feesFromFeeGrowthDelta, fetchPoolId, fetchSfpmV3PoolId, forceExercise, forceExerciseAndWait, formatBlockNumber, formatBps, formatCompact, formatDatetime, formatDuration, formatDurationSeconds, formatFeeTier, formatGas, formatGwei, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatPoolIdHex, formatPriceRange, formatRateWad, formatRatioPercent, formatTick, formatTickRange, formatTimestamp, formatTimestampLocale, formatTokenAmount, formatTokenAmountSigned, formatTokenDelta, formatTokenFlow, formatTokenIdHex, formatTokenIdShort, formatTxHash, formatUtilization, formatWad, formatWadPercent, formatWadSigned, formatWei, generateOverlappingTokenIds, getAccountBuyingPower, getAccountCollateral, getAccountGreeks, getAccountHistory, getAccountPremia, getAccountSummaryBasic, getAccountSummaryRisk, getAssetIndex, getBlockMeta, getChainDeployment, getChunkLiquidities, getChunkSpreads, getClosedPositions, getClosedPositionsKey, getCollateralAddresses, getCollateralData, getCollateralSharePrices, getCollateralTotalAssetsBatch, getCurrentRates, getDeltaHedgeParams, getEnforcedTickLimits, getFactoryConstructMetadata, getFactoryOwnerOf, getFactoryTokenURI, getForfeitablePremium, getGuardianUnlockState, getInterestState, getIrmCurrent, getIrmCurve, getItmAmounts, getLegDelta, getLegDeltaInVaultFrame, getLegGamma, getLegNetValueWidth0, getLegValue, getLiquidationPrices, getMarginBuffer, getMaxPositionSize, getMaxRedeem, getMaxWithdrawable, getNativeTokenPrice, getNetLiquidationValue, getNetLiquidationValues, getNotEnoughTokensError, getOpenPositionIds, getOpenPositionPreview, getOracleRiskParameters, getOracleState, getPanopticPoolAddress, getPanopticPoolFromPoolId, getPendingPositions, getPendingPositionsKey, getPool, getPoolDeploymentBlock, getPoolDisplayId, getPoolLiquidities, getPoolMetaKey, getPoolMetadata, getPoolPrefix, getPortfolioValue, getPosition, getPositionChunkData, getPositionEnrichmentData, getPositionGreeks, getPositionMetaKey, getPositions, getPositionsKey, getPositionsWithPremia, getPriceHistory, getPricesAtTick, getRealizedPnL, getRequiredCreditForITM, getRiskParameters, getSafeMode, getSchemaVersionKey, getStreamiaHistory, getSyncCheckpointKey, getSyncStatus, getTickSpacing, getTokenListId, getTrackedChunks, getTrackedChunksKey, getTrackedPositionIds, getTradeHistory, getUniswapFeeHistory, getUniswapV3LpPositionState, getUniswapV3PoolFromId, getUniswapV3PoolInfo, getUniswapV3PoolLiquidities, getUniswapV4LpPositionState, getUniswapV4PoolBasicState, getUniswapV4PoolInfo, getUniswapV4PoolKeyFromId, getUniswapV4PoolLiquidities, getUtilization, hasLoanOrCredit, hasLongLeg, interpolateBlocks, isCall, isCowSupportedChain, isCredit, isCreditLeg, isDefinedRisk, isGasError, isInputListFailError, isLiquidatable, isLoan, isLoanLeg, isNonceError, isPanopticErrorType, isPositionTracked, isRetryableRpcError, isShortOnly, isSpread, isSupportedChain, isolateGroupTokenId, jsonSerializer, ladderStrikeSequence, liquidate, liquidateAndWait, loadCheckpoint, minePoolAddress, mint, mintAndWait, mintableAfterBuffer, multicallRead, mutationEffects, openPosition, openPositionAndWait, optimizeTokenIdRiskPartners, oracleEpochAt, orderListForSettle, packMarketState, panopticPoolV2Abi, parseBps, parseCollateralLog, parsePanopticError, parsePoolLog, parseTokenAmount, parseTokenListId, parseWad, planDeriveStrategy, pokeOracle, pokeOracleAndWait, previewBorrow, previewDeposit, previewMint, previewRedeem, previewUnwrap, previewWithdraw, previewWrap, priceToTick, publicBroadcaster, queryKeys, quoteOneTokenFlow, quoteSfpmSwap, quoteTemporaryLoanRecovery, quoteTokenShortfallRecovery, quoteV3ExactIn, ratePerSecWadToAprPct, reconstructFromEvents, recoverSnapshot, recoverSnapshotFromTx, redeem, redeemAndWait, removeTrackedChunks, repay, repayAndWait, requireChainDeployment, resolveBlockNumbers, resolveLadderStrike, resolvePanopticPoolFromPoolId, resolveTokenIndex, resolveUniswapV4PoolKey, riskEngineAbi, rollPosition, rollPositionAndWait, roundToTickSpacing, saveCheckpoint, saveClosedPosition, scanChunks, selectDispatchForAccount, settleAccumulatedPremia, settleAccumulatedPremiaAndWait, settlePremiumFrom, settlePremiumFromAndWait, simulateBatchDispatch, simulateClosePosition, simulateDeployNewPool, simulateDeposit, simulateDispatch, simulateForceExercise, simulateLiquidate, simulateOpenPosition, simulateSFPMBurn, simulateSFPMMint, simulateSettle, simulateSettlePremiumBatch, simulateSettlePremiumFrom, simulateSettleSequence, simulateSwapExactIn, simulateSwapExactOut, simulateWithTokenFlow, simulateWithdraw, slippageBpsToTickDistance, smartRepay, smartRepayAndWait, speedUpTransaction, splitTokenIdByTimescale, sqrtPriceX96ToPriceDecimalScaled, sqrtPriceX96ToTick, supply, supplyAndWait, swapExactIn, swapExactInAndWait, swapExactOut, swapExactOutAndWait, syncPositions, tickLimits, tickToPrice, tickToPriceDecimalScaled, tickToSqrtPriceX96, toVaultFrameAtTick, truncateAddress, unsupply, unsupplyAndWait, unwrapWeth, unwrapWethAndWait, unwrapXstock, unwrapXstockAndWait, useAccountCollateral, useAccountGreeks, useAccountPremia, useAccountSummaryBasic, useAccountSummaryRisk, useAddPendingPosition, useApprove, useApproveErc20ForCow, useApproveErc20ForPermit2, useApprovePool, useApproveRouterViaPermit2, useBatchDispatch as useBatchDispatchHook, useBorrow as useBorrowHook, useCancelCowOrder, useCheckCowApproval, useCheckRouterApproval, useChunkSpreads, useClearTrackedPositions, useClosePosition as useClosePositionHook, useClosedPositions, useCollateralBreakdown, useCollateralData, useConfirmPendingPosition, useCowOrderStatus, useCurrentRates, useDeployNewPool as useDeployNewPoolHook, useDeposit as useDepositHook, useDispatch as useDispatchHook, useEstimateCollateralRequired, useEventPoller, useEventSubscription, useExecuteSettleSequence, useFactoryConstructMetadata, useFactoryOwnerOf, useFactoryTokenURI, useFailPendingPosition, useFlowNeutralTokenId, useForceExercise as useForceExerciseHook, useForfeitablePremium, useGuardianUnlockState, useInterestState, useIsLiquidatable, useLiquidate as useLiquidateHook, useLiquidationPrices, useMarginBuffer, useMaxPositionSize, useMaxRedeem, useMaxWithdrawable, useMinePoolAddress as useMinePoolAddressHook, useMintShares, useNativeTokenPrice, useNetLiquidationValue, useNetLiquidationValues, useOpenPosition as useOpenPositionHook, useOpenPositionPreview, useOptimizeRiskPartners, useOracleState, usePanopticContext, usePanopticPoolAddress, usePokeOracle as usePokeOracleHook, usePool, usePoolLiquidities, usePosition, usePositionGreeks, usePositions, usePositionsWithPremia, usePreviewBorrow, usePreviewDeposit, usePreviewMint, usePreviewRedeem, usePreviewWithdraw, usePriceHistory, useQuoteCowSwap, useQuoteSwapExactInViaRouter, useQuoteSwapExactOutViaRouter, useRealizedPnL, useRedeem as useRedeemHook, useRepay as useRepayHook, useResolveUniswapV4PoolKey, useRiskParameters, useRollPosition as useRollPositionHook, useSafeMode, useSettleAccumulatedPremia as useSettleAccumulatedPremiaHook, useSettlePremiumFrom as useSettlePremiumFromHook, useSimulateBatchDispatch, useSimulateClosePosition, useSimulateDeployNewPool, useSimulateDeposit, useSimulateDispatch, useSimulateForceExercise, useSimulateLiquidate, useSimulateOpenPosition, useSimulateSFPMBurn, useSimulateSFPMMint, useSimulateSettle, useSimulateSettlePremiumBatch, useSimulateSettlePremiumFrom, useSimulateSettleSequence, useSimulateSwapExactIn, useSimulateSwapExactOut, useSimulateWithdraw, useSmartRepay as useSmartRepayHook, useStreamiaHistory, useSubmitCowOrder, useSupply as useSupplyHook, useSwapExactIn, useSwapExactInViaRouter, useSwapExactOut, useSwapExactOutViaRouter, useSyncPositions, useSyncStatus, useTrackedPositionIds, useTradeHistory, useTxEventConfirmation, useUniswapFeeHistory, useUniswapV3PoolInfo, useUniswapV3PoolLiquidities, useUniswapV4PoolBasicState, useUniswapV4PoolInfo, useUniswapV4PoolLiquidities, useUnsupply as useUnsupplyHook, useUnwrapWeth, useUnwrapXstock, useUtilization, useValidateBuilderCode, useWatchEvents, useWithdraw as useWithdrawHook, useWithdrawWithPositions as useWithdrawWithPositionsHook, useWrapEth, useWrapXstock, utilizationBpsToWad, utilizationPctToWad, validateBatch, validateBuilderCode, validatePoolId, verifyBlockContinuity, watchEvents, wethWrapAbi, withdraw, withdrawAndWait, withdrawWithPositions, withdrawWithPositionsAndWait, wrapEth, wrapEthAndWait, wrapXstock, wrapXstockAndWait, xstockWrapperAbi };
|
|
34802
35438
|
//# sourceMappingURL=react-public.js.map
|