@lifi/perps-sdk 28.0.0 → 29.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 +13 -0
- package/dist/cjs/decimal/format.d.ts +5 -1
- package/dist/cjs/decimal/format.d.ts.map +1 -1
- package/dist/cjs/decimal/format.js +49 -13
- package/dist/cjs/decimal/format.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math/position.d.ts +12 -0
- package/dist/cjs/math/position.d.ts.map +1 -1
- package/dist/cjs/math/position.js +43 -5
- package/dist/cjs/math/position.js.map +1 -1
- package/dist/cjs/types/deposit.d.ts +3 -3
- package/dist/cjs/types/deposit.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +4 -1
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/decimal/format.d.ts +18 -2
- package/dist/esm/decimal/format.d.ts.map +1 -1
- package/dist/esm/decimal/format.js +55 -15
- package/dist/esm/decimal/format.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math/position.d.ts +36 -9
- package/dist/esm/math/position.d.ts.map +1 -1
- package/dist/esm/math/position.js +68 -15
- package/dist/esm/math/position.js.map +1 -1
- package/dist/esm/services/getGasRecommendation.d.ts +2 -2
- package/dist/esm/services/getGasRecommendation.js +1 -1
- package/dist/esm/types/deposit.d.ts +9 -8
- package/dist/esm/types/deposit.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +20 -7
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/utils/depositAssets.d.ts +3 -3
- package/dist/esm/utils/depositAssets.js +3 -3
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/decimal/format.d.ts +18 -2
- package/dist/types/decimal/format.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/math/position.d.ts +36 -9
- package/dist/types/math/position.d.ts.map +1 -1
- package/dist/types/services/getGasRecommendation.d.ts +2 -2
- package/dist/types/types/deposit.d.ts +9 -8
- package/dist/types/types/deposit.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +20 -7
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/utils/depositAssets.d.ts +3 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/decimal/format.ts +127 -13
- package/src/index.ts +6 -2
- package/src/math/position.ts +74 -14
- package/src/services/getGasRecommendation.ts +2 -2
- package/src/types/deposit.ts +9 -8
- package/src/types/provider.ts +20 -6
- package/src/utils/depositAssets.ts +3 -3
- package/src/version.ts +1 -1
package/src/decimal/format.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { DecimalString } from '@lifi/perps-types'
|
|
2
2
|
import Big from 'big.js'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
absDecimalString,
|
|
5
|
+
divideDecimalStringRoundDown,
|
|
6
|
+
multiplyDecimalString,
|
|
7
|
+
} from './arithmetic.js'
|
|
8
|
+
import { compareDecimalStrings } from './compare.js'
|
|
9
|
+
import {
|
|
10
|
+
type DecimalRounding,
|
|
11
|
+
numberToDecimalString,
|
|
12
|
+
roundDecimalString,
|
|
13
|
+
} from './convert.js'
|
|
14
|
+
import { bigToDecimalString, decimalStringToBig } from './decimalStringToBig.js'
|
|
4
15
|
|
|
5
16
|
/**
|
|
6
17
|
* Options shared by the human-facing display formatters.
|
|
@@ -26,6 +37,21 @@ export interface FormatOptions {
|
|
|
26
37
|
rounding?: RoundingMode
|
|
27
38
|
}
|
|
28
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Options for {@link formatCompactUsd}.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export interface CompactUsdOptions extends FormatOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Significant digits of the compact mantissa, with trailing zeros dropped
|
|
48
|
+
* (`$84.5K`, `$1M`). Replaces `decimals` when set.
|
|
49
|
+
*/
|
|
50
|
+
significantDigits?: number
|
|
51
|
+
/** Magnitudes below this value render as {@link formatUsd}, with no suffix. */
|
|
52
|
+
compactFrom?: DecimalString
|
|
53
|
+
}
|
|
54
|
+
|
|
29
55
|
/**
|
|
30
56
|
* Rounding mode for {@link FormatOptions.rounding}.
|
|
31
57
|
*
|
|
@@ -275,20 +301,76 @@ export function formatPrice(
|
|
|
275
301
|
return `${sign}$${body}`
|
|
276
302
|
}
|
|
277
303
|
|
|
304
|
+
const COMPACT_TIER_SIZE = 1_000
|
|
305
|
+
|
|
306
|
+
const COMPACT_TIERS = [
|
|
307
|
+
[1_000, 'K'],
|
|
308
|
+
[1_000_000, 'M'],
|
|
309
|
+
] as const
|
|
310
|
+
|
|
311
|
+
const COMPACT_DECIMAL_ROUNDING: Record<RoundingMode, DecimalRounding> = {
|
|
312
|
+
halfUp: 'round',
|
|
313
|
+
floor: 'truncate',
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Significant digits span the whole number: one digit truncates `84.559` to `80`. */
|
|
317
|
+
function roundToSignificantDigits(
|
|
318
|
+
value: string,
|
|
319
|
+
significantDigits: number,
|
|
320
|
+
rounding: DecimalRounding
|
|
321
|
+
): string {
|
|
322
|
+
const integerPart = roundDecimalString(absDecimalString(value), 0, 'truncate')
|
|
323
|
+
const integerDigits = integerPart === '0' ? 0 : integerPart.length
|
|
324
|
+
const decimals = significantDigits - integerDigits
|
|
325
|
+
if (decimals >= 0) {
|
|
326
|
+
return roundDecimalString(value, decimals, rounding)
|
|
327
|
+
}
|
|
328
|
+
const scale = `1${'0'.repeat(-decimals)}`
|
|
329
|
+
return multiplyDecimalString(
|
|
330
|
+
roundDecimalString(divideDecimalStringRoundDown(value, scale), 0, rounding),
|
|
331
|
+
scale
|
|
332
|
+
)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function compactMantissa(
|
|
336
|
+
value: string,
|
|
337
|
+
divisor: number,
|
|
338
|
+
decimals: number,
|
|
339
|
+
significantDigits: number | undefined,
|
|
340
|
+
rounding: DecimalRounding
|
|
341
|
+
): string {
|
|
342
|
+
const scaled = divideDecimalStringRoundDown(
|
|
343
|
+
value,
|
|
344
|
+
numberToDecimalString(divisor)
|
|
345
|
+
)
|
|
346
|
+
return significantDigits === undefined
|
|
347
|
+
? roundDecimalString(scaled, decimals, rounding)
|
|
348
|
+
: roundToSignificantDigits(scaled, significantDigits, rounding)
|
|
349
|
+
}
|
|
350
|
+
|
|
278
351
|
/**
|
|
279
352
|
* Format a USD value compactly with a `B`/`M`/`K` suffix: `$1.23B`, `$45.6M`,
|
|
280
353
|
* `$789.0K`, `$12.34`.
|
|
281
354
|
*
|
|
282
|
-
*
|
|
355
|
+
* Values below 1000 (or `compactFrom`) render as {@link formatUsd}. Negatives
|
|
356
|
+
* place the `-` before the `$`. `rounding: 'floor'` truncates toward zero, so
|
|
357
|
+
* a compact balance is never overstated. Null/undefined/non-finite input
|
|
283
358
|
* renders the placeholder.
|
|
284
359
|
*
|
|
285
360
|
* @public
|
|
286
361
|
*/
|
|
287
362
|
export function formatCompactUsd(
|
|
288
363
|
value: FormatInput,
|
|
289
|
-
options:
|
|
364
|
+
options: CompactUsdOptions = {}
|
|
290
365
|
): string {
|
|
291
|
-
const {
|
|
366
|
+
const {
|
|
367
|
+
decimals = 2,
|
|
368
|
+
placeholder = DEFAULT_PLACEHOLDER,
|
|
369
|
+
locale,
|
|
370
|
+
rounding = 'halfUp',
|
|
371
|
+
significantDigits,
|
|
372
|
+
compactFrom,
|
|
373
|
+
} = options
|
|
292
374
|
const n = toBig(value)
|
|
293
375
|
if (n === null) {
|
|
294
376
|
return placeholder
|
|
@@ -296,16 +378,48 @@ export function formatCompactUsd(
|
|
|
296
378
|
if (typeof n === 'string') {
|
|
297
379
|
return n
|
|
298
380
|
}
|
|
299
|
-
const
|
|
300
|
-
const abs =
|
|
301
|
-
if (
|
|
302
|
-
|
|
381
|
+
const decimal = bigToDecimalString(n)
|
|
382
|
+
const abs = absDecimalString(decimal)
|
|
383
|
+
if (
|
|
384
|
+
compareDecimalStrings(abs, numberToDecimalString(COMPACT_TIER_SIZE)) < 0 ||
|
|
385
|
+
(compactFrom !== undefined && compareDecimalStrings(abs, compactFrom) < 0)
|
|
386
|
+
) {
|
|
387
|
+
return formatUsd(value, options)
|
|
303
388
|
}
|
|
304
|
-
|
|
305
|
-
|
|
389
|
+
const decimalRounding = COMPACT_DECIMAL_ROUNDING[rounding]
|
|
390
|
+
const render = (mantissa: string, suffix: string): string => {
|
|
391
|
+
const mantissaDecimals =
|
|
392
|
+
significantDigits === undefined
|
|
393
|
+
? decimals
|
|
394
|
+
: (mantissa.split('.')[1]?.length ?? 0)
|
|
395
|
+
return `${formatUsd(mantissa, { locale, decimals: mantissaDecimals })}${suffix}`
|
|
306
396
|
}
|
|
307
|
-
|
|
308
|
-
|
|
397
|
+
// The tier is picked after rounding, so 999,999.99 promotes to M, not 1000K.
|
|
398
|
+
for (const [divisor, suffix] of COMPACT_TIERS) {
|
|
399
|
+
const mantissa = compactMantissa(
|
|
400
|
+
decimal,
|
|
401
|
+
divisor,
|
|
402
|
+
decimals,
|
|
403
|
+
significantDigits,
|
|
404
|
+
decimalRounding
|
|
405
|
+
)
|
|
406
|
+
if (
|
|
407
|
+
compareDecimalStrings(
|
|
408
|
+
absDecimalString(mantissa),
|
|
409
|
+
numberToDecimalString(COMPACT_TIER_SIZE)
|
|
410
|
+
) < 0
|
|
411
|
+
) {
|
|
412
|
+
return render(mantissa, suffix)
|
|
413
|
+
}
|
|
309
414
|
}
|
|
310
|
-
return
|
|
415
|
+
return render(
|
|
416
|
+
compactMantissa(
|
|
417
|
+
decimal,
|
|
418
|
+
1_000_000_000,
|
|
419
|
+
decimals,
|
|
420
|
+
significantDigits,
|
|
421
|
+
decimalRounding
|
|
422
|
+
),
|
|
423
|
+
'B'
|
|
424
|
+
)
|
|
311
425
|
}
|
package/src/index.ts
CHANGED
|
@@ -52,7 +52,11 @@ export {
|
|
|
52
52
|
safeScaledIntegerToDecimalString,
|
|
53
53
|
scaledIntegerToDecimalString,
|
|
54
54
|
} from './decimal/convert.js'
|
|
55
|
-
export type {
|
|
55
|
+
export type {
|
|
56
|
+
CompactUsdOptions,
|
|
57
|
+
FormatOptions,
|
|
58
|
+
RoundingMode,
|
|
59
|
+
} from './decimal/format.js'
|
|
56
60
|
export {
|
|
57
61
|
formatCompactUsd,
|
|
58
62
|
formatNumber,
|
|
@@ -259,9 +263,9 @@ export type {
|
|
|
259
263
|
export type {
|
|
260
264
|
DeclaredDepositAsset,
|
|
261
265
|
DepositFlow,
|
|
262
|
-
DepositFlowFirstDepositPipeline,
|
|
263
266
|
DepositFlowLifiSwap,
|
|
264
267
|
DepositFlowSetupRequired,
|
|
268
|
+
DepositFlowVenueDepositPipeline,
|
|
265
269
|
} from './types/deposit.js'
|
|
266
270
|
export type {
|
|
267
271
|
ActionSignerContribution,
|
package/src/math/position.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
type PerpsMarket,
|
|
16
16
|
type Position,
|
|
17
17
|
PositionMarginAdjustment,
|
|
18
|
+
PositionSide,
|
|
18
19
|
} from '@lifi/perps-types'
|
|
19
20
|
import { DivBig } from '../decimal/big.js'
|
|
20
21
|
import {
|
|
@@ -174,16 +175,27 @@ export const safeCalculateEffectiveLeverage = createSafeFunction(
|
|
|
174
175
|
* margin_available = entryPrice × (1 / leverage - mmr)
|
|
175
176
|
* liq_price = entryPrice - side × margin_available / (1 - mmr × side)
|
|
176
177
|
*
|
|
178
|
+
* With `current`, the order of `size` adds to that position on the same side.
|
|
179
|
+
* The equity of the blended position at `entryPrice` is `current.margin`, the
|
|
180
|
+
* PnL of `current` at `entryPrice`, and the margin of the order. The margin
|
|
181
|
+
* available is that equity minus the maintenance margin of the blended size,
|
|
182
|
+
* and the formula above divides it by the blended size.
|
|
183
|
+
*
|
|
177
184
|
* For existing positions, prefer `Position.liquidationPrice` from the venue.
|
|
178
185
|
*
|
|
179
186
|
* @param maintenanceMarginRate - Venue maintenance margin rate as a fraction
|
|
180
187
|
* (`'0.01'` = 1%).
|
|
181
|
-
* @
|
|
182
|
-
* `
|
|
183
|
-
*
|
|
188
|
+
* @param size - Order size as a non-negative magnitude. Read only with
|
|
189
|
+
* `current`.
|
|
190
|
+
* @param current - Open isolated position on the same side that the order
|
|
191
|
+
* adds to. `margin` is its collateral net of unrealized PnL.
|
|
192
|
+
* @returns The estimate, or `undefined` when the margin above the
|
|
193
|
+
* maintenance requirement is not positive: the position opens at or past
|
|
194
|
+
* liquidation, so the model has no price on the correct side of entry.
|
|
184
195
|
* @throws {PerpsError} `ValidationError` when an input does not match the
|
|
185
|
-
* decimal pattern, `leverage` is zero,
|
|
186
|
-
* zero denominator (`1` for a long, `-1` for a short)
|
|
196
|
+
* decimal pattern, `leverage` is zero, `maintenanceMarginRate` gives a
|
|
197
|
+
* zero denominator (`1` for a long, `-1` for a short), `current` comes
|
|
198
|
+
* without `size`, or `current.size + size` is not positive.
|
|
187
199
|
* @public
|
|
188
200
|
*/
|
|
189
201
|
export function estimateLiquidationPrice(params: {
|
|
@@ -191,6 +203,8 @@ export function estimateLiquidationPrice(params: {
|
|
|
191
203
|
leverage: string
|
|
192
204
|
isLong: boolean
|
|
193
205
|
maintenanceMarginRate: string
|
|
206
|
+
size?: string
|
|
207
|
+
current?: { size: string; entryPrice: string; margin: string }
|
|
194
208
|
}): string | undefined {
|
|
195
209
|
const entryPrice = decimalStringToBig(params.entryPrice)
|
|
196
210
|
const leverage = decimalStringToBig(params.leverage)
|
|
@@ -206,13 +220,38 @@ export function estimateLiquidationPrice(params: {
|
|
|
206
220
|
`must not be ${params.isLong ? '1' : '-1'} for this side`
|
|
207
221
|
)
|
|
208
222
|
}
|
|
209
|
-
|
|
210
|
-
|
|
223
|
+
if (params.current === undefined) {
|
|
224
|
+
const marginFractionAvailable = new DivBig(1).div(leverage).minus(mmr)
|
|
225
|
+
if (marginFractionAvailable.lte(0)) {
|
|
226
|
+
return undefined
|
|
227
|
+
}
|
|
228
|
+
const marginAvailable = marginFractionAvailable.times(entryPrice)
|
|
229
|
+
return bigToDecimalString(
|
|
230
|
+
entryPrice.minus(marginAvailable.times(side).div(denominator))
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
if (params.size === undefined) {
|
|
234
|
+
throw invalidInput('size', 'is required with `current`')
|
|
235
|
+
}
|
|
236
|
+
const addSize = decimalStringToBig(params.size)
|
|
237
|
+
const currentSize = decimalStringToBig(params.current.size)
|
|
238
|
+
const currentEntry = decimalStringToBig(params.current.entryPrice)
|
|
239
|
+
const currentMargin = decimalStringToBig(params.current.margin)
|
|
240
|
+
const totalSize = currentSize.plus(addSize)
|
|
241
|
+
if (totalSize.lte(0)) {
|
|
242
|
+
throw invalidInput('size + current.size', 'must be positive')
|
|
243
|
+
}
|
|
244
|
+
const equity = currentMargin
|
|
245
|
+
.plus(currentSize.times(entryPrice.minus(currentEntry)).times(side))
|
|
246
|
+
.plus(new DivBig(entryPrice).times(addSize).div(leverage))
|
|
247
|
+
const marginAvailablePerUnit = new DivBig(equity)
|
|
248
|
+
.minus(mmr.times(totalSize).times(entryPrice))
|
|
249
|
+
.div(totalSize)
|
|
250
|
+
if (marginAvailablePerUnit.lte(0)) {
|
|
211
251
|
return undefined
|
|
212
252
|
}
|
|
213
|
-
const marginAvailable = marginFractionAvailable.times(entryPrice)
|
|
214
253
|
return bigToDecimalString(
|
|
215
|
-
entryPrice.minus(
|
|
254
|
+
entryPrice.minus(marginAvailablePerUnit.times(side).div(denominator))
|
|
216
255
|
)
|
|
217
256
|
}
|
|
218
257
|
|
|
@@ -223,12 +262,16 @@ export const safeEstimateLiquidationPrice = createSafeFunction(
|
|
|
223
262
|
)
|
|
224
263
|
|
|
225
264
|
/**
|
|
226
|
-
* Estimate the liquidation price of
|
|
227
|
-
* `market.maintenanceMarginRate
|
|
265
|
+
* Estimate the liquidation price of the isolated position that an order
|
|
266
|
+
* leaves, from the flat `market.maintenanceMarginRate`: a new position, or
|
|
267
|
+
* the blend of the order into `params.position`. The collateral of the
|
|
268
|
+
* position is `position.marginUsed`, so the venue `marginUsed` must exclude
|
|
269
|
+
* the unrealized PnL, as Lighter `allocated_margin` does.
|
|
228
270
|
*
|
|
229
271
|
* @returns The estimate, or `undefined` when the market carries no
|
|
230
|
-
* `maintenanceMarginRate
|
|
231
|
-
*
|
|
272
|
+
* `maintenanceMarginRate`, when the order or the position is cross (the
|
|
273
|
+
* liquidation depends on the whole account), when the order reduces the
|
|
274
|
+
* position, or when {@link estimateLiquidationPrice} gives `undefined`.
|
|
232
275
|
* @throws {PerpsError} `ValidationError` on an input that
|
|
233
276
|
* {@link estimateLiquidationPrice} rejects.
|
|
234
277
|
* @public
|
|
@@ -237,7 +280,14 @@ export function estimateLiquidationPriceAtMarketRate(
|
|
|
237
280
|
market: PerpsMarket,
|
|
238
281
|
params: LiquidationEstimateParams
|
|
239
282
|
): string | undefined {
|
|
240
|
-
|
|
283
|
+
const { position } = params
|
|
284
|
+
if (
|
|
285
|
+
market.maintenanceMarginRate === undefined ||
|
|
286
|
+
params.marginMode === MarginMode.CROSS ||
|
|
287
|
+
position?.marginMode === MarginMode.CROSS ||
|
|
288
|
+
(position !== undefined &&
|
|
289
|
+
(position.side === PositionSide.LONG) !== params.isLong)
|
|
290
|
+
) {
|
|
241
291
|
return undefined
|
|
242
292
|
}
|
|
243
293
|
return estimateLiquidationPrice({
|
|
@@ -245,6 +295,16 @@ export function estimateLiquidationPriceAtMarketRate(
|
|
|
245
295
|
leverage: params.leverage,
|
|
246
296
|
isLong: params.isLong,
|
|
247
297
|
maintenanceMarginRate: market.maintenanceMarginRate,
|
|
298
|
+
size: params.size,
|
|
299
|
+
...(position === undefined
|
|
300
|
+
? {}
|
|
301
|
+
: {
|
|
302
|
+
current: {
|
|
303
|
+
size: position.size,
|
|
304
|
+
entryPrice: position.entryPrice,
|
|
305
|
+
margin: position.marginUsed,
|
|
306
|
+
},
|
|
307
|
+
}),
|
|
248
308
|
})
|
|
249
309
|
}
|
|
250
310
|
|
|
@@ -17,13 +17,13 @@ export const LIFI_API_URL = 'https://li.quest/v1'
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export interface GetGasRecommendationParams {
|
|
20
|
-
/** Chain to hold native gas on — a `
|
|
20
|
+
/** Chain to hold native gas on — a `venueDepositPipeline` flow's `chainId`. */
|
|
21
21
|
chainId: number
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* How much native gas LI.FI suggests holding on `params.chainId` to transact
|
|
26
|
-
* there, for seeding the gas leg of a
|
|
26
|
+
* there, for seeding the gas leg of a venue-deposit pipeline. Read straight
|
|
27
27
|
* from the LI.FI API by the user's client.
|
|
28
28
|
*
|
|
29
29
|
* @returns The suggestion, with `available: false` and no amounts on a chain
|
package/src/types/deposit.ts
CHANGED
|
@@ -37,20 +37,21 @@ export interface DepositFlowLifiSwap {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* Fund an address that has no venue account yet
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
* Fund an address that has no venue account yet, or an existing account on a
|
|
41
|
+
* venue whose collateral no LI.FI route credits directly. Collateral and the
|
|
42
|
+
* native gas to broadcast with are both needed on `chainId`, where the venue's
|
|
43
|
+
* {@link ActionType.DEPOSIT} action stages the on-chain legs that credit the
|
|
44
|
+
* account and open it when none exists.
|
|
44
45
|
*
|
|
45
46
|
* @public
|
|
46
47
|
*/
|
|
47
|
-
export interface
|
|
48
|
-
kind: '
|
|
48
|
+
export interface DepositFlowVenueDepositPipeline {
|
|
49
|
+
kind: 'venueDepositPipeline'
|
|
49
50
|
/** Chain on which the deposit legs broadcast; the wallet must be switched here. */
|
|
50
51
|
chainId: number
|
|
51
52
|
/** Native gas asset needed to broadcast the deposit legs. */
|
|
52
53
|
gasAsset: DeclaredDepositAsset
|
|
53
|
-
/** Collateral asset
|
|
54
|
+
/** Collateral asset the venue deposit credits. */
|
|
54
55
|
collateral: DeclaredDepositAsset
|
|
55
56
|
/** Action type used to stage the deposit pipeline. */
|
|
56
57
|
bridgeAction: ActionType.DEPOSIT
|
|
@@ -77,5 +78,5 @@ export interface DepositFlowSetupRequired {
|
|
|
77
78
|
*/
|
|
78
79
|
export type DepositFlow =
|
|
79
80
|
| DepositFlowLifiSwap
|
|
80
|
-
|
|
|
81
|
+
| DepositFlowVenueDepositPipeline
|
|
81
82
|
| DepositFlowSetupRequired
|
package/src/types/provider.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
AvailableToTrade,
|
|
12
12
|
DecimalString,
|
|
13
13
|
FillsResponse,
|
|
14
|
+
MarginMode,
|
|
14
15
|
Market,
|
|
15
16
|
MarketRef,
|
|
16
17
|
MarketSettings,
|
|
@@ -160,7 +161,8 @@ export interface ActionSignerContribution {
|
|
|
160
161
|
}
|
|
161
162
|
|
|
162
163
|
/**
|
|
163
|
-
* Inputs for {@link PerpsProviderPlugin.estimateLiquidationPrice}:
|
|
164
|
+
* Inputs for {@link PerpsProviderPlugin.estimateLiquidationPrice}: the order
|
|
165
|
+
* and, when the order adds to one, the open position on the market.
|
|
164
166
|
* `leverage` is the user-selected leverage for the new position, `isLong`
|
|
165
167
|
* carries direction.
|
|
166
168
|
*
|
|
@@ -172,6 +174,14 @@ export interface LiquidationEstimateParams {
|
|
|
172
174
|
leverage: string
|
|
173
175
|
/** `true` for long, `false` for short. */
|
|
174
176
|
isLong: boolean
|
|
177
|
+
marginMode: MarginMode
|
|
178
|
+
/**
|
|
179
|
+
* Order size in base-asset units. The estimate reads it only with
|
|
180
|
+
* `position`, to blend the order into that position.
|
|
181
|
+
*/
|
|
182
|
+
size?: DecimalString
|
|
183
|
+
/** Open position on the market that the order joins. */
|
|
184
|
+
position?: Position
|
|
175
185
|
}
|
|
176
186
|
|
|
177
187
|
/**
|
|
@@ -633,16 +643,20 @@ export interface PerpsProviderPlugin {
|
|
|
633
643
|
}
|
|
634
644
|
|
|
635
645
|
/**
|
|
636
|
-
* Estimate the liquidation price of
|
|
637
|
-
* using the venue's margin model
|
|
646
|
+
* Estimate the liquidation price of the position that the order leaves on
|
|
647
|
+
* `market` using the venue's margin model: a new position, or the blend of
|
|
648
|
+
* the order into `params.position`. A preview helper — for existing
|
|
638
649
|
* positions, prefer `Position.liquidationPrice` from the venue. Pure —
|
|
639
650
|
* does no I/O.
|
|
640
651
|
*
|
|
641
652
|
* @returns The estimated liquidation price, or `undefined` when `market`
|
|
642
|
-
* lacks the margin metadata the model needs
|
|
643
|
-
* margin above the maintenance requirement
|
|
653
|
+
* lacks the margin metadata the model needs, `leverage` leaves no
|
|
654
|
+
* margin above the maintenance requirement, or the venue model cannot
|
|
655
|
+
* give a correct price for the margin mode and position, such as a cross
|
|
656
|
+
* position whose liquidation depends on the whole account.
|
|
644
657
|
* @throws {PerpsError} `ValidationError` when an input does not match the
|
|
645
|
-
* decimal pattern or is degenerate, such as a zero leverage
|
|
658
|
+
* decimal pattern or is degenerate, such as a zero leverage or a
|
|
659
|
+
* `position` without a `size`.
|
|
646
660
|
*/
|
|
647
661
|
estimateLiquidationPrice(
|
|
648
662
|
market: PerpsMarket,
|
|
@@ -3,7 +3,7 @@ import { zeroAddress } from 'viem'
|
|
|
3
3
|
import type { DeclaredDepositAsset } from '../types/deposit.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* USDC on Ethereum mainnet — the collateral leg of Lighter's
|
|
6
|
+
* USDC on Ethereum mainnet — the collateral leg of Lighter's venue-deposit
|
|
7
7
|
* pipeline, and the token Ondo's provisioned deposit address is funded in.
|
|
8
8
|
*
|
|
9
9
|
* @public
|
|
@@ -15,7 +15,7 @@ export const ETHEREUM_USDC: DeclaredDepositAsset = {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Ether on Ethereum mainnet, to broadcast the
|
|
18
|
+
* Ether on Ethereum mainnet, to broadcast the venue-deposit pipeline's legs
|
|
19
19
|
* with.
|
|
20
20
|
*
|
|
21
21
|
* @public
|
|
@@ -65,7 +65,7 @@ export const ROBINHOOD_USDG: DeclaredDepositAsset = {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Ether on Robinhood Chain, to broadcast the Robinhood
|
|
68
|
+
* Ether on Robinhood Chain, to broadcast the Robinhood venue-deposit pipeline's
|
|
69
69
|
* legs with.
|
|
70
70
|
*
|
|
71
71
|
* @public
|
package/src/version.ts
CHANGED