timelock-sdk 0.0.36 → 0.0.37

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
@@ -553,30 +553,32 @@ const resolutionToGeckoTerminal = (resolution) => {
553
553
  const getPriceHistory = async (poolAddress, resolution, startTimestamp, endTimestamp) => {
554
554
  const network = "monad-testnet";
555
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}`;
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