-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathKYCToken.sol
More file actions
140 lines (120 loc) · 4.29 KB
/
Copy pathKYCToken.sol
File metadata and controls
140 lines (120 loc) · 4.29 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {Errors} from "./libraries/Errors.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {IKYCToken, IERC721} from "./interfaces/IKYCToken.sol";
import {Roles} from "./libraries/Roles.sol";
contract KYCToken is ERC721, IKYCToken {
using Address for address;
using Counters for Counters.Counter;
IAccessControl public immutable accessController;
Counters.Counter private _tokenIdCounter;
string private _uri;
// Mapping token ID to KYCData
mapping(uint256 => KYCData) private _kycData;
modifier onlyRole(bytes32 role) {
if (!accessController.hasRole(role, msg.sender)) {
revert Errors.ACCESS_CONTROL_ACCOUNT_IS_MISSING_ROLE(msg.sender, role);
}
_;
}
/**
* @param _accessController MCAGAccessController.
*/
constructor(IAccessControl _accessController) ERC721("MCAG KYC Token", "MKYCT") {
if (address(_accessController) == address(0)) {
revert Errors.CANNOT_SET_TO_ADDRESS_ZERO();
}
accessController = _accessController;
emit AccessControllerSet(address(_accessController));
}
/**
* @notice Mints a KYC NFT to the specified address.
* @dev Can only be called by MCAG_MINT_ROLE
* @param to KYC NFT receiver.
* @param kycData KYCData struct storing metadata.
*/
function mint(address to, KYCData calldata kycData) external override onlyRole(Roles.MCAG_MINT_ROLE) {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_kycData[tokenId] = kycData;
_safeMint(to, tokenId);
emit Mint(to, kycData);
}
/**
* @notice Mints a KYC NFT to the specified address.
* @dev Can only be called by MCAG_BURN_ROLE
* @param tokenId Token Id to burn.
*/
function burn(uint256 tokenId) external override onlyRole(Roles.MCAG_BURN_ROLE) {
if (_ownerOf(tokenId) == address(0)) {
revert Errors.ERC721_INVALID_TOKEN_ID();
}
KYCData memory kycData = _kycData[tokenId];
delete _kycData[tokenId];
_burn(tokenId);
emit Burn(tokenId, kycData);
}
/**
* @notice Sets a new base uri.
* @dev Can only be called by `MCAG_SET_URI_ROLE`.
* @param newUri New base uri.
*/
function setUri(string memory newUri) external override onlyRole(Roles.MCAG_SET_URI_ROLE) {
emit UriSet(_uri, newUri);
_uri = newUri;
}
/**
* @return Current token id counter.
*/
function getTokenIdCounter() external view override returns (uint256) {
return _tokenIdCounter.current();
}
/**
* @param tokenId KYC token id.
* @return KYCData struct storing metadata of the selected token id.
*/
function getKycData(uint256 tokenId) external view override returns (KYCData memory) {
if (_ownerOf(tokenId) == address(0)) {
revert Errors.ERC721_INVALID_TOKEN_ID();
}
return _kycData[tokenId];
}
/**
* @dev Token is non transferable.
*/
function approve(address to, uint256 tokenId) public pure override(ERC721, IERC721) {
revert Errors.TOKEN_IS_NOT_TRANSFERABLE();
}
/**
* @dev Token is non transferable.
*/
function setApprovalForAll(address operator, bool approved) public pure override(ERC721, IERC721) {
revert Errors.TOKEN_IS_NOT_TRANSFERABLE();
}
/**
* @dev Token is non transferable.
*/
function transferFrom(address from, address to, uint256 tokenId) public pure override(ERC721, IERC721) {
revert Errors.TOKEN_IS_NOT_TRANSFERABLE();
}
/**
* @dev Token is non transferable.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
public
pure
override(ERC721, IERC721)
{
revert Errors.TOKEN_IS_NOT_TRANSFERABLE();
}
/**
* @dev See {IERC721-_baseUri}.
*/
function _baseURI() internal view override returns (string memory) {
return _uri;
}
}