@lifi/perps-types 0.1.1-alpha.2 → 0.1.1-alpha.22

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 (193) hide show
  1. package/package.json +40 -10
  2. package/providers/hyperliquid/package.json +3 -3
  3. package/providers/lighter/package.json +5 -0
  4. package/src/_cjs/{market.js → action.js} +1 -1
  5. package/src/_cjs/action.js.map +1 -0
  6. package/src/_cjs/{trading.js → asset.js} +1 -1
  7. package/src/_cjs/asset.js.map +1 -0
  8. package/src/_cjs/enums.js +78 -15
  9. package/src/_cjs/enums.js.map +1 -1
  10. package/src/_cjs/index.js +3 -4
  11. package/src/_cjs/index.js.map +1 -1
  12. package/src/_cjs/providers/hyperliquid/assetId.js +11 -9
  13. package/src/_cjs/providers/hyperliquid/assetId.js.map +1 -1
  14. package/src/_cjs/providers/hyperliquid/mappers/activity.js +66 -0
  15. package/src/_cjs/providers/hyperliquid/mappers/activity.js.map +1 -0
  16. package/src/_cjs/providers/hyperliquid/mappers/{market.js → asset.js} +9 -9
  17. package/src/_cjs/providers/hyperliquid/mappers/asset.js.map +1 -0
  18. package/src/_cjs/providers/hyperliquid/mappers/fill.js +64 -0
  19. package/src/_cjs/providers/hyperliquid/mappers/fill.js.map +1 -0
  20. package/src/_cjs/providers/hyperliquid/mappers/index.js +12 -7
  21. package/src/_cjs/providers/hyperliquid/mappers/index.js.map +1 -1
  22. package/src/_cjs/providers/hyperliquid/mappers/order.js +59 -10
  23. package/src/_cjs/providers/hyperliquid/mappers/order.js.map +1 -1
  24. package/src/_cjs/providers/hyperliquid/mappers/position.js +7 -5
  25. package/src/_cjs/providers/hyperliquid/mappers/position.js.map +1 -1
  26. package/src/_cjs/providers/hyperliquid/mappers/shared.js +0 -10
  27. package/src/_cjs/providers/hyperliquid/mappers/shared.js.map +1 -1
  28. package/src/_cjs/providers/hyperliquid/types.js +14 -0
  29. package/src/_cjs/providers/hyperliquid/types.js.map +1 -1
  30. package/src/_cjs/{authorization.js → providers/lighter/apiTypes.js} +1 -1
  31. package/src/_cjs/providers/lighter/apiTypes.js.map +1 -0
  32. package/src/_cjs/providers/lighter/index.js +20 -0
  33. package/src/_cjs/providers/lighter/index.js.map +1 -0
  34. package/src/_cjs/providers/lighter/mappers/fill.js +28 -0
  35. package/src/_cjs/providers/lighter/mappers/fill.js.map +1 -0
  36. package/src/_cjs/providers/lighter/mappers/index.js +10 -0
  37. package/src/_cjs/providers/lighter/mappers/index.js.map +1 -0
  38. package/src/_cjs/providers/lighter/mappers/order.js +33 -0
  39. package/src/_cjs/providers/lighter/mappers/order.js.map +1 -0
  40. package/src/_cjs/providers/lighter/mappers/position.js +33 -0
  41. package/src/_cjs/providers/lighter/mappers/position.js.map +1 -0
  42. package/src/_cjs/providers/lighter/types.js +23 -0
  43. package/src/_cjs/providers/lighter/types.js.map +1 -0
  44. package/src/_cjs/{withdrawal.js → providers.js} +1 -1
  45. package/src/_cjs/providers.js.map +1 -0
  46. package/src/_esm/action.js +2 -0
  47. package/src/_esm/action.js.map +1 -0
  48. package/src/_esm/asset.js +2 -0
  49. package/src/_esm/asset.js.map +1 -0
  50. package/src/_esm/enums.js +77 -14
  51. package/src/_esm/enums.js.map +1 -1
  52. package/src/_esm/index.js +3 -4
  53. package/src/_esm/index.js.map +1 -1
  54. package/src/_esm/providers/hyperliquid/assetId.js +13 -11
  55. package/src/_esm/providers/hyperliquid/assetId.js.map +1 -1
  56. package/src/_esm/providers/hyperliquid/mappers/activity.js +69 -0
  57. package/src/_esm/providers/hyperliquid/mappers/activity.js.map +1 -0
  58. package/src/_esm/providers/hyperliquid/mappers/{market.js → asset.js} +7 -7
  59. package/src/_esm/providers/hyperliquid/mappers/asset.js.map +1 -0
  60. package/src/_esm/providers/hyperliquid/mappers/fill.js +62 -0
  61. package/src/_esm/providers/hyperliquid/mappers/fill.js.map +1 -0
  62. package/src/_esm/providers/hyperliquid/mappers/index.js +4 -4
  63. package/src/_esm/providers/hyperliquid/mappers/index.js.map +1 -1
  64. package/src/_esm/providers/hyperliquid/mappers/order.js +56 -9
  65. package/src/_esm/providers/hyperliquid/mappers/order.js.map +1 -1
  66. package/src/_esm/providers/hyperliquid/mappers/position.js +7 -5
  67. package/src/_esm/providers/hyperliquid/mappers/position.js.map +1 -1
  68. package/src/_esm/providers/hyperliquid/mappers/shared.js +1 -12
  69. package/src/_esm/providers/hyperliquid/mappers/shared.js.map +1 -1
  70. package/src/_esm/providers/hyperliquid/types.js +22 -2
  71. package/src/_esm/providers/hyperliquid/types.js.map +1 -1
  72. package/src/_esm/providers/lighter/apiTypes.js +5 -0
  73. package/src/_esm/providers/lighter/apiTypes.js.map +1 -0
  74. package/src/_esm/providers/lighter/index.js +4 -0
  75. package/src/_esm/providers/lighter/index.js.map +1 -0
  76. package/src/_esm/providers/lighter/mappers/fill.js +30 -0
  77. package/src/_esm/providers/lighter/mappers/fill.js.map +1 -0
  78. package/src/_esm/providers/lighter/mappers/index.js +4 -0
  79. package/src/_esm/providers/lighter/mappers/index.js.map +1 -0
  80. package/src/_esm/providers/lighter/mappers/order.js +34 -0
  81. package/src/_esm/providers/lighter/mappers/order.js.map +1 -0
  82. package/src/_esm/providers/lighter/mappers/position.js +34 -0
  83. package/src/_esm/providers/lighter/mappers/position.js.map +1 -0
  84. package/src/_esm/providers/lighter/types.js +30 -0
  85. package/src/_esm/providers/lighter/types.js.map +1 -0
  86. package/src/_esm/providers.js +2 -0
  87. package/src/_esm/providers.js.map +1 -0
  88. package/src/_types/account.d.ts +73 -18
  89. package/src/_types/account.d.ts.map +1 -1
  90. package/src/_types/action.d.ts +181 -0
  91. package/src/_types/action.d.ts.map +1 -0
  92. package/src/_types/{market.d.ts → asset.d.ts} +23 -34
  93. package/src/_types/asset.d.ts.map +1 -0
  94. package/src/_types/enums.d.ts +62 -5
  95. package/src/_types/enums.d.ts.map +1 -1
  96. package/src/_types/index.d.ts +3 -4
  97. package/src/_types/index.d.ts.map +1 -1
  98. package/src/_types/providers/hyperliquid/assetId.d.ts +8 -6
  99. package/src/_types/providers/hyperliquid/assetId.d.ts.map +1 -1
  100. package/src/_types/providers/hyperliquid/mappers/activity.d.ts +13 -0
  101. package/src/_types/providers/hyperliquid/mappers/activity.d.ts.map +1 -0
  102. package/src/_types/providers/hyperliquid/mappers/asset.d.ts +4 -0
  103. package/src/_types/providers/hyperliquid/mappers/asset.d.ts.map +1 -0
  104. package/src/_types/providers/hyperliquid/mappers/fill.d.ts +6 -0
  105. package/src/_types/providers/hyperliquid/mappers/fill.d.ts.map +1 -0
  106. package/src/_types/providers/hyperliquid/mappers/index.d.ts +4 -4
  107. package/src/_types/providers/hyperliquid/mappers/index.d.ts.map +1 -1
  108. package/src/_types/providers/hyperliquid/mappers/order.d.ts +8 -3
  109. package/src/_types/providers/hyperliquid/mappers/order.d.ts.map +1 -1
  110. package/src/_types/providers/hyperliquid/mappers/position.d.ts +1 -1
  111. package/src/_types/providers/hyperliquid/mappers/position.d.ts.map +1 -1
  112. package/src/_types/providers/hyperliquid/mappers/shared.d.ts +0 -6
  113. package/src/_types/providers/hyperliquid/mappers/shared.d.ts.map +1 -1
  114. package/src/_types/providers/hyperliquid/types.d.ts +63 -11
  115. package/src/_types/providers/hyperliquid/types.d.ts.map +1 -1
  116. package/src/_types/providers/lighter/apiTypes.d.ts +74 -0
  117. package/src/_types/providers/lighter/apiTypes.d.ts.map +1 -0
  118. package/src/_types/providers/lighter/index.d.ts +4 -0
  119. package/src/_types/providers/lighter/index.d.ts.map +1 -0
  120. package/src/_types/providers/lighter/mappers/fill.d.ts +10 -0
  121. package/src/_types/providers/lighter/mappers/fill.d.ts.map +1 -0
  122. package/src/_types/providers/lighter/mappers/index.d.ts +4 -0
  123. package/src/_types/providers/lighter/mappers/index.d.ts.map +1 -0
  124. package/src/_types/providers/lighter/mappers/order.d.ts +9 -0
  125. package/src/_types/providers/lighter/mappers/order.d.ts.map +1 -0
  126. package/src/_types/providers/lighter/mappers/position.d.ts +9 -0
  127. package/src/_types/providers/lighter/mappers/position.d.ts.map +1 -0
  128. package/src/_types/providers/lighter/types.d.ts +90 -0
  129. package/src/_types/providers/lighter/types.d.ts.map +1 -0
  130. package/src/_types/providers.d.ts +23 -0
  131. package/src/_types/providers.d.ts.map +1 -0
  132. package/src/_types/subscriptions.d.ts +24 -18
  133. package/src/_types/subscriptions.d.ts.map +1 -1
  134. package/src/_types/typedData.d.ts +13 -5
  135. package/src/_types/typedData.d.ts.map +1 -1
  136. package/src/account.ts +94 -18
  137. package/src/action.ts +246 -0
  138. package/src/asset.ts +88 -0
  139. package/src/enums.ts +72 -3
  140. package/src/index.ts +3 -4
  141. package/src/providers/hyperliquid/assetId.ts +18 -12
  142. package/src/providers/hyperliquid/mappers/activity.ts +94 -0
  143. package/src/providers/hyperliquid/mappers/{market.ts → asset.ts} +9 -12
  144. package/src/providers/hyperliquid/mappers/fill.ts +77 -0
  145. package/src/providers/hyperliquid/mappers/index.ts +10 -4
  146. package/src/providers/hyperliquid/mappers/order.ts +62 -15
  147. package/src/providers/hyperliquid/mappers/position.ts +7 -10
  148. package/src/providers/hyperliquid/mappers/shared.ts +0 -15
  149. package/src/providers/hyperliquid/types.ts +127 -20
  150. package/src/providers/lighter/apiTypes.ts +80 -0
  151. package/src/providers/lighter/index.ts +3 -0
  152. package/src/providers/lighter/mappers/fill.ts +45 -0
  153. package/src/providers/lighter/mappers/index.ts +3 -0
  154. package/src/providers/lighter/mappers/order.ts +37 -0
  155. package/src/providers/lighter/mappers/position.ts +43 -0
  156. package/src/providers/lighter/types.ts +115 -0
  157. package/src/providers.ts +26 -0
  158. package/src/subscriptions.ts +22 -20
  159. package/src/typedData.ts +15 -5
  160. package/src/_cjs/authorization.js.map +0 -1
  161. package/src/_cjs/market.js.map +0 -1
  162. package/src/_cjs/providers/hyperliquid/mappers/history.js +0 -22
  163. package/src/_cjs/providers/hyperliquid/mappers/history.js.map +0 -1
  164. package/src/_cjs/providers/hyperliquid/mappers/market.js.map +0 -1
  165. package/src/_cjs/trading.js.map +0 -1
  166. package/src/_cjs/withdrawal.js.map +0 -1
  167. package/src/_esm/authorization.js +0 -2
  168. package/src/_esm/authorization.js.map +0 -1
  169. package/src/_esm/market.js +0 -2
  170. package/src/_esm/market.js.map +0 -1
  171. package/src/_esm/providers/hyperliquid/mappers/history.js +0 -18
  172. package/src/_esm/providers/hyperliquid/mappers/history.js.map +0 -1
  173. package/src/_esm/providers/hyperliquid/mappers/market.js.map +0 -1
  174. package/src/_esm/trading.js +0 -2
  175. package/src/_esm/trading.js.map +0 -1
  176. package/src/_esm/withdrawal.js +0 -2
  177. package/src/_esm/withdrawal.js.map +0 -1
  178. package/src/_types/authorization.d.ts +0 -39
  179. package/src/_types/authorization.d.ts.map +0 -1
  180. package/src/_types/market.d.ts.map +0 -1
  181. package/src/_types/providers/hyperliquid/mappers/history.d.ts +0 -4
  182. package/src/_types/providers/hyperliquid/mappers/history.d.ts.map +0 -1
  183. package/src/_types/providers/hyperliquid/mappers/market.d.ts +0 -4
  184. package/src/_types/providers/hyperliquid/mappers/market.d.ts.map +0 -1
  185. package/src/_types/trading.d.ts +0 -82
  186. package/src/_types/trading.d.ts.map +0 -1
  187. package/src/_types/withdrawal.d.ts +0 -37
  188. package/src/_types/withdrawal.d.ts.map +0 -1
  189. package/src/authorization.ts +0 -46
  190. package/src/market.ts +0 -97
  191. package/src/providers/hyperliquid/mappers/history.ts +0 -25
  192. package/src/trading.ts +0 -99
  193. package/src/withdrawal.ts +0 -44
