-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathactions.go
More file actions
340 lines (293 loc) · 14.2 KB
/
actions.go
File metadata and controls
340 lines (293 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package hyperliquid
//go:generate easyjson -all
// Action structs with deterministic field ordering for consistent MessagePack serialization
// The order of fields in these structs is critical for signature generation
// CancelOrderWire represents cancel order item wire format
type CancelOrderWire struct {
Asset int `json:"a" msgpack:"a"`
OrderID int64 `json:"o" msgpack:"o"`
}
// CancelAction represents the cancel action
type CancelAction struct {
Type string `json:"type" msgpack:"type"`
Dex string `json:"dex,omitempty" msgpack:"dex,omitempty"`
Cancels []CancelOrderWire `json:"cancels" msgpack:"cancels"`
}
// CancelByCloidWire represents cancel by cloid item wire format
// NB: the CancelByCloidWire MUST have `asset` and not `o` like
// CancelOrderWire has
// See: https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/f19056ca1b65cc15a019d92dffa9ada887b3d808/hyperliquid/exchange.py#L305-L310
type CancelByCloidWire struct {
Asset int `json:"asset" msgpack:"asset"`
ClientID string `json:"cloid" msgpack:"cloid"`
}
// CancelByCloidAction represents the cancel by cloid action
type CancelByCloidAction struct {
Type string `json:"type" msgpack:"type"`
Dex string `json:"dex,omitempty" msgpack:"dex,omitempty"`
Cancels []CancelByCloidWire `json:"cancels" msgpack:"cancels"`
}
// UsdClassTransferAction represents USD class transfer
type UsdClassTransferAction struct {
Type string `json:"type" msgpack:"type"`
Amount string `json:"amount" msgpack:"amount"`
ToPerp bool `json:"toPerp" msgpack:"toPerp"`
Nonce int64 `json:"nonce" msgpack:"nonce"`
}
// SpotTransferAction represents spot transfer
type SpotTransferAction struct {
Type string `json:"type" msgpack:"type"`
Destination string `json:"destination" msgpack:"destination"`
Amount string `json:"amount" msgpack:"amount"`
Token string `json:"token" msgpack:"token"`
Time int64 `json:"time" msgpack:"time"`
}
// UsdTransferAction represents USD transfer
type UsdTransferAction struct {
Type string `json:"type" msgpack:"type"`
Destination string `json:"destination" msgpack:"destination"`
Amount string `json:"amount" msgpack:"amount"`
Time int64 `json:"time" msgpack:"time"`
}
// SubAccountTransferAction represents sub-account transfer
type SubAccountTransferAction struct {
Type string `json:"type" msgpack:"type"`
SubAccountUser string `json:"subAccountUser" msgpack:"subAccountUser"`
IsDeposit bool `json:"isDeposit" msgpack:"isDeposit"`
Usd int `json:"usd" msgpack:"usd"`
}
// VaultUsdTransferAction represents vault USD transfer
type VaultUsdTransferAction struct {
Type string `json:"type" msgpack:"type"`
VaultAddress string `json:"vaultAddress" msgpack:"vaultAddress"`
IsDeposit bool `json:"isDeposit" msgpack:"isDeposit"`
Usd int `json:"usd" msgpack:"usd"`
}
// CreateVaultAction represents create vault action
type CreateVaultAction struct {
Type string `json:"type" msgpack:"type"`
Name string `json:"name" msgpack:"name"`
Description string `json:"description" msgpack:"description"`
InitialUsd int `json:"initialUsd" msgpack:"initialUsd"`
}
// VaultModifyAction represents vault modify action
type VaultModifyAction struct {
Type string `json:"type" msgpack:"type"`
VaultAddress string `json:"vaultAddress" msgpack:"vaultAddress"`
AllowDeposits bool `json:"allowDeposits" msgpack:"allowDeposits"`
AlwaysCloseOnWithdraw bool `json:"alwaysCloseOnWithdraw" msgpack:"alwaysCloseOnWithdraw"`
}
// VaultDistributeAction represents vault distribute action
type VaultDistributeAction struct {
Type string `json:"type" msgpack:"type"`
VaultAddress string `json:"vaultAddress" msgpack:"vaultAddress"`
Usd int `json:"usd" msgpack:"usd"`
}
// UpdateLeverageAction represents leverage update
type UpdateLeverageAction struct {
Type string `json:"type" msgpack:"type"`
Asset int `json:"asset" msgpack:"asset"`
IsCross bool `json:"isCross" msgpack:"isCross"`
Leverage int `json:"leverage" msgpack:"leverage"`
}
// UpdateIsolatedMarginAction represents isolated margin update
type UpdateIsolatedMarginAction struct {
Type string `json:"type" msgpack:"type"`
Asset int `json:"asset" msgpack:"asset"`
IsBuy bool `json:"isBuy" msgpack:"isBuy"`
Ntli float64 `json:"ntli" msgpack:"ntli"`
}
// OrderWire represents the wire format for orders with deterministic field ordering
// CRITICAL: Field order MUST exactly match Python SDK insertion order: a, b, p, s, r, t, c
// See hyperliquid-python-sdk/hyperliquid/utils/signing.py:order_request_to_order_wire
type OrderWire struct {
Asset int `json:"a" msgpack:"a"` // 1st
IsBuy bool `json:"b" msgpack:"b"` // 2nd
LimitPx string `json:"p" msgpack:"p"` // 3rd
Size string `json:"s" msgpack:"s"` // 4th
ReduceOnly bool `json:"r" msgpack:"r"` // 5th
OrderType OrderWireType `json:"t" msgpack:"t"` // 6th
Cloid *string `json:"c,omitempty" msgpack:"c,omitempty"` // 7th (optional)
}
// OrderWireType represents the type of order (limit or trigger).
type OrderWireType struct {
Limit *OrderWireTypeLimit `json:"limit,omitempty" msgpack:"limit,omitempty"`
Trigger *OrderWireTypeTrigger `json:"trigger,omitempty" msgpack:"trigger,omitempty"`
}
// OrderWireTypeLimit represents a limit order with time-in-force.
type OrderWireTypeLimit struct {
Tif Tif `json:"tif,string" msgpack:"tif"`
}
// OrderWireTypeTrigger represents a trigger order (stop-loss/take-profit).
type OrderWireTypeTrigger struct {
// CRITICAL: Field order MUST match Python SDK insertion order: isMarket, triggerPx, tpsl
// See hyperliquid-python-sdk/hyperliquid/utils/signing.py:order_type_to_wire (lines 151-154)
IsMarket bool `json:"isMarket" msgpack:"isMarket"` // 1st
TriggerPx string `json:"triggerPx" msgpack:"triggerPx"` // 2nd - Must be string for msgpack serialization
Tpsl Tpsl `json:"tpsl" msgpack:"tpsl"` // 3rd - "tp" or "sl"
}
// OrderAction represents the order action with deterministic field ordering
// CRITICAL: Field order MUST match Python SDK insertion order for msgpack hash consistency
type OrderAction struct {
Type string `json:"type" msgpack:"type"`
Dex string `json:"dex,omitempty" msgpack:"dex,omitempty"`
Orders []OrderWire `json:"orders" msgpack:"orders"`
Grouping string `json:"grouping" msgpack:"grouping"`
Builder *BuilderInfo `json:"builder,omitempty" msgpack:"builder,omitempty"`
}
// ModifyAction represents a single order modification
type ModifyAction struct {
Type string `json:"type,omitempty" msgpack:"type,omitempty"`
Dex string `json:"dex,omitempty" msgpack:"dex,omitempty"`
Oid any `json:"oid" msgpack:"oid"`
Order OrderWire `json:"order" msgpack:"order"`
}
// BatchModifyAction represents multiple order modifications
type BatchModifyAction struct {
Type string `json:"type" msgpack:"type"`
Dex string `json:"dex,omitempty" msgpack:"dex,omitempty"`
Modifies []ModifyAction `json:"modifies" msgpack:"modifies"`
}
// PerpDexClassTransferAction represents perp dex class transfer
type PerpDexClassTransferAction struct {
Type string `json:"type" msgpack:"type"`
Dex string `json:"dex" msgpack:"dex"`
Token string `json:"token" msgpack:"token"`
Amount float64 `json:"amount" msgpack:"amount"`
ToPerp bool `json:"toPerp" msgpack:"toPerp"`
}
// SubAccountSpotTransferAction represents sub-account spot transfer
type SubAccountSpotTransferAction struct {
Type string `json:"type" msgpack:"type"`
SubAccountUser string `json:"subAccountUser" msgpack:"subAccountUser"`
IsDeposit bool `json:"isDeposit" msgpack:"isDeposit"`
Token string `json:"token" msgpack:"token"`
Amount float64 `json:"amount" msgpack:"amount"`
}
// ScheduleCancelAction represents schedule cancel action
type ScheduleCancelAction struct {
Type string `json:"type" msgpack:"type"`
Time *int64 `json:"time,omitempty" msgpack:"time,omitempty"`
}
// SetReferrerAction represents set referrer action
type SetReferrerAction struct {
Type string `json:"type" msgpack:"type"`
Code string `json:"code" msgpack:"code"`
}
// ReserveRequestWeightAction reserves request weight capacity
// Weight reservation costs 0.0005 USDC per weight unit
type ReserveRequestWeightAction struct {
Type string `json:"type" msgpack:"type"`
Weight int `json:"weight" msgpack:"weight"`
}
// CreateSubAccountAction represents create sub-account action
type CreateSubAccountAction struct {
Type string `json:"type" msgpack:"type"`
Name string `json:"name" msgpack:"name"`
}
// UseBigBlocksAction represents use big blocks action
type UseBigBlocksAction struct {
Type string `json:"type" msgpack:"type"`
UsingBigBlocks bool `json:"usingBigBlocks" msgpack:"usingBigBlocks"`
}
// TokenDelegateAction represents token delegate action
type TokenDelegateAction struct {
Type string `json:"type" msgpack:"type"`
Validator string `json:"validator" msgpack:"validator"`
Wei int `json:"wei" msgpack:"wei"`
IsUndelegate bool `json:"isUndelegate" msgpack:"isUndelegate"`
Nonce int64 `json:"nonce" msgpack:"nonce"`
}
// WithdrawFromBridgeAction represents withdraw from bridge action
type WithdrawFromBridgeAction struct {
Type string `json:"type" msgpack:"type"`
Destination string `json:"destination" msgpack:"destination"`
Amount string `json:"amount" msgpack:"amount"`
Time int64 `json:"time" msgpack:"time"`
}
// ApproveAgentAction represents approve agent action
type ApproveAgentAction struct {
Type string `json:"type" msgpack:"type"`
SignatureChainId string `json:"signatureChainId" msgpack:"signatureChainId"`
HyperliquidChain string `json:"hyperliquidChain" msgpack:"hyperliquidChain"`
AgentAddress string `json:"agentAddress" msgpack:"agentAddress"`
AgentName *string `json:"agentName,omitempty" msgpack:"agentName,omitempty"`
Nonce int64 `json:"nonce" msgpack:"nonce"`
}
// ApproveBuilderFeeAction represents approve builder fee action
type ApproveBuilderFeeAction struct {
Type string `json:"type" msgpack:"type"`
Builder string `json:"builder" msgpack:"builder"`
MaxFeeRate string `json:"maxFeeRate" msgpack:"maxFeeRate"`
Nonce int64 `json:"nonce" msgpack:"nonce"`
}
// ConvertToMultiSigUserAction represents convert to multi-sig user action
type ConvertToMultiSigUserAction struct {
Type string `json:"type" msgpack:"type"`
Signers string `json:"signers" msgpack:"signers"`
Nonce int64 `json:"nonce" msgpack:"nonce"`
}
// MultiSigAction represents multi-signature action
type MultiSigAction struct {
Type string `json:"type" msgpack:"type"`
Action map[string]any `json:"action" msgpack:"action"`
Signers []string `json:"signers" msgpack:"signers"`
Signatures []string `json:"signatures" msgpack:"signatures"`
}
type RegisterAssetSchema struct {
FullName string `json:"fullName" msgpack:"fullName"`
CollateralToken int `json:"collateralToken" msgpack:"collateralToken"`
OracleUpdater *string `json:"oracleUpdater" msgpack:"oracleUpdater"`
}
type AssetRequest struct {
Coin string `json:"coin" msgpack:"coin"`
SzDecimals int `json:"szDecimals" msgpack:"szDecimals"`
OraclePx string `json:"oraclePx" msgpack:"oraclePx"`
MarginTableID int `json:"marginTableId" msgpack:"marginTableId"`
OnlyIsolated bool `json:"onlyIsolated" msgpack:"onlyIsolated"`
}
type AssetRequest2 struct {
Coin string `json:"coin" msgpack:"coin"`
SzDecimals int `json:"szDecimals" msgpack:"szDecimals"`
OraclePx string `json:"oraclePx" msgpack:"oraclePx"`
MarginTableID int `json:"marginTableId" msgpack:"marginTableId"`
MarginMode string `json:"marginMode" msgpack:"marginMode"`
}
type RegisterAsset struct {
MaxGas *int `json:"maxGas" msgpack:"maxGas"`
AssetRequest AssetRequest `json:"assetRequest" msgpack:"assetRequest"`
Dex string `json:"dex" msgpack:"dex"`
Schema *RegisterAssetSchema `json:"schema" msgpack:"schema"`
}
type RegisterAsset2 struct {
MaxGas *int `json:"maxGas" msgpack:"maxGas"`
AssetRequest AssetRequest2 `json:"assetRequest" msgpack:"assetRequest"`
Dex string `json:"dex" msgpack:"dex"`
Schema *RegisterAssetSchema `json:"schema" msgpack:"schema"`
}
type PerpDeployRegisterAssetAction struct {
Type string `json:"type" msgpack:"type"`
RegisterAsset RegisterAsset `json:"registerAsset" msgpack:"registerAsset"`
}
type PerpDeployRegisterAsset2Action struct {
Type string `json:"type" msgpack:"type"`
RegisterAsset2 RegisterAsset2 `json:"registerAsset2" msgpack:"registerAsset2"`
}
type HaltTrading struct {
Coin string `json:"coin" msgpack:"coin"`
IsHalted bool `json:"isHalted" msgpack:"isHalted"`
}
type PerpDeployHaltTradingAction struct {
Type string `json:"type" msgpack:"type"`
HaltTrading HaltTrading `json:"haltTrading" msgpack:"haltTrading"`
}
type SetOracle struct {
Dex string `json:"dex" msgpack:"dex"`
OraclePxs [][]string `json:"oraclePxs" msgpack:"oraclePxs"`
MarkPxs [][][]string `json:"markPxs" msgpack:"markPxs"`
ExternalPerpPxs [][]string `json:"externalPerpPxs" msgpack:"externalPerpPxs"`
}
type PerpDeploySetOracleAction struct {
Type string `json:"type" msgpack:"type"`
SetOracle SetOracle `json:"setOracle" msgpack:"setOracle"`
}