timelock-sdk 0.0.77 → 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
 
@@ -780,6 +779,78 @@ const useSetOperatorPerms = (marketAddr) => {
780
779
  return useMutation({ mutationFn: setOperatorPerms });
781
780
  };
782
781
 
782
+ //#endregion
783
+ //#region src/hooks/market/useOptionTimeline.ts
784
+ const useOptionTimeline = (marketAddr, optionId) => {
785
+ const { graphqlClient } = useTimelockConfig();
786
+ marketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
787
+ const { data,...rest } = useQuery({
788
+ queryKey: [
789
+ "optionTimeline",
790
+ marketAddr || "--",
791
+ (optionId === null || optionId === void 0 ? void 0 : optionId.toString()) || "--"
792
+ ],
793
+ queryFn: async () => {
794
+ if (!graphqlClient || !marketAddr || optionId === void 0) return [];
795
+ const result = await graphqlClient.GetOptionEvents({
796
+ marketAddr,
797
+ optionId: optionId.toString()
798
+ });
799
+ const mintEvents = result.MintOptionEvent.map((event) => ({
800
+ id: event.id,
801
+ optionType: event.optionType,
802
+ strikeTick: event.strikeTick,
803
+ currentTick: event.currentTick,
804
+ expiresAt: /* @__PURE__ */ new Date(Number(event.expiresAt) * 1e3),
805
+ premium: BigInt(event.premium),
806
+ protocolFee: BigInt(event.protocolFee),
807
+ liquidities: event.liquidities.map((l) => BigInt(l)),
808
+ timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
809
+ blockNumber: BigInt(event.blockNumber),
810
+ transactionHash: event.transactionHash
811
+ }));
812
+ const exerciseEvents = result.ExerciseOptionEvent.map((event) => ({
813
+ id: event.id,
814
+ liquidities: event.liquidities.map((l) => BigInt(l)),
815
+ currentTick: event.currentTick,
816
+ payout: BigInt(event.payout),
817
+ timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
818
+ blockNumber: BigInt(event.blockNumber),
819
+ transactionHash: event.transactionHash
820
+ }));
821
+ const extendEvents = result.ExtendOptionEvent.map((event) => ({
822
+ id: event.id,
823
+ premium: BigInt(event.premium),
824
+ protocolFee: BigInt(event.protocolFee),
825
+ currentTick: event.currentTick,
826
+ addedDuration: BigInt(event.addedDuration),
827
+ timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
828
+ blockNumber: BigInt(event.blockNumber),
829
+ transactionHash: event.transactionHash
830
+ }));
831
+ return [
832
+ ...mintEvents.map((data$1) => ({
833
+ type: "mint",
834
+ data: data$1
835
+ })),
836
+ ...exerciseEvents.map((data$1) => ({
837
+ type: "exercise",
838
+ data: data$1
839
+ })),
840
+ ...extendEvents.map((data$1) => ({
841
+ type: "extend",
842
+ data: data$1
843
+ }))
844
+ ].sort((a, b) => a.data.timestamp.getTime() - b.data.timestamp.getTime());
845
+ },
846
+ enabled: !!marketAddr && optionId !== void 0 && !!graphqlClient
847
+ });
848
+ return {
849
+ data: data || EMPTY_ARRAY,
850
+ ...rest
851
+ };
852
+ };
853
+
783
854
  //#endregion
784
855
  //#region src/hooks/pool/usePriceAtTick.ts
785
856
  const usePriceAtTick = (tick, poolAddr) => {
@@ -1151,5 +1222,5 @@ const useVaultTVL = (vaultAddr) => {
1151
1222
  };
1152
1223
 
1153
1224
  //#endregion
1154
- export { TimelockMarketProvider, batchGetAmountsFromLiquidity, useActiveUserOptions, useApproval, useBurnLiquidity, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useOptionPnl, useOptionPremium, usePoolData, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useTimelockConfig, useUserOperators, useVaultData, useVaultTVL };
1225
+ export { TimelockMarketProvider, batchGetAmountsFromLiquidity, useActiveUserOptions, useApproval, useBurnLiquidity, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useOptionPnl, useOptionPremium, useOptionTimeline, usePoolData, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useTimelockConfig, useUserOperators, useVaultData, useVaultTVL };
1155
1226
  //# sourceMappingURL=client.js.map