fix: HL testnet - add API wallet address to signed orders, 3-param constructor

This commit is contained in:
jackyu66git
2026-05-04 15:39:31 +08:00
parent 30436bbe75
commit c5c4c7394f
3 changed files with 17 additions and 4 deletions
+13 -2
View File
@@ -39,6 +39,7 @@ type HLSignedAction struct {
Action HLOrderAction `json:"action"`
Nonce int64 `json:"nonce"`
Signature string `json:"signature"`
Address string `json:"address"` // API wallet address (signer)
VaultAddress string `json:"vaultAddress,omitempty"`
}
@@ -51,12 +52,13 @@ type HLOrderResponse struct {
type HyperLiquidTrade struct {
PrivateKey ed25519.PrivateKey
Address string
APIAddress string // API wallet address (signer), derived from private key
client *http.Client
lastNonce int64
nonceMu sync.Mutex // protect lastNonce++ (Issue #4)
}
func NewHyperLiquidTrade(privateKeyHex, address string) (*HyperLiquidTrade, error) {
func NewHyperLiquidTrade(privateKeyHex, mainAddress, apiAddress string) (*HyperLiquidTrade, error) {
if privateKeyHex == "" {
return &HyperLiquidTrade{client: &http.Client{Timeout: 10 * time.Second}}, nil
}
@@ -81,9 +83,17 @@ func NewHyperLiquidTrade(privateKeyHex, address string) (*HyperLiquidTrade, erro
return nil, fmt.Errorf("invalid private key length: %d (expected 32 or %d)", len(keyBytes), ed25519.PrivateKeySize)
}
// If apiAddress not provided, derive from private key
if apiAddress == "" {
privKey := ed25519.PrivateKey(keyBytes)
pubKey := privKey.Public().(ed25519.PublicKey)
apiAddress = "0x" + hex.EncodeToString(pubKey)
}
return &HyperLiquidTrade{
PrivateKey: ed25519.PrivateKey(keyBytes),
Address: address,
Address: mainAddress,
APIAddress: apiAddress,
client: &http.Client{Timeout: 10 * time.Second},
}, nil
}
@@ -130,6 +140,7 @@ func (h *HyperLiquidTrade) PlaceMarketOrder(coin, side, sz string) (string, erro
Action: action,
Nonce: nonce,
Signature: sig,
Address: h.APIAddress,
}
bodyJSON, _ := json.Marshal(signed)