@lifi/perps-sdk 36.3.1 → 36.5.0
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 +18 -5
- package/dist/cjs/client/PerpsClient.d.ts +3 -2
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +8 -0
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/decimal/format.d.ts +9 -1
- package/dist/cjs/decimal/format.d.ts.map +1 -1
- package/dist/cjs/decimal/format.js +18 -8
- package/dist/cjs/decimal/format.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +6 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/api.d.ts +6 -0
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +7 -1
- package/dist/cjs/types/provider.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 +13 -2
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +18 -0
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/decimal/format.d.ts +35 -1
- package/dist/esm/decimal/format.d.ts.map +1 -1
- package/dist/esm/decimal/format.js +39 -19
- package/dist/esm/decimal/format.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api.d.ts +17 -3
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +20 -1
- package/dist/esm/types/provider.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 +13 -2
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/decimal/format.d.ts +35 -1
- package/dist/types/decimal/format.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/api.d.ts +17 -3
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +20 -1
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/client/PerpsClient.ts +27 -0
- package/src/decimal/format.ts +84 -19
- package/src/index.ts +5 -0
- package/src/types/api.ts +18 -3
- package/src/types/provider.ts +25 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "36.
|
|
3
|
+
"version": "36.5.0",
|
|
4
4
|
"description": "LI.FI Perps SDK for perpetuals trading",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"@lifi/types": "^18.3.0",
|
|
46
46
|
"big.js": "^7.0.1",
|
|
47
47
|
"partysocket": "^1.1.19",
|
|
48
|
-
"@lifi/perps-types": "^30.
|
|
48
|
+
"@lifi/perps-types": "^30.6.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"viem": "
|
|
51
|
+
"viem": "2.57.11 || ^2.57.17"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
@@ -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,
|
|
@@ -925,6 +927,31 @@ export class PerpsClient {
|
|
|
925
927
|
return plugin.getDepositFlow?.({ address: params.address }, options)
|
|
926
928
|
}
|
|
927
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
|
+
|
|
928
955
|
/**
|
|
929
956
|
* Current cross-margin health of `params.address` at `params.provider`,
|
|
930
957
|
* calculated by the provider plugin.
|
package/src/decimal/format.ts
CHANGED
|
@@ -37,6 +37,31 @@ export interface FormatOptions {
|
|
|
37
37
|
rounding?: RoundingMode
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Options for {@link formatNumber}.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export interface NumberFormatOptions extends FormatOptions {
|
|
46
|
+
/** Drops trailing fraction zeros: `50.00` renders as `50`, `12.50` as `12.5`. */
|
|
47
|
+
trimZeros?: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Options for {@link formatCompactNumber}.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export interface CompactNumberOptions extends NumberFormatOptions {
|
|
56
|
+
/**
|
|
57
|
+
* Significant digits of the compact mantissa, with trailing zeros dropped
|
|
58
|
+
* (`84.5K`, `1M`). Replaces `decimals` when set.
|
|
59
|
+
*/
|
|
60
|
+
significantDigits?: number
|
|
61
|
+
/** Magnitudes below this value render as {@link formatNumber}, with no suffix. */
|
|
62
|
+
compactFrom?: DecimalString
|
|
63
|
+
}
|
|
64
|
+
|
|
40
65
|
/**
|
|
41
66
|
* Options for {@link formatCompactUsd}.
|
|
42
67
|
*
|
|
@@ -102,17 +127,21 @@ function signAndBody(
|
|
|
102
127
|
locale: string | undefined,
|
|
103
128
|
grouping: boolean,
|
|
104
129
|
rounding: RoundingMode,
|
|
105
|
-
signed: boolean
|
|
130
|
+
signed: boolean,
|
|
131
|
+
trimZeros = false
|
|
106
132
|
): { sign: '+' | '-' | ''; body: string } {
|
|
107
133
|
const reduced = value.round(
|
|
108
134
|
decimals,
|
|
109
135
|
rounding === 'floor' ? Big.roundDown : Big.roundHalfUp
|
|
110
136
|
)
|
|
111
137
|
const sign = reduced.lt(0) ? '-' : signed && reduced.gt(0) ? '+' : ''
|
|
112
|
-
const [integerPart = '0',
|
|
138
|
+
const [integerPart = '0', paddedFraction] = reduced
|
|
113
139
|
.abs()
|
|
114
140
|
.toFixed(decimals)
|
|
115
141
|
.split('.')
|
|
142
|
+
const fractionPart = trimZeros
|
|
143
|
+
? paddedFraction?.replace(/0+$/, '') || undefined
|
|
144
|
+
: paddedFraction
|
|
116
145
|
const integerBody = grouping
|
|
117
146
|
? BigInt(integerPart).toLocaleString(locale)
|
|
118
147
|
: integerPart
|
|
@@ -154,13 +183,14 @@ function autoDecimals(abs: Big): number {
|
|
|
154
183
|
*/
|
|
155
184
|
export function formatNumber(
|
|
156
185
|
value: FormatInput,
|
|
157
|
-
options:
|
|
186
|
+
options: NumberFormatOptions = {}
|
|
158
187
|
): string {
|
|
159
188
|
const {
|
|
160
189
|
decimals = 2,
|
|
161
190
|
placeholder = DEFAULT_PLACEHOLDER,
|
|
162
191
|
locale,
|
|
163
192
|
rounding = 'halfUp',
|
|
193
|
+
trimZeros,
|
|
164
194
|
} = options
|
|
165
195
|
const n = toBig(value)
|
|
166
196
|
if (n === null) {
|
|
@@ -169,7 +199,15 @@ export function formatNumber(
|
|
|
169
199
|
if (typeof n === 'string') {
|
|
170
200
|
return n
|
|
171
201
|
}
|
|
172
|
-
const { sign, body } = signAndBody(
|
|
202
|
+
const { sign, body } = signAndBody(
|
|
203
|
+
n,
|
|
204
|
+
decimals,
|
|
205
|
+
locale,
|
|
206
|
+
true,
|
|
207
|
+
rounding,
|
|
208
|
+
false,
|
|
209
|
+
trimZeros
|
|
210
|
+
)
|
|
173
211
|
return `${sign}${body}`
|
|
174
212
|
}
|
|
175
213
|
|
|
@@ -348,20 +386,11 @@ function compactMantissa(
|
|
|
348
386
|
: roundToSignificantDigits(scaled, significantDigits, rounding)
|
|
349
387
|
}
|
|
350
388
|
|
|
351
|
-
/**
|
|
352
|
-
|
|
353
|
-
* `$789.0K`, `$12.34`.
|
|
354
|
-
*
|
|
355
|
-
* Values below 1000 (or `compactFrom`) render as {@link formatUsd}. Negatives
|
|
356
|
-
* place the `-` before the `$`. `rounding: 'floor'` truncates toward zero, so
|
|
357
|
-
* a compact balance is never overstated. Null/undefined/non-finite input
|
|
358
|
-
* renders the placeholder.
|
|
359
|
-
*
|
|
360
|
-
* @public
|
|
361
|
-
*/
|
|
362
|
-
export function formatCompactUsd(
|
|
389
|
+
/** The compact core: `plain` renders the value below the tiers and each mantissa. */
|
|
390
|
+
function formatCompact(
|
|
363
391
|
value: FormatInput,
|
|
364
|
-
options:
|
|
392
|
+
options: CompactNumberOptions,
|
|
393
|
+
plain: typeof formatNumber
|
|
365
394
|
): string {
|
|
366
395
|
const {
|
|
367
396
|
decimals = 2,
|
|
@@ -370,6 +399,7 @@ export function formatCompactUsd(
|
|
|
370
399
|
rounding = 'halfUp',
|
|
371
400
|
significantDigits,
|
|
372
401
|
compactFrom,
|
|
402
|
+
trimZeros,
|
|
373
403
|
} = options
|
|
374
404
|
const n = toBig(value)
|
|
375
405
|
if (n === null) {
|
|
@@ -384,7 +414,7 @@ export function formatCompactUsd(
|
|
|
384
414
|
compareDecimalStrings(abs, numberToDecimalString(COMPACT_TIER_SIZE)) < 0 ||
|
|
385
415
|
(compactFrom !== undefined && compareDecimalStrings(abs, compactFrom) < 0)
|
|
386
416
|
) {
|
|
387
|
-
return
|
|
417
|
+
return plain(value, options)
|
|
388
418
|
}
|
|
389
419
|
const decimalRounding = COMPACT_DECIMAL_ROUNDING[rounding]
|
|
390
420
|
const render = (mantissa: string, suffix: string): string => {
|
|
@@ -392,7 +422,7 @@ export function formatCompactUsd(
|
|
|
392
422
|
significantDigits === undefined
|
|
393
423
|
? decimals
|
|
394
424
|
: (mantissa.split('.')[1]?.length ?? 0)
|
|
395
|
-
return `${
|
|
425
|
+
return `${plain(mantissa, { locale, decimals: mantissaDecimals, trimZeros })}${suffix}`
|
|
396
426
|
}
|
|
397
427
|
// The tier is picked after rounding, so 999,999.99 promotes to M, not 1000K.
|
|
398
428
|
for (const [divisor, suffix] of COMPACT_TIERS) {
|
|
@@ -423,3 +453,38 @@ export function formatCompactUsd(
|
|
|
423
453
|
'B'
|
|
424
454
|
)
|
|
425
455
|
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Format a number compactly with a `B`/`M`/`K` suffix and no currency symbol:
|
|
459
|
+
* `1.23B`, `45.60M`, `789.00K`, `12.34`.
|
|
460
|
+
*
|
|
461
|
+
* Values below 1000 (or `compactFrom`) render as {@link formatNumber}.
|
|
462
|
+
* `rounding: 'floor'` truncates toward zero, so a compact balance is never
|
|
463
|
+
* overstated. Null/undefined/non-finite input renders the placeholder.
|
|
464
|
+
*
|
|
465
|
+
* @public
|
|
466
|
+
*/
|
|
467
|
+
export function formatCompactNumber(
|
|
468
|
+
value: FormatInput,
|
|
469
|
+
options: CompactNumberOptions = {}
|
|
470
|
+
): string {
|
|
471
|
+
return formatCompact(value, options, formatNumber)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Format a USD value compactly with a `B`/`M`/`K` suffix: `$1.23B`, `$45.6M`,
|
|
476
|
+
* `$789.0K`, `$12.34`.
|
|
477
|
+
*
|
|
478
|
+
* Values below 1000 (or `compactFrom`) render as {@link formatUsd}. Negatives
|
|
479
|
+
* place the `-` before the `$`. `rounding: 'floor'` truncates toward zero, so
|
|
480
|
+
* a compact balance is never overstated. Null/undefined/non-finite input
|
|
481
|
+
* renders the placeholder.
|
|
482
|
+
*
|
|
483
|
+
* @public
|
|
484
|
+
*/
|
|
485
|
+
export function formatCompactUsd(
|
|
486
|
+
value: FormatInput,
|
|
487
|
+
options: CompactUsdOptions = {}
|
|
488
|
+
): string {
|
|
489
|
+
return formatCompact(value, options, formatUsd)
|
|
490
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -57,11 +57,14 @@ export {
|
|
|
57
57
|
scaledIntegerToDecimalString,
|
|
58
58
|
} from './decimal/convert.js'
|
|
59
59
|
export type {
|
|
60
|
+
CompactNumberOptions,
|
|
60
61
|
CompactUsdOptions,
|
|
61
62
|
FormatOptions,
|
|
63
|
+
NumberFormatOptions,
|
|
62
64
|
RoundingMode,
|
|
63
65
|
} from './decimal/format.js'
|
|
64
66
|
export {
|
|
67
|
+
formatCompactNumber,
|
|
65
68
|
formatCompactUsd,
|
|
66
69
|
formatNumber,
|
|
67
70
|
formatPrice,
|
|
@@ -268,6 +271,7 @@ export type {
|
|
|
268
271
|
ExecuteMetaActionParams,
|
|
269
272
|
GetAccountResult,
|
|
270
273
|
GetDepositFlowParams,
|
|
274
|
+
GetDepositStatusParams,
|
|
271
275
|
GetMarginHealthParams,
|
|
272
276
|
GetPortfolioHistoryParams,
|
|
273
277
|
GetSetupParams,
|
|
@@ -311,6 +315,7 @@ export type {
|
|
|
311
315
|
ProviderGetActivityParams,
|
|
312
316
|
ProviderGetAvailableToTradeParams,
|
|
313
317
|
ProviderGetDepositFlowParams,
|
|
318
|
+
ProviderGetDepositStatusParams,
|
|
314
319
|
ProviderGetFillsParams,
|
|
315
320
|
ProviderGetMarginHealthParams,
|
|
316
321
|
ProviderGetMarketSettingsParams,
|
package/src/types/api.ts
CHANGED
|
@@ -143,9 +143,10 @@ export interface PlaceOrderParams {
|
|
|
143
143
|
/** Optional leverage multiplier; provider defaults apply when omitted. */
|
|
144
144
|
leverage?: number
|
|
145
145
|
/**
|
|
146
|
-
* Margin mode the
|
|
147
|
-
*
|
|
148
|
-
* applies it
|
|
146
|
+
* Margin mode of the prepended leverage update. No venue order carries one.
|
|
147
|
+
* Hyperliquid requires `leverage` and sends an omitted mode as isolated.
|
|
148
|
+
* Lighter applies it only with `leverage` or `initialMarginFractionBps`,
|
|
149
|
+
* and sends an omitted mode as cross. Ondo rejects isolated.
|
|
149
150
|
*/
|
|
150
151
|
marginMode?: MarginMode
|
|
151
152
|
/** Whether the order may only reduce an existing position. */
|
|
@@ -274,6 +275,20 @@ export interface GetDepositFlowParams {
|
|
|
274
275
|
address: Address
|
|
275
276
|
}
|
|
276
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Parameters for {@link PerpsClient.getDepositStatus}.
|
|
280
|
+
*
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
export interface GetDepositStatusParams {
|
|
284
|
+
provider: string
|
|
285
|
+
address: Address
|
|
286
|
+
/** Chain of the source-chain transaction `txHash`. */
|
|
287
|
+
chainId: number
|
|
288
|
+
/** Source-chain transaction that funded the deposit. */
|
|
289
|
+
txHash: string
|
|
290
|
+
}
|
|
291
|
+
|
|
277
292
|
/**
|
|
278
293
|
* Parameters for {@link PerpsClient.getMarginHealth}.
|
|
279
294
|
*
|
package/src/types/provider.ts
CHANGED
|
@@ -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
|
*
|
|
@@ -480,6 +494,17 @@ export interface PerpsProviderPlugin {
|
|
|
480
494
|
options?: SDKRequestOptions
|
|
481
495
|
): Promise<DepositFlow>
|
|
482
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
|
+
|
|
483
508
|
/**
|
|
484
509
|
* The withdrawal flow this venue offers `params.address`, resolved from the
|
|
485
510
|
* venue's own account and setup state — the destination a withdrawal goes
|
package/src/version.ts
CHANGED