@pear-protocol/hyperliquid-sdk 0.0.60-beta-usdh → 0.0.60-beta-usdh-1

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/index.d.ts CHANGED
@@ -178,6 +178,8 @@ interface TradeHistoryAssetDataDto {
178
178
  externalFeePaid: number;
179
179
  builderFeePaid: number;
180
180
  realizedPnl: number;
181
+ marketPrefix?: string | null;
182
+ collateralToken?: CollateralToken;
181
183
  }
182
184
  /**
183
185
  * Trade history data structure
package/dist/index.js CHANGED
@@ -1013,16 +1013,69 @@ const useAccountSummary = () => {
1013
1013
  return { data: calculated, isLoading };
1014
1014
  };
1015
1015
 
1016
+ // Helper to find asset metadata from perpMetaAssets
1017
+ function findAssetMeta$2(coinName, perpMetaAssets) {
1018
+ var _a, _b, _c, _d;
1019
+ if (!perpMetaAssets) {
1020
+ return { collateralToken: 'USDC', marketPrefix: null };
1021
+ }
1022
+ // Try exact match first (for prefixed assets like "xyz:TSLA")
1023
+ const exactMatch = perpMetaAssets.find((a) => a.name === coinName);
1024
+ if (exactMatch) {
1025
+ return {
1026
+ collateralToken: (_a = exactMatch.collateralToken) !== null && _a !== void 0 ? _a : 'USDC',
1027
+ marketPrefix: (_b = exactMatch.marketPrefix) !== null && _b !== void 0 ? _b : null,
1028
+ };
1029
+ }
1030
+ // Try matching by base symbol (for non-prefixed names in data)
1031
+ const baseMatch = perpMetaAssets.find((a) => {
1032
+ const baseName = a.name.includes(':') ? a.name.split(':')[1] : a.name;
1033
+ return baseName === coinName;
1034
+ });
1035
+ if (baseMatch) {
1036
+ return {
1037
+ collateralToken: (_c = baseMatch.collateralToken) !== null && _c !== void 0 ? _c : 'USDC',
1038
+ marketPrefix: (_d = baseMatch.marketPrefix) !== null && _d !== void 0 ? _d : null,
1039
+ };
1040
+ }
1041
+ return { collateralToken: 'USDC', marketPrefix: null };
1042
+ }
1043
+ // Enrich trade history assets with market prefix and collateral token
1044
+ function enrichTradeHistoryAssets(assets, perpMetaAssets) {
1045
+ return assets.map((asset) => {
1046
+ const meta = findAssetMeta$2(asset.coin, perpMetaAssets);
1047
+ return {
1048
+ ...asset,
1049
+ marketPrefix: meta.marketPrefix,
1050
+ collateralToken: meta.collateralToken,
1051
+ };
1052
+ });
1053
+ }
1054
+ // Enrich all trade histories with market metadata
1055
+ function enrichTradeHistories(histories, perpMetaAssets) {
1056
+ return histories.map((history) => ({
1057
+ ...history,
1058
+ closedLongAssets: enrichTradeHistoryAssets(history.closedLongAssets, perpMetaAssets),
1059
+ closedShortAssets: enrichTradeHistoryAssets(history.closedShortAssets, perpMetaAssets),
1060
+ }));
1061
+ }
1016
1062
  const useTradeHistories = () => {
1017
1063
  const context = useContext(PearHyperliquidContext);
1018
1064
  if (!context) {
1019
1065
  throw new Error('useTradeHistories must be used within a PearHyperliquidProvider');
1020
1066
  }
1021
1067
  const tradeHistories = useUserData((state) => state.tradeHistories);
1068
+ const perpMetaAssets = useHyperliquidData((state) => state.perpMetaAssets);
1022
1069
  const isLoading = useMemo(() => {
1023
1070
  return tradeHistories === null && context.isConnected;
1024
1071
  }, [tradeHistories, context.isConnected]);
1025
- return { data: tradeHistories, isLoading };
1072
+ // Enrich trade histories with market prefix and collateral token
1073
+ const enrichedTradeHistories = useMemo(() => {
1074
+ if (!tradeHistories)
1075
+ return null;
1076
+ return enrichTradeHistories(tradeHistories, perpMetaAssets);
1077
+ }, [tradeHistories, perpMetaAssets]);
1078
+ return { data: enrichedTradeHistories, isLoading };
1026
1079
  };
1027
1080
  /**
1028
1081
  * Hook to access open orders with loading state
package/dist/types.d.ts CHANGED
@@ -162,6 +162,8 @@ export interface TradeHistoryAssetDataDto {
162
162
  externalFeePaid: number;
163
163
  builderFeePaid: number;
164
164
  realizedPnl: number;
165
+ marketPrefix?: string | null;
166
+ collateralToken?: CollateralToken;
165
167
  }
166
168
  /**
167
169
  * Trade history data structure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.60-beta-usdh",
3
+ "version": "0.0.60-beta-usdh-1",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,7 +38,6 @@
38
38
  "@types/react": "^18.0.0",
39
39
  "concurrently": "^9.2.1",
40
40
  "esbuild": "^0.25.9",
41
-
42
41
  "rimraf": "^5.0.0",
43
42
  "rollup": "^3.0.0",
44
43
  "rollup-plugin-dts": "^6.0.0",