@lifi/perps-sdk 0.0.0-preview-e1b82a0 → 0.0.0-preview-dba4b08
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 +5 -4
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math/fills.d.ts.map +1 -1
- package/dist/cjs/math/fills.js +15 -14
- package/dist/cjs/math/fills.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 +5 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math/fills.d.ts +5 -1
- package/dist/esm/math/fills.d.ts.map +1 -1
- package/dist/esm/math/fills.js +20 -15
- package/dist/esm/math/fills.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 +5 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/math/fills.d.ts +5 -1
- package/dist/types/math/fills.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 +7 -5
- package/src/math/fills.ts +24 -15
- 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/fills.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
FillClassification,
|
|
4
4
|
OrderSide,
|
|
5
5
|
} from '@lifi/perps-types'
|
|
6
|
-
import {
|
|
6
|
+
import { requireDecimal } from '../decimal/requireDecimal.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Re-exported fill taxonomy used by {@link classifyFillFromPosition}.
|
|
@@ -19,7 +19,9 @@ export { FillClassification }
|
|
|
19
19
|
* @param startPosition Signed position held BEFORE this fill (`> 0` long,
|
|
20
20
|
* `< 0` short, `0` flat).
|
|
21
21
|
* @param side Hyperliquid-style: `'B'` for buy, anything else for sell.
|
|
22
|
-
* @param sz Unsigned fill size
|
|
22
|
+
* @param sz Unsigned fill size.
|
|
23
|
+
* @throws {PerpsError} `ValidationError` when `startPosition` or `sz` is not a
|
|
24
|
+
* decimal string.
|
|
23
25
|
* @public
|
|
24
26
|
*/
|
|
25
27
|
export function classifyFillFromPosition(
|
|
@@ -27,36 +29,39 @@ export function classifyFillFromPosition(
|
|
|
27
29
|
side: string,
|
|
28
30
|
sz: DecimalString
|
|
29
31
|
): FillClassification {
|
|
30
|
-
const start =
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const start = requireDecimal(
|
|
33
|
+
startPosition,
|
|
34
|
+
'classifyFillFromPosition(startPosition)'
|
|
35
|
+
)
|
|
36
|
+
const size = requireDecimal(sz, 'classifyFillFromPosition(sz)')
|
|
37
|
+
const end = side === 'B' ? start.plus(size) : start.minus(size)
|
|
33
38
|
|
|
34
|
-
if (start
|
|
35
|
-
return end
|
|
39
|
+
if (start.eq(0)) {
|
|
40
|
+
return end.gt(0)
|
|
36
41
|
? FillClassification.OPENED_LONG
|
|
37
42
|
: FillClassification.OPENED_SHORT
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
if (start
|
|
41
|
-
if (end
|
|
45
|
+
if (start.gt(0)) {
|
|
46
|
+
if (end.eq(0)) {
|
|
42
47
|
return FillClassification.CLOSED_LONG
|
|
43
48
|
}
|
|
44
|
-
if (end
|
|
49
|
+
if (end.lt(0)) {
|
|
45
50
|
return FillClassification.SWITCHED_SHORT
|
|
46
51
|
}
|
|
47
|
-
if (end
|
|
52
|
+
if (end.gt(start)) {
|
|
48
53
|
return FillClassification.INCREASED_LONG
|
|
49
54
|
}
|
|
50
55
|
return FillClassification.REDUCED_LONG
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
if (end
|
|
58
|
+
if (end.eq(0)) {
|
|
54
59
|
return FillClassification.CLOSED_SHORT
|
|
55
60
|
}
|
|
56
|
-
if (end
|
|
61
|
+
if (end.gt(0)) {
|
|
57
62
|
return FillClassification.SWITCHED_LONG
|
|
58
63
|
}
|
|
59
|
-
if (end
|
|
64
|
+
if (end.lt(start)) {
|
|
60
65
|
return FillClassification.INCREASED_SHORT
|
|
61
66
|
}
|
|
62
67
|
return FillClassification.REDUCED_SHORT
|
|
@@ -66,13 +71,17 @@ export function classifyFillFromPosition(
|
|
|
66
71
|
* Classify a fill as open or close based on realizedPnl.
|
|
67
72
|
* @deprecated Use `Fill.classification` instead — it uses startPosition
|
|
68
73
|
* for accurate open/increase/reduce/close/reverse classification.
|
|
74
|
+
* @throws {PerpsError} `ValidationError` when `realizedPnl` is a string that
|
|
75
|
+
* is not a decimal string.
|
|
69
76
|
* @public
|
|
70
77
|
*/
|
|
71
78
|
export function classifyFill(
|
|
72
79
|
side: OrderSide,
|
|
73
80
|
realizedPnl: DecimalString | null | undefined
|
|
74
81
|
): FillClassification {
|
|
75
|
-
const isClose =
|
|
82
|
+
const isClose =
|
|
83
|
+
realizedPnl != null &&
|
|
84
|
+
!requireDecimal(realizedPnl, 'classifyFill(realizedPnl)').eq(0)
|
|
76
85
|
if (side === OrderSide.BUY) {
|
|
77
86
|
return isClose
|
|
78
87
|
? FillClassification.CLOSED_SHORT
|
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