timelock-sdk 0.0.33 → 0.0.35
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 +3 -3
- package/dist/abis.js +1 -1
- package/dist/client.cjs +102 -33
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +204 -124
- package/dist/client.d.ts +202 -122
- package/dist/client.js +94 -26
- package/dist/client.js.map +1 -1
- package/dist/{index-CA5kB-yT.d.cts → index-B7b3c8cu.d.cts} +92 -92
- package/dist/package.d.cts +1 -1
- package/dist/{uniswapV3Pool-Copswrde.js → singleOwnerVault-DMu9pqN1.js} +696 -696
- package/dist/singleOwnerVault-DMu9pqN1.js.map +1 -0
- package/dist/{uniswapV3Pool-D9Vqrkmz.cjs → singleOwnerVault-gf2zNZVk.cjs} +696 -696
- package/dist/singleOwnerVault-gf2zNZVk.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/uniswapV3Pool-Copswrde.js.map +0 -1
- package/dist/uniswapV3Pool-D9Vqrkmz.cjs.map +0 -1
package/dist/abis.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_optionsMarket = require('./optionsMarket-Br-bjuSA.cjs');
|
|
2
|
-
const
|
|
2
|
+
const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
|
|
3
3
|
|
|
4
4
|
exports.erc20Abi = require_optionsMarket.erc20Abi;
|
|
5
5
|
exports.lensAbi = require_optionsMarket.lensAbi;
|
|
6
6
|
exports.optionsMarketAbi = require_optionsMarket.optionsMarketAbi;
|
|
7
|
-
exports.singleOwnerVaultAbi =
|
|
7
|
+
exports.singleOwnerVaultAbi = require_singleOwnerVault.singleOwnerVaultAbi;
|
|
8
8
|
exports.uniswapMathLensAbi = require_optionsMarket.uniswapMathLensAbi;
|
|
9
|
-
exports.uniswapV3PoolAbi =
|
|
9
|
+
exports.uniswapV3PoolAbi = require_singleOwnerVault.uniswapV3PoolAbi;
|
package/dist/abis.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { erc20Abi, lensAbi, optionsMarketAbi, uniswapMathLensAbi } from "./optionsMarket-DyBxHplR.js";
|
|
2
|
-
import { singleOwnerVaultAbi, uniswapV3PoolAbi } from "./
|
|
2
|
+
import { singleOwnerVaultAbi, uniswapV3PoolAbi } from "./singleOwnerVault-DMu9pqN1.js";
|
|
3
3
|
|
|
4
4
|
export { erc20Abi, lensAbi, optionsMarketAbi, singleOwnerVaultAbi, uniswapMathLensAbi, uniswapV3PoolAbi };
|
package/dist/client.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const require_numberUtils = require('./numberUtils-DOUvJfQD.cjs');
|
|
5
5
|
const require_optionsMarket = require('./optionsMarket-Br-bjuSA.cjs');
|
|
6
|
-
const
|
|
6
|
+
const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
|
|
7
7
|
let viem = require("viem");
|
|
8
8
|
viem = require_numberUtils.__toESM(viem);
|
|
9
9
|
let react = require("react");
|
|
@@ -37,6 +37,7 @@ const GetActiveUserOptionsDocument = graphql_tag.default`
|
|
|
37
37
|
optionType
|
|
38
38
|
strikeTick
|
|
39
39
|
entryTick
|
|
40
|
+
startTick
|
|
40
41
|
strikePrice
|
|
41
42
|
entryPrice
|
|
42
43
|
expiresAt
|
|
@@ -69,6 +70,7 @@ const GetClosedUserOptionsDocument = graphql_tag.default`
|
|
|
69
70
|
optionType
|
|
70
71
|
strikeTick
|
|
71
72
|
entryTick
|
|
73
|
+
startTick
|
|
72
74
|
strikePrice
|
|
73
75
|
entryPrice
|
|
74
76
|
expiresAt
|
|
@@ -203,30 +205,36 @@ const useMarketData = (marketAddr) => {
|
|
|
203
205
|
return data || {};
|
|
204
206
|
};
|
|
205
207
|
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/hooks/useLens.ts
|
|
210
|
+
const useLens = () => {
|
|
211
|
+
const client = (0, wagmi.useClient)();
|
|
212
|
+
return (0, react.useMemo)(() => ({
|
|
213
|
+
timelockLens: client ? require_numberUtils.getTimelockLens(client) : void 0,
|
|
214
|
+
uniswapLens: client ? require_numberUtils.getUniswapMathLens(client) : void 0
|
|
215
|
+
}), [client]);
|
|
216
|
+
};
|
|
217
|
+
|
|
206
218
|
//#endregion
|
|
207
219
|
//#region src/hooks/market/useExerciseOption.ts
|
|
208
220
|
const useExerciseOption = (marketAddr) => {
|
|
209
221
|
const { vault } = useMarketData(marketAddr);
|
|
222
|
+
const { timelockLens } = useLens();
|
|
210
223
|
const client = (0, wagmi.useClient)();
|
|
211
|
-
const { data: lowestTick } = (0, wagmi.useReadContract)({
|
|
212
|
-
address: vault,
|
|
213
|
-
abi: require_uniswapV3Pool.singleOwnerVaultAbi,
|
|
214
|
-
functionName: "lowestTick"
|
|
215
|
-
});
|
|
216
224
|
const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
|
|
217
225
|
const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
|
|
218
|
-
const exerciseOption = async (
|
|
219
|
-
if (!client) throw new Error("Wallet not connected");
|
|
220
|
-
|
|
226
|
+
const exerciseOption = async (option, liquidities) => {
|
|
227
|
+
if (!client || !timelockLens || !vault || !marketAddr) throw new Error("Wallet not connected");
|
|
228
|
+
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
221
229
|
const hash$1 = await writeContractAsync({
|
|
222
230
|
address: marketAddr,
|
|
223
231
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
224
232
|
functionName: "exerciseOption",
|
|
225
233
|
args: [
|
|
226
|
-
|
|
234
|
+
option.id,
|
|
227
235
|
liquidities,
|
|
228
236
|
0n,
|
|
229
|
-
|
|
237
|
+
refTick
|
|
230
238
|
]
|
|
231
239
|
});
|
|
232
240
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
|
|
@@ -243,16 +251,6 @@ const useExerciseOption = (marketAddr) => {
|
|
|
243
251
|
};
|
|
244
252
|
};
|
|
245
253
|
|
|
246
|
-
//#endregion
|
|
247
|
-
//#region src/hooks/useLens.ts
|
|
248
|
-
const useLens = () => {
|
|
249
|
-
const client = (0, wagmi.useClient)();
|
|
250
|
-
return (0, react.useMemo)(() => ({
|
|
251
|
-
timelockLens: client ? require_numberUtils.getTimelockLens(client) : void 0,
|
|
252
|
-
uniswapLens: client ? require_numberUtils.getUniswapMathLens(client) : void 0
|
|
253
|
-
}), [client]);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
254
|
//#endregion
|
|
257
255
|
//#region src/hooks/market/useMaxPositionSize.ts
|
|
258
256
|
const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) => {
|
|
@@ -315,7 +313,7 @@ const useCurrentTick = (poolAddr) => {
|
|
|
315
313
|
const { tickSpacing } = usePoolData(poolAddr);
|
|
316
314
|
const { data } = (0, wagmi.useReadContract)({
|
|
317
315
|
address: poolAddr,
|
|
318
|
-
abi:
|
|
316
|
+
abi: require_singleOwnerVault.uniswapV3PoolAbi,
|
|
319
317
|
functionName: "slot0",
|
|
320
318
|
args: []
|
|
321
319
|
});
|
|
@@ -420,8 +418,9 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration, strike
|
|
|
420
418
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
421
419
|
const strikeTickRounded = (0, react.useMemo)(() => {
|
|
422
420
|
if (!tickSpacing || currentTick === void 0) return;
|
|
423
|
-
|
|
424
|
-
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0)
|
|
421
|
+
let strikeTickRounded$1 = require_numberUtils.roundTickDown(strikeTick ?? currentTick, tickSpacing);
|
|
422
|
+
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTickRounded$1 += tickSpacing;
|
|
423
|
+
return strikeTickRounded$1;
|
|
425
424
|
}, [
|
|
426
425
|
currentTick,
|
|
427
426
|
tickSpacing,
|
|
@@ -468,8 +467,8 @@ const useUserOptions = (user, active = false) => {
|
|
|
468
467
|
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
469
468
|
premiumPaid: BigInt(option.premiumPaid),
|
|
470
469
|
realizedPayout: BigInt(option.realizedPayout),
|
|
471
|
-
liquiditiesAtOpen: option.liquiditiesAtOpen.map((
|
|
472
|
-
liquiditiesCurrent: option.liquiditiesCurrent.map((
|
|
470
|
+
liquiditiesAtOpen: option.liquiditiesAtOpen.map((l) => BigInt(l)),
|
|
471
|
+
liquiditiesCurrent: option.liquiditiesCurrent.map((l) => BigInt(l)),
|
|
473
472
|
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
474
473
|
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
475
474
|
strikePrice: BigInt(option.strikePrice),
|
|
@@ -513,12 +512,81 @@ const useCurrentPrice = (poolAddr) => {
|
|
|
513
512
|
}), [currentPrice, currentTick]);
|
|
514
513
|
};
|
|
515
514
|
|
|
515
|
+
//#endregion
|
|
516
|
+
//#region src/lib/price.ts
|
|
517
|
+
const resolutionToGeckoTerminal = (resolution) => {
|
|
518
|
+
return {
|
|
519
|
+
"1m": {
|
|
520
|
+
timeframe: "minute",
|
|
521
|
+
aggregate: "1",
|
|
522
|
+
seconds: 60
|
|
523
|
+
},
|
|
524
|
+
"5m": {
|
|
525
|
+
timeframe: "minute",
|
|
526
|
+
aggregate: "5",
|
|
527
|
+
seconds: 300
|
|
528
|
+
},
|
|
529
|
+
"15m": {
|
|
530
|
+
timeframe: "minute",
|
|
531
|
+
aggregate: "15",
|
|
532
|
+
seconds: 900
|
|
533
|
+
},
|
|
534
|
+
"1h": {
|
|
535
|
+
timeframe: "hour",
|
|
536
|
+
aggregate: "1",
|
|
537
|
+
seconds: 3600
|
|
538
|
+
},
|
|
539
|
+
"4h": {
|
|
540
|
+
timeframe: "hour",
|
|
541
|
+
aggregate: "4",
|
|
542
|
+
seconds: 14400
|
|
543
|
+
},
|
|
544
|
+
"1d": {
|
|
545
|
+
timeframe: "day",
|
|
546
|
+
aggregate: "1",
|
|
547
|
+
seconds: 86400
|
|
548
|
+
}
|
|
549
|
+
}[resolution];
|
|
550
|
+
};
|
|
551
|
+
const getPriceHistory = async (poolAddress, resolution, startTimestamp, endTimestamp) => {
|
|
552
|
+
const network = "monad-testnet";
|
|
553
|
+
const { timeframe, aggregate, seconds } = resolutionToGeckoTerminal(resolution);
|
|
554
|
+
const timeDiff = endTimestamp - startTimestamp;
|
|
555
|
+
const url = `https://api.geckoterminal.com/api/v2/networks/${network}/pools/${poolAddress}/ohlcv/${timeframe}?aggregate=${aggregate}&limit=${Math.min(Math.ceil(timeDiff / seconds), 1e3)}&token=quote¤cy=usd&before_timestamp=${endTimestamp}`;
|
|
556
|
+
const res = await fetch(url, { headers: { Accept: "application/json" } });
|
|
557
|
+
if (!res.ok) throw new Error(`Failed to fetch price history: ${res.statusText}`);
|
|
558
|
+
return (await res.json()).data.attributes.ohlcv_list.map(({ 0: timestamp, 4: price }) => ({
|
|
559
|
+
timestamp,
|
|
560
|
+
price
|
|
561
|
+
})).filter((point) => point.timestamp >= startTimestamp && point.timestamp <= endTimestamp).sort((a, b) => a.timestamp - b.timestamp);
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/hooks/pool/usePriceHistory.ts
|
|
566
|
+
const usePriceHistory = ({ poolAddress, resolution, startTimestamp, endTimestamp, enabled = true }) => {
|
|
567
|
+
return (0, __tanstack_react_query.useQuery)({
|
|
568
|
+
queryKey: [
|
|
569
|
+
"priceHistory",
|
|
570
|
+
poolAddress,
|
|
571
|
+
(0, wagmi.useChainId)(),
|
|
572
|
+
resolution,
|
|
573
|
+
startTimestamp,
|
|
574
|
+
endTimestamp
|
|
575
|
+
],
|
|
576
|
+
queryFn: () => getPriceHistory(poolAddress, resolution, startTimestamp, endTimestamp),
|
|
577
|
+
enabled: enabled && !!poolAddress && startTimestamp < endTimestamp,
|
|
578
|
+
staleTime: 60 * 1e3,
|
|
579
|
+
gcTime: 300 * 1e3,
|
|
580
|
+
retry: 2
|
|
581
|
+
});
|
|
582
|
+
};
|
|
583
|
+
|
|
516
584
|
//#endregion
|
|
517
585
|
//#region src/hooks/vault/useVaultData.ts
|
|
518
586
|
const useVaultData = (vaultAddr) => {
|
|
519
587
|
const { data } = (0, wagmi.useReadContract)({
|
|
520
588
|
address: vaultAddr,
|
|
521
|
-
abi:
|
|
589
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
522
590
|
functionName: "pool"
|
|
523
591
|
});
|
|
524
592
|
return { pool: data };
|
|
@@ -538,7 +606,7 @@ const useBurnLiquidity = (vaultAddr) => {
|
|
|
538
606
|
if (!vaultAddr || !timelockLens) throw new Error("Vault/lens not available");
|
|
539
607
|
const hash$1 = await writeContractAsync({
|
|
540
608
|
address: vaultAddr,
|
|
541
|
-
abi:
|
|
609
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
542
610
|
functionName: "burn",
|
|
543
611
|
args: [
|
|
544
612
|
tickLower,
|
|
@@ -560,10 +628,10 @@ const useBurnLiquidity = (vaultAddr) => {
|
|
|
560
628
|
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
|
|
561
629
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
562
630
|
address: vaultAddr,
|
|
563
|
-
abi:
|
|
631
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
564
632
|
functionName: "multicall",
|
|
565
633
|
args: [positions.map((p, i) => (0, viem.encodeFunctionData)({
|
|
566
|
-
abi:
|
|
634
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
567
635
|
functionName: "burn",
|
|
568
636
|
args: [
|
|
569
637
|
p.tickLower,
|
|
@@ -678,7 +746,7 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
678
746
|
}]);
|
|
679
747
|
const hash$1 = await writeContractAsync({
|
|
680
748
|
address: vaultAddr,
|
|
681
|
-
abi:
|
|
749
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
682
750
|
functionName: "mint",
|
|
683
751
|
args: [
|
|
684
752
|
tickLower,
|
|
@@ -701,10 +769,10 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
701
769
|
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
|
|
702
770
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
703
771
|
address: vaultAddr,
|
|
704
|
-
abi:
|
|
772
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
705
773
|
functionName: "multicall",
|
|
706
774
|
args: [positions.map((p, i) => (0, viem.encodeFunctionData)({
|
|
707
|
-
abi:
|
|
775
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
708
776
|
functionName: "mint",
|
|
709
777
|
args: [
|
|
710
778
|
p.tickLower,
|
|
@@ -785,6 +853,7 @@ exports.useOptionPnl = useOptionPnl;
|
|
|
785
853
|
exports.useOptionPremium = useOptionPremium;
|
|
786
854
|
exports.usePoolData = usePoolData;
|
|
787
855
|
exports.usePriceAtTick = usePriceAtTick;
|
|
856
|
+
exports.usePriceHistory = usePriceHistory;
|
|
788
857
|
exports.useTimelockConfig = useTimelockConfig;
|
|
789
858
|
exports.useVaultData = useVaultData;
|
|
790
859
|
exports.useVaultTVL = useVaultTVL;
|