@lifi/perps-sdk 0.0.0-preview-66a58bdf → 0.0.0-preview-5cb52bb3

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 (64) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/client/PerpsClient.d.ts +3 -2
  3. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  4. package/dist/cjs/client/PerpsClient.js +11 -4
  5. package/dist/cjs/client/PerpsClient.js.map +1 -1
  6. package/dist/cjs/index.d.ts +2 -2
  7. package/dist/cjs/index.d.ts.map +1 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/types/api.d.ts +6 -0
  10. package/dist/cjs/types/api.d.ts.map +1 -1
  11. package/dist/cjs/types/provider.d.ts +7 -1
  12. package/dist/cjs/types/provider.d.ts.map +1 -1
  13. package/dist/cjs/utils/actionResult.d.ts +1 -2
  14. package/dist/cjs/utils/actionResult.d.ts.map +1 -1
  15. package/dist/cjs/utils/actionResult.js +0 -25
  16. package/dist/cjs/utils/actionResult.js.map +1 -1
  17. package/dist/cjs/version.d.ts +1 -1
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/cjs/websocket/WsProviderBase.d.ts +0 -1
  20. package/dist/cjs/websocket/WsProviderBase.d.ts.map +1 -1
  21. package/dist/cjs/websocket/WsProviderBase.js +0 -11
  22. package/dist/cjs/websocket/WsProviderBase.js.map +1 -1
  23. package/dist/esm/client/PerpsClient.d.ts +14 -4
  24. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  25. package/dist/esm/client/PerpsClient.js +25 -10
  26. package/dist/esm/client/PerpsClient.js.map +1 -1
  27. package/dist/esm/index.d.ts +2 -2
  28. package/dist/esm/index.d.ts.map +1 -1
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/types/api.d.ts +13 -2
  31. package/dist/esm/types/api.d.ts.map +1 -1
  32. package/dist/esm/types/provider.d.ts +21 -4
  33. package/dist/esm/types/provider.d.ts.map +1 -1
  34. package/dist/esm/utils/actionResult.d.ts +1 -8
  35. package/dist/esm/utils/actionResult.d.ts.map +1 -1
  36. package/dist/esm/utils/actionResult.js +0 -30
  37. package/dist/esm/utils/actionResult.js.map +1 -1
  38. package/dist/esm/version.d.ts +1 -1
  39. package/dist/esm/version.js +1 -1
  40. package/dist/esm/websocket/WsProviderBase.d.ts +0 -9
  41. package/dist/esm/websocket/WsProviderBase.d.ts.map +1 -1
  42. package/dist/esm/websocket/WsProviderBase.js +0 -19
  43. package/dist/esm/websocket/WsProviderBase.js.map +1 -1
  44. package/dist/types/client/PerpsClient.d.ts +14 -4
  45. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  46. package/dist/types/index.d.ts +2 -2
  47. package/dist/types/index.d.ts.map +1 -1
  48. package/dist/types/types/api.d.ts +13 -2
  49. package/dist/types/types/api.d.ts.map +1 -1
  50. package/dist/types/types/provider.d.ts +21 -4
  51. package/dist/types/types/provider.d.ts.map +1 -1
  52. package/dist/types/utils/actionResult.d.ts +1 -8
  53. package/dist/types/utils/actionResult.d.ts.map +1 -1
  54. package/dist/types/version.d.ts +1 -1
  55. package/dist/types/websocket/WsProviderBase.d.ts +0 -9
  56. package/dist/types/websocket/WsProviderBase.d.ts.map +1 -1
  57. package/package.json +2 -2
  58. package/src/client/PerpsClient.ts +35 -18
  59. package/src/index.ts +2 -0
  60. package/src/types/api.ts +14 -2
  61. package/src/types/provider.ts +26 -3
  62. package/src/utils/actionResult.ts +1 -34
  63. package/src/version.ts +1 -1
  64. package/src/websocket/WsProviderBase.ts +0 -22
