Skip to content

A comprehensive yield farming client for Ethereum blockchain, implemented in both Rust and Go. This project provides robust, production-ready tools for interacting with DeFi yield farming protocols.

Notifications You must be signed in to change notification settings

xerion0712/yield-farming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Blockchain Yield Farming

A comprehensive yield farming client for Ethereum blockchain, implemented in both Rust and Go. This project provides robust, production-ready tools for interacting with DeFi yield farming protocols.

What is Yield Farming?

Yield farming, also known as liquidity mining, is a process where users earn rewards by providing liquidity to decentralized exchanges (DEXs) or other blockchain platforms. Users deposit their cryptocurrency assets into liquidity pools and earn rewards based on:

  • Amount of liquidity provided
  • Fees generated by the DEX
  • Additional reward tokens
  • Protocol incentives

Important Disclaimer

Yield farming involves significant risks:

  • Cryptocurrency price volatility
  • Smart contract vulnerabilities
  • Impermanent loss
  • Potential scams or rug pulls
  • Regulatory uncertainty

Always conduct thorough research and understand the risks before participating. This software is provided "as is" without warranties.

Project Structure

blockchain-yield-farming/
β”œβ”€β”€ src/                          # Rust source code
β”‚   └── main.rs                  # Main Rust application
β”œβ”€β”€ sample-example-web3.rs        # Rust yield farming client
β”œβ”€β”€ sample-example-go-ethereum.go # Go yield farming client
β”œβ”€β”€ Cargo.toml                   # Rust dependencies and configuration
β”œβ”€β”€ go.mod                       # Go module configuration
β”œβ”€β”€ README.md                    # This file
└── LICENSE                      # MIT License

Rust Implementation

Features

  • Async/Await Support: Modern async programming with Tokio
  • Comprehensive Client: Full-featured yield farming client
  • Error Handling: Robust error handling with proper Result types
  • Gas Optimization: Automatic gas estimation and optimization
  • Transaction Management: Complete transaction lifecycle management
  • Pool Analytics: Real-time pool statistics and APY calculations

Prerequisites

  • Rust 1.70+ (Install Rust)
  • Ethereum node access (Infura, Alchemy, or local node)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/blockchain-yield-farming.git
    cd blockchain-yield-farming
  2. Install dependencies:

    cargo build
  3. Configure environment:

    # Create .env file
    cp .env.example .env
    
    # Edit .env with your configuration
    RPC_URL=https://mainnet.infura.io/v3/YOUR_PROJECT_ID
    CONTRACT_ADDRESS=0x1234567890123456789012345678901234567890
    PRIVATE_KEY=your_private_key_here
  4. Run the application:

    cargo run

Usage Example

use blockchain_yield_farming::YieldFarmingClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize client
    let client = YieldFarmingClient::new(
        "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
        contract_address,
        contract_abi
    )?;
    
    // Get pool information
    let tvl = client.get_total_value_locked().await?;
    let apy = client.get_current_apy().await?;
    
    println!("Total Value Locked: {} wei", tvl);
    println!("Current APY: {}%", apy);
    
    // Deposit tokens
    let amount = U256::from(1000000000000000000u64); // 1 ETH
    let tx_hash = client.deposit(amount, account).await?;
    
    // Wait for confirmation
    let receipt = client.wait_for_transaction(tx_hash).await?;
    println!("Transaction confirmed in block {}", receipt.block_number);
    
    Ok(())
}

Go Implementation

Features

  • Production Ready: Enterprise-grade Go implementation
  • Context Support: Full context and cancellation support
  • Transaction Signing: Secure transaction signing and broadcasting
  • Gas Management: Automatic gas price and limit estimation
  • Error Handling: Comprehensive error handling with wrapped errors
  • Pool Monitoring: Real-time pool and user position monitoring

Prerequisites

  • Go 1.21+ (Install Go)
  • Ethereum node access (Infura, Alchemy, or local node)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/blockchain-yield-farming.git
    cd blockchain-yield-farming
  2. Install dependencies:

    go mod tidy
  3. Configure the application:

    // Edit the main function with your configuration
    rpcURL := "https://mainnet.infura.io/v3/YOUR_PROJECT_ID"
    contractAddress := common.HexToAddress("0x1234567890123456789012345678901234567890")
    privateKeyHex := "YOUR_PRIVATE_KEY_HERE"
  4. Run the application:

    go run sample-example-go-ethereum.go

