From d097c49cc75f9a3b72693f2c66a09133e715b781 Mon Sep 17 00:00:00 2001 From: tringuyenskymavis Date: Wed, 5 Jun 2024 14:10:58 +0700 Subject: [PATCH] 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 80cf431..11ba116 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 a06caf0..8486171 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; }