timelock-sdk 0.0.127 → 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.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
 
4
- const require_optionUtils = require('./optionUtils-uEYbxQWj.cjs');
4
+ const require_optionUtils = require('./optionUtils-BQIg6hnc.cjs');
5
5
  const require_optionsMarket = require('./optionsMarket-C8-v8IvX.cjs');
6
6
  const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
7
7
  let viem = require("viem");
@@ -571,21 +571,30 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) =>
571
571
  //#region src/hooks/pool/useCurrentTick.ts
572
572
  const useCurrentTick = (poolAddr) => {
573
573
  const { tickSpacing } = usePoolData(poolAddr);
574
- const { data } = (0, wagmi.useReadContract)({
574
+ const { data,...rest } = (0, wagmi.useReadContract)({
575
575
  address: poolAddr,
576
576
  abi: require_singleOwnerVault.uniswapV3PoolAbi,
577
577
  functionName: "slot0",
578
- args: []
578
+ args: [],
579
+ query: {
580
+ refetchInterval: 3e3,
581
+ select: (raw) => {
582
+ const sqrtPriceX96 = raw === null || raw === void 0 ? void 0 : raw[0];
583
+ const exact = raw === null || raw === void 0 ? void 0 : raw[1];
584
+ return {
585
+ exact,
586
+ rounded: exact !== void 0 && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
587
+ sqrtPriceX96
588
+ };
589
+ }
590
+ }
579
591
  });
580
- return (0, react.useMemo)(() => {
581
- const sqrtPriceX96 = data === null || data === void 0 ? void 0 : data[0];
582
- const exact = data === null || data === void 0 ? void 0 : data[1];
583
- return {
584
- exact,
585
- rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
586
- sqrtPriceX96
587
- };
588
- }, [data, tickSpacing]);
592
+ return {
593
+ exact: data === null || data === void 0 ? void 0 : data.exact,
594
+ rounded: data === null || data === void 0 ? void 0 : data.rounded,
595
+ sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
596
+ ...rest
597
+ };
589
598
  };
590
599
 
591
600
  //#endregion
@@ -617,7 +626,7 @@ const useApproval = () => {
617
626
  const useMintOption = (marketAddr) => {
618
627
  const { payoutAsset, vault, pool, optionAssetIsToken0 } = useMarketData(marketAddr);
619
628
  const { tickSpacing } = usePoolData(pool);
620
- const { exact: currentTick } = useCurrentTick(pool);
629
+ const { refetch: refetchCurrentTick } = useCurrentTick(pool);
621
630
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
622
631
  const client = (0, wagmi.useClient)();
623
632
  const { address } = (0, wagmi.useAccount)();
@@ -628,8 +637,10 @@ const useMintOption = (marketAddr) => {
628
637
  if (!client || !address) throw new Error("Wallet not connected");
629
638
  if (!marketAddr) throw new Error("Market address not available");
630
639
  if (!timelockLens) throw new Error("Timelock lens not available");
640
+ if (!tickSpacing) throw new Error("Pool data not available");
631
641
  if (!vault || !payoutAsset || optionAssetIsToken0 === void 0) throw new Error("Market data not available");
632
- if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
642
+ const { data: { exact: currentTick } = {} } = await refetchCurrentTick();
643
+ if (currentTick === void 0) throw new Error("Could not fetch current tick");
633
644
  strikeTick = require_optionUtils.getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
634
645
  const [premium, protocolFee] = await require_optionUtils.getTimelockMarket(marketAddr, client).read.calculatePremium([
635
646
  optionType === "CALL" ? 0 : 1,
@@ -1094,18 +1105,20 @@ const useMintPerp = (marketAddr) => {
1094
1105
  const { mutateAsync: setOperatorPerms } = useSetOperatorPerms(marketAddr);
1095
1106
  const { pool, optionAssetIsToken0, payoutAsset } = useMarketData(marketAddr);
1096
1107
  const { tickSpacing } = usePoolData(pool);
1097
- const { exact: currentTick } = useCurrentTick(pool);
1108
+ const { refetch: refetchCurrentTick } = useCurrentTick(pool);
1098
1109
  const userPerms = operatorAddr ? operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase()) : void 0;
1099
1110
  const hasEnoughPerms = userPerms && userPerms.canMint && userPerms.canExtend && userPerms.canExercise;
1100
1111
  const mintPerp = async (data) => {
1101
1112
  const { optionType, amount, duration, strikeTick } = data;
1102
1113
  if (!client || !address) throw new Error("Wallet not connected");
1103
1114
  if (!marketAddr) throw new Error("Market address not found");
1115
+ if (!tickSpacing) throw new Error("Pool data not found");
1104
1116
  if (!operator || !operatorAddr) throw new Error("Operator address not found");
1105
- if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
1106
1117
  if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
1107
1118
  if (!operator.auth) await signMessage();
1108
1119
  const market = require_optionUtils.getTimelockMarket(marketAddr, client);
1120
+ const { data: { exact: currentTick } = {} } = await refetchCurrentTick();
1121
+ if (currentTick === void 0) throw new Error("Could not fetch current tick");
1109
1122
  const validStrikeTick = require_optionUtils.getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
1110
1123
  const [premium, protocolFee] = await market.read.calculatePremium([
1111
1124
  optionType === "CALL" ? 0 : 1,