Skip to content

Commit

Permalink
script: minor script fix and add rns operation deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Feb 21, 2024
1 parent 2b934a1 commit 0bb6c62
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.19;

import { IMulticall3 } from "forge-std/interfaces/IMulticall3.sol";
import { LibString } from "solady/utils/LibString.sol";
import { DefaultNetwork } from "foundry-deployment-kit/utils/DefaultNetwork.sol";
import { DefaultContract } from "foundry-deployment-kit/utils/DefaultContract.sol";
import { Contract } from "../utils/Contract.sol";
import { INSDomainPrice, RNSDomainPrice } from "@rns-contracts/RNSDomainPrice.sol";
Expand All @@ -18,14 +19,54 @@ contract Migration__01_UpgradeRNSDomainPriceAndOverrideTierForCommunityNames_RNS
function run() external {
_domainPrice = RNSDomainPrice(_upgradeProxy(Contract.RNSDomainPrice.key()));
_multicall = IMulticall3(loadContract(DefaultContract.Multicall3.key()));

_lbHashes = toLabelHashes(_labels);

vm.broadcast(_domainPrice.getRoleMember(_domainPrice.OVERRIDER_ROLE(), 0));
_domainPrice.bulkOverrideTiers(_lbHashes, _tiers);
uint256 batchSize = 100;
uint256 totalElements = _lbHashes.length;
uint256 totalBatches = (totalElements + batchSize - 1) / batchSize;

address overrider = _domainPrice.getRoleMember(_domainPrice.OVERRIDER_ROLE(), 0);

for (uint256 i; i < totalBatches; i++) {
console.log("Processing batch", i, "of", totalBatches);
uint256 start = i * batchSize;
uint256 end = (i + 1) * batchSize;
if (end > totalElements) {
end = totalElements;
}

bytes32[] memory batchHashes = new bytes32[](end - start);
uint256[] memory batchTiers = new uint256[](end - start);

for (uint256 j = start; j < end; j++) {
batchHashes[j - start] = _lbHashes[j];
batchTiers[j - start] = _tiers[j];
}

vm.broadcast(overrider);
_domainPrice.bulkOverrideTiers(batchHashes, batchTiers);
}
}

function _postCheck() internal override logFn("_postChecking ...") {
_validateOverridenTiers();
_validateOtherDomainTiers();
}

function _validateOtherDomainTiers() internal logFn("_validating other domain tiers ...") {
if (network() == DefaultNetwork.RoninMainnet.key()) {
assertEq(_domainPrice.getTier("tudo"), 2, "invalid tier for tudo");
assertEq(_domainPrice.getTier("duke"), 2, "invalid tier for duke");
assertEq(_domainPrice.getTier("ace"), 1, "invalid tier for ace");
assertEq(_domainPrice.getTier("dragon"), 2, "invalid tier for dragon");
assertEq(_domainPrice.getTier("tokuda"), 3, "invalid tier for tokuda");
assertEq(_domainPrice.getTier("metaverse"), 2, "invalid tier for metaverse");
assertEq(_domainPrice.getTier("nuke"), 2, "invalid tier for nuke");
assertEq(_domainPrice.getTier("merchandising"), 3, "invalid tier for merchandising");
}
}

