timelock-sdk 0.0.113 → 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.
@@ -1,13 +1,13 @@
1
- import { n as optionsMarketAbi, r as lensAbi, t as uniswapMathLensAbi } from "./uniswapMathLens-ChJFZ6hc.js";
1
+ import { n as optionsMarketAbi, r as lensAbi, t as uniswapMathLensAbi } from "./uniswapMathLens-B_cHjOOB.cjs";
2
2
  import * as viem0 from "viem";
3
3
  import { Address, Client, GetContractReturnType, Hex, PublicClient } from "viem";
4
- import Big from "big.js";
5
4
  import React, { ReactNode } from "react";
5
+ import "graphql";
6
6
  import { GraphQLClient, RequestOptions } from "graphql-request";
7
7
  import * as _tanstack_react_query0 from "@tanstack/react-query";
8
8
  import { NonUndefinedGuard } from "@tanstack/react-query";
9
- import "graphql";
10
9
  import * as _tanstack_query_core0 from "@tanstack/query-core";
10
+ import Big from "big.js";
11
11
  import * as _wagmi_core0 from "@wagmi/core";
12
12
 
13
13
  //#region src/generated/graphql.d.ts
@@ -36524,6 +36524,7 @@ declare const getCurrentPrice: (poolAddress: string) => Promise<PriceData>;
36524
36524
  //#endregion
36525
36525
  //#region src/lib/liquidityUtils.d.ts
36526
36526
  declare const PRICE_PRECISION: bigint;
36527
+ declare const getPriceSqrtPriceX96: (sqrtPriceX96: bigint) => bigint;
36527
36528
  declare const getPriceAtTick: (tick: number) => bigint;
36528
36529
  declare const getTickAtPrice: (price: bigint) => number;
36529
36530
  declare const getNearestValidStrikeTick: (optionType: "CALL" | "PUT", optionAssetIsToken0: boolean, tickSpacing: number, currentTick: number, strikeTick?: number) => number;
