timelock-sdk 0.0.34 → 0.0.36
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 -32
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +258 -122
- package/dist/client.d.ts +313 -177
- package/dist/client.js +94 -25
- package/dist/client.js.map +1 -1
- package/dist/{index-CRhFaRiq.d.ts → index-B20z73_3.d.ts} +92 -92
- package/dist/package.d.ts +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/client.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { lensAbi, optionsMarketAbi } from "./optionsMarket-DyBxHplR.js";
|
|
5
5
|
import { PRICE_PRECISION, getErc20, getPriceAtTick, getTimelockLens, getTimelockMarket, getUniswapMathLens, roundTickDown, timelockLenses, token0ToToken1, token1ToToken0, uniswapMathLenses, wrapAmount, wrapPrice } from "./numberUtils-CAMznXR5.js";
|
|
6
|
-
import { singleOwnerVaultAbi, uniswapV3PoolAbi } from "./
|
|
6
|
+
import { singleOwnerVaultAbi, uniswapV3PoolAbi } from "./singleOwnerVault-DMu9pqN1.js";
|
|
7
7
|
import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
|
|
8
8
|
import React, { createContext, useContext, useMemo } from "react";
|
|
9
9
|
import { useAccount, useChainId, useClient, useReadContract, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
@@ -20,6 +20,7 @@ const GetActiveUserOptionsDocument = gql`
|
|
|
20
20
|
limit: 1000
|
|
21
21
|
) {
|
|
22
22
|
id
|
|
23
|
+
optionId
|
|
23
24
|
ownerAddr
|
|
24
25
|
exerciseEvents {
|
|
25
26
|
transactionHash
|
|
@@ -30,6 +31,7 @@ const GetActiveUserOptionsDocument = gql`
|
|
|
30
31
|
optionType
|
|
31
32
|
strikeTick
|
|
32
33
|
entryTick
|
|
34
|
+
startTick
|
|
33
35
|
strikePrice
|
|
34
36
|
entryPrice
|
|
35
37
|
expiresAt
|
|
@@ -52,6 +54,7 @@ const GetClosedUserOptionsDocument = gql`
|
|
|
52
54
|
limit: 1000
|
|
53
55
|
) {
|
|
54
56
|
id
|
|
57
|
+
optionId
|
|
55
58
|
ownerAddr
|
|
56
59
|
exerciseEvents {
|
|
57
60
|
transactionHash
|
|
@@ -62,6 +65,7 @@ const GetClosedUserOptionsDocument = gql`
|
|
|
62
65
|
optionType
|
|
63
66
|
strikeTick
|
|
64
67
|
entryTick
|
|
68
|
+
startTick
|
|
65
69
|
strikePrice
|
|
66
70
|
entryPrice
|
|
67
71
|
expiresAt
|
|
@@ -196,30 +200,36 @@ const useMarketData = (marketAddr) => {
|
|
|
196
200
|
return data || {};
|
|
197
201
|
};
|
|
198
202
|
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/hooks/useLens.ts
|
|
205
|
+
const useLens = () => {
|
|
206
|
+
const client = useClient();
|
|
207
|
+
return useMemo(() => ({
|
|
208
|
+
timelockLens: client ? getTimelockLens(client) : void 0,
|
|
209
|
+
uniswapLens: client ? getUniswapMathLens(client) : void 0
|
|
210
|
+
}), [client]);
|
|
211
|
+
};
|
|
212
|
+
|
|
199
213
|
//#endregion
|
|
200
214
|
//#region src/hooks/market/useExerciseOption.ts
|
|
201
215
|
const useExerciseOption = (marketAddr) => {
|
|
202
216
|
const { vault } = useMarketData(marketAddr);
|
|
217
|
+
const { timelockLens } = useLens();
|
|
203
218
|
const client = useClient();
|
|
204
|
-
const { data: lowestTick } = useReadContract({
|
|
205
|
-
address: vault,
|
|
206
|
-
abi: singleOwnerVaultAbi,
|
|
207
|
-
functionName: "lowestTick"
|
|
208
|
-
});
|
|
209
219
|
const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
|
|
210
220
|
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
|
|
211
|
-
const exerciseOption = async (
|
|
212
|
-
if (!client) throw new Error("Wallet not connected");
|
|
213
|
-
|
|
221
|
+
const exerciseOption = async (option, liquidities) => {
|
|
222
|
+
if (!client || !timelockLens || !vault || !marketAddr) throw new Error("Wallet not connected");
|
|
223
|
+
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
214
224
|
const hash$1 = await writeContractAsync({
|
|
215
225
|
address: marketAddr,
|
|
216
226
|
abi: optionsMarketAbi,
|
|
217
227
|
functionName: "exerciseOption",
|
|
218
228
|
args: [
|
|
219
|
-
optionId,
|
|
229
|
+
option.optionId,
|
|
220
230
|
liquidities,
|
|
221
231
|
0n,
|
|
222
|
-
|
|
232
|
+
refTick
|
|
223
233
|
]
|
|
224
234
|
});
|
|
225
235
|
await waitForTransactionReceipt(client, { hash: hash$1 });
|
|
@@ -236,16 +246,6 @@ const useExerciseOption = (marketAddr) => {
|
|
|
236
246
|
};
|
|
237
247
|
};
|
|
238
248
|
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/hooks/useLens.ts
|
|
241
|
-
const useLens = () => {
|
|
242
|
-
const client = useClient();
|
|
243
|
-
return useMemo(() => ({
|
|
244
|
-
timelockLens: client ? getTimelockLens(client) : void 0,
|
|
245
|
-
uniswapLens: client ? getUniswapMathLens(client) : void 0
|
|
246
|
-
}), [client]);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
249
|
//#endregion
|
|
250
250
|
//#region src/hooks/market/useMaxPositionSize.ts
|
|
251
251
|
const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) => {
|
|
@@ -455,15 +455,15 @@ const useUserOptions = (user, active = false) => {
|
|
|
455
455
|
if (!graphqlClient) return [];
|
|
456
456
|
return (active ? await graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : await graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() })).UserOption.map((option) => ({
|
|
457
457
|
...option,
|
|
458
|
-
|
|
458
|
+
optionId: BigInt(option.optionId),
|
|
459
459
|
marketAddr: option.marketAddr,
|
|
460
460
|
optionType: option.optionType,
|
|
461
461
|
createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
|
|
462
462
|
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
463
463
|
premiumPaid: BigInt(option.premiumPaid),
|
|
464
464
|
realizedPayout: BigInt(option.realizedPayout),
|
|
465
|
-
liquiditiesAtOpen: option.liquiditiesAtOpen.map((
|
|
466
|
-
liquiditiesCurrent: option.liquiditiesCurrent.map((
|
|
465
|
+
liquiditiesAtOpen: option.liquiditiesAtOpen.map((l) => BigInt(l)),
|
|
466
|
+
liquiditiesCurrent: option.liquiditiesCurrent.map((l) => BigInt(l)),
|
|
467
467
|
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
468
468
|
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
469
469
|
strikePrice: BigInt(option.strikePrice),
|
|
@@ -507,6 +507,75 @@ const useCurrentPrice = (poolAddr) => {
|
|
|
507
507
|
}), [currentPrice, currentTick]);
|
|
508
508
|
};
|
|
509
509
|
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/lib/price.ts
|
|
512
|
+
const resolutionToGeckoTerminal = (resolution) => {
|
|
513
|
+
return {
|
|
514
|
+
"1m": {
|
|
515
|
+
timeframe: "minute",
|
|
516
|
+
aggregate: "1",
|
|
517
|
+
seconds: 60
|
|
518
|
+
},
|
|
519
|
+
"5m": {
|
|
520
|
+
timeframe: "minute",
|
|
521
|
+
aggregate: "5",
|
|
522
|
+
seconds: 300
|
|
523
|
+
},
|
|
524
|
+
"15m": {
|
|
525
|
+
timeframe: "minute",
|
|
526
|
+
aggregate: "15",
|
|
527
|
+
seconds: 900
|
|
528
|
+
},
|
|
529
|
+
"1h": {
|
|
530
|
+
timeframe: "hour",
|
|
531
|
+
aggregate: "1",
|
|
532
|
+
seconds: 3600
|
|
533
|
+
},
|
|
534
|
+
"4h": {
|
|
535
|
+
timeframe: "hour",
|
|
536
|
+
aggregate: "4",
|
|
537
|
+
seconds: 14400
|
|
538
|
+
},
|
|
539
|
+
"1d": {
|
|
540
|
+
timeframe: "day",
|
|
541
|
+
aggregate: "1",
|
|
542
|
+
seconds: 86400
|
|
543
|
+
}
|
|
544
|
+
}[resolution];
|
|
545
|
+
};
|
|
546
|
+
const getPriceHistory = async (poolAddress, resolution, startTimestamp, endTimestamp) => {
|
|
547
|
+
const network = "monad-testnet";
|
|
548
|
+
const { timeframe, aggregate, seconds } = resolutionToGeckoTerminal(resolution);
|
|
549
|
+
const timeDiff = endTimestamp - startTimestamp;
|
|
550
|
+
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}`;
|
|
551
|
+
const res = await fetch(url, { headers: { Accept: "application/json" } });
|
|
552
|
+
if (!res.ok) throw new Error(`Failed to fetch price history: ${res.statusText}`);
|
|
553
|
+
return (await res.json()).data.attributes.ohlcv_list.map(({ 0: timestamp, 4: price }) => ({
|
|
554
|
+
timestamp,
|
|
555
|
+
price
|
|
556
|
+
})).filter((point) => point.timestamp >= startTimestamp && point.timestamp <= endTimestamp).sort((a, b) => a.timestamp - b.timestamp);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region src/hooks/pool/usePriceHistory.ts
|
|
561
|
+
const usePriceHistory = ({ poolAddress, resolution, startTimestamp, endTimestamp, enabled = true }) => {
|
|
562
|
+
return useQuery({
|
|
563
|
+
queryKey: [
|
|
564
|
+
"priceHistory",
|
|
565
|
+
poolAddress,
|
|
566
|
+
useChainId(),
|
|
567
|
+
resolution,
|
|
568
|
+
startTimestamp,
|
|
569
|
+
endTimestamp
|
|
570
|
+
],
|
|
571
|
+
queryFn: () => getPriceHistory(poolAddress, resolution, startTimestamp, endTimestamp),
|
|
572
|
+
enabled: enabled && !!poolAddress && startTimestamp < endTimestamp,
|
|
573
|
+
staleTime: 60 * 1e3,
|
|
574
|
+
gcTime: 300 * 1e3,
|
|
575
|
+
retry: 2
|
|
576
|
+
});
|
|
577
|
+
};
|
|
578
|
+
|
|
510
579
|
//#endregion
|
|
511
580
|
//#region src/hooks/vault/useVaultData.ts
|
|
512
581
|
const useVaultData = (vaultAddr) => {
|
|
@@ -760,5 +829,5 @@ const useVaultTVL = (vaultAddr) => {
|
|
|
760
829
|
};
|
|
761
830
|
|
|
762
831
|
//#endregion
|
|
763
|
-
export { TimelockMarketProvider, batchGetAmountsFromLiquidity, useActiveUserOptions, useBurnLiquidity, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useOptionPnl, useOptionPremium, usePoolData, usePriceAtTick, useTimelockConfig, useVaultData, useVaultTVL };
|
|
832
|
+
export { TimelockMarketProvider, batchGetAmountsFromLiquidity, useActiveUserOptions, useBurnLiquidity, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useOptionPnl, useOptionPremium, usePoolData, usePriceAtTick, usePriceHistory, useTimelockConfig, useVaultData, useVaultTVL };
|
|
764
833
|
//# sourceMappingURL=client.js.map
|