mirror of
https://github.com/luxfi/erc-3643.git
synced 2026-10-30 16:58:28 +00:00
OpenZeppelin v5 dropped parameterless __Ownable_init() and Ownable() in favor of explicit owner argument. Required for solc 0.8.31 + OZ v5 build (see partner/contracts foundry.toml). 10 files: ModularCompliance, AbstractModuleUpgradeable, TREXFactory, TREXImplementationAuthority, ClaimTopicsRegistry, IdentityRegistry, IdentityRegistryStorage, TrustedIssuersRegistry, AgentRole, Token.
282 lines
12 KiB
Solidity
282 lines
12 KiB
Solidity
// SPDX-License-Identifier: GPL-3.0
|
|
//
|
|
// :+#####%%%%%%%%%%%%%%+
|
|
// .-*@@@%+.:+%@@@@@%%#***%@@%=
|
|
// :=*%@@@#=. :#@@% *@@@%=
|
|
// .-+*%@%*-.:+%@@@@@@+. -*+: .=#. :%@@@%-
|
|
// :=*@@@@%%@@@@@@@@@%@@@- .=#@@@%@%= =@@@@#.
|
|
// -=+#%@@%#*=:. :%@@@@%. -*@@#*@@@@@@@#=:- *@@@@+
|
|
// =@@%=:. :=: *@@@@@%#- =%*%@@@@#+-. =+ :%@@@%-
|
|
// -@@%. .+@@@ =+=-. @@#- +@@@%- =@@@@%:
|
|
// :@@@. .+@@#%: : .=*=-::.-%@@@+*@@= +@@@@#.
|
|
// %@@: +@%%* =%@@@@@@@@@@@#. .*@%- +@@@@*.
|
|
// #@@= .+@@@@%:=*@@@@@- :%@%: .*@@@@+
|
|
// *@@* +@@@#-@@%-:%@@* +@@#. :%@@@@-
|
|
// -@@% .:-=++*##%%%@@@@@@@@@@@@*. :@+.@@@%: .#@@+ =@@@@#:
|
|
// .@@@*-+*#%%%@@@@@@@@@@@@@@@@%%#**@@%@@@. *@=*@@# :#@%= .#@@@@#-
|
|
// -%@@@@@@@@@@@@@@@*+==-:-@@@= *@# .#@*-=*@@@@%= -%@@@* =@@@@@%-
|
|
// -+%@@@#. %@%%= -@@:+@: -@@* *@@*-:: -%@@%=. .*@@@@@#
|
|
// *@@@* +@* *@@##@@- #@*@@+ -@@= . :+@@@#: .-+@@@%+-
|
|
// +@@@%*@@:..=@@@@* .@@@* .#@#. .=+- .=%@@@*. :+#@@@@*=:
|
|
// =@@@@%@@@@@@@@@@@@@@@@@@@@@@%- :+#*. :*@@@%=. .=#@@@@%+:
|
|
// .%@@= ..... .=#@@+. .#@@@*: -*%@@@@%+.
|
|
// +@@#+===---:::... .=%@@*- +@@@+. -*@@@@@%+.
|
|
// -@@@@@@@@@@@@@@@@@@@@@@%@@@@= -@@@+ -#@@@@@#=.
|
|
// ..:::---===+++***###%%%@@@#- .#@@+ -*@@@@@#=.
|
|
// @@@@@@+. +@@*. .+@@@@@%=.
|
|
// -@@@@@= =@@%: -#@@@@%+.
|
|
// +@@@@@. =@@@= .+@@@@@*:
|
|
// #@@@@#:%@@#. :*@@@@#-
|
|
// @@@@@%@@@= :#@@@@+.
|
|
// :@@@@@@@#.:#@@@%-
|
|
// +@@@@@@-.*@@@*:
|
|
// #@@@@#.=@@@+.
|
|
// @@@@+-%@%=
|
|
// :@@@#%@%=
|
|
// +@@@@%-
|
|
// :#%%=
|
|
//
|
|
/**
|
|
* NOTICE
|
|
*
|
|
* The T-REX software is licensed under a proprietary license or the GPL v.3.
|
|
* If you choose to receive it under the GPL v.3 license, the following applies:
|
|
* T-REX is a suite of smart contracts implementing the ERC-3643 standard and
|
|
* developed by Tokeny to manage and transfer financial assets on EVM blockchains
|
|
*
|
|
* Copyright (C) 2023, Tokeny sàrl.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
pragma solidity ^0.8.17;
|
|
|
|
import "@onchain-id/solidity/contracts/interface/IClaimIssuer.sol";
|
|
import "@onchain-id/solidity/contracts/interface/IIdentity.sol";
|
|
|
|
import "../interface/IClaimTopicsRegistry.sol";
|
|
import "../interface/ITrustedIssuersRegistry.sol";
|
|
import "../interface/IIdentityRegistry.sol";
|
|
import "../../roles/AgentRoleUpgradeable.sol";
|
|
import "../interface/IIdentityRegistryStorage.sol";
|
|
import "../storage/IRStorage.sol";
|
|
|
|
|
|
contract IdentityRegistry is IIdentityRegistry, AgentRoleUpgradeable, IRStorage {
|
|
|
|
/**
|
|
* @dev the constructor initiates the Identity Registry smart contract
|
|
* @param _trustedIssuersRegistry the trusted issuers registry linked to the Identity Registry
|
|
* @param _claimTopicsRegistry the claim topics registry linked to the Identity Registry
|
|
* @param _identityStorage the identity registry storage linked to the Identity Registry
|
|
* emits a `ClaimTopicsRegistrySet` event
|
|
* emits a `TrustedIssuersRegistrySet` event
|
|
* emits an `IdentityStorageSet` event
|
|
*/
|
|
function init(
|
|
address _trustedIssuersRegistry,
|
|
address _claimTopicsRegistry,
|
|
address _identityStorage
|
|
) external initializer {
|
|
require(
|
|
_trustedIssuersRegistry != address(0)
|
|
&& _claimTopicsRegistry != address(0)
|
|
&& _identityStorage != address(0)
|
|
, "invalid argument - zero address");
|
|
_tokenTopicsRegistry = IClaimTopicsRegistry(_claimTopicsRegistry);
|
|
_tokenIssuersRegistry = ITrustedIssuersRegistry(_trustedIssuersRegistry);
|
|
_tokenIdentityStorage = IIdentityRegistryStorage(_identityStorage);
|
|
emit ClaimTopicsRegistrySet(_claimTopicsRegistry);
|
|
emit TrustedIssuersRegistrySet(_trustedIssuersRegistry);
|
|
emit IdentityStorageSet(_identityStorage);
|
|
__Ownable_init(msg.sender);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-batchRegisterIdentity}.
|
|
*/
|
|
function batchRegisterIdentity(
|
|
address[] calldata _userAddresses,
|
|
IIdentity[] calldata _identities,
|
|
uint16[] calldata _countries
|
|
) external override {
|
|
for (uint256 i = 0; i < _userAddresses.length; i++) {
|
|
registerIdentity(_userAddresses[i], _identities[i], _countries[i]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-updateIdentity}.
|
|
*/
|
|
function updateIdentity(address _userAddress, IIdentity _identity) external override onlyAgent {
|
|
IIdentity oldIdentity = identity(_userAddress);
|
|
_tokenIdentityStorage.modifyStoredIdentity(_userAddress, _identity);
|
|
emit IdentityUpdated(oldIdentity, _identity);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-updateCountry}.
|
|
*/
|
|
function updateCountry(address _userAddress, uint16 _country) external override onlyAgent {
|
|
_tokenIdentityStorage.modifyStoredInvestorCountry(_userAddress, _country);
|
|
emit CountryUpdated(_userAddress, _country);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-deleteIdentity}.
|
|
*/
|
|
function deleteIdentity(address _userAddress) external override onlyAgent {
|
|
IIdentity oldIdentity = identity(_userAddress);
|
|
_tokenIdentityStorage.removeIdentityFromStorage(_userAddress);
|
|
emit IdentityRemoved(_userAddress, oldIdentity);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-setIdentityRegistryStorage}.
|
|
*/
|
|
function setIdentityRegistryStorage(address _identityRegistryStorage) external override onlyOwner {
|
|
_tokenIdentityStorage = IIdentityRegistryStorage(_identityRegistryStorage);
|
|
emit IdentityStorageSet(_identityRegistryStorage);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-setClaimTopicsRegistry}.
|
|
*/
|
|
function setClaimTopicsRegistry(address _claimTopicsRegistry) external override onlyOwner {
|
|
_tokenTopicsRegistry = IClaimTopicsRegistry(_claimTopicsRegistry);
|
|
emit ClaimTopicsRegistrySet(_claimTopicsRegistry);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-setTrustedIssuersRegistry}.
|
|
*/
|
|
function setTrustedIssuersRegistry(address _trustedIssuersRegistry) external override onlyOwner {
|
|
_tokenIssuersRegistry = ITrustedIssuersRegistry(_trustedIssuersRegistry);
|
|
emit TrustedIssuersRegistrySet(_trustedIssuersRegistry);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-isVerified}.
|
|
*/
|
|
// solhint-disable-next-line code-complexity
|
|
function isVerified(address _userAddress) external view override returns (bool) {
|
|
if (address(identity(_userAddress)) == address(0)) {return false;}
|
|
uint256[] memory requiredClaimTopics = _tokenTopicsRegistry.getClaimTopics();
|
|
if (requiredClaimTopics.length == 0) {
|
|
return true;
|
|
}
|
|
|
|
uint256 foundClaimTopic;
|
|
uint256 scheme;
|
|
address issuer;
|
|
bytes memory sig;
|
|
bytes memory data;
|
|
uint256 claimTopic;
|
|
for (claimTopic = 0; claimTopic < requiredClaimTopics.length; claimTopic++) {
|
|
IClaimIssuer[] memory trustedIssuers =
|
|
_tokenIssuersRegistry.getTrustedIssuersForClaimTopic(requiredClaimTopics[claimTopic]);
|
|
|
|
if (trustedIssuers.length == 0) {return false;}
|
|
|
|
bytes32[] memory claimIds = new bytes32[](trustedIssuers.length);
|
|
for (uint256 i = 0; i < trustedIssuers.length; i++) {
|
|
claimIds[i] = keccak256(abi.encode(trustedIssuers[i], requiredClaimTopics[claimTopic]));
|
|
}
|
|
|
|
for (uint256 j = 0; j < claimIds.length; j++) {
|
|
(foundClaimTopic, scheme, issuer, sig, data, ) = identity(_userAddress).getClaim(claimIds[j]);
|
|
|
|
if (foundClaimTopic == requiredClaimTopics[claimTopic]) {
|
|
try IClaimIssuer(issuer).isClaimValid(identity(_userAddress), requiredClaimTopics[claimTopic], sig,
|
|
data) returns(bool _validity) {
|
|
|
|
if (
|
|
_validity
|
|
) {
|
|
j = claimIds.length;
|
|
}
|
|
if (!_validity && j == (claimIds.length - 1)) {
|
|
return false;
|
|
}
|
|
} catch {
|
|
if (j == (claimIds.length - 1)) {
|
|
return false;
|
|
}
|
|
}
|
|
} else if (j == (claimIds.length - 1)) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-investorCountry}.
|
|
*/
|
|
function investorCountry(address _userAddress) external view override returns (uint16) {
|
|
return _tokenIdentityStorage.storedInvestorCountry(_userAddress);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-issuersRegistry}.
|
|
*/
|
|
function issuersRegistry() external view override returns (ITrustedIssuersRegistry) {
|
|
return _tokenIssuersRegistry;
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-topicsRegistry}.
|
|
*/
|
|
function topicsRegistry() external view override returns (IClaimTopicsRegistry) {
|
|
return _tokenTopicsRegistry;
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-identityStorage}.
|
|
*/
|
|
function identityStorage() external view override returns (IIdentityRegistryStorage) {
|
|
return _tokenIdentityStorage;
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-contains}.
|
|
*/
|
|
function contains(address _userAddress) external view override returns (bool) {
|
|
if (address(identity(_userAddress)) == address(0)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-registerIdentity}.
|
|
*/
|
|
function registerIdentity(
|
|
address _userAddress,
|
|
IIdentity _identity,
|
|
uint16 _country
|
|
) public override onlyAgent {
|
|
_tokenIdentityStorage.addIdentityToStorage(_userAddress, _identity, _country);
|
|
emit IdentityRegistered(_userAddress, _identity);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IIdentityRegistry-identity}.
|
|
*/
|
|
function identity(address _userAddress) public view override returns (IIdentity) {
|
|
return _tokenIdentityStorage.storedIdentity(_userAddress);
|
|
}
|
|
}
|