@@ -9,6 +9,7 @@ import type {
9
9
  AvailableToTrade,
10
10
  CreateActionResponse,
11
11
  DecimalString,
12
+ DepositStatus,
12
13
  ExecuteActionResponse,
13
14
  MarginHealth,
14
15
  MarketRef,
@@ -60,6 +61,7 @@ import type {
60
61
  ExecuteMetaActionParams,
61
62
  GetAccountResult,
62
63
  GetDepositFlowParams,
64
+ GetDepositStatusParams,
63
65
  GetMarginHealthParams,
64
66
  GetPortfolioHistoryParams,
65
67
  GetSetupParams,
@@ -96,10 +98,7 @@ import type {
96
98
  WithdrawalSourceTypes,
97
99
  WithdrawFlow,
98
100
  } from '../types/withdrawal.js'
99
- import {
100
- isSubmittedOrAccepted,
101
- sentBeforeExecuteResults,
102
- } from '../utils/actionResult.js'
101
+ import { isSubmittedOrAccepted } from '../utils/actionResult.js'
103
102
  import { isUserFacingSetupStep } from '../utils/setupActions.js'
104
103
  import { signTypedDataWithSigner } from '../utils/signTypedData.js'
105
104
  import {
@@ -507,8 +506,7 @@ export class PerpsClient {
507
506
  * empty report means nothing executed.
508
507
  *
509
508
  * @throws {PerpsExecutionError} When the submission or the plugin callback
510
- * throws after a result is known. A failed submission reports the signed
511
- * steps that already moved funds as `Submitted`.
509
+ * throws after a result is known.
512
510
  */
513
511
  private async submitSignedActions(
514
512
  provider: string,
@@ -531,10 +529,7 @@ export class PerpsClient {
531
529
  })
532
530
  results = [...executed, ...response.results]
533
531
  } catch (error) {
534
- rethrowWithKnownResults(
535
- [...executed, ...sentBeforeExecuteResults(signed)],
536
- error
537
- )
532
+ rethrowWithKnownResults(executed, error)
538
533
  }
539
534
  }
540
535
  if (results.length === 0) {
@@ -932,6 +927,31 @@ export class PerpsClient {
932
927
  return plugin.getDepositFlow?.({ address: params.address }, options)
933
928
  }
934
929
 
930
+ /**
931
+ * Status of the deposit that `params.txHash` funded for `params.address` at
932
+ * `params.provider`, read from the provider plugin.
933
+ *
934
+ * @returns `undefined` when the plugin declares no read, or when the venue has
935
+ * no record of the transaction yet. Treat `undefined` as not yet credited.
936
+ * @throws {PerpsError} When the provider plugin is not registered, or the
937
+ * venue read fails.
938
+ * @public
939
+ */
940
+ async getDepositStatus(
941
+ params: GetDepositStatusParams,
942
+ options?: SDKRequestOptions
943
+ ): Promise<DepositStatus | undefined> {
944
+ const plugin = this.requireProvider(params.provider)
945
+ return plugin.getDepositStatus?.(
946
+ {
947
+ address: params.address,
948
+ chainId: params.chainId,
949
+ txHash: params.txHash,
950
+ },
951
+ options
952
+ )
953
+ }
954
+
935
955
  /**
936
956
  * Current cross-margin health of `params.address` at `params.provider`,
937
957
  * calculated by the provider plugin.
@@ -1164,19 +1184,16 @@ export class PerpsClient {
1164
1184
  const { provider, address } = params
1165
1185
 
1166
1186
  const metadata = await this.getProviderMetadata(provider)
1167
- const setupBeforeDeposit = metadata.setup.some(
1168
- (descriptor) =>
1169
- descriptor.signingMethod === SigningMethod.SIWE ||
1170
- descriptor.type === ActionType.CREATE_ACCOUNT
1187
+ const hasSiweSetup = metadata.setup.some(
1188
+ (descriptor) => descriptor.signingMethod === SigningMethod.SIWE
1171
1189
  )
1172
1190
 
1173
1191
  // Gate on existence first: an unfunded account has no setup, so short-circuit
1174
1192
  // before any createAction round-trip and let the consumer prompt a deposit.
1175
1193
  //
1176
- // Two exceptions must still stage setup. SIWE-first providers (Ondo) cannot
1177
- // probe account existence before the user signs in. Providers with a
1178
- // CREATE_ACCOUNT step (Extended) open the account in setup, before a deposit.
1179
- if (!setupBeforeDeposit && !(await this.accountExists(provider, address))) {
1194
+ // SIWE-first providers (Ondo) are the exception: they cannot reliably probe
1195
+ // account existence before the user signs in, so setup must still stage.
1196
+ if (!hasSiweSetup && !(await this.accountExists(provider, address))) {
1180
1197
  return {
1181
1198
  accountExists: false,
1182
1199
  setup: [],
package/src/index.ts CHANGED
@@ -271,6 +271,7 @@ export type {
271
271
  ExecuteMetaActionParams,
272
272
  GetAccountResult,
273
273
  GetDepositFlowParams,
274
+ GetDepositStatusParams,
274
275
  GetMarginHealthParams,
275
276
  GetPortfolioHistoryParams,
276
277
  GetSetupParams,
@@ -314,6 +315,7 @@ export type {
314
315
  ProviderGetActivityParams,
315
316
  ProviderGetAvailableToTradeParams,
316
317
  ProviderGetDepositFlowParams,
318
+ ProviderGetDepositStatusParams,
317
319
  ProviderGetFillsParams,
318
320
  ProviderGetMarginHealthParams,
319
321
  ProviderGetMarketSettingsParams,
package/src/types/api.ts CHANGED
@@ -274,6 +274,20 @@ export interface GetDepositFlowParams {
274
274
  address: Address
275
275
  }
276
276
 
277
+ /**
278
+ * Parameters for {@link PerpsClient.getDepositStatus}.
279
+ *
280
+ * @public
281
+ */
282
+ export interface GetDepositStatusParams {
283
+ provider: string
284
+ address: Address
285
+ /** Chain of the source-chain transaction `txHash`. */
286
+ chainId: number
287
+ /** Source-chain transaction that funded the deposit. */
288
+ txHash: string
289
+ }
290
+
277
291
  /**
278
292
  * Parameters for {@link PerpsClient.getMarginHealth}.
279
293
  *
@@ -378,8 +392,6 @@ export interface ProviderSetup {
378
392
  * whose account has not yet been funded (Hyperliquid accounts are created by
379
393
  * their first deposit). When `false`, `setup` is empty and `isReady` is
380
394
  * `false` — the consumer prompts the deposit flow before any setup steps.
381
- * Always `true` for a venue that opens the account in setup (a SIWE step, or
382
- * a `CREATE_ACCOUNT` step as on Extended): `setup` then stages the opening.
383
395
  */
384
396
  accountExists: boolean
385
397
  /** Unsatisfied setup steps, ordered by descriptor `sequence`. */
@@ -11,6 +11,7 @@ import type {
11
11
  ActivityType,
12
12
  AvailableToTrade,
13
13
  DecimalString,
14
+ DepositStatus,
14
15
  FillsResponse,
15
16
  MarginHealth,
16
17
  MarginMode,
@@ -216,6 +217,19 @@ export interface ProviderGetDepositFlowParams {
216
217
  address: Address
217
218
  }
218
219
 
220
+ /**
221
+ * Read params for {@link PerpsProviderPlugin.getDepositStatus}.
222
+ *
223
+ * @public
224
+ */
225
+ export interface ProviderGetDepositStatusParams {
226
+ address: Address
227
+ /** Chain of the source-chain transaction `txHash`. */
228
+ chainId: number
229
+ /** Source-chain transaction that funded the deposit. */
230
+ txHash: string
231
+ }
232
+
219
233
  /**
220
234
  * Read params for {@link PerpsProviderPlugin.getWithdrawFlow}.
221
235
  *
@@ -459,9 +473,7 @@ export interface PerpsProviderPlugin {
459
473
  * own existence signal: Hyperliquid probes `preTransferCheck.userExists` (an
460
474
  * account exists once it has been funded, paying the one-time creation fee),
461
475
  * whereas Lighter resolves it from its `getAccount` → `AccountNotFound`
462
- * semantics. Used by `PerpsClient.checkSetup` to gate the deposit-first flow,
463
- * except for a venue that opens the account in setup (SIWE or
464
- * `CREATE_ACCOUNT`), where `checkSetup` does not call it.
476
+ * semantics. Used by `PerpsClient.checkSetup` to gate the deposit-first flow.
465
477
  */
466
478
  accountExists(
467
479
  params: ProviderAccountExistsParams,
@@ -482,6 +494,17 @@ export interface PerpsProviderPlugin {
482
494
  options?: SDKRequestOptions
483
495
  ): Promise<DepositFlow>
484
496
 
497
+ /**
498
+ * Status of the deposit that `params.txHash` funded for `params.address`.
499
+ * Resolves `undefined` when the venue has no record of the transaction yet,
500
+ * and a caller treats that as not yet credited. Optional: a provider that
501
+ * cannot report a deposit status omits it.
502
+ */
503
+ getDepositStatus?(
504
+ params: ProviderGetDepositStatusParams,
505
+ options?: SDKRequestOptions
506
+ ): Promise<DepositStatus | undefined>
507
+
485
508
  /**
486
509
  * The withdrawal flow this venue offers `params.address`, resolved from the
487
510
  * venue's own account and setup state — the destination a withdrawal goes
@@ -1,4 +1,4 @@
1
- import type { ActionResult, SignedActionStep } from '@lifi/perps-types'
1
+ import type { ActionResult } from '@lifi/perps-types'
2
2
  import { UserActionStatus } from '@lifi/perps-types'
3
3
 
4
4
  /** Whether the action took effect: its status is `Submitted` or `Accepted`. */
@@ -8,36 +8,3 @@ export function isSubmittedOrAccepted(result: ActionResult): boolean {
8
8
  result.status === UserActionStatus.Accepted
9
9
  )
10
10
  }
11
-
12
- /**
13
- * `Submitted` results for the signed steps that took effect before
14
- * `/executeAction`: an EVM transaction the wallet broadcast, or a Stark
15
- * request the client sent itself. Other steps take effect only through
16
- * `/executeAction`, so they give no result.
17
- */
18
- export function sentBeforeExecuteResults(
19
- signed: SignedActionStep[]
20
- ): ActionResult[] {
21
- return signed.flatMap((step): ActionResult[] => {
22
- if ('txHash' in step) {
23
- return [
24
- {
25
- action: step.action,
26
- status: UserActionStatus.Submitted,
27
- txHash: step.txHash,
28
- },
29
- ]
30
- }
31
- if ('stark' in step && step.clientSent !== undefined) {
32
- const { orderId } = step.clientSent
33
- return [
34
- {
35
- action: step.action,
36
- status: UserActionStatus.Submitted,
37
- ...(orderId === undefined ? {} : { orderId }),
38
- },
39
- ]
40
- }
41
- return []
42
- })
43
- }
package/src/version.ts CHANGED
@@ -10,4 +10,4 @@ export const name = '@lifi/perps-sdk'
10
10
  *
11
11
  * @public
12
12
  */
13
- export const version = '0.0.0-preview-66a58bdf'
13
+ export const version = '0.0.0-preview-5cb52bb3'
@@ -372,28 +372,6 @@ export abstract class WsProviderBase<TSub = unknown> implements WsProvider {
372
372
  }
373
373
  }
374
374
 
375
- /**
376
- * Finish a channel open: run `register` (the {@link registerSub} calls and
377
- * their ref counts), wait for the socket, and return `release` as the
378
- * channel teardown. When `register` or the wait fails, run `release` and
379
- * rethrow, so a failed open leaves no wire sub or ref count that a later
380
- * reconnect replays. `release` must accept a partial `register`; an error
381
- * from it is logged, and the open error is rethrown.
382
- */
383
- protected async openWires(
384
- register: () => Promise<void>,
385
- release: () => void
386
- ): Promise<() => void> {
387
- try {
388
- await register()
389
- await this.rws.ready()
390
- return release
391
- } catch (error) {
392
- this.callListener('open-release', release)
393
- throw error
394
- }
395
- }
396
-
397
375
  /** Forget a wire subscription so the next (re)open no longer replays it. */
398
376
  protected unregisterSub(key: string): void {
399
377
  this.wireSubs.delete(key)