Skip to Content

@cfxdevkit/compiler


@cfxdevkit/compiler / MULTISIG_SOURCE

Variable: MULTISIG_SOURCE

const MULTISIG_SOURCE: ”// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\n/**\n * @title MultiSigWallet\n * @notice M-of-N multisig wallet. Teaches: dynamic arrays, structs, the\n * low-level call pattern, and collaborative governance primitives.\n */\ncontract MultiSigWallet {\n struct Transaction {\n address to;\n uint256 value;\n bytes data;\n bool executed;\n uint256 confirmCount;\n }\n\n address[] public owners;\n uint256 public required;\n mapping(address => bool) public isOwner;\n Transaction[] public transactions;\n mapping(uint256 => mapping(address => bool)) public confirmed;\n\n event Deposit(address indexed sender, uint256 amount);\n event TransactionSubmitted(uint256 indexed txId, address indexed to, uint256 value);\n event TransactionConfirmed(uint256 indexed txId, address indexed owner);\n event ConfirmationRevoked(uint256 indexed txId, address indexed owner);\n event TransactionExecuted(uint256 indexed txId);\n\n modifier onlyOwner() {\n require(isOwner[msg.sender], “MultiSig: not an owner”);\n _;\n }\n\n modifier txExists(uint256 txId) {\n require(txId < transactions.length, “MultiSig: tx does not exist”);\n _;\n }\n\n modifier notExecuted(uint256 txId) {\n require(!transactions[txId].executed, “MultiSig: already executed”);\n _;\n }\n\n modifier notConfirmed(uint256 txId) {\n require(!confirmed[txId][msg.sender], “MultiSig: already confirmed”);\n _;\n }\n\n /// @param _owners List of owner addresses (no duplicates, no zero address)\n /// @param _required Number of confirmations needed to execute a transaction\n constructor(address[] memory _owners, uint256 _required) {\n require(_owners.length > 0, “MultiSig: need at least one owner”);\n require(_required > 0 && _required <= _owners.length, “MultiSig: invalid required count”);\n\n for (uint256 i = 0; i < _owners.length; i++) {\n address o = _owners[i];\n require(o != address(0), “MultiSig: zero address owner”);\n require(!isOwner[o], “MultiSig: duplicate owner”);\n isOwner[o] = true;\n owners.push(o);\n }\n required = _required;\n }\n\n receive() external payable {\n emit Deposit(msg.sender, msg.value);\n }\n\n /// @notice Submit a new transaction for confirmation.\n function submitTransaction(address to, uint256 value, bytes calldata data)\n external onlyOwner returns (uint256 txId)\n {\n txId = transactions.length;\n transactions.push(Transaction({ to: to, value: value, data: data, executed: false, confirmCount: 0 }));\n emit TransactionSubmitted(txId, to, value);\n }\n\n /// @notice Confirm a pending transaction.\n function confirmTransaction(uint256 txId)\n external onlyOwner txExists(txId) notExecuted(txId) notConfirmed(txId)\n {\n confirmed[txId][msg.sender] = true;\n transactions[txId].confirmCount++;\n emit TransactionConfirmed(txId, msg.sender);\n }\n\n /// @notice Revoke your confirmation for a pending transaction.\n function revokeConfirmation(uint256 txId)\n external onlyOwner txExists(txId) notExecuted(txId)\n {\n require(confirmed[txId][msg.sender], “MultiSig: not confirmed”);\n confirmed[txId][msg.sender] = false;\n transactions[txId].confirmCount—;\n emit ConfirmationRevoked(txId, msg.sender);\n }\n\n /// @notice Execute a transaction once it has enough confirmations.\n function executeTransaction(uint256 txId)\n external onlyOwner txExists(txId) notExecuted(txId)\n {\n Transaction storage txn = transactions[txId];\n require(txn.confirmCount >= required, “MultiSig: not enough confirmations”);\n txn.executed = true;\n (bool success, ) = txn.to.call{value: txn.value}(txn.data);\n require(success, “MultiSig: execution failed”);\n emit TransactionExecuted(txId);\n }\n\n /// @notice Contract’s current CFX balance.\n function balance() external view returns (uint256) {\n return address(this).balance;\n }\n\n /// @notice Total number of submitted transactions.\n function transactionCount() external view returns (uint256) {\n return transactions.length;\n }\n\n /// @notice List all owner addresses.\n function getOwners() external view returns (address[] memory) {\n return owners;\n }\n}”

Defined in: templates/multisig.ts:13