timelock-sdk 0.0.119 → 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/abis.cjs +1 -1
- package/dist/abis.d.cts +1 -1
- package/dist/abis.d.ts +1 -1
- package/dist/abis.js +1 -1
- package/dist/{client-Cgi8okgz.d.cts → client-D7objc4l.d.ts} +2566 -2953
- package/dist/{client-CxAAahmW.d.ts → client-bCuyjf6z.d.cts} +2566 -2953
- package/dist/client.cjs +60 -60
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +60 -60
- package/dist/client.js.map +1 -1
- package/dist/{optionUtils-ZSFOJxaV.cjs → optionUtils-DENHUR2w.cjs} +59 -15
- package/dist/optionUtils-DENHUR2w.cjs.map +1 -0
- package/dist/{optionUtils-D8zF6lcX.js → optionUtils-MZU-Gklx.js} +28 -14
- package/dist/optionUtils-MZU-Gklx.js.map +1 -0
- package/dist/{optionsMarket-D6zrIXc3.cjs → optionsMarket-C8-v8IvX.cjs} +65 -155
- package/dist/optionsMarket-C8-v8IvX.cjs.map +1 -0
- package/dist/{optionsMarket-DBuVI-kl.js → optionsMarket-Dkwpa2uO.js} +65 -155
- package/dist/optionsMarket-Dkwpa2uO.js.map +1 -0
- package/dist/package.cjs +8 -3
- package/dist/package.d.cts +3 -3
- package/dist/package.d.ts +3 -3
- package/dist/package.js +3 -3
- package/dist/{uniswapMathLens-ChJFZ6hc.d.ts → uniswapMathLens-DtacRMPz.d.cts} +55 -124
- package/dist/{uniswapMathLens-B_cHjOOB.d.cts → uniswapMathLens-JKcBN1v_.d.ts} +55 -124
- package/package.json +1 -1
- package/dist/optionUtils-D8zF6lcX.js.map +0 -1
- package/dist/optionUtils-ZSFOJxaV.cjs.map +0 -1
- package/dist/optionsMarket-D6zrIXc3.cjs.map +0 -1
- package/dist/optionsMarket-DBuVI-kl.js.map +0 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./uniswapMathLens-
|
|
2
|
-
import { B as
|
|
1
|
+
import "./uniswapMathLens-DtacRMPz.cjs";
|
|
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
|
-
import "./uniswapMathLens-
|
|
2
|
-
import { B as
|
|
1
|
+
import "./uniswapMathLens-JKcBN1v_.js";
|
|
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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-
|
|
5
|
-
import { A as
|
|
4
|
+
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-Dkwpa2uO.js";
|
|
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
|
|
@@ -485,7 +484,6 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
485
484
|
|
|
486
485
|
//#endregion
|
|
487
486
|
//#region src/hooks/options/useExerciseOption.ts
|
|
488
|
-
const swapper = "0x877309663591ad974bE2c0C7fB453844c8D613D8";
|
|
489
487
|
const useExerciseOption = (marketAddr) => {
|
|
490
488
|
const { vault, pool } = useMarketData(marketAddr);
|
|
491
489
|
const { fee } = usePoolData(pool);
|
|
@@ -500,6 +498,8 @@ const useExerciseOption = (marketAddr) => {
|
|
|
500
498
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
501
499
|
if (!vault) throw new Error("Vault not available");
|
|
502
500
|
if (!fee) throw new Error("Pool data not available");
|
|
501
|
+
const swapper = swappers[client.chain.id];
|
|
502
|
+
if (!swapper) throw new Error("Swapper not available");
|
|
503
503
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
504
504
|
const hash = await writeContractAsync({
|
|
505
505
|
address: marketAddr,
|
|
@@ -661,31 +661,71 @@ const useMintOption = (marketAddr) => {
|
|
|
661
661
|
return useMutation({ mutationFn: mintOption });
|
|
662
662
|
};
|
|
663
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
|
+
|
|
664
704
|
//#endregion
|
|
665
705
|
//#region src/hooks/options/useOptionPnl.ts
|
|
666
706
|
const useOptionPnl = (option) => {
|
|
667
707
|
const { marketAddr, optionType, strikeTick, positionSizeCurrent } = option;
|
|
668
708
|
const { pool, optionAssetIsToken0, payoutAssetDecimals, tickSpacing } = useMarketData(marketAddr);
|
|
669
|
-
const {
|
|
709
|
+
const { currentPrice } = useCurrentPrice(pool);
|
|
670
710
|
const displayPnl = useMemo(() => {
|
|
671
|
-
if (optionAssetIsToken0 === void 0 ||
|
|
672
|
-
const strikeSize = optionAssetIsToken0 ?
|
|
673
|
-
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;
|
|
674
714
|
return wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
|
|
675
715
|
}, [
|
|
676
716
|
strikeTick,
|
|
677
717
|
optionType,
|
|
678
718
|
optionAssetIsToken0,
|
|
679
|
-
|
|
719
|
+
currentPrice,
|
|
680
720
|
positionSizeCurrent,
|
|
681
721
|
payoutAssetDecimals
|
|
682
722
|
]);
|
|
683
723
|
return {
|
|
684
724
|
unrealizedPayout: useMemo(() => {
|
|
685
|
-
if (!payoutAssetDecimals || !
|
|
686
|
-
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);
|
|
687
727
|
}, [
|
|
688
|
-
|
|
728
|
+
currentPrice,
|
|
689
729
|
tickSpacing,
|
|
690
730
|
optionType,
|
|
691
731
|
payoutAssetDecimals,
|
|
@@ -856,20 +896,20 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
856
896
|
id: event.id,
|
|
857
897
|
optionType: event.optionType,
|
|
858
898
|
strikeTick: event.strikeTick,
|
|
859
|
-
|
|
860
|
-
expiresAt: /* @__PURE__ */ new Date(Number(event.expiresAt) * 1e3),
|
|
899
|
+
price: BigInt(event.price),
|
|
861
900
|
premium: BigInt(event.premium),
|
|
862
901
|
protocolFee: BigInt(event.protocolFee),
|
|
863
902
|
liquidities: event.liquidities.map((l) => BigInt(l)),
|
|
864
903
|
timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
|
|
904
|
+
expiresAt: /* @__PURE__ */ new Date(Number(event.expiresAt) * 1e3),
|
|
865
905
|
blockNumber: BigInt(event.blockNumber),
|
|
866
906
|
transactionHash: event.transactionHash
|
|
867
907
|
}));
|
|
868
908
|
const exerciseEvents = result.ExerciseOptionEvent.map((event) => ({
|
|
869
909
|
id: event.id,
|
|
870
|
-
liquidities: event.liquidities.map((l) => BigInt(l)),
|
|
871
|
-
currentTick: event.currentTick,
|
|
872
910
|
payout: BigInt(event.payout),
|
|
911
|
+
price: BigInt(event.price),
|
|
912
|
+
liquidities: event.liquidities.map((l) => BigInt(l)),
|
|
873
913
|
timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
|
|
874
914
|
blockNumber: BigInt(event.blockNumber),
|
|
875
915
|
transactionHash: event.transactionHash
|
|
@@ -878,7 +918,7 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
878
918
|
id: event.id,
|
|
879
919
|
premium: BigInt(event.premium),
|
|
880
920
|
protocolFee: BigInt(event.protocolFee),
|
|
881
|
-
|
|
921
|
+
price: BigInt(event.price),
|
|
882
922
|
addedDuration: BigInt(event.addedDuration),
|
|
883
923
|
timestamp: /* @__PURE__ */ new Date(Number(event.timestamp) * 1e3),
|
|
884
924
|
blockNumber: BigInt(event.blockNumber),
|
|
@@ -1186,46 +1226,6 @@ const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
|
|
|
1186
1226
|
};
|
|
1187
1227
|
};
|
|
1188
1228
|
|
|
1189
|
-
//#endregion
|
|
1190
|
-
//#region src/hooks/pool/usePriceAtTick.ts
|
|
1191
|
-
const usePriceAtTick = (tick, poolAddr) => {
|
|
1192
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
1193
|
-
const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
|
|
1194
|
-
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
1195
|
-
priceBigInt,
|
|
1196
|
-
token0Decimals,
|
|
1197
|
-
token1Decimals
|
|
1198
|
-
]);
|
|
1199
|
-
};
|
|
1200
|
-
const usePriceSqrtPriceX96 = (sqrtPriceX96, poolAddr) => {
|
|
1201
|
-
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
1202
|
-
const priceBigInt = useMemo(() => sqrtPriceX96 !== void 0 ? getPriceSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
1203
|
-
return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
1204
|
-
priceBigInt,
|
|
1205
|
-
token0Decimals,
|
|
1206
|
-
token1Decimals
|
|
1207
|
-
]);
|
|
1208
|
-
};
|
|
1209
|
-
|
|
1210
|
-
//#endregion
|
|
1211
|
-
//#region src/hooks/pool/useCurrentPrice.ts
|
|
1212
|
-
const useCurrentPrice = (poolAddr) => {
|
|
1213
|
-
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolAddr);
|
|
1214
|
-
const currentPrice = usePriceSqrtPriceX96(sqrtPriceX96, poolAddr);
|
|
1215
|
-
return useMemo(() => ({
|
|
1216
|
-
currentPrice,
|
|
1217
|
-
sqrtPriceX96,
|
|
1218
|
-
currentTick: {
|
|
1219
|
-
exact,
|
|
1220
|
-
rounded
|
|
1221
|
-
}
|
|
1222
|
-
}), [
|
|
1223
|
-
currentPrice,
|
|
1224
|
-
exact,
|
|
1225
|
-
rounded
|
|
1226
|
-
]);
|
|
1227
|
-
};
|
|
1228
|
-
|
|
1229
1229
|
//#endregion
|
|
1230
1230
|
//#region src/hooks/pool/usePriceHistory.ts
|
|
1231
1231
|
const usePriceHistory = (pool, resolution, startTimestamp, endTimestamp) => {
|