-
Notifications
You must be signed in to change notification settings - Fork 5
/
Beneficiary.sol
74 lines (61 loc) · 2.02 KB
/
Beneficiary.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
68
69
70
71
72
73
74
// contracts/token/modules/Beneficiary.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import "./interfaces/IBeneficiary.sol";
/// @dev Note that this implementation is agnostic to whether or not a token
/// has actually been minted. Resultantly, it allows setting the beneficiary of yet-to-be
/// minuted tokens by directly calling `_setBeneficiary`.
abstract contract Beneficiary is IBeneficiary {
//////////////////////////////
/// State
//////////////////////////////
/// @notice Map of tokens to their beneficiaries.
mapping(uint256 => address) internal _beneficiaries;
//////////////////////////////
/// Errors
//////////////////////////////
error BeneficiaryOnly();
//////////////////////////////
/// Events
//////////////////////////////
/// @notice Alert of new beneficiary
/// @param tokenId ID of token.
/// @param newBeneficiary Address of new beneficiary.
event LogBeneficiaryUpdated(
uint256 indexed tokenId,
address indexed newBeneficiary
);
//////////////////////////////
/// Public Methods
//////////////////////////////
/// @dev See {IBeneficiary.setBeneficiary}
function setBeneficiary(uint256 tokenId_, address payable beneficiary_)
public
override
{
if (msg.sender != _beneficiaries[tokenId_]) revert BeneficiaryOnly();
_setBeneficiary(tokenId_, beneficiary_);
}
/// @dev See {IBeneficiary.beneficiaryOf}
function beneficiaryOf(uint256 tokenId_)
public
view
override
returns (address)
{
return _beneficiaries[tokenId_];
}
//////////////////////////////
/// Internal Methods
//////////////////////////////
/// @notice Internal beneficiary setter.
/// @dev Should be invoked immediately after calling `#_safeMint`
/// @param tokenId_ Token to set beneficiary of.
/// @param beneficiary_ Address of beneficiary.
function _setBeneficiary(uint256 tokenId_, address payable beneficiary_)
internal
{
_beneficiaries[tokenId_] = beneficiary_;
emit LogBeneficiaryUpdated(tokenId_, beneficiary_);
}
}