@panoptic-eng/sdk 1.0.44 → 1.0.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { BatchValidationError, DEFAULT_VEGOID, InputListFailError, InvalidTickLimitsError, InvalidTokenIdParameterError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LoanSlotExhaustedError, MaxRetriesExceededError, MissingPositionIdsError, NoLoanPositionsError, OracleRateLimitedError, PanopticError, PositionSnapshotNotFoundError, ProviderLagError, STRIKE_CONVERSION_FACTOR, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, collateralTrackerV2Abi, createTxResult, decodeLeftRightUnsigned, decodeOracleTiming, getBlockMeta, getOpenPositionIds, getPool, getPoolMetaKey, getPoolMetadata, getPositionMetaKey, getPositions, getPositionsKey, getSyncCheckpointKey, getTrackedPositionIds, jsonSerializer, oracleEpochAt, panopticErrorsAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticPoolV2Abi, parsePanopticError, submitWrite } from "./getTrackedPositionIds-ms3W9dYB.js";
2
- import { REORG_DEPTH, calculatePositionGreeks, tickLimits } from "./greeks-GysWXct-.js";
1
+ import { BatchValidationError, DEFAULT_VEGOID, InputListFailError, InvalidTickLimitsError, InvalidTokenIdParameterError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LoanSlotExhaustedError, MaxRetriesExceededError, MissingPositionIdsError, NoLoanPositionsError, OracleRateLimitedError, PanopticError, PositionSnapshotNotFoundError, ProviderLagError, STRIKE_CONVERSION_FACTOR, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, collateralTrackerV2Abi, createTxResult, decodeLeftRightUnsigned, decodeOracleTiming, getBlockMeta, getOpenPositionIds, getPool, getPoolMetaKey, getPoolMetadata, getPositionMetaKey, getPositions, getPositionsKey, getSyncCheckpointKey, getTrackedPositionIds, jsonSerializer, oracleEpochAt, panopticErrorsAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticPoolV2Abi, parsePanopticError, submitWrite } from "./getTrackedPositionIds-BwBtLpz-.js";
2
+ import { REORG_DEPTH, calculatePositionGreeks, tickLimits } from "./greeks-9aTE-DwO.js";
3
3
  import { decodeFunctionResult, encodeFunctionData, erc20Abi, getAbiItem } from "viem";
4
4
 
5
5
  //#region src/panoptic/v2/writes/broadcaster.ts
