timelock-sdk 0.0.44 → 0.0.46

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 CHANGED
@@ -389,27 +389,37 @@ const useMintOption = (marketAddr) => {
389
389
 
390
390
  //#endregion
391
391
  //#region src/hooks/market/useOptionPnl.ts
392
- const useOptionPnl = (optionData) => {
393
- const { marketAddr, optionType, strikePrice, positionSizeCurrent } = optionData;
394
- const { pool, optionAssetIsToken0, payoutAssetDecimals } = useMarketData(marketAddr);
392
+ const useOptionPnl = (option) => {
393
+ const { marketAddr, optionType, strikePrice, positionSizeCurrent } = option;
394
+ const { pool, optionAssetIsToken0, payoutAssetDecimals, tickSpacing } = useMarketData(marketAddr);
395
395
  const { exact: currentTick } = useCurrentTick(pool);
396
- return (0, react.useMemo)(() => {
396
+ const strikeSize = positionSizeCurrent * strikePrice / require_numberUtils.PRICE_PRECISION;
397
+ const displayPnl = (0, react.useMemo)(() => {
397
398
  if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !positionSizeCurrent || !payoutAssetDecimals) return {};
398
- const strikeSize = positionSizeCurrent * strikePrice / require_numberUtils.PRICE_PRECISION;
399
399
  const delta = (optionAssetIsToken0 ? require_numberUtils.token0ToToken1(positionSizeCurrent, currentTick) : require_numberUtils.token1ToToken0(positionSizeCurrent, currentTick)) - strikeSize;
400
- const displayPnl = require_numberUtils.wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
401
- return {
402
- unrealizedPayout: require_numberUtils.wrapAmount(displayPnl.scaled < 0 ? 0n : displayPnl.scaled, payoutAssetDecimals),
403
- displayPnl
404
- };
400
+ return require_numberUtils.wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
405
401
  }, [
406
- strikePrice,
407
402
  optionType,
408
403
  optionAssetIsToken0,
409
404
  currentTick,
410
405
  positionSizeCurrent,
411
406
  payoutAssetDecimals
412
407
  ]);
408
+ return {
409
+ unrealizedPayout: (0, react.useMemo)(() => {
410
+ if (!payoutAssetDecimals || !currentTick || !tickSpacing) return {};
411
+ const [amount0, amount1] = require_numberUtils.liquiditiesToAmounts(option.liquiditiesCurrent, option.startTick, currentTick, tickSpacing);
412
+ const delta = (optionAssetIsToken0 ? amount1 + require_numberUtils.token0ToToken1(amount0, currentTick) : amount0 + require_numberUtils.token1ToToken0(amount1, currentTick)) - strikeSize;
413
+ const pnl = optionType === "CALL" ? delta : -delta;
414
+ return require_numberUtils.wrapAmount(pnl < 0 ? 0n : pnl, payoutAssetDecimals);
415
+ }, [
416
+ currentTick,
417
+ tickSpacing,
418
+ optionType,
419
+ payoutAssetDecimals
420
+ ]),
421
+ displayPnl
422
+ };
413
423
  };
414
424
 
415
425
  //#endregion
@@ -691,8 +701,8 @@ const useLiquidityBlocks = (vaultAddr) => {
691
701
  address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
692
702
  abi: require_optionsMarket.lensAbi,
693
703
  functionName: "getAllBlocks",
694
- args: [vaultAddr],
695
- query: { enabled: !!vaultAddr && !!timelockLens }
704
+ args: [vaultAddr || viem.zeroAddress],
705
+ query: { enabled: !!vaultAddr }
696
706
  });
697
707
  return {
698
708
  data: blocks,