timelock-sdk 0.0.128 → 0.0.129

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.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./uniswapMathLens-DtacRMPz.cjs";
2
- import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-BLEAyw98.cjs";
2
+ import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-Dxww1phu.cjs";
3
3
  export { ExerciseOptionEvent, ExtendEvent, LiquidityBlockData, MintOptionEvent, OptionData, OptionEvent, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMarketPriceHistory, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, usePriceSqrtPriceX96, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
package/dist/client.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./uniswapMathLens-JKcBN1v_.js";
2
- import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-BO26n70m.js";
2
+ import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-DrMMUpE7.js";
3
3
  export { ExerciseOptionEvent, ExtendEvent, LiquidityBlockData, MintOptionEvent, OptionData, OptionEvent, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMarketPriceHistory, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, usePriceSqrtPriceX96, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
package/dist/client.js CHANGED
@@ -569,21 +569,30 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) =>
569
569
  //#region src/hooks/pool/useCurrentTick.ts
570
570
  const useCurrentTick = (poolAddr) => {
571
571
  const { tickSpacing } = usePoolData(poolAddr);
572
- const { data } = useReadContract({
572
+ const { data,...rest } = useReadContract({
573
573
  address: poolAddr,
574
574
  abi: uniswapV3PoolAbi,
575
575
  functionName: "slot0",
576
- args: []
576
+ args: [],
577
+ query: {
578
+ refetchInterval: 3e3,
579
+ select: (raw) => {
580
+ const sqrtPriceX96 = raw === null || raw === void 0 ? void 0 : raw[0];
581
+ const exact = raw === null || raw === void 0 ? void 0 : raw[1];
582
+ return {
583
+ exact,
584
+ rounded: exact !== void 0 && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
585
+ sqrtPriceX96
586
+ };
587
+ }
588
+ }
577
589
  });
578
- return useMemo(() => {
579
- const sqrtPriceX96 = data === null || data === void 0 ? void 0 : data[0];
580
- const exact = data === null || data === void 0 ? void 0 : data[1];
581
- return {
582
- exact,
583
- rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
584
- sqrtPriceX96
585
- };
586
- }, [data, tickSpacing]);
590
+ return {
591
+ exact: data === null || data === void 0 ? void 0 : data.exact,
592
+ rounded: data === null || data === void 0 ? void 0 : data.rounded,
593
+ sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
594
+ ...rest
595
+ };
587
596
  };
588
597
 
589
598
  //#endregion
@@ -615,7 +624,7 @@ const useApproval = () => {
615
624
  const useMintOption = (marketAddr) => {
616
625
  const { payoutAsset, vault, pool, optionAssetIsToken0 } = useMarketData(marketAddr);
617
626
  const { tickSpacing } = usePoolData(pool);
618
- const { exact: currentTick } = useCurrentTick(pool);
627
+ const { refetch: refetchCurrentTick } = useCurrentTick(pool);
619
628
  const queryClient = useQueryClient();
620
629
  const client = useClient();
621
630
  const { address } = useAccount();
@@ -626,8 +635,10 @@ const useMintOption = (marketAddr) => {
626
635
  if (!client || !address) throw new Error("Wallet not connected");
627
636
  if (!marketAddr) throw new Error("Market address not available");
628
637
  if (!timelockLens) throw new Error("Timelock lens not available");
638
+ if (!tickSpacing) throw new Error("Pool data not available");
629
639
  if (!vault || !payoutAsset || optionAssetIsToken0 === void 0) throw new Error("Market data not available");
630
- if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
640
+ const { data: { exact: currentTick } = {} } = await refetchCurrentTick();
641
+ if (currentTick === void 0) throw new Error("Could not fetch current tick");
631
642
  strikeTick = getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
632
643
  const [premium, protocolFee] = await getTimelockMarket(marketAddr, client).read.calculatePremium([
633
644
  optionType === "CALL" ? 0 : 1,
@@ -1092,18 +1103,20 @@ const useMintPerp = (marketAddr) => {
1092
1103
  const { mutateAsync: setOperatorPerms } = useSetOperatorPerms(marketAddr);
1093
1104
  const { pool, optionAssetIsToken0, payoutAsset } = useMarketData(marketAddr);
1094
1105
  const { tickSpacing } = usePoolData(pool);
1095
- const { exact: currentTick } = useCurrentTick(pool);
1106
+ const { refetch: refetchCurrentTick } = useCurrentTick(pool);
1096
1107
  const userPerms = operatorAddr ? operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase()) : void 0;
1097
1108
  const hasEnoughPerms = userPerms && userPerms.canMint && userPerms.canExtend && userPerms.canExercise;
1098
1109
  const mintPerp = async (data) => {
1099
1110
  const { optionType, amount, duration, strikeTick } = data;
1100
1111
  if (!client || !address) throw new Error("Wallet not connected");
1101
1112
  if (!marketAddr) throw new Error("Market address not found");
1113
+ if (!tickSpacing) throw new Error("Pool data not found");
1102
1114
  if (!operator || !operatorAddr) throw new Error("Operator address not found");
1103
- if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
1104
1115
  if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
1105
1116
  if (!operator.auth) await signMessage();
1106
1117
  const market = getTimelockMarket(marketAddr, client);
1118
+ const { data: { exact: currentTick } = {} } = await refetchCurrentTick();
1119
+ if (currentTick === void 0) throw new Error("Could not fetch current tick");
1107
1120
  const validStrikeTick = getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
1108
1121
  const [premium, protocolFee] = await market.read.calculatePremium([
1109
1122
  optionType === "CALL" ? 0 : 1,