timelock-sdk 0.0.157 → 0.0.160

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.
Files changed (31) hide show
  1. package/dist/abis.cjs +1 -1
  2. package/dist/abis.d.cts +1 -1
  3. package/dist/abis.d.ts +1 -1
  4. package/dist/abis.js +1 -1
  5. package/dist/{client-CSYKjcyD.d.cts → client-DmXuKRhM.d.cts} +12987 -3020
  6. package/dist/{client-cNTMuD8y.d.ts → client-Dx6YoDji.d.ts} +12950 -2983
  7. package/dist/client.cjs +688 -169
  8. package/dist/client.cjs.map +1 -1
  9. package/dist/client.d.cts +3 -3
  10. package/dist/client.d.ts +3 -3
  11. package/dist/client.js +684 -171
  12. package/dist/client.js.map +1 -1
  13. package/dist/{optionUtils-Daz9iARj.cjs → optionUtils-B-TKN7Ni.cjs} +10 -3
  14. package/dist/optionUtils-B-TKN7Ni.cjs.map +1 -0
  15. package/dist/{optionUtils-B7EA45zY.js → optionUtils-CL-MSoFS.js} +5 -4
  16. package/dist/optionUtils-CL-MSoFS.js.map +1 -0
  17. package/dist/{optionsMarket-CT26uUTa.js → optionsMarket-BbXpQnpV.js} +193 -148
  18. package/dist/optionsMarket-BbXpQnpV.js.map +1 -0
  19. package/dist/{optionsMarket-T7r7iDKa.cjs → optionsMarket-DtjLm46g.cjs} +193 -148
  20. package/dist/optionsMarket-DtjLm46g.cjs.map +1 -0
  21. package/dist/package.cjs +3 -2
  22. package/dist/package.d.cts +3 -3
  23. package/dist/package.d.ts +3 -3
  24. package/dist/package.js +3 -3
  25. package/dist/{uniswapMathLens-DNbMIHSs.d.ts → uniswapMathLens-BoQxBJoY.d.cts} +95 -51
  26. package/dist/{uniswapMathLens-DT3TTcQa.d.cts → uniswapMathLens-Ds8UmCMU.d.ts} +95 -51
  27. package/package.json +1 -1
  28. package/dist/optionUtils-B7EA45zY.js.map +0 -1
  29. package/dist/optionUtils-Daz9iARj.cjs.map +0 -1
  30. package/dist/optionsMarket-CT26uUTa.js.map +0 -1
  31. package/dist/optionsMarket-T7r7iDKa.cjs.map +0 -1
package/dist/client.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
 
3
3
 
4
- const require_optionUtils = require('./optionUtils-Daz9iARj.cjs');
5
- const require_optionsMarket = require('./optionsMarket-T7r7iDKa.cjs');
4
+ const require_optionUtils = require('./optionUtils-B-TKN7Ni.cjs');
5
+ const require_optionsMarket = require('./optionsMarket-DtjLm46g.cjs');
6
6
  const require_singleOwnerVault = require('./singleOwnerVault-GCpQV7pN.cjs');
7
7
  let viem = require("viem");
8
8
  let react = require("react");
@@ -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
@@ -462,183 +462,26 @@ const useMarketData = (marketAddr) => {
462
462
  };
463
463
 
464
464
  //#endregion
