From 26414b11e3ec40089022ba7519d66002c80c721b Mon Sep 17 00:00:00 2001 From: Mihalis Date: Fri, 6 Dec 2024 12:42:04 +0200 Subject: [PATCH 1/3] BT-129 - IRS ERC3643 implementation --- .../IdentityRegistryStorageERC3643.sol | 177 ++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 contracts/registry/implementation/IdentityRegistryStorageERC3643.sol diff --git a/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol b/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol new file mode 100644 index 00000000..98e7a64f --- /dev/null +++ b/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol @@ -0,0 +1,177 @@ +// 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 . + */ + +pragma solidity 0.8.27; + +import "../../errors/InvalidArgumentErrors.sol"; + +import "../../roles/AgentRoleUpgradeable.sol"; +import "../../roles/IERC173.sol"; +import "../interface/IIdentityRegistryStorage.sol"; +import "../storage/IRSStorage.sol"; +import "@onchain-id/solidity/contracts/factory/IIdFactory.sol"; +import "@onchain-id/solidity/contracts/interface/IIdentity.sol"; +import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; + +/// Errors + +/// @dev Thrown when address is already stored +error AddressAlreadyStored(); + +/// @dev Thrown when address is not yet stored. +error AddressNotYetStored(); + +/// @dev Thrown when trying to call write functions. +error ContractIsReadOnly(); + +/// @dev Thrown when maximum numbe of identity registry by identity registry storage is reached. +/// @param _max miximum number of IR by IRS. +error MaxIRByIRSReached(uint256 _max); + + +contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUpgradeable, IRSStorage, IERC165 { + IIdFactory internal iidFactory; + function init(_identityFactoryAddress) external initializer { + require(_identityFactoryAddress != address(0), ZeroAddress()); + iidFactory = IIdFactory(_identityFactoryAddress); + __Ownable_init(); + } + + /** + * @dev See {IIdentityRegistryStorage-addIdentityToStorage}. + */ + function addIdentityToStorage( + address _userAddress, + IIdentity _identity, + uint16 _country + ) external view override onlyAgent { + revert ContractIsReadOnly(); + } + + /** + * @dev See {IIdentityRegistryStorage-modifyStoredIdentity}. + */ + function modifyStoredIdentity(address _userAddress, IIdentity _identity) external view override onlyAgent { + revert ContractIsReadOnly(); + + } + + /** + * @dev See {IIdentityRegistryStorage-modifyStoredInvestorCountry}. + */ + function modifyStoredInvestorCountry(address _userAddress, uint16 _country) external view override onlyAgent { + revert ContractIsReadOnly(); + + } + + /** + * @dev See {IIdentityRegistryStorage-removeIdentityFromStorage}. + */ + function removeIdentityFromStorage(address _userAddress) external view override onlyAgent { + revert ContractIsReadOnly(); + } + + /** + * @dev See {IIdentityRegistryStorage-bindIdentityRegistry}. + */ + function bindIdentityRegistry(address _identityRegistry) external view override { + revert ContractIsReadOnly(); + } + + /** + * @dev See {IIdentityRegistryStorage-unbindIdentityRegistry}. + */ + function unbindIdentityRegistry(address _identityRegistry) external view override { + revert ContractIsReadOnly(); + } + + /** + * @dev See {IIdentityRegistryStorage-linkedIdentityRegistries}. + */ + function linkedIdentityRegistries() external view override returns (address[] memory) { + return _identityRegistries; + } + + /** + * @dev See {IIdentityRegistryStorage-storedIdentity}. + */ + function storedIdentity(address _userAddress) external view override returns (IIdentity) { + return IIdentity(iidFactory.getIdentity(_userAddress)); + } + + /** + * @dev See {IIdentityRegistryStorage-storedInvestorCountry}. + */ + function storedInvestorCountry(address _userAddress) external view override returns (uint16) { + return _identities[_userAddress].investorCountry; + } + + /** + * @dev See {IERC165-supportsInterface}. + */ + function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) { + return + interfaceId == type(IERC3643IdentityRegistryStorage).interfaceId || + interfaceId == type(IERC173).interfaceId || + interfaceId == type(IERC165).interfaceId; + } +} From e2758cc6ea34c289528ee26f8b300940f33ff0a8 Mon Sep 17 00:00:00 2001 From: Mihalis Date: Fri, 6 Dec 2024 13:04:08 +0200 Subject: [PATCH 2/3] BT-129 - IRS ERC3643 implementation --- .../IdentityRegistryStorageERC3643.sol | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol b/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol index 98e7a64f..3ee835b8 100644 --- a/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol +++ b/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol @@ -89,28 +89,24 @@ error MaxIRByIRSReached(uint256 _max); contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUpgradeable, IRSStorage, IERC165 { - IIdFactory internal iidFactory; + IIdFactory internal _iidFactory; function init(_identityFactoryAddress) external initializer { require(_identityFactoryAddress != address(0), ZeroAddress()); - iidFactory = IIdFactory(_identityFactoryAddress); + _iidFactory = IIdFactory(_identityFactoryAddress); __Ownable_init(); } /** * @dev See {IIdentityRegistryStorage-addIdentityToStorage}. */ - function addIdentityToStorage( - address _userAddress, - IIdentity _identity, - uint16 _country - ) external view override onlyAgent { + function addIdentityToStorage() external view override onlyAgent { revert ContractIsReadOnly(); } /** * @dev See {IIdentityRegistryStorage-modifyStoredIdentity}. */ - function modifyStoredIdentity(address _userAddress, IIdentity _identity) external view override onlyAgent { + function modifyStoredIdentity() external view override onlyAgent { revert ContractIsReadOnly(); } @@ -118,7 +114,7 @@ contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUp /** * @dev See {IIdentityRegistryStorage-modifyStoredInvestorCountry}. */ - function modifyStoredInvestorCountry(address _userAddress, uint16 _country) external view override onlyAgent { + function modifyStoredInvestorCountry() external view override onlyAgent { revert ContractIsReadOnly(); } @@ -126,21 +122,21 @@ contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUp /** * @dev See {IIdentityRegistryStorage-removeIdentityFromStorage}. */ - function removeIdentityFromStorage(address _userAddress) external view override onlyAgent { + function removeIdentityFromStorage() external view override onlyAgent { revert ContractIsReadOnly(); } /** * @dev See {IIdentityRegistryStorage-bindIdentityRegistry}. */ - function bindIdentityRegistry(address _identityRegistry) external view override { + function bindIdentityRegistry() external view override { revert ContractIsReadOnly(); } /** * @dev See {IIdentityRegistryStorage-unbindIdentityRegistry}. */ - function unbindIdentityRegistry(address _identityRegistry) external view override { + function unbindIdentityRegistry() external view override { revert ContractIsReadOnly(); } @@ -155,7 +151,7 @@ contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUp * @dev See {IIdentityRegistryStorage-storedIdentity}. */ function storedIdentity(address _userAddress) external view override returns (IIdentity) { - return IIdentity(iidFactory.getIdentity(_userAddress)); + return IIdentity(_iidFactory.getIdentity(_userAddress)); } /** From f4d816810b8bb41ee6a0ecede7b11a1521191a8e Mon Sep 17 00:00:00 2001 From: Mihalis Date: Thu, 12 Dec 2024 12:39:30 +0200 Subject: [PATCH 3/3] BT-129 - IRS ERC3643 implementation --- ... GlobalIdentityRegistryStorageERC3643.sol} | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) rename contracts/registry/implementation/{IdentityRegistryStorageERC3643.sol => GlobalIdentityRegistryStorageERC3643.sol} (85%) diff --git a/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol b/contracts/registry/implementation/GlobalIdentityRegistryStorageERC3643.sol similarity index 85% rename from contracts/registry/implementation/IdentityRegistryStorageERC3643.sol rename to contracts/registry/implementation/GlobalIdentityRegistryStorageERC3643.sol index 3ee835b8..9e84ba08 100644 --- a/contracts/registry/implementation/IdentityRegistryStorageERC3643.sol +++ b/contracts/registry/implementation/GlobalIdentityRegistryStorageERC3643.sol @@ -88,7 +88,7 @@ error ContractIsReadOnly(); error MaxIRByIRSReached(uint256 _max); -contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUpgradeable, IRSStorage, IERC165 { +contract GlobalIdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUpgradeable, IRSStorage, IERC165 { IIdFactory internal _iidFactory; function init(_identityFactoryAddress) external initializer { require(_identityFactoryAddress != address(0), ZeroAddress()); @@ -99,45 +99,49 @@ contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUp /** * @dev See {IIdentityRegistryStorage-addIdentityToStorage}. */ - function addIdentityToStorage() external view override onlyAgent { - revert ContractIsReadOnly(); + function addIdentityToStorage( + address _userAddress, + IIdentity _identity, + uint16 _country + ) external view override onlyAgent { + bytes32 hash = keccak256( + abi.encode( + "Authorize ONCHAINID wallet addition", + _identity, + _userAddress + ) + ); } /** * @dev See {IIdentityRegistryStorage-modifyStoredIdentity}. */ function modifyStoredIdentity() external view override onlyAgent { - revert ContractIsReadOnly(); - } /** * @dev See {IIdentityRegistryStorage-modifyStoredInvestorCountry}. */ function modifyStoredInvestorCountry() external view override onlyAgent { - revert ContractIsReadOnly(); - } /** * @dev See {IIdentityRegistryStorage-removeIdentityFromStorage}. */ - function removeIdentityFromStorage() external view override onlyAgent { - revert ContractIsReadOnly(); + function removeIdentityFromStorage(address _userAddress) external view override onlyAgent { + // verify message sender } /** * @dev See {IIdentityRegistryStorage-bindIdentityRegistry}. */ function bindIdentityRegistry() external view override { - revert ContractIsReadOnly(); } /** * @dev See {IIdentityRegistryStorage-unbindIdentityRegistry}. */ function unbindIdentityRegistry() external view override { - revert ContractIsReadOnly(); } /** @@ -151,14 +155,25 @@ contract IdentityRegistryStorage is IERC3643IdentityRegistryStorage, AgentRoleUp * @dev See {IIdentityRegistryStorage-storedIdentity}. */ function storedIdentity(address _userAddress) external view override returns (IIdentity) { - return IIdentity(_iidFactory.getIdentity(_userAddress)); + if (_identities[_userAddress] != address(0)) { + return _identities[_userAddress].identityContract; + } + address identity = _iidFactory.getIdentity(_userAddress); + if (identity != address(0)) { + _identities[_userAddress].identityContract = IIdentity(identity); + return _identities[_userAddress].identityContract; + } + return address(0); } /** * @dev See {IIdentityRegistryStorage-storedInvestorCountry}. */ function storedInvestorCountry(address _userAddress) external view override returns (uint16) { - return _identities[_userAddress].investorCountry; + if(_identities[_userAddress].investorCountry != 0) { + return _identities[_userAddress].investorCountry; + } + return 42; } /**