timelock-sdk 0.0.34 → 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 +99 -31
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +203 -123
- package/dist/client.d.ts +147 -67
- package/dist/client.js +91 -24
- package/dist/client.js.map +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
|
});
|
|
@@ -469,8 +467,8 @@ const useUserOptions = (user, active = false) => {
|
|
|
469
467
|
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
470
468
|
premiumPaid: BigInt(option.premiumPaid),
|
|
471
469
|
realizedPayout: BigInt(option.realizedPayout),
|
|
472
|
-
liquiditiesAtOpen: option.liquiditiesAtOpen.map((
|
|
473
|
-
liquiditiesCurrent: option.liquiditiesCurrent.map((
|
|
470
|
+
liquiditiesAtOpen: option.liquiditiesAtOpen.map((l) => BigInt(l)),
|
|
471
|
+
liquiditiesCurrent: option.liquiditiesCurrent.map((l) => BigInt(l)),
|
|
474
472
|
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
475
473
|
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
476
474
|
strikePrice: BigInt(option.strikePrice),
|
|
@@ -514,12 +512,81 @@ const useCurrentPrice = (poolAddr) => {
|
|
|
514
512
|
}), [currentPrice, currentTick]);
|
|
515
513
|
};
|
|
516
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
|
+
|
|
517
584
|
//#endregion
|
|
518
585
|
//#region src/hooks/vault/useVaultData.ts
|
|
519
586
|
const useVaultData = (vaultAddr) => {
|
|
520
587
|
const { data } = (0, wagmi.useReadContract)({
|
|
521
588
|
address: vaultAddr,
|
|
522
|
-
abi:
|
|
589
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
523
590
|
functionName: "pool"
|
|
524
591
|
});
|
|
525
592
|
return { pool: data };
|
|
@@ -539,7 +606,7 @@ const useBurnLiquidity = (vaultAddr) => {
|
|
|
539
606
|
if (!vaultAddr || !timelockLens) throw new Error("Vault/lens not available");
|
|
540
607
|
const hash$1 = await writeContractAsync({
|
|
541
608
|
address: vaultAddr,
|
|
542
|
-
abi:
|
|
609
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
543
610
|
functionName: "burn",
|
|
544
611
|
args: [
|
|
545
612
|
tickLower,
|
|
@@ -561,10 +628,10 @@ const useBurnLiquidity = (vaultAddr) => {
|
|
|
561
628
|
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
|
|
562
629
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
563
630
|
address: vaultAddr,
|
|
564
|
-
abi:
|
|
631
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
565
632
|
functionName: "multicall",
|
|
566
633
|
args: [positions.map((p, i) => (0, viem.encodeFunctionData)({
|
|
567
|
-
abi:
|
|
634
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
568
635
|
functionName: "burn",
|
|
569
636
|
args: [
|
|
570
637
|
p.tickLower,
|
|
@@ -679,7 +746,7 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
679
746
|
}]);
|
|
680
747
|
const hash$1 = await writeContractAsync({
|
|
681
748
|
address: vaultAddr,
|
|
682
|
-
abi:
|
|
749
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
683
750
|
functionName: "mint",
|
|
684
751
|
args: [
|
|
685
752
|
tickLower,
|
|
@@ -702,10 +769,10 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
702
769
|
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
|
|
703
770
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
704
771
|
address: vaultAddr,
|
|
705
|
-
abi:
|
|
772
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
706
773
|
functionName: "multicall",
|
|
707
774
|
args: [positions.map((p, i) => (0, viem.encodeFunctionData)({
|
|
708
|
-
abi:
|
|
775
|
+
abi: require_singleOwnerVault.singleOwnerVaultAbi,
|
|
709
776
|
functionName: "mint",
|
|
710
777
|
args: [
|
|
711
778
|
p.tickLower,
|
|
@@ -786,6 +853,7 @@ exports.useOptionPnl = useOptionPnl;
|
|
|
786
853
|
exports.useOptionPremium = useOptionPremium;
|
|
787
854
|
exports.usePoolData = usePoolData;
|
|
788
855
|
exports.usePriceAtTick = usePriceAtTick;
|
|
856
|
+
exports.usePriceHistory = usePriceHistory;
|
|
789
857
|
exports.useTimelockConfig = useTimelockConfig;
|
|
790
858
|
exports.useVaultData = useVaultData;
|
|
791
859
|
exports.useVaultTVL = useVaultTVL;
|