timelock-sdk 0.0.82 → 0.0.84

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.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-6PlyceXp.js";
5
- import { A as getErc20, D as token1ToToken0, E as token0ToToken1, F as uniswapMathLenses, M as getTimelockMarket$1, N as getUniswapMathLens, P as timelockLenses, _ as getAmountsFromLiquidity, d as wrapAmount, j as getTimelockLens, k as getPriceHistory, n as EMPTY_ARRAY, p as wrapPrice, t as getPayoutAtTick, v as getNearestValidStrikeTick$1, w as roundTickDown, y as getPriceAtTick } from "./optionUtils-CoIk8zAr.js";
5
+ import { A as getErc20, D as token1ToToken0, E as token0ToToken1, F as uniswapMathLenses, M as getTimelockMarket, N as getUniswapMathLens, P as timelockLenses, _ as getAmountsFromLiquidity, d as wrapAmount, j as getTimelockLens, k as getPriceHistory, n as EMPTY_ARRAY, p as wrapPrice, t as getPayoutAtTick, v as getNearestValidStrikeTick, w as roundTickDown, y as getPriceAtTick } from "./optionUtils-CoIk8zAr.js";
6
6
  import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
7
7
  import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
8
8
  import React, { createContext, useContext, useMemo } from "react";
@@ -11,8 +11,6 @@ import { GraphQLClient, RequestOptions } from "graphql-request";
11
11
  import gql from "graphql-tag";
12
12
  import { waitForTransactionReceipt } from "viem/actions";
13
13
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
14
- import { getNearestValidStrikeTick, getTimelockMarket } from "timelock-sdk";
15
- import { useApproval as useApproval$1, useCurrentTick as useCurrentTick$1, useMarketData as useMarketData$1, usePoolData as usePoolData$1, useSetOperatorPerms as useSetOperatorPerms$1, useUserOperators as useUserOperators$1 } from "timelock-sdk/client";
16
14
 
17
15
  //#region src/generated/graphql.ts