package/src/account.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import type { Address } from './typedData.js'
2
+ import type { AssetDisplay } from './asset.js'
2
3
  import type {
3
- HistoryItemStatus,
4
+ ActivityType,
5
+ FillClassification,
6
+ FillStatus,
4
7
  MarginMode,
5
8
  OrderSide,
6
9
  OrderType,
@@ -13,9 +16,7 @@ export interface FeeTier {
13
16
  }
14
17
 
15
18
  export interface Position {
16
- symbol: string
17
- assetId: number
18
- dex: string
19
+ asset: AssetDisplay
19
20
  side: PositionSide
20
21
  size: string
21
22
  entryPrice: string
@@ -29,15 +30,14 @@ export interface Position {
29
30
 
30
31
  export interface OpenOrder {
31
32
  id: string
32
- symbol: string
33
- assetId: number
34
- dex: string
33
+ asset: AssetDisplay
35
34
  side: OrderSide
36
35
  type: OrderType
37
36
  size: string
38
37
  price: string
39
38
  filledSize: string
40
39
  reduceOnly: boolean
40
+ label?: string
41
41
  createdAt: string
42
42
  }
43
43
 
@@ -47,30 +47,52 @@ export interface Balance {
47
47
  }
48
48
 
49
49
  export interface AccountResponse {
50
- dex: string
50
+ provider: string
51
51
  address: Address
52
- balances: Balance[]
52
+ balances: Record<string, Balance[]>
53
53
  marginUsed: string
54
54
  unrealizedPnl: string
55
55
  feeTier: FeeTier
56
+ config: Record<string, unknown>
57
+ }
58
+
59
+ export interface TriggerOrder {
60
+ id: string
61
+ asset: AssetDisplay
62
+ type: OrderType
63
+ size: string
64
+ triggerPrice: string
65
+ limitPrice?: string
66
+ label?: string
67
+ createdAt: string
68
+ }
69
+
70
+ export interface PositionsResponse {
71
+ provider: string
56
72
  positions: Position[]
73
+ pagination: Pagination
74
+ }
75
+
76
+ export interface OrdersResponse {
77
+ provider: string
57
78
  openOrders: OpenOrder[]
58
- config: Record<string, unknown>
79
+ triggerOrders: TriggerOrder[]
80
+ pagination: Pagination
59
81
  }
60
82
 
61
- export interface HistoryItem {
83
+ export interface Fill {
62
84
  id: string
63
- symbol: string
64
- assetId: number
65
- dex: string
85
+ asset: AssetDisplay
66
86
  side: OrderSide
67
87
  type: OrderType
68
88
  size: string
69
89
  price: string
70
- status: HistoryItemStatus
90
+ status: FillStatus
71
91
  filledSize?: string
72
92
  fee?: string
73
93
  realizedPnl?: string | null
94
+ startPosition?: string
95
+ classification: FillClassification
74
96
  createdAt: string
75
97
  }
76
98
 
@@ -81,8 +103,62 @@ export interface Pagination {
81
103
  nextUrl?: string
82
104
  }
83
105
 
84
- export interface HistoryResponse {
85
- dex: string
86
- items: HistoryItem[]
106
+ export interface FillsResponse {
107
+ provider: string
108
+ items: Fill[]
109
+ pagination: Pagination
110
+ }
111
+
112
+ // ---------------------------------------------------------------------------
113
+ // Activities
114
+ // ---------------------------------------------------------------------------
115
+
116
+ export interface BaseActivity {
117
+ id: string
118
+ provider: string
119
+ timestamp: string
120
+ }
121
+
122
+ export interface DepositActivity extends BaseActivity {
123
+ type: ActivityType.DEPOSIT
124
+ amount: string
125
+ }
126
+
127
+ export interface WithdrawalActivity extends BaseActivity {
128
+ type: ActivityType.WITHDRAWAL
129
+ amount: string
130
+ fee: string
131
+ }
132
+
133
+ export interface LiquidatedPosition {
134
+ asset: AssetDisplay
135
+ size: string
136
+ }
137
+
138
+ export interface LiquidationActivity extends BaseActivity {
139
+ type: ActivityType.LIQUIDATION
140
+ liquidatedNotionalPosition: string
141
+ accountValue: string
142
+ leverageType: string
143
+ liquidatedPositions: LiquidatedPosition[]
144
+ }
145
+
146
+ export interface FundingActivity extends BaseActivity {
147
+ type: ActivityType.FUNDING
148
+ asset: AssetDisplay
149
+ amount: string
150
+ positionSize: string
151
+ fundingRate: string
152
+ }
153
+
154
+ export type ActivityItem =
155
+ | DepositActivity
156
+ | WithdrawalActivity
157
+ | LiquidationActivity
158
+ | FundingActivity
159
+
160
+ export interface ActivitiesResponse {
161
+ provider: string
162
+ items: ActivityItem[]
87
163
  pagination: Pagination
88
164
  }
package/src/action.ts ADDED
@@ -0,0 +1,246 @@
1
+ import type { OrderType } from './enums.js'
2
+ import {
3
+ type ActionType,
4
+ type OrderSide,
5
+ type OrderStatus,
6
+ type TimeInForce,
7
+ type TriggerCondition,
8
+ } from './enums.js'
9
+ import type { Address, Hex, PerpsTypedData } from './typedData.js'
10
+ import type { AssetIdentity, AssetDisplay } from './asset.js'
11
+
12
+ // ---------------------------------------------------------------------------
13
+ // Action step types (create → sign → execute flow)
14
+ //
15
+ // Union by structural shape — the SDK knows which variant to expect based
16
+ // on the provider's `signingMethod` from the /providers response.
17
+ //
18
+ // Eip712 – Hyperliquid and future EVM dexes (EIP-712 typed data + ECDSA sig)
19
+ // WasmBlob – Lighter and zk-rollup dexes (WASM signer → {txType, txInfo, txHash})
20
+ // EvmTx – plain EVM transaction (reserved for future use)
21
+ // ---------------------------------------------------------------------------
22
+
23
+ export interface Eip712ActionStep {
24
+ action: ActionType
25
+ typedData: PerpsTypedData
26
+ }
27
+
28
+ export interface WasmBlobActionStep {
29
+ action: ActionType
30
+ wasmSignParams: Record<string, unknown>
31
+ }
32
+
33
+ export interface EvmTxActionStep {
34
+ action: ActionType
35
+ txParams: Record<string, unknown>
36
+ }
37
+
38
+ export type ActionStep = Eip712ActionStep | WasmBlobActionStep | EvmTxActionStep
39
+
40
+ export interface Eip712SignedActionStep {
41
+ action: ActionType
42
+ typedData: PerpsTypedData
43
+ signature: Hex
44
+ }
45
+
46
+ export interface WasmBlobSignedActionStep {
47
+ action: ActionType
48
+ wasmSignParams: Record<string, unknown>
49
+ signedTx: {
50
+ txType: number
51
+ txInfo: string
52
+ txHash: string
53
+ }
54
+ }
55
+
56
+ export interface EvmTxSignedActionStep {
57
+ action: ActionType
58
+ txParams: Record<string, unknown>
59
+ txHash: string
60
+ }
61
+
62
+ export type SignedActionStep =
63
+ | Eip712SignedActionStep
64
+ | WasmBlobSignedActionStep
65
+ | EvmTxSignedActionStep
66
+
67
+ export interface ActionResult {
68
+ action: ActionType
69
+ success: boolean
70
+ orderId?: string
71
+ error?: string
72
+ }
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Shared data types
76
+ // ---------------------------------------------------------------------------
77
+
78
+ export interface TriggerOrderInput {
79
+ triggerPrice: string
80
+ limitPrice?: string
81
+ }
82
+
83
+ export interface ModifyOrderInput {
84
+ id: string
85
+ price?: string
86
+ size?: string
87
+ triggerPrice?: string
88
+ limitPrice?: string
89
+ }
90
+
91
+ export interface Order {
92
+ orderId: string
93
+ asset: AssetDisplay
94
+ side: OrderSide
95
+ type: OrderType
96
+ price?: string
97
+ originalSize: string
98
+ remainingSize: string
99
+ filledSize: string
100
+ timeInForce?: TimeInForce
101
+ expiresAt?: string
102
+ reduceOnly?: boolean
103
+ isTrigger?: boolean
104
+ triggerPrice?: string
105
+ triggerCondition?: TriggerCondition
106
+ status: OrderStatus
107
+ averagePrice?: string
108
+ createdAt: string
109
+ updatedAt: string
110
+ }
111
+
112
+ // ---------------------------------------------------------------------------
113
+ // Per-action param types
114
+ // ---------------------------------------------------------------------------
115
+
116
+ export interface PlaceOrderParams {
117
+ asset: AssetIdentity
118
+ side: OrderSide
119
+ type?: OrderType
120
+ size: string
121
+ price?: string
122
+ leverage?: number
123
+ reduceOnly?: boolean
124
+ timeInForce?: TimeInForce
125
+ expiresAt?: string
126
+ takeProfit?: TriggerOrderInput
127
+ stopLoss?: TriggerOrderInput
128
+ }
129
+
130
+ export interface PlaceTriggerOrderParams {
131
+ asset: AssetIdentity
132
+ side: OrderSide
133
+ takeProfit?: TriggerOrderInput
134
+ stopLoss?: TriggerOrderInput
135
+ }
136
+
137
+ export interface CancelOrderParams {
138
+ ids: string[]
139
+ }
140
+
141
+ export interface ModifyOrderParams {
142
+ modifications: ModifyOrderInput[]
143
+ }
144
+
145
+ export interface UpdateLeverageParams {
146
+ asset: AssetIdentity
147
+ leverage: number
148
+ }
149
+
150
+ export interface UpdatePositionMarginParams {
151
+ asset: AssetIdentity
152
+ action: 'add' | 'remove'
153
+ amount: string
154
+ }
155
+
156
+ export interface WithdrawalParams {
157
+ destination: Address
158
+ amount: string
159
+ }
160
+
161
+ export interface DepositParams {
162
+ /** Amount of the token to deposit (human-readable, e.g. "100.5"). */
163
+ amount: string
164
+ /** ERC-20 token address on the source chain. */
165
+ tokenAddress: Address
166
+ /** Chain ID of the source chain (e.g. 1 for Ethereum, 42161 for Arbitrum). */
167
+ chainId: number
168
+ }
169
+
170
+ export interface ApproveAgentParams {
171
+ agentAddress: string
172
+ agentTtlMs?: number
173
+ }
174
+
175
+ export interface SetAbstractionParams {
176
+ abstraction?: string
177
+ }
178
+
179
+ export interface SendAssetParams {
180
+ collateral: string
181
+ sourceDex: string
182
+ destinationDex: string
183
+ amount: string
184
+ }
185
+
186
+ // ---------------------------------------------------------------------------
187
+ // ActionParamsMap — compile-time type resolution for SDK
188
+ // ---------------------------------------------------------------------------
189
+
190
+ export interface CancelAllOrdersParams {
191
+ /** 0=immediate (cancel GTC), 1=scheduled, 2=abort scheduled */
192
+ timeInForce: number
193
+ /** Unix timestamp in milliseconds (required for scheduled cancels) */
194
+ timestampMs?: number
195
+ }
196
+
197
+ export interface RegisterApiKeyParams {
198
+ /** The API key slot index to register (0-255). Reusing a fixed slot overwrites the old key. */
199
+ apiKeyIndex: number
200
+ }
201
+
202
+ export interface ActionParamsMap {
203
+ [ActionType.APPROVE_AGENT]: ApproveAgentParams
204
+ [ActionType.APPROVE_BUILDER_FEE]: Record<string, never>
205
+ [ActionType.USER_SET_ABSTRACTION]: SetAbstractionParams
206
+ [ActionType.AGENT_SET_ABSTRACTION]: SetAbstractionParams
207
+ [ActionType.SEND_ASSET]: SendAssetParams
208
+ [ActionType.WITHDRAWAL]: WithdrawalParams
209
+ [ActionType.PLACE_ORDER]: PlaceOrderParams
210
+ [ActionType.PLACE_TRIGGER_ORDER]: PlaceTriggerOrderParams
211
+ [ActionType.CANCEL_ORDER]: CancelOrderParams
212
+ [ActionType.CANCEL_ALL_ORDERS]: CancelAllOrdersParams
213
+ [ActionType.MODIFY_ORDER]: ModifyOrderParams
214
+ [ActionType.UPDATE_LEVERAGE]: UpdateLeverageParams
215
+ [ActionType.UPDATE_POSITION_MARGIN]: UpdatePositionMarginParams
216
+ [ActionType.REGISTER_API_KEY]: RegisterApiKeyParams
217
+ [ActionType.DEPOSIT]: DepositParams
218
+ }
219
+
220
+ // ---------------------------------------------------------------------------
221
+ // Request / Response types
222
+ // ---------------------------------------------------------------------------
223
+
224
+ export interface CreateActionRequest {
225
+ provider: string
226
+ address: Address
227
+ signerAddress?: Address
228
+ action: ActionType
229
+ params: ActionParamsMap[ActionType]
230
+ }
231
+
232
+ export interface CreateActionResponse {
233
+ actions: ActionStep[]
234
+ }
235
+
236
+ export interface ExecuteActionRequest {
237
+ provider: string
238
+ address: Address
239
+ signerAddress?: Address
240
+ action: ActionType
241
+ actions: SignedActionStep[]
242
+ }
243
+
244
+ export interface ExecuteActionResponse {
245
+ results: ActionResult[]
246
+ }
package/src/asset.ts ADDED
@@ -0,0 +1,88 @@
1
+ export interface FundingInfo {
2
+ rate: string
3
+ nextFundingTime: number
4
+ }
5
+
6
+ export interface AssetIdentity {
7
+ assetId: string // provider's canonical identity: "BTC", "xyz:PURR", "@142"
8
+ market: string // market category from /providers.markets: "hyperliquid", "xyz", "spot"
9
+ }
10
+
11
+ export interface Asset extends AssetIdentity {
12
+ displaySymbol: string // UI base name: "BTC", "PURR"; spot keeps full pair: "PURR/USDC"
13
+ displayQuote: string | null // quote asset for perps: "USDC", "USDH"; null for spot
14
+ displayName?: string // future: "Bitcoin", "Ethereum"
15
+ logoURI: string
16
+ szDecimals: number
17
+ maxLeverage: number
18
+ onlyIsolated: boolean
19
+ isMarginCollateral?: boolean
20
+ funding: FundingInfo
21
+ openInterest?: string
22
+ volume24h?: string
23
+ prevDayPrice?: string
24
+ markPrice: string
25
+ }
26
+
27
+ export type AssetDisplay = Pick<
28
+ Asset,
29
+ 'assetId' | 'market' | 'displaySymbol' | 'displayQuote'
30
+ >
31
+
32
+ export interface AssetPrice {
33
+ assetId: string
34
+ price: string
35
+ }
36
+
37
+ export interface AssetsResponse {
38
+ assets: Asset[]
39
+ }
40
+
41
+ export interface PricesResponse {
42
+ prices: AssetPrice[]
43
+ }
44
+
45
+ export interface Candle {
46
+ t: number
47
+ o: string
48
+ h: string
49
+ l: string
50
+ c: string
51
+ v: string
52
+ }
53
+
54
+ export interface OhlcvResponse {
55
+ provider: string
56
+ assetId: string
57
+ interval: string
58
+ candles: Candle[]
59
+ }
60
+
61
+ export type OhlcvInterval =
62
+ | '1m'
63
+ | '3m'
64
+ | '5m'
65
+ | '15m'
66
+ | '30m'
67
+ | '1h'
68
+ | '2h'
69
+ | '4h'
70
+ | '8h'
71
+ | '12h'
72
+ | '1d'
73
+ | '3d'
74
+ | '1w'
75
+ | '1M'
76
+
77
+ export interface OrderbookLevel {
78
+ price: string
79
+ size: string
80
+ }
81
+
82
+ export interface OrderbookResponse {
83
+ provider: string
84
+ assetId: string
85
+ bids: OrderbookLevel[]
86
+ asks: OrderbookLevel[]
87
+ timestamp: number
88
+ }
package/src/enums.ts CHANGED
@@ -5,6 +5,7 @@ export enum PerpsErrorCode {
5
5
  ValidationError = 2002,
6
6
  TimeoutError = 2003,
7
7
  ThirdPartyError = 2004,
8
+ SDKError = 2005,
8
9
 
9
10
  // Auth errors (2010-2019)
10
11
  SignatureInvalid = 2010,
@@ -38,6 +39,11 @@ export enum OrderSide {
38
39
  export enum OrderType {
39
40
  MARKET = 'MARKET',
40
41
  LIMIT = 'LIMIT',
42
+ STOP_MARKET = 'STOP_MARKET',
43
+ STOP_LIMIT = 'STOP_LIMIT',
44
+ TAKE_PROFIT_MARKET = 'TAKE_PROFIT_MARKET',
45
+ TAKE_PROFIT_LIMIT = 'TAKE_PROFIT_LIMIT',
46
+ TRIGGER_ONLY = 'TRIGGER_ONLY',
41
47
  }
42
48
 
43
49
  export enum PositionSide {
@@ -68,18 +74,29 @@ export enum OrderStatus {
68
74
  TRIGGERED = 'TRIGGERED',
69
75
  }
70
76
 
71
- export enum HistoryItemStatus {
77
+ export enum FillStatus {
72
78
  FILLED = 'FILLED',
73
79
  PARTIALLY_FILLED = 'PARTIALLY_FILLED',
74
80
  CANCELLED = 'CANCELLED',
75
81
  REJECTED = 'REJECTED',
76
82
  }
77
83
 
78
- export enum OrderActionType {
79
- UPDATE_LEVERAGE = 'updateLeverage',
84
+ export enum ActionType {
85
+ APPROVE_AGENT = 'approveAgent',
86
+ APPROVE_BUILDER_FEE = 'approveBuilderFee',
87
+ USER_SET_ABSTRACTION = 'userSetAbstraction',
88
+ AGENT_SET_ABSTRACTION = 'agentSetAbstraction',
89
+ SEND_ASSET = 'sendAsset',
90
+ WITHDRAWAL = 'withdrawal',
80
91
  PLACE_ORDER = 'placeOrder',
81
92
  PLACE_TRIGGER_ORDER = 'placeTriggerOrder',
82
93
  CANCEL_ORDER = 'cancelOrder',
94
+ CANCEL_ALL_ORDERS = 'cancelAllOrders',
95
+ MODIFY_ORDER = 'modifyOrder',
96
+ UPDATE_LEVERAGE = 'updateLeverage',
97
+ UPDATE_POSITION_MARGIN = 'updatePositionMargin',
98
+ REGISTER_API_KEY = 'registerApiKey',
99
+ DEPOSIT = 'deposit',
83
100
  }
84
101
 
85
102
  export enum TriggerCondition {
@@ -97,3 +114,55 @@ export enum TriggerOrderStatus {
97
114
  TRIGGERED = 'TRIGGERED',
98
115
  CANCELLED = 'CANCELLED',
99
116
  }
117
+
118
+ export enum ActivityType {
119
+ DEPOSIT = 'DEPOSIT',
120
+ WITHDRAWAL = 'WITHDRAWAL',
121
+ LIQUIDATION = 'LIQUIDATION',
122
+ FUNDING = 'FUNDING',
123
+ }
124
+
125
+ export enum FillClassification {
126
+ OPENED_LONG = 'Opened Long',
127
+ OPENED_SHORT = 'Opened Short',
128
+ INCREASED_LONG = 'Increased Long',
129
+ INCREASED_SHORT = 'Increased Short',
130
+ REDUCED_LONG = 'Reduced Long',
131
+ REDUCED_SHORT = 'Reduced Short',
132
+ CLOSED_LONG = 'Closed Long',
133
+ CLOSED_SHORT = 'Closed Short',
134
+ SWITCHED_LONG = 'Switched Long',
135
+ SWITCHED_SHORT = 'Switched Short',
136
+ SPOT_BUY = 'Spot Buy',
137
+ SPOT_SELL = 'Spot Sell',
138
+ }
139
+
140
+ export enum LiquidationClassification {
141
+ LIQUIDATED = 'Liquidated',
142
+ }
143
+
144
+ export enum FundingClassification {
145
+ FUNDING = 'Funding',
146
+ }
147
+
148
+ export enum TransferClassification {
149
+ DEPOSIT = 'Deposit',
150
+ WITHDRAWAL = 'Withdrawal',
151
+ }
152
+
153
+ export type ActivityClassification =
154
+ | FillClassification
155
+ | LiquidationClassification
156
+ | FundingClassification
157
+ | TransferClassification
158
+
159
+ export enum PerpsSigner {
160
+ USER = 'USER',
161
+ AGENT = 'AGENT',
162
+ }
163
+
164
+ export enum SigningMethod {
165
+ EIP712 = 'eip712',
166
+ WASM_BLOB = 'wasmBlob',
167
+ EVM_TX = 'evmTx',
168
+ }
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  export * from './typedData.js'
2
2
  export * from './enums.js'
3
- export * from './market.js'
4
- export * from './authorization.js'
3
+ export * from './providers.js'
4
+ export * from './asset.js'
5
+ export * from './action.js'
5
6
  export * from './account.js'
6
- export * from './trading.js'
7
- export * from './withdrawal.js'
8
7
  export * from './errors.js'
9
8
  export * from './subscriptions.js'
@@ -1,26 +1,32 @@
1
+ /** Spot asset IDs use the @pairIndex format (e.g. "@230"). */
2
+ export const assetIsSpot = (assetId: string): boolean => assetId.startsWith('@')
3
+
1
4
  /**
2
- * Calculate the asset ID for a given DEX index and asset index.
5
+ * Calculate the asset ID for a given provider index and asset index.
3
6
  *
4
- * Main DEX (dex = ''): assetId = indexInDex
5
- * HIP-3 DEXes (dex = 'xyz'): assetId = 100_000 + perpDexIndex * 10_000 + indexInDex
7
+ * Main provider (provider = ''): assetId = indexInProvider
8
+ * HIP-3 providers (provider = 'xyz'): assetId = 100_000 + perpDexIndex * 10_000 + indexInProvider
6
9
  */
7
10
  export const calculateAssetId = (
8
- dexIndex: number,
9
- indexInDex: number
11
+ providerIndex: number,
12
+ indexInProvider: number
10
13
  ): number => {
11
- if (dexIndex === 0) {
12
- return indexInDex
14
+ if (providerIndex === 0) {
15
+ return indexInProvider
13
16
  }
14
- return 100_000 + dexIndex * 10_000 + indexInDex
17
+ return 100_000 + providerIndex * 10_000 + indexInProvider
15
18
  }
16
19
 
17
20
  /**
18
- * Get the DEX index from the given list of dex names.
21
+ * Get the provider index from the given list of provider names.
19
22
  */
20
- export const getDexIndex = (dex: string, dexNames: string[]): number => {
21
- const index = dexNames.indexOf(dex)
23
+ export const getProviderIndex = (
24
+ provider: string,
25
+ providerNames: string[]
26
+ ): number => {
27
+ const index = providerNames.indexOf(provider)
22
28
  if (index === -1) {
23
- throw new Error(`Unknown sub-dex: ${dex}`)
29
+ throw new Error(`Unknown sub-provider: ${provider}`)
24
30
  }
25
31
  return index
26
32
  }