timelock-sdk 0.0.240 → 0.0.242
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 +93 -49
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +970 -959
- package/dist/client.d.ts +1224 -1213
- package/dist/client.js +93 -50
- package/dist/client.js.map +1 -1
- package/dist/{index-BDJmXd7_.d.cts → index-5nk6fHx2.d.cts} +618 -618
- package/dist/{index-CNTlT0vf.d.ts → index-C4hRFzOj.d.ts} +614 -614
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1303,10 +1303,10 @@ const calculateDisplayPnl = (option, poolPrice, optionAssetIsToken0, payoutAsset
|
|
|
1303
1303
|
return require_numberUtils.wrapAmount(option.optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
|
|
1304
1304
|
};
|
|
1305
1305
|
const useOptionPnl = (option) => {
|
|
1306
|
-
const
|
|
1307
|
-
const {
|
|
1308
|
-
const {
|
|
1309
|
-
const {
|
|
1306
|
+
const chainId = (0, wagmi.useChainId)();
|
|
1307
|
+
const { timelockLens } = useLens();
|
|
1308
|
+
const { vault, poolManager, poolKey, optionAssetIsToken0, payoutAssetDecimals } = useMarketData(option === null || option === void 0 ? void 0 : option.marketAddr);
|
|
1309
|
+
const { currentPrice: poolPrice, sqrtPriceX96 } = useCurrentPrice(poolManager, poolKey);
|
|
1310
1310
|
const displayPnl = (0, react.useMemo)(() => {
|
|
1311
1311
|
if (!option || !poolPrice || !payoutAssetDecimals || optionAssetIsToken0 === void 0) return void 0;
|
|
1312
1312
|
return calculateDisplayPnl(option, poolPrice.scaled, optionAssetIsToken0, payoutAssetDecimals);
|
|
@@ -1316,56 +1316,54 @@ const useOptionPnl = (option) => {
|
|
|
1316
1316
|
poolPrice,
|
|
1317
1317
|
payoutAssetDecimals
|
|
1318
1318
|
]);
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
"
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
],
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
}
|
|
1355
|
-
return require_numberUtils.wrapAmount(payout, payoutAssetDecimals);
|
|
1356
|
-
},
|
|
1357
|
-
enabled: canQueryPayout,
|
|
1358
|
-
staleTime: 1e4
|
|
1319
|
+
const swapperData = (0, react.useMemo)(() => {
|
|
1320
|
+
if (!sqrtPriceX96) return void 0;
|
|
1321
|
+
return (0, viem.encodeAbiParameters)([
|
|
1322
|
+
{ type: "uint160" },
|
|
1323
|
+
{ type: "uint160" },
|
|
1324
|
+
{ type: "uint256" }
|
|
1325
|
+
], [
|
|
1326
|
+
sqrtPriceX96 * 9n / 10n,
|
|
1327
|
+
sqrtPriceX96 * 11n / 10n,
|
|
1328
|
+
BigInt(Math.floor(Date.now() / 1e3) + 600)
|
|
1329
|
+
]);
|
|
1330
|
+
}, [sqrtPriceX96]);
|
|
1331
|
+
const { data: refTick } = (0, wagmi.useSimulateContract)({
|
|
1332
|
+
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
1333
|
+
abi: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.abi,
|
|
1334
|
+
functionName: "getRefTick",
|
|
1335
|
+
args: vault && (option === null || option === void 0 ? void 0 : option.startTick) ? [vault, option.startTick] : void 0,
|
|
1336
|
+
query: { enabled: !!vault && !!(option === null || option === void 0 ? void 0 : option.startTick) && !!timelockLens }
|
|
1337
|
+
});
|
|
1338
|
+
const { data: simulateResult } = (0, wagmi.useSimulateContract)({
|
|
1339
|
+
address: option === null || option === void 0 ? void 0 : option.marketAddr,
|
|
1340
|
+
abi: require_stateView.optionsMarketAbi,
|
|
1341
|
+
functionName: "exerciseOption",
|
|
1342
|
+
args: option && swapperData && (refTick === null || refTick === void 0 ? void 0 : refTick.result) ? [
|
|
1343
|
+
option.optionId,
|
|
1344
|
+
option.liquiditiesCurrent,
|
|
1345
|
+
0n,
|
|
1346
|
+
require_numberUtils.swappers[chainId],
|
|
1347
|
+
swapperData,
|
|
1348
|
+
refTick.result
|
|
1349
|
+
] : void 0,
|
|
1350
|
+
query: {
|
|
1351
|
+
enabled: !!option && !!swapperData && !!(refTick === null || refTick === void 0 ? void 0 : refTick.result) && !!option.marketAddr,
|
|
1352
|
+
staleTime: 1e4
|
|
1353
|
+
}
|
|
1359
1354
|
});
|
|
1360
1355
|
return {
|
|
1361
|
-
unrealizedPayout,
|
|
1356
|
+
unrealizedPayout: (0, react.useMemo)(() => {
|
|
1357
|
+
if (!(simulateResult === null || simulateResult === void 0 ? void 0 : simulateResult.result) || !payoutAssetDecimals) return void 0;
|
|
1358
|
+
return require_numberUtils.wrapAmount(simulateResult.result, payoutAssetDecimals);
|
|
1359
|
+
}, [simulateResult === null || simulateResult === void 0 ? void 0 : simulateResult.result, payoutAssetDecimals]),
|
|
1362
1360
|
displayPnl
|
|
1363
1361
|
};
|
|
1364
1362
|
};
|
|
1365
1363
|
|
|
1366
1364
|
//#endregion
|
|
1367
|
-
//#region src/hooks/options/
|
|
1368
|
-
const
|
|
1365
|
+
//#region src/hooks/options/useMintFees.ts
|
|
1366
|
+
const useMintFees = (marketAddr, optionType, optionAmount, duration, strikeTick) => {
|
|
1369
1367
|
const { poolManager, poolKey, payoutAssetDecimals, optionAssetIsToken0 } = useMarketData(marketAddr);
|
|
1370
1368
|
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
1371
1369
|
const { data: { currentTick } = {} } = useCurrentTick(poolManager, poolKey);
|
|
@@ -1385,11 +1383,56 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, addedDuration, s
|
|
|
1385
1383
|
address: marketAddr,
|
|
1386
1384
|
abi: require_stateView.optionsMarketAbi,
|
|
1387
1385
|
functionName: "getMintFees",
|
|
1388
|
-
args: strikeTickRounded !== void 0 && optionAmount !== void 0 &&
|
|
1386
|
+
args: strikeTickRounded !== void 0 && optionAmount !== void 0 && duration !== void 0 ? [
|
|
1387
|
+
optionType === "CALL" ? 0 : 1,
|
|
1388
|
+
optionAmount,
|
|
1389
|
+
strikeTickRounded,
|
|
1390
|
+
duration,
|
|
1391
|
+
"0x"
|
|
1392
|
+
] : void 0
|
|
1393
|
+
});
|
|
1394
|
+
return (0, react.useMemo)(() => {
|
|
1395
|
+
if (premium === void 0 || protocolFee === void 0 || payoutAssetDecimals === void 0) return {};
|
|
1396
|
+
return {
|
|
1397
|
+
premium: require_numberUtils.wrapAmount(premium, payoutAssetDecimals),
|
|
1398
|
+
protocolFee: require_numberUtils.wrapAmount(protocolFee, payoutAssetDecimals),
|
|
1399
|
+
totalPremium: require_numberUtils.wrapAmount(premium + protocolFee, payoutAssetDecimals)
|
|
1400
|
+
};
|
|
1401
|
+
}, [
|
|
1402
|
+
premium,
|
|
1403
|
+
protocolFee,
|
|
1404
|
+
payoutAssetDecimals
|
|
1405
|
+
]);
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region src/hooks/options/useExtensionFees.ts
|
|
1410
|
+
const useExtensionFees = (marketAddr, optionType, optionAmount, addedDuration, remainingDuration, strikeTick) => {
|
|
1411
|
+
const { poolManager, poolKey, payoutAssetDecimals, optionAssetIsToken0 } = useMarketData(marketAddr);
|
|
1412
|
+
const { tickSpacing } = usePoolData(poolManager, poolKey);
|
|
1413
|
+
const { data: { currentTick } = {} } = useCurrentTick(poolManager, poolKey);
|
|
1414
|
+
const strikeTickRounded = (0, react.useMemo)(() => {
|
|
1415
|
+
if (!tickSpacing || currentTick === void 0) return;
|
|
1416
|
+
let strikeTickRounded$1 = require_numberUtils.roundTick(strikeTick ?? currentTick, tickSpacing);
|
|
1417
|
+
if (optionType === "CALL" && optionAssetIsToken0 || optionType === "PUT" && !optionAssetIsToken0) strikeTickRounded$1 += tickSpacing;
|
|
1418
|
+
return strikeTickRounded$1;
|
|
1419
|
+
}, [
|
|
1420
|
+
currentTick,
|
|
1421
|
+
tickSpacing,
|
|
1422
|
+
optionType,
|
|
1423
|
+
optionAssetIsToken0,
|
|
1424
|
+
strikeTick
|
|
1425
|
+
]);
|
|
1426
|
+
const { data: [premium, protocolFee] = [] } = (0, wagmi.useReadContract)({
|
|
1427
|
+
address: marketAddr,
|
|
1428
|
+
abi: require_stateView.optionsMarketAbi,
|
|
1429
|
+
functionName: "getExtendFees",
|
|
1430
|
+
args: strikeTickRounded !== void 0 && optionAmount !== void 0 && addedDuration !== void 0 && remainingDuration !== void 0 ? [
|
|
1389
1431
|
optionType === "CALL" ? 0 : 1,
|
|
1390
1432
|
optionAmount,
|
|
1391
1433
|
strikeTickRounded,
|
|
1392
1434
|
addedDuration,
|
|
1435
|
+
remainingDuration,
|
|
1393
1436
|
"0x"
|
|
1394
1437
|
] : void 0
|
|
1395
1438
|
});
|
|
@@ -2659,6 +2702,7 @@ exports.useCurrentTick = useCurrentTick;
|
|
|
2659
2702
|
exports.useCurrentTicks = useCurrentTicks;
|
|
2660
2703
|
exports.useExerciseOption = useExerciseOption;
|
|
2661
2704
|
exports.useExtendOption = useExtendOption;
|
|
2705
|
+
exports.useExtensionFees = useExtensionFees;
|
|
2662
2706
|
exports.useFeeRates = useFeeRates;
|
|
2663
2707
|
exports.useGlobalGuardianState = useGlobalGuardianState;
|
|
2664
2708
|
exports.useLens = useLens;
|
|
@@ -2672,12 +2716,12 @@ exports.useMarketUserVolume = useMarketUserVolume;
|
|
|
2672
2716
|
exports.useMarketVolume = useMarketVolume;
|
|
2673
2717
|
exports.useMarketsData = useMarketsData;
|
|
2674
2718
|
exports.useMaxPositionSize = useMaxPositionSize;
|
|
2719
|
+
exports.useMintFees = useMintFees;
|
|
2675
2720
|
exports.useMintLiquidity = useMintLiquidity;
|
|
2676
2721
|
exports.useMintOption = useMintOption;
|
|
2677
2722
|
exports.useMintPerp = useMintPerp;
|
|
2678
2723
|
exports.useOperatorPerms = useOperatorPerms;
|
|
2679
2724
|
exports.useOptionPnl = useOptionPnl;
|
|
2680
|
-
exports.useOptionPremium = useOptionPremium;
|
|
2681
2725
|
exports.useOptionPricingParams = useOptionPricingParams;
|
|
2682
2726
|
exports.useOptionTimeline = useOptionTimeline;
|
|
2683
2727
|
exports.usePauseAllMarkets = usePauseAllMarkets;
|