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.cjs +30 -72
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +25 -49
- package/dist/client.d.ts +80 -104
- package/dist/client.js +31 -73
- package/dist/client.js.map +1 -1
- package/dist/{index-BK67HnC2.d.cts → index-C-uDgfkL.d.cts} +92 -92
- package/dist/package.d.cts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -297,16 +297,15 @@ const useExerciseOption = (marketAddr) => {
|
|
|
297
297
|
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
298
298
|
const client = (0, wagmi.useClient)();
|
|
299
299
|
const { address } = (0, wagmi.useAccount)();
|
|
300
|
-
const { writeContractAsync
|
|
301
|
-
const
|
|
302
|
-
const exerciseOption = async (option, liquidities) => {
|
|
300
|
+
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
301
|
+
const exerciseOption = async ({ option, liquidities }) => {
|
|
303
302
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
304
303
|
if (!marketAddr) throw new Error("Market address not available");
|
|
305
304
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
306
305
|
if (!vault) throw new Error("Vault not available");
|
|
307
306
|
if (!fee) throw new Error("Pool data not available");
|
|
308
307
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
309
|
-
const hash
|
|
308
|
+
const hash = await writeContractAsync({
|
|
310
309
|
address: marketAddr,
|
|
311
310
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
312
311
|
functionName: "exerciseOption",
|
|
@@ -319,19 +318,11 @@ const useExerciseOption = (marketAddr) => {
|
|
|
319
318
|
refTick
|
|
320
319
|
]
|
|
321
320
|
});
|
|
322
|
-
await (0, viem_actions.waitForTransactionReceipt)(client, { hash
|
|
323
|
-
|
|
324
|
-
return hash
|
|
325
|
-
};
|
|
326
|
-
return {
|
|
327
|
-
exerciseOption,
|
|
328
|
-
hash,
|
|
329
|
-
isPending,
|
|
330
|
-
isConfirming,
|
|
331
|
-
isSuccess,
|
|
332
|
-
error,
|
|
333
|
-
isLoading: isPending || isConfirming
|
|
321
|
+
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
322
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
323
|
+
return hash;
|
|
334
324
|
};
|
|
325
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: exerciseOption });
|
|
335
326
|
};
|
|
336
327
|
|
|
337
328
|
//#endregion
|
|
@@ -428,10 +419,9 @@ const useMintOption = (marketAddr) => {
|
|
|
428
419
|
const client = (0, wagmi.useClient)();
|
|
429
420
|
const { address } = (0, wagmi.useAccount)();
|
|
430
421
|
const { timelockLens } = useLens();
|
|
431
|
-
const { askForApproval
|
|
432
|
-
const { writeContractAsync
|
|
433
|
-
const
|
|
434
|
-
const mintOption = async (optionType, amount, duration, strikeTick) => {
|
|
422
|
+
const { askForApproval } = useApproval();
|
|
423
|
+
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
424
|
+
const mintOption = async ({ optionType, amount, duration, strikeTick }) => {
|
|
435
425
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
436
426
|
if (!marketAddr) throw new Error("Market address not available");
|
|
437
427
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
@@ -446,7 +436,7 @@ const useMintOption = (marketAddr) => {
|
|
|
446
436
|
0
|
|
447
437
|
]);
|
|
448
438
|
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
|
|
449
|
-
const hash
|
|
439
|
+
const hash = await writeContractAsync({
|
|
450
440
|
address: marketAddr,
|
|
451
441
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
452
442
|
functionName: "mintOption",
|
|
@@ -460,22 +450,11 @@ const useMintOption = (marketAddr) => {
|
|
|
460
450
|
await timelockLens.read.getRefTick([vault, strikeTick])
|
|
461
451
|
]
|
|
462
452
|
});
|
|
463
|
-
await (0, viem_actions.waitForTransactionReceipt)(client, { hash
|
|
464
|
-
|
|
465
|
-
return hash
|
|
466
|
-
};
|
|
467
|
-
return {
|
|
468
|
-
mintOption,
|
|
469
|
-
hash,
|
|
470
|
-
isPending: isPending || isApprovalPending,
|
|
471
|
-
isConfirming,
|
|
472
|
-
isSuccess,
|
|
473
|
-
error: error || approvalError,
|
|
474
|
-
isLoading: isPending || isConfirming || isApprovalPending,
|
|
475
|
-
isApprovalPending,
|
|
476
|
-
approvalError,
|
|
477
|
-
resetApproval
|
|
453
|
+
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
454
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
455
|
+
return hash;
|
|
478
456
|
};
|
|
457
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintOption });
|
|
479
458
|
};
|
|
480
459
|
|
|
481
460
|
//#endregion
|
|
@@ -611,10 +590,9 @@ const useExtendOption = (marketAddr) => {
|
|
|
611
590
|
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
612
591
|
const client = (0, wagmi.useClient)();
|
|
613
592
|
const { address } = (0, wagmi.useAccount)();
|
|
614
|
-
const { askForApproval
|
|
615
|
-
const { writeContractAsync
|
|
616
|
-
const
|
|
617
|
-
const extendOption = async (option, duration) => {
|
|
593
|
+
const { askForApproval } = useApproval();
|
|
594
|
+
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
595
|
+
const extendOption = async ({ option, duration }) => {
|
|
618
596
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
619
597
|
if (!marketAddr || !payoutAsset) throw new Error("Market address not available");
|
|
620
598
|
const market = require_numberUtils.getTimelockMarket(marketAddr, client);
|
|
@@ -627,7 +605,7 @@ const useExtendOption = (marketAddr) => {
|
|
|
627
605
|
remainingDuration
|
|
628
606
|
]);
|
|
629
607
|
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
|
|
630
|
-
const hash
|
|
608
|
+
const hash = await writeContractAsync({
|
|
631
609
|
address: marketAddr,
|
|
632
610
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
633
611
|
functionName: "extendOption",
|
|
@@ -637,22 +615,11 @@ const useExtendOption = (marketAddr) => {
|
|
|
637
615
|
viem.maxUint256
|
|
638
616
|
]
|
|
639
617
|
});
|
|
640
|
-
await (0, viem_actions.waitForTransactionReceipt)(client, { hash
|
|
641
|
-
|
|
642
|
-
return hash
|
|
643
|
-
};
|
|
644
|
-
return {
|
|
645
|
-
extendOption,
|
|
646
|
-
hash,
|
|
647
|
-
isPending: isPending || isApprovalPending,
|
|
648
|
-
isConfirming,
|
|
649
|
-
isSuccess,
|
|
650
|
-
error: error || approvalError,
|
|
651
|
-
isLoading: isPending || isConfirming || isApprovalPending,
|
|
652
|
-
isApprovalPending,
|
|
653
|
-
approvalError,
|
|
654
|
-
resetApproval
|
|
618
|
+
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
619
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
620
|
+
return hash;
|
|
655
621
|
};
|
|
622
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: extendOption });
|
|
656
623
|
};
|
|
657
624
|
|
|
658
625
|
//#endregion
|
|
@@ -690,12 +657,11 @@ const useSetOperatorPerms = (marketAddr) => {
|
|
|
690
657
|
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
691
658
|
const client = (0, wagmi.useClient)();
|
|
692
659
|
const { address } = (0, wagmi.useAccount)();
|
|
693
|
-
const { writeContractAsync
|
|
694
|
-
const {
|
|
695
|
-
const setOperatorPerms = async (operator, canExtend, canExercise, canTransfer, canMint, spendingApproval) => {
|
|
660
|
+
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
661
|
+
const setOperatorPerms = async ({ operator, canExtend, canExercise, canTransfer, canMint, spendingApproval }) => {
|
|
696
662
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
697
663
|
if (!marketAddr) throw new Error("Market address not available");
|
|
698
|
-
const hash
|
|
664
|
+
const hash = await writeContractAsync({
|
|
699
665
|
address: marketAddr,
|
|
700
666
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
701
667
|
functionName: "setOperatorPerms",
|
|
@@ -708,23 +674,15 @@ const useSetOperatorPerms = (marketAddr) => {
|
|
|
708
674
|
spendingApproval
|
|
709
675
|
]
|
|
710
676
|
});
|
|
711
|
-
await (0, viem_actions.waitForTransactionReceipt)(client, { hash
|
|
712
|
-
|
|
677
|
+
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
678
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
713
679
|
"userOperators",
|
|
714
680
|
address.toLowerCase(),
|
|
715
681
|
marketAddr.toLowerCase()
|
|
716
682
|
] });
|
|
717
|
-
return hash
|
|
718
|
-
};
|
|
719
|
-
return {
|
|
720
|
-
setOperatorPerms,
|
|
721
|
-
hash,
|
|
722
|
-
isPending,
|
|
723
|
-
isConfirming,
|
|
724
|
-
isSuccess,
|
|
725
|
-
error,
|
|
726
|
-
isLoading: isPending || isConfirming
|
|
683
|
+
return hash;
|
|
727
684
|
};
|
|
685
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: setOperatorPerms });
|
|
728
686
|
};
|
|
729
687
|
|
|
730
688
|
//#endregion
|