timelock-sdk 0.0.144 → 0.0.145

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-X6H7QwrK.cjs";
2
- import { $ as ExerciseOptionEvent, At as TimelockProvider, Dt as OptionData, Et as useExerciseOption, G as useUserOperators, J as useClosedUserPerps, K as useOperatorPerms, Mt as useTimelockConfig, Ot as useActiveUserOptions, Q as useMintPerp, Tt as useMarketData, W as useSetOperatorPerms, X as usePerpsOperator, Y as useUserPerps, Z as useClosePerp, _ as useCurrentTick, a as useTokenData, at as useOptionPremium, b as UniswapPoolData, c as batchGetAmountsFromLiquidity, ct as useMaxPositionSize, d as useLiquidityBlocks, et as ExtendEvent, f as useBurnLiquidity, g as usePriceAtTick, h as usePriceAtSqrtPriceX96, i as TokenData, it as useExtendOption, jt as useCurrentMarket, kt as useClosedUserOptions, l as useMintLiquidity, m as usePriceHistory, n as useApproval, nt as OptionEvent, o as useVaultTVL, ot as useOptionPnl, p as useMarketPriceHistory, q as useActiveUserPerps, r as useTokenBalance, rt as useOptionTimeline, s as useVaultData, st as useMintOption, t as useLens, tt as MintOptionEvent, u as LiquidityBlockData, v as useCurrentPrice, wt as useMarketVolume, x as usePoolData, y as PoolKey } from "./client-BRzenCT7.cjs";
2
+ import { $ as ExerciseOptionEvent, At as TimelockProvider, Dt as OptionData, Et as useExerciseOption, G as useUserOperators, J as useClosedUserPerps, K as useOperatorPerms, Mt as useTimelockConfig, Ot as useActiveUserOptions, Q as useMintPerp, Tt as useMarketData, W as useSetOperatorPerms, X as usePerpsOperator, Y as useUserPerps, Z as useClosePerp, _ as useCurrentTick, a as useTokenData, at as useOptionPremium, b as UniswapPoolData, c as batchGetAmountsFromLiquidity, ct as useMaxPositionSize, d as useLiquidityBlocks, et as ExtendEvent, f as useBurnLiquidity, g as usePriceAtTick, h as usePriceAtSqrtPriceX96, i as TokenData, it as useExtendOption, jt as useCurrentMarket, kt as useClosedUserOptions, l as useMintLiquidity, m as usePriceHistory, n as useApproval, nt as OptionEvent, o as useVaultTVL, ot as useOptionPnl, p as useMarketPriceHistory, q as useActiveUserPerps, r as useTokenBalance, rt as useOptionTimeline, s as useVaultData, st as useMintOption, t as useLens, tt as MintOptionEvent, u as LiquidityBlockData, v as useCurrentPrice, wt as useMarketVolume, x as usePoolData, y as PoolKey } from "./client-B7N77R-L.cjs";
3
3
  export { ExerciseOptionEvent, ExtendEvent, LiquidityBlockData, MintOptionEvent, OptionData, OptionEvent, PoolKey, TimelockProvider, TokenData, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMarketPriceHistory, useMarketVolume, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtSqrtPriceX96, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useTimelockConfig, useTokenBalance, useTokenData, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
package/dist/client.js CHANGED
@@ -4,13 +4,14 @@
4
4
  import { i as erc20Abi$1, r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-DpvbjVFL.js";
5
5
  import { A as token1ToToken0, B as swappers, D as roundTick, F as getStateView, H as statelessStateViewAbi, I as getTimelockLens, L as getTimelockMarket, N as getPriceHistory, O as token0ToToken1, P as getErc20, b as getPriceAtSqrtPriceX96, f as wrapAmount, j as token1ToToken0AtTick, k as token0ToToken1AtTick, m as wrapPrice, r as EMPTY_ARRAY, t as getPayoutAtPrice, v as getAmountsFromLiquidity, x as getPriceAtTick, y as getNearestValidStrikeTick } from "./optionUtils-DuJzVAs5.js";
6
6
  import { t as singleOwnerVaultAbi } from "./singleOwnerVault-BJyEs_D_.js";
7
- import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint160, maxUint256, zeroAddress } from "viem";
7
+ import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
8
8
  import React, { createContext, useContext, useEffect, useMemo } from "react";
9
9
  import { GraphQLClient, RequestOptions } from "graphql-request";
10
10
  import gql from "graphql-tag";
11
11
  import { waitForTransactionReceipt } from "viem/actions";
12
12
  import { useChainId, useClient, useConnection, useReadContract, useSignMessage, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
13
13
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
14
+ import "zod/v4/locales";
14
15
  import { z } from "zod";
15
16
 
16
17
  //#region src/generated/graphql.ts
@@ -487,6 +488,98 @@ const useMarketData = (marketAddr) => {
487
488
  return data || fallback || {};
488
489
  };
489
490
 
491
+ //#endregion
492
+ //#region src/hooks/pool/usePoolData.ts
493
+ const usePoolData = (poolManager, poolKey) => {
494
+ const { timelockLens } = useLens();
495
+ const { data } = useReadContract({
496
+ address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
497
+ abi: lensAbi,
498
+ functionName: "getPoolData",
499
+ args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
500
+ query: { enabled: !!poolManager && !!poolKey }
501
+ });
502
+ const _default = useMemo(() => ({
503
+ token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
504
+ token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
505
+ tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
506
+ fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
507
+ }), [poolKey]);
508
+ return data || _default;
509
+ };
510
+
511
+ //#endregion
512
+ //#region src/hooks/pool/usePriceAtTick.ts
513
+ const usePriceAtTick = (poolManager, poolKey, tick) => {
514
+ const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
515
+ const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
516
+ return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
517
+ priceBigInt,
518
+ token0Decimals,
519
+ token1Decimals
520
+ ]);
521
+ };
522
+ const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
523
+ const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
524
+ const priceBigInt = useMemo(() => sqrtPriceX96 !== void 0 ? getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
525
+ return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
526
+ priceBigInt,
527
+ token0Decimals,
528
+ token1Decimals
529
+ ]);
530
+ };
531
+
532
+ //#endregion
533
+ //#region src/hooks/pool/useCurrentTick.ts
534
+ const useCurrentTick = (poolManager, poolKey) => {
535
+ const { stateView } = useLens();
536
+ const { tickSpacing } = usePoolData(poolManager, poolKey);
537
+ const { data, ...rest } = useReadContract({
538
+ address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
539
+ abi: statelessStateViewAbi,
540
+ functionName: "getSlot0",
541
+ args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
542
+ query: {
543
+ enabled: !!poolManager && !!poolKey,
544
+ refetchInterval: 3e3,
545
+ select: (raw) => {
546
+ const sqrtPriceX96 = raw[0];
547
+ const exact = raw[1];
548
+ return {
549
+ exact,
550
+ rounded: tickSpacing ? roundTick(exact, tickSpacing) : void 0,
551
+ sqrtPriceX96
552
+ };
553
+ }
554
+ }
555
+ });
556
+ return {
557
+ exact: data === null || data === void 0 ? void 0 : data.exact,
558
+ rounded: data === null || data === void 0 ? void 0 : data.rounded,
559
+ sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
560
+ ...rest
561
+ };
562
+ };
563
+
564
+ //#endregion
565
+ //#region src/hooks/pool/useCurrentPrice.ts
566
+ const useCurrentPrice = (poolManager, poolKey) => {
567
+ const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
568
+ const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
569
+ return useMemo(() => ({
570
+ currentPrice,
571
+ sqrtPriceX96,
572
+ currentTick: {
573
+ exact,
574
+ rounded
575
+ }
576
+ }), [
577
+ currentPrice,
578
+ exact,
579
+ rounded
580
+ ]);
581
+ };
582
+
490
583
  //#endregion
