Files
Mohamad HammoudandGitHub 94182deb9c ✨ BT-1418 integrate foundry & hardhat + migrating solidity tests (#76)
* ✨ 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
2025-12-31 16:58:16 +08:00

361 lines
14 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/InvalidArgumentErrors.sol";
import "../errors/RoleErrors.sol";
import "../roles/AgentRole.sol";
import "../roles/IERC173.sol";
import "./ITREXGateway.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/// Errors
/// The Public Deployment Status is already set properly
error PublicDeploymentAlreadyEnabled();
/// The Public Deployment Status is already set properly
error PublicDeploymentAlreadyDisabled();
/// The Deployment fees are already enabled
error DeploymentFeesAlreadyEnabled();
/// The Deployment fees are already disabled
error DeploymentFeesAlreadyDisabled();
/// The address is already a deployer
error DeployerAlreadyExists(address deployer);
/// The address is not a deployer
error DeployerDoesNotExist(address deployer);
/// Cannot deploy if not deployer when public deployment disabled
error PublicDeploymentsNotAllowed();
/// Public deployers can only deploy for themselves
error PublicCannotDeployOnBehalf();
/// Discount cannot be bigger than 10000 (100%)
error DiscountOutOfRange();
/// Batch Size is too big, could run out of gas
error BatchMaxLengthExceeded(uint16 lengthLimit);
contract TREXGateway is ITREXGateway, AgentRole, IERC165 {
/// address of the TREX Factory that is managed by the Gateway
address private _factory;
/// public deployment status variable
bool private _publicDeploymentStatus;
/// deployment fee details
Fee private _deploymentFee;
/// deployment fees enabling variable
bool private _deploymentFeeEnabled;
/// mapping containing all deployer addresses
mapping(address => bool) private _deployers;
/// mapping for deployment discounts on fees
mapping(address => uint16) private _feeDiscount;
/// constructor of the contract, setting up the factory address and
/// the public deployment status
constructor(address factory, bool publicDeploymentStatus) {
_factory = factory;
_publicDeploymentStatus = publicDeploymentStatus;
emit FactorySet(factory);
emit PublicDeploymentStatusSet(publicDeploymentStatus);
}
/**
* @dev See {ITREXGateway-setFactory}.
*/
function setFactory(address factory) external override onlyOwner {
require(factory != address(0), ZeroAddress());
_factory = factory;
emit FactorySet(factory);
}
/**
* @dev See {ITREXGateway-setPublicDeploymentStatus}.
*/
function setPublicDeploymentStatus(bool _isEnabled) external override onlyOwner {
if (_isEnabled == _publicDeploymentStatus) {
if (_isEnabled) {
revert PublicDeploymentAlreadyEnabled();
}
revert PublicDeploymentAlreadyDisabled();
}
_publicDeploymentStatus = _isEnabled;
emit PublicDeploymentStatusSet(_isEnabled);
}
/**
* @dev See {ITREXGateway-transferFactoryOwnership}.
*/
function transferFactoryOwnership(address _newOwner) external override onlyOwner {
Ownable(_factory).transferOwnership(_newOwner);
}
/**
* @dev See {ITREXGateway-enableDeploymentFee}.
*/
function enableDeploymentFee(bool _isEnabled) external override onlyOwner {
if (_isEnabled == _deploymentFeeEnabled) {
if (_isEnabled) {
revert DeploymentFeesAlreadyEnabled();
}
revert DeploymentFeesAlreadyDisabled();
}
_deploymentFeeEnabled = _isEnabled;
emit DeploymentFeeEnabled(_isEnabled);
}
/**
* @dev See {ITREXGateway-setDeploymentFee}.
*/
function setDeploymentFee(uint256 _fee, address _feeToken, address _feeCollector) external override onlyOwner {
require(_feeToken != address(0) && _feeCollector != address(0), ZeroAddress());
_deploymentFee.fee = _fee;
_deploymentFee.feeToken = _feeToken;
_deploymentFee.feeCollector = _feeCollector;
emit DeploymentFeeSet(_fee, _feeToken, _feeCollector);
}
/**
* @dev See {ITREXGateway-batchAddDeployer}.
*/
function batchAddDeployer(address[] calldata deployers) external override {
require(isAgent(msg.sender) || msg.sender == owner(), SenderIsNotAdmin());
require(deployers.length <= 500, BatchMaxLengthExceeded(500));
for (uint256 i = 0; i < deployers.length; i++) {
require(!isDeployer(deployers[i]), DeployerAlreadyExists(deployers[i]));
_deployers[deployers[i]] = true;
emit DeployerAdded(deployers[i]);
}
}
/**
* @dev See {ITREXGateway-addDeployer}.
*/
function addDeployer(address deployer) external override {
require(isAgent(msg.sender) || msg.sender == owner(), SenderIsNotAdmin());
require(!isDeployer(deployer), DeployerAlreadyExists(deployer));
_deployers[deployer] = true;
emit DeployerAdded(deployer);
}
/**
* @dev See {ITREXGateway-batchRemoveDeployer}.
*/
function batchRemoveDeployer(address[] calldata deployers) external override {
require(isAgent(msg.sender) || msg.sender == owner(), SenderIsNotAdmin());
require(deployers.length <= 500, BatchMaxLengthExceeded(500));
for (uint256 i = 0; i < deployers.length; i++) {
require(isDeployer(deployers[i]), DeployerDoesNotExist(deployers[i]));
delete _deployers[deployers[i]];
emit DeployerRemoved(deployers[i]);
}
}
/**
* @dev See {ITREXGateway-removeDeployer}.
*/
function removeDeployer(address deployer) external override {
require(isAgent(msg.sender) || msg.sender == owner(), SenderIsNotAdmin());
require(isDeployer(deployer), DeployerDoesNotExist(deployer));
delete _deployers[deployer];
emit DeployerRemoved(deployer);
}
/**
* @dev See {ITREXGateway-batchApplyFeeDiscount}.
*/
function batchApplyFeeDiscount(address[] calldata deployers, uint16[] calldata discounts) external override {
require(isAgent(msg.sender) || msg.sender == owner(), SenderIsNotAdmin());
require(deployers.length <= 500, BatchMaxLengthExceeded(500));
for (uint256 i = 0; i < deployers.length; i++) {
require(discounts[i] <= 10000, DiscountOutOfRange());
_feeDiscount[deployers[i]] = discounts[i];
emit FeeDiscountApplied(deployers[i], discounts[i]);
}
}
/**
* @dev See {ITREXGateway-applyFeeDiscount}.
*/
function applyFeeDiscount(address deployer, uint16 discount) external override {
require(isAgent(msg.sender) || msg.sender == owner(), SenderIsNotAdmin());
require(discount <= 10000, DiscountOutOfRange());
_feeDiscount[deployer] = discount;
emit FeeDiscountApplied(deployer, discount);
}
/**
* @dev See {ITREXGateway-batchDeployTREXSuite}.
*/
function batchDeployTREXSuite(
ITREXFactory.TokenDetails[] memory _tokenDetails,
ITREXFactory.ClaimDetails[] memory _claimDetails
) external override {
require(_tokenDetails.length <= 5, BatchMaxLengthExceeded(5));
for (uint256 i = 0; i < _tokenDetails.length; i++) {
deployTREXSuite(_tokenDetails[i], _claimDetails[i]);
}
}
/**
* @dev See {ITREXGateway-getPublicDeploymentStatus}.
*/
function getPublicDeploymentStatus() external view override returns (bool) {
return _publicDeploymentStatus;
}
/**
* @dev See {ITREXGateway-getFactory}.
*/
function getFactory() external view override returns (address) {
return _factory;
}
/**
* @dev See {ITREXGateway-getDeploymentFee}.
*/
function getDeploymentFee() external view override returns (Fee memory) {
return _deploymentFee;
}
/**
* @dev See {ITREXGateway-isDeploymentFeeEnabled}.
*/
function isDeploymentFeeEnabled() external view override returns (bool) {
return _deploymentFeeEnabled;
}
/**
* @dev See {ITREXGateway-deployTREXSuite}.
*/
function deployTREXSuite(
ITREXFactory.TokenDetails memory _tokenDetails,
ITREXFactory.ClaimDetails memory _claimDetails
) public override {
require(_publicDeploymentStatus || isDeployer(msg.sender), PublicDeploymentsNotAllowed());
require(
!_publicDeploymentStatus || msg.sender == _tokenDetails.owner || isDeployer(msg.sender),
PublicCannotDeployOnBehalf()
);
uint256 feeApplied = 0;
if (_deploymentFeeEnabled) {
if (_deploymentFee.fee > 0 && _feeDiscount[msg.sender] < 10000) {
feeApplied = calculateFee(msg.sender);
IERC20(_deploymentFee.feeToken).transferFrom(msg.sender, _deploymentFee.feeCollector, feeApplied);
}
}
string memory _salt = string(abi.encodePacked(Strings.toHexString(_tokenDetails.owner), _tokenDetails.name));
ITREXFactory(_factory).deployTREXSuite(_salt, _tokenDetails, _claimDetails);
emit GatewaySuiteDeploymentProcessed(msg.sender, _tokenDetails.owner, feeApplied);
}
/**
* @dev See {ITREXGateway-isDeployer}.
*/
function isDeployer(address deployer) public view override returns (bool) {
return _deployers[deployer];
}
/**
* @dev See {ITREXGateway-calculateFee}.
*/
function calculateFee(address deployer) public view override returns (uint256) {
return _deploymentFee.fee - ((_feeDiscount[deployer] * _deploymentFee.fee) / 10000);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {
return interfaceId == type(ITREXGateway).interfaceId || interfaceId == type(IERC173).interfaceId
|| interfaceId == type(IERC165).interfaceId;
}
}