@lifi/perps-sdk-provider-lighter 32.0.0 → 34.0.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/dist/cjs/LighterProvider.d.ts.map +1 -1
- package/dist/cjs/LighterProvider.js +20 -45
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/utils/liquidation.js.map +1 -1
- package/dist/cjs/utils/mapFill.js +1 -1
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/mapOrder.js +1 -1
- package/dist/cjs/utils/mapOrder.js.map +1 -1
- package/dist/cjs/utils/transferMargin.d.ts +2 -2
- package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
- package/dist/cjs/utils/transferMargin.js +2 -2
- package/dist/cjs/utils/transferMargin.js.map +1 -1
- package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/LighterWsProvider.js +6 -8
- package/dist/cjs/websocket/LighterWsProvider.js.map +1 -1
- package/dist/esm/LighterProvider.d.ts +21 -6
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +23 -47
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/utils/liquidation.js +2 -2
- package/dist/esm/utils/liquidation.js.map +1 -1
- package/dist/esm/utils/mapFill.js +1 -1
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapOrder.js +1 -1
- package/dist/esm/utils/mapOrder.js.map +1 -1
- package/dist/esm/utils/transferMargin.d.ts +2 -2
- package/dist/esm/utils/transferMargin.d.ts.map +1 -1
- package/dist/esm/utils/transferMargin.js +2 -2
- package/dist/esm/utils/transferMargin.js.map +1 -1
- package/dist/esm/websocket/LighterWsProvider.d.ts +3 -2
- package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/LighterWsProvider.js +11 -13
- package/dist/esm/websocket/LighterWsProvider.js.map +1 -1
- package/dist/types/LighterProvider.d.ts +21 -6
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/utils/transferMargin.d.ts +2 -2
- package/dist/types/utils/transferMargin.d.ts.map +1 -1
- package/dist/types/websocket/LighterWsProvider.d.ts +3 -2
- package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/LighterProvider.ts +58 -55
- package/src/utils/liquidation.ts +2 -2
- package/src/utils/mapFill.ts +1 -1
- package/src/utils/mapOrder.ts +1 -1
- package/src/utils/transferMargin.ts +7 -4
- package/src/websocket/LighterWsProvider.ts +11 -14
package/src/utils/liquidation.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
-
estimateLiquidationPrice as
|
|
11
|
+
estimateLiquidationPrice as estimateLiquidationPriceAtRate,
|
|
12
12
|
type LiquidationEstimateParams,
|
|
13
13
|
} from '@lifi/perps-sdk'
|
|
14
14
|
import type { PerpsMarket } from '@lifi/perps-types'
|
|
@@ -30,7 +30,7 @@ export function estimateLiquidationPrice(
|
|
|
30
30
|
if (market.maintenanceMarginRate === undefined) {
|
|
31
31
|
return undefined
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return estimateLiquidationPriceAtRate({
|
|
34
34
|
entryPrice: params.entryPrice,
|
|
35
35
|
leverage: params.leverage,
|
|
36
36
|
isLong: params.isLong,
|
package/src/utils/mapFill.ts
CHANGED
package/src/utils/mapOrder.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { PerpsError } from '@lifi/perps-sdk'
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
type Position,
|
|
2
|
+
PerpsError,
|
|
5
3
|
positionSupportsMarginAdjustment,
|
|
6
4
|
positionSupportsMarginRemoval,
|
|
5
|
+
} from '@lifi/perps-sdk'
|
|
6
|
+
import {
|
|
7
|
+
type DecimalString,
|
|
8
|
+
PerpsErrorCode,
|
|
9
|
+
type Position,
|
|
7
10
|
} from '@lifi/perps-types'
|
|
8
11
|
import Big from 'big.js'
|
|
9
12
|
|
|
@@ -47,7 +50,7 @@ function positivePositionAmount(value: string, field: string): Big {
|
|
|
47
50
|
*/
|
|
48
51
|
export function positionRemovableMargin(
|
|
49
52
|
position: Position
|
|
50
|
-
):
|
|
53
|
+
): DecimalString | undefined {
|
|
51
54
|
if (!positionSupportsMarginAdjustment(position)) {
|
|
52
55
|
return undefined
|
|
53
56
|
}
|
|
@@ -293,15 +293,6 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
293
293
|
|
|
294
294
|
const wireChannels = await this.resolveChannel(sub)
|
|
295
295
|
|
|
296
|
-
// Reject before any wire sub registers: a registered sub whose token can
|
|
297
|
-
// never be resolved is retried on every reopen without the caller ever
|
|
298
|
-
// seeing the failure.
|
|
299
|
-
for (const { channel, needsAuth, address } of wireChannels) {
|
|
300
|
-
if (needsAuth) {
|
|
301
|
-
await this.requireAuthToken(channel, address)
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
296
|
// Acquired before the wire subs register, so a rejected spot-mark open
|
|
306
297
|
// leaves no `user_stats`/`account_all` entry behind for the next replay.
|
|
307
298
|
const releaseSpotMarks =
|
|
@@ -392,8 +383,9 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
392
383
|
* The auth token a gated channel's subscribe frame carries, or a throw when
|
|
393
384
|
* no resolver is wired or the resolver yields none. Shared by the
|
|
394
385
|
* subscribe-time guard and the per-send resolve so both report one message.
|
|
395
|
-
* Throws {@link PerpsError}
|
|
396
|
-
*
|
|
386
|
+
* Throws {@link PerpsError}: `SetupRequired` when the resolver yields no
|
|
387
|
+
* token, the code the REST reads throw for the same missing credential, and
|
|
388
|
+
* `SDKError` when no resolver is wired, which no account setup can fix.
|
|
397
389
|
*/
|
|
398
390
|
private async requireAuthToken(
|
|
399
391
|
channel: string,
|
|
@@ -402,7 +394,7 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
402
394
|
const resolve = this.authTokenResolver()
|
|
403
395
|
if (!resolve || !address) {
|
|
404
396
|
throw new PerpsError(
|
|
405
|
-
PerpsErrorCode.
|
|
397
|
+
PerpsErrorCode.SDKError,
|
|
406
398
|
`Lighter WS channel '${channel}' requires authentication but no auth-token resolver was available. ` +
|
|
407
399
|
'Register `lighterProvider()` on the same client, or pass `resolveAuthToken` to `lighterWsProvider`.'
|
|
408
400
|
)
|
|
@@ -410,7 +402,7 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
410
402
|
const token = await resolve(address)
|
|
411
403
|
if (!token) {
|
|
412
404
|
throw new PerpsError(
|
|
413
|
-
PerpsErrorCode.
|
|
405
|
+
PerpsErrorCode.SetupRequired,
|
|
414
406
|
`Lighter WS channel '${channel}' requires authentication but no token was available for ${address}.`
|
|
415
407
|
)
|
|
416
408
|
}
|
|
@@ -534,13 +526,18 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
534
526
|
sub.channel === 'fills' ||
|
|
535
527
|
sub.channel === 'positions'
|
|
536
528
|
) {
|
|
537
|
-
const accountIndex = await this.resolveAccountIndex(sub.address)
|
|
538
529
|
const lighterChannel = LIGHTER_AUTH_CHANNEL[sub.channel]
|
|
539
530
|
// `account_all_trades` is publicly readable per the Lighter WS spec —
|
|
540
531
|
// an auth token only filters events to the user's own account, which
|
|
541
532
|
// we don't currently use to scope further. Skip the token here so a
|
|
542
533
|
// user without a registered API key still gets their fill stream.
|
|
543
534
|
const needsAuth = sub.channel !== 'fills'
|
|
535
|
+
// Before the account lookup and before registration: a registered sub
|
|
536
|
+
// with no token would fail on every reopen without the caller seeing it.
|
|
537
|
+
if (needsAuth) {
|
|
538
|
+
await this.requireAuthToken(lighterChannel, sub.address)
|
|
539
|
+
}
|
|
540
|
+
const accountIndex = await this.resolveAccountIndex(sub.address)
|
|
544
541
|
return [
|
|
545
542
|
{
|
|
546
543
|
channel: `${lighterChannel}/${accountIndex}`,
|