@pear-protocol/hyperliquid-sdk 0.0.70-beta → 0.0.71

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 +45 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1389,20 +1389,20 @@ const useTokenSelectionMetadataStore = create((set) => ({
1389
1389
  });
1390
1390
  return totalFunding;
1391
1391
  })();
1392
- // Max leverage (maximum across all tokens)
1392
+ // Max leverage (minimum across all tokens)
1393
1393
  const maxLeverage = (() => {
1394
1394
  if (!perpMetaAssets)
1395
1395
  return 0;
1396
1396
  const allTokenSymbols = [...longTokens, ...shortTokens].map((t) => t.symbol);
1397
1397
  if (allTokenSymbols.length === 0)
1398
1398
  return 0;
1399
- let maxLev = 0;
1399
+ let minLev = Infinity;
1400
1400
  allTokenSymbols.forEach((symbol) => {
1401
1401
  const tokenUniverse = perpMetaAssets.find((u) => u.name === symbol);
1402
1402
  if (tokenUniverse === null || tokenUniverse === void 0 ? void 0 : tokenUniverse.maxLeverage)
1403
- maxLev = Math.max(maxLev, tokenUniverse.maxLeverage);
1403
+ minLev = Math.min(minLev, tokenUniverse.maxLeverage);
1404
1404
  });
1405
- return maxLev;
1405
+ return minLev === Infinity ? 0 : minLev;
1406
1406
  })();
1407
1407
  // Min margin (10 * total number of tokens)
1408
1408
  const minMargin = (() => {
@@ -6640,7 +6640,9 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
6640
6640
  positionValue: currentNotional,
6641
6641
  unrealizedPnl: unrealizedPnl,
6642
6642
  entryPositionValue: entryNotional,
6643
- initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
6643
+ initialWeight: totalInitialPositionSize > 0
6644
+ ? entryNotional / totalInitialPositionSize
6645
+ : 0,
6644
6646
  fundingPaid: (_a = asset.fundingPaid) !== null && _a !== void 0 ? _a : 0,
6645
6647
  };
6646
6648
  };
@@ -6660,15 +6662,16 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
6660
6662
  takeProfit: position.takeProfit,
6661
6663
  stopLoss: position.stopLoss,
6662
6664
  };
6663
- const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0) +
6664
- position.shortAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0);
6665
- mappedPosition.longAssets = position.longAssets.map(longAsset => {
6665
+ const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0) +
6666
+ position.shortAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0);
6667
+ mappedPosition.longAssets = position.longAssets.map((longAsset) => {
6666
6668
  var _a, _b, _c;
6667
6669
  const currentPrice = parseFloat(allMids.mids[longAsset.coin]);
6668
- const assetState = (_a = clearinghouseState.assetPositions.find(ap => toDisplaySymbol(ap.position.coin) === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6670
+ const assetState = (_a = clearinghouseState.assetPositions.find((ap) => toDisplaySymbol(ap.position.coin) === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6669
6671
  const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : longAsset.leverage;
6670
6672
  const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, leverage, true);
6671
- mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
6673
+ mappedPosition.entryPositionValue +=
6674
+ mappedPositionAssets.entryPositionValue;
6672
6675
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6673
6676
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6674
6677
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
@@ -6676,13 +6679,14 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
6676
6679
  mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.initialWeight);
6677
6680
  return mappedPositionAssets;
6678
6681
  });
6679
- mappedPosition.shortAssets = position.shortAssets.map(shortAsset => {
6682
+ mappedPosition.shortAssets = position.shortAssets.map((shortAsset) => {
6680
6683
  var _a, _b, _c;
6681
6684
  const currentPrice = parseFloat(allMids.mids[shortAsset.coin]);
6682
- const assetState = (_a = clearinghouseState.assetPositions.find(ap => toDisplaySymbol(ap.position.coin) === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6685
+ const assetState = (_a = clearinghouseState.assetPositions.find((ap) => toDisplaySymbol(ap.position.coin) === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6683
6686
  const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : shortAsset.leverage;
6684
6687
  const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, leverage, false);
6685
- mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
6688
+ mappedPosition.entryPositionValue +=
6689
+ mappedPositionAssets.entryPositionValue;
6686
6690
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6687
6691
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6688
6692
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
@@ -6690,16 +6694,40 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
6690
6694
  mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.initialWeight);
6691
6695
  return mappedPositionAssets;
6692
6696
  });
6693
- mappedPosition.positionValue = mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
6697
+ mappedPosition.positionValue =
6698
+ mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
6694
6699
  if (position.longAssets.length === 1 && position.shortAssets.length === 1) {
6695
6700
  const long = position.longAssets[0];
6696
6701
  const short = position.shortAssets[0];
6697
6702
  const longMark = parseFloat(allMids.mids[long.coin]);
6698
6703
  const shortMark = parseFloat(allMids.mids[short.coin]);
6699
- mappedPosition.entryPriceRatio = long.entryPrice / short.entryPrice;
6700
- mappedPosition.markPriceRatio = longMark / shortMark;
6704
+ if (long.size > 0 && short.size > 0) {
6705
+ mappedPosition.entryPriceRatio = long.entryPrice / short.entryPrice;
6706
+ mappedPosition.markPriceRatio = longMark / shortMark;
6707
+ }
6708
+ else if (long.size > 0) {
6709
+ mappedPosition.entryPriceRatio = long.entryPrice;
6710
+ mappedPosition.markPriceRatio = longMark;
6711
+ }
6712
+ else if (short.size > 0) {
6713
+ mappedPosition.entryPriceRatio = short.entryPrice;
6714
+ mappedPosition.markPriceRatio = shortMark;
6715
+ }
6716
+ }
6717
+ if (position.longAssets.length === 1 && position.shortAssets.length === 0) {
6718
+ const long = position.longAssets[0];
6719
+ const longMark = parseFloat(allMids.mids[long.coin]);
6720
+ mappedPosition.entryPriceRatio = long.entryPrice;
6721
+ mappedPosition.markPriceRatio = longMark;
6722
+ }
6723
+ if (position.longAssets.length === 0 && position.shortAssets.length === 1) {
6724
+ const short = position.shortAssets[0];
6725
+ const shortMark = parseFloat(allMids.mids[short.coin]);
6726
+ mappedPosition.entryPriceRatio = short.entryPrice;
6727
+ mappedPosition.markPriceRatio = shortMark;
6701
6728
  }
6702
- mappedPosition.unrealizedPnlPercentage = mappedPosition.unrealizedPnl / mappedPosition.marginUsed;
6729
+ mappedPosition.unrealizedPnlPercentage =
6730
+ mappedPosition.unrealizedPnl / mappedPosition.marginUsed;
6703
6731
  return mappedPosition;
6704
6732
  });
6705
6733
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.70-beta",
3
+ "version": "0.0.71",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",