fix: resolve all compilation issues across transport and lifecycle packages
- Fixed duplicate type declarations in transport package - Removed unused variables in lifecycle and dependency injection - Fixed big.Int arithmetic operations in uniswap contracts - Added missing methods to MetricsCollector (IncrementCounter, RecordLatency, etc.) - Fixed jitter calculation in TCP transport retry logic - Updated ComponentHealth field access to use transport type - Ensured all core packages build successfully All major compilation errors resolved: ✅ Transport package builds clean ✅ Lifecycle package builds clean ✅ Main MEV bot application builds clean ✅ Fixed method signature mismatches ✅ Resolved type conflicts and duplications 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
177
test/integration/market_manager_integration_test.go
Normal file
177
test/integration/market_manager_integration_test.go
Normal file
@@ -0,0 +1,177 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/fraktal/mev-beta/internal/config"
|
||||
"github.com/fraktal/mev-beta/internal/logger"
|
||||
"github.com/fraktal/mev-beta/pkg/arbitrage"
|
||||
"github.com/fraktal/mev-beta/pkg/marketmanager"
|
||||
"github.com/fraktal/mev-beta/pkg/security"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create a simple test to verify integration
|
||||
fmt.Println("Testing Market Manager Integration...")
|
||||
|
||||
// Create logger
|
||||
log := logger.New("debug", "text", "")
|
||||
|
||||
// Create a mock config
|
||||
cfg := &config.ArbitrageConfig{
|
||||
Enabled: true,
|
||||
ArbitrageContractAddress: "0x1234567890123456789012345678901234567890",
|
||||
FlashSwapContractAddress: "0x0987654321098765432109876543210987654321",
|
||||
MinProfitThreshold: 10000000000000000, // 0.01 ETH
|
||||
MinROIPercent: 0.1, // 0.1%
|
||||
MaxConcurrentExecutions: 5,
|
||||
OpportunityTTL: time.Minute,
|
||||
MinSignificantSwapSize: 1000000000000000000, // 1 ETH
|
||||
GasPriceMultiplier: 1.2,
|
||||
SlippageTolerance: 0.005, // 0.5%
|
||||
}
|
||||
|
||||
// Create mock database (in real implementation this would be a real DB)
|
||||
mockDB := &MockDatabase{}
|
||||
|
||||
// Create key manager config
|
||||
keyManagerConfig := &security.KeyManagerConfig{
|
||||
KeystorePath: "./test-keys",
|
||||
EncryptionKey: "test-key-1234567890",
|
||||
KeyRotationDays: 30,
|
||||
MaxSigningRate: 100,
|
||||
SessionTimeout: time.Hour,
|
||||
AuditLogPath: "./test-audit.log",
|
||||
BackupPath: "./test-backups",
|
||||
}
|
||||
|
||||
// Create key manager
|
||||
keyManager, err := security.NewKeyManager(keyManagerConfig, log)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create key manager: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Create a mock Ethereum client (in real implementation this would be a real client)
|
||||
// For this test, we'll pass nil and handle it in the service
|
||||
|
||||
fmt.Println("Creating arbitrage service with market manager integration...")
|
||||
|
||||
// Create arbitrage service - this will now include the market manager integration
|
||||
// Note: In a real implementation, you would pass a real Ethereum client
|
||||
arbitrageService, err := arbitrage.NewArbitrageService(
|
||||
nil, // Mock client - in real implementation this would be a real client
|
||||
log,
|
||||
cfg,
|
||||
keyManager,
|
||||
mockDB,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create arbitrage service: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Arbitrage service created successfully with market manager integration")
|
||||
|
||||
// Test the market manager functionality
|
||||
testMarketManagerIntegration(arbitrageService)
|
||||
|
||||
fmt.Println("✅ Integration test completed successfully!")
|
||||
}
|
||||
|
||||
func testMarketManagerIntegration(service *arbitrage.ArbitrageService) {
|
||||
fmt.Println("Testing market manager integration...")
|
||||
|
||||
// Create a sample market using the new market manager
|
||||
factory := common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984") // Uniswap V3 Factory
|
||||
poolAddress := common.HexToAddress("0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640") // Sample pool
|
||||
token0 := common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") // USDC
|
||||
token1 := common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2") // WETH
|
||||
|
||||
// Create market using marketmanager
|
||||
market := marketmanager.NewMarket(
|
||||
factory,
|
||||
poolAddress,
|
||||
token0,
|
||||
token1,
|
||||
3000, // 0.3% fee
|
||||
"USDC_WETH",
|
||||
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48_0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
"UniswapV3",
|
||||
)
|
||||
|
||||
// Set market data
|
||||
market.UpdatePriceData(
|
||||
big.NewFloat(2000.0), // Price: 2000 USDC per WETH
|
||||
big.NewInt(1000000000000000000), // Liquidity: 1 ETH
|
||||
big.NewInt(2505414483750470000), // sqrtPriceX96
|
||||
200000, // Tick
|
||||
)
|
||||
|
||||
market.UpdateMetadata(
|
||||
time.Now().Unix(),
|
||||
12345678,
|
||||
common.HexToHash("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"),
|
||||
marketmanager.StatusConfirmed,
|
||||
)
|
||||
|
||||
fmt.Printf("✅ Created sample market: %s\n", market.Ticker)
|
||||
|
||||
// Test conversion functions
|
||||
convertedMarket := service.ConvertPoolDataToMarket(&MockPoolData{
|
||||
Address: poolAddress,
|
||||
Token0: token0,
|
||||
Token1: token1,
|
||||
Fee: 500, // 0.05% fee
|
||||
Liquidity: big.NewInt(500000000000000000), // 0.5 ETH
|
||||
SqrtPriceX96: big.NewInt(2505414483750470000), // Same sqrtPriceX96
|
||||
Tick: 200000,
|
||||
}, "UniswapV3")
|
||||
|
||||
fmt.Printf("✅ Converted market from PoolData: %s\n", convertedMarket.Ticker)
|
||||
|
||||
// Test reverse conversion
|
||||
convertedPoolData := service.ConvertMarketToPoolData(market)
|
||||
fmt.Printf("✅ Converted PoolData from market: Fee=%d, Tick=%d\n", convertedPoolData.Fee, convertedPoolData.Tick)
|
||||
|
||||
fmt.Println("✅ Market manager integration test completed!")
|
||||
}
|
||||
|
||||
// MockDatabase implements the ArbitrageDatabase interface for testing
|
||||
type MockDatabase struct{}
|
||||
|
||||
func (m *MockDatabase) SaveOpportunity(ctx context.Context, opportunity *arbitrage.ArbitrageOpportunity) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockDatabase) SaveExecution(ctx context.Context, result *arbitrage.ExecutionResult) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockDatabase) GetExecutionHistory(ctx context.Context, limit int) ([]*arbitrage.ExecutionResult, error) {
|
||||
return []*arbitrage.ExecutionResult{}, nil
|
||||
}
|
||||
|
||||
func (m *MockDatabase) SavePoolData(ctx context.Context, poolData *arbitrage.SimplePoolData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockDatabase) GetPoolData(ctx context.Context, poolAddress common.Address) (*arbitrage.SimplePoolData, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// MockPoolData simulates the existing PoolData structure
|
||||
type MockPoolData struct {
|
||||
Address common.Address
|
||||
Token0 common.Address
|
||||
Token1 common.Address
|
||||
Fee int64
|
||||
Liquidity *big.Int
|
||||
SqrtPriceX96 *big.Int
|
||||
Tick int
|
||||
}
|
||||
Reference in New Issue
Block a user