Skip to content

Instantly share code, notes, and snippets.

@pythonpete32
Created November 30, 2022 06:41
Show Gist options
  • Save pythonpete32/479403ce36cca374053eab57527bdfa9 to your computer and use it in GitHub Desktop.
Save pythonpete32/479403ce36cca374053eab57527bdfa9 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.10+commit.fc410830.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {Plugin} from "https://github.com/aragon/core/blob/develop/packages/contracts/contracts/core/plugin/Plugin.sol";
import {IDAO} from "https://github.com/aragon/core/blob/develop/packages/contracts/contracts/core/IDAO.sol";
contract MultisigPlugin is Plugin {
/* ====================================================================== */
/* Permissions */
/* ====================================================================== */
bytes32 public constant SIGNER_PERMISSION_ID = keccak256("SIGNER_PERMISSION");
/* ====================================================================== */
/* Events */
/* ====================================================================== */
event NewTransfer(address indexed creator, uint256 transferId);
event SignedTransfer(address indexed signer, uint256 transferId);
event ExecutedTransfer(uint256 transferId);
event UpdateThreshold(uint8 oldThreshold, uint8 newThreshold);
/* ====================================================================== */
/* State */
/* ====================================================================== */
struct Transfer {
address to;
uint256 value;
uint8 signersRemaining;
bool executed;
}
uint8 public threshold;
uint256 transferId;
mapping(uint256 => Transfer) public transfers;
constructor(uint8 _threshold, address _dao) Plugin(IDAO(_dao)) {
assert(_threshold > 0);
transferId = 0;
threshold = _threshold;
}
/* ====================================================================== */
/* Functions */
/* ====================================================================== */
function newTransfer(address _to, uint256 _value) external auth(SIGNER_PERMISSION_ID) {
transfers[transferId] = Transfer({
to: _to,
value: _value,
signersRemaining: threshold - 1,
executed: false
});
emit NewTransfer(_msgSender(), transferId);
transferId++;
if (threshold == 1) _executeTransfer(transferId);
}
function signTransfer(uint256 _transferId) external auth(SIGNER_PERMISSION_ID) {
assert(_transferId < transferId);
assert(!transfers[_transferId].executed);
transfers[_transferId].signersRemaining--;
emit SignedTransfer(_msgSender(), _transferId);
if (transfers[_transferId].signersRemaining == 0) _executeTransfer(transferId);
}
function _executeTransfer(uint256 _transferId) internal {
transfers[_transferId].executed = true;
dao.withdraw(
address(0),
transfers[_transferId].to,
transfers[_transferId].value,
"MultiSig Plugin"
);
emit ExecutedTransfer(_transferId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment