Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RNSCommission): fix typo and revert if commission recipient is null #248

Merged
merged 11 commits into from
Jun 25, 2024
Merged
8 changes: 6 additions & 2 deletions src/RNSCommission.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission
/// @dev Role for accounts that can send RON for this contract.
bytes32 public constant SENDER_ROLE = keccak256("SENDER_ROLE");

/// @dev Gap for upgradability.
/// @dev Gap for upgradeability.
uint256[50] private ____gap;
/// @dev Array of `Commission` structs that store commissions infomation.
/// @dev Array of `Commission` structs that store commissions information.
Commission[] internal _commissionInfos;

constructor() {
Expand Down Expand Up @@ -55,6 +55,8 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission
onlyRole(DEFAULT_ADMIN_ROLE)
{
if (commissionIdx >= _commissionInfos.length) revert InvalidArrayLength();
// TODO: should fix to not duplicate logic in set commision info
if (newRecipient == address(0)) revert NullAddress();

_commissionInfos[commissionIdx].recipient = newRecipient;
_commissionInfos[commissionIdx].name = newName;
Expand Down Expand Up @@ -98,6 +100,8 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission
uint256 sum;

for (uint256 i; i < length; ++i) {
if (commissionInfos[i].recipient == address(0)) revert NullAddress();

sum += commissionInfos[i].ratio;
_commissionInfos.push(commissionInfos[i]);
}
Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/INSCommission.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface INSCommission {
event CommissionInfoUpdated(
address indexed updatedBy, uint256 indexed commissionIdx, address payable newRecipient, string newName
);
/// @dev Emiited when transfer RON to commission's recipient.
/// @dev Emitted when transfer RON to commission's recipient.
event Distributed(address indexed recipient, uint256 commissionAmount);

/// @dev Revert when index is out of range
Expand All @@ -23,6 +23,8 @@ interface INSCommission {
error InvalidRatio();
/// @dev Revert when amount of RON is invalid
error InvalidAmountOfRON();
/// @dev Revert when recipient address is null
error NullAddress();

/**
* @dev Maximum commission percentage.
Expand All @@ -35,7 +37,7 @@ interface INSCommission {
function SENDER_ROLE() external pure returns (bytes32);

/**
* @dev Returns comissions information.
* @dev Returns commissions information.
*/
function getCommissions() external view returns (Commission[] memory commissionInfos);

Expand Down
Loading