feat(core): implement core MEV bot functionality with market scanning and Uniswap V3 pricing
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -129,7 +129,7 @@ func (sc *SecureConfig) Set(key, value string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encrypt value for key %s: %w", key, err)
|
||||
}
|
||||
|
||||
|
||||
sc.values[key] = encrypted
|
||||
return nil
|
||||
}
|
||||
@@ -151,11 +151,11 @@ func (sc *SecureConfig) GetRequired(key string) (string, error) {
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("required configuration value missing: %s", key)
|
||||
}
|
||||
|
||||
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return "", fmt.Errorf("required configuration value empty: %s", key)
|
||||
}
|
||||
|
||||
|
||||
return value, nil
|
||||
}
|
||||
|
||||
@@ -176,13 +176,13 @@ func (sc *SecureConfig) LoadFromEnvironment(keys []string) error {
|
||||
sc.manager.logger.Warn(fmt.Sprintf("Could not load secure config for %s: %v", key, err))
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
// Store encrypted in memory
|
||||
if err := sc.Set(key, value); err != nil {
|
||||
return fmt.Errorf("failed to store secure config for %s: %w", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -199,17 +199,17 @@ func (sc *SecureConfig) Clear() {
|
||||
// Validate checks that all required configuration is present
|
||||
func (sc *SecureConfig) Validate(requiredKeys []string) error {
|
||||
var missingKeys []string
|
||||
|
||||
|
||||
for _, key := range requiredKeys {
|
||||
if _, err := sc.GetRequired(key); err != nil {
|
||||
missingKeys = append(missingKeys, key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(missingKeys) > 0 {
|
||||
return fmt.Errorf("missing required configuration keys: %s", strings.Join(missingKeys, ", "))
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func GenerateConfigKey() (string, error) {
|
||||
if _, err := rand.Read(key); err != nil {
|
||||
return "", fmt.Errorf("failed to generate random key: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return base64.StdEncoding.EncodeToString(key), nil
|
||||
}
|
||||
|
||||
@@ -240,11 +240,11 @@ func (cv *ConfigValidator) ValidateURL(url string) error {
|
||||
if url == "" {
|
||||
return errors.New("URL cannot be empty")
|
||||
}
|
||||
|
||||
|
||||
if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "wss://") {
|
||||
return errors.New("URL must use HTTPS or WSS protocol")
|
||||
}
|
||||
|
||||
|
||||
// Additional validation could go here (DNS lookup, connection test, etc.)
|
||||
return nil
|
||||
}
|
||||
@@ -254,16 +254,16 @@ func (cv *ConfigValidator) ValidateAPIKey(key string) error {
|
||||
if key == "" {
|
||||
return errors.New("API key cannot be empty")
|
||||
}
|
||||
|
||||
|
||||
if len(key) < 32 {
|
||||
return errors.New("API key must be at least 32 characters")
|
||||
}
|
||||
|
||||
|
||||
// Check for basic entropy (not all same character, contains mixed case, etc.)
|
||||
if strings.Count(key, string(key[0])) == len(key) {
|
||||
return errors.New("API key lacks sufficient entropy")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -272,21 +272,21 @@ func (cv *ConfigValidator) ValidateAddress(address string) error {
|
||||
if address == "" {
|
||||
return errors.New("address cannot be empty")
|
||||
}
|
||||
|
||||
|
||||
if !strings.HasPrefix(address, "0x") {
|
||||
return errors.New("address must start with 0x")
|
||||
}
|
||||
|
||||
|
||||
if len(address) != 42 { // 0x + 40 hex chars
|
||||
return errors.New("address must be 42 characters long")
|
||||
}
|
||||
|
||||
|
||||
// Validate hex format
|
||||
for i, char := range address[2:] {
|
||||
if !((char >= '0' && char <= '9') || (char >= 'a' && char <= 'f') || (char >= 'A' && char <= 'F')) {
|
||||
return fmt.Errorf("invalid hex character at position %d: %c", i+2, char)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user