@lifi/perps-sdk 0.0.0-preview-697b8c5 → 0.0.0-preview-1edeff0

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 (158) hide show
  1. package/dist/cjs/client/PerpsClient.d.ts +3 -1
  2. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  3. package/dist/cjs/client/PerpsClient.js +4 -0
  4. package/dist/cjs/client/PerpsClient.js.map +1 -1
  5. package/dist/cjs/index.d.ts +10 -5
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js +18 -6
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/registry/marketRegistry.d.ts +3 -0
  10. package/dist/cjs/registry/marketRegistry.d.ts.map +1 -1
  11. package/dist/cjs/registry/marketRegistry.js +16 -1
  12. package/dist/cjs/registry/marketRegistry.js.map +1 -1
  13. package/dist/cjs/registry/referenceDataRegistry.d.ts.map +1 -1
  14. package/dist/cjs/registry/referenceDataRegistry.js +0 -1
  15. package/dist/cjs/registry/referenceDataRegistry.js.map +1 -1
  16. package/dist/cjs/services/getGasRecommendation.d.ts +9 -0
  17. package/dist/cjs/services/getGasRecommendation.d.ts.map +1 -0
  18. package/dist/cjs/services/getGasRecommendation.js +10 -0
  19. package/dist/cjs/services/getGasRecommendation.js.map +1 -0
  20. package/dist/cjs/services/getMarket.d.ts.map +1 -1
  21. package/dist/cjs/services/getMarket.js +2 -1
  22. package/dist/cjs/services/getMarket.js.map +1 -1
  23. package/dist/cjs/services/getMarkets.d.ts.map +1 -1
  24. package/dist/cjs/services/getMarkets.js +3 -1
  25. package/dist/cjs/services/getMarkets.js.map +1 -1
  26. package/dist/cjs/types/api.d.ts +4 -0
  27. package/dist/cjs/types/api.d.ts.map +1 -1
  28. package/dist/cjs/types/deposit.d.ts +25 -0
  29. package/dist/cjs/types/deposit.d.ts.map +1 -0
  30. package/dist/cjs/types/deposit.js +3 -0
  31. package/dist/cjs/types/deposit.js.map +1 -0
  32. package/dist/cjs/types/provider.d.ts +5 -0
  33. package/dist/cjs/types/provider.d.ts.map +1 -1
  34. package/dist/cjs/utils/accountSummary.d.ts.map +1 -1
  35. package/dist/cjs/utils/accountSummary.js +10 -4
  36. package/dist/cjs/utils/accountSummary.js.map +1 -1
  37. package/dist/cjs/utils/depositAssets.d.ts +8 -0
  38. package/dist/cjs/utils/depositAssets.d.ts.map +1 -0
  39. package/dist/cjs/utils/depositAssets.js +36 -0
  40. package/dist/cjs/utils/depositAssets.js.map +1 -0
  41. package/dist/cjs/utils/scaleToInteger.d.ts +3 -0
  42. package/dist/cjs/utils/scaleToInteger.d.ts.map +1 -0
  43. package/dist/cjs/utils/scaleToInteger.js +30 -0
  44. package/dist/cjs/utils/scaleToInteger.js.map +1 -0
  45. package/dist/cjs/utils/setupActions.d.ts +3 -0
  46. package/dist/cjs/utils/setupActions.d.ts.map +1 -0
  47. package/dist/cjs/utils/setupActions.js +8 -0
  48. package/dist/cjs/utils/setupActions.js.map +1 -0
  49. package/dist/cjs/version.d.ts +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/esm/client/PerpsClient.d.ts +13 -1
  52. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  53. package/dist/esm/client/PerpsClient.js +14 -0
  54. package/dist/esm/client/PerpsClient.js.map +1 -1
  55. package/dist/esm/index.d.ts +11 -6
  56. package/dist/esm/index.d.ts.map +1 -1
  57. package/dist/esm/index.js +6 -3
  58. package/dist/esm/index.js.map +1 -1
  59. package/dist/esm/registry/marketRegistry.d.ts +15 -2
  60. package/dist/esm/registry/marketRegistry.d.ts.map +1 -1
  61. package/dist/esm/registry/marketRegistry.js +26 -2
  62. package/dist/esm/registry/marketRegistry.js.map +1 -1
  63. package/dist/esm/registry/referenceDataRegistry.d.ts +2 -1
  64. package/dist/esm/registry/referenceDataRegistry.d.ts.map +1 -1
  65. package/dist/esm/registry/referenceDataRegistry.js +2 -2
  66. package/dist/esm/registry/referenceDataRegistry.js.map +1 -1
  67. package/dist/esm/services/getGasRecommendation.d.ts +31 -0
  68. package/dist/esm/services/getGasRecommendation.d.ts.map +1 -0
  69. package/dist/esm/services/getGasRecommendation.js +22 -0
  70. package/dist/esm/services/getGasRecommendation.js.map +1 -0
  71. package/dist/esm/services/getMarket.d.ts +5 -4
  72. package/dist/esm/services/getMarket.d.ts.map +1 -1
  73. package/dist/esm/services/getMarket.js +7 -5
  74. package/dist/esm/services/getMarket.js.map +1 -1
  75. package/dist/esm/services/getMarkets.d.ts +6 -3
  76. package/dist/esm/services/getMarkets.d.ts.map +1 -1
  77. package/dist/esm/services/getMarkets.js +9 -4
  78. package/dist/esm/services/getMarkets.js.map +1 -1
  79. package/dist/esm/types/api.d.ts +9 -0
  80. package/dist/esm/types/api.d.ts.map +1 -1
  81. package/dist/esm/types/deposit.d.ts +68 -0
  82. package/dist/esm/types/deposit.d.ts.map +1 -0
  83. package/dist/esm/types/deposit.js +2 -0
  84. package/dist/esm/types/deposit.js.map +1 -0
  85. package/dist/esm/types/provider.d.ts +19 -0
  86. package/dist/esm/types/provider.d.ts.map +1 -1
  87. package/dist/esm/utils/accountSummary.d.ts.map +1 -1
  88. package/dist/esm/utils/accountSummary.js +13 -4
  89. package/dist/esm/utils/accountSummary.js.map +1 -1
  90. package/dist/esm/utils/depositAssets.d.ts +46 -0
  91. package/dist/esm/utils/depositAssets.d.ts.map +1 -0
  92. package/dist/esm/utils/depositAssets.js +71 -0
  93. package/dist/esm/utils/depositAssets.js.map +1 -0
  94. package/dist/esm/utils/scaleToInteger.d.ts +22 -0
  95. package/dist/esm/utils/scaleToInteger.d.ts.map +1 -0
  96. package/dist/esm/utils/scaleToInteger.js +34 -0
  97. package/dist/esm/utils/scaleToInteger.js.map +1 -0
  98. package/dist/esm/utils/setupActions.d.ts +17 -0
  99. package/dist/esm/utils/setupActions.d.ts.map +1 -0
  100. package/dist/esm/utils/setupActions.js +19 -0
  101. package/dist/esm/utils/setupActions.js.map +1 -0
  102. package/dist/esm/version.d.ts +1 -1
  103. package/dist/esm/version.js +1 -1
  104. package/dist/types/client/PerpsClient.d.ts +13 -1
  105. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  106. package/dist/types/index.d.ts +11 -6
  107. package/dist/types/index.d.ts.map +1 -1
  108. package/dist/types/registry/marketRegistry.d.ts +15 -2
  109. package/dist/types/registry/marketRegistry.d.ts.map +1 -1
  110. package/dist/types/registry/referenceDataRegistry.d.ts +2 -1
  111. package/dist/types/registry/referenceDataRegistry.d.ts.map +1 -1
  112. package/dist/types/services/getGasRecommendation.d.ts +31 -0
  113. package/dist/types/services/getGasRecommendation.d.ts.map +1 -0
  114. package/dist/types/services/getMarket.d.ts +5 -4
  115. package/dist/types/services/getMarket.d.ts.map +1 -1
  116. package/dist/types/services/getMarkets.d.ts +6 -3
  117. package/dist/types/services/getMarkets.d.ts.map +1 -1
  118. package/dist/types/types/api.d.ts +9 -0
  119. package/dist/types/types/api.d.ts.map +1 -1
  120. package/dist/types/types/deposit.d.ts +68 -0
  121. package/dist/types/types/deposit.d.ts.map +1 -0
  122. package/dist/types/types/provider.d.ts +19 -0
  123. package/dist/types/types/provider.d.ts.map +1 -1
  124. package/dist/types/utils/accountSummary.d.ts.map +1 -1
  125. package/dist/types/utils/depositAssets.d.ts +46 -0
  126. package/dist/types/utils/depositAssets.d.ts.map +1 -0
  127. package/dist/types/utils/scaleToInteger.d.ts +22 -0
  128. package/dist/types/utils/scaleToInteger.d.ts.map +1 -0
  129. package/dist/types/utils/setupActions.d.ts +17 -0
  130. package/dist/types/utils/setupActions.d.ts.map +1 -0
  131. package/dist/types/version.d.ts +1 -1
  132. package/package.json +4 -3
  133. package/src/client/PerpsClient.ts +19 -0
  134. package/src/index.ts +26 -5
  135. package/src/registry/marketRegistry.ts +33 -2
  136. package/src/registry/referenceDataRegistry.ts +2 -2
  137. package/src/services/getGasRecommendation.ts +45 -0
  138. package/src/services/getMarket.ts +7 -5
  139. package/src/services/getMarkets.ts +14 -4
  140. package/src/types/api.ts +10 -0
  141. package/src/types/deposit.ts +75 -0
  142. package/src/types/provider.ts +24 -0
  143. package/src/utils/accountSummary.ts +18 -5
  144. package/src/utils/depositAssets.ts +77 -0
  145. package/src/utils/scaleToInteger.ts +56 -0
  146. package/src/utils/setupActions.ts +24 -0
  147. package/src/version.ts +1 -1
  148. package/dist/cjs/utils/depositChain.d.ts +0 -6
  149. package/dist/cjs/utils/depositChain.d.ts.map +0 -1
  150. package/dist/cjs/utils/depositChain.js +0 -13
  151. package/dist/cjs/utils/depositChain.js.map +0 -1
  152. package/dist/esm/utils/depositChain.d.ts +0 -27
  153. package/dist/esm/utils/depositChain.d.ts.map +0 -1
  154. package/dist/esm/utils/depositChain.js +0 -23
  155. package/dist/esm/utils/depositChain.js.map +0 -1
  156. package/dist/types/utils/depositChain.d.ts +0 -27
  157. package/dist/types/utils/depositChain.d.ts.map +0 -1
  158. package/src/utils/depositChain.ts +0 -38
