@lifi/perps-sdk 0.0.0-preview-e1b82a0 → 0.0.0-preview-bc9d3c9

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 (103) hide show
  1. package/README.md +1 -12
  2. package/dist/cjs/client/PerpsClient.d.ts +2 -3
  3. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  4. package/dist/cjs/client/PerpsClient.js +2 -11
  5. package/dist/cjs/client/PerpsClient.js.map +1 -1
  6. package/dist/cjs/decimal/compare.d.ts +3 -0
  7. package/dist/cjs/decimal/compare.d.ts.map +1 -0
  8. package/dist/cjs/decimal/compare.js +8 -0
  9. package/dist/cjs/decimal/compare.js.map +1 -0
  10. package/dist/cjs/decimal/format.d.ts.map +1 -1
  11. package/dist/cjs/decimal/format.js +3 -0
  12. package/dist/cjs/decimal/format.js.map +1 -1
  13. package/dist/cjs/decimal/parse.d.ts +1 -0
  14. package/dist/cjs/decimal/parse.d.ts.map +1 -1
  15. package/dist/cjs/decimal/parse.js +8 -0
  16. package/dist/cjs/decimal/parse.js.map +1 -1
  17. package/dist/cjs/decimal/requireDecimal.d.ts +1 -1
  18. package/dist/cjs/decimal/requireDecimal.d.ts.map +1 -1
  19. package/dist/cjs/decimal/requireDecimal.js +1 -6
  20. package/dist/cjs/decimal/requireDecimal.js.map +1 -1
  21. package/dist/cjs/index.d.ts +6 -5
  22. package/dist/cjs/index.d.ts.map +1 -1
  23. package/dist/cjs/index.js +7 -3
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/math/position.d.ts +3 -1
  26. package/dist/cjs/math/position.d.ts.map +1 -1
  27. package/dist/cjs/math/position.js +12 -0
  28. package/dist/cjs/math/position.js.map +1 -1
  29. package/dist/cjs/types/api.d.ts +0 -4
  30. package/dist/cjs/types/api.d.ts.map +1 -1
  31. package/dist/cjs/types/provider.d.ts +1 -5
  32. package/dist/cjs/types/provider.d.ts.map +1 -1
  33. package/dist/cjs/types/withdrawal.d.ts +4 -12
  34. package/dist/cjs/types/withdrawal.d.ts.map +1 -1
  35. package/dist/cjs/version.d.ts +1 -1
  36. package/dist/cjs/version.js +1 -1
  37. package/dist/esm/client/PerpsClient.d.ts +4 -17
  38. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  39. package/dist/esm/client/PerpsClient.js +4 -25
  40. package/dist/esm/client/PerpsClient.js.map +1 -1
  41. package/dist/esm/decimal/compare.d.ts +11 -0
  42. package/dist/esm/decimal/compare.d.ts.map +1 -0
  43. package/dist/esm/decimal/compare.js +13 -0
  44. package/dist/esm/decimal/compare.js.map +1 -0
  45. package/dist/esm/decimal/format.d.ts.map +1 -1
  46. package/dist/esm/decimal/format.js +4 -0
  47. package/dist/esm/decimal/format.js.map +1 -1
  48. package/dist/esm/decimal/parse.d.ts +10 -0
  49. package/dist/esm/decimal/parse.d.ts.map +1 -1
  50. package/dist/esm/decimal/parse.js +17 -1
  51. package/dist/esm/decimal/parse.js.map +1 -1
  52. package/dist/esm/decimal/requireDecimal.d.ts +2 -8
  53. package/dist/esm/decimal/requireDecimal.d.ts.map +1 -1
  54. package/dist/esm/decimal/requireDecimal.js +3 -14
  55. package/dist/esm/decimal/requireDecimal.js.map +1 -1
  56. package/dist/esm/index.d.ts +6 -5
  57. package/dist/esm/index.d.ts.map +1 -1
  58. package/dist/esm/index.js +3 -2
  59. package/dist/esm/index.js.map +1 -1
  60. package/dist/esm/math/position.d.ts +11 -1
  61. package/dist/esm/math/position.d.ts.map +1 -1
  62. package/dist/esm/math/position.js +19 -0
  63. package/dist/esm/math/position.js.map +1 -1
  64. package/dist/esm/types/api.d.ts +0 -9
  65. package/dist/esm/types/api.d.ts.map +1 -1
  66. package/dist/esm/types/provider.d.ts +5 -22
  67. package/dist/esm/types/provider.d.ts.map +1 -1
  68. package/dist/esm/types/withdrawal.d.ts +7 -32
  69. package/dist/esm/types/withdrawal.d.ts.map +1 -1
  70. package/dist/esm/version.d.ts +1 -1
  71. package/dist/esm/version.js +1 -1
  72. package/dist/types/client/PerpsClient.d.ts +4 -17
  73. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  74. package/dist/types/decimal/compare.d.ts +11 -0
  75. package/dist/types/decimal/compare.d.ts.map +1 -0
  76. package/dist/types/decimal/format.d.ts.map +1 -1
  77. package/dist/types/decimal/parse.d.ts +10 -0
  78. package/dist/types/decimal/parse.d.ts.map +1 -1
  79. package/dist/types/decimal/requireDecimal.d.ts +2 -8
  80. package/dist/types/decimal/requireDecimal.d.ts.map +1 -1
  81. package/dist/types/index.d.ts +6 -5
  82. package/dist/types/index.d.ts.map +1 -1
  83. package/dist/types/math/position.d.ts +11 -1
  84. package/dist/types/math/position.d.ts.map +1 -1
  85. package/dist/types/types/api.d.ts +0 -9
  86. package/dist/types/types/api.d.ts.map +1 -1
  87. package/dist/types/types/provider.d.ts +5 -22
  88. package/dist/types/types/provider.d.ts.map +1 -1
  89. package/dist/types/types/withdrawal.d.ts +7 -32
  90. package/dist/types/types/withdrawal.d.ts.map +1 -1
  91. package/dist/types/version.d.ts +1 -1
  92. package/package.json +2 -2
  93. package/src/client/PerpsClient.ts +5 -35
  94. package/src/decimal/compare.ts +17 -0
  95. package/src/decimal/format.ts +4 -0
  96. package/src/decimal/parse.ts +28 -1
  97. package/src/decimal/requireDecimal.ts +4 -17
  98. package/src/index.ts +8 -5
  99. package/src/math/position.ts +25 -0
  100. package/src/types/api.ts +0 -10
  101. package/src/types/provider.ts +5 -31
  102. package/src/types/withdrawal.ts +8 -35
  103. package/src/version.ts +1 -1
