@lifi/perps-types 0.0.0-preview-a5f5e3b

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.
Files changed (170) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +48 -0
  3. package/dist/cjs/acceptTerms.d.ts +20 -0
  4. package/dist/cjs/acceptTerms.d.ts.map +1 -0
  5. package/dist/cjs/acceptTerms.js +10 -0
  6. package/dist/cjs/acceptTerms.js.map +1 -0
  7. package/dist/cjs/account.d.ts +191 -0
  8. package/dist/cjs/account.d.ts.map +1 -0
  9. package/dist/cjs/account.js +3 -0
  10. package/dist/cjs/account.js.map +1 -0
  11. package/dist/cjs/action.d.ts +200 -0
  12. package/dist/cjs/action.d.ts.map +1 -0
  13. package/dist/cjs/action.js +3 -0
  14. package/dist/cjs/action.js.map +1 -0
  15. package/dist/cjs/asset.d.ts +11 -0
  16. package/dist/cjs/asset.d.ts.map +1 -0
  17. package/dist/cjs/asset.js +3 -0
  18. package/dist/cjs/asset.js.map +1 -0
  19. package/dist/cjs/enums.d.ts +148 -0
  20. package/dist/cjs/enums.d.ts.map +1 -0
  21. package/dist/cjs/enums.js +170 -0
  22. package/dist/cjs/enums.js.map +1 -0
  23. package/dist/cjs/errors.d.ts +7 -0
  24. package/dist/cjs/errors.d.ts.map +1 -0
  25. package/dist/cjs/errors.js +3 -0
  26. package/dist/cjs/errors.js.map +1 -0
  27. package/dist/cjs/index.d.ts +15 -0
  28. package/dist/cjs/index.d.ts.map +1 -0
  29. package/dist/cjs/index.js +31 -0
  30. package/dist/cjs/index.js.map +1 -0
  31. package/dist/cjs/market.d.ts +69 -0
  32. package/dist/cjs/market.d.ts.map +1 -0
  33. package/dist/cjs/market.js +3 -0
  34. package/dist/cjs/market.js.map +1 -0
  35. package/dist/cjs/meta.d.ts +17 -0
  36. package/dist/cjs/meta.d.ts.map +1 -0
  37. package/dist/cjs/meta.js +3 -0
  38. package/dist/cjs/meta.js.map +1 -0
  39. package/dist/cjs/package.json +1 -0
  40. package/dist/cjs/primitives.d.ts +3 -0
  41. package/dist/cjs/primitives.d.ts.map +1 -0
  42. package/dist/cjs/primitives.js +3 -0
  43. package/dist/cjs/primitives.js.map +1 -0
  44. package/dist/cjs/providers.d.ts +58 -0
  45. package/dist/cjs/providers.d.ts.map +1 -0
  46. package/dist/cjs/providers.js +3 -0
  47. package/dist/cjs/providers.js.map +1 -0
  48. package/dist/cjs/quote.d.ts +23 -0
  49. package/dist/cjs/quote.d.ts.map +1 -0
  50. package/dist/cjs/quote.js +3 -0
  51. package/dist/cjs/quote.js.map +1 -0
  52. package/dist/cjs/subscriptions.d.ts +77 -0
  53. package/dist/cjs/subscriptions.d.ts.map +1 -0
  54. package/dist/cjs/subscriptions.js +3 -0
  55. package/dist/cjs/subscriptions.js.map +1 -0
  56. package/dist/cjs/typedData.d.ts +23 -0
  57. package/dist/cjs/typedData.d.ts.map +1 -0
  58. package/dist/cjs/typedData.js +3 -0
  59. package/dist/cjs/typedData.js.map +1 -0
  60. package/dist/cjs/vote.d.ts +27 -0
  61. package/dist/cjs/vote.d.ts.map +1 -0
  62. package/dist/cjs/vote.js +12 -0
  63. package/dist/cjs/vote.js.map +1 -0
  64. package/dist/esm/acceptTerms.d.ts +45 -0
  65. package/dist/esm/acceptTerms.d.ts.map +1 -0
  66. package/dist/esm/acceptTerms.js +12 -0
  67. package/dist/esm/acceptTerms.js.map +1 -0
  68. package/dist/esm/account.d.ts +229 -0
  69. package/dist/esm/account.d.ts.map +1 -0
  70. package/dist/esm/account.js +2 -0
  71. package/dist/esm/account.js.map +1 -0
  72. package/dist/esm/action.d.ts +248 -0
  73. package/dist/esm/action.d.ts.map +1 -0
  74. package/dist/esm/action.js +2 -0
  75. package/dist/esm/action.js.map +1 -0
  76. package/dist/esm/asset.d.ts +25 -0
  77. package/dist/esm/asset.d.ts.map +1 -0
  78. package/dist/esm/asset.js +2 -0
  79. package/dist/esm/asset.js.map +1 -0
  80. package/dist/esm/enums.d.ts +171 -0
  81. package/dist/esm/enums.d.ts.map +1 -0
  82. package/dist/esm/enums.js +195 -0
  83. package/dist/esm/enums.js.map +1 -0
  84. package/dist/esm/errors.d.ts +8 -0
  85. package/dist/esm/errors.d.ts.map +1 -0
  86. package/dist/esm/errors.js +2 -0
  87. package/dist/esm/errors.js.map +1 -0
  88. package/dist/esm/index.d.ts +23 -0
  89. package/dist/esm/index.d.ts.map +1 -0
  90. package/dist/esm/index.js +23 -0
  91. package/dist/esm/index.js.map +1 -0
  92. package/dist/esm/market.d.ts +102 -0
  93. package/dist/esm/market.d.ts.map +1 -0
  94. package/dist/esm/market.js +2 -0
  95. package/dist/esm/market.js.map +1 -0
  96. package/dist/esm/meta.d.ts +37 -0
  97. package/dist/esm/meta.d.ts.map +1 -0
  98. package/dist/esm/meta.js +2 -0
  99. package/dist/esm/meta.js.map +1 -0
  100. package/dist/esm/package.json +1 -0
  101. package/dist/esm/primitives.d.ts +5 -0
  102. package/dist/esm/primitives.d.ts.map +1 -0
  103. package/dist/esm/primitives.js +2 -0
  104. package/dist/esm/primitives.js.map +1 -0
  105. package/dist/esm/providers.d.ts +116 -0
  106. package/dist/esm/providers.d.ts.map +1 -0
  107. package/dist/esm/providers.js +2 -0
  108. package/dist/esm/providers.js.map +1 -0
  109. package/dist/esm/quote.d.ts +47 -0
  110. package/dist/esm/quote.d.ts.map +1 -0
  111. package/dist/esm/quote.js +2 -0
  112. package/dist/esm/quote.js.map +1 -0
  113. package/dist/esm/subscriptions.d.ts +115 -0
  114. package/dist/esm/subscriptions.d.ts.map +1 -0
  115. package/dist/esm/subscriptions.js +2 -0
  116. package/dist/esm/subscriptions.js.map +1 -0
  117. package/dist/esm/typedData.d.ts +28 -0
  118. package/dist/esm/typedData.d.ts.map +1 -0
  119. package/dist/esm/typedData.js +2 -0
  120. package/dist/esm/typedData.js.map +1 -0
  121. package/dist/esm/vote.d.ts +68 -0
  122. package/dist/esm/vote.d.ts.map +1 -0
  123. package/dist/esm/vote.js +20 -0
  124. package/dist/esm/vote.js.map +1 -0
  125. package/dist/types/acceptTerms.d.ts +45 -0
  126. package/dist/types/acceptTerms.d.ts.map +1 -0
  127. package/dist/types/account.d.ts +229 -0
  128. package/dist/types/account.d.ts.map +1 -0
  129. package/dist/types/action.d.ts +248 -0
  130. package/dist/types/action.d.ts.map +1 -0
  131. package/dist/types/asset.d.ts +25 -0
  132. package/dist/types/asset.d.ts.map +1 -0
  133. package/dist/types/enums.d.ts +171 -0
  134. package/dist/types/enums.d.ts.map +1 -0
  135. package/dist/types/errors.d.ts +8 -0
  136. package/dist/types/errors.d.ts.map +1 -0
  137. package/dist/types/index.d.ts +23 -0
  138. package/dist/types/index.d.ts.map +1 -0
  139. package/dist/types/market.d.ts +102 -0
  140. package/dist/types/market.d.ts.map +1 -0
  141. package/dist/types/meta.d.ts +37 -0
  142. package/dist/types/meta.d.ts.map +1 -0
  143. package/dist/types/primitives.d.ts +5 -0
  144. package/dist/types/primitives.d.ts.map +1 -0
  145. package/dist/types/providers.d.ts +116 -0
  146. package/dist/types/providers.d.ts.map +1 -0
  147. package/dist/types/quote.d.ts +47 -0
  148. package/dist/types/quote.d.ts.map +1 -0
  149. package/dist/types/subscriptions.d.ts +115 -0
  150. package/dist/types/subscriptions.d.ts.map +1 -0
  151. package/dist/types/typedData.d.ts +28 -0
  152. package/dist/types/typedData.d.ts.map +1 -0
  153. package/dist/types/vote.d.ts +68 -0
  154. package/dist/types/vote.d.ts.map +1 -0
  155. package/package.json +49 -0
  156. package/src/acceptTerms.ts +53 -0
  157. package/src/account.ts +277 -0
  158. package/src/action.ts +292 -0
  159. package/src/asset.ts +25 -0
  160. package/src/enums.ts +205 -0
  161. package/src/errors.ts +8 -0
  162. package/src/index.ts +23 -0
  163. package/src/market.ts +132 -0
  164. package/src/meta.ts +38 -0
  165. package/src/primitives.ts +5 -0
  166. package/src/providers.ts +122 -0
  167. package/src/quote.ts +49 -0
  168. package/src/subscriptions.ts +118 -0
  169. package/src/typedData.ts +32 -0
  170. package/src/vote.ts +79 -0
