Created
May 28, 2024 13:27
-
-
Save franko4don/6f96c1665d95b92f10f0be36e801afc2 to your computer and use it in GitHub Desktop.
Test Verification contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.0; | |
| contract MultiSigWallet { | |
| address[] public approvers; | |
| uint public quorum; | |
| // Transfer struct | |
| // Called by one of the approver addressese to suggest a transfer of tokens | |
| struct Transfer { | |
| uint id; | |
| uint amount; | |
| address payable to; | |
| uint approvals; | |
| bool sent; | |
| } | |
| // mapping transfer to go along with each transaction | |
| Transfer[] public transfers; | |
| // Transfer approval mapping | |
| mapping(address => mapping(uint => bool)) public approvals; | |
| // Instantiate at start - list of approvers | |
| // Amount that will be needed for quorum | |
| constructor(address[] memory _approvers, uint _quorum) { | |
| approvers = _approvers; | |
| quorum = _quorum; | |
| } | |
| // return the list of addressess that can approve trandactions | |
| function getApprovers() external view returns(address[] memory) { | |
| return approvers; | |
| } | |
| // return list of transfers | |
| function getTransfers() external view returns(Transfer[] memory) { | |
| return transfers; | |
| } | |
| // generate trandfer when called by apporving address | |
| function createTransfer(uint amount, address payable to) external onlyApprover(){ | |
| transfers.push(Transfer( | |
| transfers.length, | |
| amount, | |
| to, | |
| 0, | |
| false | |
| )); | |
| } | |
| // Approve each transfer | |
| function approveTransfer(uint id) external onlyApprover() { | |
| // require checks for any double spend or call | |
| require(transfers[id].sent == false, 'Transfer has already been sent'); | |
| require(approvals[msg.sender][id] == false, 'cannot approve transfer twice'); | |
| approvals[msg.sender][id] = true; // change id = true | |
| transfers[id].approvals++; // increment number of approvals | |
| // if the transfer approval is equal or more than needed | |
| if(transfers[id].approvals >= quorum) { | |
| transfers[id].sent = true; // mark that transfer is sent | |
| address payable to = transfers[id].to; // send payment to address given | |
| uint amount = transfers[id].amount; // send amount provided | |
| to.transfer(amount); // transfer - 'tranfer' is a Solidity function | |
| } | |
| } | |
| // Allow contract to receive funds | |
| // Solidity key word function | |
| receive() external payable {} | |
| // Access Control Modifier to attach to create and approve transfer functions | |
| modifier onlyApprover() { | |
| bool allowed = false; | |
| for(uint i = 0; i < approvers.length; i++) { | |
| if(approvers[i] == msg.sender) { | |
| allowed = true; | |
| } | |
| } | |
| require(allowed == true, 'only approver allowed'); | |
| _; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment