Files

179 lines
7.6 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 "../../roles/AgentRole.sol";
import "./ICompliance.sol";
import "../../token/IToken.sol";
abstract contract BasicCompliance is AgentRole, ICompliance {
/// Mapping between agents and their statuses
mapping(address => bool) private _tokenAgentsList;
/// Mapping of tokens linked to the compliance contract
IToken public tokenBound;
/**
* @dev Throws if called by any address that is not a token bound to the compliance.
*/
modifier onlyToken() {
require(_isToken(), "error : this address is not a token bound to the compliance contract");
_;
}
/**
* @dev Throws if called by any address that is not owner of compliance or agent of the token.
*/
modifier onlyAdmin() {
require(owner() == msg.sender || (AgentRole(address(tokenBound))).isAgent(msg.sender) ,
"can be called only by Admin address");
_;
}
/**
* @dev See {ICompliance-addTokenAgent}.
* this function is deprecated, but still implemented to avoid breaking interfaces
*/
function addTokenAgent(address _agentAddress) external override onlyOwner {
require(!_tokenAgentsList[_agentAddress], "This Agent is already registered");
_tokenAgentsList[_agentAddress] = true;
emit TokenAgentAdded(_agentAddress);
}
/**
* @dev See {ICompliance-isTokenAgent}.
*/
function removeTokenAgent(address _agentAddress) external override onlyOwner {
require(_tokenAgentsList[_agentAddress], "This Agent is not registered yet");
_tokenAgentsList[_agentAddress] = false;
emit TokenAgentRemoved(_agentAddress);
}
/**
* @dev See {ICompliance-bindToken}.
*/
function bindToken(address _token) external override {
require(owner() == msg.sender || (address(tokenBound) == address(0) && msg.sender == _token),
"only owner or token can call");
tokenBound = IToken(_token);
emit TokenBound(_token);
}
/**
* @dev See {ICompliance-unbindToken}.
*/
function unbindToken(address _token) external override {
require(owner() == msg.sender || msg.sender == _token , "only owner or token can call");
require(_token == address(tokenBound), "This token is not bound");
delete tokenBound;
emit TokenUnbound(_token);
}
/**
* @dev See {ICompliance-isTokenAgent}.
*/
function isTokenAgent(address _agentAddress) public override view returns (bool) {
if (!_tokenAgentsList[_agentAddress] && !(AgentRole(address(tokenBound))).isAgent(_agentAddress)) {
return false;
}
return true;
}
/**
* @dev See {ICompliance-isTokenBound}.
*/
function isTokenBound(address _token) public override view returns (bool) {
if (_token != address(tokenBound)){
return false;
}
return true;
}
/**
* @dev Returns true if the sender corresponds to a token that is bound with the Compliance contract
*/
function _isToken() internal view returns (bool) {
return isTokenBound(msg.sender);
}
/**
* @dev Returns the ONCHAINID (Identity) of the _userAddress
* @param _userAddress Address of the wallet
* internal function, can be called only from the functions of the Compliance smart contract
*/
function _getIdentity(address _userAddress) internal view returns (address) {
return address(tokenBound.identityRegistry().identity(_userAddress));
}
/**
* @dev Returns the country of residence of the _userAddress
* @param _userAddress Address of the wallet
* internal function, can be called only from the functions of the Compliance smart contract
*/
function _getCountry(address _userAddress) internal view returns (uint16) {
return tokenBound.identityRegistry().investorCountry(_userAddress);
}
}