timelock-sdk 0.0.43 → 0.0.45
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 +22 -12
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +58 -66
- package/dist/client.d.ts +59 -67
- package/dist/client.js +23 -13
- package/dist/client.js.map +1 -1
- package/dist/{index-CRhFaRiq.d.ts → index-B20z73_3.d.ts} +92 -92
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -389,27 +389,37 @@ const useMintOption = (marketAddr) => {
|
|
|
389
389
|
|
|
390
390
|
//#endregion
|
|
391
391
|
//#region src/hooks/market/useOptionPnl.ts
|
|
392
|
-
const useOptionPnl = (
|
|
393
|
-
const { marketAddr, optionType, strikePrice, positionSizeCurrent } =
|
|
394
|
-
const { pool, optionAssetIsToken0, payoutAssetDecimals } = useMarketData(marketAddr);
|
|
392
|
+
const useOptionPnl = (option) => {
|
|
393
|
+
const { marketAddr, optionType, strikePrice, positionSizeCurrent } = option;
|
|
394
|
+
const { pool, optionAssetIsToken0, payoutAssetDecimals, tickSpacing } = useMarketData(marketAddr);
|
|
395
395
|
const { exact: currentTick } = useCurrentTick(pool);
|
|
396
|
-
|
|
396
|
+
const strikeSize = positionSizeCurrent * strikePrice / require_numberUtils.PRICE_PRECISION;
|
|
397
|
+
const displayPnl = (0, react.useMemo)(() => {
|
|
397
398
|
if (optionAssetIsToken0 === void 0 || currentTick === void 0 || !positionSizeCurrent || !payoutAssetDecimals) return {};
|
|
398
|
-
const strikeSize = positionSizeCurrent * strikePrice / require_numberUtils.PRICE_PRECISION;
|
|
399
399
|
const delta = (optionAssetIsToken0 ? require_numberUtils.token0ToToken1(positionSizeCurrent, currentTick) : require_numberUtils.token1ToToken0(positionSizeCurrent, currentTick)) - strikeSize;
|
|
400
|
-
|
|
401
|
-
return {
|
|
402
|
-
unrealizedPayout: require_numberUtils.wrapAmount(displayPnl.scaled < 0 ? 0n : displayPnl.scaled, payoutAssetDecimals),
|
|
403
|
-
displayPnl
|
|
404
|
-
};
|
|
400
|
+
return require_numberUtils.wrapAmount(optionType === "CALL" ? delta : -delta, payoutAssetDecimals);
|
|
405
401
|
}, [
|
|
406
|
-
strikePrice,
|
|
407
402
|
optionType,
|
|
408
403
|
optionAssetIsToken0,
|
|
409
404
|
currentTick,
|
|
410
405
|
positionSizeCurrent,
|
|
411
406
|
payoutAssetDecimals
|
|
412
407
|
]);
|
|
408
|
+
return {
|
|
409
|
+
unrealizedPayout: (0, react.useMemo)(() => {
|
|
410
|
+
if (!payoutAssetDecimals || !currentTick || !tickSpacing) return {};
|
|
411
|
+
const [amount0, amount1] = require_numberUtils.liquiditiesToAmounts(option.liquiditiesCurrent, option.startTick, currentTick, tickSpacing);
|
|
412
|
+
const delta = (optionAssetIsToken0 ? amount1 + require_numberUtils.token0ToToken1(amount0, currentTick) : amount0 + require_numberUtils.token1ToToken0(amount1, currentTick)) - strikeSize;
|
|
413
|
+
const pnl = optionType === "CALL" ? delta : -delta;
|
|
414
|
+
return require_numberUtils.wrapAmount(pnl < 0 ? 0n : pnl, payoutAssetDecimals);
|
|
415
|
+
}, [
|
|
416
|
+
currentTick,
|
|
417
|
+
tickSpacing,
|
|
418
|
+
optionType,
|
|
419
|
+
payoutAssetDecimals
|
|
420
|
+
]),
|
|
421
|
+
displayPnl
|
|
422
|
+
};
|
|
413
423
|
};
|
|
414
424
|
|
|
415
425
|
//#endregion
|
|
@@ -586,7 +596,7 @@ const getPriceHistory = async (poolAddress, resolution, start, end) => {
|
|
|
586
596
|
return fillGaps((await res.json()).data.attributes.ohlcv_list.map(([timestamp, , , , close]) => ({
|
|
587
597
|
timestamp: /* @__PURE__ */ new Date(timestamp * 1e3),
|
|
588
598
|
price: close
|
|
589
|
-
})).
|
|
599
|
+
})).sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()), start, end, seconds * 1e3).filter((point) => point.timestamp.getTime() / 1e3 >= startSecs && point.timestamp.getTime() / 1e3 <= endSecs);
|
|
590
600
|
};
|
|
591
601
|
|
|
592
602
|
//#endregion
|