A comprehensive smart contract system designed to reward users with SOLO tokens based on their gas usage, creating an incentive mechanism for network participation. The system supports both standard and upgradeable contract implementations.
Contracts-Tx-Mining/
βββ src/ # Source contracts
β βββ core/ # Standard (non-upgradeable) contracts
β β βββ GasMining.sol # Main gas mining contract
β β βββ interfaces/
β β β βββ IGasMining.sol # Interface for GasMining contract
β β βββ mock/
β β βββ SOLOToken.sol # Mock SOLO token for testing
β βββ upgradeable/ # Upgradeable contract implementations
β βββ GasMining.sol # Upgradeable gas mining contract
β βββ interfaces/
β β βββ IGasMining.sol # Interface for upgradeable GasMining
β βββ mock/
β βββ SOLOToken.sol # Upgradeable mock SOLO token
βββ test/ # Test files
β βββ core/ # Tests for standard contracts
β β βββ GasMining.t.sol # Unit tests for GasMining
β β βββ GasMiningFuzz.t.sol # Fuzz tests for GasMining
β βββ upgradeable/ # Tests for upgradeable contracts
β βββ GasMining.t.sol # Unit tests for upgradeable GasMining
β βββ GasMiningFuzz.t.sol # Fuzz tests for upgradeable GasMining
βββ script/ # Deployment and interaction scripts
β βββ core/ # Scripts for standard contracts
β βββ upgradeable/ # Scripts for upgradeable contracts
βββ lib/ # External dependencies
β βββ forge-std/ # Foundry standard library
β βββ openzeppelin-contracts/ # OpenZeppelin contracts
β βββ openzeppelin-contracts-upgradeable/ # OpenZeppelin upgradeable contracts
βββ out/ # Compiled contracts
βββ broadcast/ # Deployment artifacts
βββ cache/ # Foundry cache
βββ foundry.toml # Foundry configuration
The main contract that implements the gas mining reward system. It inherits from Ownable and implements the IGasMining interface.
Key Features:
- Block-Based Rewards: Users receive rewards based on their gas consumption in specific blocks
- Epoch System: Rewards are organized in epochs for better tracking and distribution
- Dual Claiming Options:
- Instant claiming with 50% burn penalty
- Staking rewards to avoid burn penalty
- Configurable Parameters: Adjustable block rewards, epoch duration, and burn percentage
- Admin Controls: Owner-only functions for system management
Inheritance Chain:
GasMining β Ownable β Context
Interface defining the complete API for the GasMining contract, including:
- View functions for querying user data and system state
- State-changing functions for claiming and staking rewards
- Admin functions for system configuration
- Events for tracking important contract activities
An upgradeable version of the GasMining contract that inherits from:
Initializable- For proxy initializationOwnableUpgradeable- For upgradeable ownershipUUPSUpgradeable- For Universal Upgradeable Proxy Standard
Key Differences from Core Version:
- Uses
initialize()function instead of constructor - Includes storage gap for future upgrades
- Implements
_authorizeUpgrade()for upgrade authorization - Uses OpenZeppelin's upgradeable contracts
- Block-Based Tracking: Rewards are calculated and distributed based on specific block numbers
- Epoch Management: System operates in epochs for organized reward distribution
- Flexible Claiming: Users can choose between instant claiming (with burn) or staking (no burn)
- Owner-Only Admin Functions: Critical system parameters can only be modified by the owner
- Safe Math Operations: All arithmetic operations use SafeMath to prevent overflows
- Claim Verification: Multiple checks ensure proper reward distribution
- Burn Mechanism: Configurable burn percentage (default 50%) for instant claims
- UUPS Proxy Pattern: Uses Universal Upgradeable Proxy Standard for upgrades
- Storage Gaps: Reserved storage slots for future contract upgrades
- Authorization: Only owner can authorize contract upgrades
- Foundry
- Ethereum RPC URL
- Private key for deployment
- Etherscan API Key (for verification)
# Clone the repository
git clone <your-repo-url>
cd Contracts-Tx-Mining
# Install dependencies
forge install# Build all contracts
forge build# Run all tests
forge test
# Run tests with detailed output
forge test -vv
# Run specific test suite
forge test --match-path "test/core/*"
forge test --match-path "test/upgradeable/*"
# Run fuzz tests with more iterations
forge test --fuzz-runs 1000
# Generate gas report
forge test --gas-reporttoken: Address of the SOLO token contract (ERC20)blockReward: Amount of tokens distributed per blockepochDuration: Number of blocks in one epochlatestClaimableBlock: Latest block number for which rewards can be claimedburnBasisPoints: Percentage of rewards burned on instant claim (default: 5000 = 50%)
struct UserClaim {
uint256 lastClaimedBlock; // Last block user claimed rewards
uint256 totalClaimAmount; // Total amount ever claimed
uint256 pendingClaimAmount; // Current pending rewards
uint256[] claimedBlocks; // Array of blocks with claims
mapping(uint256 => uint256) blockClaimAmounts; // Amount per block
}uint256[] memory blocks = [100, 101, 102];
uint256[] memory amounts = [10e18, 20e18, 30e18];
uint256[] memory emptyArray = new uint256[](0);
gasMining.updateUserClaim(
userAddress,
blocks,
amounts,
emptyArray, // preboostAmounts
emptyArray, // comparativeAmounts
0, // multiplierWeight
0, // stSOLOAmount
"" // stSOLOTier
);gasMining.instantClaimRewards();address stakingContract = 0x...;
gasMining.stakeClaim(stakingContract);// Get pending claim amount
uint256 pending = gasMining.getPendingClaimAmount(userAddress);
// Get total claim amount
uint256 total = gasMining.getTotalClaimAmount(userAddress);
// Get detailed unclaimed information
IGasMining.UnclaimedDetails memory details = gasMining.getUnclaimedDetails(userAddress);# Start local node
anvil
# Deploy core contracts
forge script script/core/Deploy.s.sol:DeployScript \
--rpc-url http://localhost:8545 \
--private-key $PRIVATE_KEY \
--broadcast
# Deploy upgradeable contracts
forge script script/upgradeable/DeployScriptGasMining.s.sol:DeployScriptGasMining \
--rpc-url http://localhost:8545 \
--private-key $PRIVATE_KEY \
--broadcast# Deploy with verification
forge script script/core/Deploy.s.sol:DeployScript \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY# Core contract verification
forge verify-contract \
--chain-id <chain_id> \
--compiler-version <compiler_version> \
--constructor-args $(cast abi-encode "constructor(address,uint256,uint256,uint256)" <token_address> <block_reward> <epoch_duration> <latest_claimable_block>) \
<deployed_address> \
src/core/GasMining.sol:GasMining \
$ETHERSCAN_API_KEY
# Upgradeable contract verification
forge verify-contract \
--chain-id <chain_id> \
--compiler-version <compiler_version> \
<deployed_address> \
src/upgradeable/GasMining.sol:GasMining \
$ETHERSCAN_API_KEY# Create gas snapshots
forge snapshot# Generate test coverage report
forge coverage# Run Slither security analysis
slither .The contracts include several security features:
- Access Control: Owner-only administrative functions
- Safe Math: All arithmetic operations are protected against overflows
- Input Validation: Comprehensive checks on all user inputs
- Claim Verification: Multiple safety checks ensure proper reward distribution
- Upgrade Authorization: Only owner can authorize contract upgrades (upgradeable version)
The contract emits the following events for tracking:
InstantRewardClaimed: When a user claims rewards instantlyRewardStaked: When a user stakes rewards instead of claimingUserClaimUpdated: When admin updates user claim dataBlockRewardUpdated: When block reward is changedEpochDurationUpdated: When epoch duration is changedLatestClaimableBlockUpdated: When claimable block is updatedAdminWithdraw: When admin withdraws tokensBurnBasisPointsUpdated: When burn percentage is changed
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This system is designed for educational and development purposes. Please conduct thorough testing and security audits before deploying to mainnet.