-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BT-129 - IRS ERC3643 implementation #233
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// 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.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() external view override onlyAgent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the whole idea of this contract is to provide a decentralized way of managing the links between OIDs and wallet addresses, therefore i think we should allow users to add and remove wallets linked to their OID, but to make sure they are really owning these wallets, they should provide a signature done by this wallet to make the transaction happen. the transaction should be called either by a wallet that is a management key on the OID or by the OID itself (through approve/execute) |
||
revert ContractIsReadOnly(); | ||
} | ||
|
||
/** | ||
* @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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as the addIdentity stuff, but in this case no need of a signature. A wallet can be removed by another wallet that is a management key on the OID or by the OID itself, note that you cannot remove the initial wallet linked to the OID on the IDFactory as that one is registered there forever |
||
revert ContractIsReadOnly(); | ||
} | ||
|
||
/** | ||
* @dev See {IIdentityRegistryStorage-bindIdentityRegistry}. | ||
*/ | ||
function bindIdentityRegistry() external view override { | ||
revert ContractIsReadOnly(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just do nothing, don't revert, otherwise the factory won't be able to use this contract, as the factory will try to bind |
||
} | ||
|
||
/** | ||
* @dev See {IIdentityRegistryStorage-unbindIdentityRegistry}. | ||
*/ | ||
function unbindIdentityRegistry() 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fetch from IdFactory only the first time, and store locally, it costs less gas to call internal memory |
||
} | ||
|
||
/** | ||
* @dev See {IIdentityRegistryStorage-storedInvestorCountry}. | ||
*/ | ||
function storedInvestorCountry(address _userAddress) external view override returns (uint16) { | ||
return _identities[_userAddress].investorCountry; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just return 42 or something, by default, in case the |
||
} | ||
|
||
/** | ||
* @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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call this contract another way, we already have an identity registry storage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call it GlobalIRS or something