timelock-sdk 0.0.78 → 0.0.79

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/client.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-6PlyceXp.js";
5
- import { A as timelockLenses, D as getTimelockLens, E as getErc20, O as getTimelockMarket, S as roundTickDown, T as token1ToToken0, _ as getPriceAtTick, d as wrapPrice, g as getNearestValidStrikeTick, j as uniswapMathLenses, k as getUniswapMathLens, l as wrapAmount, m as PRICE_PRECISION, w as token0ToToken1, x as liquiditiesToAmounts } from "./numberUtils--YU8VSJO.js";
5
+ import { A as getTimelockMarket, D as token1ToToken0, E as token0ToToken1, M as timelockLenses, N as uniswapMathLenses, O as getErc20, d as wrapAmount, j as getUniswapMathLens, k as getTimelockLens, n as EMPTY_ARRAY, p as wrapPrice, t as getPayoutAtTick, v as getNearestValidStrikeTick, w as roundTickDown, y as getPriceAtTick } from "./optionUtils-CI-AZi8X.js";
6
6
  import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
7
7
  import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
8
8
  import React, { createContext, useContext, useMemo } from "react";
@@ -548,15 +548,16 @@ const useMintOption = (marketAddr) => {
548
548
  //#endregion
549
549
  //#region src/hooks/market/useOptionPnl.ts
550
550
  const useOptionPnl = (option) => {
551
- const { marketAddr, optionType, strikePrice, positionSizeCurrent } = option;
551
+ const { marketAddr, optionType, entryTick, positionSizeCurrent } = option;
552
552
  const { pool, optionAssetIsToken0, payoutAssetDecimals, tickSpacing } = useMarketData(marketAddr);
553
553
  const { exact: currentTick } = useCurrentTick(pool);
554
- const strikeSize = positionSizeCurrent * strikePrice / PRICE_PRECISION;
555
554
  const displayPnl = useMemo(() => {
556
- if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !positionSizeCurrent || !payoutAssetDecimals) return void 0;
557
- const delta = (optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, currentTick) : token1ToToken0(positionSizeCurrent, currentTick)) - strikeSize;
555
+ if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !payoutAssetDecimals) return void 0;
556
+ const entrySize = optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, entryTick) : token1ToToken0(positionSizeCurrent, entryTick);
557
+ const delta = (optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, currentTick) : token1ToToken0(positionSizeCurrent, currentTick)) - entrySize;
558
558
  return wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
559
559
  }, [
560
+ entryTick,
560
561
  optionType,
561
562
  optionAssetIsToken0,
562
563
  currentTick,
@@ -565,16 +566,14 @@ const useOptionPnl = (option) => {
565
566
  ]);
566
567
  return {
567
568
  unrealizedPayout: useMemo(() => {
568
- if (!payoutAssetDecimals || !currentTick || !tickSpacing) return void 0;
569
- const [amount0, amount1] = liquiditiesToAmounts(option.liquiditiesCurrent, option.startTick, currentTick, tickSpacing);
570
- const delta = (optionAssetIsToken0 ? amount1 + token0ToToken1(amount0, currentTick) : amount0 + token1ToToken0(amount1, currentTick)) - strikeSize;
571
- const pnl = optionType === "CALL" ? delta : -delta;
572
- return wrapAmount(pnl < 0 ? 0n : pnl, payoutAssetDecimals);
569
+ if (!payoutAssetDecimals || !currentTick || !tickSpacing || optionAssetIsToken0 === void 0) return void 0;
570
+ return wrapAmount(getPayoutAtTick(option, option.liquiditiesCurrent, currentTick, tickSpacing, optionAssetIsToken0), payoutAssetDecimals);
573
571
  }, [
574
572
  currentTick,
575
573
  tickSpacing,
576
574
  optionType,
577
- payoutAssetDecimals
575
+ payoutAssetDecimals,
576
+ optionAssetIsToken0
578
577
  ]),
579
578
  displayPnl
580
579
  };
@@ -667,7 +666,7 @@ const useUserOptions = (userAddr, marketAddr, active = false) => {
667
666
  enabled: !!userAddr && !!marketAddr && !!graphqlClient
668
667
  });
669
668
  return {
670
- data: data || [],
669
+ data: data || EMPTY_ARRAY,
671
670
  ...rest
672
671
  };
673
672
  };
@@ -742,7 +741,7 @@ const useUserOperators = (userAddr, marketAddr) => {
742
741
  });
743
742
  return {
744
743
  ...rest,
745
- data: data || []
744
+ data: data || EMPTY_ARRAY
746
745
  };
747
746
  };
748
747
 
@@ -784,17 +783,17 @@ const useSetOperatorPerms = (marketAddr) => {
784
783
  //#region src/hooks/market/useOptionTimeline.ts
785
784
  const useOptionTimeline = (marketAddr, optionId) => {
786
785
  const { graphqlClient } = useTimelockConfig();
787
- const normalizedMarketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
786
+ marketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
788
787
  const { data,...rest } = useQuery({
789
788
  queryKey: [
790
789
  "optionTimeline",
791
- normalizedMarketAddr || "--",
790
+ marketAddr || "--",
792
791
  (optionId === null || optionId === void 0 ? void 0 : optionId.toString()) || "--"
793
792
  ],
794
793
  queryFn: async () => {
795
- if (!graphqlClient || !normalizedMarketAddr || optionId === void 0) return [];
794
+ if (!graphqlClient || !marketAddr || optionId === void 0) return [];
796
795
  const result = await graphqlClient.GetOptionEvents({
797
- marketAddr: normalizedMarketAddr,
796
+ marketAddr,
798
797
  optionId: optionId.toString()
799
798
  });
800
799
  const mintEvents = result.MintOptionEvent.map((event) => ({
@@ -844,10 +843,10 @@ const useOptionTimeline = (marketAddr, optionId) => {
844
843
  }))
845
844
  ].sort((a, b) => a.data.timestamp.getTime() - b.data.timestamp.getTime());
846
845
  },
847
- enabled: !!normalizedMarketAddr && optionId !== void 0 && !!graphqlClient
846
+ enabled: !!marketAddr && optionId !== void 0 && !!graphqlClient
848
847
  });
849
848
  return {
850
- data: data || [],
849
+ data: data || EMPTY_ARRAY,
851
850
  ...rest
852
851
  };
853
852
  };