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.cjs +13 -9
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +168 -125
- package/dist/client.d.ts +168 -125
- package/dist/client.js +13 -9
- package/dist/client.js.map +1 -1
- package/dist/{index-B7b3c8cu.d.cts → index-BwLIRtzJ.d.ts} +93 -93
- package/dist/{index-CRhFaRiq.d.ts → index-CA5kB-yT.d.cts} +2 -2
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
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.
|
|
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
|
-
|
|
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
|
|
548
|
-
const
|
|
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¤cy=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 >=
|
|
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 = (
|
|
563
|
+
const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
|
|
560
564
|
return useQuery({
|
|
561
565
|
queryKey: [
|
|
562
566
|
"priceHistory",
|
|
563
|
-
|
|
567
|
+
pool,
|
|
564
568
|
useChainId(),
|
|
565
569
|
resolution,
|
|
566
570
|
startTimestamp,
|
|
567
571
|
endTimestamp
|
|
568
572
|
],
|
|
569
|
-
queryFn: () => getPriceHistory(
|
|
570
|
-
enabled:
|
|
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
|