18
16
  const UserOptionFieldsFragmentDoc = gql`
@@ -381,7 +379,7 @@ const usePoolData = (poolAddr) => {
381
379
 
382
380
  //#endregion
383
381
  //#region src/hooks/options/useExerciseOption.ts
384
- const swapper = "0xc396aa907F8De0c32460050B8Adbf047186C504d";
382
+ const swapper = "0x2c79DD9797C35A3D966C2716739542a282BB5540";
385
383
  const useExerciseOption = (marketAddr) => {
386
384
  const { vault, pool } = useMarketData(marketAddr);
387
385
  const { fee } = usePoolData(pool);
@@ -519,8 +517,8 @@ const useMintOption = (marketAddr) => {
519
517
  if (!timelockLens) throw new Error("Timelock lens not available");
520
518
  if (!vault || !payoutAsset || optionAssetIsToken0 === void 0) throw new Error("Market data not available");
521
519
  if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
522
- strikeTick = getNearestValidStrikeTick$1(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
523
- const [premium, protocolFee] = await getTimelockMarket$1(marketAddr, client).read.calculatePremium([
520
+ strikeTick = getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
521
+ const [premium, protocolFee] = await getTimelockMarket(marketAddr, client).read.calculatePremium([
524
522
  optionType === "CALL" ? 0 : 1,
525
523
  amount,
526
524
  strikeTick,
@@ -693,7 +691,7 @@ const useExtendOption = (marketAddr) => {
693
691
  const extendOption = async ({ option, duration }) => {
694
692
  if (!client || !address) throw new Error("Wallet not connected");
695
693
  if (!marketAddr || !payoutAsset) throw new Error("Market address not available");
696
- const market = getTimelockMarket$1(marketAddr, client);
694
+ const market = getTimelockMarket(marketAddr, client);
697
695
  const remainingDuration = Math.max(0, Math.floor((option.expiresAt.getTime() - Date.now()) / 1e3));
698
696
  const [premium, protocolFee] = await market.read.calculatePremium([
699
697
  option.optionType === "CALL" ? 0 : 1,
@@ -880,69 +878,6 @@ const usePerpsOperator = () => {
880
878
  };
881
879
  };
882
880
 
883
- //#endregion
884
- //#region src/hooks/perps/useMintPerp.ts
885
- const useMintPerp = (marketAddr) => {
886
- const queryClient = useQueryClient();
887
- const client = useClient();
888
- const { address } = useAccount();
889
- const { operator, address: operatorAddr } = usePerpsOperator();
890
- const { askForApproval } = useApproval$1();
891
- const { data: operators } = useUserOperators$1(address, marketAddr);
892
- const { mutateAsync: setOperatorPerms } = useSetOperatorPerms$1(marketAddr);
893
- const { pool, optionAssetIsToken0, payoutAsset } = useMarketData$1(marketAddr);
894
- const { tickSpacing } = usePoolData$1(pool);
895
- const { exact: currentTick } = useCurrentTick$1(pool);
896
- const userPerms = operatorAddr ? operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase()) : void 0;
897
- const hasEnoughPerms = userPerms && userPerms.canMint && userPerms.canExtend;
898
- const mintPerp = async (data) => {
899
- const { optionType, amount, duration, strikeTick } = data;
900
- if (!client || !address) throw new Error("Wallet not connected");
901
- if (!marketAddr) throw new Error("Market address not found");
902
- if (!operator || !operatorAddr) throw new Error("Operator address not found");
903
- if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
904
- if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
905
- if (!hasEnoughPerms) await setOperatorPerms({
906
- operator: operatorAddr,
907
- canMint: true,
908
- canExtend: true,
909
- canExercise: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canExercise) || false,
910
- canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
911
- spendingApproval: maxUint256
912
- });
913
- const market = getTimelockMarket(marketAddr, client);
914
- const validStrikeTick = getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
915
- const [premium, protocolFee] = await market.read.calculatePremium([
916
- optionType === "CALL" ? 0 : 1,
917
- amount,
918
- validStrikeTick,
919
- duration,
920
- 0
921
- ]);
922
- await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
923
- await operator.mintPerp({
924
- marketAddr,
925
- userAddr: address,
926
- amount,
927
- optionType,
928
- duration,
929
- strikeTick: validStrikeTick
930
- });
931
- queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
932
- };
933
- return useMutation({ mutationFn: mintPerp });
934
- };
935
-
936
- //#endregion
937
- //#region src/hooks/perps/useClosePerp.ts
938
- const useClosePerp = () => {
939
- const { operator } = usePerpsOperator();
940
- return useMutation({ mutationFn: (body) => {
941
- if (!operator) throw new Error("Operator not connected");
942
- return operator.exercisePerp(body);
943
- } });
944
- };
945
-
946
881
  //#endregion
947
882
  //#region src/hooks/operators/useUserOperators.ts
948
883
  const useUserOperators = (userAddr, marketAddr) => {
@@ -1006,11 +941,74 @@ const useSetOperatorPerms = (marketAddr) => {
1006
941
  return useMutation({ mutationFn: setOperatorPerms });
1007
942
  };
1008
943
 
944
+ //#endregion
945
+ //#region src/hooks/perps/useMintPerp.ts
946
+ const useMintPerp = (marketAddr) => {
947
+ const queryClient = useQueryClient();
948
+ const client = useClient();
949
+ const { address } = useAccount();
950
+ const { operator, address: operatorAddr } = usePerpsOperator();
951
+ const { askForApproval } = useApproval();
952
+ const { data: operators } = useUserOperators(address, marketAddr);
953
+ const { mutateAsync: setOperatorPerms } = useSetOperatorPerms(marketAddr);
954
+ const { pool, optionAssetIsToken0, payoutAsset } = useMarketData(marketAddr);
955
+ const { tickSpacing } = usePoolData(pool);
956
+ const { exact: currentTick } = useCurrentTick(pool);
957
+ const userPerms = operatorAddr ? operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase()) : void 0;
958
+ const hasEnoughPerms = userPerms && userPerms.canMint && userPerms.canExtend;
959
+ const mintPerp = async (data) => {
960
+ const { optionType, amount, duration, strikeTick } = data;
961
+ if (!client || !address) throw new Error("Wallet not connected");
962
+ if (!marketAddr) throw new Error("Market address not found");
963
+ if (!operator || !operatorAddr) throw new Error("Operator address not found");
964
+ if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
965
+ if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
966
+ if (!hasEnoughPerms) await setOperatorPerms({
967
+ operator: operatorAddr,
968
+ canMint: true,
969
+ canExtend: true,
970
+ canExercise: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canExercise) || false,
971
+ canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
972
+ spendingApproval: maxUint256
973
+ });
974
+ const market = getTimelockMarket(marketAddr, client);
975
+ const validStrikeTick = getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
976
+ const [premium, protocolFee] = await market.read.calculatePremium([
977
+ optionType === "CALL" ? 0 : 1,
978
+ amount,
979
+ validStrikeTick,
980
+ duration,
981
+ 0
982
+ ]);
983
+ await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
984
+ await operator.mintPerp({
985
+ marketAddr,
986
+ userAddr: address,
987
+ amount,
988
+ optionType,
989
+ duration,
990
+ strikeTick: validStrikeTick
991
+ });
992
+ queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
993
+ };
994
+ return useMutation({ mutationFn: mintPerp });
995
+ };
996
+
997
+ //#endregion
998
+ //#region src/hooks/perps/useClosePerp.ts
999
+ const useClosePerp = () => {
1000
+ const { operator } = usePerpsOperator();
1001
+ return useMutation({ mutationFn: (body) => {
1002
+ if (!operator) throw new Error("Operator not connected");
1003
+ return operator.exercisePerp(body);
1004
+ } });
1005
+ };
1006
+
1009
1007
  //#endregion
1010
1008
  //#region src/hooks/pool/usePriceAtTick.ts
1011
1009
  const usePriceAtTick = (tick, poolAddr) => {
1012
1010
  const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
1013
- const priceBigInt = useMemo(() => tick ? getPriceAtTick(tick) : void 0, [tick]);
1011
+ const priceBigInt = useMemo(() => tick !== void 0 ? getPriceAtTick(tick) : void 0, [tick]);
1014
1012
  return useMemo(() => priceBigInt && token0Decimals && token1Decimals ? wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
1015
1013
  priceBigInt,
1016
1014
  token0Decimals,
@@ -1162,6 +1160,7 @@ const batchGetAmountsFromLiquidity = (tickLowers, tickUppers, liquidities, curre
1162
1160
  };
1163
1161
  };
1164
1162
  const useMintLiquidity = (vaultAddr) => {
1163
+ const queryClient = useQueryClient();
1165
1164
  const client = useClient();
1166
1165
  const { pool } = useVaultData(vaultAddr);
1167
1166
  const { timelockLens } = useLens();
@@ -1198,6 +1197,7 @@ const useMintLiquidity = (vaultAddr) => {
1198
1197
  ]
1199
1198
  }))]
1200
1199
  }) });
1200
+ queryClient.invalidateQueries({ queryKey: ["readContract"] });
1201
1201
  } });
1202
1202
  };
1203
1203