@lifi/perps-sdk-provider-hyperliquid 0.0.0-preview-66a58bdf → 0.0.0-preview-d4ecff50

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 (34) hide show
  1. package/README.md +9 -2
  2. package/dist/cjs/accountConfig.d.ts.map +1 -1
  3. package/dist/cjs/accountConfig.js +0 -2
  4. package/dist/cjs/accountConfig.js.map +1 -1
  5. package/dist/cjs/services/getActivity.d.ts.map +1 -1
  6. package/dist/cjs/services/getActivity.js +5 -1
  7. package/dist/cjs/services/getActivity.js.map +1 -1
  8. package/dist/cjs/utils/mapActivity.d.ts +4 -0
  9. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  10. package/dist/cjs/utils/mapActivity.js +36 -2
  11. package/dist/cjs/utils/mapActivity.js.map +1 -1
  12. package/dist/cjs/websocket/HyperliquidWsProvider.js +13 -15
  13. package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
  14. package/dist/esm/accountConfig.d.ts.map +1 -1
  15. package/dist/esm/accountConfig.js +0 -2
  16. package/dist/esm/accountConfig.js.map +1 -1
  17. package/dist/esm/services/getActivity.d.ts.map +1 -1
  18. package/dist/esm/services/getActivity.js +5 -1
  19. package/dist/esm/services/getActivity.js.map +1 -1
  20. package/dist/esm/utils/mapActivity.d.ts +5 -0
  21. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  22. package/dist/esm/utils/mapActivity.js +36 -1
  23. package/dist/esm/utils/mapActivity.js.map +1 -1
  24. package/dist/esm/websocket/HyperliquidWsProvider.js +13 -15
  25. package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
  26. package/dist/types/accountConfig.d.ts.map +1 -1
  27. package/dist/types/services/getActivity.d.ts.map +1 -1
  28. package/dist/types/utils/mapActivity.d.ts +5 -0
  29. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  30. package/package.json +3 -3
  31. package/src/accountConfig.ts +0 -2
  32. package/src/services/getActivity.ts +7 -1
  33. package/src/utils/mapActivity.ts +49 -1
  34. package/src/websocket/HyperliquidWsProvider.ts +13 -13
@@ -42,6 +42,7 @@ import {
42
42
  infoRequest,
43
43
  } from '../utils/infoClient.js'
44
44
  import { isFillLiquidatingAccount } from '../utils/isFillLiquidatingAccount.js'
45
+ import { isSameAccountTransfer } from '../utils/mapActivity.js'
45
46
  import { requireAccountExists } from './getAccountExists.js'
46
47
  import { getLedgerHistory, getLedgerWindow } from './getLedgerHistory.js'
47
48
  import { getHistoryLimit, historyPage } from './historyPagination.js'
@@ -199,9 +200,14 @@ const fetchActivityData = async (
199
200
  !typeFilter.includes(ActivityType.REWARD)) ||
200
201
  (!typeFilter.includes(ActivityType.TRANSFER) &&
201
202
  (isSpotTransferDelta(entry.delta) ||
202
- isSendAssetDelta(entry.delta) ||
203
203
  isCollateralTransferDelta(entry.delta) ||
204
204
  isVaultTransferDelta(entry.delta))) ||
