-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEligibility.sol
77 lines (66 loc) · 2.42 KB
/
Eligibility.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
75
76
77
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "../../interfaces/IEligibility.sol";
struct Result {
uint8 tier; // The KYC tier.
string validator; // The KYC validator.
string transactionId; // The KYC transaction id.
}
/**
* @title Eligibility.
* @author Mathieu Bour, Julien Schneider, Charly Mancel, Valentin Pollart and Clarisse Tarrou for the DeepSquare Association.
* @dev Basic implementation of a KYC storage.
*/
contract Eligibility is AccessControl, IEligibility {
event Validation(address indexed account, Result result);
/**
* @notice Map KYC tiers with their limits in USD. Zero means no-limit.
*/
mapping(uint8 => uint256) public limits;
/**
* @notice Map accounts to a KYC tier.
*/
mapping(address => Result) public results;
/**
* @notice The WRITER role which defines which account is allowed to write the KYC information.
*/
bytes32 public constant WRITER = keccak256("WRITER");
/**
* @dev Grant the OWNER and WRITER roles to the contract deployer.
*/
constructor() {
// Define the roles
_setRoleAdmin(WRITER, DEFAULT_ADMIN_ROLE);
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(WRITER, msg.sender);
// Set the default KYC limits.
setLimit(1, 15000);
setLimit(2, 100000);
}
/**
* @notice Get the tier and limit for an account.
* @param account The account address to lookup.
*/
function lookup(address account) external view returns (uint8, uint256) {
return (results[account].tier, limits[results[account].tier]);
}
/**
* @notice Set the limit of a given KYC tier. Zero means there is no limit. Restricted to the OWNER role.
* @param tier The KYC tier.
* @param newLimit The KYC tier limit.
*/
function setLimit(uint8 tier, uint256 newLimit) public onlyRole(DEFAULT_ADMIN_ROLE) {
limits[tier] = newLimit;
}
/**
* @notice Set the latest KYC result of an account. Restricted to the WRITER role.
* @param account The validated account address.
* @param result The account KYC result.
*/
function setResult(address account, Result memory result) external onlyRole(WRITER) {
results[account] = result;
emit Validation(account, result);
}
}