timelock-sdk 0.0.53 → 0.0.55
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 +1 -1
- package/dist/abis.d.cts +1 -1
- package/dist/abis.d.ts +1 -1
- package/dist/abis.js +1 -1
- package/dist/client.cjs +20 -9
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +61 -61
- package/dist/client.d.ts +116 -116
- package/dist/client.js +21 -10
- package/dist/client.js.map +1 -1
- package/dist/{index-Dt4gerGl.d.ts → index-C2ZV26z-.d.cts} +2 -2
- package/dist/{index-HQTA4ETi.d.cts → index-D5xWncVD.d.ts} +93 -93
- package/dist/{numberUtils-Cznv1Tfa.js → numberUtils-BHnUMxbB.js} +2 -2
- package/dist/{numberUtils-Cznv1Tfa.js.map → numberUtils-BHnUMxbB.js.map} +1 -1
- package/dist/{numberUtils-CkwkoxOr.cjs → numberUtils-DUFFdMYG.cjs} +2 -2
- package/dist/{numberUtils-CkwkoxOr.cjs.map → numberUtils-DUFFdMYG.cjs.map} +1 -1
- package/dist/{optionsMarket-BDBU1gUS.js → optionsMarket-gAjmVL6j.js} +8 -3
- package/dist/{optionsMarket-BDBU1gUS.js.map → optionsMarket-gAjmVL6j.js.map} +1 -1
- package/dist/{optionsMarket-DEFMUI2G.cjs → optionsMarket-k4C_Yx7a.cjs} +8 -3
- package/dist/{optionsMarket-DEFMUI2G.cjs.map → optionsMarket-k4C_Yx7a.cjs.map} +1 -1
- package/dist/package.cjs +2 -2
- package/dist/package.d.cts +2 -2
- package/dist/package.d.ts +2 -2
- package/dist/package.js +2 -2
- package/dist/{uniswapMathLens-DCuaXAGZ.d.ts → uniswapMathLens-BCl11EO1.d.ts} +7 -3
- package/dist/{uniswapMathLens-BQ_ArpKd.d.cts → uniswapMathLens-CGKa7m43.d.cts} +7 -3
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-
|
|
5
|
-
import { C as token1ToToken0, D as getUniswapMathLens, E as getTimelockMarket, O as timelockLenses, S as token0ToToken1, T as getTimelockLens, b as roundTickDown, d as wrapPrice, h as getPriceAtTick, k as uniswapMathLenses, l as wrapAmount, m as PRICE_PRECISION, w as getErc20, y as liquiditiesToAmounts } from "./numberUtils-
|
|
4
|
+
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-gAjmVL6j.js";
|
|
5
|
+
import { C as token1ToToken0, D as getUniswapMathLens, E as getTimelockMarket, O as timelockLenses, S as token0ToToken1, T as getTimelockLens, b as roundTickDown, d as wrapPrice, h as getPriceAtTick, k as uniswapMathLenses, l as wrapAmount, m as PRICE_PRECISION, w as getErc20, y as liquiditiesToAmounts } from "./numberUtils-BHnUMxbB.js";
|
|
6
6
|
import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
|
|
7
7
|
import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
|
|
8
8
|
import React, { createContext, useContext, useMemo } from "react";
|
|
@@ -10,7 +10,7 @@ import { useAccount, useChainId, useClient, useReadContract, useWaitForTransacti
|
|
|
10
10
|
import { GraphQLClient, RequestOptions } from "graphql-request";
|
|
11
11
|
import gql from "graphql-tag";
|
|
12
12
|
import { waitForTransactionReceipt } from "viem/actions";
|
|
13
|
-
import { useQuery } from "@tanstack/react-query";
|
|
13
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
14
14
|
|
|
15
15
|
//#region src/generated/graphql.ts
|
|
16
16
|
const GetActiveUserOptionsDocument = gql`
|
|
@@ -246,11 +246,17 @@ const useExerciseOption = (marketAddr) => {
|
|
|
246
246
|
const { vault, pool } = useMarketData(marketAddr);
|
|
247
247
|
const { fee } = usePoolData(pool);
|
|
248
248
|
const { timelockLens } = useLens();
|
|
249
|
+
const queryClient = useQueryClient();
|
|
249
250
|
const client = useClient();
|
|
251
|
+
const { address } = useAccount();
|
|
250
252
|
const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
|
|
251
253
|
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
|
|
252
254
|
const exerciseOption = async (option, liquidities) => {
|
|
253
|
-
if (!client || !
|
|
255
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
256
|
+
if (!marketAddr) throw new Error("Market address not available");
|
|
257
|
+
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
258
|
+
if (!vault) throw new Error("Vault not available");
|
|
259
|
+
if (!fee) throw new Error("Pool data not available");
|
|
254
260
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
255
261
|
const hash$1 = await writeContractAsync({
|
|
256
262
|
address: marketAddr,
|
|
@@ -266,6 +272,7 @@ const useExerciseOption = (marketAddr) => {
|
|
|
266
272
|
]
|
|
267
273
|
});
|
|
268
274
|
await waitForTransactionReceipt(client, { hash: hash$1 });
|
|
275
|
+
await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
269
276
|
return hash$1;
|
|
270
277
|
};
|
|
271
278
|
return {
|
|
@@ -348,6 +355,7 @@ const useMintOption = (marketAddr) => {
|
|
|
348
355
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
349
356
|
const client = useClient();
|
|
350
357
|
const { address } = useAccount();
|
|
358
|
+
const queryClient = useQueryClient();
|
|
351
359
|
const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
|
|
352
360
|
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
|
|
353
361
|
const askForApproval = async (premiumAmount) => {
|
|
@@ -361,7 +369,7 @@ const useMintOption = (marketAddr) => {
|
|
|
361
369
|
}) });
|
|
362
370
|
};
|
|
363
371
|
const mintOption = async (optionType, amount, duration, strikeTick) => {
|
|
364
|
-
if (!client) throw new Error("Wallet not connected");
|
|
372
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
365
373
|
if (!marketAddr) throw new Error("Market address not available");
|
|
366
374
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
367
375
|
if (!vault) throw new Error("Vault not available");
|
|
@@ -390,6 +398,7 @@ const useMintOption = (marketAddr) => {
|
|
|
390
398
|
]
|
|
391
399
|
});
|
|
392
400
|
await waitForTransactionReceipt(client, { hash: hash$1 });
|
|
401
|
+
await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
393
402
|
return hash$1;
|
|
394
403
|
};
|
|
395
404
|
return {
|
|
@@ -440,7 +449,7 @@ const useOptionPnl = (option) => {
|
|
|
440
449
|
|
|
441
450
|
//#endregion
|
|
442
451
|
//#region src/hooks/market/useOptionPremium.ts
|
|
443
|
-
const useOptionPremium = (marketAddr, optionType, optionAmount,
|
|
452
|
+
const useOptionPremium = (marketAddr, optionType, optionAmount, addedDuration, remainingDuration = 0, strikeTick) => {
|
|
444
453
|
const { pool, payoutAssetDecimals, optionAssetIsToken0 } = useMarketData(marketAddr);
|
|
445
454
|
const { tickSpacing } = usePoolData(pool);
|
|
446
455
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
@@ -464,7 +473,8 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration, strike
|
|
|
464
473
|
optionType === "CALL" ? 0 : 1,
|
|
465
474
|
optionAmount,
|
|
466
475
|
strikeTickRounded,
|
|
467
|
-
|
|
476
|
+
addedDuration,
|
|
477
|
+
remainingDuration
|
|
468
478
|
] : void 0,
|
|
469
479
|
query: { enabled: strikeTickRounded !== void 0 }
|
|
470
480
|
});
|
|
@@ -486,15 +496,16 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration, strike
|
|
|
486
496
|
//#region src/hooks/market/useUserOptions.ts
|
|
487
497
|
const useUserOptions = (user, active = false) => {
|
|
488
498
|
const { graphqlClient } = useTimelockConfig();
|
|
499
|
+
user = user === null || user === void 0 ? void 0 : user.toLowerCase();
|
|
489
500
|
const { data,...rest } = useQuery({
|
|
490
501
|
queryKey: [
|
|
491
|
-
"
|
|
502
|
+
"userOptions",
|
|
492
503
|
user || "--",
|
|
493
504
|
active
|
|
494
505
|
],
|
|
495
506
|
queryFn: async () => {
|
|
496
|
-
if (!graphqlClient) return [];
|
|
497
|
-
return (active ? await graphqlClient.GetActiveUserOptions({ user
|
|
507
|
+
if (!graphqlClient || !user) return [];
|
|
508
|
+
return (active ? await graphqlClient.GetActiveUserOptions({ user }) : await graphqlClient.GetClosedUserOptions({ user })).UserOption.map((option) => ({
|
|
498
509
|
...option,
|
|
499
510
|
optionId: BigInt(option.optionId),
|
|
500
511
|
marketAddr: option.marketAddr,
|