@@ -10,10 +10,12 @@
10
10
 
11
11
  import {
12
12
  MarginMode,
13
+ type PerpsMarket,
13
14
  type Position,
14
15
  PositionMarginAdjustment,
15
16
  } from '@lifi/perps-types'
16
17
  import { areFinite, DivBig } from '../decimal/big.js'
18
+ import type { LiquidationEstimateParams } from '../types/provider.js'
17
19
 
18
20
  /**
19
21
  * Calculate notional value of a position.
@@ -179,6 +181,29 @@ export function estimateLiquidationPrice(params: {
179
181
  .toNumber()
180
182
  }
181
183
 
184
+ /**
185
+ * Estimate the liquidation price of a new isolated position from the flat
186
+ * `market.maintenanceMarginRate`.
187
+ *
188
+ * @returns The estimate, or `undefined` when the market carries no
189
+ * `maintenanceMarginRate` or `estimateLiquidationPrice` cannot produce one.
190
+ * @public
191
+ */
192
+ export function estimateLiquidationPriceAtMarketRate(
193
+ market: PerpsMarket,
194
+ params: LiquidationEstimateParams
195
+ ): number | undefined {
196
+ if (market.maintenanceMarginRate === undefined) {
197
+ return undefined
198
+ }
199
+ return estimateLiquidationPrice({
200
+ entryPrice: params.entryPrice,
201
+ leverage: params.leverage,
202
+ isLong: params.isLong,
203
+ maintenanceMarginRate: market.maintenanceMarginRate,
204
+ })
205
+ }
206
+
182
207
  /**
183
208
  * Whether an isolated position with this liquidation price is already past
184
209
  * liquidation at `currentPrice`: a long liquidates when the price falls to its
package/src/types/api.ts CHANGED
@@ -293,16 +293,6 @@ export interface GetWithdrawableBalancesParams {
293
293
  address: Address
294
294
  }
295
295
 
296
- /**
297
- * Parameters for {@link PerpsClient.getWithdrawalTypes}.
298
- *
299
- * @public
300
- */
301
- export interface GetWithdrawalTypesParams {
302
- provider: string
303
- address: Address
304
- }
305
-
306
296
  /**
307
297
  * Parameters for {@link PerpsClient.getPortfolioHistory}.
308
298
  *
@@ -37,11 +37,7 @@ import type {
37
37
  SDKRequestOptions,
38
38
  } from './config.js'
39
39
  import type { DepositFlow } from './deposit.js'
40
- import type {
41
- ProviderWithdrawableBalance,
42
- WithdrawalSourceTypes,
43
- WithdrawFlow,
44
- } from './withdrawal.js'
40
+ import type { ProviderWithdrawableBalance, WithdrawFlow } from './withdrawal.js'
45
41
 
46
42
  /**
47
43
  * Low-level SDK client: resolved config, the optional end-user wallet, and the
@@ -203,15 +199,6 @@ export interface ProviderGetWithdrawableBalancesParams {
203
199
  address: Address
204
200
  }
205
201
 
206
- /**
207
- * Read params for {@link PerpsProviderPlugin.getWithdrawalTypes}.
208
- *
209
- * @public
210
- */
211
- export interface ProviderGetWithdrawalTypesParams {
212
- address: Address
213
- }
214
-
215
202
  /**
216
203
  * Read params for {@link PerpsProvider.getPositions}.
217
204
  *
@@ -447,33 +434,20 @@ export interface PerpsProviderPlugin {
447
434
  ): Promise<WithdrawFlow>
448
435
 
449
436
  /**
450
- * The `(asset, category)` pairs `params.address` currently has something to
437
+ * The `(asset, route)` pairs `params.address` currently has something to
451
438
  * withdraw from, keyed by provider-native asset id. Only the venue knows how
452
- * its balance payload splits across categories, so the split is owned here; the
439
+ * its balance payload splits across routes, so the split is owned here; the
453
440
  * per-asset venue minimum is applied by `PerpsClient.getWithdrawableBalances`,
454
441
  * which holds the core asset registry.
455
442
  *
456
- * Optional: a provider whose withdrawals are not a per-category selection
457
- * omits it, and `PerpsClient.getWithdrawableBalances` then resolves
458
- * `undefined`.
443
+ * Optional: a provider whose withdrawals are not a per-route selection omits
444
+ * it, and `PerpsClient.getWithdrawableBalances` then resolves `undefined`.
459
445
  */
