@lifi/perps-sdk-provider-lighter 35.1.0 → 37.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 +99 -58
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/accountSummary.d.ts +1 -2
- package/dist/cjs/accountSummary.d.ts.map +1 -1
- package/dist/cjs/accountSummary.js +16 -16
- package/dist/cjs/accountSummary.js.map +1 -1
- package/dist/cjs/availableToTrade.d.ts +1 -2
- package/dist/cjs/availableToTrade.d.ts.map +1 -1
- package/dist/cjs/availableToTrade.js +8 -12
- package/dist/cjs/availableToTrade.js.map +1 -1
- package/dist/cjs/signers/LighterSigner.d.ts.map +1 -1
- package/dist/cjs/signers/LighterSigner.js +2 -6
- package/dist/cjs/signers/LighterSigner.js.map +1 -1
- package/dist/cjs/types/submit.d.ts +5 -0
- package/dist/cjs/types/submit.d.ts.map +1 -1
- package/dist/cjs/utils/index.d.ts +4 -4
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +5 -8
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +44 -31
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/mapOpenPositions.d.ts +1 -0
- package/dist/cjs/utils/mapOpenPositions.d.ts.map +1 -1
- package/dist/cjs/utils/mapOpenPositions.js +8 -4
- package/dist/cjs/utils/mapOpenPositions.js.map +1 -1
- package/dist/cjs/utils/mapOrder.d.ts +1 -1
- package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
- package/dist/cjs/utils/mapOrder.js +44 -23
- package/dist/cjs/utils/mapOrder.js.map +1 -1
- package/dist/cjs/utils/mapPortfolioHistory.d.ts +1 -2
- package/dist/cjs/utils/mapPortfolioHistory.d.ts.map +1 -1
- package/dist/cjs/utils/mapPortfolioHistory.js +29 -21
- package/dist/cjs/utils/mapPortfolioHistory.js.map +1 -1
- package/dist/cjs/utils/mapPosition.d.ts +3 -3
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
- package/dist/cjs/utils/mapPosition.js +54 -39
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/cjs/utils/rowTimestamp.d.ts +2 -0
- package/dist/cjs/utils/rowTimestamp.d.ts.map +1 -0
- package/dist/cjs/utils/rowTimestamp.js +14 -0
- package/dist/cjs/utils/rowTimestamp.js.map +1 -0
- package/dist/cjs/utils/settlementPool.d.ts +2 -3
- package/dist/cjs/utils/settlementPool.d.ts.map +1 -1
- package/dist/cjs/utils/settlementPool.js +8 -7
- package/dist/cjs/utils/settlementPool.js.map +1 -1
- package/dist/cjs/utils/spotPrice.d.ts +3 -4
- package/dist/cjs/utils/spotPrice.d.ts.map +1 -1
- package/dist/cjs/utils/spotPrice.js +6 -11
- package/dist/cjs/utils/spotPrice.js.map +1 -1
- package/dist/cjs/utils/time.d.ts.map +1 -1
- package/dist/cjs/utils/time.js +3 -2
- package/dist/cjs/utils/time.js.map +1 -1
- package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
- package/dist/cjs/utils/transferMargin.js +8 -11
- package/dist/cjs/utils/transferMargin.js.map +1 -1
- package/dist/cjs/utils/wireEncoding.d.ts +0 -2
- package/dist/cjs/utils/wireEncoding.d.ts.map +1 -1
- package/dist/cjs/utils/wireEncoding.js +1 -15
- package/dist/cjs/utils/wireEncoding.js.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.js +12 -17
- package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
- package/dist/cjs/utils/withdrawalTypes.d.ts +17 -0
- package/dist/cjs/utils/withdrawalTypes.d.ts.map +1 -0
- package/dist/cjs/utils/withdrawalTypes.js +58 -0
- package/dist/cjs/utils/withdrawalTypes.js.map +1 -0
- package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/LighterWsProvider.js +74 -66
- package/dist/cjs/websocket/LighterWsProvider.js.map +1 -1
- package/dist/cjs/websocket/orderBookSide.d.ts +20 -0
- package/dist/cjs/websocket/orderBookSide.d.ts.map +1 -0
- package/dist/cjs/websocket/orderBookSide.js +73 -0
- package/dist/cjs/websocket/orderBookSide.js.map +1 -0
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +113 -62
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/accountSummary.d.ts +1 -2
- package/dist/esm/accountSummary.d.ts.map +1 -1
- package/dist/esm/accountSummary.js +17 -14
- package/dist/esm/accountSummary.js.map +1 -1
- package/dist/esm/availableToTrade.d.ts +1 -2
- package/dist/esm/availableToTrade.d.ts.map +1 -1
- package/dist/esm/availableToTrade.js +9 -10
- package/dist/esm/availableToTrade.js.map +1 -1
- package/dist/esm/signers/LighterSigner.d.ts.map +1 -1
- package/dist/esm/signers/LighterSigner.js +3 -4
- package/dist/esm/signers/LighterSigner.js.map +1 -1
- package/dist/esm/types/submit.d.ts +14 -0
- package/dist/esm/types/submit.d.ts.map +1 -1
- package/dist/esm/utils/index.d.ts +4 -4
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +3 -4
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/mapFill.d.ts +1 -1
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +51 -35
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapOpenPositions.d.ts +9 -2
- package/dist/esm/utils/mapOpenPositions.d.ts.map +1 -1
- package/dist/esm/utils/mapOpenPositions.js +14 -5
- package/dist/esm/utils/mapOpenPositions.js.map +1 -1
- package/dist/esm/utils/mapOrder.d.ts +10 -3
- package/dist/esm/utils/mapOrder.d.ts.map +1 -1
- package/dist/esm/utils/mapOrder.js +54 -23
- package/dist/esm/utils/mapOrder.js.map +1 -1
- package/dist/esm/utils/mapPortfolioHistory.d.ts +6 -3
- package/dist/esm/utils/mapPortfolioHistory.d.ts.map +1 -1
- package/dist/esm/utils/mapPortfolioHistory.js +34 -19
- package/dist/esm/utils/mapPortfolioHistory.js.map +1 -1
- package/dist/esm/utils/mapPosition.d.ts +13 -9
- package/dist/esm/utils/mapPosition.d.ts.map +1 -1
- package/dist/esm/utils/mapPosition.js +65 -43
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/esm/utils/rowTimestamp.d.ts +6 -0
- package/dist/esm/utils/rowTimestamp.d.ts.map +1 -0
- package/dist/esm/utils/rowTimestamp.js +14 -0
- package/dist/esm/utils/rowTimestamp.js.map +1 -0
- package/dist/esm/utils/settlementPool.d.ts +2 -3
- package/dist/esm/utils/settlementPool.d.ts.map +1 -1
- package/dist/esm/utils/settlementPool.js +8 -7
- package/dist/esm/utils/settlementPool.js.map +1 -1
- package/dist/esm/utils/spotPrice.d.ts +3 -4
- package/dist/esm/utils/spotPrice.d.ts.map +1 -1
- package/dist/esm/utils/spotPrice.js +6 -8
- package/dist/esm/utils/spotPrice.js.map +1 -1
- package/dist/esm/utils/time.d.ts +10 -2
- package/dist/esm/utils/time.d.ts.map +1 -1
- package/dist/esm/utils/time.js +13 -4
- package/dist/esm/utils/time.js.map +1 -1
- package/dist/esm/utils/transferMargin.d.ts.map +1 -1
- package/dist/esm/utils/transferMargin.js +9 -9
- package/dist/esm/utils/transferMargin.js.map +1 -1
- package/dist/esm/utils/wireEncoding.d.ts +2 -28
- package/dist/esm/utils/wireEncoding.d.ts.map +1 -1
- package/dist/esm/utils/wireEncoding.js +2 -38
- package/dist/esm/utils/wireEncoding.js.map +1 -1
- package/dist/esm/utils/withdrawableBalances.d.ts +5 -3
- package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/esm/utils/withdrawableBalances.js +17 -17
- package/dist/esm/utils/withdrawableBalances.js.map +1 -1
- package/dist/esm/utils/withdrawalTypes.d.ts +45 -0
- package/dist/esm/utils/withdrawalTypes.d.ts.map +1 -0
- package/dist/esm/utils/withdrawalTypes.js +68 -0
- package/dist/esm/utils/withdrawalTypes.js.map +1 -0
- package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/LighterWsProvider.js +85 -65
- package/dist/esm/websocket/LighterWsProvider.js.map +1 -1
- package/dist/esm/websocket/orderBookSide.d.ts +34 -0
- package/dist/esm/websocket/orderBookSide.d.ts.map +1 -0
- package/dist/esm/websocket/orderBookSide.js +78 -0
- package/dist/esm/websocket/orderBookSide.js.map +1 -0
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/accountSummary.d.ts +1 -2
- package/dist/types/accountSummary.d.ts.map +1 -1
- package/dist/types/availableToTrade.d.ts +1 -2
- package/dist/types/availableToTrade.d.ts.map +1 -1
- package/dist/types/signers/LighterSigner.d.ts.map +1 -1
- package/dist/types/types/submit.d.ts +14 -0
- package/dist/types/types/submit.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +4 -4
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts +1 -1
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/utils/mapOpenPositions.d.ts +9 -2
- package/dist/types/utils/mapOpenPositions.d.ts.map +1 -1
- package/dist/types/utils/mapOrder.d.ts +10 -3
- package/dist/types/utils/mapOrder.d.ts.map +1 -1
- package/dist/types/utils/mapPortfolioHistory.d.ts +6 -3
- package/dist/types/utils/mapPortfolioHistory.d.ts.map +1 -1
- package/dist/types/utils/mapPosition.d.ts +13 -9
- package/dist/types/utils/mapPosition.d.ts.map +1 -1
- package/dist/types/utils/rowTimestamp.d.ts +6 -0
- package/dist/types/utils/rowTimestamp.d.ts.map +1 -0
- package/dist/types/utils/settlementPool.d.ts +2 -3
- package/dist/types/utils/settlementPool.d.ts.map +1 -1
- package/dist/types/utils/spotPrice.d.ts +3 -4
- package/dist/types/utils/spotPrice.d.ts.map +1 -1
- package/dist/types/utils/time.d.ts +10 -2
- package/dist/types/utils/time.d.ts.map +1 -1
- package/dist/types/utils/transferMargin.d.ts.map +1 -1
- package/dist/types/utils/wireEncoding.d.ts +2 -28
- package/dist/types/utils/wireEncoding.d.ts.map +1 -1
- package/dist/types/utils/withdrawableBalances.d.ts +5 -3
- package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/types/utils/withdrawalTypes.d.ts +45 -0
- package/dist/types/utils/withdrawalTypes.d.ts.map +1 -0
- package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/types/websocket/orderBookSide.d.ts +34 -0
- package/dist/types/websocket/orderBookSide.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/LighterProvider.ts +231 -97
- package/src/accountSummary.ts +62 -22
- package/src/availableToTrade.ts +38 -15
- package/src/signers/LighterSigner.ts +11 -4
- package/src/types/submit.ts +15 -0
- package/src/utils/index.ts +9 -5
- package/src/utils/mapFill.ts +82 -43
- package/src/utils/mapOpenPositions.ts +16 -5
- package/src/utils/mapOrder.ts +76 -26
- package/src/utils/mapPortfolioHistory.ts +78 -24
- package/src/utils/mapPosition.ts +93 -50
- package/src/utils/rowTimestamp.ts +15 -0
- package/src/utils/settlementPool.ts +36 -12
- package/src/utils/spotPrice.ts +18 -12
- package/src/utils/time.ts +14 -4
- package/src/utils/transferMargin.ts +32 -15
- package/src/utils/wireEncoding.ts +2 -43
- package/src/utils/withdrawableBalances.ts +34 -20
- package/src/utils/withdrawalTypes.ts +125 -0
- package/src/websocket/LighterWsProvider.ts +137 -114
- package/src/websocket/orderBookSide.ts +119 -0
- package/dist/cjs/utils/decimal.d.ts +0 -5
- package/dist/cjs/utils/decimal.d.ts.map +0 -1
- package/dist/cjs/utils/decimal.js +0 -38
- package/dist/cjs/utils/decimal.js.map +0 -1
- package/dist/cjs/utils/liquidation.d.ts +0 -4
- package/dist/cjs/utils/liquidation.d.ts.map +0 -1
- package/dist/cjs/utils/liquidation.js +0 -16
- package/dist/cjs/utils/liquidation.js.map +0 -1
- package/dist/esm/utils/decimal.d.ts +0 -15
- package/dist/esm/utils/decimal.d.ts.map +0 -1
- package/dist/esm/utils/decimal.js +0 -39
- package/dist/esm/utils/decimal.js.map +0 -1
- package/dist/esm/utils/liquidation.d.ts +0 -22
- package/dist/esm/utils/liquidation.d.ts.map +0 -1
- package/dist/esm/utils/liquidation.js +0 -31
- package/dist/esm/utils/liquidation.js.map +0 -1
- package/dist/types/utils/decimal.d.ts +0 -15
- package/dist/types/utils/decimal.d.ts.map +0 -1
- package/dist/types/utils/liquidation.d.ts +0 -22
- package/dist/types/utils/liquidation.d.ts.map +0 -1
- package/src/utils/decimal.ts +0 -52
- package/src/utils/liquidation.ts +0 -39
|
@@ -1,76 +1,98 @@
|
|
|
1
|
+
import { absDecimalString, createWarnOnce, divideDecimalString, isDecimalString, isDecimalStringZero, multiplyDecimalString, safeDivideDecimalString, safeIsDecimalStringGreaterThan, safeNumberToDecimalString, safeRoundDecimalString, warnSkippedVenueRow, } from '@lifi/perps-sdk';
|
|
1
2
|
import { MarginMode, PositionSide } from '@lifi/perps-types';
|
|
2
|
-
import
|
|
3
|
-
import { LIGHTER_IMF_PERCENT_SCALE, LIGHTER_LEVERAGE_PRECISION, } from '../constants.js';
|
|
3
|
+
import { LIGHTER_IMF_PERCENT_SCALE, LIGHTER_LEVERAGE_PRECISION, LIGHTER_PROVIDER_KEY, } from '../constants.js';
|
|
4
4
|
import { LT_MARGIN_MODE_ISOLATED } from '../types/index.js';
|
|
5
|
-
import { toPositiveRequiredBig, toRequiredBig } from './decimal.js';
|
|
6
5
|
/**
|
|
7
6
|
* Display leverage from an IMF percent string: `100 / IMF` in exact decimal
|
|
8
|
-
* arithmetic, rounded half-up to `LIGHTER_LEVERAGE_PRECISION
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* arithmetic, rounded half-up to `LIGHTER_LEVERAGE_PRECISION`, so the value a
|
|
8
|
+
* client reads is the value it saved. Provider risk calculations consume the
|
|
9
|
+
* original decimal IMF instead. `undefined` for a non-positive or unparsable
|
|
10
|
+
* IMF.
|
|
12
11
|
* @public
|
|
13
12
|
*/
|
|
14
13
|
export const leverageFromImf = (imf) => {
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
parsed = new Big(imf);
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
if (parsed.lte(0)) {
|
|
14
|
+
if (safeIsDecimalStringGreaterThan(imf, '0') !== true) {
|
|
23
15
|
return undefined;
|
|
24
16
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const leverage = safeDivideDecimalString('100', imf);
|
|
18
|
+
return leverage === undefined
|
|
19
|
+
? undefined
|
|
20
|
+
: safeRoundDecimalString(leverage, LIGHTER_LEVERAGE_PRECISION, 'round');
|
|
29
21
|
};
|
|
30
22
|
/**
|
|
31
23
|
* Display leverage from an integer IMF on `LIGHTER_IMF_PERCENT_SCALE`, the
|
|
32
24
|
* unit of trade rows and order-book details: `500` is 5.00%, so 20x.
|
|
33
|
-
* `undefined` for a non-positive or
|
|
25
|
+
* `undefined` for a non-positive or non-finite IMF. Lighter declares the
|
|
34
26
|
* fraction a `StrictInt`, so the scale division is exact.
|
|
35
27
|
*/
|
|
36
28
|
export const leverageFromScaledImf = (imf) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
const scaled = safeNumberToDecimalString(imf);
|
|
30
|
+
const percent = scaled === undefined
|
|
31
|
+
? undefined
|
|
32
|
+
: safeDivideDecimalString(scaled, String(LIGHTER_IMF_PERCENT_SCALE));
|
|
33
|
+
return percent === undefined ? undefined : leverageFromImf(percent);
|
|
34
|
+
};
|
|
35
|
+
const skipPosition = (marketId, field, value) => {
|
|
36
|
+
warnSkippedVenueRow(LIGHTER_PROVIDER_KEY, 'position', field, value, {
|
|
37
|
+
marketId,
|
|
38
|
+
});
|
|
39
|
+
return undefined;
|
|
40
|
+
};
|
|
41
|
+
const warnUnreadableFieldOnce = createWarnOnce();
|
|
42
|
+
const warnUnreadableField = (field, value) => {
|
|
43
|
+
warnUnreadableFieldOnce(`${LIGHTER_PROVIDER_KEY}|position.${field}`, `[${LIGHTER_PROVIDER_KEY}] position \`${field}\` is not readable, so the derived fields are absent: '${String(value).slice(0, 64)}'`);
|
|
45
44
|
};
|
|
46
45
|
/**
|
|
47
|
-
* Map a raw Lighter account position to the generic Position type.
|
|
46
|
+
* Map a raw Lighter account position to the generic Position type. A row with
|
|
47
|
+
* an invalid size gives `undefined`. An invalid position value or a
|
|
48
|
+
* non-positive initial margin fraction keeps the row, leaves `leverage` and
|
|
49
|
+
* `initialMarginRequirement` absent, sets a cross `marginUsed` to `'0'` and
|
|
50
|
+
* warns once. Prices, PnL, funding and isolated margin pass through raw.
|
|
48
51
|
* @param market - Backend-resolved market identity for `pos.market_id`.
|
|
49
52
|
* @public
|
|
50
53
|
*/
|
|
51
54
|
export const mapPosition = (pos, market) => {
|
|
52
|
-
|
|
55
|
+
if (!isDecimalString(pos.position)) {
|
|
56
|
+
return skipPosition(market.id, 'position', pos.position);
|
|
57
|
+
}
|
|
53
58
|
const isIsolated = pos.margin_mode === LT_MARGIN_MODE_ISOLATED;
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
const size = absDecimalString(pos.position);
|
|
60
|
+
const positionValue = isDecimalString(pos.position_value)
|
|
61
|
+
? absDecimalString(pos.position_value)
|
|
62
|
+
: undefined;
|
|
63
|
+
if (positionValue === undefined) {
|
|
64
|
+
warnUnreadableField('position_value', pos.position_value);
|
|
65
|
+
}
|
|
66
|
+
const imf = pos.initial_margin_fraction;
|
|
67
|
+
const leverage = isDecimalString(imf) ? leverageFromImf(imf) : undefined;
|
|
68
|
+
if (leverage === undefined) {
|
|
69
|
+
warnUnreadableField('initial_margin_fraction', imf);
|
|
70
|
+
}
|
|
71
|
+
const initialMarginRequirement = positionValue === undefined || leverage === undefined
|
|
72
|
+
? undefined
|
|
73
|
+
: divideDecimalString(multiplyDecimalString(positionValue, imf), '100');
|
|
60
74
|
return {
|
|
61
75
|
market,
|
|
62
76
|
side: pos.sign >= 0 ? PositionSide.LONG : PositionSide.SHORT,
|
|
63
|
-
size
|
|
77
|
+
size,
|
|
64
78
|
entryPrice: pos.avg_entry_price,
|
|
65
|
-
|
|
66
|
-
?
|
|
67
|
-
:
|
|
79
|
+
...(positionValue === undefined
|
|
80
|
+
? {}
|
|
81
|
+
: {
|
|
82
|
+
markPrice: isDecimalStringZero(positionValue) || isDecimalStringZero(size)
|
|
83
|
+
? '0'
|
|
84
|
+
: divideDecimalString(positionValue, size),
|
|
85
|
+
}),
|
|
68
86
|
liquidationPrice: pos.liquidation_price,
|
|
69
87
|
unrealizedPnl: pos.unrealized_pnl,
|
|
70
88
|
accruedFunding: pos.total_funding_paid_out ?? '0',
|
|
71
|
-
leverage:
|
|
72
|
-
marginUsed
|
|
73
|
-
|
|
89
|
+
...(leverage === undefined ? {} : { leverage }),
|
|
90
|
+
marginUsed: isIsolated
|
|
91
|
+
? pos.allocated_margin
|
|
92
|
+
: (initialMarginRequirement ?? '0'),
|
|
93
|
+
...(initialMarginRequirement === undefined
|
|
94
|
+
? {}
|
|
95
|
+
: { initialMarginRequirement }),
|
|
74
96
|
marginMode: isIsolated ? MarginMode.ISOLATED : MarginMode.CROSS,
|
|
75
97
|
};
|
|
76
98
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapPosition.js","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"
|
|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C,wBAAwB,IAAI,GAAG,CAAC;QACrC,GAAG,CAAC,wBAAwB,KAAK,SAAS;YACxC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,wBAAwB,EAAE,CAAC;QACjC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK;KAChE,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a venue row time as an ISO-8601 string, or `undefined` when the time is
|
|
3
|
+
* not valid. The caller logs the row skip, so this logs nothing.
|
|
4
|
+
*/
|
|
5
|
+
export declare const rowTimestampToIsoStringOrUndefined: (value: string | number) => string | undefined;
|
|
6
|
+
//# sourceMappingURL=rowTimestamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rowTimestamp.d.ts","sourceRoot":"","sources":["../../../src/utils/rowTimestamp.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,kCAAkC,GAC7C,OAAO,MAAM,GAAG,MAAM,KACrB,MAAM,GAAG,SAMX,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { timestampToIsoString } from '@lifi/perps-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Read a venue row time as an ISO-8601 string, or `undefined` when the time is
|
|
4
|
+
* not valid. The caller logs the row skip, so this logs nothing.
|
|
5
|
+
*/
|
|
6
|
+
export const rowTimestampToIsoStringOrUndefined = (value) => {
|
|
7
|
+
try {
|
|
8
|
+
return timestampToIsoString(value);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=rowTimestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rowTimestamp.js","sourceRoot":"","sources":["../../../src/utils/rowTimestamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;;GAGG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,KAAsB,EACF,EAAE;IACtB,IAAI,CAAC;QACH,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type Big from 'big.js';
|
|
2
1
|
import type { LtAccountAsset } from '../types/account.js';
|
|
3
2
|
/** Both routes of a unified account's settlement asset, as one holding. */
|
|
4
|
-
export declare const pooledSettlementUnits: (asset: LtAccountAsset) =>
|
|
3
|
+
export declare const pooledSettlementUnits: (asset: LtAccountAsset) => string;
|
|
5
4
|
/**
|
|
6
5
|
* Spot units a unified account can spend from its settlement pool: the free
|
|
7
6
|
* spot route plus the margin route up to the account's `available_balance`.
|
|
8
7
|
* This is `computeSpotAvailableToTradeMarket` in Lighter's `lighter-ts` for an
|
|
9
8
|
* asset priced 1:1 with a `loan_to_value` of 1. The result can be negative.
|
|
10
9
|
*/
|
|
11
|
-
export declare const pooledSettlementSpendable: (asset: LtAccountAsset, availableBalance:
|
|
10
|
+
export declare const pooledSettlementSpendable: (asset: LtAccountAsset, availableBalance: string) => string;
|
|
12
11
|
/** Spot-route `balance` of the collateral asset; `'0'` when the account holds none. */
|
|
13
12
|
export declare const collateralSpotBalance: (assets: readonly LtAccountAsset[], settlementAssetIndex: number) => string;
|
|
14
13
|
//# sourceMappingURL=settlementPool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settlementPool.d.ts","sourceRoot":"","sources":["../../../src/utils/settlementPool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"settlementPool.d.ts","sourceRoot":"","sources":["../../../src/utils/settlementPool.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,GAAI,OAAO,cAAc,KAAG,MAQ3D,CAAA;AAEH;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GACpC,OAAO,cAAc,EACrB,kBAAkB,MAAM,KACvB,MAmBF,CAAA;AAED,uFAAuF;AACvF,eAAO,MAAM,qBAAqB,GAChC,QAAQ,SAAS,cAAc,EAAE,EACjC,sBAAsB,MAAM,KAC3B,MAKF,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addDecimalString, isDecimalStringGreaterThan, subtractDecimalString, unknownToDecimalString, } from '@lifi/perps-sdk';
|
|
2
|
+
import { LIGHTER_PROVIDER_KEY } from '../constants.js';
|
|
2
3
|
/** Both routes of a unified account's settlement asset, as one holding. */
|
|
3
|
-
export const pooledSettlementUnits = (asset) =>
|
|
4
|
+
export const pooledSettlementUnits = (asset) => addDecimalString(unknownToDecimalString(asset.balance, 'balance', LIGHTER_PROVIDER_KEY), unknownToDecimalString(asset.margin_balance, 'margin_balance', LIGHTER_PROVIDER_KEY));
|
|
4
5
|
/**
|
|
5
6
|
* Spot units a unified account can spend from its settlement pool: the free
|
|
6
7
|
* spot route plus the margin route up to the account's `available_balance`.
|
|
@@ -8,16 +9,16 @@ export const pooledSettlementUnits = (asset) => toRequiredBig(asset.balance, 'ba
|
|
|
8
9
|
* asset priced 1:1 with a `loan_to_value` of 1. The result can be negative.
|
|
9
10
|
*/
|
|
10
11
|
export const pooledSettlementSpendable = (asset, availableBalance) => {
|
|
11
|
-
const marginBalance =
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const marginBalance = unknownToDecimalString(asset.margin_balance, 'margin_balance', LIGHTER_PROVIDER_KEY);
|
|
13
|
+
return addDecimalString(subtractDecimalString(unknownToDecimalString(asset.balance, 'balance', LIGHTER_PROVIDER_KEY), unknownToDecimalString(asset.locked_balance, 'locked_balance', LIGHTER_PROVIDER_KEY)), isDecimalStringGreaterThan(marginBalance, availableBalance)
|
|
14
|
+
? availableBalance
|
|
15
|
+
: marginBalance);
|
|
15
16
|
};
|
|
16
17
|
/** Spot-route `balance` of the collateral asset; `'0'` when the account holds none. */
|
|
17
18
|
export const collateralSpotBalance = (assets, settlementAssetIndex) => {
|
|
18
19
|
const asset = assets.find((a) => a.asset_id === settlementAssetIndex);
|
|
19
20
|
return asset === undefined
|
|
20
21
|
? '0'
|
|
21
|
-
:
|
|
22
|
+
: unknownToDecimalString(asset.balance, 'balance', LIGHTER_PROVIDER_KEY);
|
|
22
23
|
};
|
|
23
24
|
//# sourceMappingURL=settlementPool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settlementPool.js","sourceRoot":"","sources":["../../../src/utils/settlementPool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"settlementPool.js","sourceRoot":"","sources":["../../../src/utils/settlementPool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAGtD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAqB,EAAU,EAAE,CACrE,gBAAgB,CACd,sBAAsB,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,oBAAoB,CAAC,EACtE,sBAAsB,CACpB,KAAK,CAAC,cAAc,EACpB,gBAAgB,EAChB,oBAAoB,CACrB,CACF,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,KAAqB,EACrB,gBAAwB,EAChB,EAAE;IACV,MAAM,aAAa,GAAG,sBAAsB,CAC1C,KAAK,CAAC,cAAc,EACpB,gBAAgB,EAChB,oBAAoB,CACrB,CAAA;IACD,OAAO,gBAAgB,CACrB,qBAAqB,CACnB,sBAAsB,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,oBAAoB,CAAC,EACtE,sBAAsB,CACpB,KAAK,CAAC,cAAc,EACpB,gBAAgB,EAChB,oBAAoB,CACrB,CACF,EACD,0BAA0B,CAAC,aAAa,EAAE,gBAAgB,CAAC;QACzD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,aAAa,CAClB,CAAA;AACH,CAAC,CAAA;AAED,uFAAuF;AACvF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAAiC,EACjC,oBAA4B,EACpB,EAAE;IACV,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,oBAAoB,CAAC,CAAA;IACrE,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAA;AAC5E,CAAC,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Market, MarketContext } from '@lifi/perps-types';
|
|
2
|
-
import Big from 'big.js';
|
|
3
2
|
/**
|
|
4
3
|
* Unit prices keyed by spot base `Asset.id` (the venue `asset_id`), read from
|
|
5
4
|
* each spot market's `markPrice` for the base assets in `assetIds` only. A
|
|
@@ -10,14 +9,14 @@ import Big from 'big.js';
|
|
|
10
9
|
* @throws {PerpsError} `SDKError` when a context row for a requested asset
|
|
11
10
|
* carries a non-decimal mark.
|
|
12
11
|
*/
|
|
13
|
-
export declare const spotPriceByAssetId: (markets: readonly Market[], spotCategoryId: string, contexts: readonly MarketContext[], assetIds: ReadonlySet<string>) => Map<string,
|
|
12
|
+
export declare const spotPriceByAssetId: (markets: readonly Market[], spotCategoryId: string, contexts: readonly MarketContext[], assetIds: ReadonlySet<string>) => Map<string, string>;
|
|
14
13
|
/**
|
|
15
14
|
* USD value of `units` of a Lighter asset, with the unit price it used: the
|
|
16
15
|
* settlement asset at 1, any other at its `spotPrices` entry. An asset absent
|
|
17
16
|
* from `spotPrices` values at 0 and carries no price.
|
|
18
17
|
*/
|
|
19
|
-
export declare const spotValuation: (assetId: number, units: string, settlementAssetIndex: number, spotPrices: ReadonlyMap<string,
|
|
18
|
+
export declare const spotValuation: (assetId: number, units: string, settlementAssetIndex: number, spotPrices: ReadonlyMap<string, string>) => {
|
|
20
19
|
valueUsd: string;
|
|
21
|
-
price?:
|
|
20
|
+
price?: string;
|
|
22
21
|
};
|
|
23
22
|
//# sourceMappingURL=spotPrice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spotPrice.d.ts","sourceRoot":"","sources":["../../../src/utils/spotPrice.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spotPrice.d.ts","sourceRoot":"","sources":["../../../src/utils/spotPrice.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAG9D;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,SAAS,MAAM,EAAE,EAC1B,gBAAgB,MAAM,EACtB,UAAU,SAAS,aAAa,EAAE,EAClC,UAAU,WAAW,CAAC,MAAM,CAAC,KAC5B,GAAG,CAAC,MAAM,EAAE,MAAM,CAuBpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,MAAM,EACf,OAAO,MAAM,EACb,sBAAsB,MAAM,EAC5B,YAAY,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,KACtC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAMpC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { isDecimalStringGreaterThan, multiplyDecimalString, unknownToDecimalString, } from '@lifi/perps-sdk';
|
|
2
|
+
import { LIGHTER_PROVIDER_KEY } from '../constants.js';
|
|
3
3
|
/**
|
|
4
4
|
* Unit prices keyed by spot base `Asset.id` (the venue `asset_id`), read from
|
|
5
5
|
* each spot market's `markPrice` for the base assets in `assetIds` only. A
|
|
@@ -21,8 +21,8 @@ export const spotPriceByAssetId = (markets, spotCategoryId, contexts, assetIds)
|
|
|
21
21
|
priceByAssetId.has(market.baseAsset.id)) {
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
|
-
const price =
|
|
25
|
-
if (price
|
|
24
|
+
const price = unknownToDecimalString(mark, 'markPrice', LIGHTER_PROVIDER_KEY);
|
|
25
|
+
if (isDecimalStringGreaterThan(price, '0')) {
|
|
26
26
|
priceByAssetId.set(market.baseAsset.id, price);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -34,11 +34,9 @@ export const spotPriceByAssetId = (markets, spotCategoryId, contexts, assetIds)
|
|
|
34
34
|
* from `spotPrices` values at 0 and carries no price.
|
|
35
35
|
*/
|
|
36
36
|
export const spotValuation = (assetId, units, settlementAssetIndex, spotPrices) => {
|
|
37
|
-
const price = assetId === settlementAssetIndex
|
|
38
|
-
? new Big(1)
|
|
39
|
-
: spotPrices.get(String(assetId));
|
|
37
|
+
const price = assetId === settlementAssetIndex ? '1' : spotPrices.get(String(assetId));
|
|
40
38
|
return price === undefined
|
|
41
39
|
? { valueUsd: '0' }
|
|
42
|
-
: { valueUsd:
|
|
40
|
+
: { valueUsd: multiplyDecimalString(units, price), price };
|
|
43
41
|
};
|
|
44
42
|
//# sourceMappingURL=spotPrice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spotPrice.js","sourceRoot":"","sources":["../../../src/utils/spotPrice.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spotPrice.js","sourceRoot":"","sources":["../../../src/utils/spotPrice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA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xC,MAAM,KAAK,GACT,OAAO,KAAK,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IAC1E,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE;QACnB,CAAC,CAAC,EAAE,QAAQ,EAAE,qBAAqB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,CAAA;AAC9D,CAAC,CAAA"}
|
package/dist/esm/utils/time.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Convert seconds since unix epoch to ISO-8601.
|
|
3
|
+
*
|
|
4
|
+
* @throws {PerpsError} `ValidationError` when `seconds` is not a valid time.
|
|
5
|
+
*/
|
|
2
6
|
export declare const toIsoFromSeconds: (seconds: number) => string;
|
|
3
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Convert milliseconds since unix epoch to ISO-8601.
|
|
9
|
+
*
|
|
10
|
+
* @throws {PerpsError} `ValidationError` when `ms` is not a valid time.
|
|
11
|
+
*/
|
|
4
12
|
export declare const toIsoFromMs: (ms: number) => string;
|
|
5
13
|
//# sourceMappingURL=time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,KAAG,MACb,CAAA;AAEtC;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,IAAI,MAAM,KAAG,MAAkC,CAAA"}
|
package/dist/esm/utils/time.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { timestampToIsoString } from '@lifi/perps-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Convert seconds since unix epoch to ISO-8601.
|
|
4
|
+
*
|
|
5
|
+
* @throws {PerpsError} `ValidationError` when `seconds` is not a valid time.
|
|
6
|
+
*/
|
|
7
|
+
export const toIsoFromSeconds = (seconds) => timestampToIsoString(seconds * 1000);
|
|
8
|
+
/**
|
|
9
|
+
* Convert milliseconds since unix epoch to ISO-8601.
|
|
10
|
+
*
|
|
11
|
+
* @throws {PerpsError} `ValidationError` when `ms` is not a valid time.
|
|
12
|
+
*/
|
|
13
|
+
export const toIsoFromMs = (ms) => timestampToIsoString(ms);
|
|
5
14
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAU,EAAE,CAC1D,oBAAoB,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transferMargin.d.ts","sourceRoot":"","sources":["../../../src/utils/transferMargin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transferMargin.d.ts","sourceRoot":"","sources":["../../../src/utils/transferMargin.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAA;AA+B1B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,GACjB,aAAa,GAAG,SAAS,CAqB3B"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { PerpsError, positionSupportsMarginAdjustment, positionSupportsMarginRemoval,
|
|
1
|
+
import { addDecimalString, isDecimalString, isDecimalStringGreaterThan, PerpsError, positionSupportsMarginAdjustment, positionSupportsMarginRemoval, roundDecimalString, subtractDecimalString, } from '@lifi/perps-sdk';
|
|
2
2
|
import { PerpsErrorCode, } from '@lifi/perps-types';
|
|
3
|
-
import Big from 'big.js';
|
|
4
3
|
const AMOUNT_DECIMALS = 6;
|
|
5
4
|
function positionAmount(value, field) {
|
|
6
|
-
|
|
5
|
+
if (!isDecimalString(value)) {
|
|
6
|
+
throw new PerpsError(PerpsErrorCode.ValidationError, `Invalid \`Position.${field}\`: '${value}' does not match the decimal pattern.`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
7
9
|
}
|
|
8
10
|
function positivePositionAmount(value, field) {
|
|
9
11
|
const amount = positionAmount(value, field);
|
|
10
|
-
if (amount
|
|
12
|
+
if (!isDecimalStringGreaterThan(amount, '0')) {
|
|
11
13
|
throw new PerpsError(PerpsErrorCode.ValidationError, `Position.${field} must be greater than zero.`);
|
|
12
14
|
}
|
|
13
15
|
return amount;
|
|
@@ -33,12 +35,10 @@ export function positionRemovableMargin(position) {
|
|
|
33
35
|
if (!positionSupportsMarginRemoval(position)) {
|
|
34
36
|
return '0';
|
|
35
37
|
}
|
|
36
|
-
const removable = positivePositionAmount(position.marginUsed, 'marginUsed')
|
|
37
|
-
|
|
38
|
-
.minus(positivePositionAmount(position.initialMarginRequirement, 'initialMarginRequirement'));
|
|
39
|
-
if (removable.lte(0)) {
|
|
38
|
+
const removable = subtractDecimalString(addDecimalString(positivePositionAmount(position.marginUsed, 'marginUsed'), positionAmount(position.unrealizedPnl, 'unrealizedPnl')), positivePositionAmount(position.initialMarginRequirement, 'initialMarginRequirement'));
|
|
39
|
+
if (!isDecimalStringGreaterThan(removable, '0')) {
|
|
40
40
|
return '0';
|
|
41
41
|
}
|
|
42
|
-
return removable
|
|
42
|
+
return roundDecimalString(removable, AMOUNT_DECIMALS, 'truncate');
|
|
43
43
|
}
|
|
44
44
|
//# sourceMappingURL=transferMargin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transferMargin.js","sourceRoot":"","sources":["../../../src/utils/transferMargin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,gCAAgC,EAChC,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,cAAc,GAEf,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"transferMargin.js","sourceRoot":"","sources":["../../../src/utils/transferMargin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC1B,UAAU,EACV,gCAAgC,EAChC,6BAA6B,EAC7B,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,cAAc,GAEf,MAAM,mBAAmB,CAAA;AAE1B,MAAM,eAAe,GAAG,CAAC,CAAA;AAEzB,SAAS,cAAc,CACrB,KAAgC,EAChC,KAAa;IAEb,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,UAAU,CAClB,cAAc,CAAC,eAAe,EAC9B,sBAAsB,KAAK,QAAQ,KAAK,uCAAuC,CAChF,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,sBAAsB,CAC7B,KAAgC,EAChC,KAAa;IAEb,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC3C,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,UAAU,CAClB,cAAc,CAAC,eAAe,EAC9B,YAAY,KAAK,6BAA6B,CAC/C,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAAkB;IAElB,IAAI,CAAC,gCAAgC,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChD,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7C,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,MAAM,SAAS,GAAG,qBAAqB,CACrC,gBAAgB,CACd,sBAAsB,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,EACzD,cAAc,CAAC,QAAQ,CAAC,aAAa,EAAE,eAAe,CAAC,CACxD,EACD,sBAAsB,CACpB,QAAQ,CAAC,wBAAwB,EACjC,0BAA0B,CAC3B,CACF,CAAA;IACD,IAAI,CAAC,0BAA0B,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC;QAChD,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,OAAO,kBAAkB,CAAC,SAAS,EAAE,eAAe,EAAE,UAAU,CAAC,CAAA;AACnE,CAAC"}
|
|
@@ -1,33 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lighter wire encoding for the WASM signer:
|
|
3
|
-
*
|
|
2
|
+
* Lighter wire encoding for the WASM signer: order-type/time-in-force/expiry
|
|
3
|
+
* resolution mirroring lighter-go's rules.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* Convert Lighter's initial-margin fraction to the largest whole-number
|
|
7
|
-
* leverage exposed by the provider.
|
|
8
|
-
*
|
|
9
|
-
* Lighter expresses margin fractions in basis points (`10_000` = 100%), so
|
|
10
|
-
* the conversion is `floor(10_000 / fraction)`. Non-finite or non-positive
|
|
11
|
-
* input uses the safe `1x` fallback.
|
|
12
|
-
*
|
|
13
|
-
* @param fraction - Lighter's basis-point initial-margin fraction.
|
|
14
|
-
* @returns The floored maximum leverage, or `1` for invalid input.
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export declare const marginFractionToMaxLeverage: (fraction: number) => number;
|
|
18
|
-
/**
|
|
19
|
-
* Convert requested leverage to Lighter's basis-point margin fraction.
|
|
20
|
-
*
|
|
21
|
-
* The signer expects `round(10_000 / leverage)`, where the result is the
|
|
22
|
-
* margin requirement in basis points.
|
|
23
|
-
*
|
|
24
|
-
* @param leverage - Requested leverage multiplier.
|
|
25
|
-
* @returns The rounded basis-point margin fraction.
|
|
26
|
-
* @throws {PerpsError} With `ValidationError` when leverage is less than
|
|
27
|
-
* or equal to zero.
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export declare const leverageToFraction: (leverage: number) => number;
|
|
31
5
|
/**
|
|
32
6
|
* Map a LI.FI `OrderType` value to Lighter's integer wire type.
|
|
33
7
|
* Supported mappings are LIMIT → 0, MARKET → 1, STOP_MARKET → 2,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wireEncoding.d.ts","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH
|
|
1
|
+
{"version":3,"file":"wireEncoding.d.ts","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,MAWjD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,GAC7B,cAAc,MAAM,EACpB,MAAM,MAAM,KACX,MAgBF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,MAOlD,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAKlD,CAAA"}
|
|
@@ -1,46 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lighter wire encoding for the WASM signer:
|
|
3
|
-
*
|
|
2
|
+
* Lighter wire encoding for the WASM signer: order-type/time-in-force/expiry
|
|
3
|
+
* resolution mirroring lighter-go's rules.
|
|
4
4
|
*/
|
|
5
5
|
import { PerpsError } from '@lifi/perps-sdk';
|
|
6
6
|
import { PerpsErrorCode } from '@lifi/perps-types';
|
|
7
7
|
import { LT_DEFAULT_ORDER_EXPIRY, LT_ORDER_TYPE_LIMIT, LT_ORDER_TYPE_MARKET, LT_ORDER_TYPE_STOP_LOSS, LT_ORDER_TYPE_STOP_LOSS_LIMIT, LT_ORDER_TYPE_TAKE_PROFIT, LT_ORDER_TYPE_TAKE_PROFIT_LIMIT, LT_ORDER_TYPE_TWAP, LT_TIME_IN_FORCE_GTC, LT_TIME_IN_FORCE_IOC, LT_TIME_IN_FORCE_POST_ONLY, } from '../types/action.js';
|
|
8
|
-
/**
|
|
9
|
-
* Convert Lighter's initial-margin fraction to the largest whole-number
|
|
10
|
-
* leverage exposed by the provider.
|
|
11
|
-
*
|
|
12
|
-
* Lighter expresses margin fractions in basis points (`10_000` = 100%), so
|
|
13
|
-
* the conversion is `floor(10_000 / fraction)`. Non-finite or non-positive
|
|
14
|
-
* input uses the safe `1x` fallback.
|
|
15
|
-
*
|
|
16
|
-
* @param fraction - Lighter's basis-point initial-margin fraction.
|
|
17
|
-
* @returns The floored maximum leverage, or `1` for invalid input.
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export const marginFractionToMaxLeverage = (fraction) => {
|
|
21
|
-
if (!Number.isFinite(fraction) || fraction <= 0) {
|
|
22
|
-
return 1;
|
|
23
|
-
}
|
|
24
|
-
return Math.floor(10_000 / fraction);
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Convert requested leverage to Lighter's basis-point margin fraction.
|
|
28
|
-
*
|
|
29
|
-
* The signer expects `round(10_000 / leverage)`, where the result is the
|
|
30
|
-
* margin requirement in basis points.
|
|
31
|
-
*
|
|
32
|
-
* @param leverage - Requested leverage multiplier.
|
|
33
|
-
* @returns The rounded basis-point margin fraction.
|
|
34
|
-
* @throws {PerpsError} With `ValidationError` when leverage is less than
|
|
35
|
-
* or equal to zero.
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export const leverageToFraction = (leverage) => {
|
|
39
|
-
if (leverage <= 0) {
|
|
40
|
-
throw new PerpsError(PerpsErrorCode.ValidationError, `Invalid leverage: ${leverage}`);
|
|
41
|
-
}
|
|
42
|
-
return Math.round(10_000 / leverage);
|
|
43
|
-
};
|
|
44
8
|
/**
|
|
45
9
|
* Map a LI.FI `OrderType` value to Lighter's integer wire type.
|
|
46
10
|
* Supported mappings are LIMIT → 0, MARKET → 1, STOP_MARKET → 2,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wireEncoding.js","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,6BAA6B,EAC7B,yBAAyB,EACzB,+BAA+B,EAC/B,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,oBAAoB,CAAA;AAE3B
|
|
1
|
+
{"version":3,"file":"wireEncoding.js","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,uB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IAC1D,MAAM,GAAG,GAA2B;QAClC,GAAG,EAAE,oBAAoB;QACzB,GAAG,EAAE,oBAAoB;QACzB,SAAS,EAAE,0BAA0B;KACtC,CAAA;IACD,OAAO,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,oBAAoB,CAAA;AAClD,CAAC,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAU,EAAE;IAC1D,IAAI,MAAM,KAAK,oBAAoB,EAAE,CAAC;QACpC,OAAO,CAAC,CAAA;IACV,CAAC;IACD,OAAO,uBAAuB,CAAA;AAChC,CAAC,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ProviderWithdrawableBalance } from '@lifi/perps-sdk';
|
|
2
2
|
import type { LtAccount } from '../types/account.js';
|
|
3
3
|
/**
|
|
4
|
-
* Split each held asset into the two
|
|
5
|
-
* spot draws on `balance` net of `locked_balance`, perps draws on
|
|
4
|
+
* Split each held asset into the two categories a Lighter withdrawal can
|
|
5
|
+
* name: spot draws on `balance` net of `locked_balance`, perps draws on
|
|
6
6
|
* `margin_balance`. The settlement asset's perps route is also capped by the
|
|
7
7
|
* account `available_balance`, which excludes the margin open positions use.
|
|
8
8
|
* Every other asset's perps route reports its full `margin_balance`, uncapped,
|
|
@@ -13,7 +13,9 @@ import type { LtAccount } from '../types/account.js';
|
|
|
13
13
|
*
|
|
14
14
|
* @param settlementAssetIndex - L2 asset index of the deployment's collateral
|
|
15
15
|
* asset, the only asset that `available_balance` is denominated in.
|
|
16
|
+
* @param perpsCategoryId - The instance's perps category id, the
|
|
17
|
+
* `categoryId` its collateral `Balance` rows carry.
|
|
16
18
|
* @public
|
|
17
19
|
*/
|
|
18
|
-
export declare const lighterWithdrawableBalances: (account: Pick<LtAccount, "assets" | "available_balance">, settlementAssetIndex: number) => ProviderWithdrawableBalance[];
|
|
20
|
+
export declare const lighterWithdrawableBalances: (account: Pick<LtAccount, "assets" | "available_balance">, settlementAssetIndex: number, perpsCategoryId: string) => ProviderWithdrawableBalance[];
|
|
19
21
|
//# sourceMappingURL=withdrawableBalances.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"withdrawableBalances.d.ts","sourceRoot":"","sources":["../../../src/utils/withdrawableBalances.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,2BAA2B,EAGjC,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,2BAA2B,GACtC,SAAS,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,mBAAmB,CAAC,EACxD,sBAAsB,MAAM,EAC5B,iBAAiB,MAAM,KACtB,2BAA2B,EA8C7B,CAAA"}
|