timelock-sdk 0.0.144 → 0.0.146
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-BRzenCT7.d.cts → client-jAKjSAlA.d.cts} +380 -380
- package/dist/client.cjs +99 -95
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.js +100 -96
- package/dist/client.js.map +1 -1
- package/dist/package.d.cts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -489,6 +489,98 @@ const useMarketData = (marketAddr) => {
|
|
|
489
489
|
return data || fallback || {};
|
|
490
490
|
};
|
|
491
491
|
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/hooks/pool/usePoolData.ts
|
|
494
|
+
const usePoolData = (poolManager, poolKey) => {
|
|
495
|
+
const { timelockLens } = useLens();
|
|
496
|
+
const { data } = (0, wagmi.useReadContract)({
|
|
497
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
498
|
+
abi: require_optionsMarket.lensAbi,
|
|
499
|
+
functionName: "getPoolData",
|
|
500
|
+
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
501
|
+
query: { enabled: !!poolManager && !!poolKey }
|
|
502
|
+
});
|
|
503
|
+
const _default = (0, react.useMemo)(() => ({
|
|
504
|
+
token0: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency0,
|
|
505
|
+
token1: poolKey === null || poolKey === void 0 ? void 0 : poolKey.currency1,
|
|
506
|
+
tickSpacing: poolKey === null || poolKey === void 0 ? void 0 : poolKey.tickSpacing,
|
|
507
|
+
fee: poolKey === null || poolKey === void 0 ? void 0 : poolKey.fee
|
|
508
|
+
}), [poolKey]);
|
|
509
|
+
return data || _default;
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/hooks/pool/usePriceAtTick.ts
|
|
514
|
+
const usePriceAtTick = (poolManager, poolKey, tick) => {
|
|
515
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
516
|
+
const priceBigInt = (0, react.useMemo)(() => tick !== void 0 ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
517
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
518
|
+
priceBigInt,
|
|
519
|
+
token0Decimals,
|
|
520
|
+
token1Decimals
|
|
521
|
+
]);
|
|
522
|
+
};
|
|
523
|
+
const usePriceAtSqrtPriceX96 = (poolManager, poolKey, sqrtPriceX96) => {
|
|
524
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
|
|
525
|
+
const priceBigInt = (0, react.useMemo)(() => sqrtPriceX96 !== void 0 ? require_optionUtils.getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
526
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
527
|
+
priceBigInt,
|
|
528
|
+
token0Decimals,
|
|
529
|
+
token1Decimals
|
|
530
|
+
]);
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/hooks/pool/useCurrentTick.ts
|
|
535
|
+
const useCurrentTick = (poolManager, poolKey) => {
|
|
536
|
+
const { stateView } = useLens();
|
|
537
|
+
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
538
|
+
const { data, ...rest } = (0, wagmi.useReadContract)({
|
|
539
|
+
address: stateView === null || stateView === void 0 ? void 0 : stateView.address,
|
|
540
|
+
abi: require_optionUtils.statelessStateViewAbi,
|
|
541
|
+
functionName: "getSlot0",
|
|
542
|
+
args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
|
|
543
|
+
query: {
|
|
544
|
+
enabled: !!poolManager && !!poolKey,
|
|
545
|
+
refetchInterval: 3e3,
|
|
546
|
+
select: (raw) => {
|
|
547
|
+
const sqrtPriceX96 = raw[0];
|
|
548
|
+
const exact = raw[1];
|
|
549
|
+
return {
|
|
550
|
+
exact,
|
|
551
|
+
rounded: tickSpacing ? require_optionUtils.roundTick(exact, tickSpacing) : void 0,
|
|
552
|
+
sqrtPriceX96
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
return {
|
|
558
|
+
exact: data === null || data === void 0 ? void 0 : data.exact,
|
|
559
|
+
rounded: data === null || data === void 0 ? void 0 : data.rounded,
|
|
560
|
+
sqrtPriceX96: data === null || data === void 0 ? void 0 : data.sqrtPriceX96,
|
|
561
|
+
...rest
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/hooks/pool/useCurrentPrice.ts
|
|
567
|
+
const useCurrentPrice = (poolManager, poolKey) => {
|
|
568
|
+
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolManager, poolKey);
|
|
569
|
+
const currentPrice = usePriceAtSqrtPriceX96(poolManager, poolKey, sqrtPriceX96);
|
|
570
|
+
return (0, react.useMemo)(() => ({
|
|
571
|
+
currentPrice,
|
|
572
|
+
sqrtPriceX96,
|
|
573
|
+
currentTick: {
|
|
574
|
+
exact,
|
|
575
|
+
rounded
|
|
576
|
+
}
|
|
577
|
+
}), [
|
|
578
|
+
currentPrice,
|
|
579
|
+
exact,
|
|
580
|
+
rounded
|
|
581
|
+
]);
|
|
582
|
+
};
|
|
583
|
+
|
|
492
584
|
//#endregion
|
|
493
585
|
//#region src/lib/utils.ts
|
|
494
586
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -496,20 +588,24 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
496
588
|
//#endregion
|
|
497
589
|
//#region src/hooks/options/useExerciseOption.ts
|
|
498
590
|
const useExerciseOption = (marketAddr) => {
|
|
499
|
-
const { vault, poolKey } = useMarketData(marketAddr);
|
|
591
|
+
const { vault, poolManager, poolKey } = useMarketData(marketAddr);
|
|
500
592
|
const { timelockLens } = useLens();
|
|
501
593
|
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
502
594
|
const client = (0, wagmi.useClient)();
|
|
503
595
|
const { address } = (0, wagmi.useConnection)();
|
|
504
596
|
const { writeContractAsync } = (0, wagmi.useWriteContract)();
|
|
597
|
+
const { sqrtPriceX96 } = useCurrentPrice(poolManager, poolKey);
|
|
505
598
|
const exerciseOption = async ({ option, liquidities }) => {
|
|
506
599
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
507
600
|
if (!marketAddr) throw new Error("Market address not available");
|
|
508
601
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
509
602
|
if (!vault) throw new Error("Vault not available");
|
|
510
603
|
if (!poolKey) throw new Error("Pool data not available");
|
|
604
|
+
if (!sqrtPriceX96) throw new Error("Current price not available");
|
|
511
605
|
const swapper = require_optionUtils.swappers[client.chain.id];
|
|
512
606
|
if (!swapper) throw new Error("Swapper not available");
|
|
607
|
+
const minSqrtPrice = sqrtPriceX96 * 9n / 10n;
|
|
608
|
+
const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
|
|
513
609
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
514
610
|
const hash = await writeContractAsync({
|
|
515
611
|
address: marketAddr,
|
|
@@ -550,8 +646,8 @@ const useExerciseOption = (marketAddr) => {
|
|
|
550
646
|
{ type: "uint160" }
|
|
551
647
|
], [
|
|
552
648
|
poolKey,
|
|
553
|
-
|
|
554
|
-
|
|
649
|
+
minSqrtPrice,
|
|
650
|
+
maxSqrtPrice
|
|
555
651
|
]),
|
|
556
652
|
refTick
|
|
557
653
|
]
|
|
@@ -611,58 +707,6 @@ const useMaxPositionSize = (marketAddr, maxBorrowableRange = 100) => {
|
|
|
611
707
|
};
|
|
612
708
|
};
|
|
613
709
|
|
|
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
710
|
//#endregion
|
|
667
711
|
//#region src/hooks/tokens/useApproval.ts
|
|
668
712
|
const useApproval = () => {
|
|
@@ -740,46 +784,6 @@ const useMintOption = (marketAddr) => {
|
|
|
740
784
|
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintOption });
|
|
741
785
|
};
|
|
742
786
|
|
|
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
787
|
//#endregion
|
|
784
788
|
//#region src/hooks/options/useOptionPnl.ts
|
|
785
789
|
const useOptionPnl = (option) => {
|