@@ -0,0 +1,46 @@
1
+ import type { DeclaredDepositAsset } from '../types/deposit.js';
2
+ /**
3
+ * USDC on Ethereum mainnet — the collateral leg of Lighter's first-deposit
4
+ * pipeline, and the token Ondo's provisioned deposit address is funded in.
5
+ *
6
+ * @public
7
+ */
8
+ export declare const ETHEREUM_USDC: DeclaredDepositAsset;
9
+ /**
10
+ * Ether on Ethereum mainnet, to broadcast the first-deposit pipeline's legs
11
+ * with.
12
+ *
13
+ * @public
14
+ */
15
+ export declare const ETHEREUM_NATIVE_GAS: DeclaredDepositAsset;
16
+ /**
17
+ * USDC on the Hyperliquid venue chain: the 6-decimal perps contract. The same
18
+ * chain also lists an 8-decimal spot `USDC` at
19
+ * `0x6d1e7cde53bA9467B783Cb7c530CE05400000000`, so a deposit destination
20
+ * resolved by symbol lands on the wrong token and the wrong scale.
21
+ *
22
+ * @public
23
+ */
24
+ export declare const HYPERLIQUID_USDC: DeclaredDepositAsset;
25
+ /**
26
+ * USDC on the Lighter venue chain. The venue chain reuses the mainnet USDC
27
+ * address, so `chainId` is what distinguishes it from {@link ETHEREUM_USDC}.
28
+ *
29
+ * @public
30
+ */
31
+ export declare const LIGHTER_USDC: DeclaredDepositAsset;
32
+ /**
33
+ * USDG on Robinhood Chain — the collateral the Lighter Robinhood instance is
34
+ * funded in.
35
+ *
36
+ * @public
37
+ */
38
+ export declare const ROBINHOOD_USDG: DeclaredDepositAsset;
39
+ /**
40
+ * Ether on Robinhood Chain, to broadcast the Robinhood first-deposit pipeline's
41
+ * legs with.
42
+ *
43
+ * @public
44
+ */
45
+ export declare const ROBINHOOD_NATIVE_GAS: DeclaredDepositAsset;
46
+ //# sourceMappingURL=depositAssets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"depositAssets.d.ts","sourceRoot":"","sources":["../../../src/utils/depositAssets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,oBAI3B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,oBAIjC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,oBAI9B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,oBAI1B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,oBAI5B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,oBAIlC,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Off-grid resolution for {@link scaleToInteger}:
3
+ * - `truncate` — toward zero, for sizes and collateral amounts. The wire
4
+ * value never exceeds the caller's intent.
5
+ * - `round` — half away from zero, for prices, which snap to the nearest
6
+ * tick.
7
+ * @public
8
+ */
9
+ export type ScaleToIntegerPolicy = 'truncate' | 'round';
10
+ /**
11
+ * Scale a human-readable decimal string to a scaled integer in exact decimal
12
+ * arithmetic — an on-grid input maps to its exact scaled integer with no
13
+ * binary float artifacts (`'0.29'` at 2 decimals is 29, never 28).
14
+ * Off-grid input resolves per `policy`; there is no silent default.
15
+ *
16
+ * @throws {PerpsError} `ValidationError` when `value` is not a decimal
17
+ * numeric string, `decimals` is not a non-negative integer, or the scaled
18
+ * result's magnitude exceeds `Number.MAX_SAFE_INTEGER`.
19
+ * @public
20
+ */
21
+ export declare const scaleToInteger: (value: string, decimals: number, policy: ScaleToIntegerPolicy) => number;
22
+ //# sourceMappingURL=scaleToInteger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaleToInteger.d.ts","sourceRoot":"","sources":["../../../src/utils/scaleToInteger.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,OAAO,CAAA;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,EACb,UAAU,MAAM,EAChB,QAAQ,oBAAoB,KAC3B,MA0BF,CAAA"}
@@ -0,0 +1,17 @@
1
+ import type { ProviderAction } from '@lifi/perps-types';
2
+ /**
3
+ * Select the `Provider.setup` descriptors a user is responsible for satisfying:
4
+ * those whose `signers` include {@link PerpsSigner.USER}. Descriptors the SDK
5
+ * signs on its own (no `USER` signer) are held back — `checkSetup` completes
6
+ * them inline, so surfacing them would render inert cards the user can't act on.
7
+ *
8
+ * Membership is a property of the descriptor's `signers` alone, independent of
9
+ * any account: use this to build the onboarding list, then layer each entry's
10
+ * satisfied/unsatisfied state on top from a live `checkSetup` so the tick never
11
+ * goes stale.
12
+ *
13
+ * @param setup The provider's `setup` descriptors, in their declared order.
14
+ * @public
15
+ */
16
+ export declare function selectUserSetupActions(setup: ProviderAction[]): ProviderAction[];
17
+ //# sourceMappingURL=setupActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupActions.d.ts","sourceRoot":"","sources":["../../../src/utils/setupActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,EAAE,GACtB,cAAc,EAAE,CAIlB"}
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@lifi/perps-sdk";
2
- export declare const version = "0.0.0-preview-697b8c5";
2
+ export declare const version = "0.0.0-preview-1edeff0";
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk",
3
- "version": "0.0.0-preview-697b8c5",
3
+ "version": "0.0.0-preview-1edeff0",
4
4
  "description": "LI.FI Perps SDK for perpetuals trading",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -41,10 +41,11 @@
