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/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");
|
|
@@ -27,6 +27,7 @@ const GetActiveUserOptionsDocument = graphql_tag.default`
|
|
|
27
27
|
limit: 1000
|
|
28
28
|
) {
|
|
29
29
|
id
|
|
30
|
+
optionId
|
|
30
31
|
ownerAddr
|
|
31
32
|
exerciseEvents {
|
|
32
33
|
transactionHash
|
|
@@ -37,6 +38,7 @@ const GetActiveUserOptionsDocument = graphql_tag.default`
|
|
|
37
38
|
optionType
|
|
38
39
|
strikeTick
|
|
39
40
|
entryTick
|
|
41
|
+
startTick
|
|
40
42
|
strikePrice
|
|
41
43
|
entryPrice
|
|
42
44
|
expiresAt
|
|
@@ -59,6 +61,7 @@ const GetClosedUserOptionsDocument = graphql_tag.default`
|
|
|
59
61
|
limit: 1000
|
|
60
62
|
) {
|
|
61
63
|
id
|
|
64
|
+
optionId
|
|
62
65
|
ownerAddr
|
|
63
66
|
exerciseEvents {
|
|
64
67
|
transactionHash
|
|
@@ -69,6 +72,7 @@ const GetClosedUserOptionsDocument = graphql_tag.default`
|
|
|
69
72
|
optionType
|
|
70
73
|
strikeTick
|
|
71
74
|
entryTick
|
|
75
|
+
startTick
|
|
72
76
|
strikePrice
|
|
73
77
|
entryPrice
|
|
74
78
|
expiresAt
|
|
@@ -203,30 +207,36 @@ const useMarketData = (marketAddr) => {
|
|
|
203
207
|
return data || {};
|
|
204
208
|
};
|
|
205
209
|
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/hooks/useLens.ts
|
|
212
|
+
const useLens = () => {
|
|
213
|
+
const client = (0, wagmi.useClient)();
|
|
214
|
+
return (0, react.useMemo)(() => ({
|
|
215
|
+
timelockLens: client ? require_numberUtils.getTimelockLens(client) : void 0,
|
|
216
|
+
uniswapLens: client ? require_numberUtils.getUniswapMathLens(client) : void 0
|
|
217
|
+
}), [client]);
|
|
218
|
+
};
|
|
219
|
+
|
|
206
220
|
//#endregion
|
|
207
221
|
//#region src/hooks/market/useExerciseOption.ts
|
|
208
222
|
const useExerciseOption = (marketAddr) => {
|
|
209
223
|
const { vault } = useMarketData(marketAddr);
|
|
224
|
+
const { timelockLens } = useLens();
|
|
210
225
|
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
226
|
const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
|
|
217
227
|
const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
|
|
218
|
-
const exerciseOption = async (
|
|
219
|
-
if (!client) throw new Error("Wallet not connected");
|
|
220
|
-
|
|
228
|
+
const exerciseOption = async (option, liquidities) => {
|
|
229
|
+
if (!client || !timelockLens || !vault || !marketAddr) throw new Error("Wallet not connected");
|
|
230
|
+
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
221
231
|
const hash$1 = await writeContractAsync({
|
|
222
232
|
address: marketAddr,
|
|
223
233
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
224
234
|
functionName: "exerciseOption",
|
|
225
235
|
args: [
|
|
226
|
-
optionId,
|
|
236
|
+
option.optionId,
|
|
227
237
|
liquidities,
|
|
228
238
|
0n,
|
|
229
|
-
|
|
239
|
+
refTick
|
|
230
240
|
]
|
|
231
241
|
});
|
|
232
242
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
|
|
@@ -243,16 +253,6 @@ const useExerciseOption = (marketAddr) => {
|
|
|
243
253
|
};
|
|
244
254
|
};
|
|
245
255
|
|
|
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
256
|
//#endregion
|
|
257
257
|
//#region src/hooks/market/useMaxPositionSize.ts
|
|
258
258
|
const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) => {
|
|
@@ -315,7 +315,7 @@ const useCurrentTick = (poolAddr) => {
|
|
|
315
315
|
const { tickSpacing } = usePoolData(poolAddr);
|
|
316
316
|
const { data } = (0, wagmi.useReadContract)({
|
|
317
317
|
address: poolAddr,
|
|
318
|
-
abi:
|
|
318
|
+
abi: require_singleOwnerVault.uniswapV3PoolAbi,
|
|
319
319
|
functionName: "slot0",
|
|
320
320
|
args: []
|
|
321
321
|
});
|
|
@@ -462,15 +462,15 @@ const useUserOptions = (user, active = false) => {
|
|
|
462
462
|
if (!graphqlClient) return [];
|
|
463
463
|
return (active ? await graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : await graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() })).UserOption.map((option) => ({
|
|
464
464
|
...option,
|
|
465
|
-
|
|
465
|
+
optionId: BigInt(option.optionId),
|
|
466
466
|
marketAddr: option.marketAddr,
|
|
467
467
|
optionType: option.optionType,
|
|
468
468
|
createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
|
|
469
469
|
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
470
470
|
premiumPaid: BigInt(option.premiumPaid),
|
|
471
471
|
realizedPayout: BigInt(option.realizedPayout),
|
|
472
|
-
liquiditiesAtOpen: option.liquiditiesAtOpen.map((
|
|
473
|
-
liquiditiesCurrent: option.liquiditiesCurrent.map((
|
|
472
|
+
liquiditiesAtOpen: option.liquiditiesAtOpen.map((l) => BigInt(l)),
|
|
473
|
+
liquiditiesCurrent: option.liquiditiesCurrent.map((l) => BigInt(l)),
|
|
474
474
|
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
475
475
|
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
476
476
|
strikePrice: BigInt(option.strikePrice),
|
|
@@ -514,12 +514,81 @@ const useCurrentPrice = (poolAddr) => {
|
|
|
514
514
|
}), [currentPrice, currentTick]);
|
|
515
515
|
};
|
|
516
516
|
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/lib/price.ts
|
|
519
|
+
const resolutionToGeckoTerminal = (resolution) => {
|
|
520
|
+
return {
|
|
521
|
+
"1m": {
|
|
522
|
+
timeframe: "minute",
|
|
523
|
+
aggregate: "1",
|
|
524
|
+
seconds: 60
|
|
525
|
+
},
|
|
526
|
+
"5m": {
|
|
527
|
+
timeframe: "minute",
|
|
528
|
+
aggregate: "5",
|
|
529
|
+
seconds: 300
|
|
530
|
+
},
|
|
531
|
+
"15m": {
|
|
532
|
+
timeframe: "minute",
|
|
533
|
+
aggregate: "15",
|
|
534
|
+
seconds: 900
|
|
535
|
+
},
|
|
536
|
+
"1h": {
|
|
537
|
+
timeframe: "hour",
|
|
538
|
+
aggregate: "1",
|
|
539
|
+
seconds: 3600
|
|
540
|
+
},
|
|
541
|
+
"4h": {
|
|
542
|
+
timeframe: "hour",
|
|
543
|
+
aggregate: "4",
|
|
544
|
+
seconds: 14400
|
|
545
|
+
},
|
|
546
|
+
"1d": {
|
|
547
|
+
timeframe: "day",
|
|
548
|
+
aggregate: "1",
|
|
549
|
+
seconds: 86400
|
|
550
|
+
}
|
|
551
|
+
}[resolution];
|
|
552
|
+
};
|
|
553
|
+
const getPriceHistory = async (poolAddress, resolution, startTimestamp, endTimestamp) => {
|
|
554
|
+
const network = "monad-testnet";
|
|
555
|
+
const { timeframe, aggregate, seconds } = resolutionToGeckoTerminal(resolution);
|
|
556
|
+
const timeDiff = endTimestamp - startTimestamp;
|
|
557
|
+
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}`;
|
|
558
|
+
const res = await fetch(url, { headers: { Accept: "application/json" } });
|
|
559
|
+
if (!res.ok) throw new Error(`Failed to fetch price history: ${res.statusText}`);
|
|
560
|
+
return (await res.json()).data.attributes.ohlcv_list.map(({ 0: timestamp, 4: price }) => ({
|
|
561
|
+
timestamp,
|
|
562
|
+
price
|
|
563
|
+
})).filter((point) => point.timestamp >= startTimestamp && point.timestamp <= endTimestamp).sort((a, b) => a.timestamp - b.timestamp);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/hooks/pool/usePriceHistory.ts
|
|
568
|
+
const usePriceHistory = ({ poolAddress, resolution, startTimestamp, endTimestamp, enabled = true }) => {
|
|
569
|
+
return (0, __tanstack_react_query.useQuery)({
|
|
570
|
+
queryKey: [
|
|
571
|
+
"priceHistory",
|
|
572
|
+
poolAddress,
|
|
573
|
+
(0, wagmi.useChainId)(),
|
|
574
|
+
resolution,
|
|
575
|
+
startTimestamp,
|
|
576
|
+
endTimestamp
|
|
577
|
+
],
|
|
578
|
+
queryFn: () => getPriceHistory(poolAddress, resolution, startTimestamp, endTimestamp),
|
|
579
|
+
enabled: enabled && !!poolAddress && startTimestamp < endTimestamp,
|
|
580
|
+
staleTime: 60 * 1e3,
|
|
581
|
+
gcTime: 300 * 1e3,
|
|
582
|
+
retry: 2
|
|
583
|
+
});
|
|
584
|
+
};
|
|
585
|
+
|
|
517
586
|
//#endregion
|
|
518
587
|
//#region src/hooks/vault/useVaultData.ts
|
|
519
588
|
const useVaultData = (vaultAddr) => {
|
|
520
589
|
const { data } = (0, wagmi.useReadContract)({
|
|
521
590
|
address: vaultAddr,
|
|
522
|
-
abi:
|
|
591
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
523
592
|
functionName: "pool"
|
|
524
593
|
});
|
|
525
594
|
return { pool: data };
|
|
@@ -539,7 +608,7 @@ const useBurnLiquidity = (vaultAddr) => {
|
|
|
539
608
|
if (!vaultAddr || !timelockLens) throw new Error("Vault/lens not available");
|
|
540
609
|
const hash$1 = await writeContractAsync({
|
|
541
610
|
address: vaultAddr,
|
|
542
|
-
abi:
|
|
611
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
543
612
|
functionName: "burn",
|
|
544
613
|
args: [
|
|
545
614
|
tickLower,
|
|
@@ -561,10 +630,10 @@ const useBurnLiquidity = (vaultAddr) => {
|
|
|
561
630
|
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
|
|
562
631
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
563
632
|
address: vaultAddr,
|
|
564
|
-
abi:
|
|
633
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
565
634
|
functionName: "multicall",
|
|
566
635
|
args: [positions.map((p, i) => (0, viem.encodeFunctionData)({
|
|
567
|
-
abi:
|
|
636
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
568
637
|
functionName: "burn",
|
|
569
638
|
args: [
|
|
570
639
|
p.tickLower,
|
|
@@ -679,7 +748,7 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
679
748
|
}]);
|
|
680
749
|
const hash$1 = await writeContractAsync({
|
|
681
750
|
address: vaultAddr,
|
|
682
|
-
abi:
|
|
751
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
683
752
|
functionName: "mint",
|
|
684
753
|
args: [
|
|
685
754
|
tickLower,
|
|
@@ -702,10 +771,10 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
702
771
|
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
|
|
703
772
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
704
773
|
address: vaultAddr,
|
|
705
|
-
abi:
|
|
774
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
706
775
|
functionName: "multicall",
|
|
707
776
|
args: [positions.map((p, i) => (0, viem.encodeFunctionData)({
|
|
708
|
-
abi:
|
|
777
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
709
778
|
functionName: "mint",
|
|
710
779
|
args: [
|
|
711
780
|
p.tickLower,
|
|
@@ -786,6 +855,7 @@ exports.useOptionPnl = useOptionPnl;
|
|
|
786
855
|
exports.useOptionPremium = useOptionPremium;
|
|
787
856
|
exports.usePoolData = usePoolData;
|
|
788
857
|
exports.usePriceAtTick = usePriceAtTick;
|
|
858
|
+
exports.usePriceHistory = usePriceHistory;
|
|
789
859
|
exports.useTimelockConfig = useTimelockConfig;
|
|
790
860
|
exports.useVaultData = useVaultData;
|
|
791
861
|
exports.useVaultTVL = useVaultTVL;
|