@@ -36542,6 +36543,7 @@ declare const getPayoutAtTick: (option: OptionData, liquidities: bigint[], tick:
36542
36543
  //#region src/hooks/pool/useCurrentPrice.d.ts
36543
36544
  declare const useCurrentPrice: (poolAddr?: Address) => {
36544
36545
  currentPrice: Amount | undefined;
36546
+ sqrtPriceX96: bigint | undefined;
36545
36547
  currentTick: {
36546
36548
  exact: number | undefined;
36547
36549
  rounded: number | undefined;
@@ -36552,6 +36554,7 @@ declare const useCurrentPrice: (poolAddr?: Address) => {
36552
36554
  declare const useCurrentTick: (poolAddr?: Address) => {
36553
36555
  exact: number | undefined;
36554
36556
  rounded: number | undefined;
36557
+ sqrtPriceX96: bigint | undefined;
36555
36558
  };
36556
36559
  //#endregion
36557
36560
  //#region src/hooks/pool/usePoolData.d.ts
@@ -36572,6 +36575,7 @@ declare const usePoolData: (poolAddr?: Address) => Partial<NonUndefined<{
36572
36575
  //#endregion
36573
36576
  //#region src/hooks/pool/usePriceAtTick.d.ts
36574
36577
  declare const usePriceAtTick: (tick?: number, poolAddr?: Address) => Amount | undefined;
36578
+ declare const usePriceSqrtPriceX96: (sqrtPriceX96?: bigint, poolAddr?: Address) => Amount | undefined;
36575
36579
  //#endregion
36576
36580
  //#region src/hooks/pool/usePriceHistory.d.ts
36577
36581
  declare const usePriceHistory: (pool: Address | undefined, resolution: PriceResolution, startTimestamp: Date, endTimestamp: Date) => _tanstack_react_query0.UseQueryResult<PriceDataPoint[], Error>;
@@ -62857,5 +62861,5 @@ declare const useApproval: () => {
62857
62861
  reset: () => void;
62858
62862
  };
62859
62863
  //#endregion
62860
- export { formatCondensed as $, PriceDataPoint as A, usePerpsOperator as B, liquiditiesToAmount1 as C, getErc20 as Ct, token0ToToken1 as D, timelockLenses as Dt, roundTickUp as E, getUniswapMathLens as Et, useUserOperators as F, useExtendOption as G, useMintPerp as H, useOperatorPerms as I, useMintOption as J, useOptionPremium as K, useActiveUserPerps as L, getCurrentPrice as M, getPriceHistory as N, token1ToToken0 as O, uniswapMathLenses as Ot, useSetOperatorPerms as P, formatAmount as Q, useClosedUserPerps as R, liquiditiesToAmount0 as S, UniswapMathLens as St, roundTickDown as T, getTimelockMarket as Tt, OptionTimelineData as U, useClosePerp as V, useOptionTimeline as W, Amount as X, useMaxPositionSize as Y, EMPTY_ARRAY as Z, PRICE_PRECISION as _, useCurrentMarket as _t, batchGetAmountsFromLiquidity as a, unscalePrice as at, getPriceAtTick as b, TimelockMarket as bt, useLiquidityBlocks as c, wrapPrice as ct, usePriceAtTick as d, useMarketData as dt, formatUSD as et, UniswapPoolData as f, useExerciseOption as ft, getPayoutAtTick as g, TimelockProvider as gt, useCurrentPrice as h, useClosedUserOptions as ht, useVaultData as i, unscaleAmount as it, PriceResolution as j, PriceData as k, useBurnLiquidity as l, wrapPriceUnscaled as lt, useCurrentTick as m, useActiveUserOptions as mt, useLens as n, scaleAmount as nt, useMintLiquidity as o, wrapAmount as ot, usePoolData as p, OptionData as pt, useOptionPnl as q, useVaultTVL as r, scalePrice as rt, LiquidityBlockData as s, wrapAmountUnscaled as st, useApproval as t, formatVagueAmount as tt, usePriceHistory as u, zero as ut, getAmountsFromLiquidity as v, useTimelockConfig as vt, liquiditiesToAmounts as w, getTimelockLens as wt, getTickAtPrice as x, TimelockMarketData as xt, getNearestValidStrikeTick as y, TimelockLens as yt, useUserPerps as z };
62861
- //# sourceMappingURL=client-Bcn8F-k3.d.ts.map
62864
+ export { EMPTY_ARRAY as $, token1ToToken0 as A, uniswapMathLenses as At, useClosedUserPerps as B, getTickAtPrice as C, TimelockMarketData as Ct, roundTickDown as D, getTimelockMarket as Dt, liquiditiesToAmounts as E, getTimelockLens as Et, getPriceHistory as F, OptionTimelineData as G, usePerpsOperator as H, useSetOperatorPerms as I, useOptionPremium as J, useOptionTimeline as K, useUserOperators as L, PriceDataPoint as M, PriceResolution as N, roundTickUp as O, getUniswapMathLens as Ot, getCurrentPrice as P, Amount as Q, useOperatorPerms as R, getPriceSqrtPriceX96 as S, TimelockMarket as St, liquiditiesToAmount1 as T, getErc20 as Tt, useClosePerp as U, useUserPerps as V, useMintPerp as W, useMintOption as X, useOptionPnl as Y, useMaxPositionSize as Z, getPayoutAtTick as _, useClosedUserOptions as _t, batchGetAmountsFromLiquidity as a, scalePrice as at, getNearestValidStrikeTick as b, useTimelockConfig as bt, useLiquidityBlocks as c, wrapAmount as ct, usePriceAtTick as d, wrapPriceUnscaled as dt, formatAmount as et, usePriceSqrtPriceX96 as f, zero as ft, useCurrentPrice as g, useActiveUserOptions as gt, useCurrentTick as h, OptionData as ht, useVaultData as i, scaleAmount as it, PriceData as j, token0ToToken1 as k, timelockLenses as kt, useBurnLiquidity as l, wrapAmountUnscaled as lt, usePoolData as m, useExerciseOption as mt, useLens as n, formatUSD as nt, useMintLiquidity as o, unscaleAmount as ot, UniswapPoolData as p, useMarketData as pt, useExtendOption as q, useVaultTVL as r, formatVagueAmount as rt, LiquidityBlockData as s, unscalePrice as st, useApproval as t, formatCondensed as tt, usePriceHistory as u, wrapPrice as ut, PRICE_PRECISION as v, TimelockProvider as vt, liquiditiesToAmount0 as w, UniswapMathLens as wt, getPriceAtTick as x, TimelockLens as xt, getAmountsFromLiquidity as y, useCurrentMarket as yt, useActiveUserPerps as z };
62865
+ //# sourceMappingURL=client-dmXFiQFn.d.cts.map
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(200);
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(200);
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(200);
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(200);
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(200);
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;