timelock-sdk 0.0.130 → 0.0.132

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.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import "./uniswapMathLens-DtacRMPz.cjs";
2
- import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-CEpht_eW.cjs";
1
+ import "./uniswapMathLens-EIuBr8ZZ.cjs";
2
+ import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-VhkUQ-HJ.cjs";
3
3
  export { ExerciseOptionEvent, ExtendEvent, LiquidityBlockData, MintOptionEvent, OptionData, OptionEvent, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMarketPriceHistory, 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-JKcBN1v_.js";
2
- import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-BrI6wGfs.js";
1
+ import "./uniswapMathLens-BGtGI-Nm.js";
2
+ import { $ as OptionEvent, Ct as OptionData, Dt as useCurrentMarket, Et as TimelockProvider, G as useClosedUserPerps, H as useUserOperators, J as useClosePerp, K as useUserPerps, Ot as useTimelockConfig, Q as MintOptionEvent, St as useExerciseOption, Tt as useClosedUserOptions, U as useOperatorPerms, V as useSetOperatorPerms, W as useActiveUserPerps, X as ExerciseOptionEvent, Y as useMintPerp, Z as ExtendEvent, _ as useCurrentPrice, a as batchGetAmountsFromLiquidity, at as useMaxPositionSize, c as useLiquidityBlocks, d as usePriceHistory, et as useOptionTimeline, f as usePriceAtTick, g as useCurrentTick, h as usePoolData, i as useVaultData, it as useMintOption, l as useBurnLiquidity, m as UniswapPoolData, n as useLens, nt as useOptionPremium, o as useMintLiquidity, p as usePriceSqrtPriceX96, q as usePerpsOperator, r as useVaultTVL, rt as useOptionPnl, s as LiquidityBlockData, t as useApproval, tt as useExtendOption, u as useMarketPriceHistory, wt as useActiveUserOptions, xt as useMarketData } from "./client-gQvld5wF.js";
3
3
  export { ExerciseOptionEvent, ExtendEvent, LiquidityBlockData, MintOptionEvent, OptionData, OptionEvent, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMarketPriceHistory, 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,9 +1,9 @@
1
1
  'use client';
2
2
 
3
3
 
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-CUg_L5bP.js";
6
- import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
4
+ import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-Hq7O-Hry.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, t as getPayoutAtPrice, v as getAmountsFromLiquidity, x as getPriceAtTick, y as getNearestValidStrikeTick, z as swappers } from "./optionUtils-DTutSZPI.js";
6
+ import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-p81IjmWe.js";
7
7
  import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
8
8
  import React, { createContext, useContext, useEffect, useMemo } from "react";
9
9
  import { useAccount, useBalance, useChainId, useClient, useReadContract, useSignMessage, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
@@ -569,7 +569,7 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) =>
569
569
  //#region src/hooks/pool/useCurrentTick.ts
570
570
  const useCurrentTick = (poolAddr) => {
571
571
  const { tickSpacing } = usePoolData(poolAddr);
572
- const { data,...rest } = useReadContract({
572
+ const { data, ...rest } = useReadContract({
573
573
  address: poolAddr,
574
574
  abi: uniswapV3PoolAbi,
575
575
  functionName: "slot0",
@@ -797,7 +797,7 @@ const useUserOptions = (userAddr, marketAddr, active = false) => {
797
797
  const { graphqlClient } = useTimelockConfig();
798
798
  userAddr = userAddr === null || userAddr === void 0 ? void 0 : userAddr.toLowerCase();
799
799
  marketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
800
- const { data,...rest } = useQuery({
800
+ const { data, ...rest } = useQuery({
801
801
  queryKey: [
802
802
  "userOptions",
803
803
  userAddr || "--",
@@ -833,7 +833,7 @@ const useUserOptions = (userAddr, marketAddr, active = false) => {
833
833
  enabled: !!userAddr && !!marketAddr && !!graphqlClient
834
834
  });
835
835
  return {
836
- data: data || EMPTY_ARRAY$1,
836
+ data: data || EMPTY_ARRAY,
837
837
  ...rest
838
838
  };
839
839
  };
@@ -891,7 +891,7 @@ const useExtendOption = (marketAddr) => {
891
891
  const useOptionTimeline = (marketAddr, optionId) => {
892
892
  const { graphqlClient } = useTimelockConfig();
893
893
  marketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
894
- const { data,...rest } = useQuery({
894
+ const { data, ...rest } = useQuery({
895
895
  queryKey: [
896
896
  "optionTimeline",
897
897
  marketAddr || "--",
@@ -953,7 +953,7 @@ const useOptionTimeline = (marketAddr, optionId) => {
953
953
  enabled: !!marketAddr && optionId !== void 0 && !!graphqlClient
954
954
  });
955
955
  return {
956
- data: data || EMPTY_ARRAY$1,
956
+ data: data || EMPTY_ARRAY,
957
957
  ...rest
958
958
  };
959
959
  };
@@ -1031,66 +1031,6 @@ const usePerpsOperator = () => {
1031
1031
  };
1032
1032
  };
1033
1033
 
1034
- //#endregion
1035
- //#region src/hooks/operators/useUserOperators.ts
1036
- const useUserOperators = (userAddr, marketAddr) => {
1037
- const { graphqlClient } = useTimelockConfig();
1038
- const { data,...rest } = useQuery({
1039
- queryKey: [
1040
- "userOperators",
1041
- (userAddr === null || userAddr === void 0 ? void 0 : userAddr.toLowerCase()) || "--",
1042
- (marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase()) || "--"
1043
- ],
1044
- queryFn: async () => {
1045
- if (!userAddr || !marketAddr) return void 0;
1046
- return (await graphqlClient.GetUserMarketOperators({
1047
- userAddr: userAddr.toLowerCase(),
1048
- marketAddr: marketAddr.toLowerCase()
1049
- })).UserMarketOperator.map((operator) => ({
1050
- ...operator,
1051
- spendingApproval: BigInt(operator.spendingApproval),
1052
- operatorAddr: operator.operator.address.toLowerCase()
1053
- }));
1054
- },
1055
- enabled: !!userAddr && !!marketAddr && !!graphqlClient
1056
- });
1057
- return {
1058
- ...rest,
1059
- data: data || EMPTY_ARRAY$1
1060
- };
1061
- };
1062
-
1063
- //#endregion
1064
- //#region src/hooks/operators/useSetOperatorPerms.ts
1065
- const useSetOperatorPerms = (marketAddr) => {
1066
- const queryClient = useQueryClient();
1067
- const client = useClient();
1068
- const { address } = useAccount();
1069
- const { writeContractAsync } = useWriteContract();
1070
- const setOperatorPerms = async ({ operator, canExtend, canExercise, canTransfer, canMint, spendingApproval }) => {
1071
- if (!client || !address) throw new Error("Wallet not connected");
1072
- if (!marketAddr) throw new Error("Market address not available");
1073
- const hash = await writeContractAsync({
1074
- address: marketAddr,
1075
- abi: optionsMarketAbi,
1076
- functionName: "setOperatorPerms",
1077
- args: [
1078
- operator,
1079
- canExtend,
1080
- canExercise,
1081
- canTransfer,
1082
- canMint,
1083
- spendingApproval
1084
- ]
1085
- });
1086
- await waitForTransactionReceipt(client, { hash });
1087
- queryClient.invalidateQueries({ queryKey: ["userOperators"] });
1088
- queryClient.invalidateQueries({ queryKey: ["readContract"] });
1089
- return hash;
1090
- };
1091
- return useMutation({ mutationFn: setOperatorPerms });
1092
- };
1093
-
1094
1034
  //#endregion
1095
1035
  //#region src/hooks/perps/useMintPerp.ts
1096
1036
  const useMintPerp = (marketAddr) => {
@@ -1099,13 +1039,9 @@ const useMintPerp = (marketAddr) => {
1099
1039
  const { address } = useAccount();
1100
1040
  const { operator, address: operatorAddr, signMessage: { mutateAsync: signMessage } } = usePerpsOperator();
1101
1041
  const { askForApproval } = useApproval();
1102
- const { data: operators } = useUserOperators(address, marketAddr);
1103
- const { mutateAsync: setOperatorPerms } = useSetOperatorPerms(marketAddr);
1104
1042
  const { pool, optionAssetIsToken0, payoutAsset } = useMarketData(marketAddr);
1105
1043
  const { tickSpacing } = usePoolData(pool);
1106
1044
  const { refetch: refetchCurrentTick } = useCurrentTick(pool);
1107
- const userPerms = operatorAddr ? operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase()) : void 0;
1108
- const hasEnoughPerms = userPerms && userPerms.canMint && userPerms.canExtend && userPerms.canExercise;
1109
1045
  const mintPerp = async (data) => {
1110
1046
  const { optionType, amount, duration, strikeTick } = data;
1111
1047
  if (!client || !address) throw new Error("Wallet not connected");
@@ -1125,16 +1061,7 @@ const useMintPerp = (marketAddr) => {
1125
1061
  duration,
1126
1062
  0
1127
1063
  ]);
1128
- const maxPremium = (premium + protocolFee) * 11n / 10n;
1129
- if (!hasEnoughPerms) await setOperatorPerms({
1130
- operator: operatorAddr,
1131
- canMint: true,
1132
- canExtend: true,
1133
- canExercise: true,
1134
- canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
1135
- spendingApproval: maxPremium
1136
- });
1137
- await askForApproval(payoutAsset, marketAddr, maxPremium);
1064
+ await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
1138
1065
  await operator.mintPerp({
1139
1066
  marketAddr,
1140
1067
  amount,
@@ -1168,12 +1095,12 @@ const useClosePerp = () => {
1168
1095
 
1169
1096
  //#endregion
1170
1097
  //#region src/hooks/perps/useUserPerps.ts
1171
- const EMPTY_ARRAY = [];
1098
+ const EMPTY_ARRAY$1 = [];
1172
1099
  const useUserPerps = (marketAddr, userAddr, type) => {
1173
1100
  const { operator } = usePerpsOperator();
1174
1101
  userAddr = userAddr === null || userAddr === void 0 ? void 0 : userAddr.toLowerCase();
1175
1102
  marketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
1176
- const { data,...rest } = useQuery({
1103
+ const { data, ...rest } = useQuery({
1177
1104
  queryKey: [
1178
1105
  "userPerps",
1179
1106
  type,
@@ -1186,7 +1113,7 @@ const useUserPerps = (marketAddr, userAddr, type) => {
1186
1113
  refetchInterval: 1e4
1187
1114
  });
1188
1115
  return {
1189
- data: data || EMPTY_ARRAY,
1116
+ data: data || EMPTY_ARRAY$1,
1190
1117
  ...rest
1191
1118
  };
1192
1119
  };
@@ -1205,7 +1132,7 @@ const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
1205
1132
  address: userAddr,
1206
1133
  token: payoutAsset
1207
1134
  });
1208
- const { data,...rest } = useReadContract({
1135
+ const { data, ...rest } = useReadContract({
1209
1136
  abi: optionsMarketAbi,
1210
1137
  address: marketAddr,
1211
1138
  functionName: "operatorPerms",
@@ -1238,6 +1165,66 @@ const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
1238
1165
  };
1239
1166
  };
1240
1167
 
1168
+ //#endregion
1169
+ //#region src/hooks/operators/useUserOperators.ts
1170
+ const useUserOperators = (userAddr, marketAddr) => {
1171
+ const { graphqlClient } = useTimelockConfig();
1172
+ const { data, ...rest } = useQuery({
1173
+ queryKey: [
1174
+ "userOperators",
1175
+ (userAddr === null || userAddr === void 0 ? void 0 : userAddr.toLowerCase()) || "--",
1176
+ (marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase()) || "--"
1177
+ ],
1178
+ queryFn: async () => {
1179
+ if (!userAddr || !marketAddr) return void 0;
1180
+ return (await graphqlClient.GetUserMarketOperators({
1181
+ userAddr: userAddr.toLowerCase(),
1182
+ marketAddr: marketAddr.toLowerCase()
1183
+ })).UserMarketOperator.map((operator) => ({
1184
+ ...operator,
1185
+ spendingApproval: BigInt(operator.spendingApproval),
1186
+ operatorAddr: operator.operator.address.toLowerCase()
1187
+ }));
1188
+ },
1189
+ enabled: !!userAddr && !!marketAddr && !!graphqlClient
1190
+ });
1191
+ return {
1192
+ ...rest,
1193
+ data: data || EMPTY_ARRAY
1194
+ };
1195
+ };
1196
+
1197
+ //#endregion
1198
+ //#region src/hooks/operators/useSetOperatorPerms.ts
1199
+ const useSetOperatorPerms = (marketAddr) => {
1200
+ const queryClient = useQueryClient();
1201
+ const client = useClient();
1202
+ const { address } = useAccount();
1203
+ const { writeContractAsync } = useWriteContract();
1204
+ const setOperatorPerms = async ({ operator, canExtend, canExercise, canTransfer, canMint, spendingApproval }) => {
1205
+ if (!client || !address) throw new Error("Wallet not connected");
1206
+ if (!marketAddr) throw new Error("Market address not available");
1207
+ const hash = await writeContractAsync({
1208
+ address: marketAddr,
1209
+ abi: optionsMarketAbi,
1210
+ functionName: "setOperatorPerms",
1211
+ args: [
1212
+ operator,
1213
+ canExtend,
1214
+ canExercise,
1215
+ canTransfer,
1216
+ canMint,
1217
+ spendingApproval
1218
+ ]
1219
+ });
1220
+ await waitForTransactionReceipt(client, { hash });
1221
+ queryClient.invalidateQueries({ queryKey: ["userOperators"] });
1222
+ queryClient.invalidateQueries({ queryKey: ["readContract"] });
1223
+ return hash;
1224
+ };
1225
+ return useMutation({ mutationFn: setOperatorPerms });
1226
+ };
1227
+
1241
1228
  //#endregion
1242
1229
  //#region src/hooks/pool/usePriceHistory.ts
1243
1230
  const usePriceHistory = (pool, token, resolution, startTimestamp, endTimestamp) => {
@@ -1307,12 +1294,12 @@ const useBurnLiquidity = (vaultAddr) => {
1307
1294
  if (!timelockLens || !vaultAddr) throw new Error("Vault/lens not available");
1308
1295
  if (positions.length === 1) await burn(positions[0].tickLower, positions[0].tickUpper, positions[0].liquidity);
1309
1296
  else {
1310
- const refTick = await timelockLens.read.getRefTick([vaultAddr, positions[0].tickLower]);
1297
+ const refTick = await timelockLens.read.getRefTick([vaultAddr, Math.min(...positions.map((p) => p.tickLower))]);
1311
1298
  await waitForTransactionReceipt(client, { hash: await writeContractAsync({
1312
1299
  address: vaultAddr,
1313
1300
  abi: singleOwnerVaultAbi,
1314
1301
  functionName: "multicall",
1315
- args: [positions.map((p, i) => encodeFunctionData({
1302
+ args: [positions.map((p) => encodeFunctionData({
1316
1303
  abi: singleOwnerVaultAbi,
1317
1304
  functionName: "burn",
1318
1305
  args: [
@@ -1341,7 +1328,7 @@ const useBurnLiquidity = (vaultAddr) => {
1341
1328
  //#region src/hooks/vault/useLiquidityBlocks.ts
1342
1329
  const useLiquidityBlocks = (vaultAddr) => {
1343
1330
  const { timelockLens } = useLens();
1344
- const { data: blocks = [],...rest } = useReadContract({
1331
+ const { data: blocks = [], ...rest } = useReadContract({
1345
1332
  address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
1346
1333
  abi: lensAbi,
1347
1334
  functionName: "getAllBlocks",