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 +9 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +58 -71
- package/dist/client.d.ts +3 -16
- package/dist/client.js +9 -7
- package/dist/client.js.map +1 -1
- package/dist/{index-B20z73_3.d.ts → index-BwLIRtzJ.d.ts} +92 -92
- package/dist/{index-B7b3c8cu.d.cts → index-CA5kB-yT.d.cts} +92 -92
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
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
|
|
557
|
-
const
|
|
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¤cy=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 >=
|
|
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 = (
|
|
570
|
+
const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
|
|
569
571
|
return (0, __tanstack_react_query.useQuery)({
|
|
570
572
|
queryKey: [
|
|
571
573
|
"priceHistory",
|
|
572
|
-
|
|
574
|
+
pool,
|
|
573
575
|
(0, wagmi.useChainId)(),
|
|
574
576
|
resolution,
|
|
575
577
|
startTimestamp,
|
|
576
578
|
endTimestamp
|
|
577
579
|
],
|
|
578
|
-
queryFn: () => getPriceHistory(
|
|
579
|
-
enabled:
|
|
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
|