timelock-sdk 0.0.120 → 0.0.121
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-CTL-mr5n.d.ts → client-D7objc4l.d.ts} +396 -446
- package/dist/{client-r3O6AK_5.d.cts → client-bCuyjf6z.d.cts} +246 -296
- package/dist/client.cjs +57 -58
- 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 +57 -58
- package/dist/client.js.map +1 -1
- package/dist/{optionUtils-BHL27KMw.cjs → optionUtils-DENHUR2w.cjs} +50 -13
- package/dist/optionUtils-DENHUR2w.cjs.map +1 -0
- package/dist/{optionUtils-CtGcjfvf.js → optionUtils-MZU-Gklx.js} +25 -12
- package/dist/optionUtils-MZU-Gklx.js.map +1 -0
- package/dist/package.cjs +6 -2
- 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-BHL27KMw.cjs.map +0 -1
- package/dist/optionUtils-CtGcjfvf.js.map +0 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./uniswapMathLens-DtacRMPz.cjs";
|
|
2
|
-
import { B as
|
|
2
|
+
import { $ as useOptionPnl, B as useSetOperatorPerms, Ct as useCurrentMarket, G as useUserPerps, H as useOperatorPerms, J as useMintPerp, K as usePerpsOperator, Q as useOptionPremium, St as TimelockProvider, U as useActiveUserPerps, V as useUserOperators, W as useClosedUserPerps, X as useOptionTimeline, Y as OptionTimelineData, Z as useExtendOption, _t as useMarketData, a as batchGetAmountsFromLiquidity, bt as useActiveUserOptions, c as useLiquidityBlocks, d as usePriceAtTick, et as useMintOption, f as usePriceSqrtPriceX96, g as useCurrentPrice, h as useCurrentTick, i as useVaultData, l as useBurnLiquidity, m as usePoolData, n as useLens, o as useMintLiquidity, p as UniswapPoolData, q as useClosePerp, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, tt as useMaxPositionSize, u as usePriceHistory, vt as useExerciseOption, wt as useTimelockConfig, xt as useClosedUserOptions, yt as OptionData } from "./client-bCuyjf6z.cjs";
|
|
3
3
|
export { LiquidityBlockData, OptionData, OptionTimelineData, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, usePriceSqrtPriceX96, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./uniswapMathLens-JKcBN1v_.js";
|
|
2
|
-
import { B as
|
|
2
|
+
import { $ as useOptionPnl, B as useSetOperatorPerms, Ct as useCurrentMarket, G as useUserPerps, H as useOperatorPerms, J as useMintPerp, K as usePerpsOperator, Q as useOptionPremium, St as TimelockProvider, U as useActiveUserPerps, V as useUserOperators, W as useClosedUserPerps, X as useOptionTimeline, Y as OptionTimelineData, Z as useExtendOption, _t as useMarketData, a as batchGetAmountsFromLiquidity, bt as useActiveUserOptions, c as useLiquidityBlocks, d as usePriceAtTick, et as useMintOption, f as usePriceSqrtPriceX96, g as useCurrentPrice, h as useCurrentTick, i as useVaultData, l as useBurnLiquidity, m as usePoolData, n as useLens, o as useMintLiquidity, p as UniswapPoolData, q as useClosePerp, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, tt as useMaxPositionSize, u as usePriceHistory, vt as useExerciseOption, wt as useTimelockConfig, xt as useClosedUserOptions, yt as OptionData } from "./client-D7objc4l.js";
|
|
3
3
|
export { LiquidityBlockData, OptionData, OptionTimelineData, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, usePriceSqrtPriceX96, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-Dkwpa2uO.js";
|
|
5
|
-
import { A as
|
|
5
|
+
import { A as token0ToToken1AtTick, B as timelockLenses, D as roundTickDown, F as getErc20, I as getTimelockLens, L as getTimelockMarket, M as token1ToToken0AtTick, P as getPriceHistory, R as getUniswapMathLens, V as uniswapMathLenses, b as getPriceAtSqrtPriceX96, f as wrapAmount, j as token1ToToken0, k as token0ToToken1, m as wrapPrice, r as EMPTY_ARRAY$1, t as getPayoutAtPrice, v as getAmountsFromLiquidity, x as getPriceAtTick, y as getNearestValidStrikeTick, z as swappers } from "./optionUtils-MZU-Gklx.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, useEffect, useMemo } from "react";
|
|
@@ -26,7 +26,6 @@ const UserOptionFieldsFragmentDoc = gql`
|
|
|
26
26
|
}
|
|
27
27
|
optionType
|
|
28
28
|
strikeTick
|
|
29
|
-
entryTick
|
|
30
29
|
startTick
|
|
31
30
|
strikePrice
|
|
32
31
|
entryPrice
|
|
@@ -151,7 +150,7 @@ const GetOptionEventsDocument = gql`
|
|
|
151
150
|
id
|
|
152
151
|
optionType
|
|
153
152
|
strikeTick
|
|
154
|
-
|
|
153
|
+
price
|
|
155
154
|
expiresAt
|
|
156
155
|
premium
|
|
157
156
|
protocolFee
|
|
@@ -171,7 +170,7 @@ const GetOptionEventsDocument = gql`
|
|
|
171
170
|
) {
|
|
172
171
|
id
|
|
173
172
|
liquidities
|
|
174
|
-
|
|
173
|
+
price
|
|
175
174
|
payout
|
|
176
175
|
timestamp
|
|
177
176
|
blockNumber
|
|
@@ -189,7 +188,7 @@ const GetOptionEventsDocument = gql`
|
|
|
189
188
|
id
|
|
190
189
|
premium
|
|
191
190
|
protocolFee
|
|
192
|
-
|
|
191
|
+
price
|
|
193
192
|
addedDuration
|
|
194
193
|
timestamp
|
|
195
194
|
blockNumber
|
|
@@ -662,31 +661,71 @@ const useMintOption = (marketAddr) => {
|
|
|
662
661
|
return useMutation({ mutationFn: mintOption });
|
|
663
662
|
};
|
|
664
663
|
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/hooks/pool/usePriceAtTick.ts
|
|
666
|
+
const usePriceAtTick = (tick, poolAddr) => {
|
|
667
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
668
|
+
const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
|
|
669
|
+
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
670
|
+
priceBigInt,
|
|
671
|
+
token0Decimals,
|
|
672
|
+
token1Decimals
|
|
673
|
+
]);
|
|
674
|
+
};
|
|
675
|
+
const usePriceSqrtPriceX96 = (sqrtPriceX96, poolAddr) => {
|
|
676
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
677
|
+
const priceBigInt = useMemo(() => sqrtPriceX96 !== void 0 ? getPriceAtSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
678
|
+
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
679
|
+
priceBigInt,
|
|
680
|
+
token0Decimals,
|
|
681
|
+
token1Decimals
|
|
682
|
+
]);
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/hooks/pool/useCurrentPrice.ts
|
|
687
|
+
const useCurrentPrice = (poolAddr) => {
|
|
688
|
+
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolAddr);
|
|
689
|
+
const currentPrice = usePriceSqrtPriceX96(sqrtPriceX96, poolAddr);
|
|
690
|
+
return useMemo(() => ({
|
|
691
|
+
currentPrice,
|
|
692
|
+
sqrtPriceX96,
|
|
693
|
+
currentTick: {
|
|
694
|
+
exact,
|
|
695
|
+
rounded
|
|
696
|
+
}
|
|
697
|
+
}), [
|
|
698
|
+
currentPrice,
|
|
699
|
+
exact,
|
|
700
|
+
rounded
|
|
701
|
+
]);
|
|
702
|
+
};
|
|
703
|
+
|
|
665
704
|
//#endregion
|
|
666
705
|
//#region src/hooks/options/useOptionPnl.ts
|
|
667
706
|
const useOptionPnl = (option) => {
|
|
668
707
|
const { marketAddr, optionType, strikeTick, positionSizeCurrent } = option;
|
|
669
708
|
const { pool, optionAssetIsToken0, payoutAssetDecimals, tickSpacing } = useMarketData(marketAddr);
|
|
670
|
-
const {
|
|
709
|
+
const { currentPrice } = useCurrentPrice(pool);
|
|
671
710
|
const displayPnl = useMemo(() => {
|
|
672
|
-
if (optionAssetIsToken0 === void 0 ||
|
|
673
|
-
const strikeSize = optionAssetIsToken0 ?
|
|
674
|
-
const delta = (optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent,
|
|
711
|
+
if (optionAssetIsToken0 === void 0 || currentPrice === void 0 || !payoutAssetDecimals) return void 0;
|
|
712
|
+
const strikeSize = optionAssetIsToken0 ? token0ToToken1AtTick(positionSizeCurrent, strikeTick) : token1ToToken0AtTick(positionSizeCurrent, strikeTick);
|
|
713
|
+
const delta = (optionAssetIsToken0 ? token0ToToken1(positionSizeCurrent, currentPrice.scaled) : token1ToToken0(positionSizeCurrent, currentPrice.scaled)) - strikeSize;
|
|
675
714
|
return wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
|
|
676
715
|
}, [
|
|
677
716
|
strikeTick,
|
|
678
717
|
optionType,
|
|
679
718
|
optionAssetIsToken0,
|
|
680
|
-
|
|
719
|
+
currentPrice,
|
|
681
720
|
positionSizeCurrent,
|
|
682
721
|
payoutAssetDecimals
|
|
683
722
|
]);
|
|
684
723
|
return {
|
|
685
724
|
unrealizedPayout: useMemo(() => {
|
|
686
|
-
if (!payoutAssetDecimals || !
|
|
687
|
-
return wrapAmount(
|
|
725
|
+
if (!payoutAssetDecimals || !currentPrice || !tickSpacing || optionAssetIsToken0 === void 0) return void 0;
|
|
726
|
+
return wrapAmount(getPayoutAtPrice(option, option.liquiditiesCurrent, currentPrice.scaled, tickSpacing, optionAssetIsToken0), payoutAssetDecimals);
|
|
688
727
|
}, [
|
|
689
|
-
|
|
728
|
+
currentPrice,
|
|
690
729
|
tickSpacing,
|
|
691
730
|
optionType,
|
|
692
731
|
payoutAssetDecimals,
|
|
@@ -857,20 +896,20 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
857
896
|
id: event.id,
|
|
858
897
|
optionType: event.optionType,
|
|
859
898
|
strikeTick: event.strikeTick,
|
|
860
|
-
|
|
861
|
-
expiresAt: /* @__PURE__ */ new Date(Number(event.expiresAt) * 1e3),
|
|
899
|
+
price: BigInt(event.price),
|
|
862
900
|
premium: BigInt(event.premium),
|
|
863
901
|
protocolFee: BigInt(event.protocolFee),
|
|
864
902
|
liquidities: event.liquidities.map((l) => BigInt(l)),
|
|
865
903
|
timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
|
|
904
|
+
expiresAt: /* @__PURE__ */ new Date(Number(event.expiresAt) * 1e3),
|
|
866
905
|
blockNumber: BigInt(event.blockNumber),
|
|
867
906
|
transactionHash: event.transactionHash
|
|
868
907
|
}));
|
|
869
908
|
const exerciseEvents = result.ExerciseOptionEvent.map((event) => ({
|
|
870
909
|
id: event.id,
|
|
871
|
-
liquidities: event.liquidities.map((l) => BigInt(l)),
|
|
872
|
-
currentTick: event.currentTick,
|
|
873
910
|
payout: BigInt(event.payout),
|
|
911
|
+
price: BigInt(event.price),
|
|
912
|
+
liquidities: event.liquidities.map((l) => BigInt(l)),
|
|
874
913
|
timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
|
|
875
914
|
blockNumber: BigInt(event.blockNumber),
|
|
876
915
|
transactionHash: event.transactionHash
|
|
@@ -879,7 +918,7 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
879
918
|
id: event.id,
|
|
880
919
|
premium: BigInt(event.premium),
|
|
881
920
|
protocolFee: BigInt(event.protocolFee),
|
|
882
|
-
|
|
921
|
+
price: BigInt(event.price),
|
|
883
922
|
addedDuration: BigInt(event.addedDuration),
|
|
884
923
|
timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
|
|
885
924
|
blockNumber: BigInt(event.blockNumber),
|
|
@@ -1187,46 +1226,6 @@ const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
|
|
|
1187
1226
|
};
|
|
1188
1227
|
};
|
|
1189
1228
|
|
|
1190
|
-
//#endregion
|
|
1191
|
-
//#region src/hooks/pool/usePriceAtTick.ts
|
|
1192
|
-
const usePriceAtTick = (tick, poolAddr) => {
|
|
1193
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
1194
|
-
const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
|
|
1195
|
-
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
1196
|
-
priceBigInt,
|
|
1197
|
-
token0Decimals,
|
|
1198
|
-
token1Decimals
|
|
1199
|
-
]);
|
|
1200
|
-
};
|
|
1201
|
-
const usePriceSqrtPriceX96 = (sqrtPriceX96, poolAddr) => {
|
|
1202
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
1203
|
-
const priceBigInt = useMemo(() => sqrtPriceX96 !== void 0 ? getPriceSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
1204
|
-
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
1205
|
-
priceBigInt,
|
|
1206
|
-
token0Decimals,
|
|
1207
|
-
token1Decimals
|
|
1208
|
-
]);
|
|
1209
|
-
};
|
|
1210
|
-
|
|
1211
|
-
//#endregion
|
|
1212
|
-
//#region src/hooks/pool/useCurrentPrice.ts
|
|
1213
|
-
const useCurrentPrice = (poolAddr) => {
|
|
1214
|
-
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolAddr);
|
|
1215
|
-
const currentPrice = usePriceSqrtPriceX96(sqrtPriceX96, poolAddr);
|
|
1216
|
-
return useMemo(() => ({
|
|
1217
|
-
currentPrice,
|
|
1218
|
-
sqrtPriceX96,
|
|
1219
|
-
currentTick: {
|
|
1220
|
-
exact,
|
|
1221
|
-
rounded
|
|
1222
|
-
}
|
|
1223
|
-
}), [
|
|
1224
|
-
currentPrice,
|
|
1225
|
-
exact,
|
|
1226
|
-
rounded
|
|
1227
|
-
]);
|
|
1228
|
-
};
|
|
1229
|
-
|
|
1230
1229
|
//#endregion
|
|
1231
1230
|
//#region src/hooks/pool/usePriceHistory.ts
|
|
1232
1231
|
const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
|