timelock-sdk 0.0.56 → 0.0.58
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 +88 -18
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +83 -62
- package/dist/client.d.ts +24 -3
- package/dist/client.js +88 -19
- package/dist/client.js.map +1 -1
- package/dist/{index-DegGZn5F.d.cts → index-BP0jhXWl.d.ts} +93 -93
- package/dist/{index-DGAwlJuA.d.ts → index-C2ZV26z-.d.cts} +93 -93
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -353,33 +353,48 @@ const useCurrentTick = (poolAddr) => {
|
|
|
353
353
|
}, [data, tickSpacing]);
|
|
354
354
|
};
|
|
355
355
|
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/hooks/useApproval.ts
|
|
358
|
+
const useApproval = () => {
|
|
359
|
+
const client = (0, wagmi.useClient)();
|
|
360
|
+
const { address } = (0, wagmi.useAccount)();
|
|
361
|
+
const { writeContractAsync, data: hash, isPending, error, reset } = (0, wagmi.useWriteContract)();
|
|
362
|
+
const askForApproval = async (tokenAddress, spenderAddress, amount) => {
|
|
363
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
364
|
+
if (await require_numberUtils.getErc20(tokenAddress, client).read.allowance([address, spenderAddress]) < amount) await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
365
|
+
address: tokenAddress,
|
|
366
|
+
abi: viem.erc20Abi,
|
|
367
|
+
functionName: "approve",
|
|
368
|
+
args: [spenderAddress, viem.maxUint256]
|
|
369
|
+
}) });
|
|
370
|
+
};
|
|
371
|
+
return {
|
|
372
|
+
askForApproval,
|
|
373
|
+
hash,
|
|
374
|
+
isPending,
|
|
375
|
+
error,
|
|
376
|
+
reset
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
|
|
356
380
|
//#endregion
|
|
357
381
|
//#region src/hooks/market/useMintOption.ts
|
|
358
382
|
const useMintOption = (marketAddr) => {
|
|
359
|
-
const { timelockLens } = useLens();
|
|
360
383
|
const { payoutAsset, vault, pool, optionAssetIsToken0 } = useMarketData(marketAddr);
|
|
361
384
|
const { tickSpacing } = usePoolData(pool);
|
|
362
385
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
386
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
363
387
|
const client = (0, wagmi.useClient)();
|
|
364
388
|
const { address } = (0, wagmi.useAccount)();
|
|
365
|
-
const
|
|
389
|
+
const { timelockLens } = useLens();
|
|
390
|
+
const { askForApproval, isPending: isApprovalPending, error: approvalError, reset: resetApproval } = useApproval();
|
|
366
391
|
const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
|
|
367
392
|
const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
|
|
368
|
-
const askForApproval = async (premiumAmount) => {
|
|
369
|
-
if (!client || !address) throw new Error("Wallet not connected");
|
|
370
|
-
if (!payoutAsset || !marketAddr) throw new Error("Tokens not available");
|
|
371
|
-
if (await require_numberUtils.getErc20(payoutAsset, client).read.allowance([address, marketAddr]) < premiumAmount) await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
372
|
-
address: payoutAsset,
|
|
373
|
-
abi: viem.erc20Abi,
|
|
374
|
-
functionName: "approve",
|
|
375
|
-
args: [marketAddr, viem.maxUint256]
|
|
376
|
-
}) });
|
|
377
|
-
};
|
|
378
393
|
const mintOption = async (optionType, amount, duration, strikeTick) => {
|
|
379
394
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
380
395
|
if (!marketAddr) throw new Error("Market address not available");
|
|
381
396
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
382
|
-
if (!vault) throw new Error("Vault not available");
|
|
397
|
+
if (!vault || !payoutAsset) throw new Error("Vault not available");
|
|
383
398
|
if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
|
|
384
399
|
strikeTick = require_numberUtils.roundTickDown(strikeTick ?? currentTick, tickSpacing);
|
|
385
400
|
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTick += tickSpacing;
|
|
@@ -390,7 +405,7 @@ const useMintOption = (marketAddr) => {
|
|
|
390
405
|
duration,
|
|
391
406
|
0
|
|
392
407
|
]);
|
|
393
|
-
await askForApproval(premium + protocolFee);
|
|
408
|
+
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee * 11n) / 10n);
|
|
394
409
|
const hash$1 = await writeContractAsync({
|
|
395
410
|
address: marketAddr,
|
|
396
411
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
@@ -400,7 +415,7 @@ const useMintOption = (marketAddr) => {
|
|
|
400
415
|
amount,
|
|
401
416
|
strikeTick,
|
|
402
417
|
duration,
|
|
403
|
-
|
|
418
|
+
viem.maxUint256,
|
|
404
419
|
false,
|
|
405
420
|
await timelockLens.read.getRefTick([vault, strikeTick])
|
|
406
421
|
]
|
|
@@ -412,11 +427,14 @@ const useMintOption = (marketAddr) => {
|
|
|
412
427
|
return {
|
|
413
428
|
mintOption,
|
|
414
429
|
hash,
|
|
415
|
-
isPending,
|
|
430
|
+
isPending: isPending || isApprovalPending,
|
|
416
431
|
isConfirming,
|
|
417
432
|
isSuccess,
|
|
418
|
-
error,
|
|
419
|
-
isLoading: isPending || isConfirming
|
|
433
|
+
error: error || approvalError,
|
|
434
|
+
isLoading: isPending || isConfirming || isApprovalPending,
|
|
435
|
+
isApprovalPending,
|
|
436
|
+
approvalError,
|
|
437
|
+
resetApproval
|
|
420
438
|
};
|
|
421
439
|
};
|
|
422
440
|
|
|
@@ -545,6 +563,57 @@ const useClosedUserOptions = (user) => {
|
|
|
545
563
|
return useUserOptions(user, false);
|
|
546
564
|
};
|
|
547
565
|
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/hooks/market/useExtendOption.ts
|
|
568
|
+
const useExtendOption = (marketAddr) => {
|
|
569
|
+
const { payoutAsset } = useMarketData(marketAddr);
|
|
570
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
571
|
+
const client = (0, wagmi.useClient)();
|
|
572
|
+
const { address } = (0, wagmi.useAccount)();
|
|
573
|
+
const { askForApproval, isPending: isApprovalPending, error: approvalError, reset: resetApproval } = useApproval();
|
|
574
|
+
const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
|
|
575
|
+
const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
|
|
576
|
+
const extendOption = async (option, duration) => {
|
|
577
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
578
|
+
if (!marketAddr || !payoutAsset) throw new Error("Market address not available");
|
|
579
|
+
const market = require_numberUtils.getTimelockMarket(marketAddr, client);
|
|
580
|
+
const remainingDuration = Math.max(0, Math.floor((option.expiresAt.getTime() - Date.now()) / 1e3));
|
|
581
|
+
const [premium, protocolFee] = await market.read.calculatePremium([
|
|
582
|
+
option.optionType === "CALL" ? 0 : 1,
|
|
583
|
+
option.positionSizeCurrent,
|
|
584
|
+
option.strikeTick,
|
|
585
|
+
duration,
|
|
586
|
+
remainingDuration
|
|
587
|
+
]);
|
|
588
|
+
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee * 11n) / 10n);
|
|
589
|
+
const hash$1 = await writeContractAsync({
|
|
590
|
+
address: marketAddr,
|
|
591
|
+
abi: require_optionsMarket.optionsMarketAbi,
|
|
592
|
+
functionName: "extendOption",
|
|
593
|
+
args: [
|
|
594
|
+
option.optionId,
|
|
595
|
+
duration,
|
|
596
|
+
viem.maxUint256
|
|
597
|
+
]
|
|
598
|
+
});
|
|
599
|
+
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
|
|
600
|
+
await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
601
|
+
return hash$1;
|
|
602
|
+
};
|
|
603
|
+
return {
|
|
604
|
+
extendOption,
|
|
605
|
+
hash,
|
|
606
|
+
isPending: isPending || isApprovalPending,
|
|
607
|
+
isConfirming,
|
|
608
|
+
isSuccess,
|
|
609
|
+
error: error || approvalError,
|
|
610
|
+
isLoading: isPending || isConfirming || isApprovalPending,
|
|
611
|
+
isApprovalPending,
|
|
612
|
+
approvalError,
|
|
613
|
+
resetApproval
|
|
614
|
+
};
|
|
615
|
+
};
|
|
616
|
+
|
|
548
617
|
//#endregion
|
|
549
618
|
//#region src/hooks/pool/usePriceAtTick.ts
|
|
550
619
|
const usePriceAtTick = (tick, poolAddr) => {
|
|
@@ -925,6 +994,7 @@ exports.useCurrentMarket = useCurrentMarket;
|
|
|
925
994
|
exports.useCurrentPrice = useCurrentPrice;
|
|
926
995
|
exports.useCurrentTick = useCurrentTick;
|
|
927
996
|
exports.useExerciseOption = useExerciseOption;
|
|
997
|
+
exports.useExtendOption = useExtendOption;
|
|
928
998
|
exports.useLens = useLens;
|
|
929
999
|
exports.useLiquidityBlocks = useLiquidityBlocks;
|
|
930
1000
|
exports.useMarketData = useMarketData;
|