@@ -851,7 +851,7 @@ async function executeBatchDispatchAndWait(params) {
851
851
  * ```
852
852
  */
853
853
  async function liquidate(params) {
854
- const { client, walletClient, account, poolAddress, liquidatee, positionIdListFrom, positionIdListTo, positionIdListToFinal, usePremiaAsCollateral = 0n, txOverrides } = params;
854
+ const { client, walletClient, account, poolAddress, liquidatee, positionIdListFrom, positionIdListTo, positionIdListToFinal, usePremiaAsCollateral = 0n, value, txOverrides } = params;
855
855
  return submitWrite({
856
856
  client,
857
857
  walletClient,
@@ -866,6 +866,7 @@ async function liquidate(params) {
866
866
  positionIdListToFinal,
867
867
  usePremiaAsCollateral
868
868
  ],
869
+ value,
869
870
  txOverrides
870
871
  });
871
872
  }
@@ -1379,6 +1380,197 @@ async function forceExerciseAndWait(params) {
1379
1380
  return receipt;
1380
1381
  }
1381
1382
 
1383
+ //#endregion
1384
+ //#region src/panoptic/v2/writes/settlePremiumFrom.ts
1385
+ /**
1386
+ * Reorder a position ID list so `tokenId` is the last element.
1387
+ *
1388
+ * The position list fingerprint is an XOR hash, so ordering is free to change.
1389
+ * The contract settles premium on the last element of `positionIdListTo`.
1390
+ *
1391
+ * @throws PanopticError if `tokenId` is not in the list
1392
+ */
1393
+ function orderListForSettle(positionIdList, tokenId) {
1394
+ if (!positionIdList.includes(tokenId)) throw new PanopticError("tokenId to settle is not in the target position list");
1395
+ return [...positionIdList.filter((id) => id !== tokenId), tokenId];
1396
+ }
1397
+ /**
1398
+ * Settle another account's accumulated long premium.
1399
+ *
1400
+ * Calls `dispatchFrom` with the target's position list passed as both
1401
+ * `positionIdListTo` and `positionIdListToFinal` (equal lengths select the
1402
+ * settle-premium mode and cannot force-exercise or liquidate). Requires the
1403
+ * target account to be solvent; the settled premium is credited to the
1404
+ * sellers of the corresponding chunks.
1405
+ *
1406
+ * @param params - Settle premium parameters
1407
+ * @returns TxResult
1408
+ *
1409
+ * @example
1410
+ * ```typescript
1411
+ * const result = await settlePremiumFrom({
1412
+ * client,
1413
+ * walletClient,
1414
+ * account: sellerAddress,
1415
+ * poolAddress,
1416
+ * user: buyerAccount,
1417
+ * positionIdListFrom: sellerPositions,
1418
+ * positionIdList: buyerPositions,
1419
+ * })
1420
+ * const receipt = await result.wait()
1421
+ * ```
1422
+ */
1423
+ async function settlePremiumFrom(params) {
1424
+ const { client, walletClient, account, poolAddress, user, positionIdListFrom, positionIdList, tokenId, usePremiaAsCollateral = 0n, txOverrides } = params;
1425
+ const orderedList = tokenId !== void 0 ? orderListForSettle(positionIdList, tokenId) : positionIdList;
1426
+ return submitWrite({
1427
+ client,
1428
+ walletClient,
1429
+ account,
1430
+ address: poolAddress,
1431
+ abi: panopticPoolV2Abi,
1432
+ functionName: "dispatchFrom",
1433
+ args: [
1434
+ positionIdListFrom,
1435
+ user,
1436
+ orderedList,
1437
+ orderedList,
1438
+ usePremiaAsCollateral
1439
+ ],
1440
+ txOverrides
1441
+ });
1442
+ }
1443
+ /**
1444
+ * Settle another account's premium and wait for confirmation.
1445
+ *
1446
+ * When `storage` and `chainId` are provided, automatically syncs the
1447
+ * caller's positions after the transaction confirms.
1448
+ */
1449
+ async function settlePremiumFromAndWait(params) {
1450
+ const result = await settlePremiumFrom(params);
1451
+ const receipt = await result.wait();
1452
+ const { storage, chainId, client, poolAddress, account } = params;
1453
+ if (storage && chainId !== void 0) await syncPositions({
1454
+ client,
1455
+ chainId,
1456
+ poolAddress,
1457
+ account,
1458
+ storage
1459
+ });
1460
+ return receipt;
1461
+ }
1462
+
1463
+ //#endregion
1464
+ //#region src/panoptic/v2/writes/settleSequence.ts
1465
+ /**
1466
+ * Build the encoded PanopticPool calls for a settle sequence: one settle-mode
1467
+ * `dispatchFrom` per target (equal To/ToFinal lists, settled tokenId last),
1468
+ * then the caller's own close `dispatch` when provided.
1469
+ *
1470
+ * A pure settle changes no position list, so targets need no cross-call
1471
+ * bookkeeping (unlike a force-exercise sequence).
1472
+ */
1473
+ function buildSettleSequenceCalls(params) {
1474
+ const { positionIdListFrom, targets, close, dispatch: dispatch$1, usePremiaAsCollateral = 0n } = params;
1475
+ if (close !== void 0 && dispatch$1 !== void 0) throw new PanopticError("SettleSequence: provide either `close` or `dispatch`, not both");
1476
+ if (targets.length === 0 && close === void 0 && dispatch$1 === void 0) throw new PanopticError("SettleSequence: nothing to do (no targets, close, or dispatch)");
1477
+ const calls = targets.map((target) => {
1478
+ const orderedList = orderListForSettle(target.positionIdList, target.tokenId);
1479
+ return encodeFunctionData({
1480
+ abi: panopticPoolV2Abi,
1481
+ functionName: "dispatchFrom",
1482
+ args: [
1483
+ positionIdListFrom,
1484
+ target.user,
1485
+ orderedList,
1486
+ orderedList,
1487
+ usePremiaAsCollateral
1488
+ ]
1489
+ });
1490
+ });
1491
+ if (close !== void 0) {
1492
+ const { tokenId, finalPositionIdList, tickLimitLow, tickLimitHigh, spreadLimit = 0n, swapAtMint = false, usePremiaAsCollateral: closeUsePremia = false, builderCode = 0n } = close;
1493
+ const tickLimits$1 = swapAtMint ? [
1494
+ Number(tickLimitHigh),
1495
+ Number(tickLimitLow),
1496
+ Number(spreadLimit)
1497
+ ] : [
1498
+ Number(tickLimitLow),
1499
+ Number(tickLimitHigh),
1500
+ Number(spreadLimit)
1501
+ ];
1502
+ calls.push(encodeFunctionData({
1503
+ abi: panopticPoolV2Abi,
1504
+ functionName: "dispatch",
1505
+ args: [
1506
+ [tokenId],
1507
+ finalPositionIdList,
1508
+ [0n],
1509
+ [tickLimits$1],
1510
+ closeUsePremia,
1511
+ builderCode
1512
+ ]
1513
+ }));
1514
+ }
1515
+ if (dispatch$1 !== void 0) calls.push(encodeFunctionData({
1516
+ abi: panopticPoolV2Abi,
1517
+ functionName: "dispatch",
1518
+ args: [
1519
+ dispatch$1.positionIdList,
1520
+ dispatch$1.finalPositionIdList,
1521
+ dispatch$1.positionSizes,
1522
+ dispatch$1.tickAndSpreadLimits.map((t) => [
1523
+ Number(t[0]),
1524
+ Number(t[1]),
1525
+ Number(t[2])
1526
+ ]),
1527
+ dispatch$1.usePremiaAsCollateral,
1528
+ dispatch$1.builderCode
1529
+ ]
1530
+ }));
1531
+ return calls;
1532
+ }
1533
+ /**
1534
+ * Execute a settle sequence: settle each target buyer's owed long premium,
1535
+ * then optionally close the caller's own position, in one multicall.
1536
+ *
1537
+ * @param params - Settle sequence parameters
1538
+ * @returns TxResult
1539
+ */
1540
+ async function executeSettleSequence(params) {
1541
+ const { client, walletClient, account, poolAddress, txOverrides } = params;
1542
+ const calls = buildSettleSequenceCalls(params);
1543
+ return submitWrite({
1544
+ client,
1545
+ walletClient,
1546
+ account,
1547
+ address: poolAddress,
1548
+ abi: panopticPoolV2Abi,
1549
+ functionName: "multicall",
1550
+ args: [calls],
1551
+ txOverrides
1552
+ });
1553
+ }
1554
+ /**
1555
+ * Execute a settle sequence and wait for confirmation.
1556
+ *
1557
+ * When `storage` and `chainId` are provided, automatically syncs the
1558
+ * caller's positions after the transaction confirms.
1559
+ */
1560
+ async function executeSettleSequenceAndWait(params) {
1561
+ const result = await executeSettleSequence(params);
1562
+ const receipt = await result.wait();
1563
+ const { storage, chainId, client, poolAddress, account } = params;
1564
+ if (storage && chainId !== void 0) await syncPositions({
1565
+ client,
1566
+ chainId,
1567
+ poolAddress,
1568
+ account,
1569
+ storage
1570
+ });
1571
+ return receipt;
1572
+ }
1573
+
1382
1574
  //#endregion
1383
1575
  //#region src/panoptic/v2/reads/positionSizes.ts
1384
1576
  const BIT_MASK_128 = (1n << 128n) - 1n;
@@ -3637,4 +3829,4 @@ async function smartRepayAndWait(params) {
3637
3829
  }
3638
3830
 
3639
3831
  //#endregion
3640
- export { addLegToTokenId, approve, approveAndWait, approvePool, borrow, borrowAndWait, buildBatchDispatchArgs, buildCreditSwapCall, buildOpenPositionCalldata, buildUniqueCredit, buildUniqueLoan, buildUniqueWidthZeroLeg, calculateResyncBlock, cancelTransaction, checkApproval, clearCheckpoint, closePosition, closePositionAndWait, countLegs, createNonceManager, createTokenIdBuilder, decodeAllLegs, decodeLeg, decodePoolId, decodeTickSpacing as decodeTickSpacing$1, decodeTokenId, decodeVegoid, deployNewPool, deployNewPoolAndWait, deposit, depositAndWait, detectReorg, dispatch, dispatchAndWait, encodeLeg, encodePoolId, encodeV4PoolId, executeBatchDispatch, executeBatchDispatchAndWait, forceExercise, forceExerciseAndWait, getAssetIndex, getCurrentPositionSizes, getPoolDeploymentBlock, getPoolTokensForSimulation, hasLoanOrCredit, hasLongLeg, isCredit, isCreditLeg, isInputListFailError, isLoan, isLoanLeg, isShortOnly, isSpread, liquidate, liquidateAndWait, loadCheckpoint, mint, mintAndWait, openPosition, openPositionAndWait, pokeOracle, pokeOracleAndWait, previewBorrow, previewUnwrap, previewWrap, publicBroadcaster, reconstructFromEvents, redeem, redeemAndWait, repay, repayAndWait, resolveTokenIndex, rollPosition, rollPositionAndWait, saveCheckpoint, settleAccumulatedPremia, settleAccumulatedPremiaAndWait, simulateOpenPosition, simulateWithTokenFlow, smartRepay, smartRepayAndWait, speedUpTransaction, supply, supplyAndWait, swapExactIn, swapExactInAndWait, swapExactOut, swapExactOutAndWait, syncPositions, unsupply, unsupplyAndWait, unwrapWeth, unwrapWethAndWait, unwrapXstock, unwrapXstockAndWait, validateBatch, validatePoolId, verifyBlockContinuity, wethWrapAbi, withdraw, withdrawAndWait, withdrawWithPositions, withdrawWithPositionsAndWait, wrapEth, wrapEthAndWait, wrapXstock, wrapXstockAndWait, xstockWrapperAbi };
3832
+ export { addLegToTokenId, approve, approveAndWait, approvePool, borrow, borrowAndWait, buildBatchDispatchArgs, buildCreditSwapCall, buildOpenPositionCalldata, buildSettleSequenceCalls, buildUniqueCredit, buildUniqueLoan, buildUniqueWidthZeroLeg, calculateResyncBlock, cancelTransaction, checkApproval, clearCheckpoint, closePosition, closePositionAndWait, countLegs, createNonceManager, createTokenIdBuilder, decodeAllLegs, decodeLeg, decodePoolId, decodeTickSpacing as decodeTickSpacing$1, decodeTokenId, decodeVegoid, deployNewPool, deployNewPoolAndWait, deposit, depositAndWait, detectReorg, dispatch, dispatchAndWait, encodeLeg, encodePoolId, encodeV4PoolId, executeBatchDispatch, executeBatchDispatchAndWait, executeSettleSequence, executeSettleSequenceAndWait, forceExercise, forceExerciseAndWait, getAssetIndex, getCurrentPositionSizes, getPoolDeploymentBlock, getPoolTokensForSimulation, hasLoanOrCredit, hasLongLeg, isCredit, isCreditLeg, isInputListFailError, isLoan, isLoanLeg, isShortOnly, isSpread, liquidate, liquidateAndWait, loadCheckpoint, mint, mintAndWait, openPosition, openPositionAndWait, orderListForSettle, pokeOracle, pokeOracleAndWait, previewBorrow, previewUnwrap, previewWrap, publicBroadcaster, reconstructFromEvents, redeem, redeemAndWait, repay, repayAndWait, resolveTokenIndex, rollPosition, rollPositionAndWait, saveCheckpoint, settleAccumulatedPremia, settleAccumulatedPremiaAndWait, settlePremiumFrom, settlePremiumFromAndWait, simulateOpenPosition, simulateWithTokenFlow, smartRepay, smartRepayAndWait, speedUpTransaction, supply, supplyAndWait, swapExactIn, swapExactInAndWait, swapExactOut, swapExactOutAndWait, syncPositions, unsupply, unsupplyAndWait, unwrapWeth, unwrapWethAndWait, unwrapXstock, unwrapXstockAndWait, validateBatch, validatePoolId, verifyBlockContinuity, wethWrapAbi, withdraw, withdrawAndWait, withdrawWithPositions, withdrawWithPositionsAndWait, wrapEth, wrapEthAndWait, wrapXstock, wrapXstockAndWait, xstockWrapperAbi };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoptic-eng/sdk",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/panoptic-labs/panoptic-sdk.git"