timelock-sdk 0.0.242 → 0.0.244
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 +41 -37
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +986 -803
- package/dist/client.d.ts +1008 -825
- package/dist/client.js +42 -38
- package/dist/client.js.map +1 -1
- package/dist/{index-C4hRFzOj.d.ts → index-CPdgeq8i.d.ts} +5 -5
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1264,6 +1264,15 @@ const useExerciseOption = (marketAddr) => {
|
|
|
1264
1264
|
const maxSqrtPrice = sqrtPriceX96 * 11n / 10n;
|
|
1265
1265
|
const deadline = BigInt(Math.floor(Date.now() / 1e3) + 600);
|
|
1266
1266
|
const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
|
|
1267
|
+
const swapperData$1 = (0, viem.encodeAbiParameters)([
|
|
1268
|
+
{ type: "uint160" },
|
|
1269
|
+
{ type: "uint160" },
|
|
1270
|
+
{ type: "uint256" }
|
|
1271
|
+
], [
|
|
1272
|
+
minSqrtPrice,
|
|
1273
|
+
maxSqrtPrice,
|
|
1274
|
+
deadline
|
|
1275
|
+
]);
|
|
1267
1276
|
const hash = await writeContractAsync({
|
|
1268
1277
|
address: marketAddr,
|
|
1269
1278
|
abi: require_stateView.optionsMarketAbi,
|
|
@@ -1273,15 +1282,7 @@ const useExerciseOption = (marketAddr) => {
|
|
|
1273
1282
|
liquidities,
|
|
1274
1283
|
0n,
|
|
1275
1284
|
swapper,
|
|
1276
|
-
|
|
1277
|
-
{ type: "uint160" },
|
|
1278
|
-
{ type: "uint160" },
|
|
1279
|
-
{ type: "uint256" }
|
|
1280
|
-
], [
|
|
1281
|
-
minSqrtPrice,
|
|
1282
|
-
maxSqrtPrice,
|
|
1283
|
-
deadline
|
|
1284
|
-
]),
|
|
1285
|
+
swapperData$1,
|
|
1285
1286
|
refTick
|
|
1286
1287
|
]
|
|
1287
1288
|
});
|
|
@@ -1302,11 +1303,21 @@ const calculateDisplayPnl = (option, poolPrice, optionAssetIsToken0, payoutAsset
|
|
|
1302
1303
|
const delta = (optionAssetIsToken0 ? require_numberUtils.token0ToToken1(option.positionSizeCurrent, poolPrice) : require_numberUtils.token1ToToken0(option.positionSizeCurrent, poolPrice)) - strikeSize;
|
|
1303
1304
|
return require_numberUtils.wrapAmount(option.optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
|
|
1304
1305
|
};
|
|
1306
|
+
const swapperData = (0, viem.encodeAbiParameters)([
|
|
1307
|
+
{ type: "uint160" },
|
|
1308
|
+
{ type: "uint160" },
|
|
1309
|
+
{ type: "uint256" }
|
|
1310
|
+
], [
|
|
1311
|
+
0n,
|
|
1312
|
+
viem.maxUint160,
|
|
1313
|
+
BigInt(Math.floor(Date.now() / 1e3) + 600)
|
|
1314
|
+
]);
|
|
1305
1315
|
const useOptionPnl = (option) => {
|
|
1306
1316
|
const chainId = (0, wagmi.useChainId)();
|
|
1317
|
+
const { address: account } = (0, wagmi.useConnection)();
|
|
1307
1318
|
const { timelockLens } = useLens();
|
|
1308
1319
|
const { vault, poolManager, poolKey, optionAssetIsToken0, payoutAssetDecimals } = useMarketData(option === null || option === void 0 ? void 0 : option.marketAddr);
|
|
1309
|
-
const { currentPrice: poolPrice
|
|
1320
|
+
const { currentPrice: poolPrice } = useCurrentPrice(poolManager, poolKey);
|
|
1310
1321
|
const displayPnl = (0, react.useMemo)(() => {
|
|
1311
1322
|
if (!option || !poolPrice || !payoutAssetDecimals || optionAssetIsToken0 === void 0) return void 0;
|
|
1312
1323
|
return calculateDisplayPnl(option, poolPrice.scaled, optionAssetIsToken0, payoutAssetDecimals);
|
|
@@ -1316,48 +1327,41 @@ const useOptionPnl = (option) => {
|
|
|
1316
1327
|
poolPrice,
|
|
1317
1328
|
payoutAssetDecimals
|
|
1318
1329
|
]);
|
|
1319
|
-
const
|
|
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)({
|
|
1330
|
+
const { data: refTick } = (0, wagmi.useReadContract)({
|
|
1332
1331
|
address: timelockLens === null || timelockLens === void 0 ? void 0 : timelockLens.address,
|
|
1333
|
-
abi:
|
|
1332
|
+
abi: require_stateView.lensAbi,
|
|
1334
1333
|
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 }
|
|
1334
|
+
args: vault && (option === null || option === void 0 ? void 0 : option.startTick) ? [vault, option.startTick] : void 0
|
|
1337
1335
|
});
|
|
1338
|
-
const
|
|
1336
|
+
const swapper = require_numberUtils.swappers[chainId];
|
|
1337
|
+
const { data: unrealizedPayout, ...rest } = (0, wagmi.useSimulateContract)({
|
|
1339
1338
|
address: option === null || option === void 0 ? void 0 : option.marketAddr,
|
|
1340
1339
|
abi: require_stateView.optionsMarketAbi,
|
|
1341
1340
|
functionName: "exerciseOption",
|
|
1342
|
-
|
|
1341
|
+
account,
|
|
1342
|
+
args: option && refTick ? [
|
|
1343
1343
|
option.optionId,
|
|
1344
1344
|
option.liquiditiesCurrent,
|
|
1345
1345
|
0n,
|
|
1346
|
-
|
|
1346
|
+
swapper,
|
|
1347
1347
|
swapperData,
|
|
1348
|
-
refTick
|
|
1348
|
+
refTick
|
|
1349
1349
|
] : void 0,
|
|
1350
1350
|
query: {
|
|
1351
|
-
enabled: !!option && !!swapperData && !!
|
|
1352
|
-
staleTime: 1e4
|
|
1351
|
+
enabled: !!option && !!swapperData && !!swapper && refTick !== void 0 && !!account,
|
|
1352
|
+
staleTime: 1e4,
|
|
1353
|
+
select: (data) => {
|
|
1354
|
+
if (!payoutAssetDecimals) return void 0;
|
|
1355
|
+
return require_numberUtils.wrapAmount(data.result, payoutAssetDecimals);
|
|
1356
|
+
}
|
|
1353
1357
|
}
|
|
1354
1358
|
});
|
|
1355
1359
|
return {
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1360
|
+
...rest,
|
|
1361
|
+
data: {
|
|
1362
|
+
displayPnl,
|
|
1363
|
+
unrealizedPayout
|
|
1364
|
+
}
|
|
1361
1365
|
};
|
|
1362
1366
|
};
|
|
1363
1367
|
|