timelock-sdk 0.0.257 → 0.0.259

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
@@ -121,7 +121,7 @@ var PerpsOperator = class {
121
121
  //#endregion
122
122
  //#region src/providers/TimelockProvider.tsx
123
123
  const TimelockContext = (0, react.createContext)(void 0);
124
- const TimelockProvider = ({ children, marketData, timelockGraphqlUrl, univ4GraphqlUrl, perpsOperatorUrl }) => {
124
+ const TimelockProvider = ({ children, marketData, timelockGraphqlUrl, univ4GraphqlUrl, perpsOperatorReadUrl, perpsOperatorWriteUrl }) => {
125
125
  const timelockGraphqlClient = (0, react.useMemo)(() => {
126
126
  if (!timelockGraphqlUrl) return;
127
127
  return require_graphql.getTimelockGraphqlClient(timelockGraphqlUrl);
@@ -131,9 +131,9 @@ const TimelockProvider = ({ children, marketData, timelockGraphqlUrl, univ4Graph
131
131
  return require_graphql.getUniv4GraphqlClient(univ4GraphqlUrl);
132
132
  }, [univ4GraphqlUrl]);
133
133
  const perpsOperator = (0, react.useMemo)(() => {
134
- if (!perpsOperatorUrl) return;
135
- return new PerpsOperator(perpsOperatorUrl);
136
- }, [perpsOperatorUrl]);
134
+ if (!perpsOperatorReadUrl || !perpsOperatorWriteUrl) return;
135
+ return new PerpsOperator(perpsOperatorReadUrl, perpsOperatorWriteUrl);
136
+ }, [perpsOperatorReadUrl, perpsOperatorWriteUrl]);
137
137
  const contextValue = (0, react.useMemo)(() => ({
138
138
  marketData: marketData || {},
139
139
  timelockGraphqlUrl,
@@ -141,7 +141,8 @@ const TimelockProvider = ({ children, marketData, timelockGraphqlUrl, univ4Graph
141
141
  perpsOperator,
142
142
  univ4GraphqlClient,
143
143
  timelockGraphqlClient,
144
- perpsOperatorUrl
144
+ perpsOperatorReadUrl,
145
+ perpsOperatorWriteUrl
145
146
  }), [
146
147
  marketData,
147
148
  timelockGraphqlUrl,
@@ -149,7 +150,8 @@ const TimelockProvider = ({ children, marketData, timelockGraphqlUrl, univ4Graph
149
150
  perpsOperator,
150
151
  timelockGraphqlClient,
151
152
  univ4GraphqlClient,
152
- perpsOperatorUrl
153
+ perpsOperatorReadUrl,
154
+ perpsOperatorWriteUrl
153
155
  ]);
154
156
  return /* @__PURE__ */ react.default.createElement(TimelockContext.Provider, { value: contextValue }, children);
155
157
  };
@@ -1199,22 +1201,21 @@ const useSetOperatorPerms = (marketAddr) => {
1199
1201
  const client = (0, wagmi.useClient)();
1200
1202
  const { address } = (0, wagmi.useConnection)();
1201
1203
  const { mutateAsync: writeContractAsync } = (0, wagmi.useWriteContract)();
1202
- const setOperatorPerms = async ({ operators, perms }) => {
1204
+ const setOperatorsPerms = async (perms) => {
1203
1205
  if (!client || !address) throw new Error("Wallet not connected");
1204
1206
  if (!marketAddr) throw new Error("Market address not available");
1205
- if (operators.length !== perms.length) throw new Error("Operators and perms arrays must have the same length");
1206
1207
  const hash = await writeContractAsync({
1207
1208
  address: marketAddr,
1208
1209
  abi: require_stateView.optionsMarketAbi,
1209
1210
  functionName: "setOperatorsPerms",
1210
- args: [operators, perms]
1211
+ args: [perms.map((perm) => perm.operator), perms]
1211
1212
  });
1212
1213
  await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
1213
1214
  queryClient.invalidateQueries({ queryKey: ["userOperators"] });
1214
1215
  queryClient.invalidateQueries({ queryKey: ["readContract"] });
1215
1216
  return hash;
1216
1217
  };
1217
- return (0, _tanstack_react_query.useMutation)({ mutationFn: setOperatorPerms });
1218
+ return (0, _tanstack_react_query.useMutation)({ mutationFn: setOperatorsPerms });
1218
1219
  };
1219
1220
 
1220
1221
  //#endregion
@@ -1233,25 +1234,19 @@ const useMintPerp = (marketAddr) => {
1233
1234
  const updateOperatorPermsIfNeeded = async (requiredSpendingApproval) => {
1234
1235
  if (!operatorAddresses) return;
1235
1236
  const { data: operators = [] } = await refetchOperators();
1236
- const operatorsToUpdate = [];
1237
1237
  const permsToUpdate = [];
1238
1238
  for (const operatorAddr of operatorAddresses) {
1239
1239
  const userPerms = operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase());
1240
- if (!(userPerms && userPerms.canMint && userPerms.canExtend && userPerms.canExercise && userPerms.spendingApproval > requiredSpendingApproval)) {
1241
- operatorsToUpdate.push(operatorAddr);
1242
- permsToUpdate.push({
1243
- canMint: true,
1244
- canExtend: true,
1245
- canExercise: true,
1246
- canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) ?? false,
1247
- spendingApproval: viem.maxUint256
1248
- });
1249
- }
1240
+ if (!(userPerms && userPerms.canMint && userPerms.canExtend && userPerms.canExercise && userPerms.spendingApproval > requiredSpendingApproval)) permsToUpdate.push({
1241
+ operator: operatorAddr,
1242
+ canMint: true,
1243
+ canExtend: true,
1244
+ canExercise: true,
1245
+ canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) ?? false,
1246
+ spendingApproval: viem.maxUint256
1247
+ });
1250
1248
  }
1251
- if (operatorsToUpdate.length > 0) await setOperatorPerms({
1252
- operators: operatorsToUpdate,
1253
- perms: permsToUpdate
1254
- });
1249
+ if (permsToUpdate.length > 0) await setOperatorPerms(permsToUpdate);
1255
1250
  };
1256
1251
  const mintPerp = async (data) => {
1257
1252
  const { optionType, amount, duration, strikeTick } = data;