timelock-sdk 0.0.35 → 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.js CHANGED
@@ -20,6 +20,7 @@ const GetActiveUserOptionsDocument = gql`
20
20
  limit: 1000
21
21
  ) {
22
22
  id
23
+ optionId
23
24
  ownerAddr
24
25
  exerciseEvents {
25
26
  transactionHash
@@ -53,6 +54,7 @@ const GetClosedUserOptionsDocument = gql`
53
54
  limit: 1000
54
55
  ) {
55
56
  id
57
+ optionId
56
58
  ownerAddr
57
59
  exerciseEvents {
58
60
  transactionHash
@@ -224,7 +226,7 @@ const useExerciseOption = (marketAddr) => {
224
226
  abi: optionsMarketAbi,
225
227
  functionName: "exerciseOption",
226
228
  args: [
227
- option.id,
229
+ option.optionId,
228
230
  liquidities,
229
231
  0n,
230
232
  refTick
@@ -453,7 +455,7 @@ const useUserOptions = (user, active = false) => {
453
455
  if (!graphqlClient) return [];
454
456
  return (active ? await graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : await graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() })).UserOption.map((option) => ({
455
457
  ...option,
456
- id: BigInt(option.id),
458
+ optionId: BigInt(option.optionId),
457
459
  marketAddr: option.marketAddr,
458
460
  optionType: option.optionType,
459
461
  createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
@@ -544,30 +546,32 @@ const resolutionToGeckoTerminal = (resolution) => {
544
546
  const getPriceHistory = async (poolAddress, resolution, startTimestamp, endTimestamp) => {
545
547
  const network = "monad-testnet";
546
548
  const { timeframe, aggregate, seconds } = resolutionToGeckoTerminal(resolution);
547
- const timeDiff = endTimestamp - startTimestamp;
548
- 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}`;
549
+ const startSecs = Math.floor(startTimestamp.getTime() / 1e3);
550
+ const endSecs = Math.floor(endTimestamp.getTime() / 1e3);
551
+ const diffSeconds = endSecs - startSecs;
552
+ 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}`;
549
553
  const res = await fetch(url, { headers: { Accept: "application/json" } });
550
554
  if (!res.ok) throw new Error(`Failed to fetch price history: ${res.statusText}`);
551
555
  return (await res.json()).data.attributes.ohlcv_list.map(({ 0: timestamp, 4: price }) => ({
552
556
  timestamp,
553
557
  price
554
- })).filter((point) => point.timestamp >= startTimestamp && point.timestamp <= endTimestamp).sort((a, b) => a.timestamp - b.timestamp);
558
+ })).filter((point) => point.timestamp >= startSecs && point.timestamp <= endSecs).sort((a, b) => a.timestamp - b.timestamp);
555
559
  };
556
560
 
557
561
  //#endregion
558
562
  //#region src/hooks/pool/usePriceHistory.ts
559
- const usePriceHistory = ({ poolAddress, resolution, startTimestamp, endTimestamp, enabled = true }) => {
563
+ const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
560
564
  return useQuery({
561
565
  queryKey: [
562
566
  "priceHistory",
563
- poolAddress,
567
+ pool,
564
568
  useChainId(),
565
569
  resolution,
566
570
  startTimestamp,
567
571
  endTimestamp
568
572
  ],
569
- queryFn: () => getPriceHistory(poolAddress, resolution, startTimestamp, endTimestamp),
570
- enabled: enabled && !!poolAddress && startTimestamp < endTimestamp,
573
+ queryFn: () => getPriceHistory(pool, resolution, startTimestamp, endTimestamp),
574
+ enabled: !!pool && startTimestamp < endTimestamp,
571
575
  staleTime: 60 * 1e3,
572
576
  gcTime: 300 * 1e3,
573
577
  retry: 2