timelock-sdk 0.0.81 → 0.0.83
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-DSnOWcqf.d.ts → client-Dtm1qie2.d.ts} +236 -245
- package/dist/{client-CPNANzx8.d.cts → client-GoHd57RL.d.cts} +87 -96
- package/dist/client.cjs +101 -166
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +105 -168
- package/dist/client.js.map +1 -1
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./uniswapMathLens-CK8C7WOt.cjs";
|
|
2
|
-
import { B as useOptionTimeline, F as useUserOperators, G as useMaxPositionSize, H as useOptionPremium, I as usePerpsOperator, L as useClosePerp, P as useSetOperatorPerms, R as useMintPerp, U as useOptionPnl, V as useExtendOption, W as useMintOption, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, ct as useExerciseOption, d as usePriceAtTick, dt as useClosedUserOptions, f as UniswapPoolData, ft as TimelockProvider, h as useCurrentPrice, i as useVaultData, l as useBurnLiquidity, lt as OptionData, m as useCurrentTick, mt as useTimelockConfig, n as useLens, o as useMintLiquidity, p as usePoolData, pt as useCurrentMarket, r as useVaultTVL, s as LiquidityBlockData, st as useMarketData, t as useApproval, u as usePriceHistory, ut as useActiveUserOptions, z as OptionTimelineData } from "./client-
|
|
2
|
+
import { B as useOptionTimeline, F as useUserOperators, G as useMaxPositionSize, H as useOptionPremium, I as usePerpsOperator, L as useClosePerp, P as useSetOperatorPerms, R as useMintPerp, U as useOptionPnl, V as useExtendOption, W as useMintOption, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, ct as useExerciseOption, d as usePriceAtTick, dt as useClosedUserOptions, f as UniswapPoolData, ft as TimelockProvider, h as useCurrentPrice, i as useVaultData, l as useBurnLiquidity, lt as OptionData, m as useCurrentTick, mt as useTimelockConfig, n as useLens, o as useMintLiquidity, p as usePoolData, pt as useCurrentMarket, r as useVaultTVL, s as LiquidityBlockData, st as useMarketData, t as useApproval, u as usePriceHistory, ut as useActiveUserOptions, z as OptionTimelineData } from "./client-GoHd57RL.cjs";
|
|
3
3
|
export { LiquidityBlockData, OptionData, OptionTimelineData, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useTimelockConfig, useUserOperators, useVaultData, useVaultTVL };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./uniswapMathLens-C54iWXpi.js";
|
|
2
|
-
import { B as useOptionTimeline, F as useUserOperators, G as useMaxPositionSize, H as useOptionPremium, I as usePerpsOperator, L as useClosePerp, P as useSetOperatorPerms, R as useMintPerp, U as useOptionPnl, V as useExtendOption, W as useMintOption, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, ct as useExerciseOption, d as usePriceAtTick, dt as useClosedUserOptions, f as UniswapPoolData, ft as TimelockProvider, h as useCurrentPrice, i as useVaultData, l as useBurnLiquidity, lt as OptionData, m as useCurrentTick, mt as useTimelockConfig, n as useLens, o as useMintLiquidity, p as usePoolData, pt as useCurrentMarket, r as useVaultTVL, s as LiquidityBlockData, st as useMarketData, t as useApproval, u as usePriceHistory, ut as useActiveUserOptions, z as OptionTimelineData } from "./client-
|
|
2
|
+
import { B as useOptionTimeline, F as useUserOperators, G as useMaxPositionSize, H as useOptionPremium, I as usePerpsOperator, L as useClosePerp, P as useSetOperatorPerms, R as useMintPerp, U as useOptionPnl, V as useExtendOption, W as useMintOption, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, ct as useExerciseOption, d as usePriceAtTick, dt as useClosedUserOptions, f as UniswapPoolData, ft as TimelockProvider, h as useCurrentPrice, i as useVaultData, l as useBurnLiquidity, lt as OptionData, m as useCurrentTick, mt as useTimelockConfig, n as useLens, o as useMintLiquidity, p as usePoolData, pt as useCurrentMarket, r as useVaultTVL, s as LiquidityBlockData, st as useMarketData, t as useApproval, u as usePriceHistory, ut as useActiveUserOptions, z as OptionTimelineData } from "./client-Dtm1qie2.js";
|
|
3
3
|
export { LiquidityBlockData, OptionData, OptionTimelineData, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useTimelockConfig, useUserOperators, useVaultData, useVaultTVL };
|
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
|
|
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`
|
|
@@ -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
|
|
523
|
-
const [premium, protocolFee] = await getTimelockMarket
|
|
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
|
|
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,6 +941,69 @@ 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) => {
|
|
@@ -1142,25 +1140,17 @@ const useLiquidityBlocks = (vaultAddr) => {
|
|
|
1142
1140
|
|
|
1143
1141
|
//#endregion
|
|
1144
1142
|
//#region src/hooks/vault/useMintLiquidity.ts
|
|
1145
|
-
const batchGetAmountsFromLiquidity =
|
|
1146
|
-
const currentTicksArray = new Array(tickLower.length).fill(currentTick);
|
|
1147
|
-
const amounts = await lens.read.batchGetAmountsForLiquidityTicks([
|
|
1148
|
-
currentTicksArray,
|
|
1149
|
-
tickLower,
|
|
1150
|
-
tickUpper,
|
|
1151
|
-
liquidity
|
|
1152
|
-
]);
|
|
1143
|
+
const batchGetAmountsFromLiquidity = (tickLowers, tickUppers, liquidities, currentTick) => {
|
|
1153
1144
|
let totalAmount0 = 0n;
|
|
1154
1145
|
let totalAmount1 = 0n;
|
|
1155
1146
|
const amounts0 = [];
|
|
1156
1147
|
const amounts1 = [];
|
|
1157
|
-
for (const
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
amounts1.push(scaled);
|
|
1148
|
+
for (const [i, tickLower] of tickLowers.entries()) {
|
|
1149
|
+
const [amount0, amount1] = getAmountsFromLiquidity(tickLower, tickUppers[i], liquidities[i], currentTick);
|
|
1150
|
+
totalAmount0 += amount0;
|
|
1151
|
+
totalAmount1 += amount1;
|
|
1152
|
+
amounts0.push(amount0);
|
|
1153
|
+
amounts1.push(amount1);
|
|
1164
1154
|
}
|
|
1165
1155
|
return {
|
|
1166
1156
|
totalAmount0,
|
|
@@ -1170,98 +1160,45 @@ const batchGetAmountsFromLiquidity = async (lens, tickLower, tickUpper, liquidit
|
|
|
1170
1160
|
};
|
|
1171
1161
|
};
|
|
1172
1162
|
const useMintLiquidity = (vaultAddr) => {
|
|
1163
|
+
const queryClient = useQueryClient();
|
|
1173
1164
|
const client = useClient();
|
|
1174
|
-
const { address } = useAccount();
|
|
1175
1165
|
const { pool } = useVaultData(vaultAddr);
|
|
1176
|
-
const { timelockLens
|
|
1177
|
-
const currentTick = useCurrentTick(pool);
|
|
1166
|
+
const { timelockLens } = useLens();
|
|
1167
|
+
const { exact: currentTick } = useCurrentTick(pool);
|
|
1178
1168
|
const { token0, token1 } = usePoolData(pool);
|
|
1179
|
-
const {
|
|
1180
|
-
const {
|
|
1181
|
-
const
|
|
1182
|
-
if (!
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
const approvalPromises = [];
|
|
1187
|
-
if (allowance0 <= totalAmount0) {
|
|
1188
|
-
const approvalHash = await writeContractAsync({
|
|
1189
|
-
address: token0,
|
|
1190
|
-
abi: erc20Abi,
|
|
1191
|
-
functionName: "approve",
|
|
1192
|
-
args: [vaultAddr, maxUint256]
|
|
1193
|
-
});
|
|
1194
|
-
approvalPromises.push(waitForTransactionReceipt(client, { hash: approvalHash }));
|
|
1195
|
-
}
|
|
1196
|
-
if (allowance1 <= totalAmount1) {
|
|
1197
|
-
const approvalHash1 = await writeContractAsync({
|
|
1198
|
-
address: token1,
|
|
1199
|
-
abi: erc20Abi,
|
|
1200
|
-
functionName: "approve",
|
|
1201
|
-
args: [vaultAddr, maxUint256]
|
|
1202
|
-
});
|
|
1203
|
-
approvalPromises.push(waitForTransactionReceipt(client, { hash: approvalHash1 }));
|
|
1204
|
-
}
|
|
1205
|
-
if (approvalPromises.length > 0) await Promise.all(approvalPromises);
|
|
1169
|
+
const { askForApproval } = useApproval();
|
|
1170
|
+
const { writeContractAsync } = useWriteContract();
|
|
1171
|
+
const processApproval = async (params) => {
|
|
1172
|
+
if (currentTick === void 0 || !token0 || !token1 || !vaultAddr) throw new Error("Current tick not available");
|
|
1173
|
+
const { totalAmount0, totalAmount1 } = batchGetAmountsFromLiquidity(params.map((p) => p.tickLower), params.map((p) => p.tickUpper), params.map((p) => p.liquidity), currentTick);
|
|
1174
|
+
await askForApproval(token0, vaultAddr, totalAmount0);
|
|
1175
|
+
await askForApproval(token1, vaultAddr, totalAmount1);
|
|
1206
1176
|
};
|
|
1207
|
-
|
|
1177
|
+
return useMutation({ mutationFn: async (params) => {
|
|
1208
1178
|
if (!client) throw new Error("Wallet not connected");
|
|
1209
|
-
if (
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1179
|
+
if (currentTick === void 0) throw new Error("Current tick not available");
|
|
1180
|
+
if (!timelockLens || !vaultAddr) throw new Error("Vault/lens not available");
|
|
1181
|
+
if (!Array.isArray(params)) params = [params];
|
|
1182
|
+
if (params.length === 0) throw new Error("No positions to mint");
|
|
1183
|
+
await processApproval(params);
|
|
1184
|
+
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, params.map((position) => position.tickLower)]);
|
|
1185
|
+
await waitForTransactionReceipt(client, { hash: await writeContractAsync({
|
|
1216
1186
|
address: vaultAddr,
|
|
1217
1187
|
abi: singleOwnerVaultAbi,
|
|
1218
|
-
functionName: "
|
|
1219
|
-
args: [
|
|
1220
|
-
tickLower,
|
|
1221
|
-
tickUpper,
|
|
1222
|
-
liquidity,
|
|
1223
|
-
await timelockLens.read.getRefTick([vaultAddr, tickLower])
|
|
1224
|
-
]
|
|
1225
|
-
});
|
|
1226
|
-
await waitForTransactionReceipt(client, { hash: hash$1 });
|
|
1227
|
-
return hash$1;
|
|
1228
|
-
};
|
|
1229
|
-
const mintMultiple = async (positions) => {
|
|
1230
|
-
if (!client) throw new Error("Wallet not connected");
|
|
1231
|
-
if (!currentTick.exact) throw new Error("Current tick not available");
|
|
1232
|
-
if (positions.length === 0) throw new Error("No positions to mint");
|
|
1233
|
-
if (!timelockLens || !vaultAddr) throw new Error("Vault/lens not available");
|
|
1234
|
-
if (positions.length === 1) await mint(positions[0].tickLower, positions[0].tickUpper, positions[0].liquidity);
|
|
1235
|
-
else {
|
|
1236
|
-
await askForApproval(positions);
|
|
1237
|
-
const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
|
|
1238
|
-
await waitForTransactionReceipt(client, { hash: await writeContractAsync({
|
|
1239
|
-
address: vaultAddr,
|
|
1188
|
+
functionName: "multicall",
|
|
1189
|
+
args: [params.map((p, i) => encodeFunctionData({
|
|
1240
1190
|
abi: singleOwnerVaultAbi,
|
|
1241
|
-
functionName: "
|
|
1242
|
-
args: [
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
}) });
|
|
1253
|
-
}
|
|
1254
|
-
};
|
|
1255
|
-
return {
|
|
1256
|
-
mintMultiple,
|
|
1257
|
-
mint,
|
|
1258
|
-
hash,
|
|
1259
|
-
isPending,
|
|
1260
|
-
isConfirming,
|
|
1261
|
-
isSuccess,
|
|
1262
|
-
error,
|
|
1263
|
-
isLoading: isPending || isConfirming
|
|
1264
|
-
};
|
|
1191
|
+
functionName: "mint",
|
|
1192
|
+
args: [
|
|
1193
|
+
p.tickLower,
|
|
1194
|
+
p.tickUpper,
|
|
1195
|
+
p.liquidity,
|
|
1196
|
+
refTicks[i]
|
|
1197
|
+
]
|
|
1198
|
+
}))]
|
|
1199
|
+
}) });
|
|
1200
|
+
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1201
|
+
} });
|
|
1265
1202
|
};
|
|
1266
1203
|
|
|
1267
1204
|
//#endregion
|