Skip to content

Commit

Permalink
feat(multi-treasury): implement add-null-address-error (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 authored Jun 25, 2024
2 parents 56bb9c2 + 255b5ba commit 3bd1dea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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

0 comments on commit 3bd1dea

Please sign in to comment.