timelock-sdk 0.0.78 → 0.0.79
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/{index-CdkTrz02.d.ts → client-D9QtRxOF.d.ts} +30559 -93
- package/dist/{index-CFBcBY1K.d.cts → client-h7lO3ik2.d.cts} +30468 -2
- package/dist/client.cjs +49 -50
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -30468
- package/dist/client.d.ts +2 -30468
- package/dist/client.js +18 -19
- package/dist/client.js.map +1 -1
- package/dist/{numberUtils-fHghA8Tv.cjs → optionUtils-CDD_7qmy.cjs} +23 -1
- package/dist/optionUtils-CDD_7qmy.cjs.map +1 -0
- package/dist/{numberUtils--YU8VSJO.js → optionUtils-CI-AZi8X.js} +12 -2
- package/dist/optionUtils-CI-AZi8X.js.map +1 -0
- package/dist/package.cjs +34 -32
- package/dist/package.d.cts +2 -2
- package/dist/package.d.ts +2 -2
- package/dist/package.js +2 -2
- package/package.json +1 -1
- package/dist/numberUtils--YU8VSJO.js.map +0 -1
- package/dist/numberUtils-fHghA8Tv.cjs.map +0 -1
package/dist/client.cjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const require_optionUtils = require('./optionUtils-CDD_7qmy.cjs');
|
|
5
5
|
const require_optionsMarket = require('./optionsMarket-DxGdV3HF.cjs');
|
|
6
6
|
const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
|
|
7
7
|
let viem = require("viem");
|
|
8
|
-
viem =
|
|
8
|
+
viem = require_optionUtils.__toESM(viem);
|
|
9
9
|
let react = require("react");
|
|
10
|
-
react =
|
|
10
|
+
react = require_optionUtils.__toESM(react);
|
|
11
11
|
let wagmi = require("wagmi");
|
|
12
|
-
wagmi =
|
|
12
|
+
wagmi = require_optionUtils.__toESM(wagmi);
|
|
13
13
|
let graphql_request = require("graphql-request");
|
|
14
|
-
graphql_request =
|
|
14
|
+
graphql_request = require_optionUtils.__toESM(graphql_request);
|
|
15
15
|
let graphql_tag = require("graphql-tag");
|
|
16
|
-
graphql_tag =
|
|
16
|
+
graphql_tag = require_optionUtils.__toESM(graphql_tag);
|
|
17
17
|
let viem_actions = require("viem/actions");
|
|
18
|
-
viem_actions =
|
|
18
|
+
viem_actions = require_optionUtils.__toESM(viem_actions);
|
|
19
19
|
let __tanstack_react_query = require("@tanstack/react-query");
|
|
20
|
-
__tanstack_react_query =
|
|
20
|
+
__tanstack_react_query = require_optionUtils.__toESM(__tanstack_react_query);
|
|
21
21
|
|
|
22
22
|
//#region src/generated/graphql.ts
|
|
23
23
|
const UserOptionFieldsFragmentDoc = graphql_tag.default`
|
|
@@ -291,8 +291,8 @@ function getSdk(client, withWrapper = defaultWrapper) {
|
|
|
291
291
|
const TimelockMarketContext = (0, react.createContext)(void 0);
|
|
292
292
|
const TimelockMarketProvider = ({ children, marketData, envioGraphqlUrl }) => {
|
|
293
293
|
const chainId = (0, wagmi.useChainId)();
|
|
294
|
-
const lensAddr =
|
|
295
|
-
const uniswapMathLensAddr =
|
|
294
|
+
const lensAddr = require_optionUtils.timelockLenses[chainId];
|
|
295
|
+
const uniswapMathLensAddr = require_optionUtils.uniswapMathLenses[chainId];
|
|
296
296
|
const graphqlClient = (0, react.useMemo)(() => {
|
|
297
297
|
if (envioGraphqlUrl) return getSdk(new graphql_request.GraphQLClient(envioGraphqlUrl));
|
|
298
298
|
}, [envioGraphqlUrl]);
|
|
@@ -327,8 +327,8 @@ const useTimelockConfig = () => {
|
|
|
327
327
|
const useLens = () => {
|
|
328
328
|
const client = (0, wagmi.useClient)();
|
|
329
329
|
return (0, react.useMemo)(() => ({
|
|
330
|
-
timelockLens: client ?
|
|
331
|
-
uniswapLens: client ?
|
|
330
|
+
timelockLens: client ? require_optionUtils.getTimelockLens(client) : void 0,
|
|
331
|
+
uniswapLens: client ? require_optionUtils.getUniswapMathLens(client) : void 0
|
|
332
332
|
}), [client]);
|
|
333
333
|
};
|
|
334
334
|
|
|
@@ -447,8 +447,8 @@ const useMaxPositionSize = (marketAddr, strikeTick, maxBorrowableRange = 100) =>
|
|
|
447
447
|
});
|
|
448
448
|
const data = strikeTick !== void 0 ? data1 : data0;
|
|
449
449
|
const { maxCallSize, maxPutSize } = (0, react.useMemo)(() => data && optionAssetDecimals ? {
|
|
450
|
-
maxCallSize:
|
|
451
|
-
maxPutSize:
|
|
450
|
+
maxCallSize: require_optionUtils.wrapAmount(data[0], optionAssetDecimals),
|
|
451
|
+
maxPutSize: require_optionUtils.wrapAmount(data[1], optionAssetDecimals)
|
|
452
452
|
} : {}, [data, optionAssetDecimals]);
|
|
453
453
|
const refetch = () => {
|
|
454
454
|
refetch0();
|
|
@@ -488,7 +488,7 @@ const useApproval = () => {
|
|
|
488
488
|
const { writeContractAsync, data: hash, isPending, error, reset } = (0, wagmi.useWriteContract)();
|
|
489
489
|
const askForApproval = async (tokenAddress, spenderAddress, amount) => {
|
|
490
490
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
491
|
-
if (await
|
|
491
|
+
if (await require_optionUtils.getErc20(tokenAddress, client).read.allowance([address, spenderAddress]) < amount) await (0, viem_actions.waitForTransactionReceipt)(client, { hash: await writeContractAsync({
|
|
492
492
|
address: tokenAddress,
|
|
493
493
|
abi: viem.erc20Abi,
|
|
494
494
|
functionName: "approve",
|
|
@@ -522,8 +522,8 @@ const useMintOption = (marketAddr) => {
|
|
|
522
522
|
if (!timelockLens) throw new Error("Timelock lens not available");
|
|
523
523
|
if (!vault || !payoutAsset || optionAssetIsToken0 === void 0) throw new Error("Market data not available");
|
|
524
524
|
if (currentTick === void 0 || !tickSpacing) throw new Error("Pool data not available");
|
|
525
|
-
strikeTick =
|
|
526
|
-
const [premium, protocolFee] = await
|
|
525
|
+
strikeTick = require_optionUtils.getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
|
|
526
|
+
const [premium, protocolFee] = await require_optionUtils.getTimelockMarket(marketAddr, client).read.calculatePremium([
|
|
527
527
|
optionType === "CALL" ? 0 : 1,
|
|
528
528
|
amount,
|
|
529
529
|
strikeTick,
|
|
@@ -555,15 +555,16 @@ const useMintOption = (marketAddr) => {
|
|
|
555
555
|
//#endregion
|
|
556
556
|
//#region src/hooks/market/useOptionPnl.ts
|
|
557
557
|
const useOptionPnl = (option) => {
|
|
558
|
-
const { marketAddr, optionType,
|
|
558
|
+
const { marketAddr, optionType, entryTick, positionSizeCurrent } = option;
|
|
559
559
|
const { pool, optionAssetIsToken0, payoutAssetDecimals, tickSpacing } = useMarketData(marketAddr);
|
|
560
560
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
561
|
-
const strikeSize = positionSizeCurrent * strikePrice / require_numberUtils.PRICE_PRECISION;
|
|
562
561
|
const displayPnl = (0, react.useMemo)(() => {
|
|
563
|
-
if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !
|
|
564
|
-
const
|
|
565
|
-
|
|
562
|
+
if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !payoutAssetDecimals) return void 0;
|
|
563
|
+
const entrySize = optionAssetIsToken0 ? require_optionUtils.token0ToToken1(positionSizeCurrent, entryTick) : require_optionUtils.token1ToToken0(positionSizeCurrent, entryTick);
|
|
564
|
+
const delta = (optionAssetIsToken0 ? require_optionUtils.token0ToToken1(positionSizeCurrent, currentTick) : require_optionUtils.token1ToToken0(positionSizeCurrent, currentTick)) - entrySize;
|
|
565
|
+
return require_optionUtils.wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
|
|
566
566
|
}, [
|
|
567
|
+
entryTick,
|
|
567
568
|
optionType,
|
|
568
569
|
optionAssetIsToken0,
|
|
569
570
|
currentTick,
|
|
@@ -572,16 +573,14 @@ const useOptionPnl = (option) => {
|
|
|
572
573
|
]);
|
|
573
574
|
return {
|
|
574
575
|
unrealizedPayout: (0, react.useMemo)(() => {
|
|
575
|
-
if (!payoutAssetDecimals || !currentTick || !tickSpacing) return void 0;
|
|
576
|
-
|
|
577
|
-
const delta = (optionAssetIsToken0 ? amount1 + require_numberUtils.token0ToToken1(amount0, currentTick) : amount0 + require_numberUtils.token1ToToken0(amount1, currentTick)) - strikeSize;
|
|
578
|
-
const pnl = optionType === "CALL" ? delta : -delta;
|
|
579
|
-
return require_numberUtils.wrapAmount(pnl < 0 ? 0n : pnl, payoutAssetDecimals);
|
|
576
|
+
if (!payoutAssetDecimals || !currentTick || !tickSpacing || optionAssetIsToken0 === void 0) return void 0;
|
|
577
|
+
return require_optionUtils.wrapAmount(require_optionUtils.getPayoutAtTick(option, option.liquiditiesCurrent, currentTick, tickSpacing, optionAssetIsToken0), payoutAssetDecimals);
|
|
580
578
|
}, [
|
|
581
579
|
currentTick,
|
|
582
580
|
tickSpacing,
|
|
583
581
|
optionType,
|
|
584
|
-
payoutAssetDecimals
|
|
582
|
+
payoutAssetDecimals,
|
|
583
|
+
optionAssetIsToken0
|
|
585
584
|
]),
|
|
586
585
|
displayPnl
|
|
587
586
|
};
|
|
@@ -595,7 +594,7 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, addedDuration, r
|
|
|
595
594
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
596
595
|
const strikeTickRounded = (0, react.useMemo)(() => {
|
|
597
596
|
if (!tickSpacing || currentTick === void 0) return;
|
|
598
|
-
let strikeTickRounded$1 =
|
|
597
|
+
let strikeTickRounded$1 = require_optionUtils.roundTickDown(strikeTick ?? currentTick, tickSpacing);
|
|
599
598
|
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTickRounded$1 += tickSpacing;
|
|
600
599
|
return strikeTickRounded$1;
|
|
601
600
|
}, [
|
|
@@ -621,9 +620,9 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, addedDuration, r
|
|
|
621
620
|
return (0, react.useMemo)(() => {
|
|
622
621
|
if (premium === void 0 || protocolFee === void 0 || payoutAssetDecimals === void 0) return {};
|
|
623
622
|
return {
|
|
624
|
-
premium:
|
|
625
|
-
protocolFee:
|
|
626
|
-
totalPremium:
|
|
623
|
+
premium: require_optionUtils.wrapAmount(premium, payoutAssetDecimals),
|
|
624
|
+
protocolFee: require_optionUtils.wrapAmount(protocolFee, payoutAssetDecimals),
|
|
625
|
+
totalPremium: require_optionUtils.wrapAmount(premium + protocolFee, payoutAssetDecimals)
|
|
627
626
|
};
|
|
628
627
|
}, [
|
|
629
628
|
premium,
|
|
@@ -674,7 +673,7 @@ const useUserOptions = (userAddr, marketAddr, active = false) => {
|
|
|
674
673
|
enabled: !!userAddr && !!marketAddr && !!graphqlClient
|
|
675
674
|
});
|
|
676
675
|
return {
|
|
677
|
-
data: data ||
|
|
676
|
+
data: data || require_optionUtils.EMPTY_ARRAY,
|
|
678
677
|
...rest
|
|
679
678
|
};
|
|
680
679
|
};
|
|
@@ -697,7 +696,7 @@ const useExtendOption = (marketAddr) => {
|
|
|
697
696
|
const extendOption = async ({ option, duration }) => {
|
|
698
697
|
if (!client || !address) throw new Error("Wallet not connected");
|
|
699
698
|
if (!marketAddr || !payoutAsset) throw new Error("Market address not available");
|
|
700
|
-
const market =
|
|
699
|
+
const market = require_optionUtils.getTimelockMarket(marketAddr, client);
|
|
701
700
|
const remainingDuration = Math.max(0, Math.floor((option.expiresAt.getTime() - Date.now()) / 1e3));
|
|
702
701
|
const [premium, protocolFee] = await market.read.calculatePremium([
|
|
703
702
|
option.optionType === "CALL" ? 0 : 1,
|
|
@@ -749,7 +748,7 @@ const useUserOperators = (userAddr, marketAddr) => {
|
|
|
749
748
|
});
|
|
750
749
|
return {
|
|
751
750
|
...rest,
|
|
752
|
-
data: data ||
|
|
751
|
+
data: data || require_optionUtils.EMPTY_ARRAY
|
|
753
752
|
};
|
|
754
753
|
};
|
|
755
754
|
|
|
@@ -791,17 +790,17 @@ const useSetOperatorPerms = (marketAddr) => {
|
|
|
791
790
|
//#region src/hooks/market/useOptionTimeline.ts
|
|
792
791
|
const useOptionTimeline = (marketAddr, optionId) => {
|
|
793
792
|
const { graphqlClient } = useTimelockConfig();
|
|
794
|
-
|
|
793
|
+
marketAddr = marketAddr === null || marketAddr === void 0 ? void 0 : marketAddr.toLowerCase();
|
|
795
794
|
const { data,...rest } = (0, __tanstack_react_query.useQuery)({
|
|
796
795
|
queryKey: [
|
|
797
796
|
"optionTimeline",
|
|
798
|
-
|
|
797
|
+
marketAddr || "--",
|
|
799
798
|
(optionId === null || optionId === void 0 ? void 0 : optionId.toString()) || "--"
|
|
800
799
|
],
|
|
801
800
|
queryFn: async () => {
|
|
802
|
-
if (!graphqlClient || !
|
|
801
|
+
if (!graphqlClient || !marketAddr || optionId === void 0) return [];
|
|
803
802
|
const result = await graphqlClient.GetOptionEvents({
|
|
804
|
-
marketAddr
|
|
803
|
+
marketAddr,
|
|
805
804
|
optionId: optionId.toString()
|
|
806
805
|
});
|
|
807
806
|
const mintEvents = result.MintOptionEvent.map((event) => ({
|
|
@@ -851,10 +850,10 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
851
850
|
}))
|
|
852
851
|
].sort((a, b) => a.data.timestamp.getTime() - b.data.timestamp.getTime());
|
|
853
852
|
},
|
|
854
|
-
enabled: !!
|
|
853
|
+
enabled: !!marketAddr && optionId !== void 0 && !!graphqlClient
|
|
855
854
|
});
|
|
856
855
|
return {
|
|
857
|
-
data: data ||
|
|
856
|
+
data: data || require_optionUtils.EMPTY_ARRAY,
|
|
858
857
|
...rest
|
|
859
858
|
};
|
|
860
859
|
};
|
|
@@ -863,8 +862,8 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
863
862
|
//#region src/hooks/pool/usePriceAtTick.ts
|
|
864
863
|
const usePriceAtTick = (tick, poolAddr) => {
|
|
865
864
|
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
866
|
-
const priceBigInt = (0, react.useMemo)(() => tick ?
|
|
867
|
-
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ?
|
|
865
|
+
const priceBigInt = (0, react.useMemo)(() => tick ? require_optionUtils.getPriceAtTick(tick) : void 0, [tick]);
|
|
866
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
868
867
|
priceBigInt,
|
|
869
868
|
token0Decimals,
|
|
870
869
|
token1Decimals
|
|
@@ -1110,7 +1109,7 @@ const useMintLiquidity = (vaultAddr) => {
|
|
|
1110
1109
|
if (!address || !client) throw new Error("Wallet not connected");
|
|
1111
1110
|
if (currentTick.exact === void 0 || !token0 || !token1 || !vaultAddr || !uniswapLens) throw new Error("Current tick not available");
|
|
1112
1111
|
const { totalAmount0, totalAmount1 } = await batchGetAmountsFromLiquidity(uniswapLens, params.map((p) => p.tickLower), params.map((p) => p.tickUpper), params.map((p) => p.liquidity), currentTick.exact);
|
|
1113
|
-
const [allowance0, allowance1] = await Promise.all([
|
|
1112
|
+
const [allowance0, allowance1] = await Promise.all([require_optionUtils.getErc20(token0, client).read.allowance([address, vaultAddr]), require_optionUtils.getErc20(token1, client).read.allowance([address, vaultAddr])]);
|
|
1114
1113
|
const approvalPromises = [];
|
|
1115
1114
|
if (allowance0 <= totalAmount0) {
|
|
1116
1115
|
const approvalHash = await writeContractAsync({
|
|
@@ -1207,13 +1206,13 @@ const useVaultTVL = (vaultAddr) => {
|
|
|
1207
1206
|
});
|
|
1208
1207
|
return (0, react.useMemo)(() => {
|
|
1209
1208
|
if (!token0Decimals || !token1Decimals || !data) return {};
|
|
1210
|
-
const totalAmount0 =
|
|
1211
|
-
const totalAmount1 =
|
|
1212
|
-
const borrowedAmount0 =
|
|
1213
|
-
const borrowedAmount1 =
|
|
1209
|
+
const totalAmount0 = require_optionUtils.wrapAmount(data[0], token0Decimals);
|
|
1210
|
+
const totalAmount1 = require_optionUtils.wrapAmount(data[1], token1Decimals);
|
|
1211
|
+
const borrowedAmount0 = require_optionUtils.wrapAmount(data[2], token0Decimals);
|
|
1212
|
+
const borrowedAmount1 = require_optionUtils.wrapAmount(data[3], token1Decimals);
|
|
1214
1213
|
return {
|
|
1215
|
-
tvl0:
|
|
1216
|
-
tvl1:
|
|
1214
|
+
tvl0: require_optionUtils.wrapAmount(data[4], token0Decimals),
|
|
1215
|
+
tvl1: require_optionUtils.wrapAmount(data[5], token1Decimals),
|
|
1217
1216
|
totalAmount0,
|
|
1218
1217
|
totalAmount1,
|
|
1219
1218
|
borrowedAmount0,
|