package/src/action.ts ADDED
@@ -0,0 +1,292 @@
1
+ import type { AcceptTermsParams } from './acceptTerms.js'
2
+ import type {
3
+ ActionType,
4
+ MarginMode,
5
+ OrderSide,
6
+ OrderStatus,
7
+ OrderType,
8
+ TimeInForce,
9
+ TriggerCondition,
10
+ } from './enums.js'
11
+ import type { MarketDisplay, MarketRef } from './market.js'
12
+ import type { Address, Hex } from './primitives.js'
13
+ import type { PerpsTypedData } from './typedData.js'
14
+ import type { VoteParams } from './vote.js'
15
+
16
+ /** @public */
17
+ export interface Eip712ActionStep {
18
+ action: ActionType
19
+ typedData: PerpsTypedData
20
+ }
21
+
22
+ /** @public */
23
+ export interface WasmBlobActionStep {
24
+ action: ActionType
25
+ wasmSignParams: Record<string, unknown>
26
+ }
27
+
28
+ /** @public */
29
+ export interface EvmTxActionStep {
30
+ action: ActionType
31
+ txParams: Record<string, unknown>
32
+ }
33
+
34
+ /** @public */
35
+ export type ActionStep = Eip712ActionStep | WasmBlobActionStep | EvmTxActionStep
36
+
37
+ /** @public */
38
+ export interface Eip712SignedActionStep {
39
+ action: ActionType
40
+ typedData: PerpsTypedData
41
+ signature: Hex
42
+ }
43
+
44
+ /** @public */
45
+ export interface WasmBlobSignedActionStep {
46
+ action: ActionType
47
+ wasmSignParams: Record<string, unknown>
48
+ signedTx: {
49
+ txType: number
50
+ txInfo: string
51
+ txHash: string
52
+ }
53
+ }
54
+
55
+ /** @public */
56
+ export interface EvmTxSignedActionStep {
57
+ action: ActionType
58
+ txParams: Record<string, unknown>
59
+ txHash: string
60
+ }
61
+
62
+ /** @public */
63
+ export type SignedActionStep =
64
+ | Eip712SignedActionStep
65
+ | WasmBlobSignedActionStep
66
+ | EvmTxSignedActionStep
67
+
68
+ /** @public */
69
+ export type ActionResult =
70
+ | {
71
+ action: ActionType
72
+ success: true
73
+ orderId?: string
74
+ }
75
+ | {
76
+ action: ActionType
77
+ success: false
78
+ error: string
79
+ }
80
+
81
+ /** @public */
82
+ export interface TriggerOrderInput {
83
+ triggerPrice: string
84
+ limitPrice?: string
85
+ }
86
+
87
+ /** @public */
88
+ export interface ModifyOrderInput {
89
+ id: string
90
+ price?: string
91
+ size?: string
92
+ triggerPrice?: string
93
+ limitPrice?: string
94
+ }
95
+
96
+ /** @public */
97
+ export interface Order {
98
+ orderId: string
99
+ market: MarketDisplay
100
+ side: OrderSide
101
+ type: OrderType
102
+ price?: string
103
+ originalSize: string
104
+ remainingSize: string
105
+ filledSize: string
106
+ timeInForce?: TimeInForce
107
+ expiresAt?: string
108
+ reduceOnly?: boolean
109
+ isTrigger?: boolean
110
+ triggerPrice?: string
111
+ triggerCondition?: TriggerCondition
112
+ status: OrderStatus
113
+ /** Human-readable reason for a terminal non-FILLED status; undefined when no actionable detail. */
114
+ statusReason?: string
115
+ averagePrice?: string
116
+ createdAt: string
117
+ updatedAt: string
118
+ }
119
+
120
+ /** @public */
121
+ export interface PlaceOrderParams {
122
+ market: MarketRef
123
+ side: OrderSide
124
+ type?: OrderType
125
+ size: string
126
+ price?: string
127
+ leverage?: number
128
+ /** Omitted falls back to the provider's default (currently CROSS). */
129
+ marginMode?: MarginMode
130
+ reduceOnly?: boolean
131
+ timeInForce?: TimeInForce
132
+ expiresAt?: string
133
+ takeProfit?: TriggerOrderInput
134
+ stopLoss?: TriggerOrderInput
135
+ }
136
+
137
+ /** @public */
138
+ export interface PlaceTriggerOrderParams {
139
+ market: MarketRef
140
+ side: OrderSide
141
+ takeProfit?: TriggerOrderInput
142
+ stopLoss?: TriggerOrderInput
143
+ }
144
+
145
+ /** @public */
146
+ export interface CancelOrderParams {
147
+ ids: string[]
148
+ }
149
+
150
+ /** @public */
151
+ export interface ModifyOrderParams {
152
+ modifications: ModifyOrderInput[]
153
+ }
154
+
155
+ /** @public */
156
+ export interface UpdateLeverageParams {
157
+ market: MarketRef
158
+ leverage: number
159
+ /** Omitted falls back to the provider's default (currently CROSS). */
160
+ marginMode?: MarginMode
161
+ }
162
+
163
+ /** @public */
164
+ export interface UpdatePositionMarginParams {
165
+ market: MarketRef
166
+ action: 'add' | 'remove'
167
+ amount: string
168
+ }
169
+
170
+ /** @public */
171
+ export interface WithdrawalParams {
172
+ destination: Address
173
+ amount: string
174
+ }
175
+
176
+ /** @public */
177
+ export interface DepositParams {
178
+ /** Amount of the token to deposit (human-readable, e.g. "100.5"). */
179
+ amount: string
180
+ /** ERC-20 token address on the source chain. */
181
+ tokenAddress: Address
182
+ /** Chain ID of the source chain (e.g. 1 for Ethereum, 42161 for Arbitrum). */
183
+ chainId: number
184
+ }
185
+
186
+ /** @public */
187
+ export interface ApproveAgentParams {
188
+ agentAddress: string
189
+ agentTtlMs?: number
190
+ }
191
+
192
+ /** @public */
193
+ export interface AccountModeParams {
194
+ mode: string
195
+ }
196
+
197
+ /** @public */
198
+ export interface AccountTypeParams {
199
+ tier: string
200
+ }
201
+
202
+ /** @public */
203
+ export interface SendAssetParams {
204
+ collateral: string
205
+ sourceDex: string
206
+ destinationDex: string
207
+ amount: string
208
+ }
209
+
210
+ /** @public */
211
+ export interface CancelAllOrdersParams {
212
+ /** 0=immediate (cancel GTC), 1=scheduled, 2=abort scheduled */
213
+ timeInForce: number
214
+ /** Unix timestamp in milliseconds (required for scheduled cancels) */
215
+ timestampMs?: number
216
+ }
217
+
218
+ /** @public */
219
+ export interface RegisterApiKeyParams {
220
+ /** The API key slot index to register (0-255). Reusing a fixed slot overwrites the old key. */
221
+ apiKeyIndex: number
222
+ /**
223
+ * The SDK's currently-stored Lighter public key for this slot, if any. The
224
+ * backend returns `[]` (already satisfied) only when this equals the
225
+ * on-chain pubkey at the slot; otherwise it stages a ChangePubKey blob so
226
+ * the slot can be (re-)registered. Omit when the SDK has no local key.
227
+ */
228
+ knownPublicKey?: string
229
+ }
230
+
231
+ /** @public */
232
+ export interface ApproveReadOnlyTokenParams {
233
+ accountIndex: number
234
+ /** Absolute unix-seconds expiry. Lighter requires lifetime between 1 day and 10 years. */
235
+ expirySeconds: number
236
+ scope: 'single' | 'all'
237
+ }
238
+
239
+ /** @public */
240
+ export interface ActionParamsMap {
241
+ [ActionType.APPROVE_AGENT]: ApproveAgentParams
242
+ [ActionType.APPROVE_BUILDER_FEE]: Record<string, never>
243
+ [ActionType.ACCOUNT_MODE]: AccountModeParams
244
+ [ActionType.ACCOUNT_TYPE]: AccountTypeParams
245
+ [ActionType.SEND_ASSET]: SendAssetParams
246
+ [ActionType.WITHDRAWAL]: WithdrawalParams
247
+ [ActionType.TRANSFER]: Record<string, never>
248
+ [ActionType.PLACE_ORDER]: PlaceOrderParams
249
+ [ActionType.PLACE_TRIGGER_ORDER]: PlaceTriggerOrderParams
250
+ [ActionType.CANCEL_ORDER]: CancelOrderParams
251
+ [ActionType.CANCEL_ALL_ORDERS]: CancelAllOrdersParams
252
+ [ActionType.MODIFY_ORDER]: ModifyOrderParams
253
+ [ActionType.UPDATE_LEVERAGE]: UpdateLeverageParams
254
+ [ActionType.UPDATE_POSITION_MARGIN]: UpdatePositionMarginParams
255
+ [ActionType.REGISTER_API_KEY]: RegisterApiKeyParams
256
+ [ActionType.APPROVE_READ_ONLY_TOKEN]: ApproveReadOnlyTokenParams
257
+ [ActionType.DEPOSIT]: DepositParams
258
+ [ActionType.META_VOTE]: VoteParams
259
+ [ActionType.META_ACCEPT_TERMS]: AcceptTermsParams
260
+ }
261
+
262
+ /** @public */
263
+ export type CreateActionRequest = {
264
+ [K in ActionType]: {
265
+ provider: string
266
+ address: Address
267
+ signerAddress?: Address
268
+ action: K
269
+ params: ActionParamsMap[K]
270
+ }
271
+ }[ActionType]
272
+
273
+ /** @public */
274
+ export interface CreateActionResponse {
275
+ actions: ActionStep[]
276
+ }
277
+
278
+ /** @public */
279
+ export type ExecuteActionRequest = {
280
+ [K in ActionType]: {
281
+ provider: string
282
+ address: Address
283
+ signerAddress?: Address
284
+ action: K
285
+ actions: SignedActionStep[]
286
+ }
287
+ }[ActionType]
288
+
289
+ /** @public */
290
+ export interface ExecuteActionResponse {
291
+ results: ActionResult[]
292
+ }
package/src/asset.ts ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Underlying token/registry entry. The base entity of the perps taxonomy:
3
+ * a tradable unit referenced by markets (as base/quote legs) and held by
4
+ * accounts (as balances). NOT a market — see {@link BaseMarket}.
5
+ * @public
6
+ */
7
+ export interface Asset {
8
+ providerId: string
9
+ /**
10
+ * The asset's own provider-native id. Lighter: numeric `asset_id`, stringified.
11
+ * Hyperliquid spot: the venue token index (`spotMeta.tokens[].index`, the
12
+ * value HL carries in a balance's `token` field) — identical to that token's
13
+ * spot `Market.baseAsset.id`, so a held balance resolves to its market by
14
+ * identity. NEVER the coin symbol (that is `displaySymbol`).
15
+ */
16
+ id: string
17
+ displaySymbol: string
18
+ logoURI: string
19
+ displayName?: string
20
+ }
21
+
22
+ /** @public */
23
+ export interface AssetsResponse {
24
+ assets: Asset[]
25
+ }
package/src/enums.ts ADDED
@@ -0,0 +1,205 @@
1
+ /** @public */
2
+ export enum PerpsErrorCode {
3
+ // Base errors (2000-2009)
4
+ DefaultError = 2000,
5
+ ServerError = 2001,
6
+ ValidationError = 2002,
7
+ TimeoutError = 2003,
8
+ ThirdPartyError = 2004,
9
+ SDKError = 2005,
10
+
11
+ // Auth errors (2010-2019)
12
+ SignatureInvalid = 2010,
13
+ AgentUnauthorized = 2011,
14
+ TermsNotAccepted = 2012,
15
+
16
+ // Trading errors (2020-2039)
17
+ ExchangeRejected = 2020,
18
+ InsufficientMargin = 2021,
19
+ InsufficientBalance = 2022,
20
+ MarketNotFound = 2023,
21
+ OrderNotFound = 2024,
22
+ PositionNotFound = 2025,
23
+ AccountNotFound = 2026,
24
+
25
+ // Nonce errors (2040-2049)
26
+ InvalidNonce = 2040,
27
+ NonceAlreadyUsed = 2041,
28
+ NonceExpired = 2042,
29
+
30
+ // Payload errors (2050-2059)
31
+ PayloadMismatch = 2050,
32
+
33
+ // Routing errors (2060-2069)
34
+ RouteNotFound = 2060,
35
+ }
36
+
37
+ /** @public */
38
+ export enum OrderSide {
39
+ BUY = 'BUY',
40
+ SELL = 'SELL',
41
+ }
42
+
43
+ /** @public */
44
+ export enum OrderType {
45
+ MARKET = 'MARKET',
46
+ LIMIT = 'LIMIT',
47
+ STOP_MARKET = 'STOP_MARKET',
48
+ STOP_LIMIT = 'STOP_LIMIT',
49
+ TAKE_PROFIT_MARKET = 'TAKE_PROFIT_MARKET',
50
+ TAKE_PROFIT_LIMIT = 'TAKE_PROFIT_LIMIT',
51
+ TRIGGER_ONLY = 'TRIGGER_ONLY',
52
+ }
53
+
54
+ /** @public */
55
+ export enum PositionSide {
56
+ LONG = 'LONG',
57
+ SHORT = 'SHORT',
58
+ }
59
+
60
+ /** @public */
61
+ export enum MarginMode {
62
+ ISOLATED = 'ISOLATED',
63
+ CROSS = 'CROSS',
64
+ }
65
+
66
+ /** @public */
67
+ export enum TimeInForce {
68
+ GTC = 'GTC',
69
+ IOC = 'IOC',
70
+ POST_ONLY = 'POST_ONLY',
71
+ GTT = 'GTT',
72
+ }
73
+
74
+ /** @public */
75
+ export enum OrderStatus {
76
+ PENDING = 'PENDING',
77
+ OPEN = 'OPEN',
78
+ PARTIALLY_FILLED = 'PARTIALLY_FILLED',
79
+ FILLED = 'FILLED',
80
+ CANCELLED = 'CANCELLED',
81
+ REJECTED = 'REJECTED',
82
+ EXPIRED = 'EXPIRED',
83
+ TRIGGERED = 'TRIGGERED',
84
+ }
85
+
86
+ /** @public */
87
+ export enum FillStatus {
88
+ FILLED = 'FILLED',
89
+ PARTIALLY_FILLED = 'PARTIALLY_FILLED',
90
+ CANCELLED = 'CANCELLED',
91
+ REJECTED = 'REJECTED',
92
+ }
93
+
94
+ /** @public */
95
+ export enum LiquidityRole {
96
+ MAKER = 'maker',
97
+ TAKER = 'taker',
98
+ }
99
+
100
+ /** @public */
101
+ export enum ActionType {
102
+ APPROVE_AGENT = 'approveAgent',
103
+ APPROVE_BUILDER_FEE = 'approveBuilderFee',
104
+ ACCOUNT_MODE = 'accountMode',
105
+ ACCOUNT_TYPE = 'accountType',
106
+ SEND_ASSET = 'sendAsset',
107
+ WITHDRAWAL = 'withdrawal',
108
+ TRANSFER = 'transfer',
109
+ PLACE_ORDER = 'placeOrder',
110
+ PLACE_TRIGGER_ORDER = 'placeTriggerOrder',
111
+ CANCEL_ORDER = 'cancelOrder',
112
+ CANCEL_ALL_ORDERS = 'cancelAllOrders',
113
+ MODIFY_ORDER = 'modifyOrder',
114
+ UPDATE_LEVERAGE = 'updateLeverage',
115
+ UPDATE_POSITION_MARGIN = 'updatePositionMargin',
116
+ REGISTER_API_KEY = 'registerApiKey',
117
+ APPROVE_READ_ONLY_TOKEN = 'approveReadOnlyToken',
118
+ DEPOSIT = 'deposit',
119
+ /** Provider-independent: sent with the `META_PROVIDER` sentinel, not a real provider key. */
120
+ META_VOTE = 'metaVote',
121
+ /** Provider-independent: sent with the `META_PROVIDER` sentinel, not a real provider key. */
122
+ META_ACCEPT_TERMS = 'metaAcceptTerms',
123
+ }
124
+
125
+ /** @public */
126
+ export enum TriggerCondition {
127
+ ABOVE = 'ABOVE',
128
+ BELOW = 'BELOW',
129
+ }
130
+
131
+ /** @public */
132
+ export enum TriggerOrderType {
133
+ TAKE_PROFIT = 'TAKE_PROFIT',
134
+ STOP_LOSS = 'STOP_LOSS',
135
+ }
136
+
137
+ /** @public */
138
+ export enum TriggerOrderStatus {
139
+ WAITING = 'WAITING',
140
+ TRIGGERED = 'TRIGGERED',
141
+ CANCELLED = 'CANCELLED',
142
+ }
143
+
144
+ /** @public */
145
+ export enum ActivityType {
146
+ DEPOSIT = 'DEPOSIT',
147
+ WITHDRAWAL = 'WITHDRAWAL',
148
+ LIQUIDATION = 'LIQUIDATION',
149
+ FUNDING = 'FUNDING',
150
+ TRANSFER = 'TRANSFER',
151
+ }
152
+
153
+ /** @public */
154
+ export enum FillClassification {
155
+ OPENED_LONG = 'Opened Long',
156
+ OPENED_SHORT = 'Opened Short',
157
+ INCREASED_LONG = 'Increased Long',
158
+ INCREASED_SHORT = 'Increased Short',
159
+ REDUCED_LONG = 'Reduced Long',
160
+ REDUCED_SHORT = 'Reduced Short',
161
+ CLOSED_LONG = 'Closed Long',
162
+ CLOSED_SHORT = 'Closed Short',
163
+ SWITCHED_LONG = 'Switched Long',
164
+ SWITCHED_SHORT = 'Switched Short',
165
+ SPOT_BUY = 'Spot Buy',
166
+ SPOT_SELL = 'Spot Sell',
167
+ }
168
+
169
+ /** @public */
170
+ export enum LiquidationClassification {
171
+ LIQUIDATED = 'Liquidated',
172
+ }
173
+
174
+ /** @public */
175
+ export enum FundingClassification {
176
+ FUNDING = 'Funding',
177
+ }
178
+
179
+ /** @public */
180
+ export enum TransferClassification {
181
+ DEPOSIT = 'Deposit',
182
+ WITHDRAWAL = 'Withdrawal',
183
+ TRANSFER = 'Transfer',
184
+ }
185
+
186
+ /** @public */
187
+ export type ActivityClassification =
188
+ | FillClassification
189
+ | LiquidationClassification
190
+ | FundingClassification
191
+ | TransferClassification
192
+
193
+ /** @public */
194
+ export enum PerpsSigner {
195
+ USER = 'USER',
196
+ AGENT = 'AGENT',
197
+ API_KEY = 'API_KEY',
198
+ }
199
+
200
+ /** @public */
201
+ export enum SigningMethod {
202
+ EIP712 = 'eip712',
203
+ WASM_BLOB = 'wasmBlob',
204
+ EVM_TX = 'evmTx',
205
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { PerpsErrorCode } from './enums.js'
2
+
3
+ /** @public */
4
+ export interface PerpsErrorBody {
5
+ code: PerpsErrorCode
6
+ tool?: string
7
+ message: string
8
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `@lifi/perps-types` — shared cross-provider type surface for the perps SDK:
3
+ * account/order/market shapes, action params, enums, error codes, provider
4
+ * descriptors, subscriptions, and EIP-712 typed-data structures.
5
+ *
6
+ * @packageDocumentation
7
+ * @public
8
+ */
9
+
10
+ export * from './acceptTerms.js'
11
+ export * from './account.js'
12
+ export * from './action.js'
13
+ export * from './asset.js'
14
+ export * from './enums.js'
15
+ export * from './errors.js'
16
+ export * from './market.js'
17
+ export * from './meta.js'
18
+ export * from './primitives.js'
19
+ export * from './providers.js'
20
+ export * from './quote.js'
21
+ export * from './subscriptions.js'
22
+ export * from './typedData.js'
23
+ export * from './vote.js'
package/src/market.ts ADDED
@@ -0,0 +1,132 @@
1
+ import type { Asset } from './asset.js'
2
+
3
+ /** @public */
4
+ export interface FundingInfo {
5
+ rate: string
6
+ nextFundingTime: number
7
+ }
8
+
9
+ /** @public */
10
+ export interface BaseMarket {
11
+ providerId: string
12
+ /** Opaque provider market id; referenced elsewhere as `marketId`. */
13
+ id: string
14
+ /** References a {@link ProviderCategory} by id. */
15
+ categoryId: string
16
+ baseAsset: Asset
17
+ quoteAsset: Asset
18
+ szDecimals: number
19
+ /**
20
+ * Maximum decimal places the venue accepts for order prices on this market.
21
+ * Some venues impose further constraints on top of this budget (e.g. a
22
+ * significant-figure cap), so always format prices through the provider's
23
+ * `formatOrderPrice` rather than applying this field directly.
24
+ */
25
+ priceDecimals?: number
26
+ markPrice: string
27
+ volume24h?: string
28
+ prevDayPrice?: string
29
+ }
30
+
31
+ /** @public */
32
+ export interface PerpsMarket extends BaseMarket {
33
+ maxLeverage: number
34
+ onlyIsolated: boolean
35
+ funding: FundingInfo
36
+ openInterest?: string
37
+ /**
38
+ * Venue maintenance margin rate for this market as a fraction (e.g. `0.012`
39
+ * = 1.2%). Feeds client-side liquidation-price estimates via the provider's
40
+ * `estimateLiquidationPrice`.
41
+ */
42
+ maintenanceMarginRate?: number
43
+ }
44
+
45
+ /** @public */
46
+ export interface SpotMarket extends BaseMarket {}
47
+
48
+ /** @public */
49
+ export type Market = PerpsMarket | SpotMarket
50
+
51
+ /** @public */
52
+ export type MarketDisplay = Pick<
53
+ BaseMarket,
54
+ 'providerId' | 'id' | 'categoryId' | 'baseAsset' | 'quoteAsset'
55
+ >
56
+
57
+ /**
58
+ * Minimal market reference for write-action params: identifies a market by
59
+ * its opaque `marketId` within a `categoryId`. Embeds no Assets — write
60
+ * params reference by id, not value.
61
+ * @public
62
+ */
63
+ export interface MarketRef {
64
+ marketId: string
65
+ categoryId: string
66
+ }
67
+
68
+ /** @public */
69
+ export interface MarketsResponse {
70
+ markets: Market[]
71
+ }
72
+
73
+ /** @public */
74
+ export interface MarketPrice {
75
+ marketId: string
76
+ price: string
77
+ }
78
+
79
+ /** @public */
80
+ export interface PricesResponse {
81
+ prices: MarketPrice[]
82
+ }
83
+
84
+ /** @public */
85
+ export interface Candle {
86
+ t: number
87
+ o: string
88
+ h: string
89
+ l: string
90
+ c: string
91
+ v: string
92
+ }
93
+
94
+ /** @public */
95
+ export interface OhlcvResponse {
96
+ provider: string
97
+ marketId: string
98
+ interval: string
99
+ candles: Candle[]
100
+ }
101
+
102
+ /** @public */
103
+ export type OhlcvInterval =
104
+ | '1m'
105
+ | '3m'
106
+ | '5m'
107
+ | '15m'
108
+ | '30m'
109
+ | '1h'
110
+ | '2h'
111
+ | '4h'
112
+ | '8h'
113
+ | '12h'
114
+ | '1d'
115
+ | '3d'
116
+ | '1w'
117
+ | '1M'
118
+
119
+ /** @public */
120
+ export interface OrderbookLevel {
121
+ price: string
122
+ size: string
123
+ }
124
+
125
+ /** @public */
126
+ export interface OrderbookResponse {
127
+ provider: string
128
+ marketId: string
129
+ bids: OrderbookLevel[]
130
+ asks: OrderbookLevel[]
131
+ timestamp: number
132
+ }