timelock-sdk 0.0.49 → 0.0.50
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 +27 -21
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +55 -55
- package/dist/client.d.ts +56 -56
- package/dist/client.js +28 -22
- package/dist/client.js.map +1 -1
- package/dist/{index-DiDvh-kv.d.ts → index-DFXuUhcW.d.ts} +92 -92
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -217,16 +217,33 @@ const useLens = () => {
|
|
|
217
217
|
}), [client]);
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/hooks/pool/usePoolData.ts
|
|
222
|
+
const usePoolData = (poolAddr) => {
|
|
223
|
+
const { timelockLens } = useLens();
|
|
224
|
+
const client = (0, wagmi.useClient)();
|
|
225
|
+
const { data } = (0, wagmi.useReadContract)({
|
|
226
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
227
|
+
abi: require_optionsMarket.lensAbi,
|
|
228
|
+
functionName: "getPoolData",
|
|
229
|
+
args: poolAddr ? [poolAddr] : void 0,
|
|
230
|
+
query: { enabled: !!poolAddr && !!client }
|
|
231
|
+
});
|
|
232
|
+
return data || {};
|
|
233
|
+
};
|
|
234
|
+
|
|
220
235
|
//#endregion
|
|
221
236
|
//#region src/hooks/market/useExerciseOption.ts
|
|
237
|
+
const swapper = "0xc396aa907F8De0c32460050B8Adbf047186C504d";
|
|
222
238
|
const useExerciseOption = (marketAddr) => {
|
|
223
|
-
const { vault } = useMarketData(marketAddr);
|
|
239
|
+
const { vault, pool } = useMarketData(marketAddr);
|
|
240
|
+
const { fee } = usePoolData(pool);
|
|
224
241
|
const { timelockLens } = useLens();
|
|
225
242
|
const client = (0, wagmi.useClient)();
|
|
226
243
|
const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
|
|
227
244
|
const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
|
|
228
245
|
const exerciseOption = async (option, liquidities) => {
|
|
229
|
-
if (!client || !timelockLens || !vault || !marketAddr) throw new Error("Wallet not connected");
|
|
246
|
+
if (!client || !timelockLens || !vault || !marketAddr || !fee) throw new Error("Wallet not connected");
|
|
230
247
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
231
248
|
const hash$1 = await writeContractAsync({
|
|
232
249
|
address: marketAddr,
|
|
@@ -236,6 +253,8 @@ const useExerciseOption = (marketAddr) => {
|
|
|
236
253
|
option.optionId,
|
|
237
254
|
liquidities,
|
|
238
255
|
0n,
|
|
256
|
+
swapper,
|
|
257
|
+
(0, viem.encodeAbiParameters)([{ type: "uint24" }], [fee]),
|
|
239
258
|
refTick
|
|
240
259
|
]
|
|
241
260
|
});
|
|
@@ -294,21 +313,6 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) =>
|
|
|
294
313
|
};
|
|
295
314
|
};
|
|
296
315
|
|
|
297
|
-
//#endregion
|
|
298
|
-
//#region src/hooks/pool/usePoolData.ts
|
|
299
|
-
const usePoolData = (poolAddr) => {
|
|
300
|
-
const { timelockLens } = useLens();
|
|
301
|
-
const client = (0, wagmi.useClient)();
|
|
302
|
-
const { data } = (0, wagmi.useReadContract)({
|
|
303
|
-
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
304
|
-
abi: require_optionsMarket.lensAbi,
|
|
305
|
-
functionName: "getPoolData",
|
|
306
|
-
args: poolAddr ? [poolAddr] : void 0,
|
|
307
|
-
query: { enabled: !!poolAddr && !!client }
|
|
308
|
-
});
|
|
309
|
-
return data || {};
|
|
310
|
-
};
|
|
311
|
-
|
|
312
316
|
//#endregion
|
|
313
317
|
//#region src/hooks/pool/useCurrentTick.ts
|
|
314
318
|
const useCurrentTick = (poolAddr) => {
|
|
@@ -354,12 +358,13 @@ const useMintOption = (marketAddr) => {
|
|
|
354
358
|
if (!timelockLens || !vault || !marketAddr || !currentTick || !tickSpacing) throw new Error("Lowest tick lower not available");
|
|
355
359
|
strikeTick = require_numberUtils.roundTickDown(strikeTick ?? currentTick, tickSpacing);
|
|
356
360
|
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTick += tickSpacing;
|
|
357
|
-
|
|
361
|
+
const [premium, protocolFee] = await require_numberUtils.getTimelockMarket(marketAddr, client).read.calculatePremium([
|
|
358
362
|
optionType === "CALL" ? 0 : 1,
|
|
359
363
|
amount,
|
|
360
364
|
strikeTick,
|
|
361
|
-
|
|
362
|
-
])
|
|
365
|
+
duration
|
|
366
|
+
]);
|
|
367
|
+
await askForApproval(premium + protocolFee);
|
|
363
368
|
const hash$1 = await writeContractAsync({
|
|
364
369
|
address: marketAddr,
|
|
365
370
|
abi: require_optionsMarket.optionsMarketAbi,
|
|
@@ -368,8 +373,9 @@ const useMintOption = (marketAddr) => {
|
|
|
368
373
|
optionType === "CALL" ? 0 : 1,
|
|
369
374
|
amount,
|
|
370
375
|
strikeTick,
|
|
371
|
-
|
|
376
|
+
duration,
|
|
372
377
|
BigInt(1e69),
|
|
378
|
+
false,
|
|
373
379
|
await timelockLens.read.getRefTick([vault, strikeTick])
|
|
374
380
|
]
|
|
375
381
|
});
|