@lifi/perps-sdk-provider-lighter 42.0.0 → 43.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 +5 -1
- package/dist/cjs/LighterProvider.d.ts.map +1 -1
- package/dist/cjs/LighterProvider.js +5 -5
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/constants.d.ts +0 -1
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +1 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/ws.d.ts +2 -0
- package/dist/cjs/types/ws.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +2 -3
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/spotPrice.d.ts +1 -1
- package/dist/cjs/utils/spotPrice.d.ts.map +1 -1
- package/dist/cjs/utils/spotPrice.js +2 -2
- package/dist/cjs/utils/spotPrice.js.map +1 -1
- package/dist/cjs/utils/tradePrice.d.ts +3 -0
- package/dist/cjs/utils/tradePrice.d.ts.map +1 -0
- package/dist/cjs/utils/tradePrice.js +9 -0
- package/dist/cjs/utils/tradePrice.js.map +1 -0
- package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.js +2 -1
- package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
- package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/LighterWsProvider.js +4 -3
- package/dist/cjs/websocket/LighterWsProvider.js.map +1 -1
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +8 -8
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/constants.d.ts +0 -10
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +0 -10
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- 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/ws.d.ts +2 -0
- package/dist/esm/types/ws.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +3 -6
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/spotPrice.d.ts +1 -1
- package/dist/esm/utils/spotPrice.d.ts.map +1 -1
- package/dist/esm/utils/spotPrice.js +3 -3
- package/dist/esm/utils/spotPrice.js.map +1 -1
- package/dist/esm/utils/tradePrice.d.ts +11 -0
- package/dist/esm/utils/tradePrice.d.ts.map +1 -0
- package/dist/esm/utils/tradePrice.js +13 -0
- package/dist/esm/utils/tradePrice.js.map +1 -0
- package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/esm/utils/withdrawableBalances.js +3 -2
- package/dist/esm/utils/withdrawableBalances.js.map +1 -1
- package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/LighterWsProvider.js +6 -5
- package/dist/esm/websocket/LighterWsProvider.js.map +1 -1
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/constants.d.ts +0 -10
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/ws.d.ts +2 -0
- package/dist/types/types/ws.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/utils/spotPrice.d.ts +1 -1
- package/dist/types/utils/spotPrice.d.ts.map +1 -1
- package/dist/types/utils/tradePrice.d.ts +11 -0
- package/dist/types/utils/tradePrice.d.ts.map +1 -0
- package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/LighterProvider.ts +6 -6
- package/src/constants.ts +0 -11
- package/src/index.ts +0 -1
- package/src/types/ws.ts +2 -0
- package/src/utils/mapFill.ts +2 -7
- package/src/utils/spotPrice.ts +2 -2
- package/src/utils/tradePrice.ts +20 -0
- package/src/utils/withdrawableBalances.ts +3 -2
- package/src/websocket/LighterWsProvider.ts +6 -7
package/src/constants.ts
CHANGED
|
@@ -16,17 +16,6 @@ export const LIGHTER_PROVIDER_KEY = 'lighter'
|
|
|
16
16
|
*/
|
|
17
17
|
export const LIGHTER_RH_PROVIDER_KEY = 'lighter-rh'
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Category id for Lighter spot token holdings, matching the backend's Lighter
|
|
21
|
-
* spot asset category. Every Lighter call site, REST and WebSocket, uses this
|
|
22
|
-
* constant for the spot category. The perps category id is not a constant:
|
|
23
|
-
* `LighterProvider.getAccount` reads it from the `/providers` category whose
|
|
24
|
-
* `quoteAsset` is not null.
|
|
25
|
-
*
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export const LIGHTER_SPOT_CATEGORY_ID = 'spot'
|
|
29
|
-
|
|
30
19
|
/**
|
|
31
20
|
* Default mainnet REST and WS base URL for Lighter.
|
|
32
21
|
*
|
package/src/index.ts
CHANGED
package/src/types/ws.ts
CHANGED
package/src/utils/mapFill.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
isDecimalStringZero,
|
|
11
11
|
safeAddDecimalString,
|
|
12
12
|
safeDivideDecimalString,
|
|
13
|
-
safeIsDecimalStringZero,
|
|
14
13
|
safeMultiplyDecimalString,
|
|
15
14
|
warnSkippedVenueRow,
|
|
16
15
|
} from '@lifi/perps-sdk'
|
|
@@ -20,6 +19,7 @@ import { LIGHTER_FEE_TICK_SCALE, LIGHTER_PROVIDER_KEY } from '../constants.js'
|
|
|
20
19
|
import type { LtTrade } from '../types/index.js'
|
|
21
20
|
import { leverageFromScaledImf } from './mapPosition.js'
|
|
22
21
|
import { rowTimestampToIsoStringOrUndefined } from './rowTimestamp.js'
|
|
22
|
+
import { resolveTradePrice } from './tradePrice.js'
|
|
23
23
|
import { isPlaceholderTxHash } from './txHash.js'
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -144,12 +144,7 @@ export const mapFill = (
|
|
|
144
144
|
market: MarketDisplay
|
|
145
145
|
): Fill | undefined => {
|
|
146
146
|
const { size } = trade
|
|
147
|
-
|
|
148
|
-
// still carries the execution notional.
|
|
149
|
-
const price =
|
|
150
|
-
trade.type === 'deleverage' && safeIsDecimalStringZero(trade.price) === true
|
|
151
|
-
? (safeDivideDecimalString(trade.usd_amount, size) ?? trade.price)
|
|
152
|
-
: trade.price
|
|
147
|
+
const price = resolveTradePrice(trade)
|
|
153
148
|
const createdAt = rowTimestampToIsoStringOrUndefined(trade.timestamp)
|
|
154
149
|
if (createdAt === undefined) {
|
|
155
150
|
warnSkippedVenueRow(
|
package/src/utils/spotPrice.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isDecimalStringGreaterThan,
|
|
3
|
+
isSpotCategory,
|
|
3
4
|
multiplyDecimalString,
|
|
4
5
|
unknownToDecimalString,
|
|
5
6
|
} from '@lifi/perps-sdk'
|
|
@@ -18,7 +19,6 @@ import { LIGHTER_PROVIDER_KEY } from '../constants.js'
|
|
|
18
19
|
*/
|
|
19
20
|
export const spotPriceByAssetId = (
|
|
20
21
|
markets: readonly Market[],
|
|
21
|
-
spotCategoryId: string,
|
|
22
22
|
contexts: readonly MarketContext[],
|
|
23
23
|
assetIds: ReadonlySet<string>
|
|
24
24
|
): Map<string, string> => {
|
|
@@ -27,7 +27,7 @@ export const spotPriceByAssetId = (
|
|
|
27
27
|
for (const market of markets) {
|
|
28
28
|
const mark = markByMarketId.get(market.id)
|
|
29
29
|
if (
|
|
30
|
-
market.categoryId
|
|
30
|
+
!isSpotCategory(market.categoryId) ||
|
|
31
31
|
mark === undefined ||
|
|
32
32
|
!assetIds.has(market.baseAsset.id) ||
|
|
33
33
|
priceByAssetId.has(market.baseAsset.id)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
safeDivideDecimalString,
|
|
3
|
+
safeIsDecimalStringZero,
|
|
4
|
+
} from '@lifi/perps-sdk'
|
|
5
|
+
import type { LtTrade } from '../types/index.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Execution price of a Lighter trade row. Lighter reports a zero `price` on a
|
|
9
|
+
* `deleverage` row, but `usd_amount` still carries the execution notional, so
|
|
10
|
+
* that row resolves to `usd_amount / size`. Every other row, and a row whose
|
|
11
|
+
* division fails, keeps the venue `price`.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export const resolveTradePrice = (
|
|
16
|
+
trade: Pick<LtTrade, 'type' | 'price' | 'size' | 'usd_amount'>
|
|
17
|
+
): string =>
|
|
18
|
+
trade.type === 'deleverage' && safeIsDecimalStringZero(trade.price) === true
|
|
19
|
+
? (safeDivideDecimalString(trade.usd_amount, trade.size) ?? trade.price)
|
|
20
|
+
: trade.price
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
subtractDecimalString,
|
|
7
7
|
unknownToDecimalString,
|
|
8
8
|
} from '@lifi/perps-sdk'
|
|
9
|
-
import {
|
|
9
|
+
import { SPOT_CATEGORY_ID } from '@lifi/perps-types'
|
|
10
|
+
import { LIGHTER_PROVIDER_KEY } from '../constants.js'
|
|
10
11
|
import type { LtAccount } from '../types/account.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -45,7 +46,7 @@ export const lighterWithdrawableBalances = (
|
|
|
45
46
|
if (isDecimalStringGreaterThan(spot, '0')) {
|
|
46
47
|
rows.push({
|
|
47
48
|
assetId,
|
|
48
|
-
categoryId:
|
|
49
|
+
categoryId: SPOT_CATEGORY_ID,
|
|
49
50
|
available: spot,
|
|
50
51
|
max: calculateWithdrawMax({ available: spot }),
|
|
51
52
|
})
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createSafeFunction,
|
|
5
5
|
getMarketRegistry,
|
|
6
6
|
isDecimalStringGreaterThan,
|
|
7
|
+
isSpotCategory,
|
|
7
8
|
type MarketRegistry,
|
|
8
9
|
numberToDecimalString,
|
|
9
10
|
PerpsError,
|
|
@@ -41,7 +42,6 @@ import {
|
|
|
41
42
|
LIGHTER_COLLATERAL_ASSETS,
|
|
42
43
|
LIGHTER_PROVIDER_KEY,
|
|
43
44
|
LIGHTER_RH_PROVIDER_KEY,
|
|
44
|
-
LIGHTER_SPOT_CATEGORY_ID,
|
|
45
45
|
} from '../constants.js'
|
|
46
46
|
import type { LighterPerpsProvider } from '../LighterProvider.js'
|
|
47
47
|
import type {
|
|
@@ -73,6 +73,7 @@ import {
|
|
|
73
73
|
mapPosition,
|
|
74
74
|
} from '../utils/index.js'
|
|
75
75
|
import { spotPriceByAssetId, spotValuation } from '../utils/spotPrice.js'
|
|
76
|
+
import { resolveTradePrice } from '../utils/tradePrice.js'
|
|
76
77
|
import { askOrder, bidOrder, OrderBookSide } from './orderBookSide.js'
|
|
77
78
|
|
|
78
79
|
// Public channels: `marketsContext` (market_stats/all + spot_market_stats/all),
|
|
@@ -207,7 +208,6 @@ const heldPortfolioValue = (
|
|
|
207
208
|
.filter(([, balance]) => isDecimalStringGreaterThan(balance, '0'))
|
|
208
209
|
const spotPrices = spotPriceByAssetId(
|
|
209
210
|
markets,
|
|
210
|
-
LIGHTER_SPOT_CATEGORY_ID,
|
|
211
211
|
contexts,
|
|
212
212
|
new Set(
|
|
213
213
|
held
|
|
@@ -526,10 +526,9 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
526
526
|
)
|
|
527
527
|
}
|
|
528
528
|
const market = this.registry.require(sub.marketId)
|
|
529
|
-
const prefix =
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
: 'market_stats'
|
|
529
|
+
const prefix = isSpotCategory(market.categoryId)
|
|
530
|
+
? 'spot_market_stats'
|
|
531
|
+
: 'market_stats'
|
|
533
532
|
return [{ channel: `${prefix}/${market.id}`, needsAuth: false }]
|
|
534
533
|
}
|
|
535
534
|
if (sub.channel === 'orderbook') {
|
|
@@ -1097,7 +1096,7 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
1097
1096
|
data: trades.map((t) => ({
|
|
1098
1097
|
provider: this.providerKey,
|
|
1099
1098
|
marketId: assetId,
|
|
1100
|
-
price: t
|
|
1099
|
+
price: resolveTradePrice(t),
|
|
1101
1100
|
size: t.size,
|
|
1102
1101
|
timestamp: t.timestamp,
|
|
1103
1102
|
side: t.is_maker_ask ? 'buy' : 'sell',
|