@lifi/perps-types 18.0.0 → 18.1.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/account.d.ts +63 -62
- package/dist/cjs/account.d.ts.map +1 -1
- package/dist/cjs/action.d.ts +17 -16
- package/dist/cjs/action.d.ts.map +1 -1
- package/dist/cjs/asset.d.ts +2 -1
- package/dist/cjs/asset.d.ts.map +1 -1
- package/dist/cjs/decimal.d.ts +4 -0
- package/dist/cjs/decimal.d.ts.map +1 -0
- package/dist/cjs/decimal.js +9 -0
- package/dist/cjs/decimal.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/market.d.ts +24 -23
- package/dist/cjs/market.d.ts.map +1 -1
- package/dist/cjs/portfolioHistory.d.ts +5 -4
- package/dist/cjs/portfolioHistory.d.ts.map +1 -1
- package/dist/cjs/quote.d.ts +7 -6
- package/dist/cjs/quote.d.ts.map +1 -1
- package/dist/cjs/referral.d.ts +4 -3
- package/dist/cjs/referral.d.ts.map +1 -1
- package/dist/cjs/referral.js.map +1 -1
- package/dist/cjs/subscriptions.d.ts +2 -1
- package/dist/cjs/subscriptions.d.ts.map +1 -1
- package/dist/esm/account.d.ts +63 -62
- package/dist/esm/account.d.ts.map +1 -1
- package/dist/esm/action.d.ts +17 -16
- package/dist/esm/action.d.ts.map +1 -1
- package/dist/esm/asset.d.ts +2 -1
- package/dist/esm/asset.d.ts.map +1 -1
- package/dist/esm/decimal.d.ts +23 -0
- package/dist/esm/decimal.d.ts.map +1 -0
- package/dist/esm/decimal.js +17 -0
- package/dist/esm/decimal.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/market.d.ts +24 -23
- package/dist/esm/market.d.ts.map +1 -1
- package/dist/esm/portfolioHistory.d.ts +5 -4
- package/dist/esm/portfolioHistory.d.ts.map +1 -1
- package/dist/esm/quote.d.ts +7 -6
- package/dist/esm/quote.d.ts.map +1 -1
- package/dist/esm/referral.d.ts +4 -3
- package/dist/esm/referral.d.ts.map +1 -1
- package/dist/esm/referral.js.map +1 -1
- package/dist/esm/subscriptions.d.ts +2 -1
- package/dist/esm/subscriptions.d.ts.map +1 -1
- package/dist/types/account.d.ts +63 -62
- package/dist/types/account.d.ts.map +1 -1
- package/dist/types/action.d.ts +17 -16
- package/dist/types/action.d.ts.map +1 -1
- package/dist/types/asset.d.ts +2 -1
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/decimal.d.ts +23 -0
- package/dist/types/decimal.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/market.d.ts +24 -23
- package/dist/types/market.d.ts.map +1 -1
- package/dist/types/portfolioHistory.d.ts +5 -4
- package/dist/types/portfolioHistory.d.ts.map +1 -1
- package/dist/types/quote.d.ts +7 -6
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/referral.d.ts +4 -3
- package/dist/types/referral.d.ts.map +1 -1
- package/dist/types/subscriptions.d.ts +2 -1
- package/dist/types/subscriptions.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/account.ts +63 -62
- package/src/action.ts +17 -16
- package/src/asset.ts +3 -1
- package/src/decimal.ts +26 -0
- package/src/index.ts +1 -0
- package/src/market.ts +24 -23
- package/src/portfolioHistory.ts +6 -4
- package/src/quote.ts +7 -6
- package/src/referral.ts +4 -3
- package/src/subscriptions.ts +2 -1
package/src/action.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AcceptTermsParams } from './acceptTerms.js'
|
|
2
|
+
import type { DecimalString } from './decimal.js'
|
|
2
3
|
import type {
|
|
3
4
|
ActionType,
|
|
4
5
|
MarginMode,
|
|
@@ -271,13 +272,13 @@ export type ActionResult =
|
|
|
271
272
|
* @public
|
|
272
273
|
*/
|
|
273
274
|
export interface TriggerOrderInput {
|
|
274
|
-
triggerPrice:
|
|
275
|
-
limitPrice?:
|
|
275
|
+
triggerPrice: DecimalString
|
|
276
|
+
limitPrice?: DecimalString
|
|
276
277
|
/**
|
|
277
278
|
* Base-asset size the trigger closes. Omitted covers the entire position,
|
|
278
279
|
* tracking later size changes; set, it is a fixed partial amount.
|
|
279
280
|
*/
|
|
280
|
-
size?:
|
|
281
|
+
size?: DecimalString
|
|
281
282
|
}
|
|
282
283
|
|
|
283
284
|
/**
|
|
@@ -287,10 +288,10 @@ export interface TriggerOrderInput {
|
|
|
287
288
|
*/
|
|
288
289
|
export interface ModifyOrderInput {
|
|
289
290
|
id: string
|
|
290
|
-
price?:
|
|
291
|
-
size?:
|
|
292
|
-
triggerPrice?:
|
|
293
|
-
limitPrice?:
|
|
291
|
+
price?: DecimalString
|
|
292
|
+
size?: DecimalString
|
|
293
|
+
triggerPrice?: DecimalString
|
|
294
|
+
limitPrice?: DecimalString
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
/**
|
|
@@ -302,8 +303,8 @@ export interface PlaceOrderParams {
|
|
|
302
303
|
market: MarketRef
|
|
303
304
|
side: OrderSide
|
|
304
305
|
type?: Exclude<OrderType, OrderType.TWAP>
|
|
305
|
-
size:
|
|
306
|
-
price?:
|
|
306
|
+
size: DecimalString
|
|
307
|
+
price?: DecimalString
|
|
307
308
|
leverage?: number
|
|
308
309
|
/**
|
|
309
310
|
* Hyperliquid: requires `leverage`. Omitted leaves the market's current
|
|
@@ -344,7 +345,7 @@ export interface PlaceTwapOrderParams {
|
|
|
344
345
|
market: MarketRef
|
|
345
346
|
side: OrderSide
|
|
346
347
|
/** Total base-asset size executed across the TWAP's lifetime, as a decimal string. */
|
|
347
|
-
size:
|
|
348
|
+
size: DecimalString
|
|
348
349
|
/** Total execution window in seconds. */
|
|
349
350
|
durationSeconds: number
|
|
350
351
|
reduceOnly?: boolean
|
|
@@ -353,9 +354,9 @@ export interface PlaceTwapOrderParams {
|
|
|
353
354
|
/** Ondo: interval between child orders in seconds. */
|
|
354
355
|
frequencySeconds?: number
|
|
355
356
|
/** Ondo: lowest acceptable child-order price, as a decimal string. */
|
|
356
|
-
minPrice?:
|
|
357
|
+
minPrice?: DecimalString
|
|
357
358
|
/** Ondo: highest acceptable child-order price, as a decimal string. */
|
|
358
|
-
maxPrice?:
|
|
359
|
+
maxPrice?: DecimalString
|
|
359
360
|
}
|
|
360
361
|
|
|
361
362
|
/**
|
|
@@ -417,7 +418,7 @@ export interface UpdateLeverageParams {
|
|
|
417
418
|
export interface UpdatePositionMarginParams {
|
|
418
419
|
market: MarketRef
|
|
419
420
|
action: 'add' | 'remove'
|
|
420
|
-
amount:
|
|
421
|
+
amount: DecimalString
|
|
421
422
|
}
|
|
422
423
|
|
|
423
424
|
/**
|
|
@@ -449,7 +450,7 @@ export type WithdrawalRoute = 'perps' | 'spot'
|
|
|
449
450
|
*/
|
|
450
451
|
export interface WithdrawalParams {
|
|
451
452
|
destination: Address
|
|
452
|
-
amount:
|
|
453
|
+
amount: DecimalString
|
|
453
454
|
/** Lighter: provider-native `Asset.id` to withdraw. Omitted withdraws the quote asset. */
|
|
454
455
|
assetId?: string
|
|
455
456
|
/** Lighter: balance route to draw from. Omitted is `perps`. */
|
|
@@ -469,7 +470,7 @@ export interface WithdrawalParams {
|
|
|
469
470
|
*/
|
|
470
471
|
export interface DepositParams {
|
|
471
472
|
/** Amount of the token to deposit, as an integer string in the token's base units (e.g. "100500000" for 100.5 USDC). */
|
|
472
|
-
amount:
|
|
473
|
+
amount: DecimalString
|
|
473
474
|
/** ERC-20 token address on the source chain. */
|
|
474
475
|
tokenAddress: Address
|
|
475
476
|
/** Chain ID of the source chain (e.g. 1 for Ethereum, 42161 for Arbitrum). */
|
|
@@ -534,7 +535,7 @@ export interface SendAssetParams {
|
|
|
534
535
|
collateral: string
|
|
535
536
|
sourceDex: string
|
|
536
537
|
destinationDex: string
|
|
537
|
-
amount:
|
|
538
|
+
amount: DecimalString
|
|
538
539
|
}
|
|
539
540
|
|
|
540
541
|
/**
|
package/src/asset.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DecimalString } from './decimal.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Underlying token/registry entry. The base entity of the perps taxonomy:
|
|
3
5
|
* a tradable unit referenced by markets (as base/quote legs) and held by
|
|
@@ -32,7 +34,7 @@ export interface Asset {
|
|
|
32
34
|
/** L1 token contract; the zero address denotes native gas. */
|
|
33
35
|
l1Address?: string
|
|
34
36
|
/** Venue minimum for a single withdrawal, denominated in this asset — not USD. */
|
|
35
|
-
minWithdrawalAmount?:
|
|
37
|
+
minWithdrawalAmount?: DecimalString
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/**
|
package/src/decimal.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain decimal string: optional `-`, digits, optional fraction. No grouping,
|
|
3
|
+
* exponent, currency sign or whitespace; matches {@link DECIMAL_PATTERN}. Build
|
|
4
|
+
* it with an SDK `snap*`/`calculate*` helper or a provider, not `.toString()`.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type DecimalString = string
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The single spelling rule for a {@link DecimalString}. It stays byte-identical
|
|
12
|
+
* to the pattern `lifi-perps-backend` matches every stored decimal against, so
|
|
13
|
+
* one amount has exactly one spelling in all three repositories.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export const DECIMAL_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Narrows an unknown value to a {@link DecimalString}.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export function isDecimalString(value: unknown): value is DecimalString {
|
|
25
|
+
return typeof value === 'string' && DECIMAL_PATTERN.test(value)
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
package/src/market.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Asset } from './asset.js'
|
|
2
|
+
import type { DecimalString } from './decimal.js'
|
|
2
3
|
import type { PositionMarginAdjustment } from './enums.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -9,7 +10,7 @@ import type { PositionMarginAdjustment } from './enums.js'
|
|
|
9
10
|
*/
|
|
10
11
|
export interface FundingInfo {
|
|
11
12
|
/** Funding rate as a decimal fraction. */
|
|
12
|
-
rate:
|
|
13
|
+
rate: DecimalString
|
|
13
14
|
/** Next funding timestamp in Unix milliseconds. */
|
|
14
15
|
nextFundingTime: number
|
|
15
16
|
}
|
|
@@ -43,14 +44,14 @@ export interface BaseMarket {
|
|
|
43
44
|
* describe the tick. Format prices through the provider's `formatOrderPrice`
|
|
44
45
|
* rather than applying this field directly.
|
|
45
46
|
*/
|
|
46
|
-
priceIncrement?:
|
|
47
|
+
priceIncrement?: DecimalString
|
|
47
48
|
/**
|
|
48
49
|
* Exact size lot as a plain decimal string (e.g. `'0.05'`). Present when the
|
|
49
50
|
* venue's grid is not a power of ten, where `szDecimals` alone cannot
|
|
50
51
|
* describe the lot. Format sizes through the provider's `formatOrderSize`
|
|
51
52
|
* rather than applying this field directly.
|
|
52
53
|
*/
|
|
53
|
-
sizeIncrement?:
|
|
54
|
+
sizeIncrement?: DecimalString
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -71,11 +72,11 @@ export interface PerpsMarket extends BaseMarket {
|
|
|
71
72
|
* venue-wide `Provider.minOrderValueUsd`, which is a `number`; parse this
|
|
72
73
|
* string before comparing the two.
|
|
73
74
|
*/
|
|
74
|
-
minOrderValueUsd?:
|
|
75
|
+
minOrderValueUsd?: DecimalString
|
|
75
76
|
/** Maximum market-order notional in USD, as a plain decimal string. */
|
|
76
|
-
maxMarketOrderUsd?:
|
|
77
|
+
maxMarketOrderUsd?: DecimalString
|
|
77
78
|
/** Maximum limit-order notional in USD, as a plain decimal string. */
|
|
78
|
-
maxLimitOrderUsd?:
|
|
79
|
+
maxLimitOrderUsd?: DecimalString
|
|
79
80
|
onlyIsolated: boolean
|
|
80
81
|
/** Whether individual position margin can be added and/or removed. */
|
|
81
82
|
positionMarginAdjustment: PositionMarginAdjustment
|
|
@@ -150,16 +151,16 @@ export interface MarketContext {
|
|
|
150
151
|
/** Opaque provider market identifier for this context frame. */
|
|
151
152
|
marketId: string
|
|
152
153
|
/** Current order-book midpoint, as a decimal quote string. */
|
|
153
|
-
midPrice:
|
|
154
|
+
midPrice: DecimalString
|
|
154
155
|
/** Provider mark price, as a decimal quote string. */
|
|
155
|
-
markPrice:
|
|
156
|
-
oraclePrice?:
|
|
157
|
-
prevDayPrice?:
|
|
158
|
-
priceChange24h?:
|
|
159
|
-
volume24h?:
|
|
160
|
-
marketCap?:
|
|
156
|
+
markPrice: DecimalString
|
|
157
|
+
oraclePrice?: DecimalString
|
|
158
|
+
prevDayPrice?: DecimalString
|
|
159
|
+
priceChange24h?: DecimalString
|
|
160
|
+
volume24h?: DecimalString
|
|
161
|
+
marketCap?: DecimalString
|
|
161
162
|
/** Quote-asset open-interest notional as a decimal string. */
|
|
162
|
-
openInterest?:
|
|
163
|
+
openInterest?: DecimalString
|
|
163
164
|
funding?: FundingInfo
|
|
164
165
|
}
|
|
165
166
|
|
|
@@ -176,11 +177,11 @@ export interface PricesResponse {
|
|
|
176
177
|
*/
|
|
177
178
|
export interface Candle {
|
|
178
179
|
t: number
|
|
179
|
-
o:
|
|
180
|
-
h:
|
|
181
|
-
l:
|
|
182
|
-
c:
|
|
183
|
-
v:
|
|
180
|
+
o: DecimalString
|
|
181
|
+
h: DecimalString
|
|
182
|
+
l: DecimalString
|
|
183
|
+
c: DecimalString
|
|
184
|
+
v: DecimalString
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
/** Response containing candles for one provider market and interval. @public */
|
|
@@ -215,8 +216,8 @@ export type OhlcvInterval =
|
|
|
215
216
|
|
|
216
217
|
/** One price/size level in an order book; both values are decimal strings. @public */
|
|
217
218
|
export interface OrderbookLevel {
|
|
218
|
-
price:
|
|
219
|
-
size:
|
|
219
|
+
price: DecimalString
|
|
220
|
+
size: DecimalString
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
/** Snapshot of bids and asks for one market. `timestamp` is Unix milliseconds. @public */
|
|
@@ -232,8 +233,8 @@ export interface OrderbookResponse {
|
|
|
232
233
|
export interface Trade {
|
|
233
234
|
provider: string
|
|
234
235
|
marketId: string
|
|
235
|
-
price:
|
|
236
|
-
size:
|
|
236
|
+
price: DecimalString
|
|
237
|
+
size: DecimalString
|
|
237
238
|
timestamp: number
|
|
238
239
|
side: 'buy' | 'sell'
|
|
239
240
|
id?: string
|
package/src/portfolioHistory.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DecimalString } from './decimal.js'
|
|
2
|
+
|
|
1
3
|
/** Lookback window of a portfolio history read. @public */
|
|
2
4
|
export type PortfolioHistoryRange = '24h' | '7d' | '30d' | 'all'
|
|
3
5
|
|
|
@@ -9,9 +11,9 @@ export type PortfolioHistoryRange = '24h' | '7d' | '30d' | 'all'
|
|
|
9
11
|
export interface PortfolioHistoryPoint {
|
|
10
12
|
/** Unix milliseconds. */
|
|
11
13
|
timestamp: number
|
|
12
|
-
accountValue:
|
|
14
|
+
accountValue: DecimalString
|
|
13
15
|
/** Cumulative PnL from the start of the requested window. */
|
|
14
|
-
pnl:
|
|
16
|
+
pnl: DecimalString
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/**
|
|
@@ -22,6 +24,6 @@ export interface PortfolioHistoryPoint {
|
|
|
22
24
|
export interface PortfolioHistoryResponse {
|
|
23
25
|
range: PortfolioHistoryRange
|
|
24
26
|
points: PortfolioHistoryPoint[]
|
|
25
|
-
volume?:
|
|
26
|
-
totalPnl?:
|
|
27
|
+
volume?: DecimalString
|
|
28
|
+
totalPnl?: DecimalString
|
|
27
29
|
}
|
package/src/quote.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FeeTier } from './account.js'
|
|
2
|
+
import type { DecimalString } from './decimal.js'
|
|
2
3
|
import type { FundingInfo } from './market.js'
|
|
3
4
|
|
|
4
5
|
/** Side of the quoted market order, using lowercase wire values. @public */
|
|
@@ -26,20 +27,20 @@ export interface Quote {
|
|
|
26
27
|
type: TradeType
|
|
27
28
|
side: QuoteSide
|
|
28
29
|
/** Input notional in USD. */
|
|
29
|
-
sizeUsd:
|
|
30
|
+
sizeUsd: DecimalString
|
|
30
31
|
/** Base amount the book filled for `sizeUsd` (or the most obtainable when the book is too thin). */
|
|
31
|
-
baseSize:
|
|
32
|
-
markPrice:
|
|
32
|
+
baseSize: DecimalString
|
|
33
|
+
markPrice: DecimalString
|
|
33
34
|
/** Volume-weighted average fill price from the book walk. */
|
|
34
|
-
expectedFillPrice:
|
|
35
|
+
expectedFillPrice: DecimalString
|
|
35
36
|
/** VWAP deviation from `markPrice` in basis points; non-negative. */
|
|
36
|
-
priceImpactBps:
|
|
37
|
+
priceImpactBps: DecimalString
|
|
37
38
|
/** Base maker/taker fee fractions (not bps) for the public tier. */
|
|
38
39
|
feeTier: FeeTier
|
|
39
40
|
/** Always `true` in v1 — quotes use the public base tier, never a per-account tier. */
|
|
40
41
|
isDefaultFeeTier: boolean
|
|
41
42
|
/** Taker fee on the filled notional in USD: `filledNotional * feeTier.taker`. */
|
|
42
|
-
feeUsd:
|
|
43
|
+
feeUsd: DecimalString
|
|
43
44
|
/** Current funding for perps; `null` for spot. */
|
|
44
45
|
funding: FundingInfo | null
|
|
45
46
|
/** `true` when the book could not fill the full `sizeUsd` — `baseSize`/fill reflect the best obtainable. */
|
package/src/referral.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Pagination } from './account.js'
|
|
2
|
+
import type { DecimalString } from './decimal.js'
|
|
2
3
|
import type { Address } from './primitives.js'
|
|
3
4
|
import type { PerpsTypedData, TypedDataParameter } from './typedData.js'
|
|
4
5
|
|
|
@@ -71,9 +72,9 @@ export interface OwnedReferralCodeEligibility {
|
|
|
71
72
|
* Executed notional the address must reach, as a decimal string in the
|
|
72
73
|
* backend's reporting currency. Absent when the backend does not disclose it.
|
|
73
74
|
*/
|
|
74
|
-
requiredNotional?:
|
|
75
|
+
requiredNotional?: DecimalString
|
|
75
76
|
/** The address's executed notional so far, in the same units as `requiredNotional`. */
|
|
76
|
-
currentNotional?:
|
|
77
|
+
currentNotional?: DecimalString
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
/**
|
|
@@ -125,7 +126,7 @@ export interface ReferralActivityItem {
|
|
|
125
126
|
* Executed notional recorded against this attachment, as a decimal string in
|
|
126
127
|
* the backend's reporting currency.
|
|
127
128
|
*/
|
|
128
|
-
notional:
|
|
129
|
+
notional: DecimalString
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
/**
|
package/src/subscriptions.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
Order,
|
|
7
7
|
Position,
|
|
8
8
|
} from './account.js'
|
|
9
|
+
import type { DecimalString } from './decimal.js'
|
|
9
10
|
import type {
|
|
10
11
|
Candle,
|
|
11
12
|
MarketContext,
|
|
@@ -152,7 +153,7 @@ export type PositionsEvent = { channel: 'positions'; data: Position[] }
|
|
|
152
153
|
*/
|
|
153
154
|
export type SpotBalancesEvent = {
|
|
154
155
|
channel: 'spotBalances'
|
|
155
|
-
data: (Balance & { locked:
|
|
156
|
+
data: (Balance & { locked: DecimalString })[]
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
/**
|