timelock-sdk 0.0.243 → 0.0.245

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,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- const require_numberUtils = require('./numberUtils-C7A_E_pk.cjs');
3
+ const require_numberUtils = require('./numberUtils-CBParClR.cjs');
4
4
  const require_stateView = require('./stateView-CkfUE7Sg.cjs');
5
5
  const require_factory = require('./factory-CUMBEyKw.cjs');
6
6
  let viem = require("viem");
@@ -1264,6 +1264,15 @@ const useExerciseOption = (marketAddr) => {
1264
1264
  const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
1265
1265
  const deadline = BigInt(Math.floor(Date.now() / 1e3) + 600);
1266
1266
  const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
1267
+ const swapperData$1 = (0, viem.encodeAbiParameters)([
1268
+ { type: "uint160" },
1269
+ { type: "uint160" },
1270
+ { type: "uint256" }
1271
+ ], [
1272
+ minSqrtPrice,
1273
+ maxSqrtPrice,
1274
+ deadline
1275
+ ]);
1267
1276
  const hash = await writeContractAsync({
1268
1277
  address: marketAddr,
1269
1278
  abi: require_stateView.optionsMarketAbi,
@@ -1273,15 +1282,7 @@ const useExerciseOption = (marketAddr) => {
1273
1282
  liquidities,
1274
1283
  0n,
1275
1284
  swapper,
1276
- (0, viem.encodeAbiParameters)([
1277
- { type: "uint160" },
1278
- { type: "uint160" },
1279
- { type: "uint256" }
1280
- ], [
1281
- minSqrtPrice,
1282
- maxSqrtPrice,
1283
- deadline
1284
- ]),
1285
+ swapperData$1,
1285
1286
  refTick
1286
1287
  ]
1287
1288
  });
@@ -1302,12 +1303,21 @@ const calculateDisplayPnl = (option, poolPrice, optionAssetIsToken0, payoutAsset
1302
1303
  const delta = (optionAssetIsToken0 ? require_numberUtils.token0ToToken1(option.positionSizeCurrent, poolPrice) : require_numberUtils.token1ToToken0(option.positionSizeCurrent, poolPrice)) - strikeSize;
1303
1304
  return require_numberUtils.wrapAmount(option.optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
1304
1305
  };
1306
+ const swapperData = (0, viem.encodeAbiParameters)([
1307
+ { type: "uint160" },
1308
+ { type: "uint160" },
1309
+ { type: "uint256" }
1310
+ ], [
1311
+ 0n,
1312
+ viem.maxUint160,
1313
+ BigInt(Math.floor(Date.now() / 1e3) + 600)
1314
+ ]);
1305
1315
  const useOptionPnl = (option) => {
1306
- var _refTickSimulation$da, _refTickSimulation$da2;
1307
1316
  const chainId = (0, wagmi.useChainId)();
1317
+ const { address: account } = (0, wagmi.useConnection)();
1308
1318
  const { timelockLens } = useLens();
1309
1319
  const { vault, poolManager, poolKey, optionAssetIsToken0, payoutAssetDecimals } = useMarketData(option === null || option === void 0 ? void 0 : option.marketAddr);
1310
- const { currentPrice: poolPrice, sqrtPriceX96 } = useCurrentPrice(poolManager, poolKey);
1320
+ const { currentPrice: poolPrice } = useCurrentPrice(poolManager, poolKey);
1311
1321
  const displayPnl = (0, react.useMemo)(() => {
1312
1322
  if (!option || !poolPrice || !payoutAssetDecimals || optionAssetIsToken0 === void 0) return void 0;
1313
1323
  return calculateDisplayPnl(option, poolPrice.scaled, optionAssetIsToken0, payoutAssetDecimals);
@@ -1317,39 +1327,28 @@ const useOptionPnl = (option) => {
1317
1327
  poolPrice,
1318
1328
  payoutAssetDecimals
1319
1329
  ]);
1320
- const swapperData = (0, react.useMemo)(() => {
1321
- if (!sqrtPriceX96) return void 0;
1322
- return (0, viem.encodeAbiParameters)([
1323
- { type: "uint160" },
1324
- { type: "uint160" },
1325
- { type: "uint256" }
1326
- ], [
1327
- sqrtPriceX96 * 9n / 10n,
1328
- sqrtPriceX96 * 11n / 10n,
1329
- BigInt(Math.floor(Date.now() / 1e3) + 600)
1330
- ]);
1331
- }, [sqrtPriceX96]);
1332
- const refTickSimulation = (0, wagmi.useSimulateContract)({
1330
+ const { data: refTick } = (0, wagmi.useReadContract)({
1333
1331
  address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
1334
- abi: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.abi,
1332
+ abi: require_stateView.lensAbi,
1335
1333
  functionName: "getRefTick",
1336
- args: vault && (option === null || option === void 0 ? void 0 : option.startTick) ? [vault, option.startTick] : void 0,
1337
- query: { enabled: !!vault && !!(option === null || option === void 0 ? void 0 : option.startTick) && !!timelockLens }
1334
+ args: vault && (option === null || option === void 0 ? void 0 : option.startTick) ? [vault, option.startTick] : void 0
1338
1335
  });
1339
- const result = (0, wagmi.useSimulateContract)({
1336
+ const swapper = require_numberUtils.swappers[chainId];
1337
+ const { data: unrealizedPayout, ...rest } = (0, wagmi.useSimulateContract)({
1340
1338
  address: option === null || option === void 0 ? void 0 : option.marketAddr,
1341
1339
  abi: require_stateView.optionsMarketAbi,
1342
1340
  functionName: "exerciseOption",
1343
- args: option && swapperData && ((_refTickSimulation$da = refTickSimulation.data) === null || _refTickSimulation$da === void 0 ? void 0 : _refTickSimulation$da.result) ? [
1341
+ account,
1342
+ args: option && refTick ? [
1344
1343
  option.optionId,
1345
1344
  option.liquiditiesCurrent,
1346
1345
  0n,
1347
- require_numberUtils.swappers[chainId],
1346
+ swapper,
1348
1347
  swapperData,
1349
- refTickSimulation.data.result
1348
+ refTick
1350
1349
  ] : void 0,
1351
1350
  query: {
1352
- enabled: !!option && !!swapperData && !!((_refTickSimulation$da2 = refTickSimulation.data) === null || _refTickSimulation$da2 === void 0 ? void 0 : _refTickSimulation$da2.result) && !!option.marketAddr,
1351
+ enabled: !!option && !!swapperData && !!swapper && refTick !== void 0 && !!account,
1353
1352
  staleTime: 1e4,
1354
1353
  select: (data) => {
1355
1354
  if (!payoutAssetDecimals) return void 0;
@@ -1358,10 +1357,10 @@ const useOptionPnl = (option) => {
1358
1357
  }
1359
1358
  });
1360
1359
  return {
1361
- ...result,
1360
+ ...rest,
1362
1361
  data: {
1363
1362
  displayPnl,
1364
- unrealizedPayout: result.data
1363
+ unrealizedPayout
1365
1364
  }
1366
1365
  };
1367
1366
  };