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): allow send 0 #286

Open
wants to merge 9 commits into
base: feature/bulk-renew
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { RNSAuction, RNSAuctionDeploy } from "script/contracts/RNSAuctionDeploy.s.sol";
import {
RONRegistrarController, RONRegistrarControllerDeploy
} from "script/contracts/RONRegistrarControllerDeploy.s.sol";
import { Contract } from "script/utils/Contract.sol";
import { RNSCommission, RNSCommissionDeploy } from "script/contracts/RNSCommissionDeploy.s.sol";
import { Migration } from "script/Migration.s.sol";

contract Migration__20241105_UpgradeRNSCommissionMainnet is Migration {
RONRegistrarController private _controller;
RNSCommission private _rnsCommission;
RNSAuction _auction;

function run() public {
_auction = RNSAuction(loadContract(Contract.RNSAuction.key()));
_controller = RONRegistrarController(loadContract(Contract.RONRegistrarController.key()));
_rnsCommission = RNSCommission(_upgradeProxy(Contract.RNSCommission.key()));
}

function _postCheck() internal override {
_validateCommissionInfo();
_validateSendersAddress();
_validateSendMoneyFromSenders_NonZeroRonAmount();
_validateSendMoneyFromSenders_ZeroRonAmount();
}

function _validateCommissionInfo() internal logFn("_validateSetCommissionInfo") {
assertEq(_rnsCommission.getCommissions().length, 2);

assertEq(_rnsCommission.getCommissions()[0].recipient, payable(0xFf43f5Ef28EcB7c1f219751fc793deB40ef07A53));
assertEq(_rnsCommission.getCommissions()[1].recipient, payable(0x22cEfc91E9b7c0f3890eBf9527EA89053490694e));

assertEq(_rnsCommission.getCommissions()[0].ratio, 70_00);
assertEq(_rnsCommission.getCommissions()[1].ratio, 30_00);

assertEq(_rnsCommission.getCommissions()[0].name, "Sky Mavis");
assertEq(_rnsCommission.getCommissions()[1].name, "Ronin");
}

function _validateSendMoneyFromSenders_NonZeroRonAmount()
internal
logFn("_validateSendMoneyFromSenders_NonZeroRonAmount")
{
bool sent;
vm.deal(address(_auction), 100 ether);
vm.prank(address(_auction));
(sent,) = address(_rnsCommission).call{ value: 100 ether }("");
assertTrue(sent);

vm.deal(address(_controller), 100 ether);
vm.prank(address(_controller));
(sent,) = address(_rnsCommission).call{ value: 100 ether }("");
assertTrue(sent);

assertEq(address(_rnsCommission).balance, 0 ether);

address randomAddr = makeAddr("random address");
vm.deal(address(randomAddr), 100 ether);
vm.prank(randomAddr);
(sent,) = address(_rnsCommission).call{ value: 100 ether }("");
assertTrue(sent);

assertEq(address(_rnsCommission).balance, 100 ether);
}

function _validateSendMoneyFromSenders_ZeroRonAmount() internal logFn("_validateSendMoneyFromSenders_ZeroRonAmount") {
bool sent;
uint256 balanceBefore = address(_rnsCommission).balance;

vm.prank(address(_auction));
(sent,) = address(_rnsCommission).call{ value: 0 }("");
assertTrue(sent);

vm.prank(address(_controller));
(sent,) = address(_rnsCommission).call{ value: 0 }("");
assertTrue(sent);

assertEq(address(_rnsCommission).balance, balanceBefore);
}

function _validateSendersAddress() internal logFn("_validateSendersAddress") {
bytes32 SENDER_ROLE = keccak256("SENDER_ROLE");

require(_rnsCommission.hasRole(SENDER_ROLE, address(_auction)));
require(_rnsCommission.hasRole(SENDER_ROLE, address(_controller)));
}
}
2 changes: 1 addition & 1 deletion src/RNSCommission.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract RNSCommission is Initializable, AccessControlEnumerable, INSCommission
* @dev Helper method to allocate commission and take fee into recipient address.
*/
function _allocateCommissionAndTransferToRecipient(uint256 ronAmount) internal {
if (ronAmount == 0) revert InvalidAmountOfRON();
if (ronAmount == 0) return;

uint256 length = _commissionInfos.length;
if (length == 0) revert InvalidArrayLength();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ contract RNSCommisson__allocateCommissionAndTransferToRecipient_Test is RNSCommi
assertEq(random.balance, 0);
}

function test_RevertWhen_RonAmount_is_zero() external {
function testConcrete_Success_When_RonAmount_is_zero() external {
vm.deal(_senders[0], 1e18);

bool sent;
vm.expectRevert(INSCommission.InvalidAmountOfRON.selector);
vm.prank(_senders[0]);
(sent,) = address(_rnsCommission).call{ value: 0 }(new bytes(0));
tringuyenskymavis marked this conversation as resolved.
Show resolved Hide resolved

assertTrue(sent);
assertEq(_skyMavisTreasuryAddr.balance, 0);
assertEq(_roninNetworkTreasuryAddr.balance, 0);
assertEq(address(_rnsCommission).balance, 0);
assertEq(_senders[0].balance, 1e18);
}
}
Loading