41
41
  "!tsconfig.json"
42
42
  ],
43
43
  "dependencies": {
44
- "@lifi/types": "17.82.1",
44
+ "@lifi/types": "17.86.0",
45
+ "big.js": "^7.0.1",
45
46
  "partysocket": "^1.1.19",
46
47
  "viem": "^2.48.8",
47
- "@lifi/perps-types": "^0.0.0-preview-697b8c5"
48
+ "@lifi/perps-types": "^0.0.0-preview-1edeff0"
48
49
  },
49
50
  "publishConfig": {
50
51
  "access": "public"
@@ -30,6 +30,7 @@ import type {
30
30
  ExecuteProviderSetupParams,
31
31
  ExecuteProviderSetupResult,
32
32
  GetAccountResult,
33
+ GetDepositFlowParams,
33
34
  GetSetupParams,
34
35
  ModifyOrdersParams,
35
36
  PerpsClientOptions,
@@ -40,6 +41,7 @@ import type {
40
41
  WithdrawParams,
41
42
  } from '../types/api.js'
42
43
  import type { PerpsClientSigner, SwitchChainHook } from '../types/config.js'
44
+ import type { DepositFlow } from '../types/deposit.js'
43
45
  import type {
44
46
  ActionSignerContribution,
45
47
  PerpsProvider,
@@ -412,6 +414,23 @@ export class PerpsClient {
412
414
  return this.requireProvider(provider).accountExists({ address })
413
415
  }
414
416
 
417
+ /**
418
+ * The deposit flow for `params.address` at `params.provider`, delegated to the
419
+ * provider plugin — every deposit decision (the collateral destination, the
420
+ * account-opening pipeline, an outstanding setup gate) is venue-owned.
421
+ *
422
+ * @returns `undefined` when the registered plugin declares no deposit flow.
423
+ * @throws {PerpsError} When the provider plugin is not registered, or the
424
+ * plugin's flow resolution fails.
425
+ * @public
426
+ */
427
+ async getDepositFlow(
428
+ params: GetDepositFlowParams
429
+ ): Promise<DepositFlow | undefined> {
430
+ const plugin = this.requireProvider(params.provider)
431
+ return plugin.getDepositFlow?.({ address: params.address })
432
+ }
433
+
415
434
  /**
416
435
  * Return the unsatisfied entries on `Provider.setup` for this account as a
417
436
  * flat, self-describing list. Trading is gated on `isReady === true`.
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  /**
5
5
  * `@lifi/perps-sdk` — the public entry point. Exports `createPerpsClient` and
6
- * `PerpsClient` (the primary API), the realtime `PerpsWsClient`, the pure
6
+ * `PerpsClient` (the primary API), the WebSocket `PerpsWsClient`, the pure
7
7
  * calculation/parsing/order helpers, and re-exports the shared `@lifi/perps-types`.
8
8
  *
9
9
  * @packageDocumentation
@@ -22,6 +22,7 @@ export { PerpsError } from './errors/PerpsError.js'
22
22
  export { AssetRegistry, getAssetRegistry } from './registry/assetRegistry.js'
23
23
  export {
24
24
  getMarketRegistry,
25
+ isActiveMarket,
25
26
  MarketRegistry,
26
27
  toMarketDisplay,
27
28
  } from './registry/marketRegistry.js'
@@ -38,6 +39,11 @@ export type { GetAssetsParams } from './services/getAssets.js'
38
39
  export { getAssets } from './services/getAssets.js'
39
40
  export type { GetFillsParams } from './services/getFills.js'
40
41
  export { getFills } from './services/getFills.js'
42
+ export type { GetGasRecommendationParams } from './services/getGasRecommendation.js'
43
+ export {
44
+ getGasRecommendation,
45
+ LIFI_API_URL,
46
+ } from './services/getGasRecommendation.js'
41
47
  export type { GetMarketParams } from './services/getMarket.js'
42
48
  export { getMarket } from './services/getMarket.js'
43
49
  export type { GetMarketsParams } from './services/getMarkets.js'
@@ -92,6 +98,7 @@ export type {
92
98
  BuildProviderSetupParams,
93
99
  CancelOrdersParams,
94
100
  GetAccountResult,
101
+ GetDepositFlowParams,
95
102
  GetSetupParams,
96
103
  ModifyOrdersParams,
97
104
  PerpsClientOptions,
@@ -112,6 +119,13 @@ export type {
112
119
  SDKRequestOptions,
113
120
  SwitchChainHook,
114
121
  } from './types/config.js'
122
+ export type {
123
+ DeclaredDepositAsset,
124
+ DepositFlow,
125
+ DepositFlowFirstDepositPipeline,
126
+ DepositFlowLifiSwap,
127
+ DepositFlowSetupRequired,
128
+ } from './types/deposit.js'
115
129
  export type {
116
130
  ActionSignerContribution,
117
131
  LiquidationEstimateParams,
@@ -121,6 +135,7 @@ export type {
121
135
  ProviderAccountExistsParams,
122
136
  ProviderGetAccountParams,
123
137
  ProviderGetActivityParams,
138
+ ProviderGetDepositFlowParams,
124
139
  ProviderGetFillsParams,
125
140
  ProviderGetOrderParams,
126
141
  ProviderGetOrdersParams,
@@ -153,11 +168,14 @@ export {
153
168
  removableMargin,
154
169
  walkOrderbook,
155
170
  } from './utils/calculations.js'
156
- export type { DepositProviderKey } from './utils/depositChain.js'
157
171
  export {
158
- LIFI_DEPOSIT_CHAIN_BY_PROVIDER,
159
- lifiDepositChainForProvider,
160
- } from './utils/depositChain.js'
172
+ ETHEREUM_NATIVE_GAS,
173
+ ETHEREUM_USDC,
174
+ HYPERLIQUID_USDC,
175
+ LIGHTER_USDC,
176
+ ROBINHOOD_NATIVE_GAS,
177
+ ROBINHOOD_USDG,
178
+ } from './utils/depositAssets.js'
161
179
  export {
162
180
  ExplorerChainId,
163
181
  explorerTxUrl,
@@ -197,6 +215,9 @@ export {
197
215
  predictUnrealizedPnl,
198
216
  realizedPnlOnClose,
199
217
  } from './utils/positionMath.js'
218
+ export type { ScaleToIntegerPolicy } from './utils/scaleToInteger.js'
219
+ export { scaleToInteger } from './utils/scaleToInteger.js'
220
+ export { selectUserSetupActions } from './utils/setupActions.js'
200
221
  export {
201
222
  signTypedData,
202
223
  signTypedDataWithSigner,
@@ -23,10 +23,16 @@ export class MarketRegistry extends ReferenceDataRegistry<Market> {
23
23
  return this.items
24
24
  }
25
25
 
26
+ /** The synced markets that are available for live and write operations. */
27
+ get activeMarkets(): readonly Market[] {
28
+ return this.items.filter(isActiveMarket)
29
+ }
30
+
26
31
  /**
27
32
  * Lookup by `Market.id`, throwing when the backend list does not know the
28
- * id. The list is the source of truth for every tradable market, so an id
29
- * the venue references but the backend does not know is a hard error —
33
+ * id. The list is the source of truth for enriched historical and live
34
+ * market metadata, so an id the venue references but the backend does not
35
+ * know is a hard error —
30
36
  * never a silent fallback to an unenriched stand-in.
31
37
  *
32
38
  * @throws {PerpsError} `MarketNotFound`.
@@ -44,6 +50,26 @@ export class MarketRegistry extends ReferenceDataRegistry<Market> {
44
50
  return market
45
51
  }
46
52
 
53
+ /**
54
+ * Lookup a market for live or write use. Delisted markets remain resolvable
55
+ * through {@link require} for historical display mapping, but this method
56
+ * rejects them.
57
+ *
58
+ * @throws {PerpsError} `MarketNotFound` when the market is absent or delisted.
59
+ */
60
+ requireActive(marketId: string): Market {
61
+ const market = this.require(marketId)
62
+ if (!isActiveMarket(market)) {
63
+ const error = new PerpsError(
64
+ PerpsErrorCode.MarketNotFound,
65
+ `Market '${marketId}' is not available for live use`
66
+ )
67
+ error.tool = this.provider
68
+ throw error
69
+ }
70
+ return market
71
+ }
72
+
47
73
  protected fetchItems(): Promise<Market[]> {
48
74
  const url = buildUrl(`${this.client.config.apiUrl}/markets`, {
49
75
  provider: this.provider,
@@ -60,6 +86,10 @@ export class MarketRegistry extends ReferenceDataRegistry<Market> {
60
86
 
61
87
  const registries = new WeakMap<PerpsSDKClient, Map<string, MarketRegistry>>()
62
88
 
89
+ /** A market is active unless the provider explicitly marks it delisted. */
90
+ export const isActiveMarket = (market: Market): boolean =>
91
+ market.isDelisted !== true
92
+
63
93
  /**
64
94
  * The stable {@link MarketRegistry} for `(client, provider)`.
65
95
  *
@@ -95,4 +125,5 @@ export const toMarketDisplay = (market: Market): MarketDisplay => ({
95
125
  categoryId: market.categoryId,
96
126
  baseAsset: market.baseAsset,
97
127
  quoteAsset: market.quoteAsset,
128
+ ...(market.isDelisted === undefined ? {} : { isDelisted: market.isDelisted }),
98
129
  })
@@ -7,7 +7,8 @@ import type { PerpsSDKClient } from '../types/provider.js'
7
7
  * NOT a cache: it holds no freshness policy of its own. Every {@link sync}
8
8
  * refetches through the HTTP layer, whose `cache-control` headers decide
9
9
  * whether the response comes from disk or the network. A lookup miss warns
10
- * once and returns `undefined`; the next {@link sync} reconciles the index.
10
+ * once per id and returns `undefined`; subsequent syncs reconcile the index
11
+ * without replaying the warning for an id that remains absent.
11
12
  *
12
13
  * @internal
13
14
  */
@@ -65,7 +66,6 @@ export abstract class ReferenceDataRegistry<T> {
65
66
  const items = await this.fetchItems()
66
67
  this.index = new Map(items.map((item) => [this.keyOf(item), item]))
67
68
  this.current = items
68
- this.warnedIds.clear()
69
69
  return items
70
70
  }
71
71
  }
@@ -0,0 +1,45 @@
1
+ import type { GasRecommendationResponse } from '@lifi/types'
2
+ import { request } from '../transport/request.js'
3
+ import type { SDKRequestOptions } from '../types/config.js'
4
+ import type { PerpsSDKClient } from '../types/provider.js'
5
+
6
+ /**
7
+ * LI.FI API base URL for reads the user's client makes directly, without the
8
+ * perps backend in the path.
9
+ *
10
+ * @public
11
+ */
12
+ export const LIFI_API_URL = 'https://li.quest/v1'
13
+
14
+ /**
15
+ * Parameters for {@link getGasRecommendation}.
16
+ *
17
+ * @public
18
+ */
19
+ export interface GetGasRecommendationParams {
20
+ /** Chain to hold native gas on — a `firstDepositPipeline` flow's `chainId`. */
21
+ chainId: number
22
+ }
23
+
24
+ /**
25
+ * How much native gas LI.FI suggests holding on `params.chainId` to transact
26
+ * there, for seeding the gas leg of a first-deposit pipeline. Read straight
27
+ * from the LI.FI API by the user's client.
28
+ *
29
+ * @returns The suggestion, with `available: false` and no amounts on a chain
30
+ * LI.FI cannot source gas for.
31
+ * @throws {PerpsError} On API error responses, or network/parsing errors.
32
+ * @public
33
+ */
34
+ export async function getGasRecommendation(
35
+ client: PerpsSDKClient,
36
+ params: GetGasRecommendationParams,
37
+ options?: SDKRequestOptions
38
+ ): Promise<GasRecommendationResponse> {
39
+ return request<GasRecommendationResponse>(
40
+ client.config,
41
+ `${LIFI_API_URL}/gas/suggestion/${params.chainId}`,
42
+ {},
43
+ options
44
+ )
45
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Market, MarketsResponse } from '@lifi/perps-types'
2
2
  import { PerpsErrorCode } from '@lifi/perps-types'
3
3
  import { PerpsError } from '../errors/PerpsError.js'
4
+ import { isActiveMarket } from '../registry/marketRegistry.js'
4
5
  import { buildUrl, request } from '../transport/request.js'
5
6
  import type { SDKRequestOptions } from '../types/config.js'
6
7
  import type { PerpsSDKClient } from '../types/provider.js'
@@ -21,10 +22,11 @@ export interface GetMarketParams {
21
22
  }
22
23
 
23
24
  /**
24
- * Get a specific market by its opaque marketId. Requests the single market
25
- * from the backend `/markets` route (filtered by `marketIds`) and returns the
26
- * first match; throws a `MarketNotFound` {@link PerpsError} both when the
27
- * backend responds 404 and when it responds 200 with an empty list, matching
25
+ * Get a specific active market by its opaque marketId. Requests the single
26
+ * market from the backend `/markets` route (filtered by `marketIds`) and
27
+ * returns the first active match; throws a `MarketNotFound` {@link PerpsError}
28
+ * when the backend responds 404, returns an empty list, or returns a
29
+ * delisted market, matching
28
30
  * `MarketRegistry.require`'s miss behaviour.
29
31
  *
30
32
  * @throws {PerpsError} On backend (e.g. 404 or empty match), network, or parsing errors.
@@ -52,7 +54,7 @@ export async function getMarket(
52
54
  options
53
55
  )
54
56
  const market = markets[0]
55
- if (market === undefined) {
57
+ if (market === undefined || !isActiveMarket(market)) {
56
58
  const error = new PerpsError(
57
59
  PerpsErrorCode.MarketNotFound,
58
60
  `No ${params.provider} market found for marketId '${params.marketId}'`
@@ -1,4 +1,5 @@
1
1
  import type { MarketsResponse } from '@lifi/perps-types'
2
+ import { isActiveMarket } from '../registry/marketRegistry.js'
2
3
  import { buildUrl, request } from '../transport/request.js'
3
4
  import type { SDKRequestOptions } from '../types/config.js'
4
5
  import type { PerpsSDKClient } from '../types/provider.js'
@@ -15,9 +16,12 @@ export interface GetMarketsParams {
15
16
  }
16
17
 
17
18
  /**
18
- * Get all available markets for a provider. Thin pass-through to the LI.FI
19
- * backend's Valkey-cached `/perps/markets` route — the canonical source of
20
- * public market data for widget consumers.
19
+ * Get active markets for a provider. Delisted entries remain available to
20
+ * internal registries for historical mapping, but are excluded from this
21
+ * public market-selection surface.
22
+ *
23
+ * Thin pass-through to the LI.FI backend's Valkey-cached `/perps/markets`
24
+ * route — the canonical source of public market data for widget consumers.
21
25
  *
22
26
  * @throws {PerpsError} On backend, network, or parsing errors.
23
27
  * @example
@@ -36,5 +40,11 @@ export async function getMarkets(
36
40
  provider: params.provider,
37
41
  marketIds: params.marketIds?.join(','),
38
42
  })
39
- return request<MarketsResponse>(client.config, url, {}, options)
43
+ const response = await request<MarketsResponse>(
44
+ client.config,
45
+ url,
46
+ {},
47
+ options
48
+ )
49
+ return { markets: response.markets.filter(isActiveMarket) }
40
50
  }
package/src/types/api.ts CHANGED
@@ -209,6 +209,16 @@ export interface GetSetupParams {
209
209
  address: Address
210
210
  }
211
211
 
212
+ /**
213
+ * Parameters for {@link PerpsClient.getDepositFlow}.
214
+ *
215
+ * @public
216
+ */
217
+ export interface GetDepositFlowParams {
218
+ provider: string
219
+ address: Address
220
+ }
221
+
212
222
  /**
213
223
  * Result from {@link PerpsClient.checkSetup}.
214
224
  *
@@ -0,0 +1,75 @@
1
+ import type { ActionType } from '@lifi/perps-types'
2
+ import type { Address } from 'viem'
3
+
4
+ /**
5
+ * A token the SDK declares as part of a deposit flow, by full on-chain
6
+ * identity. Matched by `chainId` + `address`: a symbol is not identity — the
7
+ * Hyperliquid venue chain lists two `USDC` contracts with different decimals.
8
+ *
9
+ * @public
10
+ */
11
+ export interface DeclaredDepositAsset {
12
+ chainId: number
13
+ /** EIP-55 checksummed address; the zero address denotes the chain's native gas token. */
14
+ address: Address
15
+ decimals: number
16
+ }
17
+
18
+ /**
19
+ * Fund the account by swapping whatever the user holds into `destination`
20
+ * through the LI.FI surface. The source token is picked inside that surface, so
21
+ * it is not part of the flow; LI.FI routing owns whether that resolves to a
22
+ * same-chain swap or a bridge.
23
+ *
24
+ * @public
25
+ */
26
+ export interface DepositFlowLifiSwap {
27
+ kind: 'lifiSwap'
28
+ destination: DeclaredDepositAsset
29
+ /**
30
+ * Credited address when it is not the user's own — a venue-provisioned
31
+ * deposit address. Absent means the user's address receives the deposit.
32
+ */
33
+ toAddress?: Address
34
+ }
35
+
36
+ /**
37
+ * Fund an address that has no venue account yet. Collateral and the native gas
38
+ * to broadcast with are both needed on `chainId`, where the venue's
39
+ * {@link ActionType.DEPOSIT} action stages the on-chain legs that open the
40
+ * account.
41
+ *
42
+ * @public
43
+ */
44
+ export interface DepositFlowFirstDepositPipeline {
45
+ kind: 'firstDepositPipeline'
46
+ /** Chain the deposit legs broadcast on; the user's wallet must be switched to it. */
47
+ chainId: number
48
+ gasAsset: DeclaredDepositAsset
49
+ collateral: DeclaredDepositAsset
50
+ bridgeAction: ActionType.DEPOSIT
51
+ }
52
+
53
+ /**
54
+ * The venue cannot name a deposit destination until the listed setup actions
55
+ * are satisfied — Ondo provisions its deposit address behind a signed-in
56
+ * session.
57
+ *
58
+ * @public
59
+ */
60
+ export interface DepositFlowSetupRequired {
61
+ kind: 'setupRequired'
62
+ /** Outstanding `Provider.setup` action types, in the order they must be run. */
63
+ setup: ActionType[]
64
+ }
65
+
66
+ /**
67
+ * The single deposit flow a venue offers one address, resolved from the venue's
68
+ * account and setup state.
69
+ *
70
+ * @public
71
+ */
72
+ export type DepositFlow =
73
+ | DepositFlowLifiSwap
74
+ | DepositFlowFirstDepositPipeline
75
+ | DepositFlowSetupRequired
@@ -29,6 +29,7 @@ import type {
29
29
  PerpsClientSigner,
30
30
  SDKRequestOptions,
31
31
  } from './config.js'
32
+ import type { DepositFlow } from './deposit.js'
32
33
 
33
34
  /**
34
35
  * Low-level SDK client: resolved config, the optional end-user wallet, and the
@@ -162,6 +163,15 @@ export interface ProviderAccountExistsParams {
162
163
  address: Address
163
164
  }
164
165
 
166
+ /**
167
+ * Read params for {@link PerpsProviderPlugin.getDepositFlow}.
168
+ *
169
+ * @public
170
+ */
171
+ export interface ProviderGetDepositFlowParams {
172
+ address: Address
173
+ }
174
+
165
175
  /**
166
176
  * Read params for {@link PerpsProvider.getPositions}.
167
177
  *
@@ -321,6 +331,20 @@ export interface PerpsProviderPlugin {
321
331
  options?: SDKRequestOptions
322
332
  ): Promise<boolean>
323
333
 
334
+ /**
335
+ * The deposit flow this venue offers `params.address`, resolved from the
336
+ * venue's own account and setup state — which collateral token a deposit must
337
+ * land in, whether the address first needs the account-opening pipeline, and
338
+ * whether venue setup gates naming a destination at all.
339
+ *
340
+ * Optional: a provider that cannot be funded through the SDK omits it, and
341
+ * `PerpsClient.getDepositFlow` then resolves `undefined`.
342
+ */
343
+ getDepositFlow?(
344
+ params: ProviderGetDepositFlowParams,
345
+ options?: SDKRequestOptions
346
+ ): Promise<DepositFlow>
347
+
324
348
  getPositions(
325
349
  params: ProviderGetPositionsParams,
326
350
  options?: SDKRequestOptions
@@ -8,6 +8,12 @@ import { stringToFloat } from './parse.js'
8
8
  const sumValueUsd = (balances: AccountResponse['balances']): number =>
9
9
  balances.reduce((sum, b) => sum + stringToFloat(b.valueUsd), 0)
10
10
 
11
+ const sumMarginUsd = (balances: AccountResponse['balances']): number =>
12
+ balances.reduce(
13
+ (sum, b) => sum + stringToFloat(b.valueUsd) * (b.collateralWeight ?? 1),
14
+ 0
15
+ )
16
+
11
17
  /**
12
18
  * What the summed `collateralBalances` rows already contain, relative to the
13
19
  * positions' locked margin and unrealized PnL:
@@ -51,12 +57,17 @@ export function summarizeAccount(
51
57
  }
52
58
 
53
59
  const collateral = sumValueUsd(account.collateralBalances)
60
+ // Margin-eligible collateral: each row's value scaled by its loan-to-value
61
+ // weight (1 when unset), so a haircut asset backs buying power at less than
62
+ // face while `portfolioValue` still reflects its full value.
63
+ const marginCollateral = sumMarginUsd(account.collateralBalances)
54
64
  const balances = sumValueUsd(account.balances)
55
65
 
56
- const grossCollateral =
57
- semantics === 'free' || semantics === 'net'
58
- ? collateral + marginUsed
59
- : collateral
66
+ const withLocked = semantics === 'free' || semantics === 'net'
67
+ const grossCollateral = withLocked ? collateral + marginUsed : collateral
68
+ const grossMarginCollateral = withLocked
69
+ ? marginCollateral + marginUsed
70
+ : marginCollateral
60
71
  const equity =
61
72
  semantics === 'equity' || semantics === 'net'
62
73
  ? grossCollateral
@@ -66,7 +77,9 @@ export function summarizeAccount(
66
77
  // toward it. The `'free'` rows exclude uPnL from available margin, holding
67
78
  // it purely as free collateral.
68
79
  const availableMargin =
69
- semantics === 'free' ? grossCollateral - marginUsed : equity - marginUsed
80
+ grossMarginCollateral +
81
+ (semantics === 'gross' ? unrealizedPnl : 0) -
82
+ marginUsed
70
83
 
71
84
  return {
72
85
  portfolioValue: (balances + equity).toString(),