timelock-sdk 0.0.135 → 0.0.136

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.
Files changed (42) hide show
  1. package/dist/abis.cjs +602 -3
  2. package/dist/abis.cjs.map +1 -0
  3. package/dist/abis.d.cts +354 -90
  4. package/dist/abis.d.ts +354 -90
  5. package/dist/abis.js +602 -3
  6. package/dist/abis.js.map +1 -0
  7. package/dist/{client-DXq_0YH-.d.cts → client-B7kKAk49.d.cts} +38760 -28899
  8. package/dist/{client-BQGLnbLD.d.ts → client-D4EJlSs_.d.ts} +38760 -28899
  9. package/dist/client.cjs +86 -60
  10. package/dist/client.cjs.map +1 -1
  11. package/dist/client.d.cts +3 -3
  12. package/dist/client.d.ts +3 -3
  13. package/dist/client.js +85 -61
  14. package/dist/client.js.map +1 -1
  15. package/dist/optionUtils-B0rlRtfb.js +1401 -0
  16. package/dist/optionUtils-B0rlRtfb.js.map +1 -0
  17. package/dist/{optionUtils-OfLzCR6R.cjs → optionUtils-pH0o9gTm.cjs} +1069 -37
  18. package/dist/optionUtils-pH0o9gTm.cjs.map +1 -0
  19. package/dist/{optionsMarket-B2IsvbeA.js → optionsMarket-CjlRzn2K.js} +213 -21
  20. package/dist/optionsMarket-CjlRzn2K.js.map +1 -0
  21. package/dist/{optionsMarket-C6K82im8.cjs → optionsMarket-iZiYJCuW.cjs} +213 -21
  22. package/dist/optionsMarket-iZiYJCuW.cjs.map +1 -0
  23. package/dist/package.cjs +5 -6
  24. package/dist/package.d.cts +3 -3
  25. package/dist/package.d.ts +3 -3
  26. package/dist/package.js +3 -3
  27. package/dist/singleOwnerVault-BJyEs_D_.js +847 -0
  28. package/dist/singleOwnerVault-BJyEs_D_.js.map +1 -0
  29. package/dist/singleOwnerVault-GCpQV7pN.cjs +853 -0
  30. package/dist/singleOwnerVault-GCpQV7pN.cjs.map +1 -0
  31. package/dist/{uniswapMathLens-DHfzEjej.d.ts → uniswapMathLens-B0xWynAN.d.cts} +182 -21
  32. package/dist/{uniswapMathLens-Be6lFJcD.d.cts → uniswapMathLens-DAI2a8aU.d.ts} +182 -21
  33. package/package.json +38 -38
  34. package/dist/optionUtils-CQzUsKpO.js +0 -369
  35. package/dist/optionUtils-CQzUsKpO.js.map +0 -1
  36. package/dist/optionUtils-OfLzCR6R.cjs.map +0 -1
  37. package/dist/optionsMarket-B2IsvbeA.js.map +0 -1
  38. package/dist/optionsMarket-C6K82im8.cjs.map +0 -1
  39. package/dist/singleOwnerVault-gf2zNZVk.cjs +0 -1131
  40. package/dist/singleOwnerVault-gf2zNZVk.cjs.map +0 -1
  41. package/dist/singleOwnerVault-p81IjmWe.js +0 -1119
  42. package/dist/singleOwnerVault-p81IjmWe.js.map +0 -1
package/dist/client.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  'use client';
2
2
 
3
3
 
4
- const require_optionUtils = require('./optionUtils-OfLzCR6R.cjs');
5
- const require_optionsMarket = require('./optionsMarket-C6K82im8.cjs');
6
- const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
4
+ const require_optionUtils = require('./optionUtils-pH0o9gTm.cjs');
5
+ const require_optionsMarket = require('./optionsMarket-iZiYJCuW.cjs');
6
+ const require_singleOwnerVault = require('./singleOwnerVault-GCpQV7pN.cjs');
7
7
  let viem = require("viem");
8
8
  let react = require("react");
9
9
  react = require_optionUtils.__toESM(react);
10
- let wagmi = require("wagmi");
11
10
  let graphql_request = require("graphql-request");
12
11
  let graphql_tag = require("graphql-tag");
13
12
  graphql_tag = require_optionUtils.__toESM(graphql_tag);
14
13
  let viem_actions = require("viem/actions");
14
+ let wagmi = require("wagmi");
15
15
  let __tanstack_react_query = require("@tanstack/react-query");
16
16
  let zod = require("zod");
17
17
 
