timelock-sdk 0.0.23 → 0.0.25

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
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  import { lensAbi, optionsMarketAbi } from "./optionsMarket-DyBxHplR.js";
5
- import { getErc20, getPriceAtTick, getTimelockLens, getTimelockMarket, getUniswapMathLens, roundTickDown, timelockLenses, token0ToToken1, token1ToToken0, uniswapMathLenses, wrapAmount, wrapPrice } from "./numberUtils-CAMznXR5.js";
5
+ import { PRICE_PRECISION, getErc20, getPriceAtTick, getTimelockLens, getTimelockMarket, getUniswapMathLens, roundTickDown, timelockLenses, token0ToToken1, token1ToToken0, uniswapMathLenses, wrapAmount, wrapPrice } from "./numberUtils-CAMznXR5.js";
6
6
  import { singleOwnerVaultAbi, uniswapV3PoolAbi } from "./uniswapV3Pool-Copswrde.js";
7
7
  import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
8
8
  import React, { createContext, useContext, useMemo } from "react";
@@ -235,11 +235,10 @@ const useExerciseOption = (marketAddr) => {
235
235
  //#region src/hooks/useLens.ts
236
236
  const useLens = () => {
237
237
  const client = useClient();
238
- const timelockLens = useMemo(() => client ? getTimelockLens(client) : void 0, [client]);
239
- return {
240
- uniswapLens: useMemo(() => client ? getUniswapMathLens(client) : void 0, [client]),
241
- timelockLens
242
- };
238
+ return useMemo(() => ({
239
+ timelockLens: client ? getTimelockLens(client) : void 0,
240
+ uniswapLens: client ? getUniswapMathLens(client) : void 0
241
+ }), [client]);
243
242
  };
244
243
 
245
244
  //#endregion
@@ -308,11 +307,13 @@ const useCurrentTick = (poolAddr) => {
308
307
  functionName: "slot0",
309
308
  args: []
310
309
  });
311
- const exact = data === null || data === void 0 ? void 0 : data[1];
312
- return {
313
- exact,
314
- rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0
315
- };
310
+ return useMemo(() => {
311
+ const exact = data === null || data === void 0 ? void 0 : data[1];
312
+ return {
313
+ exact,
314
+ rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0
315
+ };
316
+ }, [data, tickSpacing]);
316
317
  };
317
318
 
318
319
  //#endregion
@@ -377,37 +378,26 @@ const useMintOption = (marketAddr) => {
377
378
  //#endregion
378
379
  //#region src/hooks/market/useOptionPnl.ts
379
380
  const useOptionPnl = (optionData) => {
380
- const { marketAddr, optionType, entryTick, positionSizeCurrent } = optionData;
381
+ const { marketAddr, optionType, entryPrice, positionSizeCurrent } = optionData;
381
382
  const { pool, optionAssetIsToken0, payoutAssetDecimals } = useMarketData(marketAddr);
382
383
  const { exact: currentTick } = useCurrentTick(pool);
383
- const entrySize = useMemo(() => {
384
- if (optionAssetIsToken0 === void 0) return;
385
- return optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, entryTick) : token1ToToken0(positionSizeCurrent, entryTick);
386
- }, [
387
- optionAssetIsToken0,
388
- positionSizeCurrent,
389
- entryTick
390
- ]);
391
- const { displayPnl, unrealizedPayout } = useMemo(() => {
392
- if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !positionSizeCurrent || !payoutAssetDecimals || !entrySize) return {};
384
+ return useMemo(() => {
385
+ if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !positionSizeCurrent || !payoutAssetDecimals) return {};
386
+ const entrySize = positionSizeCurrent * entryPrice / PRICE_PRECISION;
393
387
  const delta = (optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, currentTick) : token1ToToken0(positionSizeCurrent, currentTick)) - entrySize;
394
- const displayPnl$1 = wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
388
+ const displayPnl = wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
395
389
  return {
396
- unrealizedPayout: wrapAmount(displayPnl$1.scaled < 0 ? 0n : displayPnl$1.scaled, payoutAssetDecimals),
397
- displayPnl: displayPnl$1
390
+ unrealizedPayout: wrapAmount(displayPnl.scaled < 0 ? 0n : displayPnl.scaled, payoutAssetDecimals),
391
+ displayPnl
398
392
  };
399
393
  }, [
400
- entrySize,
394
+ entryPrice,
401
395
  optionType,
402
396
  optionAssetIsToken0,
403
397
  currentTick,
404
398
  positionSizeCurrent,
405
399
  payoutAssetDecimals
406
400
  ]);
407
- return {
408
- displayPnl,
409
- unrealizedPayout
410
- };
411
401
  };
412
402
 
413
403
  //#endregion
@@ -502,10 +492,11 @@ const usePriceAtTick = (tick, poolAddr) => {
502
492
  //#region src/hooks/pool/useCurrentPrice.ts
503
493
  const useCurrentPrice = (poolAddr) => {
504
494
  const currentTick = useCurrentTick(poolAddr);
505
- return {
506
- currentPrice: usePriceAtTick(currentTick.exact, poolAddr),
495
+ const currentPrice = usePriceAtTick(currentTick.exact, poolAddr);
496
+ return useMemo(() => ({
497
+ currentPrice,
507
498
  currentTick
508
- };
499
+ }), [currentPrice, currentTick]);
509
500
  };
510
501
 
511
502
  //#endregion
@@ -736,20 +727,28 @@ const useVaultTVL = (vaultAddr) => {
736
727
  args: [vaultAddr],
737
728
  query: { enabled: !!vaultAddr && !!timelockLens }
738
729
  });
739
- const totalAmount0 = data && token0Decimals ? wrapAmount(data[0], token0Decimals) : void 0;
740
- const totalAmount1 = data && token1Decimals ? wrapAmount(data[1], token1Decimals) : void 0;
741
- const borrowedAmount0 = data && token0Decimals ? wrapAmount(data[2], token0Decimals) : void 0;
742
- const borrowedAmount1 = data && token1Decimals ? wrapAmount(data[3], token1Decimals) : void 0;
743
- return {
744
- tvl0: data && token0Decimals ? wrapAmount(data[4], token0Decimals) : void 0,
745
- tvl1: data && token1Decimals ? wrapAmount(data[5], token1Decimals) : void 0,
746
- totalAmount0,
747
- totalAmount1,
748
- borrowedAmount0,
749
- borrowedAmount1,
750
- blocksCount: data === null || data === void 0 ? void 0 : data[6],
730
+ return useMemo(() => {
731
+ if (!token0Decimals || !token1Decimals || !data) return {};
732
+ const totalAmount0 = wrapAmount(data[0], token0Decimals);
733
+ const totalAmount1 = wrapAmount(data[1], token1Decimals);
734
+ const borrowedAmount0 = wrapAmount(data[2], token0Decimals);
735
+ const borrowedAmount1 = wrapAmount(data[3], token1Decimals);
736
+ return {
737
+ tvl0: wrapAmount(data[4], token0Decimals),
738
+ tvl1: wrapAmount(data[5], token1Decimals),
739
+ totalAmount0,
740
+ totalAmount1,
741
+ borrowedAmount0,
742
+ borrowedAmount1,
743
+ blocksCount: data[6],
744
+ refetch
745
+ };
746
+ }, [
747
+ data,
748
+ token0Decimals,
749
+ token1Decimals,
751
750
  refetch
752
- };
751
+ ]);
753
752
  };
754
753
 
755
754
  //#endregion