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.cjs +67 -69
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +71 -71
- package/dist/client.js.map +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -18,10 +18,6 @@ let viem_actions = require("viem/actions");
|
|
|
18
18
|
viem_actions = require_optionUtils.__toESM(viem_actions);
|
|
19
19
|
let __tanstack_react_query = require("@tanstack/react-query");
|
|
20
20
|
__tanstack_react_query = require_optionUtils.__toESM(__tanstack_react_query);
|
|
21
|
-
let timelock_sdk = require("timelock-sdk");
|
|
22
|
-
timelock_sdk = require_optionUtils.__toESM(timelock_sdk);
|
|
23
|
-
let timelock_sdk_client = require("timelock-sdk/client");
|
|
24
|
-
timelock_sdk_client = require_optionUtils.__toESM(timelock_sdk_client);
|
|
25
21
|
|
|
26
22
|
//#region src/generated/graphql.ts
|
|
27
23
|
const UserOptionFieldsFragmentDoc = graphql_tag.default`
|
|
@@ -390,7 +386,7 @@ const usePoolData = (poolAddr) => {
|
|
|
390
386
|
|
|
391
387
|
//#endregion
|
|
392
388
|
//#region src/hooks/options/useExerciseOption.ts
|
|
393
|
-
const swapper = "
|
|
389
|
+
const swapper = "0x2c79DD9797C35A3D966C2716739542a282BB5540";
|
|
394
390
|
const useExerciseOption = (marketAddr) => {
|
|
395
391
|
const { vault, pool } = useMarketData(marketAddr);
|
|
396
392
|
const { fee } = usePoolData(pool);
|
|
@@ -889,69 +885,6 @@ const usePerpsOperator = () => {
|
|
|
889
885
|
};
|
|
890
886
|
};
|
|
891
887
|
|
|
892
|
-
//#endregion
|
|
893
|
-
//#region src/hooks/perps/useMintPerp.ts
|
|
894
|
-
const useMintPerp = (marketAddr) => {
|
|
895
|
-
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
896
|
-
const client = (0, wagmi.useClient)();
|
|
897
|
-
const { address } = (0, wagmi.useAccount)();
|
|
898
|
-
const { operator, address: operatorAddr } = usePerpsOperator();
|
|
899
|
-
const { askForApproval } = (0, timelock_sdk_client.useApproval)();
|
|
900
|
-
const { data: operators } = (0, timelock_sdk_client.useUserOperators)(address, marketAddr);
|
|
901
|
-
const { mutateAsync: setOperatorPerms } = (0, timelock_sdk_client.useSetOperatorPerms)(marketAddr);
|
|
902
|
-
const { pool, optionAssetIsToken0, payoutAsset } = (0, timelock_sdk_client.useMarketData)(marketAddr);
|
|
903
|
-
const { tickSpacing } = (0, timelock_sdk_client.usePoolData)(pool);
|
|
904
|
-
const { exact: currentTick } = (0, timelock_sdk_client.useCurrentTick)(pool);
|
|
905
|
-
const userPerms = operatorAddr ? operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase()) : void 0;
|
|
906
|
-
const hasEnoughPerms = userPerms && userPerms.canMint && userPerms.canExtend;
|
|
907
|
-
const mintPerp = async (data) => {
|
|
908
|
-
const { optionType, amount, duration, strikeTick } = data;
|
|
909
|
-
if (!client || !address) throw new Error("Wallet not connected");
|
|
910
|
-
if (!marketAddr) throw new Error("Market address not found");
|
|
911
|
-
if (!operator || !operatorAddr) throw new Error("Operator address not found");
|
|
912
|
-
if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
|
|
913
|
-
if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
|
|
914
|
-
if (!hasEnoughPerms) await setOperatorPerms({
|
|
915
|
-
operator: operatorAddr,
|
|
916
|
-
canMint: true,
|
|
917
|
-
canExtend: true,
|
|
918
|
-
canExercise: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canExercise) || false,
|
|
919
|
-
canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
|
|
920
|
-
spendingApproval: viem.maxUint256
|
|
921
|
-
});
|
|
922
|
-
const market = (0, timelock_sdk.getTimelockMarket)(marketAddr, client);
|
|
923
|
-
const validStrikeTick = (0, timelock_sdk.getNearestValidStrikeTick)(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
|
|
924
|
-
const [premium, protocolFee] = await market.read.calculatePremium([
|
|
925
|
-
optionType === "CALL" ? 0 : 1,
|
|
926
|
-
amount,
|
|
927
|
-
validStrikeTick,
|
|
928
|
-
duration,
|
|
929
|
-
0
|
|
930
|
-
]);
|
|
931
|
-
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
|
|
932
|
-
await operator.mintPerp({
|
|
933
|
-
marketAddr,
|
|
934
|
-
userAddr: address,
|
|
935
|
-
amount,
|
|
936
|
-
optionType,
|
|
937
|
-
duration,
|
|
938
|
-
strikeTick: validStrikeTick
|
|
939
|
-
});
|
|
940
|
-
queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
941
|
-
};
|
|
942
|
-
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintPerp });
|
|
943
|
-
};
|
|
944
|
-
|
|
945
|
-
//#endregion
|
|
946
|
-
//#region src/hooks/perps/useClosePerp.ts
|
|
947
|
-
const useClosePerp = () => {
|
|
948
|
-
const { operator } = usePerpsOperator();
|
|
949
|
-
return (0, __tanstack_react_query.useMutation)({ mutationFn: (body) => {
|
|
950
|
-
if (!operator) throw new Error("Operator not connected");
|
|
951
|
-
return operator.exercisePerp(body);
|
|
952
|
-
} });
|
|
953
|
-
};
|
|
954
|
-
|
|
955
888
|
//#endregion
|
|
956
889
|
//#region src/hooks/operators/useUserOperators.ts
|
|
957
890
|
const useUserOperators = (userAddr, marketAddr) => {
|
|
@@ -1015,11 +948,74 @@ const useSetOperatorPerms = (marketAddr) => {
|
|
|
1015
948
|
return (0, __tanstack_react_query.useMutation)({ mutationFn: setOperatorPerms });
|
|
1016
949
|
};
|
|
1017
950
|
|
|
951
|
+
//#endregion
|
|
952
|
+
//#region src/hooks/perps/useMintPerp.ts
|
|
953
|
+
const useMintPerp = (marketAddr) => {
|
|
954
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
955
|
+
const client = (0, wagmi.useClient)();
|
|
956
|
+
const { address } = (0, wagmi.useAccount)();
|
|
957
|
+
const { operator, address: operatorAddr } = usePerpsOperator();
|
|
958
|
+
const { askForApproval } = useApproval();
|
|
959
|
+
const { data: operators } = useUserOperators(address, marketAddr);
|
|
960
|
+
const { mutateAsync: setOperatorPerms } = useSetOperatorPerms(marketAddr);
|
|
961
|
+
const { pool, optionAssetIsToken0, payoutAsset } = useMarketData(marketAddr);
|
|
962
|
+
const { tickSpacing } = usePoolData(pool);
|
|
963
|
+
const { exact: currentTick } = useCurrentTick(pool);
|
|
964
|
+
const userPerms = operatorAddr ? operators.find((o) => o.operatorAddr.toLowerCase() === operatorAddr.toLowerCase()) : void 0;
|
|
965
|
+
const hasEnoughPerms = userPerms && userPerms.canMint && userPerms.canExtend;
|
|
966
|
+
const mintPerp = async (data) => {
|
|
967
|
+
const { optionType, amount, duration, strikeTick } = data;
|
|
968
|
+
if (!client || !address) throw new Error("Wallet not connected");
|
|
969
|
+
if (!marketAddr) throw new Error("Market address not found");
|
|
970
|
+
if (!operator || !operatorAddr) throw new Error("Operator address not found");
|
|
971
|
+
if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
|
|
972
|
+
if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
|
|
973
|
+
if (!hasEnoughPerms) await setOperatorPerms({
|
|
974
|
+
operator: operatorAddr,
|
|
975
|
+
canMint: true,
|
|
976
|
+
canExtend: true,
|
|
977
|
+
canExercise: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canExercise) || false,
|
|
978
|
+
canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
|
|
979
|
+
spendingApproval: viem.maxUint256
|
|
980
|
+
});
|
|
981
|
+
const market = require_optionUtils.getTimelockMarket(marketAddr, client);
|
|
982
|
+
const validStrikeTick = require_optionUtils.getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
|
|
983
|
+
const [premium, protocolFee] = await market.read.calculatePremium([
|
|
984
|
+
optionType === "CALL" ? 0 : 1,
|
|
985
|
+
amount,
|
|
986
|
+
validStrikeTick,
|
|
987
|
+
duration,
|
|
988
|
+
0
|
|
989
|
+
]);
|
|
990
|
+
await askForApproval(payoutAsset, marketAddr, (premium + protocolFee) * 11n / 10n);
|
|
991
|
+
await operator.mintPerp({
|
|
992
|
+
marketAddr,
|
|
993
|
+
userAddr: address,
|
|
994
|
+
amount,
|
|
995
|
+
optionType,
|
|
996
|
+
duration,
|
|
997
|
+
strikeTick: validStrikeTick
|
|
998
|
+
});
|
|
999
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
|
|
1000
|
+
};
|
|
1001
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintPerp });
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
//#endregion
|
|
1005
|
+
//#region src/hooks/perps/useClosePerp.ts
|
|
1006
|
+
const useClosePerp = () => {
|
|
1007
|
+
const { operator } = usePerpsOperator();
|
|
1008
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: (body) => {
|
|
1009
|
+
if (!operator) throw new Error("Operator not connected");
|
|
1010
|
+
return operator.exercisePerp(body);
|
|
1011
|
+
} });
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1018
1014
|
//#endregion
|
|
1019
1015
|
//#region src/hooks/pool/usePriceAtTick.ts
|
|
1020
1016
|
const usePriceAtTick = (tick, poolAddr) => {
|
|
1021
1017
|
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
1022
|
-
const priceBigInt = (0, react.useMemo)(() => tick ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
1018
|
+
const priceBigInt = (0, react.useMemo)(() => tick !== void 0 ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
1023
1019
|
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
1024
1020
|
priceBigInt,
|
|
1025
1021
|
token0Decimals,
|
|
@@ -1171,6 +1167,7 @@ const batchGetAmountsFromLiquidity = (tickLowers, tickUppers, liquidities, curre
|
|
|
1171
1167
|
};
|
|
1172
1168
|
};
|
|
1173
1169
|
const useMintLiquidity = (vaultAddr) => {
|
|
1170
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
1174
1171
|
const client = (0, wagmi.useClient)();
|
|
1175
1172
|
const { pool } = useVaultData(vaultAddr);
|
|
1176
1173
|
const { timelockLens } = useLens();
|
|
@@ -1207,6 +1204,7 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
1207
1204
|
]
|
|
1208
1205
|
}))]
|
|
1209
1206
|
}) });
|
|
1207
|
+
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1210
1208
|
} });
|
|
1211
1209
|
};
|
|
1212
1210
|
|