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.
- package/dist/abis.cjs +1 -1
- package/dist/abis.d.cts +1 -1
- package/dist/abis.d.ts +1 -1
- package/dist/abis.js +1 -1
- package/dist/{client-CSYKjcyD.d.cts → client-DmXuKRhM.d.cts} +12987 -3020
- package/dist/{client-cNTMuD8y.d.ts → client-Dx6YoDji.d.ts} +12950 -2983
- package/dist/client.cjs +688 -169
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +3 -3
- package/dist/client.d.ts +3 -3
- package/dist/client.js +684 -171
- package/dist/client.js.map +1 -1
- package/dist/{optionUtils-Daz9iARj.cjs → optionUtils-B-TKN7Ni.cjs} +10 -3
- package/dist/optionUtils-B-TKN7Ni.cjs.map +1 -0
- package/dist/{optionUtils-B7EA45zY.js → optionUtils-CL-MSoFS.js} +5 -4
- package/dist/optionUtils-CL-MSoFS.js.map +1 -0
- package/dist/{optionsMarket-CT26uUTa.js → optionsMarket-BbXpQnpV.js} +193 -148
- package/dist/optionsMarket-BbXpQnpV.js.map +1 -0
- package/dist/{optionsMarket-T7r7iDKa.cjs → optionsMarket-DtjLm46g.cjs} +193 -148
- package/dist/optionsMarket-DtjLm46g.cjs.map +1 -0
- package/dist/package.cjs +3 -2
- package/dist/package.d.cts +3 -3
- package/dist/package.d.ts +3 -3
- package/dist/package.js +3 -3
- package/dist/{uniswapMathLens-DNbMIHSs.d.ts → uniswapMathLens-BoQxBJoY.d.cts} +95 -51
- package/dist/{uniswapMathLens-DT3TTcQa.d.cts → uniswapMathLens-Ds8UmCMU.d.ts} +95 -51
- package/package.json +1 -1
- package/dist/optionUtils-B7EA45zY.js.map +0 -1
- package/dist/optionUtils-Daz9iARj.cjs.map +0 -1
- package/dist/optionsMarket-CT26uUTa.js.map +0 -1
- package/dist/optionsMarket-T7r7iDKa.cjs.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import { i as erc20Abi$1, r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-
|
|
5
|
-
import { A as token1ToToken0, B as swappers, D as roundTick, F as getStateView,
|
|
4
|
+
import { i as erc20Abi$1, r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-BbXpQnpV.js";
|
|
5
|
+
import { A as token1ToToken0, B as swappers, D as roundTick, F as getStateView, I as getTimelockLens, L as getTimelockMarket, N as getPriceHistory, O as token0ToToken1, P as getErc20, U as statelessStateViewAbi, V as timelockFactories, b as getPriceAtSqrtPriceX96, f as wrapAmount, j as token1ToToken0AtTick, k as token0ToToken1AtTick, m as wrapPrice, r as EMPTY_ARRAY, t as getPayoutAtPrice, v as getAmountsFromLiquidity, x as getPriceAtTick, y as getNearestValidStrikeTick } from "./optionUtils-CL-MSoFS.js";
|
|
6
6
|
import { t as singleOwnerVaultAbi } from "./singleOwnerVault-BJyEs_D_.js";
|
|
7
|
-
import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
|
|
7
|
+
import { decodeAbiParameters, decodeEventLog, encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
|
|
8
8
|
import React, { createContext, useContext, useEffect, useMemo } from "react";
|
|
9
9
|
import { GraphQLClient, RequestOptions } from "graphql-request";
|
|
10
10
|
import gql from "graphql-tag";
|
|
11
|
-
import { waitForTransactionReceipt } from "viem/actions";
|
|
12
11
|
import { useChainId, useClient, useConnection, usePublicClient, useReadContract, useSignMessage, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
13
12
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
13
|
+
import { waitForTransactionReceipt } from "viem/actions";
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
|
|
16
16
|
//#region src/generated/graphql.ts
|
|
@@ -460,183 +460,26 @@ const useMarketData = (marketAddr) => {
|
|
|
460
460
|
};
|
|
461
461
|
|
|
462
462
|
//#endregion
|
|
463
|
-
//#region src/hooks/
|
|
464
|
-
const
|
|
463
|
+
//#region src/hooks/options/useMarketState.ts
|
|
464
|
+
const useMarketState = (marketAddr) => {
|
|
465
465
|
const { timelockLens } = useLens();
|
|
466
|
-
const { data } = useReadContract({
|
|
466
|
+
const { data, ...rest } = useReadContract({
|
|
467
467
|
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
468
468
|
abi: lensAbi,
|
|
469
|
-
functionName: "
|
|
470
|
-
args:
|
|
471
|
-
query: { enabled: !!poolManager && !!poolKey }
|
|
472
|
-
});
|
|
473
|
-
const _default = useMemo(() => ({
|
|
474
|
-
token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
|
|
475
|
-
token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
|
|
476
|
-
tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
|
|
477
|
-
fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
|
|
478
|
-
}), [poolKey]);
|
|
479
|
-
return data || _default;
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
//#endregion
|
|
483
|
-
//#region src/hooks/pool/usePriceAtTick.ts
|
|
484
|
-
const usePriceAtTick = (poolManager, poolKey, tick) => {
|
|
485
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
486
|
-
const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
|
|
487
|
-
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
488
|
-
priceBigInt,
|
|
489
|
-
token0Decimals,
|
|
490
|
-
token1Decimals
|
|
491
|
-
]);
|
|
492
|
-
};
|
|
493
|
-
const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
|
|
494
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
495
|
-
const priceBigInt = useMemo(() => sqrtPriceX96 !== void 0 ? getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
496
|
-
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
497
|
-
priceBigInt,
|
|
498
|
-
token0Decimals,
|
|
499
|
-
token1Decimals
|
|
500
|
-
]);
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
//#endregion
|
|
504
|
-
//#region src/hooks/pool/useCurrentTick.ts
|
|
505
|
-
const useCurrentTick = (poolManager, poolKey) => {
|
|
506
|
-
const { stateView } = useLens();
|
|
507
|
-
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
508
|
-
const { data, ...rest } = useReadContract({
|
|
509
|
-
address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
|
|
510
|
-
abi: statelessStateViewAbi,
|
|
511
|
-
functionName: "getSlot0",
|
|
512
|
-
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
513
|
-
query: {
|
|
514
|
-
enabled: !!poolManager && !!poolKey,
|
|
515
|
-
refetchInterval: 3e3,
|
|
516
|
-
select: (raw) => {
|
|
517
|
-
const sqrtPriceX96 = raw[0];
|
|
518
|
-
const exact = raw[1];
|
|
519
|
-
return {
|
|
520
|
-
exact,
|
|
521
|
-
rounded: tickSpacing ? roundTick(exact, tickSpacing) : void 0,
|
|
522
|
-
sqrtPriceX96
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
}
|
|
469
|
+
functionName: "getMarketState",
|
|
470
|
+
args: marketAddr ? [marketAddr] : void 0
|
|
526
471
|
});
|
|
527
472
|
return {
|
|
528
|
-
|
|
529
|
-
rounded: data === null || data === void 0 ? void 0 : data.rounded,
|
|
530
|
-
sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
|
|
473
|
+
data: data || {},
|
|
531
474
|
...rest
|
|
532
475
|
};
|
|
533
476
|
};
|
|
534
477
|
|
|
535
|
-
//#endregion
|
|
536
|
-
//#region src/hooks/pool/useCurrentPrice.ts
|
|
537
|
-
const useCurrentPrice = (poolManager, poolKey) => {
|
|
538
|
-
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
|
|
539
|
-
const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
|
|
540
|
-
return useMemo(() => ({
|
|
541
|
-
currentPrice,
|
|
542
|
-
sqrtPriceX96,
|
|
543
|
-
currentTick: {
|
|
544
|
-
exact,
|
|
545
|
-
rounded
|
|
546
|
-
}
|
|
547
|
-
}), [
|
|
548
|
-
currentPrice,
|
|
549
|
-
exact,
|
|
550
|
-
rounded
|
|
551
|
-
]);
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
//#endregion
|
|
555
|
-
//#region src/lib/utils.ts
|
|
556
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
557
|
-
|
|
558
|
-
//#endregion
|
|
559
|
-
//#region src/hooks/options/useExerciseOption.ts
|
|
560
|
-
const useExerciseOption = (marketAddr) => {
|
|
561
|
-
const { vault, poolManager, poolKey } = useMarketData(marketAddr);
|
|
562
|
-
const { timelockLens } = useLens();
|
|
563
|
-
const queryClient = useQueryClient();
|
|
564
|
-
const client = useClient();
|
|
565
|
-
const { address } = useConnection();
|
|
566
|
-
const { writeContractAsync } = useWriteContract();
|
|
567
|
-
const { sqrtPriceX96 } = useCurrentPrice(poolManager, poolKey);
|
|
568
|
-
const exerciseOption = async ({ option, liquidities }) => {
|
|
569
|
-
if (!client || !address) throw new Error("Wallet not connected");
|
|
570
|
-
if (!marketAddr) throw new Error("Market address not available");
|
|
571
|
-
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
572
|
-
if (!vault) throw new Error("Vault not available");
|
|
573
|
-
if (!poolKey) throw new Error("Pool data not available");
|
|
574
|
-
if (!sqrtPriceX96) throw new Error("Current price not available");
|
|
575
|
-
const swapper = swappers[client.chain.id];
|
|
576
|
-
if (!swapper) throw new Error("Swapper not available");
|
|
577
|
-
const minSqrtPrice = sqrtPriceX96 * 9n / 10n;
|
|
578
|
-
const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
|
|
579
|
-
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
580
|
-
const hash = await writeContractAsync({
|
|
581
|
-
address: marketAddr,
|
|
582
|
-
abi: optionsMarketAbi,
|
|
583
|
-
functionName: "exerciseOption",
|
|
584
|
-
args: [
|
|
585
|
-
option.optionId,
|
|
586
|
-
liquidities,
|
|
587
|
-
0n,
|
|
588
|
-
swapper,
|
|
589
|
-
encodeAbiParameters([
|
|
590
|
-
{
|
|
591
|
-
type: "tuple",
|
|
592
|
-
components: [
|
|
593
|
-
{
|
|
594
|
-
type: "address",
|
|
595
|
-
name: "currency0"
|
|
596
|
-
},
|
|
597
|
-
{
|
|
598
|
-
type: "address",
|
|
599
|
-
name: "currency1"
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
type: "uint24",
|
|
603
|
-
name: "fee"
|
|
604
|
-
},
|
|
605
|
-
{
|
|
606
|
-
type: "int24",
|
|
607
|
-
name: "tickSpacing"
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
type: "address",
|
|
611
|
-
name: "hooks"
|
|
612
|
-
}
|
|
613
|
-
]
|
|
614
|
-
},
|
|
615
|
-
{ type: "uint160" },
|
|
616
|
-
{ type: "uint160" }
|
|
617
|
-
], [
|
|
618
|
-
poolKey,
|
|
619
|
-
minSqrtPrice,
|
|
620
|
-
maxSqrtPrice
|
|
621
|
-
]),
|
|
622
|
-
refTick
|
|
623
|
-
]
|
|
624
|
-
});
|
|
625
|
-
await waitForTransactionReceipt(client, { hash });
|
|
626
|
-
await sleep(200);
|
|
627
|
-
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
628
|
-
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
629
|
-
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
630
|
-
return hash;
|
|
631
|
-
};
|
|
632
|
-
return useMutation({ mutationFn: exerciseOption });
|
|
633
|
-
};
|
|
634
|
-
|
|
635
478
|
//#endregion
|
|
636
479
|
//#region src/hooks/options/useMarketVolume.ts
|
|
637
480
|
const useMarketVolume = (marketAddr) => {
|
|
638
481
|
const { graphqlClient } = useTimelockConfig();
|
|
639
|
-
const { data } = useQuery({
|
|
482
|
+
const { data, ...rest } = useQuery({
|
|
640
483
|
queryKey: ["marketVolume", (marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase()) || "--"],
|
|
641
484
|
queryFn: async () => {
|
|
642
485
|
const result = await graphqlClient.GetMarketVolume({ marketAddr: marketAddr.toLowerCase() });
|
|
@@ -650,7 +493,10 @@ const useMarketVolume = (marketAddr) => {
|
|
|
650
493
|
},
|
|
651
494
|
enabled: !!marketAddr && !!graphqlClient
|
|
652
495
|
});
|
|
653
|
-
return
|
|
496
|
+
return {
|
|
497
|
+
data: data || {},
|
|
498
|
+
...rest
|
|
499
|
+
};
|
|
654
500
|
};
|
|
655
501
|
|
|
656
502
|
//#endregion
|
|
@@ -677,6 +523,58 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxSteps = 100) => {
|
|
|
677
523
|
};
|
|
678
524
|
};
|
|
679
525
|
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region src/hooks/pool/usePoolData.ts
|
|
528
|
+
const usePoolData = (poolManager, poolKey) => {
|
|
529
|
+
const { timelockLens } = useLens();
|
|
530
|
+
const { data } = useReadContract({
|
|
531
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
532
|
+
abi: lensAbi,
|
|
533
|
+
functionName: "getPoolData",
|
|
534
|
+
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
535
|
+
query: { enabled: !!poolManager && !!poolKey }
|
|
536
|
+
});
|
|
537
|
+
const _default = useMemo(() => ({
|
|
538
|
+
token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
|
|
539
|
+
token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
|
|
540
|
+
tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
|
|
541
|
+
fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
|
|
542
|
+
}), [poolKey]);
|
|
543
|
+
return data || _default;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/hooks/pool/useCurrentTick.ts
|
|
548
|
+
const useCurrentTick = (poolManager, poolKey) => {
|
|
549
|
+
const { stateView } = useLens();
|
|
550
|
+
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
551
|
+
const { data, ...rest } = useReadContract({
|
|
552
|
+
address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
|
|
553
|
+
abi: statelessStateViewAbi,
|
|
554
|
+
functionName: "getSlot0",
|
|
555
|
+
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
556
|
+
query: {
|
|
557
|
+
enabled: !!poolManager && !!poolKey,
|
|
558
|
+
refetchInterval: 3e3,
|
|
559
|
+
select: (raw) => {
|
|
560
|
+
const sqrtPriceX96 = raw[0];
|
|
561
|
+
const exact = raw[1];
|
|
562
|
+
return {
|
|
563
|
+
exact,
|
|
564
|
+
rounded: tickSpacing ? roundTick(exact, tickSpacing) : void 0,
|
|
565
|
+
sqrtPriceX96
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
return {
|
|
571
|
+
exact: data === null || data === void 0 ? void 0 : data.exact,
|
|
572
|
+
rounded: data === null || data === void 0 ? void 0 : data.rounded,
|
|
573
|
+
sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
|
|
574
|
+
...rest
|
|
575
|
+
};
|
|
576
|
+
};
|
|
577
|
+
|
|
680
578
|
//#endregion
|
|
681
579
|
//#region src/hooks/tokens/useApproval.ts
|
|
682
580
|
const useApproval = () => {
|
|
@@ -701,6 +599,10 @@ const useApproval = () => {
|
|
|
701
599
|
};
|
|
702
600
|
};
|
|
703
601
|
|
|
602
|
+
//#endregion
|
|
603
|
+
//#region src/lib/utils.ts
|
|
604
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
605
|
+
|
|
704
606
|
//#endregion
|
|
705
607
|
//#region src/hooks/options/useMintOption.ts
|
|
706
608
|
const useMintOption = (marketAddr) => {
|
|
@@ -752,7 +654,124 @@ const useMintOption = (marketAddr) => {
|
|
|
752
654
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
753
655
|
return hash;
|
|
754
656
|
};
|
|
755
|
-
return useMutation({ mutationFn: mintOption });
|
|
657
|
+
return useMutation({ mutationFn: mintOption });
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/hooks/pool/usePriceAtTick.ts
|
|
662
|
+
const usePriceAtTick = (poolManager, poolKey, tick) => {
|
|
663
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
664
|
+
const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
|
|
665
|
+
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
666
|
+
priceBigInt,
|
|
667
|
+
token0Decimals,
|
|
668
|
+
token1Decimals
|
|
669
|
+
]);
|
|
670
|
+
};
|
|
671
|
+
const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
|
|
672
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
673
|
+
const priceBigInt = useMemo(() => sqrtPriceX96 !== void 0 ? getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
674
|
+
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
675
|
+
priceBigInt,
|
|
676
|
+
token0Decimals,
|
|
677
|
+
token1Decimals
|
|
678
|
+
]);
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region src/hooks/pool/useCurrentPrice.ts
|
|
683
|
+
const useCurrentPrice = (poolManager, poolKey) => {
|
|
684
|
+
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
|
|
685
|
+
const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
|
|
686
|
+
return useMemo(() => ({
|
|
687
|
+
currentPrice,
|
|
688
|
+
sqrtPriceX96,
|
|
689
|
+
currentTick: {
|
|
690
|
+
exact,
|
|
691
|
+
rounded
|
|
692
|
+
}
|
|
693
|
+
}), [
|
|
694
|
+
currentPrice,
|
|
695
|
+
exact,
|
|
696
|
+
rounded
|
|
697
|
+
]);
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/hooks/options/useExerciseOption.ts
|
|
702
|
+
const useExerciseOption = (marketAddr) => {
|
|
703
|
+
const { vault, poolManager, poolKey } = useMarketData(marketAddr);
|
|
704
|
+
const { timelockLens } = useLens();
|
|
705
|
+
const queryClient = useQueryClient();
|
|
706
|
+
const client = useClient();
|
|
707
|
+
const { address } = useConnection();
|
|
708
|
+
const { writeContractAsync } = useWriteContract();
|
|
709
|
+
const { sqrtPriceX96 } = useCurrentPrice(poolManager, poolKey);
|
|
710
|
+
const exerciseOption = async ({ option, liquidities }) => {
|
|
711
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
712
|
+
if (!marketAddr) throw new Error("Market address not available");
|
|
713
|
+
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
714
|
+
if (!vault) throw new Error("Vault not available");
|
|
715
|
+
if (!poolKey) throw new Error("Pool data not available");
|
|
716
|
+
if (!sqrtPriceX96) throw new Error("Current price not available");
|
|
717
|
+
const swapper = swappers[client.chain.id];
|
|
718
|
+
if (!swapper) throw new Error("Swapper not available");
|
|
719
|
+
const minSqrtPrice = sqrtPriceX96 * 9n / 10n;
|
|
720
|
+
const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
|
|
721
|
+
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
722
|
+
const hash = await writeContractAsync({
|
|
723
|
+
address: marketAddr,
|
|
724
|
+
abi: optionsMarketAbi,
|
|
725
|
+
functionName: "exerciseOption",
|
|
726
|
+
args: [
|
|
727
|
+
option.optionId,
|
|
728
|
+
liquidities,
|
|
729
|
+
0n,
|
|
730
|
+
swapper,
|
|
731
|
+
encodeAbiParameters([
|
|
732
|
+
{
|
|
733
|
+
type: "tuple",
|
|
734
|
+
components: [
|
|
735
|
+
{
|
|
736
|
+
type: "address",
|
|
737
|
+
name: "currency0"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
type: "address",
|
|
741
|
+
name: "currency1"
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
type: "uint24",
|
|
745
|
+
name: "fee"
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
type: "int24",
|
|
749
|
+
name: "tickSpacing"
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
type: "address",
|
|
753
|
+
name: "hooks"
|
|
754
|
+
}
|
|
755
|
+
]
|
|
756
|
+
},
|
|
757
|
+
{ type: "uint160" },
|
|
758
|
+
{ type: "uint160" }
|
|
759
|
+
], [
|
|
760
|
+
poolKey,
|
|
761
|
+
minSqrtPrice,
|
|
762
|
+
maxSqrtPrice
|
|
763
|
+
]),
|
|
764
|
+
refTick
|
|
765
|
+
]
|
|
766
|
+
});
|
|
767
|
+
await waitForTransactionReceipt(client, { hash });
|
|
768
|
+
await sleep(200);
|
|
769
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
770
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
771
|
+
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
772
|
+
return hash;
|
|
773
|
+
};
|
|
774
|
+
return useMutation({ mutationFn: exerciseOption });
|
|
756
775
|
};
|
|
757
776
|
|
|
758
777
|
//#endregion
|
|
@@ -2194,5 +2213,499 @@ const useFeeRates = (feeStrategy) => {
|
|
|
2194
2213
|
};
|
|
2195
2214
|
|
|
2196
2215
|
//#endregion
|
|
2197
|
-
|
|
2216
|
+
//#region src/abis/factory.ts
|
|
2217
|
+
const factoryAbi = [
|
|
2218
|
+
{
|
|
2219
|
+
type: "function",
|
|
2220
|
+
name: "deployFeeStrategy",
|
|
2221
|
+
inputs: [
|
|
2222
|
+
{
|
|
2223
|
+
name: "_openingFeeRate",
|
|
2224
|
+
type: "uint32",
|
|
2225
|
+
internalType: "uint32"
|
|
2226
|
+
},
|
|
2227
|
+
{
|
|
2228
|
+
name: "_baseFeeRate",
|
|
2229
|
+
type: "uint32",
|
|
2230
|
+
internalType: "uint32"
|
|
2231
|
+
},
|
|
2232
|
+
{
|
|
2233
|
+
name: "_minOpeningFee",
|
|
2234
|
+
type: "uint128",
|
|
2235
|
+
internalType: "uint128"
|
|
2236
|
+
},
|
|
2237
|
+
{
|
|
2238
|
+
name: "_minBaseFee",
|
|
2239
|
+
type: "uint128",
|
|
2240
|
+
internalType: "uint128"
|
|
2241
|
+
},
|
|
2242
|
+
{
|
|
2243
|
+
name: "_feeRecipient",
|
|
2244
|
+
type: "address",
|
|
2245
|
+
internalType: "address"
|
|
2246
|
+
}
|
|
2247
|
+
],
|
|
2248
|
+
outputs: [{
|
|
2249
|
+
name: "",
|
|
2250
|
+
type: "address",
|
|
2251
|
+
internalType: "contract FeeStrategy"
|
|
2252
|
+
}],
|
|
2253
|
+
stateMutability: "nonpayable"
|
|
2254
|
+
},
|
|
2255
|
+
{
|
|
2256
|
+
type: "function",
|
|
2257
|
+
name: "deployOptionPricing",
|
|
2258
|
+
inputs: [
|
|
2259
|
+
{
|
|
2260
|
+
name: "_logicContract",
|
|
2261
|
+
type: "address",
|
|
2262
|
+
internalType: "contract StatelessOptionPricing"
|
|
2263
|
+
},
|
|
2264
|
+
{
|
|
2265
|
+
name: "_iv",
|
|
2266
|
+
type: "uint32",
|
|
2267
|
+
internalType: "uint32"
|
|
2268
|
+
},
|
|
2269
|
+
{
|
|
2270
|
+
name: "_riskFreeRate",
|
|
2271
|
+
type: "uint32",
|
|
2272
|
+
internalType: "uint32"
|
|
2273
|
+
},
|
|
2274
|
+
{
|
|
2275
|
+
name: "_minPremiumDailyRate",
|
|
2276
|
+
type: "uint32",
|
|
2277
|
+
internalType: "uint32"
|
|
2278
|
+
},
|
|
2279
|
+
{
|
|
2280
|
+
name: "_minPremiumAmount",
|
|
2281
|
+
type: "uint256",
|
|
2282
|
+
internalType: "uint256"
|
|
2283
|
+
}
|
|
2284
|
+
],
|
|
2285
|
+
outputs: [{
|
|
2286
|
+
name: "",
|
|
2287
|
+
type: "address",
|
|
2288
|
+
internalType: "contract OptionPricing"
|
|
2289
|
+
}],
|
|
2290
|
+
stateMutability: "nonpayable"
|
|
2291
|
+
},
|
|
2292
|
+
{
|
|
2293
|
+
type: "function",
|
|
2294
|
+
name: "deployStaticPerpsPricing",
|
|
2295
|
+
inputs: [{
|
|
2296
|
+
name: "_dailyFundingRate",
|
|
2297
|
+
type: "uint32",
|
|
2298
|
+
internalType: "uint32"
|
|
2299
|
+
}, {
|
|
2300
|
+
name: "_minFundingAmount",
|
|
2301
|
+
type: "uint128",
|
|
2302
|
+
internalType: "uint128"
|
|
2303
|
+
}],
|
|
2304
|
+
outputs: [{
|
|
2305
|
+
name: "",
|
|
2306
|
+
type: "address",
|
|
2307
|
+
internalType: "contract StaticPerpsPricing"
|
|
2308
|
+
}],
|
|
2309
|
+
stateMutability: "nonpayable"
|
|
2310
|
+
},
|
|
2311
|
+
{
|
|
2312
|
+
type: "function",
|
|
2313
|
+
name: "feeStrategies",
|
|
2314
|
+
inputs: [{
|
|
2315
|
+
name: "",
|
|
2316
|
+
type: "bytes32",
|
|
2317
|
+
internalType: "bytes32"
|
|
2318
|
+
}],
|
|
2319
|
+
outputs: [{
|
|
2320
|
+
name: "",
|
|
2321
|
+
type: "address",
|
|
2322
|
+
internalType: "contract FeeStrategy"
|
|
2323
|
+
}],
|
|
2324
|
+
stateMutability: "view"
|
|
2325
|
+
},
|
|
2326
|
+
{
|
|
2327
|
+
type: "function",
|
|
2328
|
+
name: "optionPricings",
|
|
2329
|
+
inputs: [{
|
|
2330
|
+
name: "",
|
|
2331
|
+
type: "bytes32",
|
|
2332
|
+
internalType: "bytes32"
|
|
2333
|
+
}],
|
|
2334
|
+
outputs: [{
|
|
2335
|
+
name: "",
|
|
2336
|
+
type: "address",
|
|
2337
|
+
internalType: "contract OptionPricing"
|
|
2338
|
+
}],
|
|
2339
|
+
stateMutability: "view"
|
|
2340
|
+
},
|
|
2341
|
+
{
|
|
2342
|
+
type: "function",
|
|
2343
|
+
name: "staticPerpsPricings",
|
|
2344
|
+
inputs: [{
|
|
2345
|
+
name: "",
|
|
2346
|
+
type: "bytes32",
|
|
2347
|
+
internalType: "bytes32"
|
|
2348
|
+
}],
|
|
2349
|
+
outputs: [{
|
|
2350
|
+
name: "",
|
|
2351
|
+
type: "address",
|
|
2352
|
+
internalType: "contract StaticPerpsPricing"
|
|
2353
|
+
}],
|
|
2354
|
+
stateMutability: "view"
|
|
2355
|
+
},
|
|
2356
|
+
{
|
|
2357
|
+
type: "event",
|
|
2358
|
+
name: "DeployFeeStrategy",
|
|
2359
|
+
inputs: [
|
|
2360
|
+
{
|
|
2361
|
+
name: "feeStrategy",
|
|
2362
|
+
type: "address",
|
|
2363
|
+
indexed: true,
|
|
2364
|
+
internalType: "contract FeeStrategy"
|
|
2365
|
+
},
|
|
2366
|
+
{
|
|
2367
|
+
name: "openingFeeRate",
|
|
2368
|
+
type: "uint32",
|
|
2369
|
+
indexed: false,
|
|
2370
|
+
internalType: "uint32"
|
|
2371
|
+
},
|
|
2372
|
+
{
|
|
2373
|
+
name: "baseFeeRate",
|
|
2374
|
+
type: "uint32",
|
|
2375
|
+
indexed: false,
|
|
2376
|
+
internalType: "uint32"
|
|
2377
|
+
},
|
|
2378
|
+
{
|
|
2379
|
+
name: "minOpeningFee",
|
|
2380
|
+
type: "uint128",
|
|
2381
|
+
indexed: false,
|
|
2382
|
+
internalType: "uint128"
|
|
2383
|
+
},
|
|
2384
|
+
{
|
|
2385
|
+
name: "minBaseFee",
|
|
2386
|
+
type: "uint128",
|
|
2387
|
+
indexed: false,
|
|
2388
|
+
internalType: "uint128"
|
|
2389
|
+
},
|
|
2390
|
+
{
|
|
2391
|
+
name: "feeRecipient",
|
|
2392
|
+
type: "address",
|
|
2393
|
+
indexed: false,
|
|
2394
|
+
internalType: "address"
|
|
2395
|
+
}
|
|
2396
|
+
],
|
|
2397
|
+
anonymous: false
|
|
2398
|
+
},
|
|
2399
|
+
{
|
|
2400
|
+
type: "event",
|
|
2401
|
+
name: "DeployOptionPricing",
|
|
2402
|
+
inputs: [
|
|
2403
|
+
{
|
|
2404
|
+
name: "pricing",
|
|
2405
|
+
type: "address",
|
|
2406
|
+
indexed: true,
|
|
2407
|
+
internalType: "contract OptionPricing"
|
|
2408
|
+
},
|
|
2409
|
+
{
|
|
2410
|
+
name: "statelessPricing",
|
|
2411
|
+
type: "address",
|
|
2412
|
+
indexed: false,
|
|
2413
|
+
internalType: "contract StatelessOptionPricing"
|
|
2414
|
+
},
|
|
2415
|
+
{
|
|
2416
|
+
name: "iv",
|
|
2417
|
+
type: "uint32",
|
|
2418
|
+
indexed: false,
|
|
2419
|
+
internalType: "uint32"
|
|
2420
|
+
},
|
|
2421
|
+
{
|
|
2422
|
+
name: "riskFreeRate",
|
|
2423
|
+
type: "uint32",
|
|
2424
|
+
indexed: false,
|
|
2425
|
+
internalType: "uint32"
|
|
2426
|
+
},
|
|
2427
|
+
{
|
|
2428
|
+
name: "minPremiumDailyRate",
|
|
2429
|
+
type: "uint32",
|
|
2430
|
+
indexed: false,
|
|
2431
|
+
internalType: "uint32"
|
|
2432
|
+
},
|
|
2433
|
+
{
|
|
2434
|
+
name: "minPremiumAmount",
|
|
2435
|
+
type: "uint256",
|
|
2436
|
+
indexed: false,
|
|
2437
|
+
internalType: "uint256"
|
|
2438
|
+
}
|
|
2439
|
+
],
|
|
2440
|
+
anonymous: false
|
|
2441
|
+
},
|
|
2442
|
+
{
|
|
2443
|
+
type: "event",
|
|
2444
|
+
name: "DeployStaticPerpsPricing",
|
|
2445
|
+
inputs: [
|
|
2446
|
+
{
|
|
2447
|
+
name: "pricing",
|
|
2448
|
+
type: "address",
|
|
2449
|
+
indexed: true,
|
|
2450
|
+
internalType: "contract StaticPerpsPricing"
|
|
2451
|
+
},
|
|
2452
|
+
{
|
|
2453
|
+
name: "dailyFundingRate",
|
|
2454
|
+
type: "uint32",
|
|
2455
|
+
indexed: false,
|
|
2456
|
+
internalType: "uint32"
|
|
2457
|
+
},
|
|
2458
|
+
{
|
|
2459
|
+
name: "minFundingAmount",
|
|
2460
|
+
type: "uint128",
|
|
2461
|
+
indexed: false,
|
|
2462
|
+
internalType: "uint128"
|
|
2463
|
+
}
|
|
2464
|
+
],
|
|
2465
|
+
anonymous: false
|
|
2466
|
+
}
|
|
2467
|
+
];
|
|
2468
|
+
|
|
2469
|
+
//#endregion
|
|
2470
|
+
//#region src/hooks/fees/useUpdateMarketFees.ts
|
|
2471
|
+
const useUpdateMarketFees = (marketAddr) => {
|
|
2472
|
+
const { writeContractAsync, ...rest } = useWriteContract();
|
|
2473
|
+
const publicClient = usePublicClient();
|
|
2474
|
+
const chainId = useChainId();
|
|
2475
|
+
const { data: { feeStrategy, optionPricing } } = useMarketState(marketAddr);
|
|
2476
|
+
const { openingFeeRate, baseFeeRate, minOpeningFee, minBaseFee, feeRecipient } = useFeeRates(feeStrategy);
|
|
2477
|
+
const updateMarketFeeRates = async (rates) => {
|
|
2478
|
+
if (openingFeeRate === void 0 || baseFeeRate === void 0 || minOpeningFee === void 0 || minBaseFee === void 0 || feeRecipient === void 0) throw new Error("Missing current fee rates");
|
|
2479
|
+
if (!optionPricing) throw new Error("Could not load market state");
|
|
2480
|
+
if (!publicClient) throw new Error("Public client not available");
|
|
2481
|
+
const factoryAddr = timelockFactories[chainId].toLowerCase();
|
|
2482
|
+
const hash = await writeContractAsync({
|
|
2483
|
+
address: factoryAddr,
|
|
2484
|
+
abi: factoryAbi,
|
|
2485
|
+
functionName: "deployFeeStrategy",
|
|
2486
|
+
args: [
|
|
2487
|
+
rates.openingFeeRate ?? openingFeeRate,
|
|
2488
|
+
rates.baseFeeRate ?? baseFeeRate,
|
|
2489
|
+
rates.minOpeningFee ?? minOpeningFee,
|
|
2490
|
+
rates.minBaseFee ?? minBaseFee,
|
|
2491
|
+
rates.feeRecipient ?? feeRecipient
|
|
2492
|
+
]
|
|
2493
|
+
});
|
|
2494
|
+
const deployEvent = (await publicClient.waitForTransactionReceipt({ hash })).logs.find((log) => log.address.toLowerCase() === factoryAddr);
|
|
2495
|
+
if (!deployEvent) throw new Error("DeployFeeStrategy event not found");
|
|
2496
|
+
const decodedEvent = decodeEventLog({
|
|
2497
|
+
abi: factoryAbi,
|
|
2498
|
+
data: deployEvent.data,
|
|
2499
|
+
topics: deployEvent.topics
|
|
2500
|
+
});
|
|
2501
|
+
if (decodedEvent.eventName !== "DeployFeeStrategy") throw new Error("Unexpected event");
|
|
2502
|
+
const newFeeStrategy = decodedEvent.args.feeStrategy;
|
|
2503
|
+
return {
|
|
2504
|
+
deployHash: hash,
|
|
2505
|
+
updateHash: await writeContractAsync({
|
|
2506
|
+
address: marketAddr,
|
|
2507
|
+
abi: optionsMarketAbi,
|
|
2508
|
+
functionName: "updateAddresses",
|
|
2509
|
+
args: [optionPricing, newFeeStrategy]
|
|
2510
|
+
}),
|
|
2511
|
+
newFeeStrategy
|
|
2512
|
+
};
|
|
2513
|
+
};
|
|
2514
|
+
return {
|
|
2515
|
+
updateMarketFeeRates,
|
|
2516
|
+
...rest
|
|
2517
|
+
};
|
|
2518
|
+
};
|
|
2519
|
+
|
|
2520
|
+
//#endregion
|
|
2521
|
+
//#region src/hooks/pricing/useMarketPricing.ts
|
|
2522
|
+
const useMarketPricing = (marketAddr) => {
|
|
2523
|
+
const { data: { optionPricing } } = useMarketState(marketAddr);
|
|
2524
|
+
return useReadContract({
|
|
2525
|
+
address: optionPricing,
|
|
2526
|
+
abi: [{
|
|
2527
|
+
inputs: [],
|
|
2528
|
+
name: "readState",
|
|
2529
|
+
outputs: [{
|
|
2530
|
+
name: "",
|
|
2531
|
+
type: "bytes"
|
|
2532
|
+
}],
|
|
2533
|
+
stateMutability: "view",
|
|
2534
|
+
type: "function"
|
|
2535
|
+
}],
|
|
2536
|
+
functionName: "readState",
|
|
2537
|
+
query: {
|
|
2538
|
+
enabled: !!optionPricing,
|
|
2539
|
+
select: (rawData) => {
|
|
2540
|
+
const [pricingModel] = decodeAbiParameters([{
|
|
2541
|
+
name: "model",
|
|
2542
|
+
type: "uint8"
|
|
2543
|
+
}], rawData);
|
|
2544
|
+
if (pricingModel === 0) {
|
|
2545
|
+
const [, logicContract, iv, riskFreeRate, minPremiumDailyRate, minPremiumAmount] = decodeAbiParameters([
|
|
2546
|
+
{
|
|
2547
|
+
name: "pricingModel",
|
|
2548
|
+
type: "uint8"
|
|
2549
|
+
},
|
|
2550
|
+
{
|
|
2551
|
+
name: "logicContract",
|
|
2552
|
+
type: "address"
|
|
2553
|
+
},
|
|
2554
|
+
{
|
|
2555
|
+
name: "iv",
|
|
2556
|
+
type: "uint32"
|
|
2557
|
+
},
|
|
2558
|
+
{
|
|
2559
|
+
name: "riskFreeRate",
|
|
2560
|
+
type: "uint32"
|
|
2561
|
+
},
|
|
2562
|
+
{
|
|
2563
|
+
name: "minPremiumDailyRate",
|
|
2564
|
+
type: "uint32"
|
|
2565
|
+
},
|
|
2566
|
+
{
|
|
2567
|
+
name: "minPremiumAmount",
|
|
2568
|
+
type: "uint256"
|
|
2569
|
+
}
|
|
2570
|
+
], rawData);
|
|
2571
|
+
return {
|
|
2572
|
+
model: "option",
|
|
2573
|
+
logicContract,
|
|
2574
|
+
iv,
|
|
2575
|
+
riskFreeRate,
|
|
2576
|
+
minPremiumDailyRate,
|
|
2577
|
+
minPremiumAmount
|
|
2578
|
+
};
|
|
2579
|
+
} else if (pricingModel === 1) {
|
|
2580
|
+
const [, dailyFundingRate, minFundingAmount] = decodeAbiParameters([
|
|
2581
|
+
{
|
|
2582
|
+
name: "pricingModel",
|
|
2583
|
+
type: "uint8"
|
|
2584
|
+
},
|
|
2585
|
+
{
|
|
2586
|
+
name: "dailyFundingRate",
|
|
2587
|
+
type: "uint32"
|
|
2588
|
+
},
|
|
2589
|
+
{
|
|
2590
|
+
name: "minFundingAmount",
|
|
2591
|
+
type: "uint128"
|
|
2592
|
+
}
|
|
2593
|
+
], rawData);
|
|
2594
|
+
return {
|
|
2595
|
+
model: "static",
|
|
2596
|
+
dailyFundingRate,
|
|
2597
|
+
minFundingAmount
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
2600
|
+
throw new Error("Unknown pricing model");
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
});
|
|
2604
|
+
};
|
|
2605
|
+
|
|
2606
|
+
//#endregion
|
|
2607
|
+
//#region src/hooks/pricing/useOptionPricingParams.ts
|
|
2608
|
+
const useOptionPricingParams = (pricingAddr) => {
|
|
2609
|
+
const { timelockLens } = useLens();
|
|
2610
|
+
const { data } = useReadContract({
|
|
2611
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
2612
|
+
abi: lensAbi,
|
|
2613
|
+
args: pricingAddr ? [pricingAddr] : void 0,
|
|
2614
|
+
functionName: "getOptionPricingParams"
|
|
2615
|
+
});
|
|
2616
|
+
return data || {};
|
|
2617
|
+
};
|
|
2618
|
+
|
|
2619
|
+
//#endregion
|
|
2620
|
+
//#region src/hooks/pricing/useStaticPricingParams.ts
|
|
2621
|
+
const useStaticPricingParams = (pricingAddr) => {
|
|
2622
|
+
const { timelockLens } = useLens();
|
|
2623
|
+
const { data } = useReadContract({
|
|
2624
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
2625
|
+
abi: lensAbi,
|
|
2626
|
+
args: pricingAddr ? [pricingAddr] : void 0,
|
|
2627
|
+
functionName: "getStaticPricingParams"
|
|
2628
|
+
});
|
|
2629
|
+
return data || {};
|
|
2630
|
+
};
|
|
2631
|
+
|
|
2632
|
+
//#endregion
|
|
2633
|
+
//#region src/hooks/pricing/useUpdateMarketPricing.ts
|
|
2634
|
+
const useUpdateMarketPricing = (marketAddr) => {
|
|
2635
|
+
const { writeContractAsync, ...rest } = useWriteContract();
|
|
2636
|
+
const publicClient = usePublicClient();
|
|
2637
|
+
const chainId = useChainId();
|
|
2638
|
+
const { data: { feeStrategy } } = useMarketState();
|
|
2639
|
+
const { data: pricingData } = useMarketPricing(marketAddr);
|
|
2640
|
+
const updateMarketPricing = async (data) => {
|
|
2641
|
+
if (!pricingData) throw new Error("Market pricing data not available");
|
|
2642
|
+
if (!publicClient) throw new Error("Public client not available");
|
|
2643
|
+
if (!feeStrategy) throw new Error("Fee strategy not available");
|
|
2644
|
+
const factoryAddr = timelockFactories[chainId].toLowerCase();
|
|
2645
|
+
if (data.model === "static" && pricingData.model === "static") {
|
|
2646
|
+
data.dailyFundingRate ?? (data.dailyFundingRate = pricingData.dailyFundingRate);
|
|
2647
|
+
data.minFundingAmount ?? (data.minFundingAmount = pricingData.minFundingAmount);
|
|
2648
|
+
}
|
|
2649
|
+
if (data.model === "option" && pricingData.model === "option") {
|
|
2650
|
+
data.logicContract ?? (data.logicContract = pricingData.logicContract);
|
|
2651
|
+
data.iv ?? (data.iv = pricingData.iv);
|
|
2652
|
+
data.riskFreeRate ?? (data.riskFreeRate = pricingData.riskFreeRate);
|
|
2653
|
+
data.minPremiumDailyRate ?? (data.minPremiumDailyRate = pricingData.minPremiumDailyRate);
|
|
2654
|
+
data.minPremiumAmount ?? (data.minPremiumAmount = pricingData.minPremiumAmount);
|
|
2655
|
+
}
|
|
2656
|
+
if (data.model !== pricingData.model) if (data.model === "static") {
|
|
2657
|
+
if (data.dailyFundingRate === void 0) throw new Error("dailyFundingRate is required when switching to static model");
|
|
2658
|
+
if (data.minFundingAmount === void 0) throw new Error("minFundingAmount is required when switching to static model");
|
|
2659
|
+
} else {
|
|
2660
|
+
if (data.logicContract === void 0) throw new Error("logicContract is required when switching to option model");
|
|
2661
|
+
if (data.iv === void 0) throw new Error("iv is required when switching to option model");
|
|
2662
|
+
if (data.riskFreeRate === void 0) throw new Error("riskFreeRate is required when switching to option model");
|
|
2663
|
+
if (data.minPremiumDailyRate === void 0) throw new Error("minPremiumDailyRate is required when switching to option model");
|
|
2664
|
+
if (data.minPremiumAmount === void 0) throw new Error("minPremiumAmount is required when switching to option model");
|
|
2665
|
+
}
|
|
2666
|
+
const hash = data.model === "static" ? await writeContractAsync({
|
|
2667
|
+
address: factoryAddr,
|
|
2668
|
+
abi: factoryAbi,
|
|
2669
|
+
functionName: "deployStaticPerpsPricing",
|
|
2670
|
+
args: [data.dailyFundingRate, data.minFundingAmount]
|
|
2671
|
+
}) : await writeContractAsync({
|
|
2672
|
+
address: factoryAddr,
|
|
2673
|
+
abi: factoryAbi,
|
|
2674
|
+
functionName: "deployOptionPricing",
|
|
2675
|
+
args: [
|
|
2676
|
+
data.logicContract,
|
|
2677
|
+
data.iv,
|
|
2678
|
+
data.riskFreeRate,
|
|
2679
|
+
data.minPremiumDailyRate,
|
|
2680
|
+
data.minPremiumAmount
|
|
2681
|
+
]
|
|
2682
|
+
});
|
|
2683
|
+
const deployEvent = (await publicClient.waitForTransactionReceipt({ hash })).logs.find((log) => log.address.toLowerCase() === factoryAddr);
|
|
2684
|
+
if (!deployEvent) throw new Error("DeployFeeStrategy event not found");
|
|
2685
|
+
const decodedEvent = decodeEventLog({
|
|
2686
|
+
abi: factoryAbi,
|
|
2687
|
+
data: deployEvent.data,
|
|
2688
|
+
topics: deployEvent.topics
|
|
2689
|
+
});
|
|
2690
|
+
if (decodedEvent.eventName !== "DeployStaticPerpsPricing" && decodedEvent.eventName !== "DeployOptionPricing") throw new Error("Unexpected event");
|
|
2691
|
+
const pricingAddr = decodedEvent.args.pricing;
|
|
2692
|
+
return {
|
|
2693
|
+
deployHash: hash,
|
|
2694
|
+
updateHash: await writeContractAsync({
|
|
2695
|
+
address: marketAddr,
|
|
2696
|
+
abi: optionsMarketAbi,
|
|
2697
|
+
functionName: "updateAddresses",
|
|
2698
|
+
args: [pricingAddr, feeStrategy]
|
|
2699
|
+
}),
|
|
2700
|
+
newPricingAddr: pricingAddr
|
|
2701
|
+
};
|
|
2702
|
+
};
|
|
2703
|
+
return {
|
|
2704
|
+
updateMarketPricing,
|
|
2705
|
+
...rest
|
|
2706
|
+
};
|
|
2707
|
+
};
|
|
2708
|
+
|
|
2709
|
+
//#endregion
|
|
2710
|
+
export { TimelockProvider, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useFeeRates, useGuardianGlobalState, useLens, useLiquidityBlocks, useMarketData, useMarketPriceHistory, useMarketPricing, useMarketState, useMarketVolume, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionPricingParams, useOptionTimeline, usePauseGlobalTrading, usePauseMarketTrading, usePerpsOperator, usePoolData, usePriceAtSqrtPriceX96, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useStaticPricingParams, useTimelockConfig, useTokenBalance, useTokenData, useUpdateMarketFees, useUpdateMarketPricing, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
|
2198
2711
|
//# sourceMappingURL=client.js.map
|