@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.
- package/README.md +1 -12
- package/dist/cjs/client/PerpsClient.d.ts +2 -3
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +2 -11
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/decimal/compare.d.ts +3 -0
- package/dist/cjs/decimal/compare.d.ts.map +1 -0
- package/dist/cjs/decimal/compare.js +8 -0
- package/dist/cjs/decimal/compare.js.map +1 -0
- package/dist/cjs/decimal/format.d.ts.map +1 -1
- package/dist/cjs/decimal/format.js +3 -0
- package/dist/cjs/decimal/format.js.map +1 -1
- package/dist/cjs/decimal/parse.d.ts +1 -0
- package/dist/cjs/decimal/parse.d.ts.map +1 -1
- package/dist/cjs/decimal/parse.js +8 -0
- package/dist/cjs/decimal/parse.js.map +1 -1
- package/dist/cjs/decimal/requireDecimal.d.ts +1 -1
- package/dist/cjs/decimal/requireDecimal.d.ts.map +1 -1
- package/dist/cjs/decimal/requireDecimal.js +1 -6
- package/dist/cjs/decimal/requireDecimal.js.map +1 -1
- package/dist/cjs/index.d.ts +6 -5
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math/position.d.ts +3 -1
- package/dist/cjs/math/position.d.ts.map +1 -1
- package/dist/cjs/math/position.js +12 -0
- package/dist/cjs/math/position.js.map +1 -1
- package/dist/cjs/types/api.d.ts +0 -4
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +1 -5
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts +4 -12
- package/dist/cjs/types/withdrawal.d.ts.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client/PerpsClient.d.ts +4 -17
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +4 -25
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/decimal/compare.d.ts +11 -0
- package/dist/esm/decimal/compare.d.ts.map +1 -0
- package/dist/esm/decimal/compare.js +13 -0
- package/dist/esm/decimal/compare.js.map +1 -0
- package/dist/esm/decimal/format.d.ts.map +1 -1
- package/dist/esm/decimal/format.js +4 -0
- package/dist/esm/decimal/format.js.map +1 -1
- package/dist/esm/decimal/parse.d.ts +10 -0
- package/dist/esm/decimal/parse.d.ts.map +1 -1
- package/dist/esm/decimal/parse.js +17 -1
- package/dist/esm/decimal/parse.js.map +1 -1
- package/dist/esm/decimal/requireDecimal.d.ts +2 -8
- package/dist/esm/decimal/requireDecimal.d.ts.map +1 -1
- package/dist/esm/decimal/requireDecimal.js +3 -14
- package/dist/esm/decimal/requireDecimal.js.map +1 -1
- package/dist/esm/index.d.ts +6 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math/position.d.ts +11 -1
- package/dist/esm/math/position.d.ts.map +1 -1
- package/dist/esm/math/position.js +19 -0
- package/dist/esm/math/position.js.map +1 -1
- package/dist/esm/types/api.d.ts +0 -9
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +5 -22
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +7 -32
- package/dist/esm/types/withdrawal.d.ts.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/client/PerpsClient.d.ts +4 -17
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/decimal/compare.d.ts +11 -0
- package/dist/types/decimal/compare.d.ts.map +1 -0
- package/dist/types/decimal/format.d.ts.map +1 -1
- package/dist/types/decimal/parse.d.ts +10 -0
- package/dist/types/decimal/parse.d.ts.map +1 -1
- package/dist/types/decimal/requireDecimal.d.ts +2 -8
- package/dist/types/decimal/requireDecimal.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/math/position.d.ts +11 -1
- package/dist/types/math/position.d.ts.map +1 -1
- package/dist/types/types/api.d.ts +0 -9
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +5 -22
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +7 -32
- package/dist/types/types/withdrawal.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +5 -35
- package/src/decimal/compare.ts +17 -0
- package/src/decimal/format.ts +4 -0
- package/src/decimal/parse.ts +28 -1
- package/src/decimal/requireDecimal.ts +4 -17
- package/src/index.ts +8 -5
- package/src/math/position.ts +25 -0
- package/src/types/api.ts +0 -10
- package/src/types/provider.ts +5 -31
- package/src/types/withdrawal.ts +8 -35
- package/src/version.ts +1 -1
package/src/math/position.ts
CHANGED
|
@@ -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
|
*
|
package/src/types/provider.ts
CHANGED
|
@@ -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,
|
|
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
|
|
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-
|
|
457
|
-
*
|
|
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
|
package/src/types/withdrawal.ts
CHANGED
|
@@ -2,22 +2,22 @@ import type {
|
|
|
2
2
|
ActionType,
|
|
3
3
|
Asset,
|
|
4
4
|
DecimalString,
|
|
5
|
-
|
|
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,
|
|
12
|
-
*
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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