Usage Example

package main

import (
    "context"
    "fmt"
    "math/big"
    
    "github.com/ethereum/go-ethereum/common"
)

func main() {
    ctx := context.Background()
    
    // Initialize client
    client, err := NewYieldFarmingClient(
        "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
        contractAddress,
        privateKeyHex,
    )
    if err != nil {
        log.Fatal(err)
    }
    
    // Get pool information
    poolInfo, err := client.GetPoolInfo(ctx)
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("Total Value Locked: %s wei\n", poolInfo.TotalValueLocked.String())
    fmt.Printf("Current APY: %s%%\n", poolInfo.CurrentAPY.String())
    
    // Deposit tokens
    amount := big.NewInt(1000000000000000000) // 1 ETH
    tx, err := client.Deposit(ctx, amount)
    if err != nil {
        log.Fatal(err)
    }
    
    // Wait for confirmation
    receipt, err := client.WaitForTransaction(ctx, tx)
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("Transaction confirmed in block %d\n", receipt.BlockNumber)
}

Configuration

Environment Variables

Create a .env file in the project root:

# Ethereum RPC endpoint
RPC_URL=https://mainnet.infura.io/v3/YOUR_PROJECT_ID

# Yield farming contract address
CONTRACT_ADDRESS=0x1234567890123456789012345678901234567890

# Your private key (keep this secret!)
PRIVATE_KEY=your_private_key_here

# Network configuration
CHAIN_ID=1
GAS_LIMIT=300000
GAS_PRICE=20000000000

# Pool configuration
MIN_DEPOSIT=1000000000000000000
MAX_DEPOSIT=1000000000000000000000

Network Support

  • Mainnet: Production Ethereum network
  • Goerli: Ethereum testnet (recommended for testing)
  • Sepolia: Ethereum testnet
  • Local: Local development network

Supported Operations

Core Functions

  • Deposit: Stake tokens in yield farming pools
  • Withdraw: Remove staked tokens from pools
  • Claim Rewards: Collect earned rewards
  • Harvest: Compound rewards back into the pool

Analytics & Monitoring

  • Pool Statistics: TVL, APY, reward rates
  • User Position: Staked balance, pending rewards
  • Transaction History: Complete transaction tracking
  • Performance Metrics: ROI calculations and analytics

Advanced Features

  • Gas Optimization: Automatic gas estimation and optimization
  • Batch Operations: Execute multiple operations in single transaction
  • Emergency Functions: Emergency withdrawal and pause functionality
  • Multi-Pool Support: Manage multiple yield farming pools

Testing

Rust Testing

# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test
cargo test test_client_initialization

Go Testing

# Run all tests
go test ./...

# Run tests with verbose output
go test -v ./...

# Run tests with race detection
go test -race ./...

Deployment

Production Considerations

  1. Security: Never commit private keys or sensitive data
  2. Monitoring: Implement comprehensive logging and monitoring
  3. Backup: Regular backup of configuration and state
  4. Updates: Keep dependencies updated for security patches
  5. Testing: Thorough testing on testnets before mainnet

Docker Support

FROM rust:1.70 as builder
WORKDIR /app
COPY . .
RUN cargo build --release

FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y ca-certificates
COPY --from=builder /app/target/release/yield-farming-client /usr/local/bin/
CMD ["yield-farming-client"]

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

πŸ“š Documentation

πŸ”’ Security

Best Practices

  • Private Key Management: Use hardware wallets or secure key management
  • Contract Verification: Always verify smart contract addresses and ABIs
  • Gas Limits: Set appropriate gas limits to prevent failed transactions
  • Emergency Procedures: Have emergency withdrawal procedures ready
  • Regular Audits: Regularly audit your setup and configurations

Reporting Security Issues

If you discover a security vulnerability, please email us at security@yourproject.com instead of creating a public issue.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

🌟 Star History

If you find this project helpful, please consider giving it a star! ⭐


Built with ❀️ for the DeFi community

About

A comprehensive yield farming client for Ethereum blockchain, implemented in both Rust and Go. This project provides robust, production-ready tools for interacting with DeFi yield farming protocols.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •