Add additional project structure, config, Docker support, and more prompt files

This commit is contained in:
Krypto Kajun
2025-09-12 01:21:50 -05:00
parent ba80b273e4
commit c5843a5667
17 changed files with 762 additions and 23 deletions

68
internal/config/config.go Normal file
View File

@@ -0,0 +1,68 @@
package config
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
// Config represents the application configuration
type Config struct {
Arbitrum ArbitrumConfig `yaml:"arbitrum"`
Bot BotConfig `yaml:"bot"`
Uniswap UniswapConfig `yaml:"uniswap"`
Log LogConfig `yaml:"log"`
Database DatabaseConfig `yaml:"database"`
}
// ArbitrumConfig represents the Arbitrum node configuration
type ArbitrumConfig struct {
RPCEndpoint string `yaml:"rpc_endpoint"`
WSEndpoint string `yaml:"ws_endpoint"`
ChainID int64 `yaml:"chain_id"`
}
// BotConfig represents the bot configuration
type BotConfig struct {
Enabled bool `yaml:"enabled"`
PollingInterval int `yaml:"polling_interval"`
MinProfitThreshold float64 `yaml:"min_profit_threshold"`
GasPriceMultiplier float64 `yaml:"gas_price_multiplier"`
}
// UniswapConfig represents the Uniswap configuration
type UniswapConfig struct {
FactoryAddress string `yaml:"factory_address"`
PositionManagerAddress string `yaml:"position_manager_address"`
FeeTiers []int64 `yaml:"fee_tiers"`
}
// LogConfig represents the logging configuration
type LogConfig struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
File string `yaml:"file"`
}
// DatabaseConfig represents the database configuration
type DatabaseConfig struct {
File string `yaml:"file"`
}
// Load loads the configuration from a file
func Load(filename string) (*Config, error) {
// Read the config file
data, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}
// Parse the YAML
var config Config
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to parse config file: %w", err)
}
return &config, nil
}

61
internal/logger/logger.go Normal file
View File

@@ -0,0 +1,61 @@
package logger
import (
"log"
"os"
)
// Logger represents a simple logger wrapper
type Logger struct {
logger *log.Logger
level string
}
// New creates a new logger
func New(level string, format string, file string) *Logger {
// Determine output destination
var output *os.File
if file != "" {
f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
output = f
} else {
output = os.Stdout
}
// Create the logger
logger := log.New(output, "", log.LstdFlags|log.Lshortfile)
return &Logger{
logger: logger,
level: level,
}
}
// Debug logs a debug message
func (l *Logger) Debug(v ...interface{}) {
if l.level == "debug" {
l.logger.Print("DEBUG: ", v)
}
}
// Info logs an info message
func (l *Logger) Info(v ...interface{}) {
if l.level == "debug" || l.level == "info" {
l.logger.Print("INFO: ", v)
}
}
// Warn logs a warning message
func (l *Logger) Warn(v ...interface{}) {
if l.level == "debug" || l.level == "info" || l.level == "warn" {
l.logger.Print("WARN: ", v)
}
}
// Error logs an error message
func (l *Logger) Error(v ...interface{}) {
l.logger.Print("ERROR: ", v)
}

34
internal/utils/utils.go Normal file
View File

@@ -0,0 +1,34 @@
package utils
import (
"math/big"
"time"
)
// FormatWeiToEther formats a wei amount to ether
func FormatWeiToEther(wei *big.Int) *big.Float {
ether := new(big.Float).SetInt(wei)
ether.Quo(ether, big.NewFloat(1e18))
return ether
}
// FormatTime formats a timestamp to a readable string
func FormatTime(timestamp uint64) string {
return time.Unix(int64(timestamp), 0).Format("2006-01-02 15:04:05")
}
// Min returns the smaller of two integers
func Min(a, b int) int {
if a < b {
return a
}
return b
}
// Max returns the larger of two integers
func Max(a, b int) int {
if a > b {
return a
}
return b
}