timelock-sdk 0.0.36 → 0.0.38

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
@@ -390,12 +390,12 @@ const useMintOption = (marketAddr) => {
390
390
  //#endregion
391
391
  //#region src/hooks/market/useOptionPnl.ts
392
392
  const useOptionPnl = (optionData) => {
393
- const { marketAddr, optionType, entryPrice, positionSizeCurrent } = optionData;
393
+ const { marketAddr, optionType, strikePrice, positionSizeCurrent } = optionData;
394
394
  const { pool, optionAssetIsToken0, payoutAssetDecimals } = useMarketData(marketAddr);
395
395
  const { exact: currentTick } = useCurrentTick(pool);
396
396
  return (0, react.useMemo)(() => {
397
397
  if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !positionSizeCurrent || !payoutAssetDecimals) return {};
398
- const entrySize = positionSizeCurrent * entryPrice / require_numberUtils.PRICE_PRECISION;
398
+ const entrySize = positionSizeCurrent * strikePrice / require_numberUtils.PRICE_PRECISION;
399
399
  const delta = (optionAssetIsToken0 ? require_numberUtils.token0ToToken1(positionSizeCurrent, currentTick) : require_numberUtils.token1ToToken0(positionSizeCurrent, currentTick)) - entrySize;
400
400
  const displayPnl = require_numberUtils.wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
401
401
  return {
@@ -403,7 +403,7 @@ const useOptionPnl = (optionData) => {
403
403
  displayPnl
404
404
  };
405
405
  }, [
406
- entryPrice,
406
+ strikePrice,
407
407
  optionType,
408
408
  optionAssetIsToken0,
409
409
  currentTick,
@@ -516,7 +516,7 @@ const useCurrentPrice = (poolAddr) => {
516
516
 
517
517
  //#endregion
518
518
  //#region src/lib/price.ts
519
- const resolutionToGeckoTerminal = (resolution) => {
519
+ const getResolutionConfig = (resolution) => {
520
520
  return {
521
521
  "1m": {
522
522
  timeframe: "minute",
@@ -552,31 +552,33 @@ const resolutionToGeckoTerminal = (resolution) => {
552
552
  };
553
553
  const getPriceHistory = async (poolAddress, resolution, startTimestamp, endTimestamp) => {
554
554
  const network = "monad-testnet";
555
- const { timeframe, aggregate, seconds } = resolutionToGeckoTerminal(resolution);
556
- const timeDiff = endTimestamp - startTimestamp;
557
- const url = `https://api.geckoterminal.com/api/v2/networks/${network}/pools/${poolAddress}/ohlcv/${timeframe}?aggregate=${aggregate}&limit=${Math.min(Math.ceil(timeDiff / seconds), 1e3)}&token=quote&currency=usd&before_timestamp=${endTimestamp}`;
555
+ const { timeframe, aggregate, seconds } = getResolutionConfig(resolution);
556
+ const startSecs = Math.floor(startTimestamp.getTime() / 1e3);
557
+ const endSecs = Math.floor(endTimestamp.getTime() / 1e3);
558
+ const diffSeconds = endSecs - startSecs;
559
+ const url = `https://api.geckoterminal.com/api/v2/networks/${network}/pools/${poolAddress}/ohlcv/${timeframe}?aggregate=${aggregate}&limit=${Math.min(Math.ceil(diffSeconds / seconds), 1e3)}&token=quote&currency=usd&before_timestamp=${endSecs}`;
558
560
  const res = await fetch(url, { headers: { Accept: "application/json" } });
559
561
  if (!res.ok) throw new Error(`Failed to fetch price history: ${res.statusText}`);
560
562
  return (await res.json()).data.attributes.ohlcv_list.map(({ 0: timestamp, 4: price }) => ({
561
563
  timestamp,
562
564
  price
563
- })).filter((point) => point.timestamp >= startTimestamp && point.timestamp <= endTimestamp).sort((a, b) => a.timestamp - b.timestamp);
565
+ })).filter((point) => point.timestamp >= startSecs && point.timestamp <= endSecs).sort((a, b) => a.timestamp - b.timestamp);
564
566
  };
565
567
 
566
568
  //#endregion
567
569
  //#region src/hooks/pool/usePriceHistory.ts
568
- const usePriceHistory = ({ poolAddress, resolution, startTimestamp, endTimestamp, enabled = true }) => {
570
+ const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
569
571
  return (0, __tanstack_react_query.useQuery)({
570
572
  queryKey: [
571
573
  "priceHistory",
572
- poolAddress,
574
+ pool,
573
575
  (0, wagmi.useChainId)(),
574
576
  resolution,
575
577
  startTimestamp,
576
578
  endTimestamp
577
579
  ],
578
- queryFn: () => getPriceHistory(poolAddress, resolution, startTimestamp, endTimestamp),
579
- enabled: enabled && !!poolAddress && startTimestamp < endTimestamp,
580
+ queryFn: () => getPriceHistory(pool, resolution, startTimestamp, endTimestamp),
581
+ enabled: !!pool && startTimestamp < endTimestamp,
580
582
  staleTime: 60 * 1e3,
581
583
  gcTime: 300 * 1e3,
582
584
  retry: 2