-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharedWallet.sol
67 lines (54 loc) · 2.15 KB
/
SharedWallet.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
import "./Beneficiary.sol";
/**
* @author Eval (0xeval)
* @title A simple shared wallet contract
*/
contract SharedWallet is Beneficiary {
event DepositReceived(address _from, uint _amount);
event Withdrawal(address _to, uint _amount);
constructor() payable {
addBeneficiary(msg.sender, type(uint256).max);
}
receive() external payable {
emit DepositReceived(msg.sender, msg.value);
}
/**
* @dev Overrides OpenZeppelin's Ownable default function to prevent
* owner-less contract.
*/
function renounceOwnership() public view override onlyOwner {
revert("Cannot renounce ownership");
}
/**
* @dev Overrides OpenZeppelin's ownership transfer function to update
* Wallet's beneficiaries. Transfering ownership removes entirely the previous owner of the beneficiaries.
*/
function transferOwnership(address _newOwner) public override onlyOwner {
super.transferOwnership(_newOwner);
removeBeneficiary(owner());
addBeneficiary(_newOwner, type(uint256).max);
}
/**
* Withdraw a given amount of money from the Wallet.
* The max withdrawal amount is determined by the pre-defined allowance variable
* associated to the address.
*
* @param _amount the withdrawal amount
*/
function withdraw(uint _amount) public onlyOwnerOrBeneficiary {
require(beneficiaries[msg.sender].allowance >= _amount, "Withdrawal amount above allowance.");
emit Withdrawal(msg.sender, _amount);
beneficiaries[msg.sender].allowance -= _amount;
payable(msg.sender).transfer(_amount);
}
/**
* Withdraw the total balance stored in the wallet.
* Must be called by _owner_.
*/
function withdrawAll() public onlyOwner {
emit Withdrawal(msg.sender, address(this).balance);
withdraw(address(this).balance);
}
}