timelock-sdk 0.0.52 → 0.0.54
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/client.cjs +38 -16
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +59 -59
- package/dist/client.d.ts +59 -59
- package/dist/client.js +39 -17
- package/dist/client.js.map +1 -1
- package/dist/{index-D_lnxPOC.d.ts → index-BPKijlT_.d.cts} +2 -2
- package/dist/{index-HQTA4ETi.d.cts → index-Dt4gerGl.d.ts} +2 -2
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -186,10 +186,21 @@ const useTimelockConfig = () => {
|
|
|
186
186
|
return context;
|
|
187
187
|
};
|
|
188
188
|
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/hooks/useLens.ts
|
|
191
|
+
const useLens = () => {
|
|
192
|
+
const client = (0, wagmi.useClient)();
|
|
193
|
+
return (0, react.useMemo)(() => ({
|
|
194
|
+
timelockLens: client ? require_numberUtils.getTimelockLens(client) : void 0,
|
|
195
|
+
uniswapLens: client ? require_numberUtils.getUniswapMathLens(client) : void 0
|
|
196
|
+
}), [client]);
|
|
197
|
+
};
|
|
198
|
+
|
|
189
199
|
//#endregion
|
|
190
200
|
//#region src/hooks/market/useMarketData.ts
|
|
191
201
|
const useMarketData = (marketAddr) => {
|
|
192
202
|
const { graphqlClient } = useTimelockConfig();
|
|
203
|
+
const { timelockLens } = useLens();
|
|
193
204
|
const { data } = (0, __tanstack_react_query.useQuery)({
|
|
194
205
|
queryKey: ["marketData", marketAddr || "--"],
|
|
195
206
|
queryFn: async () => {
|
|
@@ -206,17 +217,18 @@ const useMarketData = (marketAddr) => {
|
|
|
206
217
|
},
|
|
207
218
|
enabled: !!marketAddr && !!graphqlClient
|
|
208
219
|
});
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
})
|
|
220
|
+
const { data: fallback } = (0, __tanstack_react_query.useQuery)({
|
|
221
|
+
queryKey: ["marketData", marketAddr || "--"],
|
|
222
|
+
queryFn: async () => {
|
|
223
|
+
if (!marketAddr || !timelockLens) return void 0;
|
|
224
|
+
return {
|
|
225
|
+
...await timelockLens.read.getMarketData([marketAddr]),
|
|
226
|
+
tradersCount: void 0
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
enabled: !!marketAddr && !!timelockLens
|
|
230
|
+
});
|
|
231
|
+
return data || fallback || {};
|
|
220
232
|
};
|
|
221
233
|
|
|
222
234
|
//#endregion
|
|
@@ -241,11 +253,17 @@ const useExerciseOption = (marketAddr) => {
|
|
|
241
253
|
const { vault, pool } = useMarketData(marketAddr);
|
|
242
254
|
const { fee } = usePoolData(pool);
|
|
243
255
|
const { timelockLens } = useLens();
|
|
256
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
244
257
|
const client = (0, wagmi.useClient)();
|
|
258
|
+
const { address } = (0, wagmi.useAccount)();
|
|
245
259
|
const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
|
|
246
260
|
const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
|
|
247
261
|
const exerciseOption = async (option, liquidities) => {
|
|
248
|
-
if (!client || !
|
|
262
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
263
|
+
if (!marketAddr) throw new Error("Market address not available");
|
|
264
|
+
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
265
|
+
if (!vault) throw new Error("Vault not available");
|
|
266
|
+
if (!fee) throw new Error("Pool data not available");
|
|
249
267
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
250
268
|
const hash$1 = await writeContractAsync({
|
|
251
269
|
address: marketAddr,
|
|
@@ -261,6 +279,7 @@ const useExerciseOption = (marketAddr) => {
|
|
|
261
279
|
]
|
|
262
280
|
});
|
|
263
281
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
|
|
282
|
+
await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
264
283
|
return hash$1;
|
|
265
284
|
};
|
|
266
285
|
return {
|
|
@@ -343,6 +362,7 @@ const useMintOption = (marketAddr) => {
|
|
|
343
362
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
344
363
|
const client = (0, wagmi.useClient)();
|
|
345
364
|
const { address } = (0, wagmi.useAccount)();
|
|
365
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
346
366
|
const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
|
|
347
367
|
const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
|
|
348
368
|
const askForApproval = async (premiumAmount) => {
|
|
@@ -356,7 +376,7 @@ const useMintOption = (marketAddr) => {
|
|
|
356
376
|
}) });
|
|
357
377
|
};
|
|
358
378
|
const mintOption = async (optionType, amount, duration, strikeTick) => {
|
|
359
|
-
if (!client) throw new Error("Wallet not connected");
|
|
379
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
360
380
|
if (!marketAddr) throw new Error("Market address not available");
|
|
361
381
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
362
382
|
if (!vault) throw new Error("Vault not available");
|
|
@@ -385,6 +405,7 @@ const useMintOption = (marketAddr) => {
|
|
|
385
405
|
]
|
|
386
406
|
});
|
|
387
407
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
|
|
408
|
+
await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
388
409
|
return hash$1;
|
|
389
410
|
};
|
|
390
411
|
return {
|
|
@@ -481,15 +502,16 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration, strike
|
|
|
481
502
|
//#region src/hooks/market/useUserOptions.ts
|
|
482
503
|
const useUserOptions = (user, active = false) => {
|
|
483
504
|
const { graphqlClient } = useTimelockConfig();
|
|
505
|
+
user = user === null || user === void 0 ? void 0 : user.toLowerCase();
|
|
484
506
|
const { data,...rest } = (0, __tanstack_react_query.useQuery)({
|
|
485
507
|
queryKey: [
|
|
486
|
-
"
|
|
508
|
+
"userOptions",
|
|
487
509
|
user || "--",
|
|
488
510
|
active
|
|
489
511
|
],
|
|
490
512
|
queryFn: async () => {
|
|
491
|
-
if (!graphqlClient) return [];
|
|
492
|
-
return (active ? await graphqlClient.GetActiveUserOptions({ user
|
|
513
|
+
if (!graphqlClient || !user) return [];
|
|
514
|
+
return (active ? await graphqlClient.GetActiveUserOptions({ user }) : await graphqlClient.GetClosedUserOptions({ user })).UserOption.map((option) => ({
|
|
493
515
|
...option,
|
|
494
516
|
optionId: BigInt(option.optionId),
|
|
495
517
|
marketAddr: option.marketAddr,
|