491
584
  //#region src/lib/utils.ts
492
585
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -500,14 +593,18 @@ const useExerciseOption = (marketAddr) => {
500
593
  const client = useClient();
501
594
  const { address } = useConnection();
502
595
  const { writeContractAsync } = useWriteContract();
596
+ const { sqrtPriceX96 } = useCurrentPrice();
503
597
  const exerciseOption = async ({ option, liquidities }) => {
504
598
  if (!client || !address) throw new Error("Wallet not connected");
505
599
  if (!marketAddr) throw new Error("Market address not available");
506
600
  if (!timelockLens) throw new Error("Timelock lens not available");
507
601
  if (!vault) throw new Error("Vault not available");
508
602
  if (!poolKey) throw new Error("Pool data not available");
603
+ if (!sqrtPriceX96) throw new Error("Current price not available");
509
604
  const swapper = swappers[client.chain.id];
510
605
  if (!swapper) throw new Error("Swapper not available");
606
+ const minSqrtPrice = sqrtPriceX96 * 9n / 10n;
607
+ const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
511
608
  const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
512
609
  const hash = await writeContractAsync({
513
610
  address: marketAddr,
@@ -548,8 +645,8 @@ const useExerciseOption = (marketAddr) => {
548
645
  { type: "uint160" }
549
646
  ], [
550
647
  poolKey,
551
- 0n,
552
- maxUint160 - 1n
648
+ minSqrtPrice,
649
+ maxSqrtPrice
553
650
  ]),
554
651
  refTick
555
652
  ]
@@ -609,58 +706,6 @@ const useMaxPositionSize = (marketAddr, maxBorrowableRange = 100) => {
609
706
  };
610
707
  };
611
708
 
612
- //#endregion
613
- //#region src/hooks/pool/usePoolData.ts
614
- const usePoolData = (poolManager, poolKey) => {
615
- const { timelockLens } = useLens();
616
- const { data } = useReadContract({
617
- address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
618
- abi: lensAbi,
619
- functionName: "getPoolData",
620
- args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
621
- query: { enabled: !!poolManager && !!poolKey }
622
- });
623
- const _default = useMemo(() => ({
624
- token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
625
- token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
626
- tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
627
- fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
628
- }), [poolKey]);
629
- return data || _default;
630
- };
631
-
632
- //#endregion
633
- //#region src/hooks/pool/useCurrentTick.ts
634
- const useCurrentTick = (poolManager, poolKey) => {
635
- const { stateView } = useLens();
636
- const { tickSpacing } = usePoolData(poolManager, poolKey);
637
- const { data, ...rest } = useReadContract({
638
- address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
639
- abi: statelessStateViewAbi,
640
- functionName: "getSlot0",
641
- args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
642
- query: {
643
- enabled: !!poolManager && !!poolKey,
644
- refetchInterval: 3e3,
645
- select: (raw) => {
646
- const sqrtPriceX96 = raw[0];
647
- const exact = raw[1];
648
- return {
649
- exact,
650
- rounded: tickSpacing ? roundTick(exact, tickSpacing) : void 0,
651
- sqrtPriceX96
652
- };
653
- }
654
- }
655
- });
656
- return {
657
- exact: data === null || data === void 0 ? void 0 : data.exact,
658
- rounded: data === null || data === void 0 ? void 0 : data.rounded,
659
- sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
660
- ...rest
661
- };
662
- };
663
-
664
709
  //#endregion
665
710
  //#region src/hooks/tokens/useApproval.ts
666
711
  const useApproval = () => {
@@ -738,46 +783,6 @@ const useMintOption = (marketAddr) => {
738
783
  return useMutation({ mutationFn: mintOption });
739
784
  };
740
785
 
741
- //#endregion
742
- //#region src/hooks/pool/usePriceAtTick.ts
743
- const usePriceAtTick = (poolManager, poolKey, tick) => {
744
- const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
745
- const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
746
- return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
747
- priceBigInt,
748
- token0Decimals,
749
- token1Decimals
750
- ]);
751
- };
752
- const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
753
- const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
754
- const priceBigInt = useMemo(() => sqrtPriceX96 !== void 0 ? getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
755
- return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
756
- priceBigInt,
757
- token0Decimals,
758
- token1Decimals
759
- ]);
760
- };
761
-
762
- //#endregion
763
- //#region src/hooks/pool/useCurrentPrice.ts
764
- const useCurrentPrice = (poolManager, poolKey) => {
765
- const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
766
- const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
767
- return useMemo(() => ({
768
- currentPrice,
769
- sqrtPriceX96,
770
- currentTick: {
771
- exact,
772
- rounded
773
- }
774
- }), [
775
- currentPrice,
776
- exact,
777
- rounded
778
- ]);
779
- };
780
-
781
786
  //#endregion
782
787
  //#region src/hooks/options/useOptionPnl.ts
783
788
  const useOptionPnl = (option) => {