timelock-sdk 0.0.159 → 0.0.161
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-C5uUBjks.d.ts → client-BKIKRCjR.d.ts} +2036 -1199
- package/dist/{client-COCvyyDy.d.cts → client-CZoaAxx7.d.cts} +2441 -1604
- package/dist/client.cjs +363 -169
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +360 -171
- package/dist/client.js.map +1 -1
- package/dist/{optionUtils-B-TKN7Ni.cjs → optionUtils-CaKlLWf2.cjs} +3 -3
- package/dist/{optionUtils-B-TKN7Ni.cjs.map → optionUtils-CaKlLWf2.cjs.map} +1 -1
- package/dist/{optionUtils-CL-MSoFS.js → optionUtils-Ci6C7FPN.js} +3 -3
- package/dist/{optionUtils-CL-MSoFS.js.map → optionUtils-Ci6C7FPN.js.map} +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const require_optionUtils = require('./optionUtils-
|
|
4
|
+
const require_optionUtils = require('./optionUtils-CaKlLWf2.cjs');
|
|
5
5
|
const require_optionsMarket = require('./optionsMarket-DtjLm46g.cjs');
|
|
6
6
|
const require_singleOwnerVault = require('./singleOwnerVault-GCpQV7pN.cjs');
|
|
7
7
|
let viem = require("viem");
|
|
@@ -10,9 +10,9 @@ react = require_optionUtils.__toESM(react);
|
|
|
10
10
|
let graphql_request = require("graphql-request");
|
|
11
11
|
let graphql_tag = require("graphql-tag");
|
|
12
12
|
graphql_tag = require_optionUtils.__toESM(graphql_tag);
|
|
13
|
-
let viem_actions = require("viem/actions");
|
|
14
13
|
let wagmi = require("wagmi");
|
|
15
14
|
let __tanstack_react_query = require("@tanstack/react-query");
|
|
15
|
+
let viem_actions = require("viem/actions");
|
|
16
16
|
let zod = require("zod");
|
|
17
17
|
|
|
18
18
|
//#region src/generated/graphql.ts
|
|
@@ -461,6 +461,70 @@ const useMarketData = (marketAddr) => {
|
|
|
461
461
|
return data || {};
|
|
462
462
|
};
|
|
463
463
|
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/hooks/options/useMarketState.ts
|
|
466
|
+
const useMarketState = (marketAddr) => {
|
|
467
|
+
const { timelockLens } = useLens();
|
|
468
|
+
const { data, ...rest } = (0, wagmi.useReadContract)({
|
|
469
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
470
|
+
abi: require_optionsMarket.lensAbi,
|
|
471
|
+
functionName: "getMarketState",
|
|
472
|
+
args: marketAddr ? [marketAddr] : void 0
|
|
473
|
+
});
|
|
474
|
+
return {
|
|
475
|
+
data: data || {},
|
|
476
|
+
...rest
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/hooks/options/useMarketVolume.ts
|
|
482
|
+
const useMarketVolume = (marketAddr) => {
|
|
483
|
+
const { graphqlClient } = useTimelockConfig();
|
|
484
|
+
const { data, ...rest } = (0, __tanstack_react_query.useQuery)({
|
|
485
|
+
queryKey: ["marketVolume", (marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase()) || "--"],
|
|
486
|
+
queryFn: async () => {
|
|
487
|
+
const result = await graphqlClient.GetMarketVolume({ marketAddr: marketAddr.toLowerCase() });
|
|
488
|
+
return {
|
|
489
|
+
...result.TimelockMarket[0],
|
|
490
|
+
address: result.TimelockMarket[0].address,
|
|
491
|
+
volume: BigInt(result.TimelockMarket[0].volume),
|
|
492
|
+
optionsCount: BigInt(result.TimelockMarket[0].optionsCount),
|
|
493
|
+
tradersCount: BigInt(result.TimelockMarket[0].tradersCount)
|
|
494
|
+
};
|
|
495
|
+
},
|
|
496
|
+
enabled: !!marketAddr && !!graphqlClient
|
|
497
|
+
});
|
|
498
|
+
return {
|
|
499
|
+
data: data || {},
|
|
500
|
+
...rest
|
|
501
|
+
};
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region src/hooks/options/useMaxPositionSize.ts
|
|
506
|
+
const useMaxPositionSize = (marketAddr, strikeTick, maxSteps = 100) => {
|
|
507
|
+
const { timelockLens } = useLens();
|
|
508
|
+
const { optionAssetDecimals } = useMarketData(marketAddr);
|
|
509
|
+
const { data, ...rest } = (0, wagmi.useReadContract)({
|
|
510
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
511
|
+
abi: require_optionsMarket.lensAbi,
|
|
512
|
+
functionName: strikeTick ? "getMaxPositionSizes" : "getMaxATMPositionSizes",
|
|
513
|
+
args: marketAddr ? strikeTick ? [
|
|
514
|
+
marketAddr,
|
|
515
|
+
strikeTick,
|
|
516
|
+
maxSteps
|
|
517
|
+
] : [marketAddr, maxSteps] : void 0,
|
|
518
|
+
query: { enabled: !!marketAddr && !!timelockLens },
|
|
519
|
+
gas: 100000000n
|
|
520
|
+
});
|
|
521
|
+
return {
|
|
522
|
+
maxCallSize: data && optionAssetDecimals ? require_optionUtils.wrapAmount(data[0], optionAssetDecimals) : void 0,
|
|
523
|
+
maxPutSize: data && optionAssetDecimals ? require_optionUtils.wrapAmount(data[1], optionAssetDecimals) : void 0,
|
|
524
|
+
...rest
|
|
525
|
+
};
|
|
526
|
+
};
|
|
527
|
+
|
|
464
528
|
//#endregion
|
|
465
529
|
//#region src/hooks/pool/usePoolData.ts
|
|
466
530
|
const usePoolData = (poolManager, poolKey) => {
|
|
@@ -481,27 +545,6 @@ const usePoolData = (poolManager, poolKey) => {
|
|
|
481
545
|
return data || _default;
|
|
482
546
|
};
|
|
483
547
|
|
|
484
|
-
//#endregion
|
|
485
|
-
//#region src/hooks/pool/usePriceAtTick.ts
|
|
486
|
-
const usePriceAtTick = (poolManager, poolKey, tick) => {
|
|
487
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
488
|
-
const priceBigInt = (0, react.useMemo)(() => tick !== void 0 ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
489
|
-
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
490
|
-
priceBigInt,
|
|
491
|
-
token0Decimals,
|
|
492
|
-
token1Decimals
|
|
493
|
-
]);
|
|
494
|
-
};
|
|
495
|
-
const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
|
|
496
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
497
|
-
const priceBigInt = (0, react.useMemo)(() => sqrtPriceX96 !== void 0 ? require_optionUtils.getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
498
|
-
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
499
|
-
priceBigInt,
|
|
500
|
-
token0Decimals,
|
|
501
|
-
token1Decimals
|
|
502
|
-
]);
|
|
503
|
-
};
|
|
504
|
-
|
|
505
548
|
//#endregion
|
|
506
549
|
//#region src/hooks/pool/useCurrentTick.ts
|
|
507
550
|
const useCurrentTick = (poolManager, poolKey) => {
|
|
@@ -534,6 +577,109 @@ const useCurrentTick = (poolManager, poolKey) => {
|
|
|
534
577
|
};
|
|
535
578
|
};
|
|
536
579
|
|
|
580
|
+
//#endregion
|
|
581
|
+
//#region src/hooks/tokens/useApproval.ts
|
|
582
|
+
const useApproval = () => {
|
|
583
|
+
const client = (0, wagmi.useClient)();
|
|
584
|
+
const { address } = (0, wagmi.useConnection)();
|
|
585
|
+
const { writeContractAsync, data: hash, isPending, error, reset } = (0, wagmi.useWriteContract)();
|
|
586
|
+
const askForApproval = async (tokenAddress, spenderAddress, amount) => {
|
|
587
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
588
|
+
if (await require_optionUtils.getErc20(tokenAddress, client).read.allowance([address, spenderAddress]) < amount) await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
589
|
+
address: tokenAddress,
|
|
590
|
+
abi: viem.erc20Abi,
|
|
591
|
+
functionName: "approve",
|
|
592
|
+
args: [spenderAddress, viem.maxUint256]
|
|
593
|
+
}) });
|
|
594
|
+
};
|
|
595
|
+
return {
|
|
596
|
+
askForApproval,
|
|
597
|
+
hash,
|
|
598
|
+
isPending,
|
|
599
|
+
error,
|
|
600
|
+
reset
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region src/lib/utils.ts
|
|
606
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
607
|
+
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/hooks/options/useMintOption.ts
|
|
610
|
+
const useMintOption = (marketAddr) => {
|
|
611
|
+
const { payoutAsset, vault, poolManager, poolKey, optionAssetIsToken0 } = useMarketData(marketAddr);
|
|
612
|
+
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
613
|
+
const { refetch: refetchCurrentTick } = useCurrentTick(poolManager, poolKey);
|
|
614
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
615
|
+
const client = (0, wagmi.useClient)();
|
|
616
|
+
const { address } = (0, wagmi.useConnection)();
|
|
617
|
+
const { timelockLens } = useLens();
|
|
618
|
+
const { askForApproval } = useApproval();
|
|
619
|
+
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
620
|
+
const mintOption = async ({ optionType, amount, duration, strikeTick, maxSteps = 100 }) => {
|
|
621
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
622
|
+
if (!marketAddr) throw new Error("Market address not available");
|
|
623
|
+
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
624
|
+
if (!tickSpacing) throw new Error("Pool data not available");
|
|
625
|
+
if (!vault || !payoutAsset || optionAssetIsToken0 === void 0) throw new Error("Market data not available");
|
|
626
|
+
const { data: { exact: currentTick } = {} } = await refetchCurrentTick();
|
|
627
|
+
if (currentTick === void 0) throw new Error("Could not fetch current tick");
|
|
628
|
+
strikeTick = require_optionUtils.getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
|
|
629
|
+
const [premium, protocolFee] = await require_optionUtils.getTimelockMarket(marketAddr, client).read.calculatePremium([
|
|
630
|
+
optionType === "CALL" ? 0 : 1,
|
|
631
|
+
amount,
|
|
632
|
+
strikeTick,
|
|
633
|
+
duration,
|
|
634
|
+
0
|
|
635
|
+
]);
|
|
636
|
+
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
|
|
637
|
+
const hash = await writeContractAsync({
|
|
638
|
+
address: marketAddr,
|
|
639
|
+
abi: require_optionsMarket.optionsMarketAbi,
|
|
640
|
+
functionName: "mintOption",
|
|
641
|
+
args: [
|
|
642
|
+
address,
|
|
643
|
+
optionType === "CALL" ? 0 : 1,
|
|
644
|
+
amount,
|
|
645
|
+
strikeTick,
|
|
646
|
+
duration,
|
|
647
|
+
viem.maxUint256,
|
|
648
|
+
maxSteps,
|
|
649
|
+
await timelockLens.read.getRefTick([vault, strikeTick])
|
|
650
|
+
]
|
|
651
|
+
});
|
|
652
|
+
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
653
|
+
await sleep(200);
|
|
654
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
655
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
656
|
+
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
657
|
+
return hash;
|
|
658
|
+
};
|
|
659
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintOption });
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/hooks/pool/usePriceAtTick.ts
|
|
664
|
+
const usePriceAtTick = (poolManager, poolKey, tick) => {
|
|
665
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
666
|
+
const priceBigInt = (0, react.useMemo)(() => tick !== void 0 ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
667
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
668
|
+
priceBigInt,
|
|
669
|
+
token0Decimals,
|
|
670
|
+
token1Decimals
|
|
671
|
+
]);
|
|
672
|
+
};
|
|
673
|
+
const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
|
|
674
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
675
|
+
const priceBigInt = (0, react.useMemo)(() => sqrtPriceX96 !== void 0 ? require_optionUtils.getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
676
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
677
|
+
priceBigInt,
|
|
678
|
+
token0Decimals,
|
|
679
|
+
token1Decimals
|
|
680
|
+
]);
|
|
681
|
+
};
|
|
682
|
+
|
|
537
683
|
//#endregion
|
|
538
684
|
//#region src/hooks/pool/useCurrentPrice.ts
|
|
539
685
|
const useCurrentPrice = (poolManager, poolKey) => {
|
|
@@ -553,10 +699,6 @@ const useCurrentPrice = (poolManager, poolKey) => {
|
|
|
553
699
|
]);
|
|
554
700
|
};
|
|
555
701
|
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/lib/utils.ts
|
|
558
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
559
|
-
|
|
560
702
|
//#endregion
|
|
561
703
|
//#region src/hooks/options/useExerciseOption.ts
|
|
562
704
|
const useExerciseOption = (marketAddr) => {
|
|
@@ -634,132 +776,6 @@ const useExerciseOption = (marketAddr) => {
|
|
|
634
776
|
return (0, __tanstack_react_query.useMutation)({ mutationFn: exerciseOption });
|
|
635
777
|
};
|
|
636
778
|
|
|
637
|
-
//#endregion
|
|
638
|
-
//#region src/hooks/options/useMarketVolume.ts
|
|
639
|
-
const useMarketVolume = (marketAddr) => {
|
|
640
|
-
const { graphqlClient } = useTimelockConfig();
|
|
641
|
-
const { data, ...rest } = (0, __tanstack_react_query.useQuery)({
|
|
642
|
-
queryKey: ["marketVolume", (marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase()) || "--"],
|
|
643
|
-
queryFn: async () => {
|
|
644
|
-
const result = await graphqlClient.GetMarketVolume({ marketAddr: marketAddr.toLowerCase() });
|
|
645
|
-
return {
|
|
646
|
-
...result.TimelockMarket[0],
|
|
647
|
-
address: result.TimelockMarket[0].address,
|
|
648
|
-
volume: BigInt(result.TimelockMarket[0].volume),
|
|
649
|
-
optionsCount: BigInt(result.TimelockMarket[0].optionsCount),
|
|
650
|
-
tradersCount: BigInt(result.TimelockMarket[0].tradersCount)
|
|
651
|
-
};
|
|
652
|
-
},
|
|
653
|
-
enabled: !!marketAddr && !!graphqlClient
|
|
654
|
-
});
|
|
655
|
-
return {
|
|
656
|
-
data: data || {},
|
|
657
|
-
...rest
|
|
658
|
-
};
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
//#endregion
|
|
662
|
-
//#region src/hooks/options/useMaxPositionSize.ts
|
|
663
|
-
const useMaxPositionSize = (marketAddr, strikeTick, maxSteps = 100) => {
|
|
664
|
-
const { timelockLens } = useLens();
|
|
665
|
-
const { optionAssetDecimals } = useMarketData(marketAddr);
|
|
666
|
-
const { data, ...rest } = (0, wagmi.useReadContract)({
|
|
667
|
-
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
668
|
-
abi: require_optionsMarket.lensAbi,
|
|
669
|
-
functionName: strikeTick ? "getMaxPositionSizes" : "getMaxATMPositionSizes",
|
|
670
|
-
args: marketAddr ? strikeTick ? [
|
|
671
|
-
marketAddr,
|
|
672
|
-
strikeTick,
|
|
673
|
-
maxSteps
|
|
674
|
-
] : [marketAddr, maxSteps] : void 0,
|
|
675
|
-
query: { enabled: !!marketAddr && !!timelockLens },
|
|
676
|
-
gas: 100000000n
|
|
677
|
-
});
|
|
678
|
-
return {
|
|
679
|
-
maxCallSize: data && optionAssetDecimals ? require_optionUtils.wrapAmount(data[0], optionAssetDecimals) : void 0,
|
|
680
|
-
maxPutSize: data && optionAssetDecimals ? require_optionUtils.wrapAmount(data[1], optionAssetDecimals) : void 0,
|
|
681
|
-
...rest
|
|
682
|
-
};
|
|
683
|
-
};
|
|
684
|
-
|
|
685
|
-
//#endregion
|
|
686
|
-
//#region src/hooks/tokens/useApproval.ts
|
|
687
|
-
const useApproval = () => {
|
|
688
|
-
const client = (0, wagmi.useClient)();
|
|
689
|
-
const { address } = (0, wagmi.useConnection)();
|
|
690
|
-
const { writeContractAsync, data: hash, isPending, error, reset } = (0, wagmi.useWriteContract)();
|
|
691
|
-
const askForApproval = async (tokenAddress, spenderAddress, amount) => {
|
|
692
|
-
if (!client || !address) throw new Error("Wallet not connected");
|
|
693
|
-
if (await require_optionUtils.getErc20(tokenAddress, client).read.allowance([address, spenderAddress]) < amount) await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
694
|
-
address: tokenAddress,
|
|
695
|
-
abi: viem.erc20Abi,
|
|
696
|
-
functionName: "approve",
|
|
697
|
-
args: [spenderAddress, viem.maxUint256]
|
|
698
|
-
}) });
|
|
699
|
-
};
|
|
700
|
-
return {
|
|
701
|
-
askForApproval,
|
|
702
|
-
hash,
|
|
703
|
-
isPending,
|
|
704
|
-
error,
|
|
705
|
-
reset
|
|
706
|
-
};
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
//#endregion
|
|
710
|
-
//#region src/hooks/options/useMintOption.ts
|
|
711
|
-
const useMintOption = (marketAddr) => {
|
|
712
|
-
const { payoutAsset, vault, poolManager, poolKey, optionAssetIsToken0 } = useMarketData(marketAddr);
|
|
713
|
-
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
714
|
-
const { refetch: refetchCurrentTick } = useCurrentTick(poolManager, poolKey);
|
|
715
|
-
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
716
|
-
const client = (0, wagmi.useClient)();
|
|
717
|
-
const { address } = (0, wagmi.useConnection)();
|
|
718
|
-
const { timelockLens } = useLens();
|
|
719
|
-
const { askForApproval } = useApproval();
|
|
720
|
-
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
721
|
-
const mintOption = async ({ optionType, amount, duration, strikeTick, maxSteps = 100 }) => {
|
|
722
|
-
if (!client || !address) throw new Error("Wallet not connected");
|
|
723
|
-
if (!marketAddr) throw new Error("Market address not available");
|
|
724
|
-
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
725
|
-
if (!tickSpacing) throw new Error("Pool data not available");
|
|
726
|
-
if (!vault || !payoutAsset || optionAssetIsToken0 === void 0) throw new Error("Market data not available");
|
|
727
|
-
const { data: { exact: currentTick } = {} } = await refetchCurrentTick();
|
|
728
|
-
if (currentTick === void 0) throw new Error("Could not fetch current tick");
|
|
729
|
-
strikeTick = require_optionUtils.getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
|
|
730
|
-
const [premium, protocolFee] = await require_optionUtils.getTimelockMarket(marketAddr, client).read.calculatePremium([
|
|
731
|
-
optionType === "CALL" ? 0 : 1,
|
|
732
|
-
amount,
|
|
733
|
-
strikeTick,
|
|
734
|
-
duration,
|
|
735
|
-
0
|
|
736
|
-
]);
|
|
737
|
-
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
|
|
738
|
-
const hash = await writeContractAsync({
|
|
739
|
-
address: marketAddr,
|
|
740
|
-
abi: require_optionsMarket.optionsMarketAbi,
|
|
741
|
-
functionName: "mintOption",
|
|
742
|
-
args: [
|
|
743
|
-
address,
|
|
744
|
-
optionType === "CALL" ? 0 : 1,
|
|
745
|
-
amount,
|
|
746
|
-
strikeTick,
|
|
747
|
-
duration,
|
|
748
|
-
viem.maxUint256,
|
|
749
|
-
maxSteps,
|
|
750
|
-
await timelockLens.read.getRefTick([vault, strikeTick])
|
|
751
|
-
]
|
|
752
|
-
});
|
|
753
|
-
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
754
|
-
await sleep(200);
|
|
755
|
-
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
756
|
-
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
757
|
-
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
758
|
-
return hash;
|
|
759
|
-
};
|
|
760
|
-
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintOption });
|
|
761
|
-
};
|
|
762
|
-
|
|
763
779
|
//#endregion
|
|
764
780
|
//#region src/hooks/options/useOptionPnl.ts
|
|
765
781
|
const useOptionPnl = (option) => {
|
|
@@ -2198,22 +2214,6 @@ const useFeeRates = (feeStrategy) => {
|
|
|
2198
2214
|
return data || {};
|
|
2199
2215
|
};
|
|
2200
2216
|
|
|
2201
|
-
//#endregion
|
|
2202
|
-
//#region src/hooks/options/useMarketState.ts
|
|
2203
|
-
const useMarketState = (marketAddr) => {
|
|
2204
|
-
const { timelockLens } = useLens();
|
|
2205
|
-
const { data, ...rest } = (0, wagmi.useReadContract)({
|
|
2206
|
-
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
2207
|
-
abi: require_optionsMarket.lensAbi,
|
|
2208
|
-
functionName: "getMarketState",
|
|
2209
|
-
args: marketAddr ? [marketAddr] : void 0
|
|
2210
|
-
});
|
|
2211
|
-
return {
|
|
2212
|
-
data: data || {},
|
|
2213
|
-
...rest
|
|
2214
|
-
};
|
|
2215
|
-
};
|
|
2216
|
-
|
|
2217
2217
|
//#endregion
|
|
2218
2218
|
//#region src/abis/factory.ts
|
|
2219
2219
|
const factoryAbi = [
|
|
@@ -2519,6 +2519,195 @@ const useUpdateMarketFees = (marketAddr) => {
|
|
|
2519
2519
|
};
|
|
2520
2520
|
};
|
|
2521
2521
|
|
|
2522
|
+
//#endregion
|
|
2523
|
+
//#region src/hooks/pricing/useMarketPricing.ts
|
|
2524
|
+
const useMarketPricing = (marketAddr) => {
|
|
2525
|
+
const { data: { optionPricing } } = useMarketState(marketAddr);
|
|
2526
|
+
return (0, wagmi.useReadContract)({
|
|
2527
|
+
address: optionPricing,
|
|
2528
|
+
abi: [{
|
|
2529
|
+
inputs: [],
|
|
2530
|
+
name: "readState",
|
|
2531
|
+
outputs: [{
|
|
2532
|
+
name: "",
|
|
2533
|
+
type: "bytes"
|
|
2534
|
+
}],
|
|
2535
|
+
stateMutability: "view",
|
|
2536
|
+
type: "function"
|
|
2537
|
+
}],
|
|
2538
|
+
functionName: "readState",
|
|
2539
|
+
query: {
|
|
2540
|
+
enabled: !!optionPricing,
|
|
2541
|
+
select: (rawData) => {
|
|
2542
|
+
const [pricingModel] = (0, viem.decodeAbiParameters)([{
|
|
2543
|
+
name: "model",
|
|
2544
|
+
type: "uint8"
|
|
2545
|
+
}], rawData);
|
|
2546
|
+
if (pricingModel === 0) {
|
|
2547
|
+
const [, logicContract, iv, riskFreeRate, minPremiumDailyRate, minPremiumAmount] = (0, viem.decodeAbiParameters)([
|
|
2548
|
+
{
|
|
2549
|
+
name: "pricingModel",
|
|
2550
|
+
type: "uint8"
|
|
2551
|
+
},
|
|
2552
|
+
{
|
|
2553
|
+
name: "logicContract",
|
|
2554
|
+
type: "address"
|
|
2555
|
+
},
|
|
2556
|
+
{
|
|
2557
|
+
name: "iv",
|
|
2558
|
+
type: "uint32"
|
|
2559
|
+
},
|
|
2560
|
+
{
|
|
2561
|
+
name: "riskFreeRate",
|
|
2562
|
+
type: "uint32"
|
|
2563
|
+
},
|
|
2564
|
+
{
|
|
2565
|
+
name: "minPremiumDailyRate",
|
|
2566
|
+
type: "uint32"
|
|
2567
|
+
},
|
|
2568
|
+
{
|
|
2569
|
+
name: "minPremiumAmount",
|
|
2570
|
+
type: "uint256"
|
|
2571
|
+
}
|
|
2572
|
+
], rawData);
|
|
2573
|
+
return {
|
|
2574
|
+
model: "option",
|
|
2575
|
+
logicContract,
|
|
2576
|
+
iv,
|
|
2577
|
+
riskFreeRate,
|
|
2578
|
+
minPremiumDailyRate,
|
|
2579
|
+
minPremiumAmount
|
|
2580
|
+
};
|
|
2581
|
+
} else if (pricingModel === 1) {
|
|
2582
|
+
const [, dailyFundingRate, minFundingAmount] = (0, viem.decodeAbiParameters)([
|
|
2583
|
+
{
|
|
2584
|
+
name: "pricingModel",
|
|
2585
|
+
type: "uint8"
|
|
2586
|
+
},
|
|
2587
|
+
{
|
|
2588
|
+
name: "dailyFundingRate",
|
|
2589
|
+
type: "uint32"
|
|
2590
|
+
},
|
|
2591
|
+
{
|
|
2592
|
+
name: "minFundingAmount",
|
|
2593
|
+
type: "uint128"
|
|
2594
|
+
}
|
|
2595
|
+
], rawData);
|
|
2596
|
+
return {
|
|
2597
|
+
model: "static",
|
|
2598
|
+
dailyFundingRate,
|
|
2599
|
+
minFundingAmount
|
|
2600
|
+
};
|
|
2601
|
+
}
|
|
2602
|
+
throw new Error("Unknown pricing model");
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
});
|
|
2606
|
+
};
|
|
2607
|
+
|
|
2608
|
+
//#endregion
|
|
2609
|
+
//#region src/hooks/pricing/useOptionPricingParams.ts
|
|
2610
|
+
const useOptionPricingParams = (pricingAddr) => {
|
|
2611
|
+
const { timelockLens } = useLens();
|
|
2612
|
+
const { data } = (0, wagmi.useReadContract)({
|
|
2613
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
2614
|
+
abi: require_optionsMarket.lensAbi,
|
|
2615
|
+
args: pricingAddr ? [pricingAddr] : void 0,
|
|
2616
|
+
functionName: "getOptionPricingParams"
|
|
2617
|
+
});
|
|
2618
|
+
return data || {};
|
|
2619
|
+
};
|
|
2620
|
+
|
|
2621
|
+
//#endregion
|
|
2622
|
+
//#region src/hooks/pricing/useStaticPricingParams.ts
|
|
2623
|
+
const useStaticPricingParams = (pricingAddr) => {
|
|
2624
|
+
const { timelockLens } = useLens();
|
|
2625
|
+
const { data } = (0, wagmi.useReadContract)({
|
|
2626
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
2627
|
+
abi: require_optionsMarket.lensAbi,
|
|
2628
|
+
args: pricingAddr ? [pricingAddr] : void 0,
|
|
2629
|
+
functionName: "getStaticPricingParams"
|
|
2630
|
+
});
|
|
2631
|
+
return data || {};
|
|
2632
|
+
};
|
|
2633
|
+
|
|
2634
|
+
//#endregion
|
|
2635
|
+
//#region src/hooks/pricing/useUpdateMarketPricing.ts
|
|
2636
|
+
const useUpdateMarketPricing = (marketAddr) => {
|
|
2637
|
+
const { writeContractAsync, ...rest } = (0, wagmi.useWriteContract)();
|
|
2638
|
+
const publicClient = (0, wagmi.usePublicClient)();
|
|
2639
|
+
const chainId = (0, wagmi.useChainId)();
|
|
2640
|
+
const { data: { feeStrategy } } = useMarketState();
|
|
2641
|
+
const { data: pricingData } = useMarketPricing(marketAddr);
|
|
2642
|
+
const updateMarketPricing = async (data) => {
|
|
2643
|
+
if (!pricingData) throw new Error("Market pricing data not available");
|
|
2644
|
+
if (!publicClient) throw new Error("Public client not available");
|
|
2645
|
+
if (!feeStrategy) throw new Error("Fee strategy not available");
|
|
2646
|
+
const factoryAddr = require_optionUtils.timelockFactories[chainId].toLowerCase();
|
|
2647
|
+
if (data.model === "static" && pricingData.model === "static") {
|
|
2648
|
+
data.dailyFundingRate ?? (data.dailyFundingRate = pricingData.dailyFundingRate);
|
|
2649
|
+
data.minFundingAmount ?? (data.minFundingAmount = pricingData.minFundingAmount);
|
|
2650
|
+
}
|
|
2651
|
+
if (data.model === "option" && pricingData.model === "option") {
|
|
2652
|
+
data.logicContract ?? (data.logicContract = pricingData.logicContract);
|
|
2653
|
+
data.iv ?? (data.iv = pricingData.iv);
|
|
2654
|
+
data.riskFreeRate ?? (data.riskFreeRate = pricingData.riskFreeRate);
|
|
2655
|
+
data.minPremiumDailyRate ?? (data.minPremiumDailyRate = pricingData.minPremiumDailyRate);
|
|
2656
|
+
data.minPremiumAmount ?? (data.minPremiumAmount = pricingData.minPremiumAmount);
|
|
2657
|
+
}
|
|
2658
|
+
if (data.model !== pricingData.model) if (data.model === "static") {
|
|
2659
|
+
if (data.dailyFundingRate === void 0) throw new Error("dailyFundingRate is required when switching to static model");
|
|
2660
|
+
if (data.minFundingAmount === void 0) throw new Error("minFundingAmount is required when switching to static model");
|
|
2661
|
+
} else {
|
|
2662
|
+
if (data.logicContract === void 0) throw new Error("logicContract is required when switching to option model");
|
|
2663
|
+
if (data.iv === void 0) throw new Error("iv is required when switching to option model");
|
|
2664
|
+
if (data.riskFreeRate === void 0) throw new Error("riskFreeRate is required when switching to option model");
|
|
2665
|
+
if (data.minPremiumDailyRate === void 0) throw new Error("minPremiumDailyRate is required when switching to option model");
|
|
2666
|
+
if (data.minPremiumAmount === void 0) throw new Error("minPremiumAmount is required when switching to option model");
|
|
2667
|
+
}
|
|
2668
|
+
const hash = data.model === "static" ? await writeContractAsync({
|
|
2669
|
+
address: factoryAddr,
|
|
2670
|
+
abi: factoryAbi,
|
|
2671
|
+
functionName: "deployStaticPerpsPricing",
|
|
2672
|
+
args: [data.dailyFundingRate, data.minFundingAmount]
|
|
2673
|
+
}) : await writeContractAsync({
|
|
2674
|
+
address: factoryAddr,
|
|
2675
|
+
abi: factoryAbi,
|
|
2676
|
+
functionName: "deployOptionPricing",
|
|
2677
|
+
args: [
|
|
2678
|
+
data.logicContract,
|
|
2679
|
+
data.iv,
|
|
2680
|
+
data.riskFreeRate,
|
|
2681
|
+
data.minPremiumDailyRate,
|
|
2682
|
+
data.minPremiumAmount
|
|
2683
|
+
]
|
|
2684
|
+
});
|
|
2685
|
+
const deployEvent = (await publicClient.waitForTransactionReceipt({ hash })).logs.find((log) => log.address.toLowerCase() === factoryAddr);
|
|
2686
|
+
if (!deployEvent) throw new Error("DeployFeeStrategy event not found");
|
|
2687
|
+
const decodedEvent = (0, viem.decodeEventLog)({
|
|
2688
|
+
abi: factoryAbi,
|
|
2689
|
+
data: deployEvent.data,
|
|
2690
|
+
topics: deployEvent.topics
|
|
2691
|
+
});
|
|
2692
|
+
if (decodedEvent.eventName !== "DeployStaticPerpsPricing" && decodedEvent.eventName !== "DeployOptionPricing") throw new Error("Unexpected event");
|
|
2693
|
+
const pricingAddr = decodedEvent.args.pricing;
|
|
2694
|
+
return {
|
|
2695
|
+
deployHash: hash,
|
|
2696
|
+
updateHash: await writeContractAsync({
|
|
2697
|
+
address: marketAddr,
|
|
2698
|
+
abi: require_optionsMarket.optionsMarketAbi,
|
|
2699
|
+
functionName: "updateAddresses",
|
|
2700
|
+
args: [pricingAddr, feeStrategy]
|
|
2701
|
+
}),
|
|
2702
|
+
newPricingAddr: pricingAddr
|
|
2703
|
+
};
|
|
2704
|
+
};
|
|
2705
|
+
return {
|
|
2706
|
+
updateMarketPricing,
|
|
2707
|
+
...rest
|
|
2708
|
+
};
|
|
2709
|
+
};
|
|
2710
|
+
|
|
2522
2711
|
//#endregion
|
|
2523
2712
|
exports.TimelockProvider = TimelockProvider;
|
|
2524
2713
|
exports.batchGetAmountsFromLiquidity = batchGetAmountsFromLiquidity;
|
|
@@ -2540,6 +2729,8 @@ exports.useLens = useLens;
|
|
|
2540
2729
|
exports.useLiquidityBlocks = useLiquidityBlocks;
|
|
2541
2730
|
exports.useMarketData = useMarketData;
|
|
2542
2731
|
exports.useMarketPriceHistory = useMarketPriceHistory;
|
|
2732
|
+
exports.useMarketPricing = useMarketPricing;
|
|
2733
|
+
exports.useMarketState = useMarketState;
|
|
2543
2734
|
exports.useMarketVolume = useMarketVolume;
|
|
2544
2735
|
exports.useMaxPositionSize = useMaxPositionSize;
|
|
2545
2736
|
exports.useMintLiquidity = useMintLiquidity;
|
|
@@ -2548,6 +2739,7 @@ exports.useMintPerp = useMintPerp;
|
|
|
2548
2739
|
exports.useOperatorPerms = useOperatorPerms;
|
|
2549
2740
|
exports.useOptionPnl = useOptionPnl;
|
|
2550
2741
|
exports.useOptionPremium = useOptionPremium;
|
|
2742
|
+
exports.useOptionPricingParams = useOptionPricingParams;
|
|
2551
2743
|
exports.useOptionTimeline = useOptionTimeline;
|
|
2552
2744
|
exports.usePauseGlobalTrading = usePauseGlobalTrading;
|
|
2553
2745
|
exports.usePauseMarketTrading = usePauseMarketTrading;
|
|
@@ -2557,10 +2749,12 @@ exports.usePriceAtSqrtPriceX96 = usePriceAtSqrtPriceX96;
|
|
|
2557
2749
|
exports.usePriceAtTick = usePriceAtTick;
|
|
2558
2750
|
exports.usePriceHistory = usePriceHistory;
|
|
2559
2751
|
exports.useSetOperatorPerms = useSetOperatorPerms;
|
|
2752
|
+
exports.useStaticPricingParams = useStaticPricingParams;
|
|
2560
2753
|
exports.useTimelockConfig = useTimelockConfig;
|
|
2561
2754
|
exports.useTokenBalance = useTokenBalance;
|
|
2562
2755
|
exports.useTokenData = useTokenData;
|
|
2563
2756
|
exports.useUpdateMarketFees = useUpdateMarketFees;
|
|
2757
|
+
exports.useUpdateMarketPricing = useUpdateMarketPricing;
|
|
2564
2758
|
exports.useUserOperators = useUserOperators;
|
|
2565
2759
|
exports.useUserPerps = useUserPerps;
|
|
2566
2760
|
exports.useVaultData = useVaultData;
|