timelock-sdk 0.0.81 → 0.0.82

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
@@ -1151,25 +1151,17 @@ const useLiquidityBlocks = (vaultAddr) => {
1151
1151
 
1152
1152
  //#endregion
1153
1153
  //#region src/hooks/vault/useMintLiquidity.ts
1154
- const batchGetAmountsFromLiquidity = async (lens, tickLower, tickUpper, liquidity, currentTick) => {
1155
- const currentTicksArray = new Array(tickLower.length).fill(currentTick);
1156
- const amounts = await lens.read.batchGetAmountsForLiquidityTicks([
1157
- currentTicksArray,
1158
- tickLower,
1159
- tickUpper,
1160
- liquidity
1161
- ]);
1154
+ const batchGetAmountsFromLiquidity = (tickLowers, tickUppers, liquidities, currentTick) => {
1162
1155
  let totalAmount0 = 0n;
1163
1156
  let totalAmount1 = 0n;
1164
1157
  const amounts0 = [];
1165
1158
  const amounts1 = [];
1166
- for (const scaled of amounts[0]) {
1167
- totalAmount0 += scaled;
1168
- amounts0.push(scaled);
1169
- }
1170
- for (const scaled of amounts[1]) {
1171
- totalAmount1 += scaled;
1172
- amounts1.push(scaled);
1159
+ for (const [i, tickLower] of tickLowers.entries()) {
1160
+ const [amount0, amount1] = require_optionUtils.getAmountsFromLiquidity(tickLower, tickUppers[i], liquidities[i], currentTick);
1161
+ totalAmount0 += amount0;
1162
+ totalAmount1 += amount1;
1163
+ amounts0.push(amount0);
1164
+ amounts1.push(amount1);
1173
1165
  }
1174
1166
  return {
1175
1167
  totalAmount0,
@@ -1180,97 +1172,42 @@ const batchGetAmountsFromLiquidity = async (lens, tickLower, tickUpper, liquidit
1180
1172
  };
1181
1173
  const useMintLiquidity = (vaultAddr) => {
1182
1174
  const client = (0, wagmi.useClient)();
1183
- const { address } = (0, wagmi.useAccount)();
1184
1175
  const { pool } = useVaultData(vaultAddr);
1185
- const { timelockLens, uniswapLens } = useLens();
1186
- const currentTick = useCurrentTick(pool);
1176
+ const { timelockLens } = useLens();
1177
+ const { exact: currentTick } = useCurrentTick(pool);
1187
1178
  const { token0, token1 } = usePoolData(pool);
1188
- const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
1189
- const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
1190
- const askForApproval = async (params) => {
1191
- if (!address || !client) throw new Error("Wallet not connected");
1192
- if (currentTick.exact === void 0 || !token0 || !token1 || !vaultAddr || !uniswapLens) throw new Error("Current tick not available");
1193
- const { totalAmount0, totalAmount1 } = await batchGetAmountsFromLiquidity(uniswapLens, params.map((p) => p.tickLower), params.map((p) => p.tickUpper), params.map((p) => p.liquidity), currentTick.exact);
1194
- const [allowance0, allowance1] = await Promise.all([require_optionUtils.getErc20(token0, client).read.allowance([address, vaultAddr]), require_optionUtils.getErc20(token1, client).read.allowance([address, vaultAddr])]);
1195
- const approvalPromises = [];
1196
- if (allowance0 <= totalAmount0) {
1197
- const approvalHash = await writeContractAsync({
1198
- address: token0,
1199
- abi: viem.erc20Abi,
1200
- functionName: "approve",
1201
- args: [vaultAddr, viem.maxUint256]
1202
- });
1203
- approvalPromises.push((0, viem_actions.waitForTransactionReceipt)(client, { hash: approvalHash }));
1204
- }
1205
- if (allowance1 <= totalAmount1) {
1206
- const approvalHash1 = await writeContractAsync({
1207
- address: token1,
1208
- abi: viem.erc20Abi,
1209
- functionName: "approve",
1210
- args: [vaultAddr, viem.maxUint256]
1211
- });
1212
- approvalPromises.push((0, viem_actions.waitForTransactionReceipt)(client, { hash: approvalHash1 }));
1213
- }
1214
- if (approvalPromises.length > 0) await Promise.all(approvalPromises);
1179
+ const { askForApproval } = useApproval();
1180
+ const { writeContractAsync } = (0, wagmi.useWriteContract)();
1181
+ const processApproval = async (params) => {
1182
+ if (currentTick === void 0 || !token0 || !token1 || !vaultAddr) throw new Error("Current tick not available");
1183
+ const { totalAmount0, totalAmount1 } = batchGetAmountsFromLiquidity(params.map((p) => p.tickLower), params.map((p) => p.tickUpper), params.map((p) => p.liquidity), currentTick);
1184
+ await askForApproval(token0, vaultAddr, totalAmount0);
1185
+ await askForApproval(token1, vaultAddr, totalAmount1);
1215
1186
  };
1216
- const mint = async (tickLower, tickUpper, liquidity) => {
1187
+ return (0, __tanstack_react_query.useMutation)({ mutationFn: async (params) => {
1217
1188
  if (!client) throw new Error("Wallet not connected");
1218
- if (!vaultAddr || !timelockLens) throw new Error("Vault/lens not available");
1219
- await askForApproval([{
1220
- tickLower,
1221
- tickUpper,
1222
- liquidity
1223
- }]);
1224
- const hash$1 = await writeContractAsync({
1189
+ if (currentTick === void 0) throw new Error("Current tick not available");
1190
+ if (!timelockLens || !vaultAddr) throw new Error("Vault/lens not available");
1191
+ if (!Array.isArray(params)) params = [params];
1192
+ if (params.length === 0) throw new Error("No positions to mint");
1193
+ await processApproval(params);
1194
+ const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, params.map((position) => position.tickLower)]);
1195
+ await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
1225
1196
  address: vaultAddr,
1226
1197
  abi: require_singleOwnerVault.singleOwnerVaultAbi,
1227
- functionName: "mint",
1228
- args: [
1229
- tickLower,
1230
- tickUpper,
1231
- liquidity,
1232
- await timelockLens.read.getRefTick([vaultAddr, tickLower])
1233
- ]
1234
- });
1235
- await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
1236
- return hash$1;
1237
- };
1238
- const mintMultiple = async (positions) => {
1239
- if (!client) throw new Error("Wallet not connected");
1240
- if (!currentTick.exact) throw new Error("Current tick not available");
1241
- if (positions.length === 0) throw new Error("No positions to mint");
1242
- if (!timelockLens || !vaultAddr) throw new Error("Vault/lens not available");
1243
- if (positions.length === 1) await mint(positions[0].tickLower, positions[0].tickUpper, positions[0].liquidity);
1244
- else {
1245
- await askForApproval(positions);
1246
- const refTicks = await timelockLens.read.batchGetRefTick([vaultAddr, positions.map((position) => position.tickLower)]);
1247
- await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
1248
- address: vaultAddr,
1198
+ functionName: "multicall",
1199
+ args: [params.map((p, i) => (0, viem.encodeFunctionData)({
1249
1200
  abi: require_singleOwnerVault.singleOwnerVaultAbi,
1250
- functionName: "multicall",
1251
- args: [positions.map((p, i) => (0, viem.encodeFunctionData)({
1252
- abi: require_singleOwnerVault.singleOwnerVaultAbi,
1253
- functionName: "mint",
1254
- args: [
1255
- p.tickLower,
1256
- p.tickUpper,
1257
- p.liquidity,
1258
- refTicks[i]
1259
- ]
1260
- }))]
1261
- }) });
1262
- }
1263
- };
1264
- return {
1265
- mintMultiple,
1266
- mint,
1267
- hash,
1268
- isPending,
1269
- isConfirming,
1270
- isSuccess,
1271
- error,
1272
- isLoading: isPending || isConfirming
1273
- };
1201
+ functionName: "mint",
1202
+ args: [
1203
+ p.tickLower,
1204
+ p.tickUpper,
1205
+ p.liquidity,
1206
+ refTicks[i]
1207
+ ]
1208
+ }))]
1209
+ }) });
1210
+ } });
1274
1211
  };
1275
1212
 
1276
1213
  //#endregion