timelock-sdk 0.0.49 → 0.0.51

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.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
 
3
3
 
4
- import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-CvArD6d_.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-Dk0TuHnT.js";
4
+ import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-BDBU1gUS.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-Cznv1Tfa.js";
6
6
  import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
7
- import { encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
7
+ import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
8
8
  import React, { createContext, useContext, useMemo } from "react";
9
9
  import { useAccount, useChainId, useClient, useReadContract, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
10
10
  import { GraphQLClient, RequestOptions } from "graphql-request";
@@ -210,16 +210,33 @@ const useLens = () => {
210
210
  }), [client]);
211
211
  };
212
212
 
213
+ //#endregion
214
+ //#region src/hooks/pool/usePoolData.ts
215
+ const usePoolData = (poolAddr) => {
216
+ const { timelockLens } = useLens();
217
+ const client = useClient();
218
+ const { data } = useReadContract({
219
+ address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
220
+ abi: lensAbi,
221
+ functionName: "getPoolData",
222
+ args: poolAddr ? [poolAddr] : void 0,
223
+ query: { enabled: !!poolAddr && !!client }
224
+ });
225
+ return data || {};
226
+ };
227
+
213
228
  //#endregion
214
229
  //#region src/hooks/market/useExerciseOption.ts
230
+ const swapper = "0xc396aa907F8De0c32460050B8Adbf047186C504d";
215
231
  const useExerciseOption = (marketAddr) => {
216
- const { vault } = useMarketData(marketAddr);
232
+ const { vault, pool } = useMarketData(marketAddr);
233
+ const { fee } = usePoolData(pool);
217
234
  const { timelockLens } = useLens();
218
235
  const client = useClient();
219
236
  const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
220
237
  const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
221
238
  const exerciseOption = async (option, liquidities) => {
222
- if (!client || !timelockLens || !vault || !marketAddr) throw new Error("Wallet not connected");
239
+ if (!client || !timelockLens || !vault || !marketAddr || !fee) throw new Error("Wallet not connected");
223
240
  const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
224
241
  const hash$1 = await writeContractAsync({
225
242
  address: marketAddr,
@@ -229,6 +246,8 @@ const useExerciseOption = (marketAddr) => {
229
246
  option.optionId,
230
247
  liquidities,
231
248
  0n,
249
+ swapper,
250
+ encodeAbiParameters([{ type: "uint24" }], [fee]),
232
251
  refTick
233
252
  ]
234
253
  });
@@ -287,21 +306,6 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) =>
287
306
  };
288
307
  };
289
308
 
290
- //#endregion
291
- //#region src/hooks/pool/usePoolData.ts
292
- const usePoolData = (poolAddr) => {
293
- const { timelockLens } = useLens();
294
- const client = useClient();
295
- const { data } = useReadContract({
296
- address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
297
- abi: lensAbi,
298
- functionName: "getPoolData",
299
- args: poolAddr ? [poolAddr] : void 0,
300
- query: { enabled: !!poolAddr && !!client }
301
- });
302
- return data || {};
303
- };
304
-
305
309
  //#endregion
306
310
  //#region src/hooks/pool/useCurrentTick.ts
307
311
  const useCurrentTick = (poolAddr) => {
@@ -344,15 +348,19 @@ const useMintOption = (marketAddr) => {
344
348
  };
345
349
  const mintOption = async (optionType, amount, duration, strikeTick) => {
346
350
  if (!client) throw new Error("Wallet not connected");
347
- if (!timelockLens || !vault || !marketAddr || !currentTick || !tickSpacing) throw new Error("Lowest tick lower not available");
351
+ if (!marketAddr) throw new Error("Market address not available");
352
+ if (!timelockLens) throw new Error("Timelock lens not available");
353
+ if (!vault) throw new Error("Vault not available");
354
+ if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
348
355
  strikeTick = roundTickDown(strikeTick ?? currentTick, tickSpacing);
349
356
  if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTick += tickSpacing;
350
- await askForApproval(await getTimelockMarket(marketAddr, client).read.calculatePremium([
357
+ const [premium, protocolFee] = await getTimelockMarket(marketAddr, client).read.calculatePremium([
351
358
  optionType === "CALL" ? 0 : 1,
352
359
  amount,
353
360
  strikeTick,
354
- BigInt(duration)
355
- ]));
361
+ duration
362
+ ]);
363
+ await askForApproval(premium + protocolFee);
356
364
  const hash$1 = await writeContractAsync({
357
365
  address: marketAddr,
358
366
  abi: optionsMarketAbi,
@@ -361,8 +369,9 @@ const useMintOption = (marketAddr) => {
361
369
  optionType === "CALL" ? 0 : 1,
362
370
  amount,
363
371
  strikeTick,
364
- BigInt(duration),
372
+ duration,
365
373
  BigInt(1e69),
374
+ false,
366
375
  await timelockLens.read.getRefTick([vault, strikeTick])
367
376
  ]
368
377
  });