mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-15 16:56:56 +08:00
feat(trader): wire Hyperliquid wallet and quick trade flow
- Add wallet API endpoints and exchange storage fields for Hyperliquid - Normalize quick trade order paths, symbols, and builder fee coverage - Add frontend wallet connect and quick trade helpers
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"nofx/logger"
|
||||
hlprovider "nofx/provider/hyperliquid"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -58,54 +59,25 @@ var xyzDexAssets = map[string]bool{
|
||||
"XYZ100": true,
|
||||
}
|
||||
|
||||
// defaultBuilder is the builder info for order routing
|
||||
// Set to nil to avoid requiring builder fee approval
|
||||
//
|
||||
// var defaultBuilder = &hyperliquid.BuilderInfo{
|
||||
// Builder: "0x891dc6f05ad47a3c1a05da55e7a7517971faaf0d",
|
||||
// Fee: 10,
|
||||
// }
|
||||
var defaultBuilder *hyperliquid.BuilderInfo = nil
|
||||
|
||||
// isXyzDexAsset checks if a symbol is an xyz dex asset
|
||||
func isXyzDexAsset(symbol string) bool {
|
||||
// Remove common suffixes to get base symbol
|
||||
base := strings.ToUpper(symbol) // Convert to uppercase for case-insensitive matching
|
||||
for _, suffix := range []string{"USDT", "USD", "-USDC", "-USD"} {
|
||||
if strings.HasSuffix(base, suffix) {
|
||||
base = strings.TrimSuffix(base, suffix)
|
||||
break
|
||||
}
|
||||
}
|
||||
// Remove xyz: prefix if present (case-insensitive)
|
||||
base = strings.TrimPrefix(base, "XYZ:")
|
||||
base = strings.TrimPrefix(base, "xyz:")
|
||||
return xyzDexAssets[base]
|
||||
// defaultBuilder is the builder info for order routing.
|
||||
// Users approve this builder during the top-right Hyperliquid connect flow before
|
||||
// their generated agent wallet is saved for live trading.
|
||||
var defaultBuilder = &hyperliquid.BuilderInfo{
|
||||
Builder: "0x891dc6f05ad47a3c1a05da55e7a7517971faaf0d",
|
||||
Fee: 100,
|
||||
}
|
||||
|
||||
// convertSymbolToHyperliquid converts standard symbol to Hyperliquid format
|
||||
// Example: "BTCUSDT" -> "BTC", "TSLA" -> "xyz:TSLA", "silver" -> "xyz:SILVER"
|
||||
// isXyzDexAsset checks if a symbol is an xyz dex asset.
|
||||
// Keep this delegated to the provider map so newly listed xyz markets such as
|
||||
// SAMSUNG-USDC / SK-HYNIX-USDC cannot accidentally fall through as crypto.
|
||||
func isXyzDexAsset(symbol string) bool {
|
||||
return hlprovider.IsXYZAsset(symbol)
|
||||
}
|
||||
|
||||
// convertSymbolToHyperliquid converts standard/display symbols to Hyperliquid format.
|
||||
// Examples: "BTCUSDT" -> "BTC", "TSLA" -> "xyz:TSLA", "SAMSUNG-USDC" -> "xyz:SMSN".
|
||||
func convertSymbolToHyperliquid(symbol string) string {
|
||||
// Convert to uppercase for consistent handling
|
||||
base := strings.ToUpper(symbol)
|
||||
|
||||
// Remove common suffixes to get base symbol
|
||||
for _, suffix := range []string{"USDT", "USD", "-USDC", "-USD"} {
|
||||
if strings.HasSuffix(base, suffix) {
|
||||
base = strings.TrimSuffix(base, suffix)
|
||||
break
|
||||
}
|
||||
}
|
||||
// Remove xyz: prefix if present (case-insensitive, will be re-added if needed)
|
||||
if strings.HasPrefix(strings.ToLower(base), "xyz:") {
|
||||
base = base[4:] // Remove first 4 characters
|
||||
}
|
||||
|
||||
// Check if this is an xyz dex asset (stocks, forex, commodities)
|
||||
if isXyzDexAsset(base) {
|
||||
return "xyz:" + base
|
||||
}
|
||||
return base
|
||||
return hlprovider.FormatCoinForAPI(symbol)
|
||||
}
|
||||
|
||||
// absFloat returns absolute value of float
|
||||
|
||||
Reference in New Issue
Block a user