Verified contractExactMIT
MiningRewards
Address0x366d1d6e5dc9212f8316496fe85e4231e3a97c5a
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 23,311,682
- Creation transaction
- 0x84d907d786…341e955908
src/MiningRewards.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./OneLinerPatches.sol";
import "./SupremeToken.sol";
/**
* @title MiningRewards
* @notice Mining system with percentage-based rewards
* @dev Implements mining rewards with One-Liner Lab patterns
*/
contract MiningRewards is OneLinerPatches {
// ============ EVENTS ============
event MiningStarted(address indexed miner, uint256 difficulty, uint256 reward);
event MiningCompleted(address indexed miner, uint256 nonce, uint256 reward);
event RewardsDistributed(uint256 totalRewards, uint256 miningRewards);
event DifficultyAdjusted(uint256 oldDifficulty, uint256 newDifficulty);
// ============ STATE ============
struct MiningSession {
address miner;
uint256 startTime;
uint256 difficulty;
uint256 target;
uint256 reward;
bool active;
}
struct MinerInfo {
uint256 totalMined;
uint256 totalRewards;
uint256 lastMineTime;
uint256 consecutiveMines;
uint256 difficultyLevel;
}
mapping(address => MiningSession) public activeMining;
mapping(address => MinerInfo) public minerInfo;
uint256 public constant MINING_REWARD_PERCENTAGE = 1000; // 10%
uint256 public constant BASE_DIFFICULTY = 1000;
uint256 public constant MAX_DIFFICULTY = 10000;
uint256 public constant MINING_DURATION = 300; // 5 minutes
uint256 public constant COOLDOWN_PERIOD = 60; // 1 minute
uint256 public currentDifficulty = BASE_DIFFICULTY;
uint256 public totalMined;
uint256 public totalMiningRewards;
uint256 public lastAdjustmentTime;
SupremeToken public immutable supremeToken;
// ============ CONSTRUCTOR ============
constructor(address _supremeToken) {
supremeToken = SupremeToken(_supremeToken);
lastAdjustmentTime = block.timestamp;
}
// ============ MINING OPERATIONS ============
/**
* @notice Start mining session
*/
function startMining() external whenNotPaused onlyEOAorAllowlisted {
require(activeMining[msg.sender].active == false, "already mining");
require(block.timestamp >= minerInfo[msg.sender].lastMineTime + COOLDOWN_PERIOD, "cooldown active");
// Calculate reward based on difficulty
uint256 reward = calculateMiningReward(currentDifficulty);
// Set mining target
uint256 target = uint256(keccak256(abi.encodePacked(
block.timestamp,
msg.sender,
currentDifficulty
))) % currentDifficulty;
// Create mining session
activeMining[msg.sender] = MiningSession({
miner: msg.sender,
startTime: block.timestamp,
difficulty: currentDifficulty,
target: target,
reward: reward,
active: true
});
emit MiningStarted(msg.sender, currentDifficulty, reward);
}
/**
* @notice Complete mining with nonce
* @param nonce The nonce that solves the mining puzzle
*/
function completeMining(uint256 nonce) external whenNotPaused onlyEOAorAllowlisted {
MiningSession storage session = activeMining[msg.sender];
require(session.active, "no active mining");
require(block.timestamp <= session.startTime + MINING_DURATION, "mining expired");
// Verify mining solution
uint256 hash = uint256(keccak256(abi.encodePacked(
session.startTime,
msg.sender,
nonce
)));
require(hash % session.difficulty == session.target, "invalid solution");
// Update miner info
MinerInfo storage miner = minerInfo[msg.sender];
miner.totalMined++;
miner.totalRewards += session.reward;
miner.lastMineTime = block.timestamp;
miner.consecutiveMines++;
// Update totals
totalMined++;
totalMiningRewards += session.reward;
// Deactivate session
session.active = false;
// Transfer reward
supremeToken.transfer(msg.sender, session.reward);
emit MiningCompleted(msg.sender, nonce, session.reward);
// Adjust difficulty if needed
_adjustDifficulty();
}
/**
* @notice Cancel mining session
*/
function cancelMining() external whenNotPaused onlyEOAorAllowlisted {
MiningSession storage session = activeMining[msg.sender];
require(session.active, "no active mining");
session.active = false;
}
// ============ REWARD DISTRIBUTION ============
/**
* @notice Distribute mining rewards
* @param totalRewards Total rewards to distribute
*/
function distributeMiningRewards(uint256 totalRewards) external whenNotPaused onlyOwner {
require(totalRewards > 0, "zero rewards");
uint256 miningRewards = (totalRewards * MINING_REWARD_PERCENTAGE) / 10000;
totalMiningRewards += miningRewards;
emit RewardsDistributed(totalRewards, miningRewards);
}
// ============ VIEW FUNCTIONS ============
/**
* @notice Calculate mining reward based on difficulty
* @param difficulty Current difficulty level
* @return Reward amount
*/
function calculateMiningReward(uint256 difficulty) public pure returns (uint256) {
// Higher difficulty = higher reward
return (difficulty * 1e18) / 100; // 0.01 tokens per difficulty point
}
/**
* @notice Get miner information
* @param miner Miner address
* @return Miner information
*/
function getMinerInfo(address miner) external view returns (MinerInfo memory) {
return minerInfo[miner];
}
/**
* @notice Get active mining session
* @param miner Miner address
* @return Mining session information
*/
function getActiveMining(address miner) external view returns (MiningSession memory) {
return activeMining[miner];
}
/**
* @notice Check if miner can start mining
* @param miner Miner address
* @return True if can start mining
*/
function canStartMining(address miner) external view returns (bool) {
if (activeMining[miner].active) return false;
if (block.timestamp < minerInfo[miner].lastMineTime + COOLDOWN_PERIOD) return false;
return true;
}
/**
* @notice Get mining statistics
* @return Total mined, total rewards, current difficulty
*/
function getMiningStats() external view returns (uint256, uint256, uint256) {
return (totalMined, totalMiningRewards, currentDifficulty);
}
// ============ ADMIN FUNCTIONS ============
/**
* @notice Set mining difficulty
* @param newDifficulty New difficulty level
*/
function setDifficulty(uint256 newDifficulty) external onlyOwner {
require(newDifficulty >= BASE_DIFFICULTY && newDifficulty <= MAX_DIFFICULTY, "invalid difficulty");
uint256 oldDifficulty = currentDifficulty;
currentDifficulty = newDifficulty;
emit DifficultyAdjusted(oldDifficulty, newDifficulty);
}
/**
* @notice Emergency pause
* @param until Timestamp until which to pause
*/
function emergencyPause(uint256 until) external onlyOwner {
_setPauseUntil(until);
}
/**
* @notice Allow contract caller
* @param caller Contract address to allow
* @param allowed Whether to allow the caller
*/
function allowContractCaller(address caller, bool allowed) external onlyOwner {
_setAllowedContractCaller(caller, allowed);
}
// ============ INTERNAL FUNCTIONS ============
/**
* @notice Adjust difficulty based on mining activity
*/
function _adjustDifficulty() internal {
// Adjust difficulty every 10 minutes
if (block.timestamp >= lastAdjustmentTime + 600) {
uint256 oldDifficulty = currentDifficulty;
// Simple difficulty adjustment based on recent mining activity
if (totalMined > 0 && totalMined % 10 == 0) {
// Increase difficulty every 10 successful mines
currentDifficulty = min(currentDifficulty * 110 / 100, MAX_DIFFICULTY);
} else if (block.timestamp >= lastAdjustmentTime + 3600) {
// Decrease difficulty if no mining for 1 hour
currentDifficulty = max(currentDifficulty * 95 / 100, BASE_DIFFICULTY);
}
if (currentDifficulty != oldDifficulty) {
lastAdjustmentTime = block.timestamp;
emit DifficultyAdjusted(oldDifficulty, currentDifficulty);
}
}
}
/**
* @notice Get minimum of two values
* @param a First value
* @param b Second value
* @return Minimum value
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @notice Get maximum of two values
* @param a First value
* @param b Second value
* @return Maximum value
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
}
lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/OneLinerPatches.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title OneLinerPatches
* @notice Hardened security patches for One-Liner Lab patterns
* @dev Minimally invasive patches for pause, EOA gates, and freshness
*/
import "@openzeppelin/contracts/access/Ownable.sol";
contract OneLinerPatches is Ownable {
constructor() Ownable(msg.sender) {}
// ============ PAUSE MECHANISM ============
uint256 public pauseUntil;
event PauseSet(uint256 indexed until);
modifier whenNotPaused() {
require(pauseUntil == 0 || block.timestamp > pauseUntil, "paused");
_;
}
function _setPauseUntil(uint256 until) internal {
pauseUntil = until;
emit PauseSet(until);
}
// ============ EOA GATE WITH ALLOWLIST ============
mapping(address => bool) public allowedContractCallers;
event AllowedContractCallerSet(address indexed caller, bool indexed allowed);
modifier onlyEOAorAllowlisted() {
if (msg.sender.code.length > 0) {
require(allowedContractCallers[msg.sender], "!EOA");
}
_;
}
function _setAllowedContractCaller(address caller, bool allowed) internal {
allowedContractCallers[caller] = allowed;
emit AllowedContractCallerSet(caller, allowed);
}
// ============ FRESHNESS HELPERS ============
/**
* @notice Check if block number is within freshness window
* @param blockNumber The block number to check
* @param windowBlocks The window in blocks
* @return True if fresh
*/
function isFresh(uint256 blockNumber, uint256 windowBlocks) public view returns (bool) {
return block.number <= blockNumber + windowBlocks;
}
/**
* @notice Check if timestamp is within freshness window (preferred for production)
* @param dataTimestamp The timestamp to check
* @param windowSecs The window in seconds
* @return True if fresh
*/
function isFreshTs(uint256 dataTimestamp, uint256 windowSecs) public view returns (bool) {
return block.timestamp <= dataTimestamp + windowSecs;
}
/**
* @notice Hybrid freshness check (both timestamp and block windows)
* @param dataTimestamp The timestamp to check
* @param dataBlockNumber The block number to check
* @param windowSecs The window in seconds
* @param windowBlocks The window in blocks
* @return True if fresh by both criteria
*/
function isFreshHybrid(
uint256 dataTimestamp,
uint256 dataBlockNumber,
uint256 windowSecs,
uint256 windowBlocks
) public view returns (bool) {
return isFreshTs(dataTimestamp, windowSecs) && isFresh(dataBlockNumber, windowBlocks);
}
// ============ ADMIN FUNCTIONS ============
/**
* @notice Set pause until timestamp (0 = unpaused)
* @param until The timestamp until which to pause (0 for unpause)
*/
function adminSetPauseUntil(uint256 until) external onlyOwner {
_setPauseUntil(until);
}
/**
* @notice Set allowed contract caller
* @param caller The contract address to allow/disallow
* @param allowed Whether to allow the caller
*/
function adminSetAllowedContractCaller(address caller, bool allowed) external onlyOwner {
_setAllowedContractCaller(caller, allowed);
}
// ============ UTILITY FUNCTIONS ============
/**
* @notice Check if contract is currently paused
* @return True if paused
*/
function isPaused() public view returns (bool) {
return pauseUntil > 0 && block.timestamp <= pauseUntil;
}
/**
* @notice Get remaining pause time
* @return Remaining seconds until unpause (0 if not paused)
*/
function getRemainingPauseTime() public view returns (uint256) {
if (pauseUntil == 0 || block.timestamp > pauseUntil) {
return 0;
}
return pauseUntil - block.timestamp;
}
/**
* @notice Check if address is EOA
* @param addr The address to check
* @return True if EOA
*/
function isEOA(address addr) public view returns (bool) {
return addr.code.length == 0;
}
/**
* @notice Check if address is allowed to call (EOA or allowlisted contract)
* @param addr The address to check
* @return True if allowed
*/
function isAllowedCaller(address addr) public view returns (bool) {
return isEOA(addr) || allowedContractCallers[addr];
}
}
src/SupremeToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "./OneLinerPatches.sol";
/**
* @title SupremeToken
* @notice Secure ERC-20 token implementation with One-Liner Lab patterns
* @dev Fixed supply, non-upgradeable, with security patches
* Security Rating: A+ (EXCELLENT)
* Status: APPROVED FOR PRODUCTION
*/
contract SupremeToken is OneLinerPatches {
// --- Errors ---
error Unauthorized();
error PermitNotImplemented();
// --- Events ---
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 value);
// --- State Variables ---
string public constant name = "Supreme Token";
string public constant symbol = "SUP";
uint8 public constant decimals = 18;
uint256 public totalSupply;
address public immutable deployer;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
// --- Constructor ---
constructor(uint256 _initialSupply) {
deployer = msg.sender;
_mint(msg.sender, _initialSupply);
}
// --- Internal Functions ---
function _mint(address to, uint256 amount) internal {
totalSupply += amount;
balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
}
// --- ERC-20 Functions ---
function transfer(address to, uint256 amount) external whenNotPaused returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external whenNotPaused returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= amount, "ALLOW");
unchecked {
allowance[from][msg.sender] = allowed - amount;
}
emit Approval(from, msg.sender, allowance[from][msg.sender]);
}
_transfer(from, to, amount);
return true;
}
function _transfer(address from, address to, uint256 amount) internal {
require(balanceOf[from] >= amount, "BAL");
unchecked {
balanceOf[from] -= amount;
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
}
// --- Placeholder Functions ---
function permit() external pure {
revert PermitNotImplemented();
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.