205
+ (isSendAssetDelta(entry.delta) &&
206
+ !typeFilter.includes(
207
+ isSameAccountTransfer(entry.delta, timeParams.user)
208
+ ? ActivityType.INTERNAL_TRANSFER
209
+ : ActivityType.TRANSFER
210
+ )) ||
205
211
  (!typeFilter.includes(ActivityType.INTERNAL_TRANSFER) &&
206
212
  (isCStakingTransferDelta(entry.delta) ||
207
213
  isBorrowLendDelta(entry.delta) ||
@@ -101,6 +101,24 @@ const resolveLedgerAsset = (
101
101
  return asset
102
102
  }
103
103
 
104
+ /** Whether a transfer delta names the queried account as sender and recipient. */
105
+ export const isSameAccountTransfer = (
106
+ delta: { user: string; destination: string },
107
+ queriedAddress: string
108
+ ): boolean => {
109
+ const queried = queriedAddress.toLowerCase()
110
+ return (
111
+ delta.user.toLowerCase() === queried &&
112
+ delta.destination.toLowerCase() === queried
113
+ )
114
+ }
115
+
116
+ // A `send` names spot `"spot"`, the main perp dex `""`, and other perp dexes by name.
117
+ const resolveSendBalance = (
118
+ dex: unknown
119
+ ): InternalTransferBalance | undefined =>
120
+ typeof dex === 'string' ? (dex === 'spot' ? 'spot' : 'perps') : undefined
121
+
104
122
  /** Map supported ledger entries, preserving venue amounts and operation metadata. */
105
123
  export const mapLedgerEntry = (
106
124
  entry: HlLedgerUpdate,
@@ -119,6 +137,36 @@ export const mapLedgerEntry = (
119
137
  }
120
138
  const base = { id: entry.hash, provider: providerKey, timestamp }
121
139
 
140
+ if (isSendAssetDelta(delta) && isSameAccountTransfer(delta, queriedAddress)) {
141
+ const sourceBalance = resolveSendBalance(delta.sourceDex)
142
+ const destinationBalance = resolveSendBalance(delta.destinationDex)
143
+ if (
144
+ sourceBalance === undefined ||
145
+ destinationBalance === undefined ||
146
+ sourceBalance === destinationBalance
147
+ ) {
148
+ return null
149
+ }
150
+ const asset = resolveLedgerAsset(delta.token, assetRegistry, providerKey)
151
+ if (asset === null) {
152
+ return null
153
+ }
154
+ return {
155
+ ...base,
156
+ type: ActivityType.INTERNAL_TRANSFER,
157
+ sourceBalance,
158
+ destinationBalance,
159
+ asset,
160
+ amount: delta.amount,
161
+ meta: {
162
+ transferType: 'sendAsset',
163
+ sourceDex: delta.sourceDex,
164
+ destinationDex: delta.destinationDex,
165
+ },
166
+ explorerLink: explorerTxUrl(ExplorerChainId.HYPERLIQUID, entry.hash),
167
+ } satisfies InternalTransferActivity
168
+ }
169
+
122
170
  if (
123
171
  isSpotTransferDelta(delta) ||
124
172
  isSendAssetDelta(delta) ||
@@ -127,7 +175,7 @@ export const mapLedgerEntry = (
127
175
  const queried = queriedAddress.toLowerCase()
128
176
  const sender = delta.user.toLowerCase()
129
177
  const recipient = delta.destination.toLowerCase()
130
- if (sender === recipient && sender === queried) {
178
+ if (isSameAccountTransfer(delta, queriedAddress)) {
131
179
  return null
132
180
  }
133
181
  const asset = isCollateralTransferDelta(delta)
@@ -402,12 +402,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
402
402
  if (sub.channel === 'accountSummary') {
403
403
  this.summaryUsers.add(user)
404
404
  }
405
- const register = async () => {
406
- if (count === 0) {
407
- await this.registerSub(wireKey, payload)
408
- }
405
+ if (count === 0) {
406
+ await this.registerSub(wireKey, payload)
409
407
  }
410
- return this.openWires(register, () => {
408
+ await this.rws.ready()
409
+ return () => {
411
410
  if (sub.channel === 'accountSummary') {
412
411
  this.summaryUsers.delete(user)
413
412
  this.abstractionReadsByUser.delete(user)
@@ -426,7 +425,7 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
426
425
  } else {
427
426
  this.clearinghouseRefs.set(user, remaining)
428
427
  }
429
- })
428
+ }
430
429
  }
431
430
 
432
431
  // All other channels: single WS subscription per key
@@ -435,13 +434,14 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
435
434
  this.claimOrderbookKey(sub.marketId, key)
436
435
  }
437
436
  const payload = this.toHlPayload(sub)
438
- const register = async () => {
439
- await this.registerSub(key, payload)
440
- if (sub.channel === 'orderbook') {
441
- this.registerOrderbook(sub.marketId, key)
442
- }
437
+ await this.registerSub(key, payload)
438
+ if (sub.channel === 'orderbook') {
439
+ this.registerOrderbook(sub.marketId, key)
443
440
  }
444
- return this.openWires(register, () => {
441
+
442
+ await this.rws.ready()
443
+
444
+ return () => {
445
445
  this.unregisterSub(key)
446
446
  if (this.orderUpdatesKey === key) {
447
447
  this.orderUpdatesKey = undefined
@@ -456,7 +456,7 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
456
456
  if (sub.channel === 'orderbook') {
457
457
  this.releaseOrderbook(sub.marketId, key)
458
458
  }
459
- })
459
+ }
460
460
  }
461
461
 
462
462
  /**