timelock-sdk 0.0.29 → 0.0.31

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
@@ -151,16 +151,21 @@ const TimelockMarketProvider = ({ children, marketData, envioGraphqlUrl }) => {
151
151
  const chainId = (0, wagmi.useChainId)();
152
152
  const lensAddr = require_numberUtils.timelockLenses[chainId];
153
153
  const uniswapMathLensAddr = require_numberUtils.uniswapMathLenses[chainId];
154
+ const graphqlClient = (0, react.useMemo)(() => {
155
+ if (envioGraphqlUrl) return getSdk(new graphql_request.GraphQLClient(envioGraphqlUrl));
156
+ }, [envioGraphqlUrl]);
154
157
  const contextValue = (0, react.useMemo)(() => ({
155
158
  marketData: marketData || {},
156
159
  lensAddr,
157
160
  uniswapMathLensAddr,
158
- envioGraphqlUrl
161
+ envioGraphqlUrl,
162
+ graphqlClient
159
163
  }), [
160
164
  marketData,
161
165
  lensAddr,
162
166
  uniswapMathLensAddr,
163
- envioGraphqlUrl
167
+ envioGraphqlUrl,
168
+ graphqlClient
164
169
  ]);
165
170
  return /* @__PURE__ */ react.default.createElement(TimelockMarketContext.Provider, { value: contextValue }, children);
166
171
  };
@@ -172,15 +177,7 @@ const useCurrentMarket = () => {
172
177
  const useTimelockConfig = () => {
173
178
  const context = (0, react.useContext)(TimelockMarketContext);
174
179
  if (context === void 0) throw new Error("useConfig must be used within a TimelockMarketProvider");
175
- const graphqlClient = (0, react.useMemo)(() => {
176
- if (context.envioGraphqlUrl) return getSdk(new graphql_request.GraphQLClient(context.envioGraphqlUrl));
177
- }, [context.envioGraphqlUrl]);
178
- return {
179
- lensAddr: context.lensAddr,
180
- uniswapMathLensAddr: context.uniswapMathLensAddr,
181
- envioGraphqlUrl: context.envioGraphqlUrl,
182
- graphqlClient
183
- };
180
+ return context;
184
181
  };
185
182
 
186
183
  //#endregion
@@ -417,29 +414,32 @@ const useOptionPnl = (optionData) => {
417
414
 
418
415
  //#endregion
419
416
  //#region src/hooks/market/useOptionPremium.ts
420
- const useOptionPremium = (marketAddr, optionType, optionAmount, duration) => {
421
- const { pool, payoutAssetDecimals } = useMarketData(marketAddr);
417
+ const useOptionPremium = (marketAddr, optionType, optionAmount, duration, strikeTick) => {
418
+ const { pool, payoutAssetDecimals, optionAssetIsToken0 } = useMarketData(marketAddr);
422
419
  const { tickSpacing } = usePoolData(pool);
423
- const currentTick = useCurrentTick(pool);
424
- const strikeTick = (0, react.useMemo)(() => {
425
- if (currentTick.rounded === void 0 || tickSpacing === void 0) return;
426
- return optionType === "CALL" ? currentTick.rounded + tickSpacing : currentTick.rounded;
420
+ const { exact: currentTick } = useCurrentTick(pool);
421
+ const strikeTickRounded = (0, react.useMemo)(() => {
422
+ if (!tickSpacing || currentTick === void 0) return;
423
+ strikeTick = require_numberUtils.roundTickDown(strikeTick ?? currentTick, tickSpacing);
424
+ if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTick += tickSpacing;
427
425
  }, [
428
- currentTick.rounded,
426
+ currentTick,
429
427
  tickSpacing,
430
- optionType
428
+ optionType,
429
+ optionAssetIsToken0,
430
+ strikeTick
431
431
  ]);
432
432
  const { data: premiumData } = (0, wagmi.useReadContract)({
433
433
  address: marketAddr,
434
434
  abi: require_optionsMarket.optionsMarketAbi,
435
435
  functionName: "calculatePremium",
436
- args: strikeTick !== void 0 ? [
436
+ args: [
437
437
  optionType === "CALL" ? 0 : 1,
438
438
  optionAmount,
439
- strikeTick,
439
+ strikeTickRounded,
440
440
  BigInt(duration)
441
- ] : void 0,
442
- query: { enabled: currentTick.rounded !== void 0 && payoutAssetDecimals !== void 0 && tickSpacing !== void 0 && strikeTick !== void 0 }
441
+ ],
442
+ query: { enabled: strikeTickRounded !== void 0 }
443
443
  });
444
444
  return (0, react.useMemo)(() => {
445
445
  if (premiumData === void 0 || payoutAssetDecimals === void 0) return;