timelock-sdk 0.0.79 → 0.0.80
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-D9QtRxOF.d.ts → client-D_t-2-g5.d.cts} +248 -240
- package/dist/{client-h7lO3ik2.d.cts → client-euowNGgz.d.ts} +104 -96
- package/dist/client.cjs +2 -77
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -76
- package/dist/client.js.map +1 -1
- package/dist/{optionUtils-CI-AZi8X.js → optionUtils-CoIk8zAr.js} +97 -2
- package/dist/optionUtils-CoIk8zAr.js.map +1 -0
- package/dist/{optionUtils-CDD_7qmy.cjs → optionUtils-DAjhbiQ5.cjs} +108 -1
- package/dist/optionUtils-DAjhbiQ5.cjs.map +1 -0
- package/dist/package.cjs +3 -1
- package/dist/package.d.cts +2 -2
- package/dist/package.d.ts +2 -2
- package/dist/package.js +2 -2
- package/package.json +1 -1
- package/dist/optionUtils-CDD_7qmy.cjs.map +0 -1
- package/dist/optionUtils-CI-AZi8X.js.map +0 -1
package/dist/client.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const require_optionUtils = require('./optionUtils-
|
|
4
|
+
const require_optionUtils = require('./optionUtils-DAjhbiQ5.cjs');
|
|
5
5
|
const require_optionsMarket = require('./optionsMarket-DxGdV3HF.cjs');
|
|
6
6
|
const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
|
|
7
7
|
let viem = require("viem");
|
|
@@ -881,81 +881,6 @@ const useCurrentPrice = (poolAddr) => {
|
|
|
881
881
|
}), [currentPrice, currentTick]);
|
|
882
882
|
};
|
|
883
883
|
|
|
884
|
-
//#endregion
|
|
885
|
-
//#region src/lib/price.ts
|
|
886
|
-
const getResolutionConfig = (resolution) => {
|
|
887
|
-
return {
|
|
888
|
-
"1m": {
|
|
889
|
-
timeframe: "minute",
|
|
890
|
-
aggregate: "1",
|
|
891
|
-
seconds: 60
|
|
892
|
-
},
|
|
893
|
-
"5m": {
|
|
894
|
-
timeframe: "minute",
|
|
895
|
-
aggregate: "5",
|
|
896
|
-
seconds: 300
|
|
897
|
-
},
|
|
898
|
-
"15m": {
|
|
899
|
-
timeframe: "minute",
|
|
900
|
-
aggregate: "15",
|
|
901
|
-
seconds: 900
|
|
902
|
-
},
|
|
903
|
-
"1h": {
|
|
904
|
-
timeframe: "hour",
|
|
905
|
-
aggregate: "1",
|
|
906
|
-
seconds: 3600
|
|
907
|
-
},
|
|
908
|
-
"4h": {
|
|
909
|
-
timeframe: "hour",
|
|
910
|
-
aggregate: "4",
|
|
911
|
-
seconds: 14400
|
|
912
|
-
},
|
|
913
|
-
"1d": {
|
|
914
|
-
timeframe: "day",
|
|
915
|
-
aggregate: "1",
|
|
916
|
-
seconds: 86400
|
|
917
|
-
}
|
|
918
|
-
}[resolution];
|
|
919
|
-
};
|
|
920
|
-
const fillGaps = (prices, start, end, intervalMs) => {
|
|
921
|
-
if (prices.length === 0) return [];
|
|
922
|
-
const priceMap = /* @__PURE__ */ new Map();
|
|
923
|
-
for (const point of prices) {
|
|
924
|
-
const alignedTime = Math.floor(point.timestamp.getTime() / intervalMs) * intervalMs;
|
|
925
|
-
priceMap.set(alignedTime, point);
|
|
926
|
-
}
|
|
927
|
-
const filled = [];
|
|
928
|
-
let currentTime = Math.floor(prices[0].timestamp.getTime() / intervalMs) * intervalMs;
|
|
929
|
-
let lastKnownPrice = null;
|
|
930
|
-
while (currentTime <= end.getTime()) {
|
|
931
|
-
const existing = priceMap.get(currentTime);
|
|
932
|
-
if (existing) {
|
|
933
|
-
filled.push(existing);
|
|
934
|
-
lastKnownPrice = existing;
|
|
935
|
-
} else if (lastKnownPrice) filled.push({
|
|
936
|
-
timestamp: new Date(currentTime),
|
|
937
|
-
price: lastKnownPrice.price
|
|
938
|
-
});
|
|
939
|
-
currentTime += intervalMs;
|
|
940
|
-
}
|
|
941
|
-
return filled;
|
|
942
|
-
};
|
|
943
|
-
const getPriceHistory = async (poolAddress, resolution, start, end) => {
|
|
944
|
-
const network = "monad-testnet";
|
|
945
|
-
const { timeframe, aggregate, seconds } = getResolutionConfig(resolution);
|
|
946
|
-
if (end.getTime() > Date.now()) end = new Date(Date.now());
|
|
947
|
-
const startSecs = Math.floor(start.getTime() / 1e3);
|
|
948
|
-
const endSecs = Math.floor(end.getTime() / 1e3);
|
|
949
|
-
const diffSeconds = endSecs - startSecs;
|
|
950
|
-
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}`;
|
|
951
|
-
const res = await fetch(url, { headers: { Accept: "application/json" } });
|
|
952
|
-
if (!res.ok) throw new Error(`Failed to fetch price history: ${res.statusText}`);
|
|
953
|
-
return fillGaps((await res.json()).data.attributes.ohlcv_list.map(([timestamp, , , , close]) => ({
|
|
954
|
-
timestamp: /* @__PURE__ */ new Date(timestamp * 1e3),
|
|
955
|
-
price: close
|
|
956
|
-
})).sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()), start, end, seconds * 1e3).filter((point) => point.timestamp.getTime() / 1e3 >= startSecs && point.timestamp.getTime() / 1e3 <= endSecs);
|
|
957
|
-
};
|
|
958
|
-
|
|
959
884
|
//#endregion
|
|
960
885
|
//#region src/hooks/pool/usePriceHistory.ts
|
|
961
886
|
const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
|
|
@@ -968,7 +893,7 @@ const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
|
|
|
968
893
|
startTimestamp,
|
|
969
894
|
endTimestamp
|
|
970
895
|
],
|
|
971
|
-
queryFn: () => getPriceHistory(pool, resolution, startTimestamp, endTimestamp),
|
|
896
|
+
queryFn: () => require_optionUtils.getPriceHistory(pool, resolution, startTimestamp, endTimestamp),
|
|
972
897
|
enabled: !!pool && startTimestamp < endTimestamp,
|
|
973
898
|
staleTime: 60 * 1e3,
|
|
974
899
|
gcTime: 300 * 1e3,
|