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-DSnOWcqf.d.ts → client-BjjoSITU.d.ts} +149 -158
- package/dist/{client-CPNANzx8.d.cts → client-GoHd57RL.d.cts} +87 -96
- package/dist/client.cjs +36 -99
- 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 +37 -100
- 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.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 =
|
|
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
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
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
|
|
1186
|
-
const currentTick = useCurrentTick(pool);
|
|
1176
|
+
const { timelockLens } = useLens();
|
|
1177
|
+
const { exact: currentTick } = useCurrentTick(pool);
|
|
1187
1178
|
const { token0, token1 } = usePoolData(pool);
|
|
1188
|
-
const {
|
|
1189
|
-
const {
|
|
1190
|
-
const
|
|
1191
|
-
if (!
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
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
|
-
|
|
1187
|
+
return (0, __tanstack_react_query.useMutation)({ mutationFn: async (params) => {
|
|
1217
1188
|
if (!client) throw new Error("Wallet not connected");
|
|
1218
|
-
if (
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
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: "
|
|
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: "
|
|
1251
|
-
args: [
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
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
|