timelock-sdk 0.0.261 → 0.0.263

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.cjs CHANGED
@@ -53,9 +53,9 @@ var PerpsOperator = class {
53
53
  #writeRequest = async (path, body) => {
54
54
  return this.#request(this.#writeUrl, path, body);
55
55
  };
56
- getOperatorAddresses = async () => {
57
- const { addresses } = await this.#readRequest("api/operator/addresses");
58
- return addresses;
56
+ getOperatorAddress = async () => {
57
+ const { address } = await this.#readRequest("api/operator/address");
58
+ return address;
59
59
  };
60
60
  getUserPerps = async (userAddr, marketAddr, type, offset = 0, limit = 1e3) => {
61
61
  const params = new URLSearchParams({
@@ -1135,9 +1135,9 @@ const usePerpsOperator = () => {
1135
1135
  const { address: userAddr } = (0, wagmi.useConnection)();
1136
1136
  const { perpsOperator: operator } = useTimelockConfig();
1137
1137
  const { mutateAsync: signMessageAsync } = (0, wagmi.useSignMessage)();
1138
- const { data: addresses } = (0, _tanstack_react_query.useQuery)({
1139
- queryKey: ["perpsOperatorAddresses", operator || "--"],
1140
- queryFn: () => operator === null || operator === void 0 ? void 0 : operator.getOperatorAddresses(),
1138
+ const { data: address } = (0, _tanstack_react_query.useQuery)({
1139
+ queryKey: ["perpsOperatorAddress", operator || "--"],
1140
+ queryFn: () => operator === null || operator === void 0 ? void 0 : operator.getOperatorAddress(),
1141
1141
  staleTime: 1e4,
1142
1142
  refetchInterval: 1e4,
1143
1143
  enabled: !!operator
@@ -1145,9 +1145,9 @@ const usePerpsOperator = () => {
1145
1145
  const validateAndSetAuth = async (message, signature) => {
1146
1146
  if (!operator || !userAddr) return;
1147
1147
  try {
1148
- const { address, validUntil } = await operator.validateAuthMessage(message, signature);
1148
+ const { address: address$1, validUntil } = await operator.validateAuthMessage(message, signature);
1149
1149
  if (validUntil < Date.now()) throw new Error("Signature expired");
1150
- if (address.toLowerCase() !== userAddr.toLowerCase()) throw new Error("Valid signature but different user address");
1150
+ if (address$1.toLowerCase() !== userAddr.toLowerCase()) throw new Error("Valid signature but different user address");
1151
1151
  operator.setAuth(message, signature);
1152
1152
  } catch (error) {
1153
1153
  clearSignature(userAddr);
@@ -1162,7 +1162,7 @@ const usePerpsOperator = () => {
1162
1162
  }, [userAddr, operator]);
1163
1163
  return {
1164
1164
  operator,
1165
- addresses,
1165
+ address,
1166
1166
  signMessage: (0, _tanstack_react_query.useMutation)({ mutationFn: async () => {
1167
1167
  if (!operator) throw new Error("Operator not initialized");
1168
1168
  if (!userAddr) throw new Error("Wallet not connected");
@@ -1229,36 +1229,33 @@ const useMintPerp = (marketAddr) => {
1229
1229
  const queryClient = (0, _tanstack_react_query.useQueryClient)();
1230
1230
  const client = (0, wagmi.useClient)();
1231
1231
  const { address } = (0, wagmi.useConnection)();
1232
- const { operator, addresses: operatorAddresses, signMessage: { mutateAsync: signMessage } } = usePerpsOperator();
1232
+ const { operator, address: operatorAddr, signMessage: { mutateAsync: signMessage } } = usePerpsOperator();
1233
1233
  const { poolManager, poolKey, optionAssetIsToken0, payoutAsset } = useMarketData(marketAddr);
1234
1234
  const { tickSpacing } = usePoolData(poolManager, poolKey);
1235
1235
  const { askForApproval } = useApproval();
1236
1236
  const { mutateAsync: setOperatorPerms } = useSetOperatorPerms(marketAddr);
1237
1237
  const { refetch: refetchOperators } = useUserOperators(address, marketAddr);
1238
1238
  const { refetch: refetchCurrentTick } = useCurrentTick(poolManager, poolKey);
1239
- const updateOperatorPermsIfNeeded = async (requiredSpendingApproval) => {
1240
- if (!operatorAddresses) return;
1239
+ const updateOperatorPermsIfNeeded = async (requiredApproval) => {
1240
+ if (!operatorAddr) throw new Error("Operator address not found");
1241
1241
  const { data: operators = [] } = await refetchOperators();
1242
- const permsToUpdate = [];
1243
- for (const operatorAddr of operatorAddresses) {
1244
- const userPerms = operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase());
1245
- if (!(userPerms && userPerms.canMint && userPerms.canExtend && userPerms.canExercise && userPerms.spendingApproval > requiredSpendingApproval)) permsToUpdate.push({
1246
- operator: operatorAddr,
1247
- canMint: true,
1248
- canExtend: true,
1249
- canExercise: true,
1250
- canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) ?? false,
1251
- spendingApproval: viem.maxUint256
1252
- });
1253
- }
1254
- if (permsToUpdate.length > 0) await setOperatorPerms(permsToUpdate);
1242
+ const userPerms = operators.find((op) => op.operatorAddr.toLowerCase() === operatorAddr.toLowerCase());
1243
+ if (userPerms && userPerms.canMint && userPerms.canExtend && userPerms.canExercise && userPerms.spendingApproval > requiredApproval) return;
1244
+ await setOperatorPerms([{
1245
+ operator: operatorAddr,
1246
+ canMint: true,
1247
+ canExtend: true,
1248
+ canExercise: true,
1249
+ canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) ?? false,
1250
+ spendingApproval: requiredApproval
1251
+ }]);
1255
1252
  };
1256
1253
  const mintPerp = async (data) => {
1257
1254
  const { optionType, amount, duration, strikeTick, maxPremium, maxSteps } = data;
1258
1255
  if (!client || !address) throw new Error("Wallet not connected");
1259
1256
  if (!marketAddr) throw new Error("Market address not found");
1260
1257
  if (!tickSpacing) throw new Error("Pool data not found");
1261
- if (!operator || !operatorAddresses) throw new Error("Operator address not found");
1258
+ if (!operator) throw new Error("Operator address not found");
1262
1259
  if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
1263
1260
  if (!operator.auth) await signMessage();
1264
1261
  const { data: { currentTick } = {} } = await refetchCurrentTick();
@@ -1424,7 +1421,7 @@ const useMarketPriceHistory = (marketAddr, resolution, startTimestamp, endTimest
1424
1421
  //#endregion
1425
1422
  //#region src/hooks/pool/usePoolVolume.ts
1426
1423
  const usePoolVolume = (poolManager, poolKey) => {
1427
- const { uniV4GraphqlClient } = useTimelockConfig();
1424
+ const { univ4GraphqlClient } = useTimelockConfig();
1428
1425
  const poolId = (0, react.useMemo)(() => poolKey ? getPoolId(poolKey) : void 0, [poolKey]);
1429
1426
  return (0, _tanstack_react_query.useQuery)({
1430
1427
  queryKey: [
@@ -1433,7 +1430,7 @@ const usePoolVolume = (poolManager, poolKey) => {
1433
1430
  (poolManager === null || poolManager === void 0 ? void 0 : poolManager.toLowerCase()) || "--"
1434
1431
  ],
1435
1432
  queryFn: async () => {
1436
- const result = await uniV4GraphqlClient.GetPoolVolume({ poolId });
1433
+ const result = await univ4GraphqlClient.GetPoolVolume({ poolId });
1437
1434
  return {
1438
1435
  ...result.Pool[0],
1439
1436
  volume0: BigInt(result.Pool[0].volume0),
@@ -1446,7 +1443,7 @@ const usePoolVolume = (poolManager, poolKey) => {
1446
1443
  positionCount: BigInt(result.Pool[0].positionCount)
1447
1444
  };
1448
1445
  },
1449
- enabled: !!poolId && !!uniV4GraphqlClient
1446
+ enabled: !!poolId && !!univ4GraphqlClient
1450
1447
  });
1451
1448
  };
1452
1449