From 9f4e94b1df9aa1a858a0d7ec84fc7dc63d7ab615 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Mon, 3 Jun 2024 13:37:20 +0700 Subject: [PATCH 01/12] define RNSCommission contract for multi treasury transfer --- src/RNSCommission.sol | 130 ++++++++++++++++++++++++++++++ src/interfaces/IRNSCommission.sol | 51 ++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 src/RNSCommission.sol create mode 100644 src/interfaces/IRNSCommission.sol diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol new file mode 100644 index 00000000..168f82bc --- /dev/null +++ b/src/RNSCommission.sol @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; +import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; +import { IRNSCommission } from "./interfaces/IRNSCommission.sol"; +import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; +import { RONTransferHelper } from "./libraries/transfers/RONTransferHelper.sol"; + +contract RNSCommission is Initializable, AccessControlEnumerable, IRNSCommission { + uint256 public constant MAX_PERCENTAGE = 100_00; + bytes32 public constant COMMISSION_SETTER_ROLE = keccak256("COMMISSION_SETTER_ROLE"); + + /// @dev Gap for upgradability. + uint256[50] private ____gap; + + Commission[] internal _commissionInfo; + + constructor() { + _disableInitializers(); + } + + receive() external payable { + _allocateCommissionAndTransferToTreasury(msg.value); + } + + function initialize(address admin, address[] calldata commissionSetters, Commission[] calldata treasuryCommission) + external + initializer + { + _setupRole(DEFAULT_ADMIN_ROLE, admin); + uint256 length = commissionSetters.length; + for (uint256 i; i < length; ++i) { + _setupRole(COMMISSION_SETTER_ROLE, commissionSetters[i]); + } + + _replaceTreasuries(treasuryCommission); + } + + /// @inheritdoc IRNSCommission + function getTreasuries() external view returns (Commission[] memory treasuriesInfo) { + return _commissionInfo; + } + + /// @inheritdoc IRNSCommission + function replaceTreasuries(Commission[] calldata treasuriesInfo) external onlyRole(COMMISSION_SETTER_ROLE) { + _replaceTreasuries(treasuriesInfo); + } + + /// @inheritdoc IRNSCommission + function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) + external + onlyRole(COMMISSION_SETTER_ROLE) + { + if (treasuryId < 0 || treasuryId > _commissionInfo.length - 1) { + revert InvalidArrayLength(); + } + + _commissionInfo[treasuryId].recipient = newAddr; + _commissionInfo[treasuryId].name = name; + emit TreasuryInfoUpdated(newAddr, name, treasuryId); + } + + /** + * @dev Helper method to calculate allocations. + */ + function _calcAllocations(uint256 totalAmount) internal view returns (Allocation[] memory allocs) { + if (totalAmount == 0) { + revert InvalidAmountOfRON(); + } + uint256 length = _commissionInfo.length; + + allocs = new Allocation[](length); + + uint256 lastIdx = length - 1; + uint256 sumValue; + + for (uint256 i; i < lastIdx; ++i) { + allocs[i] = Allocation({ + recipient: _commissionInfo[i].recipient, + value: _computePercentage(totalAmount, _commissionInfo[i].ratio) + }); + sumValue += allocs[i].value; + } + + // Refund the remaining RON for the last treasury + if (sumValue < totalAmount) { + allocs[lastIdx] = Allocation({ recipient: _commissionInfo[lastIdx].recipient, value: totalAmount - sumValue }); + } + } + + /** + * @dev Helper method to allocate commission and take fee into treasuries address. + */ + function _allocateCommissionAndTransferToTreasury(uint256 ronAmount) internal { + IRNSCommission.Allocation[] memory allocs = _calcAllocations(ronAmount); + uint256 length = allocs.length; + + for (uint256 i = 0; i < length; ++i) { + uint256 value = allocs[i].value; + address payable recipient = allocs[i].recipient; + + RONTransferHelper.safeTransfer(recipient, value); + } + } + + function _replaceTreasuries(Commission[] calldata treasuriesInfo) internal { + uint256 length = treasuriesInfo.length; + // treasuriesInfo[] can not be empty + if (length < 1) revert InvalidArrayLength(); + + delete _commissionInfo; + + uint256 sum = 0; + + for (uint256 i = 0; i < length; ++i) { + sum += treasuriesInfo[i].ratio; + _commissionInfo.push(treasuriesInfo[i]); + } + + if (sum != MAX_PERCENTAGE) revert InvalidRatio(); + + emit TreasuriesReplaced(treasuriesInfo); + } + + // Calculate amount of money based on treasury's ratio + function _computePercentage(uint256 value, uint256 percentage) internal pure virtual returns (uint256) { + return Math.mulDiv(value, percentage, MAX_PERCENTAGE); + } +} diff --git a/src/interfaces/IRNSCommission.sol b/src/interfaces/IRNSCommission.sol new file mode 100644 index 00000000..7ad8498a --- /dev/null +++ b/src/interfaces/IRNSCommission.sol @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +interface IRNSCommission { + struct Commission { + address payable recipient; + uint256 ratio; // Values [0; 100_00] reflexes [0; 100%] + bytes name; // Treasury's name + } + + struct Allocation { + address payable recipient; + uint256 value; + } + + /// @dev Emitted when all the treasury info info are replaced. + event TreasuriesReplaced(Commission[] treasuriesInfo); + /// @dev Emitted when specific treasury info are updated. + event TreasuryInfoUpdated(address payable treasuryAddr, bytes name, uint256 treasuryId); + + /// @dev Revert when index is out of range + error InvalidArrayLength(); + /// @dev Revert when ratio is invalid + error InvalidRatio(); + /// @dev Revert when amount of RON is invalid + error InvalidAmountOfRON(); + + /** + * @dev Returns all treasury. + */ + function getTreasuries() external view returns (Commission[] memory treasuriesInfo); + + /** + * @dev Replaces all treasuries information + * + * Requirements: + * - The method caller is setter role. + * - The total ratio must be equal to 100%. + * Emits the event `TreasuriesPreplaced`. + */ + function replaceTreasuries(Commission[] calldata treasuriesInfo) external; + + /** + * @dev Sets for specific treasury information based on the treasury `id`. + * + * Requirements: + * - The method caller is setter role. + * Emits the event `TreasuryInfoUpdated`. + */ + function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) external; +} From a85d83319bbf8bb11ecc3c1d4eb8aa6fdae74cad Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Mon, 3 Jun 2024 14:05:42 +0700 Subject: [PATCH 02/12] fix(RNSCommission): fix naming --- src/RNSCommission.sol | 12 ++++---- src/interfaces/INSCommission.sol | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/interfaces/INSCommission.sol diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index 168f82bc..c6edd0cc 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.19; import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; -import { IRNSCommission } from "./interfaces/IRNSCommission.sol"; +import { INSCommission } from "./interfaces/INSCommission.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { RONTransferHelper } from "./libraries/transfers/RONTransferHelper.sol"; -contract RNSCommission is Initializable, AccessControlEnumerable, IRNSCommission { +contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission { uint256 public constant MAX_PERCENTAGE = 100_00; bytes32 public constant COMMISSION_SETTER_ROLE = keccak256("COMMISSION_SETTER_ROLE"); @@ -37,17 +37,17 @@ contract RNSCommission is Initializable, AccessControlEnumerable, IRNSCommission _replaceTreasuries(treasuryCommission); } - /// @inheritdoc IRNSCommission + /// @inheritdoc INSCommission function getTreasuries() external view returns (Commission[] memory treasuriesInfo) { return _commissionInfo; } - /// @inheritdoc IRNSCommission + /// @inheritdoc INSCommission function replaceTreasuries(Commission[] calldata treasuriesInfo) external onlyRole(COMMISSION_SETTER_ROLE) { _replaceTreasuries(treasuriesInfo); } - /// @inheritdoc IRNSCommission + /// @inheritdoc INSCommission function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) external onlyRole(COMMISSION_SETTER_ROLE) @@ -93,7 +93,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, IRNSCommission * @dev Helper method to allocate commission and take fee into treasuries address. */ function _allocateCommissionAndTransferToTreasury(uint256 ronAmount) internal { - IRNSCommission.Allocation[] memory allocs = _calcAllocations(ronAmount); + INSCommission.Allocation[] memory allocs = _calcAllocations(ronAmount); uint256 length = allocs.length; for (uint256 i = 0; i < length; ++i) { diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol new file mode 100644 index 00000000..631d3d27 --- /dev/null +++ b/src/interfaces/INSCommission.sol @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +interface INSCommission { + struct Commission { + address payable recipient; + uint256 ratio; // Values [0; 100_00] reflexes [0; 100%] + bytes name; // Treasury's name + } + + struct Allocation { + address payable recipient; + uint256 value; + } + + /// @dev Emitted when all the treasury info info are replaced. + event TreasuriesReplaced(Commission[] treasuriesInfo); + /// @dev Emitted when specific treasury info are updated. + event TreasuryInfoUpdated(address payable treasuryAddr, bytes name, uint256 treasuryId); + + /// @dev Revert when index is out of range + error InvalidArrayLength(); + /// @dev Revert when ratio is invalid + error InvalidRatio(); + /// @dev Revert when amount of RON is invalid + error InvalidAmountOfRON(); + + /** + * @dev Returns all treasury. + */ + function getTreasuries() external view returns (Commission[] memory treasuriesInfo); + + /** + * @dev Replaces all treasuries information + * + * Requirements: + * - The method caller is setter role. + * - The total ratio must be equal to 100%. + * Emits the event `TreasuriesPreplaced`. + */ + function replaceTreasuries(Commission[] calldata treasuriesInfo) external; + + /** + * @dev Sets for specific treasury information based on the treasury `id`. + * + * Requirements: + * - The method caller is setter role. + * Emits the event `TreasuryInfoUpdated`. + */ + function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) external; +} From cb0f7d987faf49dc06962b4e50319c061b5fe685 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Mon, 3 Jun 2024 14:38:16 +0700 Subject: [PATCH 03/12] rm unnecessary file --- src/interfaces/IRNSCommission.sol | 51 ------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/interfaces/IRNSCommission.sol diff --git a/src/interfaces/IRNSCommission.sol b/src/interfaces/IRNSCommission.sol deleted file mode 100644 index 7ad8498a..00000000 --- a/src/interfaces/IRNSCommission.sol +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -interface IRNSCommission { - struct Commission { - address payable recipient; - uint256 ratio; // Values [0; 100_00] reflexes [0; 100%] - bytes name; // Treasury's name - } - - struct Allocation { - address payable recipient; - uint256 value; - } - - /// @dev Emitted when all the treasury info info are replaced. - event TreasuriesReplaced(Commission[] treasuriesInfo); - /// @dev Emitted when specific treasury info are updated. - event TreasuryInfoUpdated(address payable treasuryAddr, bytes name, uint256 treasuryId); - - /// @dev Revert when index is out of range - error InvalidArrayLength(); - /// @dev Revert when ratio is invalid - error InvalidRatio(); - /// @dev Revert when amount of RON is invalid - error InvalidAmountOfRON(); - - /** - * @dev Returns all treasury. - */ - function getTreasuries() external view returns (Commission[] memory treasuriesInfo); - - /** - * @dev Replaces all treasuries information - * - * Requirements: - * - The method caller is setter role. - * - The total ratio must be equal to 100%. - * Emits the event `TreasuriesPreplaced`. - */ - function replaceTreasuries(Commission[] calldata treasuriesInfo) external; - - /** - * @dev Sets for specific treasury information based on the treasury `id`. - * - * Requirements: - * - The method caller is setter role. - * Emits the event `TreasuryInfoUpdated`. - */ - function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) external; -} From ac1e12a94e3f3b1329eafe1afd74108235953b0c Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Mon, 3 Jun 2024 16:39:15 +0700 Subject: [PATCH 04/12] fix(RNSCommission):add _allowedSenders mapping and related function --- src/RNSCommission.sol | 48 ++++++++++++++++++++++++-------- src/interfaces/INSCommission.sol | 18 ++++++++---- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index c6edd0cc..d2348ac3 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -15,26 +15,42 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission uint256[50] private ____gap; Commission[] internal _commissionInfo; + mapping(address => bool) public _allowedSenders; constructor() { _disableInitializers(); } receive() external payable { - _allocateCommissionAndTransferToTreasury(msg.value); + if (_isAllowedSender(msg.sender)) { + _allocateCommissionAndTransferToTreasury(msg.value); + } } - function initialize(address admin, address[] calldata commissionSetters, Commission[] calldata treasuryCommission) - external - initializer - { + fallback() external payable { + if (_isAllowedSender(msg.sender)) { + _allocateCommissionAndTransferToTreasury(msg.value); + } + } + + function initialize( + address admin, + address[] calldata commissionSetters, + Commission[] calldata treasuryCommission, + address[] calldata allowedSenders + ) external initializer { _setupRole(DEFAULT_ADMIN_ROLE, admin); uint256 length = commissionSetters.length; for (uint256 i; i < length; ++i) { _setupRole(COMMISSION_SETTER_ROLE, commissionSetters[i]); } - _replaceTreasuries(treasuryCommission); + uint256 sendersLength = allowedSenders.length; + for (uint256 i; i < sendersLength; ++i) { + _allowedSenders[allowedSenders[i]] = true; + } + + _setTreasuries(treasuryCommission); } /// @inheritdoc INSCommission @@ -43,8 +59,8 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } /// @inheritdoc INSCommission - function replaceTreasuries(Commission[] calldata treasuriesInfo) external onlyRole(COMMISSION_SETTER_ROLE) { - _replaceTreasuries(treasuriesInfo); + function setTreasuries(Commission[] calldata treasuriesInfo) external onlyRole(COMMISSION_SETTER_ROLE) { + _setTreasuries(treasuriesInfo); } /// @inheritdoc INSCommission @@ -61,6 +77,11 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission emit TreasuryInfoUpdated(newAddr, name, treasuryId); } + /// @inheritdoc INSCommission + function allowSender(address sender) external onlyRole(COMMISSION_SETTER_ROLE) { + _allowedSenders[sender] = true; + } + /** * @dev Helper method to calculate allocations. */ @@ -83,7 +104,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission sumValue += allocs[i].value; } - // Refund the remaining RON for the last treasury + // Refund the remaining RON to the last treasury if (sumValue < totalAmount) { allocs[lastIdx] = Allocation({ recipient: _commissionInfo[lastIdx].recipient, value: totalAmount - sumValue }); } @@ -104,7 +125,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } } - function _replaceTreasuries(Commission[] calldata treasuriesInfo) internal { + function _setTreasuries(Commission[] calldata treasuriesInfo) internal { uint256 length = treasuriesInfo.length; // treasuriesInfo[] can not be empty if (length < 1) revert InvalidArrayLength(); @@ -120,7 +141,12 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission if (sum != MAX_PERCENTAGE) revert InvalidRatio(); - emit TreasuriesReplaced(treasuriesInfo); + emit TreasuriesUpdated(treasuriesInfo); + } + + /// Check if `sender` is allowed to send money + function _isAllowedSender(address sender) internal view returns (bool) { + return _allowedSenders[sender]; } // Calculate amount of money based on treasury's ratio diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index 631d3d27..c4db5c98 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -13,8 +13,8 @@ interface INSCommission { uint256 value; } - /// @dev Emitted when all the treasury info info are replaced. - event TreasuriesReplaced(Commission[] treasuriesInfo); + /// @dev Emitted when all the treasury info info are updated. + event TreasuriesUpdated(Commission[] treasuriesInfo); /// @dev Emitted when specific treasury info are updated. event TreasuryInfoUpdated(address payable treasuryAddr, bytes name, uint256 treasuryId); @@ -31,14 +31,14 @@ interface INSCommission { function getTreasuries() external view returns (Commission[] memory treasuriesInfo); /** - * @dev Replaces all treasuries information + * @dev Sets all treasuries information * * Requirements: * - The method caller is setter role. * - The total ratio must be equal to 100%. - * Emits the event `TreasuriesPreplaced`. + * Emits the event `TreasuriesUpdated`. */ - function replaceTreasuries(Commission[] calldata treasuriesInfo) external; + function setTreasuries(Commission[] calldata treasuriesInfo) external; /** * @dev Sets for specific treasury information based on the treasury `id`. @@ -48,4 +48,12 @@ interface INSCommission { * Emits the event `TreasuryInfoUpdated`. */ function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) external; + + /** + * @dev Allows specific `sender` to send money to this contract, which will then be transferred to the treasuries. + * + * Requirements: + * - The method caller is setter role. + */ + function allowSender(address sender) external; } From ef9e7f8f8fed59c1f99cfb8af8ac56df1197f5fa Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Tue, 4 Jun 2024 14:31:03 +0700 Subject: [PATCH 05/12] fix(RNSCommission): Use AccessControl to manage senders --- src/RNSCommission.sol | 67 +++++++++++++++----------------- src/interfaces/INSCommission.sol | 20 ++++------ 2 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index d2348ac3..d485f225 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -8,29 +8,28 @@ import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { RONTransferHelper } from "./libraries/transfers/RONTransferHelper.sol"; contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission { + /// @dev Constant representing the maximum percentage value (100%). uint256 public constant MAX_PERCENTAGE = 100_00; + /// @dev Role for accounts that can set commissions infomation and grant or revoke `SENDER_ROLE`. bytes32 public constant COMMISSION_SETTER_ROLE = keccak256("COMMISSION_SETTER_ROLE"); + /// @dev Role for accounts that can send RON for this contract. + bytes32 public constant SENDER_ROLE = keccak256("SENDER_ROLE"); /// @dev Gap for upgradability. uint256[50] private ____gap; - Commission[] internal _commissionInfo; - mapping(address => bool) public _allowedSenders; + Commission[] internal _commissionInfos; constructor() { _disableInitializers(); } receive() external payable { - if (_isAllowedSender(msg.sender)) { - _allocateCommissionAndTransferToTreasury(msg.value); - } + _fallback(); } fallback() external payable { - if (_isAllowedSender(msg.sender)) { - _allocateCommissionAndTransferToTreasury(msg.value); - } + _fallback(); } function initialize( @@ -40,6 +39,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission address[] calldata allowedSenders ) external initializer { _setupRole(DEFAULT_ADMIN_ROLE, admin); + uint256 length = commissionSetters.length; for (uint256 i; i < length; ++i) { _setupRole(COMMISSION_SETTER_ROLE, commissionSetters[i]); @@ -47,15 +47,16 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission uint256 sendersLength = allowedSenders.length; for (uint256 i; i < sendersLength; ++i) { - _allowedSenders[allowedSenders[i]] = true; + _setupRole(SENDER_ROLE, allowedSenders[i]); } + _setRoleAdmin(SENDER_ROLE, COMMISSION_SETTER_ROLE); _setTreasuries(treasuryCommission); } /// @inheritdoc INSCommission - function getTreasuries() external view returns (Commission[] memory treasuriesInfo) { - return _commissionInfo; + function getCommissions() external view returns (Commission[] memory treasuriesInfo) { + return _commissionInfos; } /// @inheritdoc INSCommission @@ -64,22 +65,17 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } /// @inheritdoc INSCommission - function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) + function setTreasuryInfo(uint256 treasuryId, address payable newAddr, bytes calldata name) external onlyRole(COMMISSION_SETTER_ROLE) { - if (treasuryId < 0 || treasuryId > _commissionInfo.length - 1) { + if (treasuryId > _commissionInfos.length - 1) { revert InvalidArrayLength(); } - _commissionInfo[treasuryId].recipient = newAddr; - _commissionInfo[treasuryId].name = name; - emit TreasuryInfoUpdated(newAddr, name, treasuryId); - } - - /// @inheritdoc INSCommission - function allowSender(address sender) external onlyRole(COMMISSION_SETTER_ROLE) { - _allowedSenders[sender] = true; + _commissionInfos[treasuryId].recipient = newAddr; + _commissionInfos[treasuryId].name = name; + emit TreasuryInfoUpdated(msg.sender, newAddr, name, treasuryId); } /** @@ -89,7 +85,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission if (totalAmount == 0) { revert InvalidAmountOfRON(); } - uint256 length = _commissionInfo.length; + uint256 length = _commissionInfos.length; allocs = new Allocation[](length); @@ -98,15 +94,15 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission for (uint256 i; i < lastIdx; ++i) { allocs[i] = Allocation({ - recipient: _commissionInfo[i].recipient, - value: _computePercentage(totalAmount, _commissionInfo[i].ratio) + recipient: _commissionInfos[i].recipient, + value: _computePercentage(totalAmount, _commissionInfos[i].ratio) }); sumValue += allocs[i].value; } - // Refund the remaining RON to the last treasury + // This code replaces value of the last recipient. if (sumValue < totalAmount) { - allocs[lastIdx] = Allocation({ recipient: _commissionInfo[lastIdx].recipient, value: totalAmount - sumValue }); + allocs[lastIdx] = Allocation({ recipient: _commissionInfos[lastIdx].recipient, value: totalAmount - sumValue }); } } @@ -130,27 +126,28 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission // treasuriesInfo[] can not be empty if (length < 1) revert InvalidArrayLength(); - delete _commissionInfo; + delete _commissionInfos; - uint256 sum = 0; + uint256 sum; for (uint256 i = 0; i < length; ++i) { sum += treasuriesInfo[i].ratio; - _commissionInfo.push(treasuriesInfo[i]); + _commissionInfos.push(treasuriesInfo[i]); } if (sum != MAX_PERCENTAGE) revert InvalidRatio(); - emit TreasuriesUpdated(treasuriesInfo); - } - - /// Check if `sender` is allowed to send money - function _isAllowedSender(address sender) internal view returns (bool) { - return _allowedSenders[sender]; + emit TreasuriesUpdated(msg.sender, treasuriesInfo); } // Calculate amount of money based on treasury's ratio function _computePercentage(uint256 value, uint256 percentage) internal pure virtual returns (uint256) { return Math.mulDiv(value, percentage, MAX_PERCENTAGE); } + + function _fallback() internal { + if (hasRole(SENDER_ROLE, msg.sender)) { + _allocateCommissionAndTransferToTreasury(msg.value); + } + } } diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index c4db5c98..9597f4c7 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -14,9 +14,11 @@ interface INSCommission { } /// @dev Emitted when all the treasury info info are updated. - event TreasuriesUpdated(Commission[] treasuriesInfo); + event TreasuriesUpdated(address indexed updatedBy, Commission[] treasuriesInfo); /// @dev Emitted when specific treasury info are updated. - event TreasuryInfoUpdated(address payable treasuryAddr, bytes name, uint256 treasuryId); + event TreasuryInfoUpdated( + address indexed updatedBy, address payable treasuryAddr, bytes name, uint256 indexed treasuryId + ); /// @dev Revert when index is out of range error InvalidArrayLength(); @@ -26,9 +28,9 @@ interface INSCommission { error InvalidAmountOfRON(); /** - * @dev Returns all treasury. + * @dev Returns comissions information. */ - function getTreasuries() external view returns (Commission[] memory treasuriesInfo); + function getCommissions() external view returns (Commission[] memory treasuriesInfo); /** * @dev Sets all treasuries information @@ -47,13 +49,5 @@ interface INSCommission { * - The method caller is setter role. * Emits the event `TreasuryInfoUpdated`. */ - function changeTreasuryInfo(address payable newAddr, bytes calldata name, uint256 treasuryId) external; - - /** - * @dev Allows specific `sender` to send money to this contract, which will then be transferred to the treasuries. - * - * Requirements: - * - The method caller is setter role. - */ - function allowSender(address sender) external; + function setTreasuryInfo(uint256 treasuryId, address payable newAddr, bytes calldata name) external; } From 11d2edfe3fcff0cf638224c6d5803cf3e40c55e4 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Tue, 4 Jun 2024 17:45:19 +0700 Subject: [PATCH 06/12] fix RNSCommission --- src/RNSCommission.sol | 8 ++++---- src/interfaces/INSCommission.sol | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index d485f225..16737ba7 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -65,7 +65,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } /// @inheritdoc INSCommission - function setTreasuryInfo(uint256 treasuryId, address payable newAddr, bytes calldata name) + function setTreasuryInfo(uint256 treasuryId, address payable newAddr, string calldata name) external onlyRole(COMMISSION_SETTER_ROLE) { @@ -113,7 +113,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission INSCommission.Allocation[] memory allocs = _calcAllocations(ronAmount); uint256 length = allocs.length; - for (uint256 i = 0; i < length; ++i) { + for (uint256 i; i < length; ++i) { uint256 value = allocs[i].value; address payable recipient = allocs[i].recipient; @@ -124,13 +124,13 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission function _setTreasuries(Commission[] calldata treasuriesInfo) internal { uint256 length = treasuriesInfo.length; // treasuriesInfo[] can not be empty - if (length < 1) revert InvalidArrayLength(); + if (length == 0) revert InvalidArrayLength(); delete _commissionInfos; uint256 sum; - for (uint256 i = 0; i < length; ++i) { + for (uint256 i; i < length; ++i) { sum += treasuriesInfo[i].ratio; _commissionInfos.push(treasuriesInfo[i]); } diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index 9597f4c7..a06caf01 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -5,7 +5,7 @@ interface INSCommission { struct Commission { address payable recipient; uint256 ratio; // Values [0; 100_00] reflexes [0; 100%] - bytes name; // Treasury's name + string name; // Treasury's name } struct Allocation { @@ -17,7 +17,7 @@ interface INSCommission { event TreasuriesUpdated(address indexed updatedBy, Commission[] treasuriesInfo); /// @dev Emitted when specific treasury info are updated. event TreasuryInfoUpdated( - address indexed updatedBy, address payable treasuryAddr, bytes name, uint256 indexed treasuryId + address indexed updatedBy, address payable treasuryAddr, string name, uint256 indexed treasuryId ); /// @dev Revert when index is out of range @@ -49,5 +49,5 @@ interface INSCommission { * - The method caller is setter role. * Emits the event `TreasuryInfoUpdated`. */ - function setTreasuryInfo(uint256 treasuryId, address payable newAddr, bytes calldata name) external; + function setTreasuryInfo(uint256 treasuryId, address payable newAddr, string calldata name) external; } From 9394b468dd1c0f00a90944f10ba98f5829065037 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Wed, 5 Jun 2024 12:18:02 +0700 Subject: [PATCH 07/12] fix(RNSCommission): rm fallback() --- src/RNSCommission.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index 16737ba7..80cf431c 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -28,10 +28,6 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission _fallback(); } - fallback() external payable { - _fallback(); - } - function initialize( address admin, address[] calldata commissionSetters, From d097c49cc75f9a3b72693f2c66a09133e715b781 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Wed, 5 Jun 2024 14:10:58 +0700 Subject: [PATCH 08/12] fix(RNSCommission): fix naming --- src/RNSCommission.sol | 40 ++++++++++++++++---------------- src/interfaces/INSCommission.sol | 26 ++++++++++----------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index 80cf431c..11ba116d 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -31,7 +31,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission function initialize( address admin, address[] calldata commissionSetters, - Commission[] calldata treasuryCommission, + Commission[] calldata commissionInfos, address[] calldata allowedSenders ) external initializer { _setupRole(DEFAULT_ADMIN_ROLE, admin); @@ -47,31 +47,31 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } _setRoleAdmin(SENDER_ROLE, COMMISSION_SETTER_ROLE); - _setTreasuries(treasuryCommission); + _setCommissions(commissionInfos); } /// @inheritdoc INSCommission - function getCommissions() external view returns (Commission[] memory treasuriesInfo) { + function getCommissions() external view returns (Commission[] memory commissionInfos) { return _commissionInfos; } /// @inheritdoc INSCommission - function setTreasuries(Commission[] calldata treasuriesInfo) external onlyRole(COMMISSION_SETTER_ROLE) { - _setTreasuries(treasuriesInfo); + function setCommissions(Commission[] calldata commissionInfos) external onlyRole(COMMISSION_SETTER_ROLE) { + _setCommissions(commissionInfos); } /// @inheritdoc INSCommission - function setTreasuryInfo(uint256 treasuryId, address payable newAddr, string calldata name) + function setCommissionInfo(uint256 commissionIdx, address payable newRecipient, string calldata name) external onlyRole(COMMISSION_SETTER_ROLE) { - if (treasuryId > _commissionInfos.length - 1) { + if (commissionIdx > _commissionInfos.length - 1) { revert InvalidArrayLength(); } - _commissionInfos[treasuryId].recipient = newAddr; - _commissionInfos[treasuryId].name = name; - emit TreasuryInfoUpdated(msg.sender, newAddr, name, treasuryId); + _commissionInfos[commissionIdx].recipient = newRecipient; + _commissionInfos[commissionIdx].name = name; + emit CommissionInfoUpdated(msg.sender, newRecipient, name, commissionIdx); } /** @@ -103,9 +103,9 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } /** - * @dev Helper method to allocate commission and take fee into treasuries address. + * @dev Helper method to allocate commission and take fee into recipient address. */ - function _allocateCommissionAndTransferToTreasury(uint256 ronAmount) internal { + function _allocateCommissionAndTransferToRecipient(uint256 ronAmount) internal { INSCommission.Allocation[] memory allocs = _calcAllocations(ronAmount); uint256 length = allocs.length; @@ -117,9 +117,9 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } } - function _setTreasuries(Commission[] calldata treasuriesInfo) internal { - uint256 length = treasuriesInfo.length; - // treasuriesInfo[] can not be empty + function _setCommissions(Commission[] calldata commissionInfos) internal { + uint256 length = commissionInfos.length; + // commissionInfos[] can not be empty if (length == 0) revert InvalidArrayLength(); delete _commissionInfos; @@ -127,23 +127,23 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission uint256 sum; for (uint256 i; i < length; ++i) { - sum += treasuriesInfo[i].ratio; - _commissionInfos.push(treasuriesInfo[i]); + sum += commissionInfos[i].ratio; + _commissionInfos.push(commissionInfos[i]); } if (sum != MAX_PERCENTAGE) revert InvalidRatio(); - emit TreasuriesUpdated(msg.sender, treasuriesInfo); + emit CommissionsUpdated(msg.sender, commissionInfos); } - // Calculate amount of money based on treasury's ratio + // Calculate amount of money based on commission's ratio function _computePercentage(uint256 value, uint256 percentage) internal pure virtual returns (uint256) { return Math.mulDiv(value, percentage, MAX_PERCENTAGE); } function _fallback() internal { if (hasRole(SENDER_ROLE, msg.sender)) { - _allocateCommissionAndTransferToTreasury(msg.value); + _allocateCommissionAndTransferToRecipient(msg.value); } } } diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index a06caf01..8486171c 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -5,7 +5,7 @@ interface INSCommission { struct Commission { address payable recipient; uint256 ratio; // Values [0; 100_00] reflexes [0; 100%] - string name; // Treasury's name + string name; // Commission's name } struct Allocation { @@ -13,11 +13,11 @@ interface INSCommission { uint256 value; } - /// @dev Emitted when all the treasury info info are updated. - event TreasuriesUpdated(address indexed updatedBy, Commission[] treasuriesInfo); - /// @dev Emitted when specific treasury info are updated. - event TreasuryInfoUpdated( - address indexed updatedBy, address payable treasuryAddr, string name, uint256 indexed treasuryId + /// @dev Emitted when all the commission info is updated. + event CommissionsUpdated(address indexed updatedBy, Commission[] commissionInfo); + /// @dev Emitted when specific commission info is updated. + event CommissionInfoUpdated( + address indexed updatedBy, address payable newRecipient, string name, uint256 indexed commissionIdx ); /// @dev Revert when index is out of range @@ -30,24 +30,24 @@ interface INSCommission { /** * @dev Returns comissions information. */ - function getCommissions() external view returns (Commission[] memory treasuriesInfo); + function getCommissions() external view returns (Commission[] memory commissionInfos); /** - * @dev Sets all treasuries information + * @dev Sets all commission information * * Requirements: * - The method caller is setter role. * - The total ratio must be equal to 100%. - * Emits the event `TreasuriesUpdated`. + * Emits the event `CommissionsUpdated`. */ - function setTreasuries(Commission[] calldata treasuriesInfo) external; + function setCommissions(Commission[] calldata commissionInfos) external; /** - * @dev Sets for specific treasury information based on the treasury `id`. + * @dev Sets for specific commission information based on the `commissionIdx`. * * Requirements: * - The method caller is setter role. - * Emits the event `TreasuryInfoUpdated`. + * Emits the event `CommissionInfoUpdated`. */ - function setTreasuryInfo(uint256 treasuryId, address payable newAddr, string calldata name) external; + function setCommissionInfo(uint256 commissionIdx, address payable newAddr, string calldata name) external; } From b70610267684488aaf6248ccb7b0eee76a67dda0 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Wed, 5 Jun 2024 14:15:22 +0700 Subject: [PATCH 09/12] fix(RNSCommission): fix naming --- src/interfaces/INSCommission.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index 8486171c..02c874a2 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -14,7 +14,7 @@ interface INSCommission { } /// @dev Emitted when all the commission info is updated. - event CommissionsUpdated(address indexed updatedBy, Commission[] commissionInfo); + event CommissionsUpdated(address indexed updatedBy, Commission[] commissionInfos); /// @dev Emitted when specific commission info is updated. event CommissionInfoUpdated( address indexed updatedBy, address payable newRecipient, string name, uint256 indexed commissionIdx From cad6124a7990398ae736a45ba5e109fcc49b97f6 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Thu, 6 Jun 2024 09:10:26 +0700 Subject: [PATCH 10/12] fix(RNSCommission): fix naming --- src/RNSCommission.sol | 9 ++++----- src/interfaces/INSCommission.sol | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index 11ba116d..8e29dc92 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.19; import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; import { INSCommission } from "./interfaces/INSCommission.sol"; -import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { RONTransferHelper } from "./libraries/transfers/RONTransferHelper.sol"; contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission { @@ -61,7 +60,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } /// @inheritdoc INSCommission - function setCommissionInfo(uint256 commissionIdx, address payable newRecipient, string calldata name) + function setCommissionInfo(uint256 commissionIdx, address payable newRecipient, string calldata newName) external onlyRole(COMMISSION_SETTER_ROLE) { @@ -70,8 +69,8 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } _commissionInfos[commissionIdx].recipient = newRecipient; - _commissionInfos[commissionIdx].name = name; - emit CommissionInfoUpdated(msg.sender, newRecipient, name, commissionIdx); + _commissionInfos[commissionIdx].name = newName; + emit CommissionInfoUpdated(msg.sender, commissionIdx, newRecipient, newName); } /** @@ -138,7 +137,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission // Calculate amount of money based on commission's ratio function _computePercentage(uint256 value, uint256 percentage) internal pure virtual returns (uint256) { - return Math.mulDiv(value, percentage, MAX_PERCENTAGE); + return (value * percentage) / MAX_PERCENTAGE; } function _fallback() internal { diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index 02c874a2..d40e6a76 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -17,7 +17,7 @@ interface INSCommission { event CommissionsUpdated(address indexed updatedBy, Commission[] commissionInfos); /// @dev Emitted when specific commission info is updated. event CommissionInfoUpdated( - address indexed updatedBy, address payable newRecipient, string name, uint256 indexed commissionIdx + address indexed updatedBy, uint256 indexed commissionIdx, address payable newRecipient, string newName ); /// @dev Revert when index is out of range From e2d4138c31db4136c6df5f7afb95d00baafce36c Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Thu, 6 Jun 2024 14:22:31 +0700 Subject: [PATCH 11/12] fix(RNSCommission) --- src/RNSCommission.sol | 72 ++++++++++---------------------- src/interfaces/INSCommission.sol | 17 +++++--- 2 files changed, 34 insertions(+), 55 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index 8e29dc92..f1decb7e 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -9,14 +9,12 @@ import { RONTransferHelper } from "./libraries/transfers/RONTransferHelper.sol"; contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission { /// @dev Constant representing the maximum percentage value (100%). uint256 public constant MAX_PERCENTAGE = 100_00; - /// @dev Role for accounts that can set commissions infomation and grant or revoke `SENDER_ROLE`. - bytes32 public constant COMMISSION_SETTER_ROLE = keccak256("COMMISSION_SETTER_ROLE"); /// @dev Role for accounts that can send RON for this contract. bytes32 public constant SENDER_ROLE = keccak256("SENDER_ROLE"); /// @dev Gap for upgradability. uint256[50] private ____gap; - + /// @dev Array of `Commission` structs that store commissions infomation. Commission[] internal _commissionInfos; constructor() { @@ -27,25 +25,17 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission _fallback(); } - function initialize( - address admin, - address[] calldata commissionSetters, - Commission[] calldata commissionInfos, - address[] calldata allowedSenders - ) external initializer { + function initialize(address admin, Commission[] calldata commissionInfos, address[] calldata allowedSenders) + external + initializer + { _setupRole(DEFAULT_ADMIN_ROLE, admin); - uint256 length = commissionSetters.length; + uint256 length = allowedSenders.length; for (uint256 i; i < length; ++i) { - _setupRole(COMMISSION_SETTER_ROLE, commissionSetters[i]); - } - - uint256 sendersLength = allowedSenders.length; - for (uint256 i; i < sendersLength; ++i) { _setupRole(SENDER_ROLE, allowedSenders[i]); } - _setRoleAdmin(SENDER_ROLE, COMMISSION_SETTER_ROLE); _setCommissions(commissionInfos); } @@ -55,18 +45,16 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } /// @inheritdoc INSCommission - function setCommissions(Commission[] calldata commissionInfos) external onlyRole(COMMISSION_SETTER_ROLE) { + function setCommissions(Commission[] calldata commissionInfos) external onlyRole(DEFAULT_ADMIN_ROLE) { _setCommissions(commissionInfos); } /// @inheritdoc INSCommission function setCommissionInfo(uint256 commissionIdx, address payable newRecipient, string calldata newName) external - onlyRole(COMMISSION_SETTER_ROLE) + onlyRole(DEFAULT_ADMIN_ROLE) { - if (commissionIdx > _commissionInfos.length - 1) { - revert InvalidArrayLength(); - } + if (commissionIdx >= _commissionInfos.length) revert InvalidArrayLength(); _commissionInfos[commissionIdx].recipient = newRecipient; _commissionInfos[commissionIdx].name = newName; @@ -74,45 +62,29 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission } /** - * @dev Helper method to calculate allocations. + * @dev Helper method to allocate commission and take fee into recipient address. */ - function _calcAllocations(uint256 totalAmount) internal view returns (Allocation[] memory allocs) { - if (totalAmount == 0) { - revert InvalidAmountOfRON(); - } - uint256 length = _commissionInfos.length; + function _allocateCommissionAndTransferToRecipient(uint256 ronAmount) internal { + if (ronAmount == 0) revert InvalidAmountOfRON(); - allocs = new Allocation[](length); + uint256 length = _commissionInfos.length; + if (length == 0) revert InvalidArrayLength(); uint256 lastIdx = length - 1; uint256 sumValue; for (uint256 i; i < lastIdx; ++i) { - allocs[i] = Allocation({ - recipient: _commissionInfos[i].recipient, - value: _computePercentage(totalAmount, _commissionInfos[i].ratio) - }); - sumValue += allocs[i].value; - } + uint256 commissionAmount = _computePercentage(ronAmount, _commissionInfos[i].ratio); + sumValue += commissionAmount; - // This code replaces value of the last recipient. - if (sumValue < totalAmount) { - allocs[lastIdx] = Allocation({ recipient: _commissionInfos[lastIdx].recipient, value: totalAmount - sumValue }); + RONTransferHelper.safeTransfer(_commissionInfos[i].recipient, commissionAmount); + emit Transfer(_commissionInfos[i].recipient, commissionAmount); } - } - - /** - * @dev Helper method to allocate commission and take fee into recipient address. - */ - function _allocateCommissionAndTransferToRecipient(uint256 ronAmount) internal { - INSCommission.Allocation[] memory allocs = _calcAllocations(ronAmount); - uint256 length = allocs.length; - - for (uint256 i; i < length; ++i) { - uint256 value = allocs[i].value; - address payable recipient = allocs[i].recipient; - RONTransferHelper.safeTransfer(recipient, value); + // This code send the remaining RON to the last recipient. + if (sumValue < ronAmount) { + RONTransferHelper.safeTransfer(_commissionInfos[lastIdx].recipient, ronAmount - sumValue); + emit Transfer(_commissionInfos[lastIdx].recipient, ronAmount - sumValue); } } diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index d40e6a76..84b677ed 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -8,17 +8,14 @@ interface INSCommission { string name; // Commission's name } - struct Allocation { - address payable recipient; - uint256 value; - } - /// @dev Emitted when all the commission info is updated. event CommissionsUpdated(address indexed updatedBy, Commission[] commissionInfos); /// @dev Emitted when specific commission info is updated. event CommissionInfoUpdated( address indexed updatedBy, uint256 indexed commissionIdx, address payable newRecipient, string newName ); + /// @dev Emiited when transfer RON to commission's recipient. + event Transfer(address indexed recipient, uint256 commissionAmount); /// @dev Revert when index is out of range error InvalidArrayLength(); @@ -27,6 +24,16 @@ interface INSCommission { /// @dev Revert when amount of RON is invalid error InvalidAmountOfRON(); + /** + * @dev Maximum commission percentage. + */ + function MAX_PERCENTAGE() external pure returns (uint256); + + /** + * @dev Returns the sender role. + */ + function SENDER_ROLE() external pure returns (bytes32); + /** * @dev Returns comissions information. */ From b71cceb9a3861c3aa8f05b23390dcaae8bb8df1f Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Thu, 6 Jun 2024 16:30:27 +0700 Subject: [PATCH 12/12] fix(RNSCommission): fix naming --- src/RNSCommission.sol | 4 ++-- src/interfaces/INSCommission.sol | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RNSCommission.sol b/src/RNSCommission.sol index f1decb7e..a2382d99 100644 --- a/src/RNSCommission.sol +++ b/src/RNSCommission.sol @@ -78,13 +78,13 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission sumValue += commissionAmount; RONTransferHelper.safeTransfer(_commissionInfos[i].recipient, commissionAmount); - emit Transfer(_commissionInfos[i].recipient, commissionAmount); + emit Distributed(_commissionInfos[i].recipient, commissionAmount); } // This code send the remaining RON to the last recipient. if (sumValue < ronAmount) { RONTransferHelper.safeTransfer(_commissionInfos[lastIdx].recipient, ronAmount - sumValue); - emit Transfer(_commissionInfos[lastIdx].recipient, ronAmount - sumValue); + emit Distributed(_commissionInfos[lastIdx].recipient, ronAmount - sumValue); } } diff --git a/src/interfaces/INSCommission.sol b/src/interfaces/INSCommission.sol index 84b677ed..b52645c0 100644 --- a/src/interfaces/INSCommission.sol +++ b/src/interfaces/INSCommission.sol @@ -15,7 +15,7 @@ interface INSCommission { address indexed updatedBy, uint256 indexed commissionIdx, address payable newRecipient, string newName ); /// @dev Emiited when transfer RON to commission's recipient. - event Transfer(address indexed recipient, uint256 commissionAmount); + event Distributed(address indexed recipient, uint256 commissionAmount); /// @dev Revert when index is out of range error InvalidArrayLength();