@lifi/perps-sdk-provider-lighter 40.1.0 → 41.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/README.md +14 -1
- package/dist/cjs/LighterProvider.d.ts.map +1 -1
- package/dist/cjs/LighterProvider.js +6 -2
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/signers/LighterSigner.d.ts.map +1 -1
- package/dist/cjs/signers/LighterSigner.js +1 -20
- package/dist/cjs/signers/LighterSigner.js.map +1 -1
- package/dist/cjs/types/action.d.ts +14 -0
- package/dist/cjs/types/action.d.ts.map +1 -1
- package/dist/cjs/types/action.js +33 -1
- package/dist/cjs/types/action.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +2 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
- package/dist/cjs/utils/mapOrder.js +1 -4
- package/dist/cjs/utils/mapOrder.js.map +1 -1
- package/dist/cjs/utils/orderFormatting.d.ts +6 -0
- package/dist/cjs/utils/orderFormatting.d.ts.map +1 -1
- package/dist/cjs/utils/orderFormatting.js +7 -0
- package/dist/cjs/utils/orderFormatting.js.map +1 -1
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +8 -3
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/signers/LighterSigner.d.ts.map +1 -1
- package/dist/esm/signers/LighterSigner.js +2 -22
- package/dist/esm/signers/LighterSigner.js.map +1 -1
- package/dist/esm/types/action.d.ts +67 -0
- package/dist/esm/types/action.d.ts.map +1 -1
- package/dist/esm/types/action.js +86 -3
- package/dist/esm/types/action.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/mapOrder.d.ts.map +1 -1
- package/dist/esm/utils/mapOrder.js +2 -4
- package/dist/esm/utils/mapOrder.js.map +1 -1
- package/dist/esm/utils/orderFormatting.d.ts +13 -0
- package/dist/esm/utils/orderFormatting.d.ts.map +1 -1
- package/dist/esm/utils/orderFormatting.js +13 -0
- package/dist/esm/utils/orderFormatting.js.map +1 -1
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/signers/LighterSigner.d.ts.map +1 -1
- package/dist/types/types/action.d.ts +67 -0
- package/dist/types/types/action.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/mapOrder.d.ts.map +1 -1
- package/dist/types/utils/orderFormatting.d.ts +13 -0
- package/dist/types/utils/orderFormatting.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/LighterProvider.ts +23 -8
- package/src/signers/LighterSigner.ts +6 -23
- package/src/types/action.ts +91 -0
- package/src/utils/index.ts +5 -1
- package/src/utils/mapOrder.ts +2 -4
- package/src/utils/orderFormatting.ts +14 -0
package/src/types/action.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ActionType } from '@lifi/perps-types'
|
|
2
|
+
|
|
1
3
|
// Shapes of `wasmSignParams` per action. The backend populates these and the
|
|
2
4
|
// SDK passes them to the WASM signer alongside SDK-managed fields (nonce,
|
|
3
5
|
// account_index, api_key_index).
|
|
@@ -252,3 +254,92 @@ export const LT_NIL_TRIGGER_PRICE = 0
|
|
|
252
254
|
* @public
|
|
253
255
|
*/
|
|
254
256
|
export const LT_DEFAULT_ORDER_EXPIRY = -1
|
|
257
|
+
|
|
258
|
+
// Tx type values from lighter-go `types/txtypes/constants.go`.
|
|
259
|
+
/**
|
|
260
|
+
* Lighter tx type `TxTypeL2ChangePubKey`.
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
export const LT_TX_TYPE_CHANGE_PUB_KEY = 8
|
|
264
|
+
/**
|
|
265
|
+
* Lighter tx type `TxTypeL2Transfer`.
|
|
266
|
+
* @public
|
|
267
|
+
*/
|
|
268
|
+
export const LT_TX_TYPE_TRANSFER = 12
|
|
269
|
+
/**
|
|
270
|
+
* Lighter tx type `TxTypeL2Withdraw`.
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
export const LT_TX_TYPE_WITHDRAW = 13
|
|
274
|
+
/**
|
|
275
|
+
* Lighter tx type `TxTypeL2CreateOrder`.
|
|
276
|
+
* @public
|
|
277
|
+
*/
|
|
278
|
+
export const LT_TX_TYPE_CREATE_ORDER = 14
|
|
279
|
+
/**
|
|
280
|
+
* Lighter tx type `TxTypeL2CancelOrder`.
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
export const LT_TX_TYPE_CANCEL_ORDER = 15
|
|
284
|
+
/**
|
|
285
|
+
* Lighter tx type `TxTypeL2CancelAllOrders`.
|
|
286
|
+
* @public
|
|
287
|
+
*/
|
|
288
|
+
export const LT_TX_TYPE_CANCEL_ALL_ORDERS = 16
|
|
289
|
+
/**
|
|
290
|
+
* Lighter tx type `TxTypeL2ModifyOrder`.
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
export const LT_TX_TYPE_MODIFY_ORDER = 17
|
|
294
|
+
/**
|
|
295
|
+
* Lighter tx type `TxTypeL2UpdateLeverage`.
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
export const LT_TX_TYPE_UPDATE_LEVERAGE = 20
|
|
299
|
+
/**
|
|
300
|
+
* Lighter tx type `TxTypeL2UpdateMargin`.
|
|
301
|
+
* @public
|
|
302
|
+
*/
|
|
303
|
+
export const LT_TX_TYPE_UPDATE_MARGIN = 29
|
|
304
|
+
/**
|
|
305
|
+
* Lighter tx type `TxTypeL2UpdateAccountConfig`.
|
|
306
|
+
* @public
|
|
307
|
+
*/
|
|
308
|
+
export const LT_TX_TYPE_UPDATE_ACCOUNT_CONFIG = 41
|
|
309
|
+
/**
|
|
310
|
+
* Lighter tx type `TxTypeL2UpdateAccountAssetConfig`.
|
|
311
|
+
* @public
|
|
312
|
+
*/
|
|
313
|
+
export const LT_TX_TYPE_UPDATE_ACCOUNT_ASSET_CONFIG = 42
|
|
314
|
+
/**
|
|
315
|
+
* Lighter tx type `TxTypeL2ApproveIntegrator`.
|
|
316
|
+
* @public
|
|
317
|
+
*/
|
|
318
|
+
export const LT_TX_TYPE_APPROVE_INTEGRATOR = 45
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Lighter tx type of the signed tx the SDK's WASM signer emits for each
|
|
322
|
+
* action. An action without an entry has no Lighter signing path.
|
|
323
|
+
* @public
|
|
324
|
+
*/
|
|
325
|
+
export const LT_TX_TYPE_BY_ACTION: Readonly<
|
|
326
|
+
Partial<Record<ActionType, number>>
|
|
327
|
+
> = Object.freeze({
|
|
328
|
+
[ActionType.REGISTER_API_KEY]: LT_TX_TYPE_CHANGE_PUB_KEY,
|
|
329
|
+
[ActionType.TRANSFER]: LT_TX_TYPE_TRANSFER,
|
|
330
|
+
[ActionType.SEND_ASSET]: LT_TX_TYPE_TRANSFER,
|
|
331
|
+
[ActionType.WITHDRAWAL]: LT_TX_TYPE_WITHDRAW,
|
|
332
|
+
[ActionType.PLACE_ORDER]: LT_TX_TYPE_CREATE_ORDER,
|
|
333
|
+
[ActionType.PLACE_TRIGGER_ORDER]: LT_TX_TYPE_CREATE_ORDER,
|
|
334
|
+
[ActionType.PLACE_TWAP_ORDER]: LT_TX_TYPE_CREATE_ORDER,
|
|
335
|
+
[ActionType.CANCEL_ORDER]: LT_TX_TYPE_CANCEL_ORDER,
|
|
336
|
+
[ActionType.CANCEL_TWAP_ORDER]: LT_TX_TYPE_CANCEL_ORDER,
|
|
337
|
+
[ActionType.CANCEL_ALL_ORDERS]: LT_TX_TYPE_CANCEL_ALL_ORDERS,
|
|
338
|
+
[ActionType.MODIFY_ORDER]: LT_TX_TYPE_MODIFY_ORDER,
|
|
339
|
+
[ActionType.UPDATE_LEVERAGE]: LT_TX_TYPE_UPDATE_LEVERAGE,
|
|
340
|
+
[ActionType.UPDATE_POSITION_MARGIN]: LT_TX_TYPE_UPDATE_MARGIN,
|
|
341
|
+
[ActionType.ACCOUNT_MODE]: LT_TX_TYPE_UPDATE_ACCOUNT_CONFIG,
|
|
342
|
+
[ActionType.UPDATE_ASSET_COLLATERAL]: LT_TX_TYPE_UPDATE_ACCOUNT_ASSET_CONFIG,
|
|
343
|
+
[ActionType.APPROVE_INTEGRATOR]: LT_TX_TYPE_APPROVE_INTEGRATOR,
|
|
344
|
+
[ActionType.REVOKE_INTEGRATOR]: LT_TX_TYPE_APPROVE_INTEGRATOR,
|
|
345
|
+
})
|
package/src/utils/index.ts
CHANGED
|
@@ -19,7 +19,11 @@ export { mapPortfolioHistory } from './mapPortfolioHistory.js'
|
|
|
19
19
|
export { leverageFromImf, mapPosition } from './mapPosition.js'
|
|
20
20
|
export { mapMarketOrderLimits } from './marketLimits.js'
|
|
21
21
|
export { mapInterval } from './ohlcvInterval.js'
|
|
22
|
-
export {
|
|
22
|
+
export {
|
|
23
|
+
LIGHTER_MARKET_SLIPPAGE_PERCENT,
|
|
24
|
+
snapOrderPrice,
|
|
25
|
+
snapOrderSize,
|
|
26
|
+
} from './orderFormatting.js'
|
|
23
27
|
export { toIsoFromMs, toIsoFromSeconds } from './time.js'
|
|
24
28
|
export { positionRemovableMargin } from './transferMargin.js'
|
|
25
29
|
export {
|
package/src/utils/mapOrder.ts
CHANGED
|
@@ -174,15 +174,13 @@ export const mapOrder = (
|
|
|
174
174
|
case OrderType.STOP_LIMIT:
|
|
175
175
|
case OrderType.TAKE_PROFIT_MARKET:
|
|
176
176
|
case OrderType.TAKE_PROFIT_LIMIT: {
|
|
177
|
+
// A market trigger's `price` is its slippage-adjusted limit price.
|
|
177
178
|
return {
|
|
178
179
|
...base,
|
|
179
180
|
type,
|
|
180
181
|
triggerPrice: order.trigger_price,
|
|
181
182
|
triggerCondition: triggerConditionFor(type, base.side),
|
|
182
|
-
|
|
183
|
-
type === OrderType.TAKE_PROFIT_LIMIT
|
|
184
|
-
? { limitPrice: order.price }
|
|
185
|
-
: {}),
|
|
183
|
+
limitPrice: order.price,
|
|
186
184
|
}
|
|
187
185
|
}
|
|
188
186
|
case OrderType.MARKET:
|
|
@@ -15,6 +15,20 @@ import {
|
|
|
15
15
|
} from '@lifi/perps-types'
|
|
16
16
|
import Big from 'big.js'
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Range of the Lighter market TP/SL slippage input, as decimal string
|
|
20
|
+
* percents (`'1'` is 1%). The minimum is above Lighter's own `0`, because a
|
|
21
|
+
* 0% bound can leave the trigger order unfilled and the position unprotected.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export const LIGHTER_MARKET_SLIPPAGE_PERCENT = {
|
|
26
|
+
min: '1',
|
|
27
|
+
max: '10',
|
|
28
|
+
step: '0.01',
|
|
29
|
+
default: '1',
|
|
30
|
+
} as const
|
|
31
|
+
|
|
18
32
|
/**
|
|
19
33
|
* Snap a price onto a Lighter market's tick grid: rounded half-up to the
|
|
20
34
|
* market's `priceDecimals` (Lighter's `supported_price_decimals`), trailing
|