└── multisig /multisig: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | contract MultiSigWallet { 5 | address[] public owners; 6 | uint public requiredSignatures; 7 | mapping(address => bool) public isOwner; 8 | mapping(uint => Transaction) public transactions; 9 | uint public transactionCount; 10 | 11 | struct Transaction { 12 | address to; 13 | uint256 amount; 14 | uint256 signatureCount; 15 | mapping(address => bool) signedBy; 16 | bool executed; 17 | } 18 | 19 | modifier onlyOwner() { 20 | require(isOwner[msg.sender], "Not an owner"); 21 | _; 22 | } 23 | 24 | modifier notExecuted(uint transactionId) { 25 | require(!transactions[transactionId].executed, "Transaction already executed"); 26 | _; 27 | } 28 | 29 | constructor(address[] memory _owners, uint _requiredSignatures) { 30 | require(_owners.length > 1, "At least two owners required"); 31 | owners = _owners; 32 | requiredSignatures = _requiredSignatures; 33 | for (uint i = 0; i < _owners.length; i++) { 34 | isOwner[_owners[i]] = true; 35 | } 36 | } 37 | 38 | function createTransaction(address to, uint256 amount) public onlyOwner { 39 | transactionCount++; 40 | Transaction storage t = transactions[transactionCount]; 41 | t.to = to; 42 | t.amount = amount; 43 | t.signatureCount = 0; 44 | t.executed = false; 45 | } 46 | 47 | function signTransaction(uint transactionId) public onlyOwner notExecuted(transactionId) { 48 | Transaction storage t = transactions[transactionId]; 49 | require(!t.signedBy[msg.sender], "Already signed"); 50 | t.signedBy[msg.sender] = true; 51 | t.signatureCount++; 52 | if (t.signatureCount >= requiredSignatures) { 53 | t.executed = true; 54 | payable(t.to).transfer(t.amount); 55 | } 56 | } 57 | 58 | receive() external payable {} 59 | } 60 | --------------------------------------------------------------------------------