Skip to content

Commit

Permalink
fix(RNSCommission): fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
tringuyenskymavis committed Jun 5, 2024
1 parent 9394b46 commit d097c49
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
40 changes: 20 additions & 20 deletions src/RNSCommission.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;

Expand All @@ -117,33 +117,33 @@ 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;

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);
}
}
}
26 changes: 13 additions & 13 deletions src/interfaces/INSCommission.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ 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 {
address payable recipient;
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
Expand All @@ -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;
}

0 comments on commit d097c49

Please sign in to comment.