@lifi/perps-sdk-provider-lighter 22.0.0 → 22.1.1
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 +20 -1
- package/dist/cjs/LighterProvider.d.ts.map +1 -1
- package/dist/cjs/LighterProvider.js +11 -6
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/accountConfig.js +3 -4
- package/dist/cjs/accountConfig.js.map +1 -1
- package/dist/cjs/constants.d.ts +2 -1
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +3 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/signers/generated/wasmExecRuntime.d.ts +4 -1
- package/dist/cjs/signers/generated/wasmExecRuntime.d.ts.map +1 -1
- package/dist/cjs/signers/generated/wasmExecRuntime.js +470 -566
- package/dist/cjs/signers/generated/wasmExecRuntime.js.map +1 -1
- package/dist/cjs/signers/wasmLoader.d.ts.map +1 -1
- package/dist/cjs/signers/wasmLoader.js +1 -3
- package/dist/cjs/signers/wasmLoader.js.map +1 -1
- package/dist/cjs/types/account.d.ts +3 -3
- package/dist/cjs/types/account.d.ts.map +1 -1
- package/dist/cjs/types/action.d.ts +2 -0
- package/dist/cjs/types/action.d.ts.map +1 -1
- package/dist/cjs/types/action.js +3 -1
- package/dist/cjs/types/action.js.map +1 -1
- package/dist/cjs/types/fill.d.ts +2 -2
- package/dist/cjs/types/fill.d.ts.map +1 -1
- package/dist/cjs/utils/apiClient.d.ts.map +1 -1
- package/dist/cjs/utils/apiClient.js +8 -3
- package/dist/cjs/utils/apiClient.js.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +2 -2
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/mapPosition.js +1 -1
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +16 -7
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/accountConfig.js +5 -7
- package/dist/esm/accountConfig.js.map +1 -1
- package/dist/esm/constants.d.ts +10 -1
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +10 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/signers/generated/wasmExecRuntime.d.ts +5 -7
- package/dist/esm/signers/generated/wasmExecRuntime.d.ts.map +1 -1
- package/dist/esm/signers/generated/wasmExecRuntime.js +507 -571
- package/dist/esm/signers/generated/wasmExecRuntime.js.map +1 -1
- package/dist/esm/signers/wasmLoader.d.ts.map +1 -1
- package/dist/esm/signers/wasmLoader.js +2 -11
- package/dist/esm/signers/wasmLoader.js.map +1 -1
- package/dist/esm/types/account.d.ts +15 -4
- package/dist/esm/types/account.d.ts.map +1 -1
- package/dist/esm/types/action.d.ts +13 -0
- package/dist/esm/types/action.d.ts.map +1 -1
- package/dist/esm/types/action.js +13 -0
- package/dist/esm/types/action.js.map +1 -1
- package/dist/esm/types/fill.d.ts +2 -2
- package/dist/esm/types/fill.d.ts.map +1 -1
- package/dist/esm/utils/apiClient.d.ts.map +1 -1
- package/dist/esm/utils/apiClient.js +9 -4
- package/dist/esm/utils/apiClient.js.map +1 -1
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +3 -2
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapPosition.js +1 -1
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/constants.d.ts +10 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/signers/generated/wasmExecRuntime.d.ts +5 -7
- package/dist/types/signers/generated/wasmExecRuntime.d.ts.map +1 -1
- package/dist/types/signers/wasmLoader.d.ts.map +1 -1
- package/dist/types/types/account.d.ts +15 -4
- package/dist/types/types/account.d.ts.map +1 -1
- package/dist/types/types/action.d.ts +13 -0
- package/dist/types/types/action.d.ts.map +1 -1
- package/dist/types/types/fill.d.ts +2 -2
- package/dist/types/types/fill.d.ts.map +1 -1
- package/dist/types/utils/apiClient.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/LighterProvider.ts +26 -7
- package/src/accountConfig.ts +8 -8
- package/src/constants.ts +11 -0
- package/src/signers/generated/wasmExecRuntime.ts +570 -572
- package/src/signers/wasmLoader.ts +2 -17
- package/src/types/account.ts +15 -4
- package/src/types/action.ts +15 -0
- package/src/types/fill.ts +3 -2
- package/src/utils/apiClient.ts +11 -4
- package/src/utils/mapFill.ts +5 -3
- package/src/utils/mapPosition.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../../src/types/fill.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,OAAO,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IAIjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAGlB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,gBAAgB,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"fill.d.ts","sourceRoot":"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|
|
1
|
-
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../../src/utils/apiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../../src/utils/apiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAA;AAUxB,gBAAgB;AAChB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;AAejE;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,UAAU;CAAG;AAE3D;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,UAAU;CAAG;AAsC3D,gBAAgB;AAChB,eAAO,MAAM,sBAAsB,EAAE,mBAgBpC,CAAA;AAsBD;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,gBAAgB;AAChB,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;IACxB,aAAa,CAAC,EAAE,oBAAoB,CAAA;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAc;gBAEhC,OAAO,EAA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EhD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,OAAO,EACd,cAAc,MAAM,EACpB,QAAQ,aAAa,KACpB,
|
|
1
|
+
{"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAY5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AA2EhD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,OAAO,EACd,cAAc,MAAM,EACpB,QAAQ,aAAa,KACpB,IAgEF,CAAA"}
|
package/package.json
CHANGED
package/src/LighterProvider.ts
CHANGED
|
@@ -106,7 +106,11 @@ import type {
|
|
|
106
106
|
LtWithdrawHistoryItem,
|
|
107
107
|
LtWithdrawHistoryResponse,
|
|
108
108
|
} from './types/index.js'
|
|
109
|
-
import {
|
|
109
|
+
import {
|
|
110
|
+
LT_ACCOUNT_TRADING_MODE_SIMPLE,
|
|
111
|
+
LT_MARGIN_MODE_CROSS,
|
|
112
|
+
LT_MARGIN_MODE_ISOLATED,
|
|
113
|
+
} from './types/index.js'
|
|
110
114
|
import {
|
|
111
115
|
decodeActivityCursor,
|
|
112
116
|
encodeActivityCursor,
|
|
@@ -265,6 +269,12 @@ interface CachedStandardToken {
|
|
|
265
269
|
token: string
|
|
266
270
|
/** Unix seconds — re-create when `Date.now()/1000 + renewBuffer >= expiresAt`. */
|
|
267
271
|
expiresAt: number
|
|
272
|
+
/**
|
|
273
|
+
* Slot and key material that signed `token`, as
|
|
274
|
+
* `apiKeyIndex:accountIndex:apiKeyPrivateKey`. `REGISTER_API_KEY` rotates the
|
|
275
|
+
* stored key, and Lighter rejects a token the superseded key signed.
|
|
276
|
+
*/
|
|
277
|
+
signingKey: string
|
|
268
278
|
}
|
|
269
279
|
|
|
270
280
|
/**
|
|
@@ -369,10 +379,12 @@ export const createLighterProvider = (
|
|
|
369
379
|
indices: { apiKeyIndex: number; accountIndex: number }
|
|
370
380
|
): Promise<string> => {
|
|
371
381
|
const cacheKey = address.toLowerCase()
|
|
382
|
+
const signingKey = `${indices.apiKeyIndex}:${indices.accountIndex}:${apiKeyPrivateKey}`
|
|
372
383
|
const nowSec = Math.floor(Date.now() / 1000)
|
|
373
384
|
const cached = standardTokenByAddress.get(cacheKey)
|
|
374
385
|
if (
|
|
375
386
|
cached !== undefined &&
|
|
387
|
+
cached.signingKey === signingKey &&
|
|
376
388
|
cached.expiresAt - nowSec > tokenRenewBufferSeconds
|
|
377
389
|
) {
|
|
378
390
|
return cached.token
|
|
@@ -387,7 +399,7 @@ export const createLighterProvider = (
|
|
|
387
399
|
lifetimeSeconds: tokenLifetimeSeconds,
|
|
388
400
|
})
|
|
389
401
|
const expiresAt = nowSec + tokenLifetimeSeconds
|
|
390
|
-
standardTokenByAddress.set(cacheKey, { token, expiresAt })
|
|
402
|
+
standardTokenByAddress.set(cacheKey, { token, expiresAt, signingKey })
|
|
391
403
|
return token
|
|
392
404
|
}
|
|
393
405
|
|
|
@@ -425,11 +437,17 @@ export const createLighterProvider = (
|
|
|
425
437
|
return undefined
|
|
426
438
|
}
|
|
427
439
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
440
|
+
// Sign with the key registered at call time, not the one read on entry:
|
|
441
|
+
// `REGISTER_API_KEY` can rotate the store while an await below is pending,
|
|
442
|
+
// and Lighter rejects a token the superseded key signed. The entry value
|
|
443
|
+
// stands in only when the record is gone, which no key can re-sign.
|
|
444
|
+
const standardToken = async (): Promise<string> => {
|
|
445
|
+
const current = (await keyStore.get(address)) ?? apiKey
|
|
446
|
+
return getStandardAuthToken(address, current.apiKeyPrivateKey, {
|
|
447
|
+
apiKeyIndex: current.apiKeyIndex,
|
|
448
|
+
accountIndex: current.accountIndex,
|
|
432
449
|
})
|
|
450
|
+
}
|
|
433
451
|
|
|
434
452
|
const stored = await readOnlyTokenManager.get(address, apiKey.accountIndex)
|
|
435
453
|
if (stored !== undefined) {
|
|
@@ -887,7 +905,8 @@ export const createLighterProvider = (
|
|
|
887
905
|
apiKeyRegistered,
|
|
888
906
|
accountType: account.account_type,
|
|
889
907
|
userTierName: limitsResult?.user_tier_name,
|
|
890
|
-
accountTradingMode:
|
|
908
|
+
accountTradingMode:
|
|
909
|
+
account.account_trading_mode ?? LT_ACCOUNT_TRADING_MODE_SIMPLE,
|
|
891
910
|
assetCollateral,
|
|
892
911
|
// Satisfied when a non-expired read-only token is stored locally
|
|
893
912
|
// (`readOnlyTokenManager.get` filters out expired ones).
|
package/src/accountConfig.ts
CHANGED
|
@@ -5,6 +5,10 @@ import type {
|
|
|
5
5
|
ProviderAction,
|
|
6
6
|
} from '@lifi/perps-types'
|
|
7
7
|
import { ActionType, PerpsErrorCode } from '@lifi/perps-types'
|
|
8
|
+
import {
|
|
9
|
+
LT_ACCOUNT_TRADING_MODE_SIMPLE,
|
|
10
|
+
LT_ACCOUNT_TRADING_MODE_UNIFIED,
|
|
11
|
+
} from './types/action.js'
|
|
8
12
|
|
|
9
13
|
function assertNever(value: never): never {
|
|
10
14
|
throw new Error(
|
|
@@ -27,15 +31,11 @@ const ACCOUNT_TYPE_INT_TO_WIRE: Readonly<Record<number, string>> = {
|
|
|
27
31
|
[LIGHTER_ACCOUNT_TYPE_PREMIUM]: 'premium',
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// the backend descriptor's ParamOption values. An unmapped int projects to null.
|
|
33
|
-
const LIGHTER_ACCOUNT_MODE_SIMPLE = 0
|
|
34
|
-
const LIGHTER_ACCOUNT_MODE_UNIFIED = 1
|
|
35
|
-
|
|
34
|
+
// Wire strings match the backend descriptor's ParamOption values. An unmapped
|
|
35
|
+
// int projects to null.
|
|
36
36
|
const ACCOUNT_MODE_INT_TO_WIRE: Readonly<Record<number, string>> = {
|
|
37
|
-
[
|
|
38
|
-
[
|
|
37
|
+
[LT_ACCOUNT_TRADING_MODE_SIMPLE]: 'simpleTradingAccount',
|
|
38
|
+
[LT_ACCOUNT_TRADING_MODE_UNIFIED]: 'unifiedTradingAccount',
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
package/src/constants.ts
CHANGED
|
@@ -248,6 +248,16 @@ const LIGHTER_INVALID_AUTH_CODE = 20013
|
|
|
248
248
|
*/
|
|
249
249
|
const LIGHTER_TOKEN_REVOKED_CODE = 61006
|
|
250
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Lighter body `code` for the internal-error envelope it answers when a token's
|
|
253
|
+
* signature does not verify — the message reads `invalid signature`. Only the
|
|
254
|
+
* auth-gated read path treats it as an auth failure; a public read keeps the
|
|
255
|
+
* venue-error classification.
|
|
256
|
+
*
|
|
257
|
+
* @internal
|
|
258
|
+
*/
|
|
259
|
+
const LIGHTER_INVALID_SIGNATURE_CODE = 29500
|
|
260
|
+
|
|
251
261
|
/**
|
|
252
262
|
* Lighter body `code` values that mean success. Lighter is inconsistent per
|
|
253
263
|
* endpoint: `/api/v1/account` returns `code: 200`, most others return `code: 0`.
|
|
@@ -279,6 +289,7 @@ const LIGHTER_REFERRAL_ALREADY_USED_CODE = 41003
|
|
|
279
289
|
export {
|
|
280
290
|
LIGHTER_CODE_ACCOUNT_NOT_FOUND,
|
|
281
291
|
LIGHTER_INVALID_AUTH_CODE,
|
|
292
|
+
LIGHTER_INVALID_SIGNATURE_CODE,
|
|
282
293
|
LIGHTER_MUTATION_SUCCESS_CODE,
|
|
283
294
|
LIGHTER_REFERRAL_ALREADY_USED_CODE,
|
|
284
295
|
LIGHTER_SUCCESS_CODES,
|