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.
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
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.
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
- 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
- Rust 1.70+ (Install Rust)
- Ethereum node access (Infura, Alchemy, or local node)
-
Clone the repository:
git clone https://github.com/yourusername/blockchain-yield-farming.git cd blockchain-yield-farming
-
Install dependencies:
cargo build
-
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
-
Run the application:
cargo run
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(())
}
- 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
- Go 1.21+ (Install Go)
- Ethereum node access (Infura, Alchemy, or local node)
-
Clone the repository:
git clone https://github.com/yourusername/blockchain-yield-farming.git cd blockchain-yield-farming
-
Install dependencies:
go mod tidy
-
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"
-
Run the application:
go run sample-example-go-ethereum.go
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)
}
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
- Mainnet: Production Ethereum network
- Goerli: Ethereum testnet (recommended for testing)
- Sepolia: Ethereum testnet
- Local: Local development network
- 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
- Pool Statistics: TVL, APY, reward rates
- User Position: Staked balance, pending rewards
- Transaction History: Complete transaction tracking
- Performance Metrics: ROI calculations and analytics
- 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
# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_client_initialization
# Run all tests
go test ./...
# Run tests with verbose output
go test -v ./...
# Run tests with race detection
go test -race ./...
- Security: Never commit private keys or sensitive data
- Monitoring: Implement comprehensive logging and monitoring
- Backup: Regular backup of configuration and state
- Updates: Keep dependencies updated for security patches
- Testing: Thorough testing on testnets before mainnet
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"]
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- 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
If you discover a security vulnerability, please email us at security@yourproject.com
instead of creating a public issue.
This project is licensed under the MIT License - see the LICENSE file for details.
- web3-rs - Rust Ethereum library
- go-ethereum - Go Ethereum implementation
- OpenZeppelin - Smart contract security
- DeFi Pulse - DeFi analytics and insights
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Project Wiki
If you find this project helpful, please consider giving it a star! β
Built with β€οΈ for the DeFi community