timelock-sdk 0.0.78 → 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/{index-CFBcBY1K.d.cts → client-D_t-2-g5.d.cts} +30567 -93
- package/dist/{index-CdkTrz02.d.ts → client-euowNGgz.d.ts} +30476 -2
- package/dist/client.cjs +50 -126
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -30468
- package/dist/client.d.ts +2 -30468
- package/dist/client.js +18 -94
- package/dist/client.js.map +1 -1
- package/dist/{numberUtils--YU8VSJO.js → optionUtils-CoIk8zAr.js} +107 -2
- package/dist/optionUtils-CoIk8zAr.js.map +1 -0
- package/dist/{numberUtils-fHghA8Tv.cjs → optionUtils-DAjhbiQ5.cjs} +130 -1
- package/dist/optionUtils-DAjhbiQ5.cjs.map +1 -0
- package/dist/package.cjs +36 -32
- 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/numberUtils--YU8VSJO.js.map +0 -1
- package/dist/numberUtils-fHghA8Tv.cjs.map +0 -1
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-6PlyceXp.js";
|
|
5
|
-
import { A as
|
|
5
|
+
import { A as getErc20, D as token1ToToken0, E as token0ToToken1, F as uniswapMathLenses, M as getTimelockMarket, N as getUniswapMathLens, P as timelockLenses, d as wrapAmount, j as getTimelockLens, k as getPriceHistory, n as EMPTY_ARRAY, p as wrapPrice, t as getPayoutAtTick, v as getNearestValidStrikeTick, w as roundTickDown, y as getPriceAtTick } from "./optionUtils-CoIk8zAr.js";
|
|
6
6
|
import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
|
|
7
7
|
import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
|
|
8
8
|
import React, { createContext, useContext, useMemo } from "react";
|
|
@@ -548,15 +548,16 @@ const useMintOption = (marketAddr) => {
|
|
|
548
548
|
//#endregion
|
|
549
549
|
//#region src/hooks/market/useOptionPnl.ts
|
|
550
550
|
const useOptionPnl = (option) => {
|
|
551
|
-
const { marketAddr, optionType,
|
|
551
|
+
const { marketAddr, optionType, entryTick, positionSizeCurrent } = option;
|
|
552
552
|
const { pool, optionAssetIsToken0, payoutAssetDecimals, tickSpacing } = useMarketData(marketAddr);
|
|
553
553
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
554
|
-
const strikeSize = positionSizeCurrent * strikePrice / PRICE_PRECISION;
|
|
555
554
|
const displayPnl = useMemo(() => {
|
|
556
|
-
if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !
|
|
557
|
-
const
|
|
555
|
+
if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !payoutAssetDecimals) return void 0;
|
|
556
|
+
const entrySize = optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, entryTick) : token1ToToken0(positionSizeCurrent, entryTick);
|
|
557
|
+
const delta = (optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, currentTick) : token1ToToken0(positionSizeCurrent, currentTick)) - entrySize;
|
|
558
558
|
return wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
|
|
559
559
|
}, [
|
|
560
|
+
entryTick,
|
|
560
561
|
optionType,
|
|
561
562
|
optionAssetIsToken0,
|
|
562
563
|
currentTick,
|
|
@@ -565,16 +566,14 @@ const useOptionPnl = (option) => {
|
|
|
565
566
|
]);
|
|
566
567
|
return {
|
|
567
568
|
unrealizedPayout: useMemo(() => {
|
|
568
|
-
if (!payoutAssetDecimals || !currentTick || !tickSpacing) return void 0;
|
|
569
|
-
|
|
570
|
-
const delta = (optionAssetIsToken0 ? amount1 + token0ToToken1(amount0, currentTick) : amount0 + token1ToToken0(amount1, currentTick)) - strikeSize;
|
|
571
|
-
const pnl = optionType === "CALL" ? delta : -delta;
|
|
572
|
-
return wrapAmount(pnl < 0 ? 0n : pnl, payoutAssetDecimals);
|
|
569
|
+
if (!payoutAssetDecimals || !currentTick || !tickSpacing || optionAssetIsToken0 === void 0) return void 0;
|
|
570
|
+
return wrapAmount(getPayoutAtTick(option, option.liquiditiesCurrent, currentTick, tickSpacing, optionAssetIsToken0), payoutAssetDecimals);
|
|
573
571
|
}, [
|
|
574
572
|
currentTick,
|
|
575
573
|
tickSpacing,
|
|
576
574
|
optionType,
|
|
577
|
-
payoutAssetDecimals
|
|
575
|
+
payoutAssetDecimals,
|
|
576
|
+
optionAssetIsToken0
|
|
578
577
|
]),
|
|
579
578
|
displayPnl
|
|
580
579
|
};
|
|
@@ -667,7 +666,7 @@ const useUserOptions = (userAddr, marketAddr, active = false) => {
|
|
|
667
666
|
enabled: !!userAddr && !!marketAddr && !!graphqlClient
|
|
668
667
|
});
|
|
669
668
|
return {
|
|
670
|
-
data: data ||
|
|
669
|
+
data: data || EMPTY_ARRAY,
|
|
671
670
|
...rest
|
|
672
671
|
};
|
|
673
672
|
};
|
|
@@ -742,7 +741,7 @@ const useUserOperators = (userAddr, marketAddr) => {
|
|
|
742
741
|
});
|
|
743
742
|
return {
|
|
744
743
|
...rest,
|
|
745
|
-
data: data ||
|
|
744
|
+
data: data || EMPTY_ARRAY
|
|
746
745
|
};
|
|
747
746
|
};
|
|
748
747
|
|
|
@@ -784,17 +783,17 @@ const useSetOperatorPerms = (marketAddr) => {
|
|
|
784
783
|
//#region src/hooks/market/useOptionTimeline.ts
|
|
785
784
|
const useOptionTimeline = (marketAddr, optionId) => {
|
|
786
785
|
const { graphqlClient } = useTimelockConfig();
|
|
787
|
-
|
|
786
|
+
marketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
|
|
788
787
|
const { data,...rest } = useQuery({
|
|
789
788
|
queryKey: [
|
|
790
789
|
"optionTimeline",
|
|
791
|
-
|
|
790
|
+
marketAddr || "--",
|
|
792
791
|
(optionId === null || optionId === void 0 ? void 0 : optionId.toString()) || "--"
|
|
793
792
|
],
|
|
794
793
|
queryFn: async () => {
|
|
795
|
-
if (!graphqlClient || !
|
|
794
|
+
if (!graphqlClient || !marketAddr || optionId === void 0) return [];
|
|
796
795
|
const result = await graphqlClient.GetOptionEvents({
|
|
797
|
-
marketAddr
|
|
796
|
+
marketAddr,
|
|
798
797
|
optionId: optionId.toString()
|
|
799
798
|
});
|
|
800
799
|
const mintEvents = result.MintOptionEvent.map((event) => ({
|
|
@@ -844,10 +843,10 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
844
843
|
}))
|
|
845
844
|
].sort((a, b) => a.data.timestamp.getTime() - b.data.timestamp.getTime());
|
|
846
845
|
},
|
|
847
|
-
enabled: !!
|
|
846
|
+
enabled: !!marketAddr && optionId !== void 0 && !!graphqlClient
|
|
848
847
|
});
|
|
849
848
|
return {
|
|
850
|
-
data: data ||
|
|
849
|
+
data: data || EMPTY_ARRAY,
|
|
851
850
|
...rest
|
|
852
851
|
};
|
|
853
852
|
};
|
|
@@ -875,81 +874,6 @@ const useCurrentPrice = (poolAddr) => {
|
|
|
875
874
|
}), [currentPrice, currentTick]);
|
|
876
875
|
};
|
|
877
876
|
|
|
878
|
-
//#endregion
|
|
879
|
-
//#region src/lib/price.ts
|
|
880
|
-
const getResolutionConfig = (resolution) => {
|
|
881
|
-
return {
|
|
882
|
-
"1m": {
|
|
883
|
-
timeframe: "minute",
|
|
884
|
-
aggregate: "1",
|
|
885
|
-
seconds: 60
|
|
886
|
-
},
|
|
887
|
-
"5m": {
|
|
888
|
-
timeframe: "minute",
|
|
889
|
-
aggregate: "5",
|
|
890
|
-
seconds: 300
|
|
891
|
-
},
|
|
892
|
-
"15m": {
|
|
893
|
-
timeframe: "minute",
|
|
894
|
-
aggregate: "15",
|
|
895
|
-
seconds: 900
|
|
896
|
-
},
|
|
897
|
-
"1h": {
|
|
898
|
-
timeframe: "hour",
|
|
899
|
-
aggregate: "1",
|
|
900
|
-
seconds: 3600
|
|
901
|
-
},
|
|
902
|
-
"4h": {
|
|
903
|
-
timeframe: "hour",
|
|
904
|
-
aggregate: "4",
|
|
905
|
-
seconds: 14400
|
|
906
|
-
},
|
|
907
|
-
"1d": {
|
|
908
|
-
timeframe: "day",
|
|
909
|
-
aggregate: "1",
|
|
910
|
-
seconds: 86400
|
|
911
|
-
}
|
|
912
|
-
}[resolution];
|
|
913
|
-
};
|
|
914
|
-
const fillGaps = (prices, start, end, intervalMs) => {
|
|
915
|
-
if (prices.length === 0) return [];
|
|
916
|
-
const priceMap = /* @__PURE__ */ new Map();
|
|
917
|
-
for (const point of prices) {
|
|
918
|
-
const alignedTime = Math.floor(point.timestamp.getTime() / intervalMs) * intervalMs;
|
|
919
|
-
priceMap.set(alignedTime, point);
|
|
920
|
-
}
|
|
921
|
-
const filled = [];
|
|
922
|
-
let currentTime = Math.floor(prices[0].timestamp.getTime() / intervalMs) * intervalMs;
|
|
923
|
-
let lastKnownPrice = null;
|
|
924
|
-
while (currentTime <= end.getTime()) {
|
|
925
|
-
const existing = priceMap.get(currentTime);
|
|
926
|
-
if (existing) {
|
|
927
|
-
filled.push(existing);
|
|
928
|
-
lastKnownPrice = existing;
|
|
929
|
-
} else if (lastKnownPrice) filled.push({
|
|
930
|
-
timestamp: new Date(currentTime),
|
|
931
|
-
price: lastKnownPrice.price
|
|
932
|
-
});
|
|
933
|
-
currentTime += intervalMs;
|
|
934
|
-
}
|
|
935
|
-
return filled;
|
|
936
|
-
};
|
|
937
|
-
const getPriceHistory = async (poolAddress, resolution, start, end) => {
|
|
938
|
-
const network = "monad-testnet";
|
|
939
|
-
const { timeframe, aggregate, seconds } = getResolutionConfig(resolution);
|
|
940
|
-
if (end.getTime() > Date.now()) end = new Date(Date.now());
|
|
941
|
-
const startSecs = Math.floor(start.getTime() / 1e3);
|
|
942
|
-
const endSecs = Math.floor(end.getTime() / 1e3);
|
|
943
|
-
const diffSeconds = endSecs - startSecs;
|
|
944
|
-
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}`;
|
|
945
|
-
const res = await fetch(url, { headers: { Accept: "application/json" } });
|
|
946
|
-
if (!res.ok) throw new Error(`Failed to fetch price history: ${res.statusText}`);
|
|
947
|
-
return fillGaps((await res.json()).data.attributes.ohlcv_list.map(([timestamp, , , , close]) => ({
|
|
948
|
-
timestamp: /* @__PURE__ */ new Date(timestamp * 1e3),
|
|
949
|
-
price: close
|
|
950
|
-
})).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);
|
|
951
|
-
};
|
|
952
|
-
|
|
953
877
|
//#endregion
|
|
954
878
|
//#region src/hooks/pool/usePriceHistory.ts
|
|
955
879
|
const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
|