mirror of
https://github.com/luxfi/erc-3643.git
synced 2026-11-02 13:38:46 +00:00
198 lines
9.9 KiB
Solidity
198 lines
9.9 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 "../BasicCompliance.sol";
|
|
|
|
/**
|
|
* this feature allows to setup a blacklist of countries, investors with a blacklisted
|
|
* country of residence won't be allowed to receive tokens on their wallets
|
|
*/
|
|
abstract contract CountryRestrictions is BasicCompliance {
|
|
|
|
/// Mapping between country and their restriction status
|
|
mapping(uint16 => bool) private _restrictedCountries;
|
|
|
|
/**
|
|
* this event is emitted whenever a Country has been restricted.
|
|
* the event is emitted by 'addCountryRestriction' and 'batchRestrictCountries' functions.
|
|
* `_country` is the numeric ISO 3166-1 of the restricted country.
|
|
*/
|
|
event AddedRestrictedCountry(uint16 _country);
|
|
|
|
/**
|
|
* this event is emitted whenever a Country has been unrestricted.
|
|
* the event is emitted by 'removeCountryRestriction' and 'batchUnrestrictCountries' functions.
|
|
* `_country` is the numeric ISO 3166-1 of the unrestricted country.
|
|
*/
|
|
event RemovedRestrictedCountry(uint16 _country);
|
|
|
|
/**
|
|
* @dev Adds countries restriction in batch.
|
|
* Identities from those countries will be forbidden to manipulate Tokens linked to this Compliance.
|
|
* @param _countries Countries to be restricted, should be expressed by following numeric ISO 3166-1 standard
|
|
* Only the owner of the Compliance smart contract can call this function
|
|
* emits _countries.length `AddedRestrictedCountry` events
|
|
*/
|
|
function batchRestrictCountries(uint16[] calldata _countries) external {
|
|
for (uint i = 0; i < _countries.length; i++) {
|
|
addCountryRestriction(_countries[i]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Removes countries restriction in batch.
|
|
* Identities from those countries will again be authorised to manipulate Tokens linked to this Compliance.
|
|
* @param _countries Countries to be unrestricted, should be expressed by following numeric ISO 3166-1 standard
|
|
* Only the owner of the Compliance smart contract can call this function
|
|
* emits _countries.length `RemovedRestrictedCountry` events
|
|
*/
|
|
function batchUnrestrictCountries(uint16[] calldata _countries) external {
|
|
for (uint i = 0; i < _countries.length; i++) {
|
|
removeCountryRestriction(_countries[i]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Adds country restriction.
|
|
* Identities from those countries will be forbidden to manipulate Tokens linked to this Compliance.
|
|
* @param _country Country to be restricted, should be expressed by following numeric ISO 3166-1 standard
|
|
* Only the owner of the Compliance smart contract can call this function
|
|
* emits an `AddedRestrictedCountry` event
|
|
*/
|
|
function addCountryRestriction(uint16 _country) public onlyOwner {
|
|
require(!_restrictedCountries[_country], "country already restricted");
|
|
_restrictedCountries[_country] = true;
|
|
emit AddedRestrictedCountry(_country);
|
|
}
|
|
|
|
/**
|
|
* @dev Removes country restriction.
|
|
* Identities from those countries will again be authorised to manipulate Tokens linked to this Compliance.
|
|
* @param _country Country to be unrestricted, should be expressed by following numeric ISO 3166-1 standard
|
|
* Only the owner of the Compliance smart contract can call this function
|
|
* emits an `RemovedRestrictedCountry` event
|
|
*/
|
|
function removeCountryRestriction(uint16 _country) public onlyOwner {
|
|
require(_restrictedCountries[_country], "country not restricted");
|
|
_restrictedCountries[_country] = false;
|
|
emit RemovedRestrictedCountry(_country);
|
|
}
|
|
|
|
/**
|
|
* @dev Returns true if country is Restricted
|
|
* @param _country, numeric ISO 3166-1 standard of the country to be checked
|
|
*/
|
|
function isCountryRestricted(uint16 _country) public view returns (bool) {
|
|
return (_restrictedCountries[_country]);
|
|
}
|
|
|
|
/**
|
|
* @dev check on the compliance status of a transaction.
|
|
* If the check returns TRUE, the transfer is allowed to be executed, if the check returns FALSE, the compliance
|
|
* feature will block the transfer execution
|
|
* The check will verify if the country of residence of `_to` is restricted or not, in case the country is
|
|
* restricted, this feature will block the transfer
|
|
* @param _to the address of the transfer receiver
|
|
*/
|
|
function complianceCheckOnCountryRestrictions (address /*_from*/, address _to, uint256 /*_value*/)
|
|
public view returns (bool) {
|
|
uint16 receiverCountry = _getCountry(_to);
|
|
if (isCountryRestricted(receiverCountry)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @dev state update of the compliance feature post-transfer.
|
|
* this compliance feature doesn't require state update post-transfer
|
|
* @param _from the address of the transfer sender
|
|
* @param _to the address of the transfer receiver
|
|
* @param _value the amount of tokens that `_from` sent to `_to`
|
|
* internal function, can be called only from the functions of the Compliance smart contract
|
|
*/
|
|
// solhint-disable-next-line no-empty-blocks
|
|
function _transferActionOnCountryRestrictions(address _from, address _to, uint256 _value) internal {}
|
|
|
|
/**
|
|
* @dev state update of the compliance feature post-minting.
|
|
* this compliance feature doesn't require state update post-minting
|
|
* @param _to the address of the minting beneficiary
|
|
* @param _value the amount of tokens minted on `_to` wallet
|
|
* internal function, can be called only from the functions of the Compliance smart contract
|
|
*/
|
|
// solhint-disable-next-line no-empty-blocks
|
|
function _creationActionOnCountryRestrictions(address _to, uint256 _value) internal {}
|
|
|
|
/**
|
|
* @dev state update of the compliance feature post-burning.
|
|
* this compliance feature doesn't require state update post-burning
|
|
* @param _from the wallet address on which tokens burnt
|
|
* @param _value the amount of tokens burnt from `_from` wallet
|
|
* internal function, can be called only from the functions of the Compliance smart contract
|
|
*/
|
|
// solhint-disable-next-line no-empty-blocks
|
|
function _destructionActionOnCountryRestrictions(address _from, uint256 _value) internal {}
|
|
}
|