Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/src/demo/SimpleDistributionTableV2.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title SimpleDistributionTable
* @notice Table-based reward distribution for demo (no oracles, no calculators)
* @dev Owner manually sets shares for each miner
*/
contract SimpleDistributionTable is Ownable {
// ======== STATE ========
struct MinerShares {
address minerAddress;
uint256 shares;
string minerId; // Optional identifier
bool isActive;
}
// Miner address => shares
mapping(address => MinerShares) public miners;
address[] public minerList;
uint256 public totalShares;
// ======== EVENTS ========
event MinerAdded(address indexed miner, uint256 shares, string minerId);
event MinerUpdated(address indexed miner, uint256 oldShares, uint256 newShares);
event MinerRemoved(address indexed miner);
event SharesRecalculated(uint256 totalShares);
// ======== CONSTRUCTOR ========
constructor() Ownable(msg.sender) {}
// ======== MANAGEMENT ========
function addMiner(
address minerAddress,
uint256 shares,
string calldata minerId
) external onlyOwner {
require(minerAddress != address(0), "Invalid address");
require(shares > 0, "Shares must be > 0");
require(!miners[minerAddress].isActive, "Miner already exists");
miners[minerAddress] = MinerShares({
minerAddress: minerAddress,
shares: shares,
minerId: minerId,
isActive: true
});
minerList.push(minerAddress);
totalShares += shares;
emit MinerAdded(minerAddress, shares, minerId);
}
function updateMinerShares(address minerAddress, uint256 newShares) external onlyOwner {
require(miners[minerAddress].isActive, "Miner not found");
require(newShares > 0, "Shares must be > 0");
uint256 oldShares = miners[minerAddress].shares;
totalShares = totalShares - oldShares + newShares;
miners[minerAddress].shares = newShares;
emit MinerUpdated(minerAddress, oldShares, newShares);
}
function removeMiner(address minerAddress) external onlyOwner {
require(miners[minerAddress].isActive, "Miner not found");
totalShares -= miners[minerAddress].shares;
miners[minerAddress].isActive = false;
// Remove from list
for (uint256 i = 0; i < minerList.length; i++) {
if (minerList[i] == minerAddress) {
minerList[i] = minerList[minerList.length - 1];
minerList.pop();
break;
}
}
emit MinerRemoved(minerAddress);
}
// ======== DISTRIBUTION CALCULATION ========
function calculateDistribution(uint256 totalAmount)
external
view
returns (address[] memory recipients, uint256[] memory amounts)
{
require(totalShares > 0, "No shares");
uint256 activeCount = 0;
for (uint256 i = 0; i < minerList.length; i++) {
if (miners[minerList[i]].isActive) {
activeCount++;
}
}
recipients = new address[](activeCount);
amounts = new uint256[](activeCount);
uint256 index = 0;
uint256 distributed = 0;
for (uint256 i = 0; i < minerList.length; i++) {
address miner = minerList[i];
if (miners[miner].isActive) {
uint256 amount = (totalAmount * miners[miner].shares) / totalShares;
recipients[index] = miner;
amounts[index] = amount;
distributed += amount;
index++;
}
}
// Handle remainder - give to first recipient
if (distributed < totalAmount && activeCount > 0) {
amounts[0] += (totalAmount - distributed);
}
}
// ======== VIEWS ========
function getMinerCount() external view returns (uint256) {
uint256 count = 0;
for (uint256 i = 0; i < minerList.length; i++) {
if (miners[minerList[i]].isActive) {
count++;
}
}
return count;
}
function getAllMiners() external view returns (address[] memory) {
uint256 activeCount = 0;
for (uint256 i = 0; i < minerList.length; i++) {
if (miners[minerList[i]].isActive) {
activeCount++;
}
}
address[] memory activeMiners = new address[](activeCount);
uint256 index = 0;
for (uint256 i = 0; i < minerList.length; i++) {
if (miners[minerList[i]].isActive) {
activeMiners[index] = minerList[i];
index++;
}
}
return activeMiners;
}
function getMinerShares(address minerAddress) external view returns (uint256) {
return miners[minerAddress].shares;
}
function isMinerActive(address minerAddress) external view returns (bool) {
return miners[minerAddress].isActive;
}
}
"
},
"lib/openzeppelin-contracts/contracts/access/Ownable.sol": {
"content": "// 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": {
"content": "// 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;
}
}
"
}
},
"settings": {
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
],
"optimizer": {
"enabled": true,
"runs": 1
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "prague",
"viaIR": true
}
}}
Submitted on: 2025-10-26 13:05:22
Comments
Log in to comment.
No comments yet.