Merge feature/use-dex-config into feature/v2-prep
Some checks failed
V2 CI/CD Pipeline / Pre-Flight Checks (push) Has been cancelled
V2 CI/CD Pipeline / Build & Dependencies (push) Has been cancelled
V2 CI/CD Pipeline / Code Quality & Linting (push) Has been cancelled
V2 CI/CD Pipeline / Unit Tests (100% Coverage Required) (push) Has been cancelled
V2 CI/CD Pipeline / Integration Tests (push) Has been cancelled
V2 CI/CD Pipeline / Performance Benchmarks (push) Has been cancelled
V2 CI/CD Pipeline / Decimal Precision Validation (push) Has been cancelled
V2 CI/CD Pipeline / Modularity Validation (push) Has been cancelled
V2 CI/CD Pipeline / Final Validation Summary (push) Has been cancelled

Externalized DEX configuration to config/dex.yaml, removing hardcoded routers.

## Summary
Replaced 12 hardcoded router addresses with externalized configuration,
enabling easy updates without code changes.

## Benefits
- Configuration flexibility
- No code changes needed for new DEX routers
- Centralized in config/dex.yaml
- Backward compatible with selector matching

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Administrator
2025-11-11 13:58:18 +01:00

View File

@@ -11,9 +11,23 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/your-org/mev-bot/pkg/config"
"github.com/your-org/mev-bot/pkg/validation"
)
// Package-level DEX configuration
var dexConfig *config.DEXConfig
// InitDEXConfig loads the DEX configuration from file
func InitDEXConfig(configPath string) error {
cfg, err := config.LoadDEXConfig(configPath)
if err != nil {
return fmt.Errorf("failed to load DEX config: %w", err)
}
dexConfig = cfg
return nil
}
// L2MessageKind represents the type of L2 message
type L2MessageKind uint8
@@ -233,36 +247,17 @@ func GetSwapProtocol(to *common.Address, data []byte) *DEXProtocol {
selector := hex.EncodeToString(data[0:4])
toAddr := to.Hex()
// Map known router addresses (Arbitrum mainnet)
knownRouters := map[string]*DEXProtocol{
// UniswapV2/V3
"0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506": {Name: "SushiSwap", Version: "V2", Type: "router"},
"0xE592427A0AEce92De3Edee1F18E0157C05861564": {Name: "UniswapV3", Version: "V1", Type: "router"},
"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45": {Name: "UniswapV3", Version: "V2", Type: "router"},
"0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B": {Name: "UniswapUniversal", Version: "V1", Type: "router"},
// Camelot
"0xc873fEcbd354f5A56E00E710B90EF4201db2448d": {Name: "Camelot", Version: "V2", Type: "router"},
"0x1F721E2E82F6676FCE4eA07A5958cF098D339e18": {Name: "Camelot", Version: "V3", Type: "router"},
// Balancer
"0xBA12222222228d8Ba445958a75a0704d566BF2C8": {Name: "Balancer", Version: "V2", Type: "vault"},
// Curve
"0x7544Fe3d184b6B55D6B36c3FCA1157eE0Ba30287": {Name: "Curve", Version: "V1", Type: "router"},
// Kyber
"0x6131B5fae19EA4f9D964eAc0408E4408b66337b5": {Name: "KyberSwap", Version: "V1", Type: "router"},
"0xC1e7dFE73E1598E3910EF4C7845B68A19f0e8c6F": {Name: "KyberSwap", Version: "V2", Type: "router"},
// Aggregators
"0x1111111254EEB25477B68fb85Ed929f73A960582": {Name: "1inch", Version: "V5", Type: "router"},
"0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57": {Name: "Paraswap", Version: "V5", Type: "router"},
}
// Check if it's a known router
if protocol, ok := knownRouters[toAddr]; ok {
return protocol
// Check if it's a known router (from config if loaded, else use fallback)
if dexConfig != nil {
for addr, routerCfg := range dexConfig.Routers {
if addr == toAddr {
return &DEXProtocol{
Name: routerCfg.Name,
Version: routerCfg.Version,
Type: routerCfg.Type,
}
}
}
}
// Try to identify by function selector