timelock-sdk 0.0.112 → 0.0.114
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-Bcn8F-k3.d.ts → client-BFaMKjtt.d.ts} +165 -161
- package/dist/{client-191_W3kB.d.cts → client-dmXFiQFn.d.cts} +6 -2
- package/dist/client.cjs +56 -57
- 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 +56 -58
- package/dist/client.js.map +1 -1
- package/dist/{optionUtils-BkogxEAT.js → optionUtils-D8zF6lcX.js} +5 -2
- package/dist/optionUtils-D8zF6lcX.js.map +1 -0
- package/dist/{optionUtils-DNAmXoEX.cjs → optionUtils-DQakRJ_U.cjs} +10 -1
- package/dist/optionUtils-DQakRJ_U.cjs.map +1 -0
- package/dist/package.cjs +2 -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-BkogxEAT.js.map +0 -1
- package/dist/optionUtils-DNAmXoEX.cjs.map +0 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./uniswapMathLens-B_cHjOOB.cjs";
|
|
2
|
-
import { B as
|
|
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, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
|
2
|
+
import { B as useClosedUserPerps, G as OptionTimelineData, H as usePerpsOperator, I as useSetOperatorPerms, J as useOptionPremium, K as useOptionTimeline, L as useUserOperators, R as useOperatorPerms, U as useClosePerp, V as useUserPerps, W as useMintPerp, X as useMintOption, Y as useOptionPnl, Z as useMaxPositionSize, _t as useClosedUserOptions, a as batchGetAmountsFromLiquidity, bt as useTimelockConfig, c as useLiquidityBlocks, d as usePriceAtTick, f as usePriceSqrtPriceX96, g as useCurrentPrice, gt as useActiveUserOptions, h as useCurrentTick, ht as OptionData, i as useVaultData, l as useBurnLiquidity, m as usePoolData, mt as useExerciseOption, n as useLens, o as useMintLiquidity, p as UniswapPoolData, pt as useMarketData, q as useExtendOption, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, u as usePriceHistory, vt as TimelockProvider, yt as useCurrentMarket, z as useActiveUserPerps } from "./client-dmXFiQFn.cjs";
|
|
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-ChJFZ6hc.js";
|
|
2
|
-
import { B as
|
|
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, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
|
2
|
+
import { B as useClosedUserPerps, G as OptionTimelineData, H as usePerpsOperator, I as useSetOperatorPerms, J as useOptionPremium, K as useOptionTimeline, L as useUserOperators, R as useOperatorPerms, U as useClosePerp, V as useUserPerps, W as useMintPerp, X as useMintOption, Y as useOptionPnl, Z as useMaxPositionSize, _t as useClosedUserOptions, a as batchGetAmountsFromLiquidity, bt as useTimelockConfig, c as useLiquidityBlocks, d as usePriceAtTick, f as usePriceSqrtPriceX96, g as useCurrentPrice, gt as useActiveUserOptions, h as useCurrentTick, ht as OptionData, i as useVaultData, l as useBurnLiquidity, m as usePoolData, mt as useExerciseOption, n as useLens, o as useMintLiquidity, p as UniswapPoolData, pt as useMarketData, q as useExtendOption, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, u as usePriceHistory, vt as TimelockProvider, yt as useCurrentMarket, z as useActiveUserPerps } from "./client-BFaMKjtt.js";
|
|
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-DBuVI-kl.js";
|
|
5
|
-
import { A as
|
|
5
|
+
import { A as getPriceHistory, D as token0ToToken1, F as timelockLenses, I as uniswapMathLenses, M as getTimelockLens, N as getTimelockMarket, O as token1ToToken0, P as getUniswapMathLens, T as roundTickDown, _ as getAmountsFromLiquidity, b as getPriceSqrtPriceX96, d as wrapAmount, j as getErc20, n as EMPTY_ARRAY$1, p as wrapPrice, t as getPayoutAtTick, v as getNearestValidStrikeTick, y as getPriceAtTick } from "./optionUtils-D8zF6lcX.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";
|
|
@@ -479,6 +479,10 @@ const usePoolData = (poolAddr) => {
|
|
|
479
479
|
return data || {};
|
|
480
480
|
};
|
|
481
481
|
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/lib/utils.ts
|
|
484
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
485
|
+
|
|
482
486
|
//#endregion
|
|
483
487
|
//#region src/hooks/options/useExerciseOption.ts
|
|
484
488
|
const swapper = "0x2c79DD9797C35A3D966C2716739542a282BB5540";
|
|
@@ -511,16 +515,9 @@ const useExerciseOption = (marketAddr) => {
|
|
|
511
515
|
]
|
|
512
516
|
});
|
|
513
517
|
await waitForTransactionReceipt(client, { hash });
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
true
|
|
518
|
-
] });
|
|
519
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
520
|
-
"userOptions",
|
|
521
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
522
|
-
false
|
|
523
|
-
] });
|
|
518
|
+
await sleep(200);
|
|
519
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
520
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
524
521
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
525
522
|
return hash;
|
|
526
523
|
};
|
|
@@ -579,10 +576,12 @@ const useCurrentTick = (poolAddr) => {
|
|
|
579
576
|
args: []
|
|
580
577
|
});
|
|
581
578
|
return useMemo(() => {
|
|
579
|
+
const sqrtPriceX96 = data === null || data === void 0 ? void 0 : data[0];
|
|
582
580
|
const exact = data === null || data === void 0 ? void 0 : data[1];
|
|
583
581
|
return {
|
|
584
582
|
exact,
|
|
585
|
-
rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0
|
|
583
|
+
rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
|
|
584
|
+
sqrtPriceX96
|
|
586
585
|
};
|
|
587
586
|
}, [data, tickSpacing]);
|
|
588
587
|
};
|
|
@@ -653,16 +652,9 @@ const useMintOption = (marketAddr) => {
|
|
|
653
652
|
]
|
|
654
653
|
});
|
|
655
654
|
await waitForTransactionReceipt(client, { hash });
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
true
|
|
660
|
-
] });
|
|
661
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
662
|
-
"userOptions",
|
|
663
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
664
|
-
false
|
|
665
|
-
] });
|
|
655
|
+
await sleep(200);
|
|
656
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
657
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
666
658
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
667
659
|
return hash;
|
|
668
660
|
};
|
|
@@ -834,7 +826,10 @@ const useExtendOption = (marketAddr) => {
|
|
|
834
826
|
]
|
|
835
827
|
});
|
|
836
828
|
await waitForTransactionReceipt(client, { hash });
|
|
837
|
-
|
|
829
|
+
await sleep(200);
|
|
830
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
831
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
832
|
+
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
838
833
|
return hash;
|
|
839
834
|
};
|
|
840
835
|
return useMutation({ mutationFn: extendOption });
|
|
@@ -1072,14 +1067,6 @@ const useMintPerp = (marketAddr) => {
|
|
|
1072
1067
|
if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
|
|
1073
1068
|
if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
|
|
1074
1069
|
if (!operator.auth) await signMessage();
|
|
1075
|
-
if (!hasEnoughPerms) await setOperatorPerms({
|
|
1076
|
-
operator: operatorAddr,
|
|
1077
|
-
canMint: true,
|
|
1078
|
-
canExtend: true,
|
|
1079
|
-
canExercise: true,
|
|
1080
|
-
canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
|
|
1081
|
-
spendingApproval: maxUint256
|
|
1082
|
-
});
|
|
1083
1070
|
const market = getTimelockMarket(marketAddr, client);
|
|
1084
1071
|
const validStrikeTick = getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
|
|
1085
1072
|
const [premium, protocolFee] = await market.read.calculatePremium([
|
|
@@ -1089,7 +1076,16 @@ const useMintPerp = (marketAddr) => {
|
|
|
1089
1076
|
duration,
|
|
1090
1077
|
0
|
|
1091
1078
|
]);
|
|
1092
|
-
|
|
1079
|
+
const maxPremium = (premium + protocolFee) * 11n / 10n;
|
|
1080
|
+
if (!hasEnoughPerms) await setOperatorPerms({
|
|
1081
|
+
operator: operatorAddr,
|
|
1082
|
+
canMint: true,
|
|
1083
|
+
canExtend: true,
|
|
1084
|
+
canExercise: true,
|
|
1085
|
+
canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
|
|
1086
|
+
spendingApproval: maxPremium
|
|
1087
|
+
});
|
|
1088
|
+
await askForApproval(payoutAsset, marketAddr, maxPremium);
|
|
1093
1089
|
await operator.mintPerp({
|
|
1094
1090
|
marketAddr,
|
|
1095
1091
|
amount,
|
|
@@ -1097,16 +1093,9 @@ const useMintPerp = (marketAddr) => {
|
|
|
1097
1093
|
duration,
|
|
1098
1094
|
strikeTick: validStrikeTick
|
|
1099
1095
|
});
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
true
|
|
1104
|
-
] });
|
|
1105
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
1106
|
-
"userOptions",
|
|
1107
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1108
|
-
false
|
|
1109
|
-
] });
|
|
1096
|
+
await sleep(200);
|
|
1097
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1098
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1110
1099
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1111
1100
|
};
|
|
1112
1101
|
return useMutation({ mutationFn: mintPerp });
|
|
@@ -1116,22 +1105,14 @@ const useMintPerp = (marketAddr) => {
|
|
|
1116
1105
|
//#region src/hooks/perps/useClosePerp.ts
|
|
1117
1106
|
const useClosePerp = () => {
|
|
1118
1107
|
const queryClient = useQueryClient();
|
|
1119
|
-
const { address } = useAccount();
|
|
1120
1108
|
const { operator, signMessage: { mutateAsync: signMessage } } = usePerpsOperator();
|
|
1121
1109
|
return useMutation({ mutationFn: async (body) => {
|
|
1122
1110
|
if (!operator) throw new Error("Operator not connected");
|
|
1123
1111
|
if (!operator.auth) await signMessage();
|
|
1124
1112
|
await operator.exercisePerp(body);
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
true
|
|
1129
|
-
] });
|
|
1130
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
1131
|
-
"userOptions",
|
|
1132
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1133
|
-
false
|
|
1134
|
-
] });
|
|
1113
|
+
await sleep(200);
|
|
1114
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1115
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1135
1116
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1136
1117
|
} });
|
|
1137
1118
|
};
|
|
@@ -1216,16 +1197,33 @@ const usePriceAtTick = (tick, poolAddr) => {
|
|
|
1216
1197
|
token1Decimals
|
|
1217
1198
|
]);
|
|
1218
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
|
+
};
|
|
1219
1209
|
|
|
1220
1210
|
//#endregion
|
|
1221
1211
|
//#region src/hooks/pool/useCurrentPrice.ts
|
|
1222
1212
|
const useCurrentPrice = (poolAddr) => {
|
|
1223
|
-
const
|
|
1224
|
-
const currentPrice =
|
|
1213
|
+
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolAddr);
|
|
1214
|
+
const currentPrice = usePriceSqrtPriceX96(sqrtPriceX96, poolAddr);
|
|
1225
1215
|
return useMemo(() => ({
|
|
1226
1216
|
currentPrice,
|
|
1227
|
-
|
|
1228
|
-
|
|
1217
|
+
sqrtPriceX96,
|
|
1218
|
+
currentTick: {
|
|
1219
|
+
exact,
|
|
1220
|
+
rounded
|
|
1221
|
+
}
|
|
1222
|
+
}), [
|
|
1223
|
+
currentPrice,
|
|
1224
|
+
exact,
|
|
1225
|
+
rounded
|
|
1226
|
+
]);
|
|
1229
1227
|
};
|
|
1230
1228
|
|
|
1231
1229
|
//#endregion
|
|
@@ -1440,5 +1438,5 @@ const useVaultTVL = (vaultAddr) => {
|
|
|
1440
1438
|
};
|
|
1441
1439
|
|
|
1442
1440
|
//#endregion
|
|
1443
|
-
export { TimelockProvider, 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, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
|
1441
|
+
export { TimelockProvider, 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 };
|
|
1444
1442
|
//# sourceMappingURL=client.js.map
|