diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 0000000..d0e7f93 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,51 @@ +# Git Configuration for MEV Bot Project + +This file contains the Git configuration settings for the MEV Bot project. + +## Project-Level Git Configuration + +```ini +[core] + autocrlf = input + editor = code --wait + excludesfile = ~/.gitignore + +[push] + default = simple + +[pull] + rebase = true + +[merge] + tool = vimdiff + +[diff] + tool = vimdiff + +[color] + ui = auto + +[help] + autocorrect = 1 + +[alias] + st = status + co = checkout + br = branch + ci = commit + unstage = reset HEAD -- + last = log -1 HEAD + graph = log --oneline --graph --decorate --all + amend = commit --amend + fixup = commit --fixup + undo = reset --soft HEAD~1 + hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short + who = shortlog -s -- + grep = grep -I + +[rerere] + enabled = true + +[push] + followTags = true +``` \ No newline at end of file diff --git a/docs/BRANCH_STRATEGY.md b/docs/BRANCH_STRATEGY.md new file mode 100644 index 0000000..7b6ad6b --- /dev/null +++ b/docs/BRANCH_STRATEGY.md @@ -0,0 +1,193 @@ +# Branch Strategy for MEV Bot Project + +This document outlines the branching strategy for the MEV Bot project. + +## Branch Types + +### 1. Main Branches + +#### `main` +- Contains production-ready code +- Only accepts merges from `release/*` branches +- Always stable and deployable +- Protected branch - requires pull requests and code review + +#### `develop` +- Main development branch +- Contains latest delivered development changes +- All feature branches merge here +- Automated CI/CD pipeline runs on this branch + +### 2. Supporting Branches + +#### `feature/*` +- Used for developing new features +- Branch from: `develop` +- Merge back to: `develop` +- Branch naming: `feature/` +- Examples: + - `feature/add-market-scanner` + - `feature/improve-uniswap-pricing` + - `feature/add-logging` + +#### `fix/*` +- Used for bug fixes in development +- Branch from: `develop` +- Merge back to: `develop` +- Branch naming: `fix/` +- Examples: + - `fix/resolve-memory-leak` + - `fix/correct-pricing-calculation` + +#### `release/*` +- Used for release preparation +- Branch from: `develop` +- Merge back to: `main` and `develop` +- Branch naming: `release/` +- Examples: + - `release/v1.2.0` + - `release/v2.0.0` + +#### `hotfix/*` +- Used for critical production fixes +- Branch from: `main` +- Merge back to: `main` and `develop` +- Branch naming: `hotfix/` +- Examples: + - `hotfix/security-patch` + - `hotfix/critical-bug-fix` + +## Workflow Examples + +### Feature Development Workflow +```bash +# 1. Create feature branch from develop +git checkout develop +git pull origin develop +git checkout -b feature/add-market-scanner + +# 2. Develop feature +# ... make changes ... +git add . +git commit -m "feat(market): implement basic market scanner" + +# 3. Keep feature branch up to date +git checkout develop +git pull origin develop +git checkout feature/add-market-scanner +git rebase develop + +# 4. Push feature branch +git push -u origin feature/add-market-scanner + +# 5. Create Pull Request on GitHub/GitLab +# 6. After PR approval and merge, delete branch +git checkout develop +git pull origin develop +git branch -d feature/add-market-scanner +git push origin --delete feature/add-market-scanner +``` + +### Release Workflow +```bash +# 1. Create release branch from develop +git checkout develop +git pull origin develop +git checkout -b release/v1.2.0 + +# 2. Prepare release +# ... bump version numbers, update docs ... +git add . +git commit -m "chore(release): prepare v1.2.0" + +# 3. Merge to main +git checkout main +git pull origin main +git merge release/v1.2.0 +git tag -a v1.2.0 -m "Release v1.2.0" +git push origin main --tags + +# 4. Merge to develop +git checkout develop +git pull origin develop +git merge release/v1.2.0 +git push origin develop + +# 5. Delete release branch +git branch -d release/v1.2.0 +git push origin --delete release/v1.2.0 +``` + +### Hotfix Workflow +```bash +# 1. Create hotfix branch from main +git checkout main +git pull origin main +git checkout -b hotfix/critical-security-issue + +# 2. Fix issue +# ... make changes ... +git add . +git commit -m "fix(security): resolve critical vulnerability" + +# 3. Merge to main +git checkout main +git pull origin main +git merge hotfix/critical-security-issue +git tag -a v1.1.1 -m "Hotfix v1.1.1" +git push origin main --tags + +# 4. Merge to develop +git checkout develop +git pull origin develop +git merge hotfix/critical-security-issue +git push origin develop + +# 5. Delete hotfix branch +git branch -d hotfix/critical-security-issue +git push origin --delete hotfix/critical-security-issue +``` + +## Branch Protection Rules + +### `main` Branch +- Require pull request reviews before merging +- Require status checks to pass before merging +- Require branches to be up to date before merging +- Include administrators in restrictions +- Allow force pushes: No +- Allow deletions: No + +### `develop` Branch +- Require pull request reviews before merging +- Require status checks to pass before merging +- Include administrators in restrictions +- Allow force pushes: No +- Allow deletions: No + +## Naming Conventions + +### Good Examples +- `feature/add-uniswap-v3-support` +- `fix/resolve-arbitrum-parser-bug` +- `release/v2.1.0` +- `hotfix/security-patch` + +### Avoid These +- `feature/fix` (unclear) +- `bugfix` (use `fix/` instead) +- `new-stuff` (not descriptive) +- `feature1` (not descriptive) + +## Best Practices + +1. **Keep branches short-lived** - Max 1-2 weeks +2. **Use descriptive names** - Clearly indicate purpose +3. **Keep features small** - One branch per logical feature +4. **Regularly sync with develop** - Prevent large merge conflicts +5. **Delete branches after merging** - Keep repository clean +6. **Use pull requests** - Enable code review and discussion +7. **Write meaningful commit messages** - Help with code review +8. **Tag releases** - Enable easy rollback and version tracking + +This branching strategy ensures a clean, organized Git history while enabling parallel development and maintaining code quality. \ No newline at end of file diff --git a/docs/GIT_WORKFLOW.md b/docs/GIT_WORKFLOW.md new file mode 100644 index 0000000..d8a8bed --- /dev/null +++ b/docs/GIT_WORKFLOW.md @@ -0,0 +1,264 @@ +# Git Workflow for MEV Bot Project + +This document outlines the Git workflow, best practices, and configurations for the MEV Bot project. + +## 🌿 Branch Strategy + +### Branch Naming Conventions +``` +main # Production-ready code +develop # Main development branch +feature/ # New features (e.g., feature/add-market-scanner) +fix/ # Bug fixes (e.g., fix/memory-leak) +hotfix/ # Critical production fixes (e.g., hotfix/security-patch) +release/ # Release preparation (e.g., release/v1.2.0) +``` + +### Branch Hierarchy +``` +main +└── develop + ├── feature/add-market-scanner + ├── feature/improve-performance + ├── fix/resolve-race-condition + └── release/v1.2.0 +``` + +## 📝 Commit Message Conventions + +### Format +``` +type(scope): brief description + +- Detailed explanation of changes +- Why the change was needed +- Any breaking changes or migration notes + +Resolves: #123 +See also: #456 +``` + +### Types +- `feat`: New feature implementation +- `fix`: Bug fix +- `perf`: Performance improvement +- `refactor`: Code restructuring without feature changes +- `test`: Adding or updating tests +- `docs`: Documentation updates +- `build`: Build system or dependency changes +- `ci`: CI/CD pipeline changes +- `chore`: Maintenance tasks + +### Scopes +- `arbitrum`: Arbitrum monitoring components +- `market`: Market analysis and scanning +- `uniswap`: Uniswap V3 pricing functions +- `config`: Configuration management +- `security`: Security-related changes +- `performance`: Performance optimizations +- `testing`: Test-related changes +- `logging`: Logging improvements +- `monitor`: Monitoring components +- `scanner`: Market scanning components + +## 🔄 Workflow Process + +### 1. Feature Development +```bash +# Create feature branch from develop +git checkout develop +git pull origin develop +git checkout -b feature/new-feature-name + +# Make changes and commit frequently +git add . +git commit -m "feat(scope): description of changes" + +# Push branch to remote +git push -u origin feature/new-feature-name +``` + +### 2. Code Review Process +1. Create Pull Request from feature branch to develop +2. Request review from team members +3. Address feedback and make changes +4. Get approval from reviewers +5. Merge to develop + +### 3. Release Process +```bash +# Create release branch +git checkout develop +git pull origin develop +git checkout -b release/v1.2.0 + +# Finalize release (version bumps, docs, etc.) +git add . +git commit -m "chore(release): prepare v1.2.0" + +# Merge to main and develop +git checkout main +git merge release/v1.2.0 +git tag -a v1.2.0 -m "Release v1.2.0" +git push origin main --tags + +git checkout develop +git merge release/v1.2.0 +git push origin develop + +# Delete release branch +git branch -d release/v1.2.0 +git push origin --delete release/v1.2.0 +``` + +### 4. Hotfix Process +```bash +# Create hotfix branch from main +git checkout main +git pull origin main +git checkout -b hotfix/critical-bug + +# Fix bug and commit +git add . +git commit -m "fix(security): resolve critical vulnerability" + +# Merge to main and develop +git checkout main +git merge hotfix/critical-bug +git tag -a v1.1.1 -m "Hotfix v1.1.1" +git push origin main --tags + +git checkout develop +git merge hotfix/critical-bug +git push origin develop + +# Delete hotfix branch +git branch -d hotfix/critical-bug +git push origin --delete hotfix/critical-bug +``` + +## 🛡️ Git Hooks + +### Pre-commit Hook +Validates code quality before committing: +- Run linters +- Run tests +- Check for secrets +- Validate commit message format + +### Pre-push Hook +Validates code before pushing: +- Run full test suite +- Run security scans +- Check code coverage + +## 📊 Git Configuration + +### User Configuration +```bash +git config user.name "Your Name" +git config user.email "your.email@example.com" +``` + +### Project Configuration +```bash +# Enable color output +git config color.ui auto + +# Set default editor +git config core.editor "code --wait" + +# Enable rebasing when pulling +git config pull.rebase true + +# Set up push behavior +git config push.default simple + +# Enable Git Large File Storage (if needed) +git config lfs.repositoryformatversion 0 +``` + +## 🔧 Git Aliases + +Add these helpful aliases to your Git configuration: +```bash +git config --global alias.st status +git config --global alias.co checkout +git config --global alias.br branch +git config --global alias.ci commit +git config --global alias.unstage 'reset HEAD --' +git config --global alias.last 'log -1 HEAD' +git config --global alias.visual '!gitk' +git config --global alias.graph 'log --oneline --graph --decorate --all' +git config --global alias.amend 'commit --amend' +git config --global alias.fixup 'commit --fixup' +``` + +## 🚀 Best Practices + +### Commit Frequency +- Commit early and often +- Each commit should represent a single logical change +- Write clear, descriptive commit messages +- Keep commits small and focused + +### Branch Management +- Delete branches after merging +- Keep feature branches up to date with develop +- Use descriptive branch names +- Limit branch lifetime (max 1-2 weeks) + +### Merge Strategies +- Use merge commits for feature branches to preserve history +- Use rebase for cleaning up local commit history +- Use squash merge for small features with multiple commits +- Always review changes before merging + +### Code Review +- Review code before merging to develop or main +- Ensure tests pass and coverage is maintained +- Check for security vulnerabilities +- Verify code follows project standards + +## 📈 Git Workflow Metrics + +Track these metrics to improve the development process: +- Average time from feature branch to merge +- Number of commits per pull request +- Code review turnaround time +- Merge conflict frequency +- Release frequency + +## 🆘 Troubleshooting + +### Common Issues + +#### Merge Conflicts +```bash +# Resolve conflicts and continue merge +git add . +git commit + +# Abort merge if needed +git merge --abort +``` + +#### Accidental Commits +```bash +# Amend last commit +git commit --amend + +# Remove file from last commit +git reset --soft HEAD~1 +``` + +#### Lost Commits +```bash +# Find lost commits +git reflog + +# Restore to specific commit +git reset --hard HEAD@{n} +``` + +This Git workflow ensures consistent, high-quality code contributions while maintaining a clean, traceable history. \ No newline at end of file diff --git a/scripts/git-workflow.sh b/scripts/git-workflow.sh new file mode 100755 index 0000000..b656ec4 --- /dev/null +++ b/scripts/git-workflow.sh @@ -0,0 +1,269 @@ +#!/bin/bash + +# git-workflow.sh - Helper script for Git workflow in MEV Bot project + +set -e # Exit on any error + +echo "MEV Bot Git Workflow Helper" +echo "==========================" + +# Function to display usage +usage() { + echo "Usage: $0 [command]" + echo "" + echo "Commands:" + echo " status - Show git status" + echo " commit - Commit changes with conventional commits" + echo " push - Push changes with pre-push checks" + echo " feature NAME - Create new feature branch" + echo " fix NAME - Create new fix branch" + echo " sync - Sync current branch with develop" + echo " pr - Prepare for pull request" + echo "" + echo "Examples:" + echo " $0 commit" + echo " $0 feature add-market-scanner" + echo " $0 fix resolve-memory-leak" +} + +# Function to check if we're in the right directory +check_directory() { + if [ ! -f "go.mod" ]; then + echo "Error: This script must be run from the project root directory" + exit 1 + fi +} + +# Function to show git status +show_status() { + echo "Git Status:" + echo "===========" + git status +} + +# Function to commit changes +commit_changes() { + echo "Committing changes..." + echo "Available file types to add:" + + # Show what files are modified + if [ -n "$(git diff --name-only)" ]; then + echo "Modified files:" + git diff --name-only + fi + + if [ -n "$(git diff --name-only --cached)" ]; then + echo "Staged files:" + git diff --name-only --cached + fi + + # Ask user what to do + echo "" + echo "Options:" + echo "1) Add all changes and commit" + echo "2) Add specific files and commit" + echo "3) Commit already staged changes" + echo "4) Cancel" + + read -p "Choose option (1-4): " choice + + case $choice in + 1) + git add . + ;; + 2) + echo "Enter files to add (space separated):" + read files + git add $files + ;; + 3) + # Use already staged files + ;; + 4) + echo "Commit cancelled" + return + ;; + *) + echo "Invalid option" + return + ;; + esac + + # Run pre-commit hook manually to show what it does + echo "Running pre-commit checks..." + .git/hooks/pre-commit + + # Get commit message + echo "" + echo "Enter commit message (follow conventional commits format):" + echo "Examples:" + echo " feat(market): add new arbitrage detection algorithm" + echo " fix(parser): resolve race condition in transaction parsing" + echo " perf(pricing): optimize Uniswap V3 calculations" + read -p "Commit message: " commit_msg + + if [ -n "$commit_msg" ]; then + git commit -m "$commit_msg" + echo "Changes committed successfully!" + else + echo "No commit message provided. Commit cancelled." + fi +} + +# Function to push changes +push_changes() { + echo "Pushing changes..." + + # Run pre-push hook manually to show what it does + echo "Running pre-push checks..." + .git/hooks/pre-push + + # Get current branch + branch=$(git rev-parse --abbrev-ref HEAD) + + # Push to origin + git push -u origin $branch + echo "Changes pushed successfully!" +} + +# Function to create feature branch +create_feature_branch() { + local feature_name=$1 + + if [ -z "$feature_name" ]; then + echo "Error: Feature name required" + echo "Usage: $0 feature " + return 1 + fi + + echo "Creating feature branch: feature/$feature_name" + + # Switch to develop and pull latest + git checkout develop + git pull origin develop + + # Create new feature branch + git checkout -b feature/$feature_name + echo "Feature branch 'feature/$feature_name' created and switched to." +} + +# Function to create fix branch +create_fix_branch() { + local fix_name=$1 + + if [ -z "$fix_name" ]; then + echo "Error: Fix name required" + echo "Usage: $0 fix " + return 1 + fi + + echo "Creating fix branch: fix/$fix_name" + + # Switch to develop and pull latest + git checkout develop + git pull origin develop + + # Create new fix branch + git checkout -b fix/$fix_name + echo "Fix branch 'fix/$fix_name' created and switched to." +} + +# Function to sync with develop +sync_with_develop() { + echo "Syncing current branch with develop..." + + # Get current branch + current_branch=$(git rev-parse --abbrev-ref HEAD) + + # Stash any changes + if [ -n "$(git status --porcelain)" ]; then + echo "Stashing changes..." + git stash + stashed=true + fi + + # Switch to develop and pull + git checkout develop + git pull origin develop + + # Switch back to original branch and rebase + git checkout $current_branch + git rebase develop + + # Pop stash if we had one + if [ "$stashed" = true ]; then + echo "Restoring stashed changes..." + git stash pop + fi + + echo "Sync completed!" +} + +# Function to prepare for PR +prepare_pr() { + echo "Preparing for Pull Request..." + + # Run tests + echo "Running tests..." + go test ./... + + # Run linter if available + if command -v golangci-lint >/dev/null 2>&1; then + echo "Running linter..." + golangci-lint run + else + echo "golangci-lint not found. Skipping linting." + fi + + # Check git status + echo "" + echo "Git status:" + git status + + echo "" + echo "Ready for Pull Request!" + echo "Next steps:" + echo "1. Push your branch: git push -u origin \$(git rev-parse --abbrev-ref HEAD)" + echo "2. Create PR on GitHub/GitLab" + echo "3. Request review from team members" +} + +# Main script logic +check_directory + +if [ $# -eq 0 ]; then + usage + exit 0 +fi + +COMMAND=$1 +shift + +case $COMMAND in + status) + show_status + ;; + commit) + commit_changes + ;; + push) + push_changes + ;; + feature) + create_feature_branch $1 + ;; + fix) + create_fix_branch $1 + ;; + sync) + sync_with_develop + ;; + pr) + prepare_pr + ;; + *) + echo "Unknown command: $COMMAND" + usage + exit 1 + ;; +esac \ No newline at end of file