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.js
CHANGED
|
@@ -346,33 +346,48 @@ const useCurrentTick = (poolAddr) => {
|
|
|
346
346
|
}, [data, tickSpacing]);
|
|
347
347
|
};
|
|
348
348
|
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/hooks/useApproval.ts
|
|
351
|
+
const useApproval = () => {
|
|
352
|
+
const client = useClient();
|
|
353
|
+
const { address } = useAccount();
|
|
354
|
+
const { writeContractAsync, data: hash, isPending, error, reset } = useWriteContract();
|
|
355
|
+
const askForApproval = async (tokenAddress, spenderAddress, amount) => {
|
|
356
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
357
|
+
if (await getErc20(tokenAddress, client).read.allowance([address, spenderAddress]) < amount) await waitForTransactionReceipt(client, { hash: await writeContractAsync({
|
|
358
|
+
address: tokenAddress,
|
|
359
|
+
abi: erc20Abi,
|
|
360
|
+
functionName: "approve",
|
|
361
|
+
args: [spenderAddress, maxUint256]
|
|
362
|
+
}) });
|
|
363
|
+
};
|
|
364
|
+
return {
|
|
365
|
+
askForApproval,
|
|
366
|
+
hash,
|
|
367
|
+
isPending,
|
|
368
|
+
error,
|
|
369
|
+
reset
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
|
|
349
373
|
//#endregion
|
|
350
374
|
//#region src/hooks/market/useMintOption.ts
|
|
351
375
|
const useMintOption = (marketAddr) => {
|
|
352
|
-
const { timelockLens } = useLens();
|
|
353
376
|
const { payoutAsset, vault, pool, optionAssetIsToken0 } = useMarketData(marketAddr);
|
|
354
377
|
const { tickSpacing } = usePoolData(pool);
|
|
355
378
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
379
|
+
const queryClient = useQueryClient();
|
|
356
380
|
const client = useClient();
|
|
357
381
|
const { address } = useAccount();
|
|
358
|
-
const
|
|
382
|
+
const { timelockLens } = useLens();
|
|
383
|
+
const { askForApproval, isPending: isApprovalPending, error: approvalError, reset: resetApproval } = useApproval();
|
|
359
384
|
const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
|
|
360
385
|
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
|
|
361
|
-
const askForApproval = async (premiumAmount) => {
|
|
362
|
-
if (!client || !address) throw new Error("Wallet not connected");
|
|
363
|
-
if (!payoutAsset || !marketAddr) throw new Error("Tokens not available");
|
|
364
|
-
if (await getErc20(payoutAsset, client).read.allowance([address, marketAddr]) < premiumAmount) await waitForTransactionReceipt(client, { hash: await writeContractAsync({
|
|
365
|
-
address: payoutAsset,
|
|
366
|
-
abi: erc20Abi,
|
|
367
|
-
functionName: "approve",
|
|
368
|
-
args: [marketAddr, maxUint256]
|
|
369
|
-
}) });
|
|
370
|
-
};
|
|
371
386
|
const mintOption = async (optionType, amount, duration, strikeTick) => {
|
|
372
387
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
373
388
|
if (!marketAddr) throw new Error("Market address not available");
|
|
374
389
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
375
|
-
if (!vault) throw new Error("Vault not available");
|
|
390
|
+
if (!vault || !payoutAsset) throw new Error("Vault not available");
|
|
376
391
|
if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
|
|
377
392
|
strikeTick = roundTickDown(strikeTick ?? currentTick, tickSpacing);
|
|
378
393
|
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTick += tickSpacing;
|
|
@@ -383,7 +398,7 @@ const useMintOption = (marketAddr) => {
|
|
|
383
398
|
duration,
|
|
384
399
|
0
|
|
385
400
|
]);
|
|
386
|
-
await askForApproval(premium + protocolFee);
|
|
401
|
+
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee * 11n) / 10n);
|
|
387
402
|
const hash$1 = await writeContractAsync({
|
|
388
403
|
address: marketAddr,
|
|
389
404
|
abi: optionsMarketAbi,
|
|
@@ -393,7 +408,7 @@ const useMintOption = (marketAddr) => {
|
|
|
393
408
|
amount,
|
|
394
409
|
strikeTick,
|
|
395
410
|
duration,
|
|
396
|
-
|
|
411
|
+
maxUint256,
|
|
397
412
|
false,
|
|
398
413
|
await timelockLens.read.getRefTick([vault, strikeTick])
|
|
399
414
|
]
|
|
@@ -405,11 +420,14 @@ const useMintOption = (marketAddr) => {
|
|
|
405
420
|
return {
|
|
406
421
|
mintOption,
|
|
407
422
|
hash,
|
|
408
|
-
isPending,
|
|
423
|
+
isPending: isPending || isApprovalPending,
|
|
409
424
|
isConfirming,
|
|
410
425
|
isSuccess,
|
|
411
|
-
error,
|
|
412
|
-
isLoading: isPending || isConfirming
|
|
426
|
+
error: error || approvalError,
|
|
427
|
+
isLoading: isPending || isConfirming || isApprovalPending,
|
|
428
|
+
isApprovalPending,
|
|
429
|
+
approvalError,
|
|
430
|
+
resetApproval
|
|
413
431
|
};
|
|
414
432
|
};
|
|
415
433
|
|
|
@@ -538,6 +556,57 @@ const useClosedUserOptions = (user) => {
|
|
|
538
556
|
return useUserOptions(user, false);
|
|
539
557
|
};
|
|
540
558
|
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region src/hooks/market/useExtendOption.ts
|
|
561
|
+
const useExtendOption = (marketAddr) => {
|
|
562
|
+
const { payoutAsset } = useMarketData(marketAddr);
|
|
563
|
+
const queryClient = useQueryClient();
|
|
564
|
+
const client = useClient();
|
|
565
|
+
const { address } = useAccount();
|
|
566
|
+
const { askForApproval, isPending: isApprovalPending, error: approvalError, reset: resetApproval } = useApproval();
|
|
567
|
+
const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
|
|
568
|
+
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
|
|
569
|
+
const extendOption = async (option, duration) => {
|
|
570
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
571
|
+
if (!marketAddr || !payoutAsset) throw new Error("Market address not available");
|
|
572
|
+
const market = getTimelockMarket(marketAddr, client);
|
|
573
|
+
const remainingDuration = Math.max(0, Math.floor((option.expiresAt.getTime() - Date.now()) / 1e3));
|
|
574
|
+
const [premium, protocolFee] = await market.read.calculatePremium([
|
|
575
|
+
option.optionType === "CALL" ? 0 : 1,
|
|
576
|
+
option.positionSizeCurrent,
|
|
577
|
+
option.strikeTick,
|
|
578
|
+
duration,
|
|
579
|
+
remainingDuration
|
|
580
|
+
]);
|
|
581
|
+
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee * 11n) / 10n);
|
|
582
|
+
const hash$1 = await writeContractAsync({
|
|
583
|
+
address: marketAddr,
|
|
584
|
+
abi: optionsMarketAbi,
|
|
585
|
+
functionName: "extendOption",
|
|
586
|
+
args: [
|
|
587
|
+
option.optionId,
|
|
588
|
+
duration,
|
|
589
|
+
maxUint256
|
|
590
|
+
]
|
|
591
|
+
});
|
|
592
|
+
await waitForTransactionReceipt(client, { hash: hash$1 });
|
|
593
|
+
await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
594
|
+
return hash$1;
|
|
595
|
+
};
|
|
596
|
+
return {
|
|
597
|
+
extendOption,
|
|
598
|
+
hash,
|
|
599
|
+
isPending: isPending || isApprovalPending,
|
|
600
|
+
isConfirming,
|
|
601
|
+
isSuccess,
|
|
602
|
+
error: error || approvalError,
|
|
603
|
+
isLoading: isPending || isConfirming || isApprovalPending,
|
|
604
|
+
isApprovalPending,
|
|
605
|
+
approvalError,
|
|
606
|
+
resetApproval
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
|
|
541
610
|
//#endregion
|
|
542
611
|
//#region src/hooks/pool/usePriceAtTick.ts
|
|
543
612
|
const usePriceAtTick = (tick, poolAddr) => {
|
|
@@ -909,5 +978,5 @@ const useVaultTVL = (vaultAddr) => {
|
|
|
909
978
|
};
|
|
910
979
|
|
|
911
980
|
//#endregion
|
|
912
|
-
export { TimelockMarketProvider, batchGetAmountsFromLiquidity, useActiveUserOptions, useBurnLiquidity, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useOptionPnl, useOptionPremium, usePoolData, usePriceAtTick, usePriceHistory, useTimelockConfig, useVaultData, useVaultTVL };
|
|
981
|
+
export { TimelockMarketProvider, batchGetAmountsFromLiquidity, useActiveUserOptions, useBurnLiquidity, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useOptionPnl, useOptionPremium, usePoolData, usePriceAtTick, usePriceHistory, useTimelockConfig, useVaultData, useVaultTVL };
|
|
913
982
|
//# sourceMappingURL=client.js.map
|