timelock-sdk 0.0.49 → 0.0.51
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/abis.cjs +1 -1
- package/dist/abis.d.cts +1 -1
- package/dist/abis.d.ts +1 -1
- package/dist/abis.js +1 -1
- package/dist/client.cjs +33 -24
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +57 -513
- package/dist/client.d.ts +57 -513
- package/dist/client.js +34 -25
- package/dist/client.js.map +1 -1
- package/dist/{index-Bg4UAy7Y.d.cts → index-BPKijlT_.d.cts} +2 -458
- package/dist/{index-DiDvh-kv.d.ts → index-Dt4gerGl.d.ts} +93 -549
- package/dist/{numberUtils-BKQtAolx.cjs → numberUtils-CkwkoxOr.cjs} +3 -3
- package/dist/{numberUtils-BKQtAolx.cjs.map → numberUtils-CkwkoxOr.cjs.map} +1 -1
- package/dist/{numberUtils-Dk0TuHnT.js → numberUtils-Cznv1Tfa.js} +3 -3
- package/dist/{numberUtils-Dk0TuHnT.js.map → numberUtils-Cznv1Tfa.js.map} +1 -1
- package/dist/{optionsMarket-CvArD6d_.js → optionsMarket-BDBU1gUS.js} +1 -41
- package/dist/optionsMarket-BDBU1gUS.js.map +1 -0
- package/dist/{optionsMarket-PBduSBXF.cjs → optionsMarket-DEFMUI2G.cjs} +1 -41
- package/dist/optionsMarket-DEFMUI2G.cjs.map +1 -0
- package/dist/package.cjs +2 -2
- package/dist/package.d.cts +2 -2
- package/dist/package.d.ts +2 -2
- package/dist/package.js +2 -2
- package/dist/{uniswapMathLens-uDGUc-kg.d.ts → uniswapMathLens-BQ_ArpKd.d.cts} +1 -33
- package/dist/{uniswapMathLens-BiaRFVeY.d.cts → uniswapMathLens-DCuaXAGZ.d.ts} +1 -33
- package/package.json +1 -1
- package/dist/optionsMarket-CvArD6d_.js.map +0 -1
- package/dist/optionsMarket-PBduSBXF.cjs.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-
|
|
5
|
-
import { C as token1ToToken0, D as getUniswapMathLens, E as getTimelockMarket, O as timelockLenses, S as token0ToToken1, T as getTimelockLens, b as roundTickDown, d as wrapPrice, h as getPriceAtTick, k as uniswapMathLenses, l as wrapAmount, m as PRICE_PRECISION, w as getErc20, y as liquiditiesToAmounts } from "./numberUtils-
|
|
4
|
+
import { r as lensAbi, t as optionsMarketAbi } from "./optionsMarket-BDBU1gUS.js";
|
|
5
|
+
import { C as token1ToToken0, D as getUniswapMathLens, E as getTimelockMarket, O as timelockLenses, S as token0ToToken1, T as getTimelockLens, b as roundTickDown, d as wrapPrice, h as getPriceAtTick, k as uniswapMathLenses, l as wrapAmount, m as PRICE_PRECISION, w as getErc20, y as liquiditiesToAmounts } from "./numberUtils-Cznv1Tfa.js";
|
|
6
6
|
import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
|
|
7
|
-
import { encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
|
|
7
|
+
import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
|
|
8
8
|
import React, { createContext, useContext, useMemo } from "react";
|
|
9
9
|
import { useAccount, useChainId, useClient, useReadContract, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
10
10
|
import { GraphQLClient, RequestOptions } from "graphql-request";
|
|
@@ -210,16 +210,33 @@ const useLens = () => {
|
|
|
210
210
|
}), [client]);
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/hooks/pool/usePoolData.ts
|
|
215
|
+
const usePoolData = (poolAddr) => {
|
|
216
|
+
const { timelockLens } = useLens();
|
|
217
|
+
const client = useClient();
|
|
218
|
+
const { data } = useReadContract({
|
|
219
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
220
|
+
abi: lensAbi,
|
|
221
|
+
functionName: "getPoolData",
|
|
222
|
+
args: poolAddr ? [poolAddr] : void 0,
|
|
223
|
+
query: { enabled: !!poolAddr && !!client }
|
|
224
|
+
});
|
|
225
|
+
return data || {};
|
|
226
|
+
};
|
|
227
|
+
|
|
213
228
|
//#endregion
|
|
214
229
|
//#region src/hooks/market/useExerciseOption.ts
|
|
230
|
+
const swapper = "0xc396aa907F8De0c32460050B8Adbf047186C504d";
|
|
215
231
|
const useExerciseOption = (marketAddr) => {
|
|
216
|
-
const { vault } = useMarketData(marketAddr);
|
|
232
|
+
const { vault, pool } = useMarketData(marketAddr);
|
|
233
|
+
const { fee } = usePoolData(pool);
|
|
217
234
|
const { timelockLens } = useLens();
|
|
218
235
|
const client = useClient();
|
|
219
236
|
const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
|
|
220
237
|
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
|
|
221
238
|
const exerciseOption = async (option, liquidities) => {
|
|
222
|
-
if (!client || !timelockLens || !vault || !marketAddr) throw new Error("Wallet not connected");
|
|
239
|
+
if (!client || !timelockLens || !vault || !marketAddr || !fee) throw new Error("Wallet not connected");
|
|
223
240
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
224
241
|
const hash$1 = await writeContractAsync({
|
|
225
242
|
address: marketAddr,
|
|
@@ -229,6 +246,8 @@ const useExerciseOption = (marketAddr) => {
|
|
|
229
246
|
option.optionId,
|
|
230
247
|
liquidities,
|
|
231
248
|
0n,
|
|
249
|
+
swapper,
|
|
250
|
+
encodeAbiParameters([{ type: "uint24" }], [fee]),
|
|
232
251
|
refTick
|
|
233
252
|
]
|
|
234
253
|
});
|
|
@@ -287,21 +306,6 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) =>
|
|
|
287
306
|
};
|
|
288
307
|
};
|
|
289
308
|
|
|
290
|
-
//#endregion
|
|
291
|
-
//#region src/hooks/pool/usePoolData.ts
|
|
292
|
-
const usePoolData = (poolAddr) => {
|
|
293
|
-
const { timelockLens } = useLens();
|
|
294
|
-
const client = useClient();
|
|
295
|
-
const { data } = useReadContract({
|
|
296
|
-
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
297
|
-
abi: lensAbi,
|
|
298
|
-
functionName: "getPoolData",
|
|
299
|
-
args: poolAddr ? [poolAddr] : void 0,
|
|
300
|
-
query: { enabled: !!poolAddr && !!client }
|
|
301
|
-
});
|
|
302
|
-
return data || {};
|
|
303
|
-
};
|
|
304
|
-
|
|
305
309
|
//#endregion
|
|
306
310
|
//#region src/hooks/pool/useCurrentTick.ts
|
|
307
311
|
const useCurrentTick = (poolAddr) => {
|
|
@@ -344,15 +348,19 @@ const useMintOption = (marketAddr) => {
|
|
|
344
348
|
};
|
|
345
349
|
const mintOption = async (optionType, amount, duration, strikeTick) => {
|
|
346
350
|
if (!client) throw new Error("Wallet not connected");
|
|
347
|
-
if (!
|
|
351
|
+
if (!marketAddr) throw new Error("Market address not available");
|
|
352
|
+
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
353
|
+
if (!vault) throw new Error("Vault not available");
|
|
354
|
+
if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
|
|
348
355
|
strikeTick = roundTickDown(strikeTick ?? currentTick, tickSpacing);
|
|
349
356
|
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTick += tickSpacing;
|
|
350
|
-
|
|
357
|
+
const [premium, protocolFee] = await getTimelockMarket(marketAddr, client).read.calculatePremium([
|
|
351
358
|
optionType === "CALL" ? 0 : 1,
|
|
352
359
|
amount,
|
|
353
360
|
strikeTick,
|
|
354
|
-
|
|
355
|
-
])
|
|
361
|
+
duration
|
|
362
|
+
]);
|
|
363
|
+
await askForApproval(premium + protocolFee);
|
|
356
364
|
const hash$1 = await writeContractAsync({
|
|
357
365
|
address: marketAddr,
|
|
358
366
|
abi: optionsMarketAbi,
|
|
@@ -361,8 +369,9 @@ const useMintOption = (marketAddr) => {
|
|
|
361
369
|
optionType === "CALL" ? 0 : 1,
|
|
362
370
|
amount,
|
|
363
371
|
strikeTick,
|
|
364
|
-
|
|
372
|
+
duration,
|
|
365
373
|
BigInt(1e69),
|
|
374
|
+
false,
|
|
366
375
|
await timelockLens.read.getRefTick([vault, strikeTick])
|
|
367
376
|
]
|
|
368
377
|
});
|