mirror of
https://github.com/luxfi/erc-3643.git
synced 2026-10-30 16:58:28 +00:00
* ✨ integrate foundry alongside hardhat for dual testing framework - Add foundry.toml configuration - Reorganize test structure: test/forge/ and test/hardhat/ - Add Foundry scripts to package.json (build:forge, test:forge, coverage:forge) - Update hardhat.config.ts with evmVersion for compatibility - Add GitHub workflows and coverage scripts from template - Add Husky hooks (pre-commit, post-checkout, post-merge) - Add .vscode/settings.json for better IDE support - Disable coverage checks until tests are migrated (commented with TODO) This migration is based on TokenySolutions/contracts-template and enables gradual migration of tests from Hardhat (TypeScript) to Foundry (Solidity). Related to: BT-1418 * ✅ trex factory tests * ⚰️ remove trex suit * feat(forge): reorganize Foundry test structure and sync GitHub workflows - Move TREXFactorySetup to helpers folder - Rename TREXSuite.t.sol to TREXFactory.t.sol - Update fixture to inherit from Test for proper Foundry pattern - Transfer ownership to deployer address to match Hardhat behavior - Sync GitHub workflows with package.json scripts - Update test.yml to use npm run build and npm run test - Update push_checking.yml to use unified npm run lint - Update forge_coverage.sh to use npm run coverage * fix(ci): install Foundry and skip husky in push_checking workflow - Add Foundry installation step before npm ci - Set HUSKY=0 to skip husky setup in CI environment - Fixes 'forge: not found' error during npm prepare script * 🔧 keep hardhat settings * ✅ create addressess directly * ✅ removed test_StandardAddressesSet * ✅ fix lint * 💡 removed title natspecs * ✅ migrated trex factort tests * ✅ added test module multicall * ✅ migrate agent role test * ✅ migrate claim topics registry * ✅ migrated trusted issuer registry * ✅ migrate identity registry storage * ✅ migrated identity registry tests * ✅ migrated implementation authority test * ✅ migrated token agen restrictions * ✅ migrated token information test * ✅ migrated token recover * ✅ migrated token permit * ✅ migrated token transfer * ✅ migrated utilities upgrade * ✅ migrated freeze check * ✅ migrated compliance check in utilities test * ✅ migrated eligibility check * ✅ migrated transfer check in utilities * ✅ migrated compliance test * ✅ migrated gateway tests * 🔥 removed already defined events * 🗑️ imported Initializable error from openzeppelin * ➕ added already defined events and errors * ✅ added base test token * ✅ used idFactory * ♻️ refactored compliance test * ⚰️ remoced useless vm.prank * 🔧 deleted hardhat configurations * 💚 fixed ci * refactor: remove 100% coverage requirement from forge_coverage.sh - Remove strict 100% coverage checks that were causing workflow failures - Script now only generates and displays coverage report without failing - Aligns with previous behavior where coverage was informational only * ✅ resolve getVerifiedDetails * ✅ applied _getEligibility and remove via-ir from foundry.toml * ✅ cover tokena and token permit * ✅ cover compliance * ✅ cover identity registry * ✅ increased trex gateway coverage * ✅ increase coverage for trex factory * ✅ increased AbstractModuleUpgradeable.sol coverage * ⚰️ removed abstract module * 🔧 updted generate coverage * ✅ coverage 100% identity registry * ✅ coverage 100% trex gate way * ✅ coverage trex factory * ✅ coverage 100% AbstractModuleUpgradeable by test module * ✅ coverage IAFactory.sol * ✅ coverage 100% for implementation authority * ✅ coverage 1005 abstract proxy * ✅ coverage 100% claim topic registry * ✅ coverage 100% identity registry storage * ✅ coverage 100% modular compliance proxy * ✅ coverage trusted issuer registry proxy * ✅ coverage 100% identity registry * ✅ coverage 100% token proxy * 🚨 resolve linter in token information * ✅ coverage 100% roles * 🚨 resolve linter * 🔧 added no coverage for test, _testContracts and utils * ✅ coverage 100% for token.sol * ✅ coverage 100% for modular compliance * ✅ coverage 100% trusted issuer registry * 🔧 restore package.json * ✅ coverage 100% for utlity checker * 🚨 fix linter
364 lines
15 KiB
Solidity
364 lines
15 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) 2025, 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.30;
|
|
|
|
import "../../errors/CommonErrors.sol";
|
|
import "../../errors/InvalidArgumentErrors.sol";
|
|
import "../../factory/ITREXFactory.sol";
|
|
import "../../roles/IERC173.sol";
|
|
import "../../token/IToken.sol";
|
|
import "../interface/IProxy.sol";
|
|
import "./IIAFactory.sol";
|
|
import "./ITREXImplementationAuthority.sol";
|
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
|
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
|
|
/// Errors
|
|
|
|
/// @dev Thrown when caller is not the owner of all impacted contracts.
|
|
error CallerNotOwnerOfAllImpactedContracts();
|
|
|
|
/// @dev Thrown when called on reference contract.
|
|
error CannotCallOnReferenceContract();
|
|
|
|
/// @dev Thrown when new implementation authority is not a reference contract.
|
|
error NewIAIsNotAReferenceContract();
|
|
|
|
/// @dev Thrown when version doesn't exist.
|
|
error NonExistingVersion();
|
|
|
|
/// @dev Thrown when called by other than reference contract
|
|
error OnlyReferenceContractCanCall();
|
|
|
|
/// @dev Thrown when version is already fetched.
|
|
error VersionAlreadyFetched();
|
|
|
|
/// @dev Thrown when version already exists.
|
|
error VersionAlreadyExists();
|
|
|
|
/// @dev Thrown when version is already in use.
|
|
error VersionAlreadyInUse();
|
|
|
|
/// @dev Thrown when version of new implementation authority is not the same as the current implementation authority version.
|
|
error VersionOfNewIAMustBeTheSameAsCurrentIA();
|
|
|
|
contract TREXImplementationAuthority is ITREXImplementationAuthority, Ownable, IERC165 {
|
|
|
|
/// variables
|
|
/// current version
|
|
Version private _currentVersion;
|
|
|
|
/// mapping to get contracts of each version
|
|
mapping(bytes32 => TREXContracts) private _contracts;
|
|
|
|
/// reference ImplementationAuthority used by the TREXFactory
|
|
bool private _reference;
|
|
|
|
/// address of TREXFactory contract
|
|
address private _trexFactory;
|
|
|
|
/// address of factory for TREXImplementationAuthority contracts
|
|
address private _iaFactory;
|
|
|
|
/// functions
|
|
|
|
/**
|
|
* @dev Constructor of the ImplementationAuthority contract
|
|
* @param referenceStatus boolean value determining if the contract
|
|
* is the main IA or an auxiliary contract
|
|
* @param trexFactory the address of TREXFactory referencing the main IA
|
|
* if `referenceStatus` is true then `trexFactory` at deployment is set
|
|
* on zero address. In that scenario, call `setTREXFactory` post-deployment
|
|
* @param iaFactory the address for the factory of IA contracts
|
|
* emits `ImplementationAuthoritySet` event
|
|
* emits a `IAFactorySet` event
|
|
*/
|
|
constructor(bool referenceStatus, address trexFactory, address iaFactory) Ownable(msg.sender) {
|
|
_reference = referenceStatus;
|
|
_trexFactory = trexFactory;
|
|
_iaFactory = iaFactory;
|
|
emit ImplementationAuthoritySet(referenceStatus, trexFactory);
|
|
emit IAFactorySet(iaFactory);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-setTREXFactory}.
|
|
*/
|
|
function setTREXFactory(address trexFactory) external override onlyOwner {
|
|
require(
|
|
isReferenceContract() && ITREXFactory(trexFactory).getImplementationAuthority() == address(this),
|
|
OnlyReferenceContractCanCall()
|
|
);
|
|
_trexFactory = trexFactory;
|
|
emit TREXFactorySet(trexFactory);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-setIAFactory}.
|
|
*/
|
|
function setIAFactory(address iaFactory) external override onlyOwner {
|
|
require(
|
|
isReferenceContract() && ITREXFactory(_trexFactory).getImplementationAuthority() == address(this),
|
|
OnlyReferenceContractCanCall()
|
|
);
|
|
_iaFactory = iaFactory;
|
|
emit IAFactorySet(iaFactory);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-useTREXVersion}.
|
|
*/
|
|
function addAndUseTREXVersion(Version calldata _version, TREXContracts calldata _trex) external override {
|
|
addTREXVersion(_version, _trex);
|
|
useTREXVersion(_version);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-fetchVersionList}.
|
|
*/
|
|
function fetchVersion(Version calldata _version) external override {
|
|
require(!isReferenceContract(), CannotCallOnReferenceContract());
|
|
require(_contracts[_versionToBytes(_version)].tokenImplementation == address(0), VersionAlreadyFetched());
|
|
|
|
_contracts[_versionToBytes(_version)] =
|
|
ITREXImplementationAuthority(getReferenceContract()).getContracts(_version);
|
|
emit TREXVersionFetched(_version, _contracts[_versionToBytes(_version)]);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-changeImplementationAuthority}.
|
|
*/
|
|
// solhint-disable-next-line code-complexity, function-max-lines
|
|
function changeImplementationAuthority(address _token, address _newImplementationAuthority) external override {
|
|
require(_token != address(0), ZeroAddress());
|
|
require(_newImplementationAuthority != address(0) || isReferenceContract(), OnlyReferenceContractCanCall());
|
|
|
|
address _ir = address(IToken(_token).identityRegistry());
|
|
address _mc = address(IToken(_token).compliance());
|
|
address _irs = address(IERC3643IdentityRegistry(_ir).identityStorage());
|
|
address _ctr = address(IERC3643IdentityRegistry(_ir).topicsRegistry());
|
|
address _tir = address(IERC3643IdentityRegistry(_ir).issuersRegistry());
|
|
|
|
// calling this function requires ownership of ALL contracts of the T-REX suite
|
|
require(
|
|
Ownable(_token).owner() == msg.sender && Ownable(_ir).owner() == msg.sender
|
|
&& Ownable(_mc).owner() == msg.sender && Ownable(_irs).owner() == msg.sender
|
|
&& Ownable(_ctr).owner() == msg.sender && Ownable(_tir).owner() == msg.sender,
|
|
CallerNotOwnerOfAllImpactedContracts()
|
|
);
|
|
|
|
if (_newImplementationAuthority == address(0)) {
|
|
_newImplementationAuthority = IIAFactory(_iaFactory).deployIA(_token);
|
|
} else {
|
|
require(
|
|
_versionToBytes(ITREXImplementationAuthority(_newImplementationAuthority).getCurrentVersion())
|
|
== _versionToBytes(_currentVersion),
|
|
VersionOfNewIAMustBeTheSameAsCurrentIA()
|
|
);
|
|
require(
|
|
!ITREXImplementationAuthority(_newImplementationAuthority).isReferenceContract()
|
|
|| _newImplementationAuthority == getReferenceContract(),
|
|
NewIAIsNotAReferenceContract()
|
|
);
|
|
require(
|
|
IIAFactory(_iaFactory).deployedByFactory(_newImplementationAuthority)
|
|
|| _newImplementationAuthority == getReferenceContract(),
|
|
InvalidImplementationAuthority()
|
|
);
|
|
}
|
|
|
|
IProxy(_token).setImplementationAuthority(_newImplementationAuthority);
|
|
IProxy(_ir).setImplementationAuthority(_newImplementationAuthority);
|
|
IProxy(_mc).setImplementationAuthority(_newImplementationAuthority);
|
|
IProxy(_ctr).setImplementationAuthority(_newImplementationAuthority);
|
|
IProxy(_tir).setImplementationAuthority(_newImplementationAuthority);
|
|
// IRS can be shared by multiple tokens, and therefore could have been updated already
|
|
if (IProxy(_irs).getImplementationAuthority() == address(this)) {
|
|
IProxy(_irs).setImplementationAuthority(_newImplementationAuthority);
|
|
}
|
|
emit ImplementationAuthorityChanged(_token, _newImplementationAuthority);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getCurrentVersion}.
|
|
*/
|
|
function getCurrentVersion() external view override returns (Version memory) {
|
|
return _currentVersion;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getContracts}.
|
|
*/
|
|
function getContracts(Version calldata _version) external view override returns (TREXContracts memory) {
|
|
return _contracts[_versionToBytes(_version)];
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getTREXFactory}.
|
|
*/
|
|
function getTREXFactory() external view override returns (address) {
|
|
return _trexFactory;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getTokenImplementation}.
|
|
*/
|
|
function getTokenImplementation() external view override returns (address) {
|
|
return _contracts[_versionToBytes(_currentVersion)].tokenImplementation;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getCTRImplementation}.
|
|
*/
|
|
function getCTRImplementation() external view override returns (address) {
|
|
return _contracts[_versionToBytes(_currentVersion)].ctrImplementation;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getIRImplementation}.
|
|
*/
|
|
function getIRImplementation() external view override returns (address) {
|
|
return _contracts[_versionToBytes(_currentVersion)].irImplementation;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getIRSImplementation}.
|
|
*/
|
|
function getIRSImplementation() external view override returns (address) {
|
|
return _contracts[_versionToBytes(_currentVersion)].irsImplementation;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getTIRImplementation}.
|
|
*/
|
|
function getTIRImplementation() external view override returns (address) {
|
|
return _contracts[_versionToBytes(_currentVersion)].tirImplementation;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getMCImplementation}.
|
|
*/
|
|
function getMCImplementation() external view override returns (address) {
|
|
return _contracts[_versionToBytes(_currentVersion)].mcImplementation;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-addTREXVersion}.
|
|
*/
|
|
function addTREXVersion(Version calldata _version, TREXContracts calldata _trex) public override onlyOwner {
|
|
require(isReferenceContract(), OnlyReferenceContractCanCall());
|
|
require(_contracts[_versionToBytes(_version)].tokenImplementation == address(0), VersionAlreadyExists());
|
|
|
|
require(
|
|
_trex.ctrImplementation != address(0) && _trex.irImplementation != address(0)
|
|
&& _trex.irsImplementation != address(0) && _trex.mcImplementation != address(0)
|
|
&& _trex.tirImplementation != address(0) && _trex.tokenImplementation != address(0),
|
|
ZeroAddress()
|
|
);
|
|
|
|
_contracts[_versionToBytes(_version)] = _trex;
|
|
emit TREXVersionAdded(_version, _trex);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-useTREXVersion}.
|
|
*/
|
|
function useTREXVersion(Version calldata _version) public override onlyOwner {
|
|
require(_versionToBytes(_version) != _versionToBytes(_currentVersion), VersionAlreadyInUse());
|
|
require(_contracts[_versionToBytes(_version)].tokenImplementation != address(0), NonExistingVersion());
|
|
|
|
_currentVersion = _version;
|
|
emit VersionUpdated(_version);
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-isReferenceContract}.
|
|
*/
|
|
function isReferenceContract() public view override returns (bool) {
|
|
return _reference;
|
|
}
|
|
|
|
/**
|
|
* @dev See {ITREXImplementationAuthority-getReferenceContract}.
|
|
*/
|
|
function getReferenceContract() public view override returns (address) {
|
|
return ITREXFactory(_trexFactory).getImplementationAuthority();
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC165-supportsInterface}.
|
|
*/
|
|
function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {
|
|
return interfaceId == type(ITREXImplementationAuthority).interfaceId || interfaceId == type(IERC173).interfaceId
|
|
|| interfaceId == type(IERC165).interfaceId;
|
|
}
|
|
|
|
/**
|
|
* @dev casting function Version => bytes to allow compare values easier
|
|
*/
|
|
function _versionToBytes(Version memory _version) private pure returns (bytes32) {
|
|
return bytes32(keccak256(abi.encodePacked(_version.major, _version.minor, _version.patch)));
|
|
}
|
|
|
|
}
|