timelock-sdk 0.0.143 → 0.0.145
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-Cq9Ysrsh.d.ts → client--xA1te-V.d.ts} +388 -388
- package/dist/{client-DyWSMO32.d.cts → client-B7N77R-L.d.cts} +377 -377
- package/dist/client.cjs +99 -94
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +100 -95
- package/dist/client.js.map +1 -1
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -13,6 +13,7 @@ graphql_tag = require_optionUtils.__toESM(graphql_tag);
|
|
|
13
13
|
let viem_actions = require("viem/actions");
|
|
14
14
|
let wagmi = require("wagmi");
|
|
15
15
|
let __tanstack_react_query = require("@tanstack/react-query");
|
|
16
|
+
require("zod/v4/locales");
|
|
16
17
|
let zod = require("zod");
|
|
17
18
|
|
|
18
19
|
//#region src/generated/graphql.ts
|
|
@@ -489,6 +490,98 @@ const useMarketData = (marketAddr) => {
|
|
|
489
490
|
return data || fallback || {};
|
|
490
491
|
};
|
|
491
492
|
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/hooks/pool/usePoolData.ts
|
|
495
|
+
const usePoolData = (poolManager, poolKey) => {
|
|
496
|
+
const { timelockLens } = useLens();
|
|
497
|
+
const { data } = (0, wagmi.useReadContract)({
|
|
498
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
499
|
+
abi: require_optionsMarket.lensAbi,
|
|
500
|
+
functionName: "getPoolData",
|
|
501
|
+
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
502
|
+
query: { enabled: !!poolManager && !!poolKey }
|
|
503
|
+
});
|
|
504
|
+
const _default = (0, react.useMemo)(() => ({
|
|
505
|
+
token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
|
|
506
|
+
token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
|
|
507
|
+
tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
|
|
508
|
+
fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
|
|
509
|
+
}), [poolKey]);
|
|
510
|
+
return data || _default;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/hooks/pool/usePriceAtTick.ts
|
|
515
|
+
const usePriceAtTick = (poolManager, poolKey, tick) => {
|
|
516
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
517
|
+
const priceBigInt = (0, react.useMemo)(() => tick !== void 0 ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
518
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
519
|
+
priceBigInt,
|
|
520
|
+
token0Decimals,
|
|
521
|
+
token1Decimals
|
|
522
|
+
]);
|
|
523
|
+
};
|
|
524
|
+
const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
|
|
525
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
526
|
+
const priceBigInt = (0, react.useMemo)(() => sqrtPriceX96 !== void 0 ? require_optionUtils.getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
527
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
528
|
+
priceBigInt,
|
|
529
|
+
token0Decimals,
|
|
530
|
+
token1Decimals
|
|
531
|
+
]);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region src/hooks/pool/useCurrentTick.ts
|
|
536
|
+
const useCurrentTick = (poolManager, poolKey) => {
|
|
537
|
+
const { stateView } = useLens();
|
|
538
|
+
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
539
|
+
const { data, ...rest } = (0, wagmi.useReadContract)({
|
|
540
|
+
address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
|
|
541
|
+
abi: require_optionUtils.statelessStateViewAbi,
|
|
542
|
+
functionName: "getSlot0",
|
|
543
|
+
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
544
|
+
query: {
|
|
545
|
+
enabled: !!poolManager && !!poolKey,
|
|
546
|
+
refetchInterval: 3e3,
|
|
547
|
+
select: (raw) => {
|
|
548
|
+
const sqrtPriceX96 = raw[0];
|
|
549
|
+
const exact = raw[1];
|
|
550
|
+
return {
|
|
551
|
+
exact,
|
|
552
|
+
rounded: tickSpacing ? require_optionUtils.roundTick(exact, tickSpacing) : void 0,
|
|
553
|
+
sqrtPriceX96
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
return {
|
|
559
|
+
exact: data === null || data === void 0 ? void 0 : data.exact,
|
|
560
|
+
rounded: data === null || data === void 0 ? void 0 : data.rounded,
|
|
561
|
+
sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
|
|
562
|
+
...rest
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/hooks/pool/useCurrentPrice.ts
|
|
568
|
+
const useCurrentPrice = (poolManager, poolKey) => {
|
|
569
|
+
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
|
|
570
|
+
const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
|
|
571
|
+
return (0, react.useMemo)(() => ({
|
|
572
|
+
currentPrice,
|
|
573
|
+
sqrtPriceX96,
|
|
574
|
+
currentTick: {
|
|
575
|
+
exact,
|
|
576
|
+
rounded
|
|
577
|
+
}
|
|
578
|
+
}), [
|
|
579
|
+
currentPrice,
|
|
580
|
+
exact,
|
|
581
|
+
rounded
|
|
582
|
+
]);
|
|
583
|
+
};
|
|
584
|
+
|
|
492
585
|
//#endregion
|
|
493
586
|
//#region src/lib/utils.ts
|
|
494
587
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -502,14 +595,18 @@ const useExerciseOption = (marketAddr) => {
|
|
|
502
595
|
const client = (0, wagmi.useClient)();
|
|
503
596
|
const { address } = (0, wagmi.useConnection)();
|
|
504
597
|
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
598
|
+
const { sqrtPriceX96 } = useCurrentPrice();
|
|
505
599
|
const exerciseOption = async ({ option, liquidities }) => {
|
|
506
600
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
507
601
|
if (!marketAddr) throw new Error("Market address not available");
|
|
508
602
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
509
603
|
if (!vault) throw new Error("Vault not available");
|
|
510
604
|
if (!poolKey) throw new Error("Pool data not available");
|
|
605
|
+
if (!sqrtPriceX96) throw new Error("Current price not available");
|
|
511
606
|
const swapper = require_optionUtils.swappers[client.chain.id];
|
|
512
607
|
if (!swapper) throw new Error("Swapper not available");
|
|
608
|
+
const minSqrtPrice = sqrtPriceX96 * 9n / 10n;
|
|
609
|
+
const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
|
|
513
610
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
514
611
|
const hash = await writeContractAsync({
|
|
515
612
|
address: marketAddr,
|
|
@@ -550,8 +647,8 @@ const useExerciseOption = (marketAddr) => {
|
|
|
550
647
|
{ type: "uint160" }
|
|
551
648
|
], [
|
|
552
649
|
poolKey,
|
|
553
|
-
|
|
554
|
-
|
|
650
|
+
minSqrtPrice,
|
|
651
|
+
maxSqrtPrice
|
|
555
652
|
]),
|
|
556
653
|
refTick
|
|
557
654
|
]
|
|
@@ -611,58 +708,6 @@ const useMaxPositionSize = (marketAddr, maxBorrowableRange = 100) => {
|
|
|
611
708
|
};
|
|
612
709
|
};
|
|
613
710
|
|
|
614
|
-
//#endregion
|
|
615
|
-
//#region src/hooks/pool/usePoolData.ts
|
|
616
|
-
const usePoolData = (poolManager, poolKey) => {
|
|
617
|
-
const { timelockLens } = useLens();
|
|
618
|
-
const { data } = (0, wagmi.useReadContract)({
|
|
619
|
-
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
620
|
-
abi: require_optionsMarket.lensAbi,
|
|
621
|
-
functionName: "getPoolData",
|
|
622
|
-
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
623
|
-
query: { enabled: !!poolManager && !!poolKey }
|
|
624
|
-
});
|
|
625
|
-
const _default = (0, react.useMemo)(() => ({
|
|
626
|
-
token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
|
|
627
|
-
token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
|
|
628
|
-
tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
|
|
629
|
-
fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
|
|
630
|
-
}), [poolKey]);
|
|
631
|
-
return data || _default;
|
|
632
|
-
};
|
|
633
|
-
|
|
634
|
-
//#endregion
|
|
635
|
-
//#region src/hooks/pool/useCurrentTick.ts
|
|
636
|
-
const useCurrentTick = (poolManager, poolKey) => {
|
|
637
|
-
const { stateView } = useLens();
|
|
638
|
-
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
639
|
-
const { data, ...rest } = (0, wagmi.useReadContract)({
|
|
640
|
-
address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
|
|
641
|
-
abi: require_optionUtils.statelessStateViewAbi,
|
|
642
|
-
functionName: "getSlot0",
|
|
643
|
-
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
644
|
-
query: {
|
|
645
|
-
enabled: !!poolManager && !!poolKey,
|
|
646
|
-
refetchInterval: 3e3,
|
|
647
|
-
select: (raw) => {
|
|
648
|
-
const sqrtPriceX96 = raw[0];
|
|
649
|
-
const exact = raw[1];
|
|
650
|
-
return {
|
|
651
|
-
exact,
|
|
652
|
-
rounded: tickSpacing ? require_optionUtils.roundTick(exact, tickSpacing) : void 0,
|
|
653
|
-
sqrtPriceX96
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
return {
|
|
659
|
-
exact: data === null || data === void 0 ? void 0 : data.exact,
|
|
660
|
-
rounded: data === null || data === void 0 ? void 0 : data.rounded,
|
|
661
|
-
sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
|
|
662
|
-
...rest
|
|
663
|
-
};
|
|
664
|
-
};
|
|
665
|
-
|
|
666
711
|
//#endregion
|
|
667
712
|
//#region src/hooks/tokens/useApproval.ts
|
|
668
713
|
const useApproval = () => {
|
|
@@ -740,46 +785,6 @@ const useMintOption = (marketAddr) => {
|
|
|
740
785
|
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintOption });
|
|
741
786
|
};
|
|
742
787
|
|
|
743
|
-
//#endregion
|
|
744
|
-
//#region src/hooks/pool/usePriceAtTick.ts
|
|
745
|
-
const usePriceAtTick = (poolManager, poolKey, tick) => {
|
|
746
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
747
|
-
const priceBigInt = (0, react.useMemo)(() => tick !== void 0 ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
748
|
-
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
749
|
-
priceBigInt,
|
|
750
|
-
token0Decimals,
|
|
751
|
-
token1Decimals
|
|
752
|
-
]);
|
|
753
|
-
};
|
|
754
|
-
const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
|
|
755
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
756
|
-
const priceBigInt = (0, react.useMemo)(() => sqrtPriceX96 !== void 0 ? require_optionUtils.getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
757
|
-
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
758
|
-
priceBigInt,
|
|
759
|
-
token0Decimals,
|
|
760
|
-
token1Decimals
|
|
761
|
-
]);
|
|
762
|
-
};
|
|
763
|
-
|
|
764
|
-
//#endregion
|
|
765
|
-
//#region src/hooks/pool/useCurrentPrice.ts
|
|
766
|
-
const useCurrentPrice = (poolManager, poolKey) => {
|
|
767
|
-
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
|
|
768
|
-
const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
|
|
769
|
-
return (0, react.useMemo)(() => ({
|
|
770
|
-
currentPrice,
|
|
771
|
-
sqrtPriceX96,
|
|
772
|
-
currentTick: {
|
|
773
|
-
exact,
|
|
774
|
-
rounded
|
|
775
|
-
}
|
|
776
|
-
}), [
|
|
777
|
-
currentPrice,
|
|
778
|
-
exact,
|
|
779
|
-
rounded
|
|
780
|
-
]);
|
|
781
|
-
};
|
|
782
|
-
|
|
783
788
|
//#endregion
|
|
784
789
|
//#region src/hooks/options/useOptionPnl.ts
|
|
785
790
|
const useOptionPnl = (option) => {
|