timelock-sdk 0.0.113 → 0.0.115

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
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
 
4
- const require_optionUtils = require('./optionUtils-DNAmXoEX.cjs');
4
+ const require_optionUtils = require('./optionUtils-DQakRJ_U.cjs');
5
5
  const require_optionsMarket = require('./optionsMarket-D6zrIXc3.cjs');
6
6
  const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
7
7
  let viem = require("viem");
@@ -487,6 +487,10 @@ const usePoolData = (poolAddr) => {
487
487
  return data || {};
488
488
  };
489
489
 
490
+ //#endregion
491
+ //#region src/lib/utils.ts
492
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
493
+
490
494
  //#endregion
491
495
  //#region src/hooks/options/useExerciseOption.ts
492
496
  const swapper = "0x2c79DD9797C35A3D966C2716739542a282BB5540";
@@ -519,16 +523,9 @@ const useExerciseOption = (marketAddr) => {
519
523
  ]
520
524
  });
521
525
  await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
522
- queryClient.invalidateQueries({ queryKey: [
523
- "userOptions",
524
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
525
- true
526
- ] });
527
- queryClient.invalidateQueries({ queryKey: [
528
- "userOptions",
529
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
530
- false
531
- ] });
526
+ await sleep(400);
527
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
528
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
532
529
  queryClient.invalidateQueries({ queryKey: ["readContract"] });
533
530
  return hash;
534
531
  };
@@ -587,10 +584,12 @@ const useCurrentTick = (poolAddr) => {
587
584
  args: []
588
585
  });
589
586
  return (0, react.useMemo)(() => {
587
+ const sqrtPriceX96 = data === null || data === void 0 ? void 0 : data[0];
590
588
  const exact = data === null || data === void 0 ? void 0 : data[1];
591
589
  return {
592
590
  exact,
593
- rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0
591
+ rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
592
+ sqrtPriceX96
594
593
  };
595
594
  }, [data, tickSpacing]);
596
595
  };
@@ -661,16 +660,9 @@ const useMintOption = (marketAddr) => {
661
660
  ]
662
661
  });
663
662
  await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
664
- queryClient.invalidateQueries({ queryKey: [
665
- "userOptions",
666
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
667
- true
668
- ] });
669
- queryClient.invalidateQueries({ queryKey: [
670
- "userOptions",
671
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
672
- false
673
- ] });
663
+ await sleep(400);
664
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
665
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
674
666
  queryClient.invalidateQueries({ queryKey: ["readContract"] });
675
667
  return hash;
676
668
  };
@@ -842,7 +834,10 @@ const useExtendOption = (marketAddr) => {
842
834
  ]
843
835
  });
844
836
  await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
845
- queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
837
+ await sleep(400);
838
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
839
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
840
+ queryClient.invalidateQueries({ queryKey: ["readContract"] });
846
841
  return hash;
847
842
  };
848
843
  return (0, __tanstack_react_query.useMutation)({ mutationFn: extendOption });
@@ -1106,16 +1101,9 @@ const useMintPerp = (marketAddr) => {
1106
1101
  duration,
1107
1102
  strikeTick: validStrikeTick
1108
1103
  });
1109
- queryClient.invalidateQueries({ queryKey: [
1110
- "userOptions",
1111
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
1112
- true
1113
- ] });
1114
- queryClient.invalidateQueries({ queryKey: [
1115
- "userOptions",
1116
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
1117
- false
1118
- ] });
1104
+ await sleep(400);
1105
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
1106
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
1119
1107
  queryClient.invalidateQueries({ queryKey: ["readContract"] });
1120
1108
  };
1121
1109
  return (0, __tanstack_react_query.useMutation)({ mutationFn: mintPerp });
@@ -1125,22 +1113,14 @@ const useMintPerp = (marketAddr) => {
1125
1113
  //#region src/hooks/perps/useClosePerp.ts
1126
1114
  const useClosePerp = () => {
1127
1115
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
1128
- const { address } = (0, wagmi.useAccount)();
1129
1116
  const { operator, signMessage: { mutateAsync: signMessage } } = usePerpsOperator();
1130
1117
  return (0, __tanstack_react_query.useMutation)({ mutationFn: async (body) => {
1131
1118
  if (!operator) throw new Error("Operator not connected");
1132
1119
  if (!operator.auth) await signMessage();
1133
1120
  await operator.exercisePerp(body);
1134
- queryClient.invalidateQueries({ queryKey: [
1135
- "userOptions",
1136
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
1137
- true
1138
- ] });
1139
- queryClient.invalidateQueries({ queryKey: [
1140
- "userOptions",
1141
- address === null || address === void 0 ? void 0 : address.toLowerCase(),
1142
- false
1143
- ] });
1121
+ await sleep(400);
1122
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
1123
+ queryClient.invalidateQueries({ queryKey: ["userOptions"] });
1144
1124
  queryClient.invalidateQueries({ queryKey: ["readContract"] });
1145
1125
  } });
1146
1126
  };
@@ -1225,16 +1205,33 @@ const usePriceAtTick = (tick, poolAddr) => {
1225
1205
  token1Decimals
1226
1206
  ]);
1227
1207
  };
1208
+ const usePriceSqrtPriceX96 = (sqrtPriceX96, poolAddr) => {
1209
+ const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
1210
+ const priceBigInt = (0, react.useMemo)(() => sqrtPriceX96 !== void 0 ? require_optionUtils.getPriceSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
1211
+ return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
1212
+ priceBigInt,
1213
+ token0Decimals,
1214
+ token1Decimals
1215
+ ]);
1216
+ };
1228
1217
 
1229
1218
  //#endregion
1230
1219
  //#region src/hooks/pool/useCurrentPrice.ts
1231
1220
  const useCurrentPrice = (poolAddr) => {
1232
- const currentTick = useCurrentTick(poolAddr);
1233
- const currentPrice = usePriceAtTick(currentTick.exact, poolAddr);
1221
+ const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolAddr);
1222
+ const currentPrice = usePriceSqrtPriceX96(sqrtPriceX96, poolAddr);
1234
1223
  return (0, react.useMemo)(() => ({
1235
1224
  currentPrice,
1236
- currentTick
1237
- }), [currentPrice, currentTick]);
1225
+ sqrtPriceX96,
1226
+ currentTick: {
1227
+ exact,
1228
+ rounded
1229
+ }
1230
+ }), [
1231
+ currentPrice,
1232
+ exact,
1233
+ rounded
1234
+ ]);
1238
1235
  };
1239
1236
 
1240
1237
  //#endregion
@@ -1478,6 +1475,7 @@ exports.usePerpsOperator = usePerpsOperator;
1478
1475
  exports.usePoolData = usePoolData;
1479
1476
  exports.usePriceAtTick = usePriceAtTick;
1480
1477
  exports.usePriceHistory = usePriceHistory;
1478
+ exports.usePriceSqrtPriceX96 = usePriceSqrtPriceX96;
1481
1479
  exports.useSetOperatorPerms = useSetOperatorPerms;
1482
1480
  exports.useTimelockConfig = useTimelockConfig;
1483
1481
  exports.useUserOperators = useUserOperators;