465
- //#region src/hooks/pool/usePoolData.ts
466
- const usePoolData = (poolManager, poolKey) => {
465
+ //#region src/hooks/options/useMarketState.ts
466
+ const useMarketState = (marketAddr) => {
467
467
  const { timelockLens } = useLens();
468
- const { data } = (0, wagmi.useReadContract)({
468
+ const { data, ...rest } = (0, wagmi.useReadContract)({
469
469
  address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
470
470
  abi: require_optionsMarket.lensAbi,
471
- functionName: "getPoolData",
472
- args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
473
- query: { enabled: !!poolManager && !!poolKey }
474
- });
475
- const _default = (0, react.useMemo)(() => ({
476
- token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
477
- token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
478
- tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
479
- fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
480
- }), [poolKey]);
481
- return data || _default;
482
- };
483
-
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
- //#endregion
506
- //#region src/hooks/pool/useCurrentTick.ts
507
- const useCurrentTick = (poolManager, poolKey) => {
508
- const { stateView } = useLens();
509
- const { tickSpacing } = usePoolData(poolManager, poolKey);
510
- const { data, ...rest } = (0, wagmi.useReadContract)({
511
- address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
512
- abi: require_optionUtils.statelessStateViewAbi,
513
- functionName: "getSlot0",
514
- args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
515
- query: {
516
- enabled: !!poolManager && !!poolKey,
517
- refetchInterval: 3e3,
518
- select: (raw) => {
519
- const sqrtPriceX96 = raw[0];
520
- const exact = raw[1];
521
- return {
522
- exact,
523
- rounded: tickSpacing ? require_optionUtils.roundTick(exact, tickSpacing) : void 0,
524
- sqrtPriceX96
525
- };
526
- }
527
- }
471
+ functionName: "getMarketState",
472
+ args: marketAddr ? [marketAddr] : void 0
528
473
  });
529
474
  return {
530
- exact: data === null || data === void 0 ? void 0 : data.exact,
531
- rounded: data === null || data === void 0 ? void 0 : data.rounded,
532
- sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
475
+ data: data || {},
533
476
  ...rest
534
477
  };
535
478
  };
536
479
 
537
- //#endregion
538
- //#region src/hooks/pool/useCurrentPrice.ts
539
- const useCurrentPrice = (poolManager, poolKey) => {
540
- const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
541
- const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
542
- return (0, react.useMemo)(() => ({
543
- currentPrice,
544
- sqrtPriceX96,
545
- currentTick: {
546
- exact,
547
- rounded
548
- }
549
- }), [
550
- currentPrice,
551
- exact,
552
- rounded
553
- ]);
554
- };
555
-
556
- //#endregion
557
- //#region src/lib/utils.ts
558
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
559
-
560
- //#endregion
561
- //#region src/hooks/options/useExerciseOption.ts
562
- const useExerciseOption = (marketAddr) => {
563
- const { vault, poolManager, poolKey } = useMarketData(marketAddr);
564
- const { timelockLens } = useLens();
565
- const queryClient = (0, __tanstack_react_query.useQueryClient)();
566
- const client = (0, wagmi.useClient)();
567
- const { address } = (0, wagmi.useConnection)();
568
- const { writeContractAsync } = (0, wagmi.useWriteContract)();
569
- const { sqrtPriceX96 } = useCurrentPrice(poolManager, poolKey);
570
- const exerciseOption = async ({ option, liquidities }) => {
571
- if (!client || !address) throw new Error("Wallet not connected");
572
- if (!marketAddr) throw new Error("Market address not available");
573
- if (!timelockLens) throw new Error("Timelock lens not available");
574
- if (!vault) throw new Error("Vault not available");
575
- if (!poolKey) throw new Error("Pool data not available");
576
- if (!sqrtPriceX96) throw new Error("Current price not available");
577
- const swapper = require_optionUtils.swappers[client.chain.id];
578
- if (!swapper) throw new Error("Swapper not available");
579
- const minSqrtPrice = sqrtPriceX96 * 9n / 10n;
580
- const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
581
- const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
582
- const hash = await writeContractAsync({
583
- address: marketAddr,
584
- abi: require_optionsMarket.optionsMarketAbi,
585
- functionName: "exerciseOption",
586
- args: [
587
- option.optionId,
588
- liquidities,
589
- 0n,
590
- swapper,
591
- (0, viem.encodeAbiParameters)([
592
- {
593
- type: "tuple",
594
- components: [
595
- {
596
- type: "address",
597
- name: "currency0"
598
- },
599
- {
600
- type: "address",
601
- name: "currency1"
602
- },
603
- {
604
- type: "uint24",
605
- name: "fee"
606
- },
607
- {
608
- type: "int24",
609
- name: "tickSpacing"
610
- },
611
- {
612
- type: "address",
613
- name: "hooks"
614
- }
615
- ]
616
- },
617
- { type: "uint160" },
618
- { type: "uint160" }
619
- ], [
620
- poolKey,
621
- minSqrtPrice,
622
- maxSqrtPrice
623
- ]),
624
- refTick
625
- ]
626
- });
627
- await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
628
- await sleep(200);
629
- queryClient.invalidateQueries({ queryKey: ["userOptions"] });
630
- queryClient.invalidateQueries({ queryKey: ["userOptions"] });
631
- queryClient.invalidateQueries({ queryKey: ["readContract"] });
632
- return hash;
633
- };
634
- return (0, __tanstack_react_query.useMutation)({ mutationFn: exerciseOption });
635
- };
636
-
637
480
  //#endregion
638
481
  //#region src/hooks/options/useMarketVolume.ts
639
482
  const useMarketVolume = (marketAddr) => {
640
483
  const { graphqlClient } = useTimelockConfig();
641
- const { data } = (0, __tanstack_react_query.useQuery)({
484
+ const { data, ...rest } = (0, __tanstack_react_query.useQuery)({
642
485
  queryKey: ["marketVolume", (marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase()) || "--"],
643
486
  queryFn: async () => {
644
487
  const result = await graphqlClient.GetMarketVolume({ marketAddr: marketAddr.toLowerCase() });
@@ -652,7 +495,10 @@ const useMarketVolume = (marketAddr) => {
652
495
  },
653
496
  enabled: !!marketAddr && !!graphqlClient
654
497
  });
655
- return data || {};
498
+ return {
499
+ data: data || {},
500
+ ...rest
501
+ };
656
502
  };
657
503
 
658
504
  //#endregion
@@ -679,6 +525,58 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxSteps = 100) => {
679
525
  };
680
526
  };
681
527
 
528
+ //#endregion
529
+ //#region src/hooks/pool/usePoolData.ts
530
+ const usePoolData = (poolManager, poolKey) => {
531
+ const { timelockLens } = useLens();
532
+ const { data } = (0, wagmi.useReadContract)({
533
+ address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
534
+ abi: require_optionsMarket.lensAbi,
535
+ functionName: "getPoolData",
536
+ args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
537
+ query: { enabled: !!poolManager && !!poolKey }
538
+ });
539
+ const _default = (0, react.useMemo)(() => ({
540
+ token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
541
+ token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
542
+ tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
543
+ fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
544
+ }), [poolKey]);
545
+ return data || _default;
546
+ };
547
+
548
+ //#endregion
549
+ //#region src/hooks/pool/useCurrentTick.ts
550
+ const useCurrentTick = (poolManager, poolKey) => {
551
+ const { stateView } = useLens();
552
+ const { tickSpacing } = usePoolData(poolManager, poolKey);
553
+ const { data, ...rest } = (0, wagmi.useReadContract)({
554
+ address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
555
+ abi: require_optionUtils.statelessStateViewAbi,
556
+ functionName: "getSlot0",
557
+ args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
558
+ query: {
559
+ enabled: !!poolManager && !!poolKey,
560
+ refetchInterval: 3e3,
561
+ select: (raw) => {
562
+ const sqrtPriceX96 = raw[0];
563
+ const exact = raw[1];
564
+ return {
565
+ exact,
566
+ rounded: tickSpacing ? require_optionUtils.roundTick(exact, tickSpacing) : void 0,
567
+ sqrtPriceX96
568
+ };
569
+ }
570
+ }
571
+ });
572
+ return {
573
+ exact: data === null || data === void 0 ? void 0 : data.exact,
574
+ rounded: data === null || data === void 0 ? void 0 : data.rounded,
575
+ sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
576
+ ...rest
577
+ };
578
+ };
579
+
682
580
  //#endregion
683
581
  //#region src/hooks/tokens/useApproval.ts
684
582
  const useApproval = () => {
@@ -703,6 +601,10 @@ const useApproval = () => {
703
601
  };
704
602
  };
705
603
 
604
+ //#endregion
605
+ //#region src/lib/utils.ts
606
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
607
+
706
608
  //#endregion
707
609
  //#region src/hooks/options/useMintOption.ts
708
610
  const useMintOption = (marketAddr) => {
@@ -754,7 +656,124 @@ const useMintOption = (marketAddr) => {
754
656
  queryClient.invalidateQueries({ queryKey: ["readContract"] });
755
657
  return hash;
756
658
  };
757
- return (0, __tanstack_react_query.useMutation)({ mutationFn: mintOption });
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
+
683
+ //#endregion
684
+ //#region src/hooks/pool/useCurrentPrice.ts
685
+ const useCurrentPrice = (poolManager, poolKey) => {
686
+ const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
687
+ const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
688
+ return (0, react.useMemo)(() => ({
689
+ currentPrice,
690
+ sqrtPriceX96,
691
+ currentTick: {
692
+ exact,
693
+ rounded
694
+ }
695
+ }), [
696
+ currentPrice,
697
+ exact,
698
+ rounded
699
+ ]);
700
+ };
701
+
702
+ //#endregion
703
+ //#region src/hooks/options/useExerciseOption.ts
704
+ const useExerciseOption = (marketAddr) => {
705
+ const { vault, poolManager, poolKey } = useMarketData(marketAddr);
706
+ const { timelockLens } = useLens();
707
+ const queryClient = (0, __tanstack_react_query.useQueryClient)();
708
+ const client = (0, wagmi.useClient)();
709
+ const { address } = (0, wagmi.useConnection)();
710
+ const { writeContractAsync } = (0, wagmi.useWriteContract)();
711
+ const { sqrtPriceX96 } = useCurrentPrice(poolManager, poolKey);
712
+ const exerciseOption = async ({ option, liquidities }) => {
713
+ if (!client || !address) throw new Error("Wallet not connected");
714
+ if (!marketAddr) throw new Error("Market address not available");
715
+ if (!timelockLens) throw new Error("Timelock lens not available");
716
+ if (!vault) throw new Error("Vault not available");
717
+ if (!poolKey) throw new Error("Pool data not available");
718
+ if (!sqrtPriceX96) throw new Error("Current price not available");
719
+ const swapper = require_optionUtils.swappers[client.chain.id];
720
+ if (!swapper) throw new Error("Swapper not available");
721
+ const minSqrtPrice = sqrtPriceX96 * 9n / 10n;
722
+ const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
723
+ const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
724
+ const hash = await writeContractAsync({
725
+ address: marketAddr,
726
+ abi: require_optionsMarket.optionsMarketAbi,
727
+ functionName: "exerciseOption",
728
+ args: [
729
+ option.optionId,
730
+ liquidities,
731
+ 0n,
732
+ swapper,
733
+ (0, viem.encodeAbiParameters)([
734
+ {
735
+ type: "tuple",
736
+ components: [
737
+ {
738
+ type: "address",
739
+ name: "currency0"
740
+ },
741
+ {
742
+ type: "address",
743
+ name: "currency1"
744
+ },
745
+ {
746
+ type: "uint24",
747
+ name: "fee"
748
+ },
749
+ {
750
+ type: "int24",
751
+ name: "tickSpacing"
752
+ },
753
+ {
754
+ type: "address",
755
+ name: "hooks"
756
+ }
757
+ ]
758
+ },
759
+ { type: "uint160" },
760
+ { type: "uint160" }
761
+ ], [
762
+ poolKey,
763
+ minSqrtPrice,
764
+ maxSqrtPrice
765
+ ]),
766
+ refTick
767
+ ]
768
+ });
769
+ await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
770
+ await sleep(200);
771
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
772
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
773
+ queryClient.invalidateQueries({ queryKey: ["readContract"] });
774
+ return hash;
775
+ };
776
+ return (0, __tanstack_react_query.useMutation)({ mutationFn: exerciseOption });
758
777
  };
759
778
 
760
779
  //#endregion
@@ -2195,6 +2214,500 @@ const useFeeRates = (feeStrategy) => {
2195
2214
  return data || {};
2196
2215
  };
2197
2216
 
2217
+ //#endregion
2218
+ //#region src/abis/factory.ts
2219
+ const factoryAbi = [
2220
+ {
2221
+ type: "function",
2222
+ name: "deployFeeStrategy",
2223
+ inputs: [
2224
+ {
2225
+ name: "_openingFeeRate",
2226
+ type: "uint32",
2227
+ internalType: "uint32"
2228
+ },
2229
+ {
2230
+ name: "_baseFeeRate",
2231
+ type: "uint32",
2232
+ internalType: "uint32"
2233
+ },
2234
+ {
2235
+ name: "_minOpeningFee",
2236
+ type: "uint128",
2237
+ internalType: "uint128"
2238
+ },
2239
+ {
2240
+ name: "_minBaseFee",
2241
+ type: "uint128",
2242
+ internalType: "uint128"
2243
+ },
2244
+ {
2245
+ name: "_feeRecipient",
2246
+ type: "address",
2247
+ internalType: "address"
2248
+ }
2249
+ ],
2250
+ outputs: [{
2251
+ name: "",
2252
+ type: "address",
2253
+ internalType: "contract FeeStrategy"
2254
+ }],
2255
+ stateMutability: "nonpayable"
2256
+ },
2257
+ {
2258
+ type: "function",
2259
+ name: "deployOptionPricing",
2260
+ inputs: [
2261
+ {
2262
+ name: "_logicContract",
2263
+ type: "address",
2264
+ internalType: "contract StatelessOptionPricing"
2265
+ },
2266
+ {
2267
+ name: "_iv",
2268
+ type: "uint32",
2269
+ internalType: "uint32"
2270
+ },
2271
+ {
2272
+ name: "_riskFreeRate",
2273
+ type: "uint32",
2274
+ internalType: "uint32"
2275
+ },
2276
+ {
2277
+ name: "_minPremiumDailyRate",
2278
+ type: "uint32",
2279
+ internalType: "uint32"
2280
+ },
2281
+ {
2282
+ name: "_minPremiumAmount",
2283
+ type: "uint256",
2284
+ internalType: "uint256"
2285
+ }
2286
+ ],
2287
+ outputs: [{
2288
+ name: "",
2289
+ type: "address",
2290
+ internalType: "contract OptionPricing"
2291
+ }],
2292
+ stateMutability: "nonpayable"
2293
+ },
2294
+ {
2295
+ type: "function",
2296
+ name: "deployStaticPerpsPricing",
2297
+ inputs: [{
2298
+ name: "_dailyFundingRate",
2299
+ type: "uint32",
2300
+ internalType: "uint32"
2301
+ }, {
2302
+ name: "_minFundingAmount",
2303
+ type: "uint128",
2304
+ internalType: "uint128"
2305
+ }],
2306
+ outputs: [{
2307
+ name: "",
2308
+ type: "address",
2309
+ internalType: "contract StaticPerpsPricing"
2310
+ }],
2311
+ stateMutability: "nonpayable"
2312
+ },
2313
+ {
2314
+ type: "function",
2315
+ name: "feeStrategies",
2316
+ inputs: [{
2317
+ name: "",
2318
+ type: "bytes32",
2319
+ internalType: "bytes32"
2320
+ }],
2321
+ outputs: [{
2322
+ name: "",
2323
+ type: "address",
2324
+ internalType: "contract FeeStrategy"
2325
+ }],
2326
+ stateMutability: "view"
2327
+ },
2328
+ {
2329
+ type: "function",
2330
+ name: "optionPricings",
2331
+ inputs: [{
2332
+ name: "",
2333
+ type: "bytes32",
2334
+ internalType: "bytes32"
2335
+ }],
2336
+ outputs: [{
2337
+ name: "",
2338
+ type: "address",
2339
+ internalType: "contract OptionPricing"
2340
+ }],
2341
+ stateMutability: "view"
2342
+ },
2343
+ {
2344
+ type: "function",
2345
+ name: "staticPerpsPricings",
2346
+ inputs: [{
2347
+ name: "",
2348
+ type: "bytes32",
2349
+ internalType: "bytes32"
2350
+ }],
2351
+ outputs: [{
2352
+ name: "",
2353
+ type: "address",
2354
+ internalType: "contract StaticPerpsPricing"
2355
+ }],
2356
+ stateMutability: "view"
2357
+ },
2358
+ {
2359
+ type: "event",
2360
+ name: "DeployFeeStrategy",
2361
+ inputs: [
2362
+ {
2363
+ name: "feeStrategy",
2364
+ type: "address",
2365
+ indexed: true,
2366
+ internalType: "contract FeeStrategy"
2367
+ },
2368
+ {
2369
+ name: "openingFeeRate",
2370
+ type: "uint32",
2371
+ indexed: false,
2372
+ internalType: "uint32"
2373
+ },
2374
+ {
2375
+ name: "baseFeeRate",
2376
+ type: "uint32",
2377
+ indexed: false,
2378
+ internalType: "uint32"
2379
+ },
2380
+ {
2381
+ name: "minOpeningFee",
2382
+ type: "uint128",
2383
+ indexed: false,
2384
+ internalType: "uint128"
2385
+ },
2386
+ {
2387
+ name: "minBaseFee",
2388
+ type: "uint128",
2389
+ indexed: false,
2390
+ internalType: "uint128"
2391
+ },
2392
+ {
2393
+ name: "feeRecipient",
2394
+ type: "address",
2395
+ indexed: false,
2396
+ internalType: "address"
2397
+ }
2398
+ ],
2399
+ anonymous: false
2400
+ },
2401
+ {
2402
+ type: "event",
2403
+ name: "DeployOptionPricing",
2404
+ inputs: [
2405
+ {
2406
+ name: "pricing",
2407
+ type: "address",
2408
+ indexed: true,
2409
+ internalType: "contract OptionPricing"
2410
+ },
2411
+ {
2412
+ name: "statelessPricing",
2413
+ type: "address",
2414
+ indexed: false,
2415
+ internalType: "contract StatelessOptionPricing"
2416
+ },
2417
+ {
2418
+ name: "iv",
2419
+ type: "uint32",
2420
+ indexed: false,
2421
+ internalType: "uint32"
2422
+ },
2423
+ {
2424
+ name: "riskFreeRate",
2425
+ type: "uint32",
2426
+ indexed: false,
2427
+ internalType: "uint32"
2428
+ },
2429
+ {
2430
+ name: "minPremiumDailyRate",
2431
+ type: "uint32",
2432
+ indexed: false,
2433
+ internalType: "uint32"
2434
+ },
2435
+ {
2436
+ name: "minPremiumAmount",
2437
+ type: "uint256",
2438
+ indexed: false,
2439
+ internalType: "uint256"
2440
+ }
2441
+ ],
2442
+ anonymous: false
2443
+ },
2444
+ {
2445
+ type: "event",
2446
+ name: "DeployStaticPerpsPricing",
2447
+ inputs: [
2448
+ {
2449
+ name: "pricing",
2450
+ type: "address",
2451
+ indexed: true,
2452
+ internalType: "contract StaticPerpsPricing"
2453
+ },
2454
+ {
2455
+ name: "dailyFundingRate",
2456
+ type: "uint32",
2457
+ indexed: false,
2458
+ internalType: "uint32"
2459
+ },
2460
+ {
2461
+ name: "minFundingAmount",
2462
+ type: "uint128",
2463
+ indexed: false,
2464
+ internalType: "uint128"
2465
+ }
2466
+ ],
2467
+ anonymous: false
2468
+ }
2469
+ ];
2470
+
2471
+ //#endregion
2472
+ //#region src/hooks/fees/useUpdateMarketFees.ts
2473
+ const useUpdateMarketFees = (marketAddr) => {
2474
+ const { writeContractAsync, ...rest } = (0, wagmi.useWriteContract)();
2475
+ const publicClient = (0, wagmi.usePublicClient)();
2476
+ const chainId = (0, wagmi.useChainId)();
2477
+ const { data: { feeStrategy, optionPricing } } = useMarketState(marketAddr);
2478
+ const { openingFeeRate, baseFeeRate, minOpeningFee, minBaseFee, feeRecipient } = useFeeRates(feeStrategy);
2479
+ const updateMarketFeeRates = async (rates) => {
2480
+ if (openingFeeRate === void 0 || baseFeeRate === void 0 || minOpeningFee === void 0 || minBaseFee === void 0 || feeRecipient === void 0) throw new Error("Missing current fee rates");
2481
+ if (!optionPricing) throw new Error("Could not load market state");
2482
+ if (!publicClient) throw new Error("Public client not available");
2483
+ const factoryAddr = require_optionUtils.timelockFactories[chainId].toLowerCase();
2484
+ const hash = await writeContractAsync({
2485
+ address: factoryAddr,
2486
+ abi: factoryAbi,
2487
+ functionName: "deployFeeStrategy",
2488
+ args: [
2489
+ rates.openingFeeRate ?? openingFeeRate,
2490
+ rates.baseFeeRate ?? baseFeeRate,
2491
+ rates.minOpeningFee ?? minOpeningFee,
2492
+ rates.minBaseFee ?? minBaseFee,
2493
+ rates.feeRecipient ?? feeRecipient
2494
+ ]
2495
+ });
2496
+ const deployEvent = (await publicClient.waitForTransactionReceipt({ hash })).logs.find((log) => log.address.toLowerCase() === factoryAddr);
2497
+ if (!deployEvent) throw new Error("DeployFeeStrategy event not found");
2498
+ const decodedEvent = (0, viem.decodeEventLog)({
2499
+ abi: factoryAbi,
2500
+ data: deployEvent.data,
2501
+ topics: deployEvent.topics
2502
+ });
2503
+ if (decodedEvent.eventName !== "DeployFeeStrategy") throw new Error("Unexpected event");
2504
+ const newFeeStrategy = decodedEvent.args.feeStrategy;
2505
+ return {
2506
+ deployHash: hash,
2507
+ updateHash: await writeContractAsync({
2508
+ address: marketAddr,
2509
+ abi: require_optionsMarket.optionsMarketAbi,
2510
+ functionName: "updateAddresses",
2511
+ args: [optionPricing, newFeeStrategy]
2512
+ }),
2513
+ newFeeStrategy
2514
+ };
2515
+ };
2516
+ return {
2517
+ updateMarketFeeRates,
2518
+ ...rest
2519
+ };
2520
+ };
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
+
2198
2711
  //#endregion
2199
2712
  exports.TimelockProvider = TimelockProvider;
2200
2713
  exports.batchGetAmountsFromLiquidity = batchGetAmountsFromLiquidity;
@@ -2216,6 +2729,8 @@ exports.useLens = useLens;
2216
2729
  exports.useLiquidityBlocks = useLiquidityBlocks;
2217
2730
  exports.useMarketData = useMarketData;
2218
2731
  exports.useMarketPriceHistory = useMarketPriceHistory;
2732
+ exports.useMarketPricing = useMarketPricing;
2733
+ exports.useMarketState = useMarketState;
2219
2734
  exports.useMarketVolume = useMarketVolume;
2220
2735
  exports.useMaxPositionSize = useMaxPositionSize;
2221
2736
  exports.useMintLiquidity = useMintLiquidity;
@@ -2224,6 +2739,7 @@ exports.useMintPerp = useMintPerp;
2224
2739
  exports.useOperatorPerms = useOperatorPerms;
2225
2740
  exports.useOptionPnl = useOptionPnl;
2226
2741
  exports.useOptionPremium = useOptionPremium;
2742
+ exports.useOptionPricingParams = useOptionPricingParams;
2227
2743
  exports.useOptionTimeline = useOptionTimeline;
2228
2744
  exports.usePauseGlobalTrading = usePauseGlobalTrading;
2229
2745
  exports.usePauseMarketTrading = usePauseMarketTrading;
@@ -2233,9 +2749,12 @@ exports.usePriceAtSqrtPriceX96 = usePriceAtSqrtPriceX96;
2233
2749
  exports.usePriceAtTick = usePriceAtTick;
2234
2750
  exports.usePriceHistory = usePriceHistory;
2235
2751
  exports.useSetOperatorPerms = useSetOperatorPerms;
2752
+ exports.useStaticPricingParams = useStaticPricingParams;
2236
2753
  exports.useTimelockConfig = useTimelockConfig;
2237
2754
  exports.useTokenBalance = useTokenBalance;
2238
2755
  exports.useTokenData = useTokenData;
2756
+ exports.useUpdateMarketFees = useUpdateMarketFees;
2757
+ exports.useUpdateMarketPricing = useUpdateMarketPricing;
2239
2758
  exports.useUserOperators = useUserOperators;
2240
2759
  exports.useUserPerps = useUserPerps;
2241
2760
  exports.useVaultData = useVaultData;