460
446
  getWithdrawableBalances?(
461
447
  params: ProviderGetWithdrawableBalancesParams,
462
448
  options?: SDKRequestOptions
463
449
  ): Promise<ProviderWithdrawableBalance[]>
464
450
 
465
- /**
466
- * The withdrawal types `params.address` can choose per withdrawable holding,
467
- * each with its cap and the `withdrawalOptions` to send with it.
468
- *
469
- * Optional: a provider with one withdrawal type omits it, and
470
- * `PerpsClient.getWithdrawalTypes` then resolves `undefined`.
471
- */
472
- getWithdrawalTypes?(
473
- params: ProviderGetWithdrawalTypesParams,
474
- options?: SDKRequestOptions
475
- ): Promise<WithdrawalSourceTypes[]>
476
-
477
451
  getPositions(
478
452
  params: ProviderGetPositionsParams,
479
453
  options?: SDKRequestOptions
@@ -2,22 +2,22 @@ import type {
2
2
  ActionType,
3
3
  Asset,
4
4
  DecimalString,
5
- WithdrawalAssetRef,
6
- WithdrawalType,
5
+ WithdrawalRoute,
7
6
  } from '@lifi/perps-types'
8
7
  import type { Address } from 'viem'
9
8
 
9
+ export type { WithdrawalRoute }
10
+
10
11
  /**
11
- * One withdrawable `(asset, category)` selection as the provider reports it,
12
- * keyed by provider-native asset id and awaiting the core asset-metadata join.
12
+ * One withdrawable `(asset, route)` selection as the provider reports it, keyed
13
+ * by provider-native asset id and awaiting the core asset-metadata join.
13
14
  *
14
15
  * @public
15
16
  */
16
17
  export interface ProviderWithdrawableBalance {
17
18
  /** Provider-native `Asset.id`; never a display symbol. */
18
19
  assetId: string
19
- /** The provider category the row draws from; the same value as `Balance.categoryId`. */
20
- categoryId: string
20
+ route: WithdrawalRoute
21
21
  /** Withdrawable amount in the asset's own units. Always greater than zero. */
22
22
  available: DecimalString
23
23
  /**
@@ -41,7 +41,7 @@ export interface ProviderWithdrawableBalance {
41
41
  }
42
42
 
43
43
  /**
44
- * One withdrawable `(asset, category)` selection a caller can act on: the amount
44
+ * One withdrawable `(asset, route)` selection a caller can act on: the amount
45
45
  * clears the asset's venue minimum, and `asset` carries the precision and
46
46
  * minimum needed to scale and validate the withdrawal.
47
47
  *
@@ -49,8 +49,7 @@ export interface ProviderWithdrawableBalance {
49
49
  */
50
50
  export interface WithdrawableBalance {
51
51
  asset: Asset
52
- /** The provider category the row draws from; the same value as `Balance.categoryId`. */
53
- categoryId: string
52
+ route: WithdrawalRoute
54
53
  /** Withdrawable amount in the asset's own units. */
55
54
  available: DecimalString
56
55
  /**
@@ -78,32 +77,6 @@ export interface WithdrawableBalance {
78
77
  isFeeDeducted?: boolean
79
78
  }
80
79
 
81
- /**
82
- * One way a venue can settle a withdrawal from a holding.
83
- *
84
- * @public
85
- */
86
- export interface WithdrawalTypeOption {
87
- type: WithdrawalType
88
- /** Largest `amount` this type accepts from the holding, in the asset's own units. */
89
- max: DecimalString
90
- /**
91
- * Provider-specific options to pass unchanged as
92
- * `WithdrawalParams.withdrawalOptions` when the user picks this type.
93
- */
94
- withdrawalOptions: Record<string, unknown>
95
- }
96
-
97
- /**
98
- * The withdrawal types a venue offers for one holding.
99
- *
100
- * @public
101
- */
102
- export interface WithdrawalSourceTypes {
103
- source: WithdrawalAssetRef
104
- options: WithdrawalTypeOption[]
105
- }
106
-
107
80
  /**
108
81
  * The venue accepts a withdrawal to `destination` now.
109
82
  *
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-e1b82a0'
13
+ export const version = '0.0.0-preview-bc9d3c9'