timelock-sdk 0.0.70 → 0.0.72

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
@@ -10,7 +10,7 @@ import { useAccount, useChainId, useClient, useReadContract, useWaitForTransacti
10
10
  import { GraphQLClient, RequestOptions } from "graphql-request";
11
11
  import gql from "graphql-tag";
12
12
  import { waitForTransactionReceipt } from "viem/actions";
13
- import { useQuery, useQueryClient } from "@tanstack/react-query";
13
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
14
14
 
15
15
  //#region src/generated/graphql.ts
16
16
  const GetActiveUserOptionsDocument = gql`
@@ -290,16 +290,15 @@ const useExerciseOption = (marketAddr) => {
290
290
  const queryClient = useQueryClient();
291
291
  const client = useClient();
292
292
  const { address } = useAccount();
293
- const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
294
- const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
295
- const exerciseOption = async (option, liquidities) => {
293
+ const { writeContractAsync } = useWriteContract();
294
+ const exerciseOption = async ({ option, liquidities }) => {
296
295
  if (!client || !address) throw new Error("Wallet not connected");
297
296
  if (!marketAddr) throw new Error("Market address not available");
298
297
  if (!timelockLens) throw new Error("Timelock lens not available");
299
298
  if (!vault) throw new Error("Vault not available");
300
299
  if (!fee) throw new Error("Pool data not available");
301
300
  const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
302
- const hash$1 = await writeContractAsync({
301
+ const hash = await writeContractAsync({
303
302
  address: marketAddr,
304
303
  abi: optionsMarketAbi,
305
304
  functionName: "exerciseOption",
@@ -312,19 +311,11 @@ const useExerciseOption = (marketAddr) => {
312
311
  refTick
313
312
  ]
314
313
  });
315
- await waitForTransactionReceipt(client, { hash: hash$1 });
316
- await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
317
- return hash$1;
318
- };
319
- return {
320
- exerciseOption,
321
- hash,
322
- isPending,
323
- isConfirming,
324
- isSuccess,
325
- error,
326
- isLoading: isPending || isConfirming
314
+ await waitForTransactionReceipt(client, { hash });
315
+ queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
316
+ return hash;
327
317
  };
318
+ return useMutation({ mutationFn: exerciseOption });
328
319
  };
329
320
 
330
321
  //#endregion
@@ -421,10 +412,9 @@ const useMintOption = (marketAddr) => {
421
412
  const client = useClient();
422
413
  const { address } = useAccount();
423
414
  const { timelockLens } = useLens();
424
- const { askForApproval, isPending: isApprovalPending, error: approvalError, reset: resetApproval } = useApproval();
425
- const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
426
- const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
427
- const mintOption = async (optionType, amount, duration, strikeTick) => {
415
+ const { askForApproval } = useApproval();
416
+ const { writeContractAsync } = useWriteContract();
417
+ const mintOption = async ({ optionType, amount, duration, strikeTick }) => {
428
418
  if (!client || !address) throw new Error("Wallet not connected");
429
419
  if (!marketAddr) throw new Error("Market address not available");
430
420
  if (!timelockLens) throw new Error("Timelock lens not available");
@@ -439,7 +429,7 @@ const useMintOption = (marketAddr) => {
439
429
  0
440
430
  ]);
441
431
  await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
442
- const hash$1 = await writeContractAsync({
432
+ const hash = await writeContractAsync({
443
433
  address: marketAddr,
444
434
  abi: optionsMarketAbi,
445
435
  functionName: "mintOption",
@@ -453,22 +443,11 @@ const useMintOption = (marketAddr) => {
453
443
  await timelockLens.read.getRefTick([vault, strikeTick])
454
444
  ]
455
445
  });
456
- await waitForTransactionReceipt(client, { hash: hash$1 });
457
- await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
458
- return hash$1;
459
- };
460
- return {
461
- mintOption,
462
- hash,
463
- isPending: isPending || isApprovalPending,
464
- isConfirming,
465
- isSuccess,
466
- error: error || approvalError,
467
- isLoading: isPending || isConfirming || isApprovalPending,
468
- isApprovalPending,
469
- approvalError,
470
- resetApproval
446
+ await waitForTransactionReceipt(client, { hash });
447
+ queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
448
+ return hash;
471
449
  };
450
+ return useMutation({ mutationFn: mintOption });
472
451
  };
473
452
 
474
453
  //#endregion
@@ -604,10 +583,9 @@ const useExtendOption = (marketAddr) => {
604
583
  const queryClient = useQueryClient();
605
584
  const client = useClient();
606
585
  const { address } = useAccount();
607
- const { askForApproval, isPending: isApprovalPending, error: approvalError, reset: resetApproval } = useApproval();
608
- const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
609
- const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
610
- const extendOption = async (option, duration) => {
586
+ const { askForApproval } = useApproval();
587
+ const { writeContractAsync } = useWriteContract();
588
+ const extendOption = async ({ option, duration }) => {
611
589
  if (!client || !address) throw new Error("Wallet not connected");
612
590
  if (!marketAddr || !payoutAsset) throw new Error("Market address not available");
613
591
  const market = getTimelockMarket(marketAddr, client);
@@ -620,7 +598,7 @@ const useExtendOption = (marketAddr) => {
620
598
  remainingDuration
621
599
  ]);
622
600
  await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
623
- const hash$1 = await writeContractAsync({
601
+ const hash = await writeContractAsync({
624
602
  address: marketAddr,
625
603
  abi: optionsMarketAbi,
626
604
  functionName: "extendOption",
@@ -630,22 +608,11 @@ const useExtendOption = (marketAddr) => {
630
608
  maxUint256
631
609
  ]
632
610
  });
633
- await waitForTransactionReceipt(client, { hash: hash$1 });
634
- await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
635
- return hash$1;
636
- };
637
- return {
638
- extendOption,
639
- hash,
640
- isPending: isPending || isApprovalPending,
641
- isConfirming,
642
- isSuccess,
643
- error: error || approvalError,
644
- isLoading: isPending || isConfirming || isApprovalPending,
645
- isApprovalPending,
646
- approvalError,
647
- resetApproval
611
+ await waitForTransactionReceipt(client, { hash });
612
+ queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
613
+ return hash;
648
614
  };
615
+ return useMutation({ mutationFn: extendOption });
649
616
  };
650
617
 
651
618
  //#endregion
@@ -683,12 +650,11 @@ const useSetOperatorPerms = (marketAddr) => {
683
650
  const queryClient = useQueryClient();
684
651
  const client = useClient();
685
652
  const { address } = useAccount();
686
- const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
687
- const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
688
- const setOperatorPerms = async (operator, canExtend, canExercise, canTransfer, canMint, spendingApproval) => {
653
+ const { writeContractAsync } = useWriteContract();
654
+ const setOperatorPerms = async ({ operator, canExtend, canExercise, canTransfer, canMint, spendingApproval }) => {
689
655
  if (!client || !address) throw new Error("Wallet not connected");
690
656
  if (!marketAddr) throw new Error("Market address not available");
691
- const hash$1 = await writeContractAsync({
657
+ const hash = await writeContractAsync({
692
658
  address: marketAddr,
693
659
  abi: optionsMarketAbi,
694
660
  functionName: "setOperatorPerms",
@@ -701,23 +667,15 @@ const useSetOperatorPerms = (marketAddr) => {
701
667
  spendingApproval
702
668
  ]
703
669
  });
704
- await waitForTransactionReceipt(client, { hash: hash$1 });
705
- await queryClient.invalidateQueries({ queryKey: [
670
+ await waitForTransactionReceipt(client, { hash });
671
+ queryClient.invalidateQueries({ queryKey: [
706
672
  "userOperators",
707
673
  address.toLowerCase(),
708
674
  marketAddr.toLowerCase()
709
675
  ] });
710
- return hash$1;
711
- };
712
- return {
713
- setOperatorPerms,
714
- hash,
715
- isPending,
716
- isConfirming,
717
- isSuccess,
718
- error,
719
- isLoading: isPending || isConfirming
676
+ return hash;
720
677
  };
678
+ return useMutation({ mutationFn: setOperatorPerms });
721
679
  };
722
680
 
723
681
  //#endregion