timelock-sdk 0.0.112 → 0.0.114
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-Bcn8F-k3.d.ts → client-BFaMKjtt.d.ts} +165 -161
- package/dist/{client-191_W3kB.d.cts → client-dmXFiQFn.d.cts} +6 -2
- package/dist/client.cjs +56 -57
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +56 -58
- package/dist/client.js.map +1 -1
- package/dist/{optionUtils-BkogxEAT.js → optionUtils-D8zF6lcX.js} +5 -2
- package/dist/optionUtils-D8zF6lcX.js.map +1 -0
- package/dist/{optionUtils-DNAmXoEX.cjs → optionUtils-DQakRJ_U.cjs} +10 -1
- package/dist/optionUtils-DQakRJ_U.cjs.map +1 -0
- package/dist/package.cjs +2 -1
- 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/optionUtils-BkogxEAT.js.map +0 -1
- package/dist/optionUtils-DNAmXoEX.cjs.map +0 -1
|
@@ -36524,6 +36524,7 @@ declare const getCurrentPrice: (poolAddress: string) => Promise<PriceData>;
|
|
|
36524
36524
|
//#endregion
|
|
36525
36525
|
//#region src/lib/liquidityUtils.d.ts
|
|
36526
36526
|
declare const PRICE_PRECISION: bigint;
|
|
36527
|
+
declare const getPriceSqrtPriceX96: (sqrtPriceX96: bigint) => bigint;
|
|
36527
36528
|
declare const getPriceAtTick: (tick: number) => bigint;
|
|
36528
36529
|
declare const getTickAtPrice: (price: bigint) => number;
|
|
36529
36530
|
declare const getNearestValidStrikeTick: (optionType: "CALL" | "PUT", optionAssetIsToken0: boolean, tickSpacing: number, currentTick: number, strikeTick?: number) => number;
|
|
@@ -36542,6 +36543,7 @@ declare const getPayoutAtTick: (option: OptionData, liquidities: bigint[], tick:
|
|
|
36542
36543
|
//#region src/hooks/pool/useCurrentPrice.d.ts
|
|
36543
36544
|
declare const useCurrentPrice: (poolAddr?: Address) => {
|
|
36544
36545
|
currentPrice: Amount | undefined;
|
|
36546
|
+
sqrtPriceX96: bigint | undefined;
|
|
36545
36547
|
currentTick: {
|
|
36546
36548
|
exact: number | undefined;
|
|
36547
36549
|
rounded: number | undefined;
|
|
@@ -36552,6 +36554,7 @@ declare const useCurrentPrice: (poolAddr?: Address) => {
|
|
|
36552
36554
|
declare const useCurrentTick: (poolAddr?: Address) => {
|
|
36553
36555
|
exact: number | undefined;
|
|
36554
36556
|
rounded: number | undefined;
|
|
36557
|
+
sqrtPriceX96: bigint | undefined;
|
|
36555
36558
|
};
|
|
36556
36559
|
//#endregion
|
|
36557
36560
|
//#region src/hooks/pool/usePoolData.d.ts
|
|
@@ -36572,6 +36575,7 @@ declare const usePoolData: (poolAddr?: Address) => Partial<NonUndefined<{
|
|
|
36572
36575
|
//#endregion
|
|
36573
36576
|
//#region src/hooks/pool/usePriceAtTick.d.ts
|
|
36574
36577
|
declare const usePriceAtTick: (tick?: number, poolAddr?: Address) => Amount | undefined;
|
|
36578
|
+
declare const usePriceSqrtPriceX96: (sqrtPriceX96?: bigint, poolAddr?: Address) => Amount | undefined;
|
|
36575
36579
|
//#endregion
|
|
36576
36580
|
//#region src/hooks/pool/usePriceHistory.d.ts
|
|
36577
36581
|
declare const usePriceHistory: (pool: Address | undefined, resolution: PriceResolution, startTimestamp: Date, endTimestamp: Date) => _tanstack_react_query0.UseQueryResult<PriceDataPoint[], Error>;
|
|
@@ -62857,5 +62861,5 @@ declare const useApproval: () => {
|
|
|
62857
62861
|
reset: () => void;
|
|
62858
62862
|
};
|
|
62859
62863
|
//#endregion
|
|
62860
|
-
export {
|
|
62861
|
-
//# sourceMappingURL=client-
|
|
62864
|
+
export { EMPTY_ARRAY as $, token1ToToken0 as A, uniswapMathLenses as At, useClosedUserPerps as B, getTickAtPrice as C, TimelockMarketData as Ct, roundTickDown as D, getTimelockMarket as Dt, liquiditiesToAmounts as E, getTimelockLens as Et, getPriceHistory as F, OptionTimelineData as G, usePerpsOperator as H, useSetOperatorPerms as I, useOptionPremium as J, useOptionTimeline as K, useUserOperators as L, PriceDataPoint as M, PriceResolution as N, roundTickUp as O, getUniswapMathLens as Ot, getCurrentPrice as P, Amount as Q, useOperatorPerms as R, getPriceSqrtPriceX96 as S, TimelockMarket as St, liquiditiesToAmount1 as T, getErc20 as Tt, useClosePerp as U, useUserPerps as V, useMintPerp as W, useMintOption as X, useOptionPnl as Y, useMaxPositionSize as Z, getPayoutAtTick as _, useClosedUserOptions as _t, batchGetAmountsFromLiquidity as a, scalePrice as at, getNearestValidStrikeTick as b, useTimelockConfig as bt, useLiquidityBlocks as c, wrapAmount as ct, usePriceAtTick as d, wrapPriceUnscaled as dt, formatAmount as et, usePriceSqrtPriceX96 as f, zero as ft, useCurrentPrice as g, useActiveUserOptions as gt, useCurrentTick as h, OptionData as ht, useVaultData as i, scaleAmount as it, PriceData as j, token0ToToken1 as k, timelockLenses as kt, useBurnLiquidity as l, wrapAmountUnscaled as lt, usePoolData as m, useExerciseOption as mt, useLens as n, formatUSD as nt, useMintLiquidity as o, unscaleAmount as ot, UniswapPoolData as p, useMarketData as pt, useExtendOption as q, useVaultTVL as r, formatVagueAmount as rt, LiquidityBlockData as s, unscalePrice as st, useApproval as t, formatCondensed as tt, usePriceHistory as u, wrapPrice as ut, PRICE_PRECISION as v, TimelockProvider as vt, liquiditiesToAmount0 as w, UniswapMathLens as wt, getPriceAtTick as x, TimelockLens as xt, getAmountsFromLiquidity as y, useCurrentMarket as yt, useActiveUserPerps as z };
|
|
62865
|
+
//# sourceMappingURL=client-dmXFiQFn.d.cts.map
|
package/dist/client.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const require_optionUtils = require('./optionUtils-
|
|
4
|
+
const require_optionUtils = require('./optionUtils-DQakRJ_U.cjs');
|
|
5
5
|
const require_optionsMarket = require('./optionsMarket-D6zrIXc3.cjs');
|
|
6
6
|
const require_singleOwnerVault = require('./singleOwnerVault-gf2zNZVk.cjs');
|
|
7
7
|
let viem = require("viem");
|
|
@@ -487,6 +487,10 @@ const usePoolData = (poolAddr) => {
|
|
|
487
487
|
return data || {};
|
|
488
488
|
};
|
|
489
489
|
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/lib/utils.ts
|
|
492
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
493
|
+
|
|
490
494
|
//#endregion
|
|
491
495
|
//#region src/hooks/options/useExerciseOption.ts
|
|
492
496
|
const swapper = "0x2c79DD9797C35A3D966C2716739542a282BB5540";
|
|
@@ -519,16 +523,9 @@ const useExerciseOption = (marketAddr) => {
|
|
|
519
523
|
]
|
|
520
524
|
});
|
|
521
525
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
true
|
|
526
|
-
] });
|
|
527
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
528
|
-
"userOptions",
|
|
529
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
530
|
-
false
|
|
531
|
-
] });
|
|
526
|
+
await sleep(200);
|
|
527
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
528
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
532
529
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
533
530
|
return hash;
|
|
534
531
|
};
|
|
@@ -587,10 +584,12 @@ const useCurrentTick = (poolAddr) => {
|
|
|
587
584
|
args: []
|
|
588
585
|
});
|
|
589
586
|
return (0, react.useMemo)(() => {
|
|
587
|
+
const sqrtPriceX96 = data === null || data === void 0 ? void 0 : data[0];
|
|
590
588
|
const exact = data === null || data === void 0 ? void 0 : data[1];
|
|
591
589
|
return {
|
|
592
590
|
exact,
|
|
593
|
-
rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0
|
|
591
|
+
rounded: exact && tickSpacing ? Math.floor(exact / tickSpacing) * tickSpacing : void 0,
|
|
592
|
+
sqrtPriceX96
|
|
594
593
|
};
|
|
595
594
|
}, [data, tickSpacing]);
|
|
596
595
|
};
|
|
@@ -661,16 +660,9 @@ const useMintOption = (marketAddr) => {
|
|
|
661
660
|
]
|
|
662
661
|
});
|
|
663
662
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
true
|
|
668
|
-
] });
|
|
669
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
670
|
-
"userOptions",
|
|
671
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
672
|
-
false
|
|
673
|
-
] });
|
|
663
|
+
await sleep(200);
|
|
664
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
665
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
674
666
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
675
667
|
return hash;
|
|
676
668
|
};
|
|
@@ -842,7 +834,10 @@ const useExtendOption = (marketAddr) => {
|
|
|
842
834
|
]
|
|
843
835
|
});
|
|
844
836
|
await (0, viem_actions.waitForTransactionReceipt)(client, { hash });
|
|
845
|
-
|
|
837
|
+
await sleep(200);
|
|
838
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
839
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
840
|
+
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
846
841
|
return hash;
|
|
847
842
|
};
|
|
848
843
|
return (0, __tanstack_react_query.useMutation)({ mutationFn: extendOption });
|
|
@@ -1080,14 +1075,6 @@ const useMintPerp = (marketAddr) => {
|
|
|
1080
1075
|
if (!tickSpacing || currentTick === void 0) throw new Error("Pool data not found");
|
|
1081
1076
|
if (optionAssetIsToken0 === void 0 || !payoutAsset) throw new Error("Market data not found");
|
|
1082
1077
|
if (!operator.auth) await signMessage();
|
|
1083
|
-
if (!hasEnoughPerms) await setOperatorPerms({
|
|
1084
|
-
operator: operatorAddr,
|
|
1085
|
-
canMint: true,
|
|
1086
|
-
canExtend: true,
|
|
1087
|
-
canExercise: true,
|
|
1088
|
-
canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
|
|
1089
|
-
spendingApproval: viem.maxUint256
|
|
1090
|
-
});
|
|
1091
1078
|
const market = require_optionUtils.getTimelockMarket(marketAddr, client);
|
|
1092
1079
|
const validStrikeTick = require_optionUtils.getNearestValidStrikeTick(optionType, optionAssetIsToken0, tickSpacing, currentTick, strikeTick);
|
|
1093
1080
|
const [premium, protocolFee] = await market.read.calculatePremium([
|
|
@@ -1097,7 +1084,16 @@ const useMintPerp = (marketAddr) => {
|
|
|
1097
1084
|
duration,
|
|
1098
1085
|
0
|
|
1099
1086
|
]);
|
|
1100
|
-
|
|
1087
|
+
const maxPremium = (premium + protocolFee) * 11n / 10n;
|
|
1088
|
+
if (!hasEnoughPerms) await setOperatorPerms({
|
|
1089
|
+
operator: operatorAddr,
|
|
1090
|
+
canMint: true,
|
|
1091
|
+
canExtend: true,
|
|
1092
|
+
canExercise: true,
|
|
1093
|
+
canTransfer: (userPerms === null || userPerms === void 0 ? void 0 : userPerms.canTransfer) || false,
|
|
1094
|
+
spendingApproval: maxPremium
|
|
1095
|
+
});
|
|
1096
|
+
await askForApproval(payoutAsset, marketAddr, maxPremium);
|
|
1101
1097
|
await operator.mintPerp({
|
|
1102
1098
|
marketAddr,
|
|
1103
1099
|
amount,
|
|
@@ -1105,16 +1101,9 @@ const useMintPerp = (marketAddr) => {
|
|
|
1105
1101
|
duration,
|
|
1106
1102
|
strikeTick: validStrikeTick
|
|
1107
1103
|
});
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
true
|
|
1112
|
-
] });
|
|
1113
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
1114
|
-
"userOptions",
|
|
1115
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1116
|
-
false
|
|
1117
|
-
] });
|
|
1104
|
+
await sleep(200);
|
|
1105
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1106
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1118
1107
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1119
1108
|
};
|
|
1120
1109
|
return (0, __tanstack_react_query.useMutation)({ mutationFn: mintPerp });
|
|
@@ -1124,22 +1113,14 @@ const useMintPerp = (marketAddr) => {
|
|
|
1124
1113
|
//#region src/hooks/perps/useClosePerp.ts
|
|
1125
1114
|
const useClosePerp = () => {
|
|
1126
1115
|
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
1127
|
-
const { address } = (0, wagmi.useAccount)();
|
|
1128
1116
|
const { operator, signMessage: { mutateAsync: signMessage } } = usePerpsOperator();
|
|
1129
1117
|
return (0, __tanstack_react_query.useMutation)({ mutationFn: async (body) => {
|
|
1130
1118
|
if (!operator) throw new Error("Operator not connected");
|
|
1131
1119
|
if (!operator.auth) await signMessage();
|
|
1132
1120
|
await operator.exercisePerp(body);
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
true
|
|
1137
|
-
] });
|
|
1138
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
1139
|
-
"userOptions",
|
|
1140
|
-
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1141
|
-
false
|
|
1142
|
-
] });
|
|
1121
|
+
await sleep(200);
|
|
1122
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1123
|
+
queryClient.invalidateQueries({ queryKey: ["userOptions"] });
|
|
1143
1124
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1144
1125
|
} });
|
|
1145
1126
|
};
|
|
@@ -1224,16 +1205,33 @@ const usePriceAtTick = (tick, poolAddr) => {
|
|
|
1224
1205
|
token1Decimals
|
|
1225
1206
|
]);
|
|
1226
1207
|
};
|
|
1208
|
+
const usePriceSqrtPriceX96 = (sqrtPriceX96, poolAddr) => {
|
|
1209
|
+
const { token0Decimals, token1Decimals } = usePoolData(poolAddr);
|
|
1210
|
+
const priceBigInt = (0, react.useMemo)(() => sqrtPriceX96 !== void 0 ? require_optionUtils.getPriceSqrtPriceX96(sqrtPriceX96) : void 0, [sqrtPriceX96]);
|
|
1211
|
+
return (0, react.useMemo)(() => priceBigInt && token0Decimals && token1Decimals ? require_optionUtils.wrapPrice(priceBigInt, token0Decimals, token1Decimals) : void 0, [
|
|
1212
|
+
priceBigInt,
|
|
1213
|
+
token0Decimals,
|
|
1214
|
+
token1Decimals
|
|
1215
|
+
]);
|
|
1216
|
+
};
|
|
1227
1217
|
|
|
1228
1218
|
//#endregion
|
|
1229
1219
|
//#region src/hooks/pool/useCurrentPrice.ts
|
|
1230
1220
|
const useCurrentPrice = (poolAddr) => {
|
|
1231
|
-
const
|
|
1232
|
-
const currentPrice =
|
|
1221
|
+
const { sqrtPriceX96, exact, rounded } = useCurrentTick(poolAddr);
|
|
1222
|
+
const currentPrice = usePriceSqrtPriceX96(sqrtPriceX96, poolAddr);
|
|
1233
1223
|
return (0, react.useMemo)(() => ({
|
|
1234
1224
|
currentPrice,
|
|
1235
|
-
|
|
1236
|
-
|
|
1225
|
+
sqrtPriceX96,
|
|
1226
|
+
currentTick: {
|
|
1227
|
+
exact,
|
|
1228
|
+
rounded
|
|
1229
|
+
}
|
|
1230
|
+
}), [
|
|
1231
|
+
currentPrice,
|
|
1232
|
+
exact,
|
|
1233
|
+
rounded
|
|
1234
|
+
]);
|
|
1237
1235
|
};
|
|
1238
1236
|
|
|
1239
1237
|
//#endregion
|
|
@@ -1477,6 +1475,7 @@ exports.usePerpsOperator = usePerpsOperator;
|
|
|
1477
1475
|
exports.usePoolData = usePoolData;
|
|
1478
1476
|
exports.usePriceAtTick = usePriceAtTick;
|
|
1479
1477
|
exports.usePriceHistory = usePriceHistory;
|
|
1478
|
+
exports.usePriceSqrtPriceX96 = usePriceSqrtPriceX96;
|
|
1480
1479
|
exports.useSetOperatorPerms = useSetOperatorPerms;
|
|
1481
1480
|
exports.useTimelockConfig = useTimelockConfig;
|
|
1482
1481
|
exports.useUserOperators = useUserOperators;
|