@pear-protocol/hyperliquid-sdk 0.1.9 → 0.1.11

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.
Files changed (2) hide show
  1. package/dist/index.js +11 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1599,7 +1599,7 @@ const useTokenSelectionMetadataStore = create((set) => ({
1599
1599
  maxLeverage: 0,
1600
1600
  minSize: {},
1601
1601
  leverageMatched: true,
1602
- recompute: ({ tokenMetadata, marketData, longTokens, shortTokens, }) => {
1602
+ recompute: ({ tokenMetadata, marketData, longTokens, shortTokens }) => {
1603
1603
  const isPriceDataReady = Object.keys(tokenMetadata).length > 0;
1604
1604
  const longSymbols = longTokens.map((t) => t.symbol);
1605
1605
  const shortSymbols = shortTokens.map((t) => t.symbol);
@@ -1730,10 +1730,9 @@ const useTokenSelectionMetadataStore = create((set) => ({
1730
1730
  return 0;
1731
1731
  let maxLev = 0;
1732
1732
  allSymbols.forEach((symbol) => {
1733
- var _a;
1734
1733
  const tokenDetail = tokenMetadata[symbol];
1735
- if ((_a = tokenDetail === null || tokenDetail === void 0 ? void 0 : tokenDetail.leverage) === null || _a === void 0 ? void 0 : _a.value) {
1736
- maxLev = Math.max(maxLev, tokenDetail.leverage.value);
1734
+ if (tokenDetail === null || tokenDetail === void 0 ? void 0 : tokenDetail.maxLeverage) {
1735
+ maxLev = Math.max(maxLev, tokenDetail.maxLeverage);
1737
1736
  }
1738
1737
  });
1739
1738
  return maxLev;
@@ -6911,7 +6910,9 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
6911
6910
  var _a;
6912
6911
  const entryNotional = asset.entryPrice * asset.size;
6913
6912
  const currentNotional = currentPrice * asset.size;
6914
- const marginUsed = currentNotional / (leverage || 1);
6913
+ const effectiveLeverage = leverage || 1;
6914
+ const marginUsed = currentNotional / effectiveLeverage;
6915
+ const entryMarginUsed = entryNotional / effectiveLeverage;
6915
6916
  const unrealizedPnl = isLong
6916
6917
  ? currentNotional - entryNotional
6917
6918
  : entryNotional - currentNotional;
@@ -6921,6 +6922,7 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
6921
6922
  actualSize: asset.size,
6922
6923
  leverage: leverage,
6923
6924
  marginUsed: marginUsed,
6925
+ entryMarginUsed: entryMarginUsed,
6924
6926
  positionValue: currentNotional,
6925
6927
  unrealizedPnl: unrealizedPnl,
6926
6928
  entryPositionValue: entryNotional,
@@ -6946,6 +6948,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
6946
6948
  takeProfit: position.takeProfit,
6947
6949
  stopLoss: position.stopLoss,
6948
6950
  };
6951
+ let entryMarginUsed = 0;
6949
6952
  const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0) +
6950
6953
  position.shortAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0);
6951
6954
  mappedPosition.longAssets = position.longAssets.map((longAsset) => {
@@ -6960,6 +6963,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
6960
6963
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6961
6964
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6962
6965
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
6966
+ entryMarginUsed += mappedPositionAssets.entryMarginUsed;
6963
6967
  mappedPosition.entryRatio *= Math.pow(longAsset.entryPrice, mappedPositionAssets.initialWeight);
6964
6968
  mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.initialWeight);
6965
6969
  return mappedPositionAssets;
@@ -6976,6 +6980,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
6976
6980
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6977
6981
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6978
6982
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
6983
+ entryMarginUsed += mappedPositionAssets.entryMarginUsed;
6979
6984
  mappedPosition.entryRatio *= Math.pow(shortAsset.entryPrice, -mappedPositionAssets.initialWeight);
6980
6985
  mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.initialWeight);
6981
6986
  return mappedPositionAssets;
@@ -7013,7 +7018,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
7013
7018
  mappedPosition.markPriceRatio = shortMark;
7014
7019
  }
7015
7020
  mappedPosition.unrealizedPnlPercentage =
7016
- mappedPosition.unrealizedPnl / mappedPosition.marginUsed;
7021
+ entryMarginUsed > 0 ? mappedPosition.unrealizedPnl / entryMarginUsed : 0;
7017
7022
  return mappedPosition;
7018
7023
  });
7019
7024
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",