function _validateOverridenTiers() internal logFn("_validating overriden tiers ...") {
IMulticall3.Call[] memory calls = new IMulticall3.Call[](_lbHashes.length);

for (uint256 i; i < _lbHashes.length; ++i) {
Expand All @@ -40,7 +81,6 @@ contract Migration__01_UpgradeRNSDomainPriceAndOverrideTierForCommunityNames_RNS

for (uint256 i; i < _lbHashes.length; ++i) {
tiers[i] = abi.decode(returnData[i], (uint256));
console.log("label:", _labels[i], "tier:", tiers[i]);
assertEq(tiers[i], _tiers[i], string.concat("tier not set", vm.toString(i)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,36 @@ contract Migration__02_ResetCommunityNamesRenewalFees_RNSDomainPrice is Migratio

_lbHashes = toLabelHashes(_labels);

uint256[] memory renewalFees = new uint256[](_lbHashes.length);

address overrider = rnsDomainPrice.getRoleMember(rnsDomainPrice.OVERRIDER_ROLE(), 0);
vm.startBroadcast(overrider);
rnsDomainPrice.bulkOverrideRenewalFees(_lbHashes, renewalFees);

vm.stopBroadcast();
uint256 batchSize = 100;
uint256 totalBatches = (_lbHashes.length + batchSize - 1) / batchSize;

for (uint256 batchIndex = 0; batchIndex < totalBatches; batchIndex++) {
uint256 startIndex = batchIndex * batchSize;
uint256 endIndex = startIndex + batchSize;
if (endIndex > _lbHashes.length) {
endIndex = _lbHashes.length;
}

bytes32[] memory batchLbHashes = new bytes32[](endIndex - startIndex);
uint256[] memory batchRenewalFees = new uint256[](endIndex - startIndex);

for (uint256 i = startIndex; i < endIndex; i++) {
batchLbHashes[i - startIndex] = _lbHashes[i];
batchRenewalFees[i - startIndex] = type(uint256).max;
}

vm.broadcast(overrider);
rnsDomainPrice.bulkOverrideRenewalFees(batchLbHashes, batchRenewalFees);
}
}

function _postCheck() internal override logFn("_postChecking ...") {
RNSDomainPrice rnsDomainPrice = RNSDomainPrice(loadContract(Contract.RNSDomainPrice.key()));

for (uint256 i; i < _lbHashes.length; ++i) {
(INSDomainPrice.UnitPrice memory renewalFee,) = rnsDomainPrice.getRenewalFee(_labels[i], 1);
assertEq(renewalFee.usd, 0, "renewal fee not reset");
assertEq(renewalFee.ron, 0, "renewal fee not reset");
vm.expectRevert(INSDomainPrice.RenewalFeeIsNotOverriden.selector);
uint256 overridenRenewalFee = rnsDomainPrice.getOverriddenRenewalFee(_labels[i]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { console2 as console } from "forge-std/console2.sol";
import { Contract } from "script/utils/Contract.sol";
import { Migration } from "script/Migration.s.sol";
import { RNSUnified } from "@rns-contracts/RNSUnified.sol";
import { RNSDomainPrice } from "@rns-contracts/RNSDomainPrice.sol";
import { INSAuction, RNSAuction } from "@rns-contracts/RNSAuction.sol";
import { LibRNSDomain } from "@rns-contracts/libraries/LibRNSDomain.sol";
import { RNSOperation, RNSOperationDeploy } from "script/contracts/RNSOperationDeploy.s.sol";

contract Migration_03_DeployNewRNSOperation_OverrideTierForAuctionNames_RNSOperation is Migration {
using LibRNSDomain for string;

RNSUnified private rns;
RNSAuction private auction;
RNSOperation private rnsOperation;
RNSDomainPrice private domainPrice;

function run() public {
rnsOperation = new RNSOperationDeploy().run();

domainPrice = RNSDomainPrice(loadContract(Contract.RNSDomainPrice.key()));
rns = RNSUnified(loadContract(Contract.RNSUnified.key()));
auction = RNSAuction(loadContract(Contract.RNSAuction.key()));

address admin = rns.ownerOf(LibRNSDomain.RON_ID);

vm.broadcast(rnsOperation.owner());
rnsOperation.transferOwnership(admin);

vm.startBroadcast(admin);

rns.setApprovalForAll(address(rnsOperation), true);
auction.grantRole(auction.OPERATOR_ROLE(), address(rnsOperation));
rns.grantRole(rns.PROTECTED_SETTLER_ROLE(), address(rnsOperation));
domainPrice.grantRole(domainPrice.OVERRIDER_ROLE(), address(rnsOperation));

vm.stopBroadcast();
}

function _postCheck() internal override {
_validateBulkMint();
_validateOverridenTiers();
_validateBulkSetProtected();
_validateBulkOverrideRenewalFees();
_validateReclaimAuctionNames({ searchSize: 20 });
}

function _validateOverridenTiers() internal logFn("_validateOverridenTiers") {
string[] memory labels = new string[](5);
labels[0] = "heidi";
labels[1] = "luke";
labels[2] = "sophia";
labels[3] = "chief";
labels[4] = "slim";

for (uint256 i; i < labels.length; ++i) {
assertEq(domainPrice.getTier(labels[i]), 1, string.concat("invalid tier for auction label ", labels[i]));
}
}

function _validateBulkOverrideRenewalFees() internal logFn("_validateBulkOverrideRenewalFees") {
string memory label = "tudo-provip-maximum-ultra";
string[] memory labels = new string[](1);
labels[0] = label;
uint256[] memory yearlyUSDPrices = new uint256[](1);
// 10 usd per year
yearlyUSDPrices[0] = 10;

vm.prank(rnsOperation.owner());
rnsOperation.bulkOverrideRenewalFees(labels, yearlyUSDPrices);

assertEq(domainPrice.getOverriddenRenewalFee(label), Math.mulDiv(yearlyUSDPrices[0], 1 ether, 365 days));
}

function _validateReclaimAuctionNames(uint256 searchSize) internal logFn("_validateReclaimAuctionNames") {
INSAuction.DomainAuction[] memory domainAuctions = new INSAuction.DomainAuction[](searchSize);
uint256[] memory reservedIds = new uint256[](searchSize);
for (uint256 i; i < searchSize; ++i) {
reservedIds[i] = rns.tokenOfOwnerByIndex(address(auction), i);
(domainAuctions[i],) = auction.getAuction(reservedIds[i]);
}

uint256 reclaimableAuctionNameId;
for (uint256 i; i < searchSize; ++i) {
if (domainAuctions[i].bid.bidder == address(0x0)) {
reclaimableAuctionNameId = reservedIds[i];
break;
}
}

address to = makeAddr("to");
address[] memory tos = new address[](1);
tos[0] = to;
string memory label = rns.getRecord(reclaimableAuctionNameId).immut.label;
console.log("reclaimable auction label", label);
string[] memory labels = new string[](1);
labels[0] = label;

vm.prank(rnsOperation.owner());
rnsOperation.reclaimUnbiddedNames({ tos: tos, labels: labels, allowFailure: false });
}

function _validateBulkMint() internal logFn("_validateBulkMint") {
address to = makeAddr("to");
address[] memory tos = new address[](1);
tos[0] = to;
string[] memory labels = new string[](1);
labels[0] = "tudo-provip-maximum-utra";
uint64 duration = uint64(3 days);

vm.prank(rnsOperation.owner());
rnsOperation.bulkMint(tos, labels, duration);

uint256 id = uint256(string.concat(labels[0], ".ron").namehash());
assertEq(rns.ownerOf(id), to);
}

function _validateBulkSetProtected() internal logFn("_validateBulkSetProtected") {
string[] memory labels = new string[](1);
labels[0] = "tudo-provip-maximum-utra";

bool shouldProtect = true;

vm.prank(rnsOperation.owner());
rnsOperation.bulkSetProtected(labels, shouldProtect);

uint256 id = uint256(string.concat(labels[0], ".ron").namehash());
assertTrue(rns.getRecord(id).mut.protected);

shouldProtect = false;

vm.prank(rnsOperation.owner());
rnsOperation.bulkSetProtected(labels, shouldProtect);

assertFalse(rns.getRecord(id).mut.protected);
}
}

0 comments on commit 0bb6c62

Please sign in to comment.