@@ -401,9 +401,6 @@ var PerpsOperator = class {
401
401
  //#region src/providers/TimelockProvider.tsx
402
402
  const TimelockContext = (0, react.createContext)(void 0);
403
403
  const TimelockProvider = ({ children, marketData, envioGraphqlUrl, perpsOperatorUrl }) => {
404
- const chainId = (0, wagmi.useChainId)();
405
- const lensAddr = require_optionUtils.timelockLenses[chainId];
406
- const uniswapMathLensAddr = require_optionUtils.uniswapMathLenses[chainId];
407
404
  const graphqlClient = (0, react.useMemo)(() => {
408
405
  if (envioGraphqlUrl) return getSdk(new graphql_request.GraphQLClient(envioGraphqlUrl));
409
406
  }, [envioGraphqlUrl]);
@@ -412,16 +409,12 @@ const TimelockProvider = ({ children, marketData, envioGraphqlUrl, perpsOperator
412
409
  }, [perpsOperatorUrl]);
413
410
  const contextValue = (0, react.useMemo)(() => ({
414
411
  marketData: marketData || {},
415
- lensAddr,
416
- uniswapMathLensAddr,
417
412
  envioGraphqlUrl,
418
413
  perpsOperator,
419
414
  graphqlClient,
420
415
  perpsOperatorUrl
421
416
  }), [
422
417
  marketData,
423
- lensAddr,
424
- uniswapMathLensAddr,
425
418
  envioGraphqlUrl,
426
419
  perpsOperator,
427
420
  graphqlClient,
@@ -446,7 +439,7 @@ const useLens = () => {
446
439
  const client = (0, wagmi.useClient)();
447
440
  return (0, react.useMemo)(() => ({
448
441
  timelockLens: client ? require_optionUtils.getTimelockLens(client) : void 0,
449
- uniswapLens: client ? require_optionUtils.getUniswapMathLens(client) : void 0
442
+ stateView: client ? require_optionUtils.getStateView(client) : void 0
450
443
  }), [client]);
451
444
  };
452
445
 
@@ -486,15 +479,14 @@ const useMarketData = (marketAddr) => {
486
479
 
487
480
  //#endregion
488
481
  //#region src/hooks/pool/usePoolData.ts
489
- const usePoolData = (poolAddr) => {
482
+ const usePoolData = (poolManager, poolKey) => {
490
483
  const { timelockLens } = useLens();
491
- const client = (0, wagmi.useClient)();
492
484
  const { data } = (0, wagmi.useReadContract)({
493
485
  address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
494
486
  abi: require_optionsMarket.lensAbi,
495
487
  functionName: "getPoolData",
496
- args: poolAddr ? [poolAddr] : void 0,
497
- query: { enabled: !!poolAddr && !!client }
488
+ args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
489
+ query: { enabled: !!poolManager && !!poolKey }
498
490
  });
499
491
  return data || {};
500
492
  };
@@ -511,7 +503,7 @@ const useExerciseOption = (marketAddr) => {
511
503
  const { timelockLens } = useLens();
512
504
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
513
505
  const client = (0, wagmi.useClient)();
514
- const { address } = (0, wagmi.useAccount)();
506
+ const { address } = (0, wagmi.useConnection)();
515
507
  const { writeContractAsync } = (0, wagmi.useWriteContract)();
516
508
  const exerciseOption = async ({ option, liquidities }) => {
517
509
  if (!client || !address) throw new Error("Wallet not connected");
@@ -592,21 +584,22 @@ const useMaxPositionSize = (marketAddr, maxBorrowableRange = 100) => {
592
584
 
593
585
  //#endregion
594
586
  //#region src/hooks/pool/useCurrentTick.ts
595
- const useCurrentTick = (poolAddr) => {
596
- const { tickSpacing } = usePoolData(poolAddr);
587
+ const useCurrentTick = (poolManager, poolKey) => {
588
+ const { tickSpacing } = usePoolData(poolManager, poolKey);
597
589
  const { data, ...rest } = (0, wagmi.useReadContract)({
598
- address: poolAddr,
599
- abi: require_singleOwnerVault.uniswapV3PoolAbi,
600
- functionName: "slot0",
601
- args: [],
590
+ address: poolManager,
591
+ abi: require_optionUtils.statelessStateViewAbi,
592
+ functionName: "getSlot0",
593
+ args: poolManager && poolKey ? [poolManager, poolKey] : void 0,
602
594
  query: {
595
+ enabled: !!poolManager && !!poolKey,
603
596
  refetchInterval: 3e3,
604
597
  select: (raw) => {
605
- const sqrtPriceX96 = raw === null || raw === void 0 ? void 0 : raw[0];
606
- const exact = raw === null || raw === void 0 ? void 0 : raw[1];
598
+ const sqrtPriceX96 = raw[0];
599
+ const exact = raw[1];
607
600
  return {
608
601
  exact,
609
- rounded: exact !== void 0 && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
602
+ rounded: tickSpacing ? require_optionUtils.roundTick(exact, tickSpacing) : void 0,
610
603
  sqrtPriceX96
611
604
  };
612
605
  }
@@ -621,10 +614,10 @@ const useCurrentTick = (poolAddr) => {
621
614
  };
622
615
 
623
616
  //#endregion
624
- //#region src/hooks/useApproval.ts
617
+ //#region src/hooks/tokens/useApproval.ts
625
618
  const useApproval = () => {
626
619
  const client = (0, wagmi.useClient)();
627
- const { address } = (0, wagmi.useAccount)();
620
+ const { address } = (0, wagmi.useConnection)();
628
621
  const { writeContractAsync, data: hash, isPending, error, reset } = (0, wagmi.useWriteContract)();
629
622
  const askForApproval = async (tokenAddress, spenderAddress, amount) => {
630
623
  if (!client || !address) throw new Error("Wallet not connected");
@@ -652,7 +645,7 @@ const useMintOption = (marketAddr) => {
652
645
  const { refetch: refetchCurrentTick } = useCurrentTick(pool);
653
646
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
654
647
  const client = (0, wagmi.useClient)();
655
- const { address } = (0, wagmi.useAccount)();
648
+ const { address } = (0, wagmi.useConnection)();
656
649
  const { timelockLens } = useLens();
657
650
  const { askForApproval } = useApproval();
658
651
  const { writeContractAsync } = (0, wagmi.useWriteContract)();
@@ -779,7 +772,7 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, addedDuration, r
779
772
  const { exact: currentTick } = useCurrentTick(pool);
780
773
  const strikeTickRounded = (0, react.useMemo)(() => {
781
774
  if (!tickSpacing || currentTick === void 0) return;
782
- let strikeTickRounded$1 = require_optionUtils.roundTickDown(strikeTick ?? currentTick, tickSpacing);
775
+ let strikeTickRounded$1 = require_optionUtils.roundTick(strikeTick ?? currentTick, tickSpacing);
783
776
  if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTickRounded$1 += tickSpacing;
784
777
  return strikeTickRounded$1;
785
778
  }, [
@@ -875,7 +868,7 @@ const useExtendOption = (marketAddr) => {
875
868
  const { payoutAsset } = useMarketData(marketAddr);
876
869
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
877
870
  const client = (0, wagmi.useClient)();
878
- const { address } = (0, wagmi.useAccount)();
871
+ const { address } = (0, wagmi.useConnection)();
879
872
  const { askForApproval } = useApproval();
880
873
  const { writeContractAsync } = (0, wagmi.useWriteContract)();
881
874
  const extendOption = async ({ option, duration }) => {
@@ -1014,7 +1007,7 @@ const clearSignature = (userAddr) => {
1014
1007
  localStorage.removeItem(key);
1015
1008
  };
1016
1009
  const usePerpsOperator = () => {
1017
- const { address: userAddr } = (0, wagmi.useAccount)();
1010
+ const { address: userAddr } = (0, wagmi.useConnection)();
1018
1011
  const { perpsOperatorUrl, perpsOperator: operator } = useTimelockConfig();
1019
1012
  const { signMessageAsync } = (0, wagmi.useSignMessage)();
1020
1013
  const { data: address } = (0, __tanstack_react_query.useQuery)({
@@ -1061,7 +1054,7 @@ const usePerpsOperator = () => {
1061
1054
  const useMintPerp = (marketAddr) => {
1062
1055
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
1063
1056
  const client = (0, wagmi.useClient)();
1064
- const { address } = (0, wagmi.useAccount)();
1057
+ const { address } = (0, wagmi.useConnection)();
1065
1058
  const { operator, address: operatorAddr, signMessage: { mutateAsync: signMessage } } = usePerpsOperator();
1066
1059
  const { askForApproval } = useApproval();
1067
1060
  const { pool, optionAssetIsToken0, payoutAsset } = useMarketData(marketAddr);
@@ -1149,14 +1142,43 @@ const useClosedUserPerps = (marketAddr, userAddr) => {
1149
1142
  return useUserPerps(marketAddr, userAddr, "closed");
1150
1143
  };
1151
1144
 
1145
+ //#endregion
1146
+ //#region src/hooks/tokens/useTokenData.ts
1147
+ const useTokenData = (tokenAddr) => {
1148
+ const { timelockLens } = useLens();
1149
+ const client = (0, wagmi.useClient)();
1150
+ const { data } = (0, wagmi.useReadContract)({
1151
+ address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
1152
+ abi: require_optionsMarket.lensAbi,
1153
+ functionName: "getTokenData",
1154
+ args: tokenAddr ? [tokenAddr] : void 0,
1155
+ query: { enabled: !!tokenAddr && !!client }
1156
+ });
1157
+ return data || {};
1158
+ };
1159
+
1160
+ //#endregion
1161
+ //#region src/hooks/tokens/useTokenBalance.ts
1162
+ const useTokenBalance = (token, user) => {
1163
+ const { decimals } = useTokenData(token);
1164
+ const { data: raw, ...rest } = (0, wagmi.useReadContract)({
1165
+ address: token,
1166
+ abi: require_optionsMarket.erc20Abi,
1167
+ functionName: "balanceOf",
1168
+ args: user ? [user] : void 0,
1169
+ query: { enabled: !!token && !!user }
1170
+ });
1171
+ return {
1172
+ data: (0, react.useMemo)(() => raw !== void 0 && decimals !== void 0 ? require_optionUtils.wrapAmount(raw, decimals) : void 0, [raw, decimals]),
1173
+ ...rest
1174
+ };
1175
+ };
1176
+
1152
1177
  //#endregion
1153
1178
  //#region src/hooks/operators/useOperatorPerms.ts
1154
1179
  const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
1155
1180
  const { payoutAsset } = useMarketData(marketAddr);
1156
- const { data: payoutAssetBalance } = (0, wagmi.useBalance)({
1157
- address: userAddr,
1158
- token: payoutAsset
1159
- });
1181
+ const { data: payoutAssetBalance } = useTokenBalance(payoutAsset, userAddr);
1160
1182
  const { data, ...rest } = (0, wagmi.useReadContract)({
1161
1183
  abi: require_optionsMarket.optionsMarketAbi,
1162
1184
  address: marketAddr,
@@ -1169,7 +1191,7 @@ const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
1169
1191
  });
1170
1192
  const [canExtend, canExercise, canTransfer, canMint, spendingApproval] = data || [];
1171
1193
  const min = (a, b) => a < b ? a : b;
1172
- const effectiveApproval = spendingApproval && payoutAssetBalance ? min(spendingApproval, payoutAssetBalance.value) : 0n;
1194
+ const effectiveApproval = spendingApproval && payoutAssetBalance ? min(spendingApproval, payoutAssetBalance.scaled) : 0n;
1173
1195
  return {
1174
1196
  data: (0, react.useMemo)(() => ({
1175
1197
  canExtend,
@@ -1224,7 +1246,7 @@ const useUserOperators = (userAddr, marketAddr) => {
1224
1246
  const useSetOperatorPerms = (marketAddr) => {
1225
1247
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
1226
1248
  const client = (0, wagmi.useClient)();
1227
- const { address } = (0, wagmi.useAccount)();
1249
+ const { address } = (0, wagmi.useConnection)();
1228
1250
  const { writeContractAsync } = (0, wagmi.useWriteContract)();
1229
1251
  const setOperatorPerms = async ({ operator, canExtend, canExercise, canTransfer, canMint, spendingApproval }) => {
1230
1252
  if (!client || !address) throw new Error("Wallet not connected");
@@ -1278,12 +1300,14 @@ const useMarketPriceHistory = (marketAddr, resolution, startTimestamp, endTimest
1278
1300
  //#endregion
1279
1301
  //#region src/hooks/vault/useVaultData.ts
1280
1302
  const useVaultData = (vaultAddr) => {
1303
+ const { timelockLens } = useLens();
1281
1304
  const { data } = (0, wagmi.useReadContract)({
1282
- address: vaultAddr,
1283
- abi: require_singleOwnerVault.singleOwnerVaultAbi,
1284
- functionName: "pool"
1305
+ address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
1306
+ abi: require_optionsMarket.lensAbi,
1307
+ functionName: "getVaultData",
1308
+ args: vaultAddr ? [vaultAddr] : void 0
1285
1309
  });
1286
- return { pool: data };
1310
+ return data || {};
1287
1311
  };
1288
1312
 
1289
1313
  //#endregion
@@ -1291,8 +1315,8 @@ const useVaultData = (vaultAddr) => {
1291
1315
  const useBurnLiquidity = (vaultAddr) => {
1292
1316
  const client = (0, wagmi.useClient)();
1293
1317
  const { timelockLens } = useLens();
1294
- const { pool } = useVaultData(vaultAddr);
1295
- const currentTick = useCurrentTick(pool);
1318
+ const { poolManager, poolKey } = useVaultData(vaultAddr);
1319
+ const currentTick = useCurrentTick(poolManager, poolKey);
1296
1320
  const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
1297
1321
  const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
1298
1322
  const burn = async (tickLower, tickUpper, liquidity) => {
@@ -1390,10 +1414,10 @@ const batchGetAmountsFromLiquidity = (tickLowers, tickUppers, liquidities, curre
1390
1414
  const useMintLiquidity = (vaultAddr) => {
1391
1415
  const queryClient = (0, __tanstack_react_query.useQueryClient)();
1392
1416
  const client = (0, wagmi.useClient)();
1393
- const { pool } = useVaultData(vaultAddr);
1417
+ const { poolManager, poolKey } = useVaultData(vaultAddr);
1394
1418
  const { timelockLens } = useLens();
1395
- const { exact: currentTick } = useCurrentTick(pool);
1396
- const { token0, token1 } = usePoolData(pool);
1419
+ const { exact: currentTick } = useCurrentTick(poolManager, poolKey);
1420
+ const { token0, token1 } = usePoolData(poolManager, poolKey);
1397
1421
  const { askForApproval } = useApproval();
1398
1422
  const { writeContractAsync } = (0, wagmi.useWriteContract)();
1399
1423
  const processApproval = async (params) => {
@@ -1433,8 +1457,8 @@ const useMintLiquidity = (vaultAddr) => {
1433
1457
  //#region src/hooks/vault/useVaultTVL.ts
1434
1458
  const useVaultTVL = (vaultAddr) => {
1435
1459
  const { timelockLens } = useLens();
1436
- const { pool } = useVaultData(vaultAddr);
1437
- const { token0Decimals, token1Decimals } = usePoolData(pool);
1460
+ const { poolManager, poolKey } = useVaultData(vaultAddr);
1461
+ const { token0Decimals, token1Decimals } = usePoolData(poolManager, poolKey);
1438
1462
  const { data, refetch } = (0, wagmi.useReadContract)({
1439
1463
  address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
1440
1464
  abi: require_optionsMarket.lensAbi,
@@ -1444,17 +1468,17 @@ const useVaultTVL = (vaultAddr) => {
1444
1468
  });
1445
1469
  return (0, react.useMemo)(() => {
1446
1470
  if (!token0Decimals || !token1Decimals || !data) return {};
1447
- const totalAmount0 = require_optionUtils.wrapAmount(data[0], token0Decimals);
1448
- const totalAmount1 = require_optionUtils.wrapAmount(data[1], token1Decimals);
1449
- const borrowedAmount0 = require_optionUtils.wrapAmount(data[2], token0Decimals);
1450
- const borrowedAmount1 = require_optionUtils.wrapAmount(data[3], token1Decimals);
1471
+ const total0 = require_optionUtils.wrapAmount(data[0], token0Decimals);
1472
+ const total1 = require_optionUtils.wrapAmount(data[1], token1Decimals);
1473
+ const borrowed0 = require_optionUtils.wrapAmount(data[2], token0Decimals);
1474
+ const borrowed1 = require_optionUtils.wrapAmount(data[3], token1Decimals);
1451
1475
  return {
1452
- tvl0: require_optionUtils.wrapAmount(data[4], token0Decimals),
1453
- tvl1: require_optionUtils.wrapAmount(data[5], token1Decimals),
1454
- totalAmount0,
1455
- totalAmount1,
1456
- borrowedAmount0,
1457
- borrowedAmount1,
1476
+ tvlAs0: require_optionUtils.wrapAmount(data[4], token0Decimals),
1477
+ tvlAs1: require_optionUtils.wrapAmount(data[5], token1Decimals),
1478
+ total0,
1479
+ total1,
1480
+ borrowed0,
1481
+ borrowed1,
1458
1482
  blocksCount: data[6],
1459
1483
  refetch
1460
1484
  };
@@ -1501,6 +1525,8 @@ exports.usePriceHistory = usePriceHistory;
1501
1525
  exports.usePriceSqrtPriceX96 = usePriceSqrtPriceX96;
1502
1526
  exports.useSetOperatorPerms = useSetOperatorPerms;
1503
1527
  exports.useTimelockConfig = useTimelockConfig;
1528
+ exports.useTokenBalance = useTokenBalance;
1529
+ exports.useTokenData = useTokenData;
1504
1530
  exports.useUserOperators = useUserOperators;
1505
1531
  exports.useUserPerps = useUserPerps;
1506
1532
  exports.useVaultData = useVaultData;