Completed clean root directory structure: - Root now contains only: .git, .env, docs/, orig/ - Moved all remaining files and directories to orig/: - Config files (.claude, .dockerignore, .drone.yml, etc.) - All .env variants (except active .env) - Git config (.gitconfig, .github, .gitignore, etc.) - Tool configs (.golangci.yml, .revive.toml, etc.) - Documentation (*.md files, @prompts) - Build files (Dockerfiles, Makefile, go.mod, go.sum) - Docker compose files - All source directories (scripts, tests, tools, etc.) - Runtime directories (logs, monitoring, reports) - Dependency files (node_modules, lib, cache) - Special files (--delete) - Removed empty runtime directories (bin/, data/) V2 structure is now clean: - docs/planning/ - V2 planning documents - orig/ - Complete V1 codebase preserved - .env - Active environment config (not in git) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
141 lines
3.9 KiB
Go
141 lines
3.9 KiB
Go
package testutils
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/holiman/uint256"
|
|
|
|
"github.com/fraktal/mev-beta/internal/config"
|
|
"github.com/fraktal/mev-beta/internal/logger"
|
|
"github.com/fraktal/mev-beta/pkg/events"
|
|
"github.com/fraktal/mev-beta/pkg/market"
|
|
"github.com/fraktal/mev-beta/pkg/scanner"
|
|
)
|
|
|
|
// safeConvertInt64ToUint64 safely converts an int64 to uint64, ensuring no negative values
|
|
func safeConvertInt64ToUint64(v int64) uint64 {
|
|
if v < 0 {
|
|
return 0
|
|
}
|
|
return uint64(v)
|
|
}
|
|
|
|
// CreateTestConfig creates a test configuration
|
|
func CreateTestConfig() *config.Config {
|
|
return &config.Config{
|
|
Arbitrum: config.ArbitrumConfig{
|
|
RPCEndpoint: "https://arb1.arbitrum.io/rpc",
|
|
ChainID: 42161,
|
|
RateLimit: config.RateLimitConfig{
|
|
RequestsPerSecond: 10,
|
|
MaxConcurrent: 5,
|
|
Burst: 20,
|
|
},
|
|
},
|
|
Bot: config.BotConfig{
|
|
Enabled: true,
|
|
PollingInterval: 1,
|
|
MinProfitThreshold: 10.0,
|
|
GasPriceMultiplier: 1.2,
|
|
MaxWorkers: 10,
|
|
ChannelBufferSize: 100,
|
|
RPCTimeout: 30,
|
|
},
|
|
Uniswap: config.UniswapConfig{
|
|
FactoryAddress: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
|
PositionManagerAddress: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
|
|
FeeTiers: []int64{500, 3000, 10000},
|
|
Cache: config.CacheConfig{
|
|
Enabled: true,
|
|
Expiration: 300,
|
|
MaxSize: 10000,
|
|
},
|
|
},
|
|
Log: config.LogConfig{
|
|
Level: "info",
|
|
Format: "text",
|
|
File: "",
|
|
},
|
|
Database: config.DatabaseConfig{
|
|
File: "mev-bot.db",
|
|
MaxOpenConnections: 10,
|
|
MaxIdleConnections: 5,
|
|
},
|
|
}
|
|
}
|
|
|
|
// CreateTestLogger creates a test logger
|
|
func CreateTestLogger() *logger.Logger {
|
|
return logger.New("info", "text", "")
|
|
}
|
|
|
|
// CreateTestEvent creates a test event
|
|
func CreateTestEvent() *events.Event {
|
|
return &events.Event{
|
|
Type: events.Swap,
|
|
Protocol: "UniswapV3",
|
|
PoolAddress: common.HexToAddress("0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640"),
|
|
Token0: common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
|
|
Token1: common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
|
Amount0: big.NewInt(1000000000),
|
|
Amount1: big.NewInt(500000000000000000),
|
|
SqrtPriceX96: uint256.NewInt(2505414483750470000),
|
|
Liquidity: uint256.NewInt(1000000000000000000),
|
|
Tick: 200000,
|
|
Timestamp: safeConvertInt64ToUint64(time.Now().Unix()),
|
|
TransactionHash: common.HexToHash("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"),
|
|
BlockNumber: 12345,
|
|
}
|
|
}
|
|
|
|
// CreateTestTransaction creates a test transaction
|
|
func CreateTestTransaction() *types.Transaction {
|
|
to := common.HexToAddress("0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640")
|
|
return types.NewTransaction(0, to, big.NewInt(0), 0, big.NewInt(0), nil)
|
|
}
|
|
|
|
// CreateTestMarketManager creates a test market manager
|
|
func CreateTestMarketManager() *market.MarketManager {
|
|
cfg := &config.UniswapConfig{
|
|
Cache: config.CacheConfig{
|
|
Expiration: 300,
|
|
MaxSize: 10000,
|
|
},
|
|
}
|
|
logger := CreateTestLogger()
|
|
return market.NewMarketManager(cfg, logger)
|
|
}
|
|
|
|
// CreateTestScanner creates a test market scanner
|
|
func CreateTestScanner() *scanner.Scanner {
|
|
cfg := &config.BotConfig{
|
|
MaxWorkers: 5,
|
|
ChannelBufferSize: 10,
|
|
RPCTimeout: 30,
|
|
MinProfitThreshold: 10.0,
|
|
}
|
|
logger := CreateTestLogger()
|
|
return scanner.NewScanner(cfg, logger, nil, nil, nil)
|
|
}
|
|
|
|
// CreateTestPipeline creates a test pipeline
|
|
func CreateTestPipeline() *market.Pipeline {
|
|
cfg := &config.BotConfig{
|
|
MaxWorkers: 5,
|
|
ChannelBufferSize: 10,
|
|
}
|
|
logger := CreateTestLogger()
|
|
marketMgr := CreateTestMarketManager()
|
|
scanner := CreateTestScanner()
|
|
return market.NewPipeline(cfg, logger, marketMgr, scanner, nil)
|
|
}
|
|
|
|
// CreateTestContext creates a test context
|
|
func CreateTestContext() context.Context {
|
|
return context.Background()
|
|
}
|