Skip to content

Commit

Permalink
feat: migrate all migrations script to new foundry-deployment-kit ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
TuDo1403 committed Dec 18, 2023
1 parent 4154dcd commit 40d7d4a
Show file tree
Hide file tree
Showing 36 changed files with 512 additions and 468 deletions.
40 changes: 1 addition & 39 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
# Source (or "dot") the .env file to load environment variables
if [ -f .env ]; then
source .debug.env
else
echo "Error: .debug.env file not found."
fi

verify_arg=""
extra_argument=""
op_command=""

for arg in "$@"; do
case $arg in
--trezor)
op_command=""
extra_argument+=trezor@
;;
--broadcast)
op_command="op run --env-file="./.env" --"
;;
--log)
set -- "${@/#--log/}"
extra_argument+=log@
;;
*) ;;
esac
done

# Remove the @ character from the end of extra_argument
extra_argument="${extra_argument%%@}"

echo Debug Tx...
echo From: ${FROM}
echo To: ${TO}
echo Value: ${VALUE}
echo Calldata:
cast pretty-calldata ${CALLDATA}
calldata=$(cast calldata 'debug(uint256,address,address,uint256,bytes)' ${BLOCK} ${FROM} ${TO} ${VALUE} ${CALLDATA})
${op_command} forge script ${verify_arg} --legacy ${@} script/Debug.s.sol --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
source lib/foundry-deployment-kit/debug.sh
45 changes: 22 additions & 23 deletions script/20231015-deploy/20231015_Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { console2 } from "forge-std/console2.sol";
import { console2 as console } from "forge-std/console2.sol";
import { StdStyle } from "forge-std/StdStyle.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { LibRNSDomain } from "@rns-contracts/libraries/LibRNSDomain.sol";
import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { Contract } from "script/utils/Contract.sol";
import {
RONRegistrarController, RONRegistrarControllerDeploy
} from "script/contracts/RONRegistrarControllerDeploy.s.sol";
Expand All @@ -16,9 +16,10 @@ import { NameChecker, NameCheckerDeploy } from "script/contracts/NameCheckerDepl
import { RNSDomainPrice, RNSDomainPriceDeploy } from "script/contracts/RNSDomainPriceDeploy.s.sol";
import { PublicResolver, PublicResolverDeploy } from "script/contracts/PublicResolverDeploy.s.sol";
import { RNSReverseRegistrar, RNSReverseRegistrarDeploy } from "script/contracts/RNSReverseRegistrarDeploy.s.sol";
import { INSDomainPrice, RNSDeploy } from "../RNSDeploy.s.sol";
import { DefaultNetwork, Migration } from "../Migration.s.sol";
import { INSDomainPrice } from "script/interfaces/ISharedArgument.sol";

contract Migration__20231015_Deploy is RNSDeploy {
contract Migration__20231015_Deploy is Migration {
using Strings for *;
using LibRNSDomain for string;

Expand All @@ -32,7 +33,7 @@ contract Migration__20231015_Deploy is RNSDeploy {

string[] internal _blacklistedWords;

function run() public trySetUp {
function run() public onlyOn(DefaultNetwork.RoninTestnet.key()) {
_rns = new RNSUnifiedDeploy().run();
_auction = new RNSAuctionDeploy().run();
_nameChecker = new NameCheckerDeploy().run();
Expand All @@ -48,7 +49,6 @@ contract Migration__20231015_Deploy is RNSDeploy {
}
uint256[] memory packedWords = _nameChecker.packBulk(_blacklistedWords);

vm.resumeGasMetering();
vm.startBroadcast(admin);

_rns.grantRole(_rns.CONTROLLER_ROLE(), address(_auction));
Expand All @@ -67,7 +67,6 @@ contract Migration__20231015_Deploy is RNSDeploy {
_nameChecker.setForbiddenWords({ packedWords: packedWords, shouldForbid: true });

vm.stopBroadcast();
vm.pauseGasMetering();

_validateAuction();
_validateController();
Expand All @@ -76,7 +75,7 @@ contract Migration__20231015_Deploy is RNSDeploy {
_validateNameChecker();
_validateRNSUnified(ronId, addrReverseId);

console2.log(StdStyle.green(unicode"✅ All checks are passed"));
console.log(StdStyle.green(unicode"✅ All checks are passed"));
}

function _validateController() internal logFn("_validateController") {
Expand All @@ -90,7 +89,7 @@ contract Migration__20231015_Deploy is RNSDeploy {
_ronController.computeCommitment(domain, user.addr, duration, secret, address(_publicResolver), data, true);

(, uint256 ronPrice) = _ronController.rentPrice(domain, duration);
console2.log("domain price:", ronPrice);
console.log("domain price:", ronPrice);
vm.deal(user.addr, ronPrice);

vm.startPrank(user.addr);
Expand All @@ -103,7 +102,7 @@ contract Migration__20231015_Deploy is RNSDeploy {

uint256 expectedId = uint256(string.concat(domain, ".ron").namehash());
assertEq(_rns.ownerOf(expectedId), user.addr);
console2.log(unicode"✅ Controller checks are passed");
console.log(unicode"✅ Controller checks are passed");
}

function _validateRNSUnified(uint256 ronId, uint256 addrReverseId) internal logFn("validateRNSUnified") {
Expand All @@ -113,7 +112,7 @@ contract Migration__20231015_Deploy is RNSDeploy {
assertTrue(_rns.hasRole(_rns.RESERVATION_ROLE(), address(_auction)), "grant reservation role failed");
assertEq(address(_ronController.getPriceOracle()), address(_domainPrice), "set price oracle failed");

console2.log(unicode"✅ RNSUnified checks are passed");
console.log(unicode"✅ RNSUnified checks are passed");
}

function _validateReverseRegistrar() internal logFn("validateReverseRegistrar") {
Expand Down Expand Up @@ -146,7 +145,7 @@ contract Migration__20231015_Deploy is RNSDeploy {
assertTrue(_auction.reserved(id), "invalid bulkRegister");
assertEq(_rns.getRecord(id).mut.expiry, _rns.MAX_EXPIRY(), "invalid expiry time");

console2.log(unicode"✅ Auction checks are passed");
console.log(unicode"✅ Auction checks are passed");
}

function _validateDomainPrice() internal logFn("validateDomainPrice") {
Expand Down Expand Up @@ -191,12 +190,12 @@ contract Migration__20231015_Deploy is RNSDeploy {

vm.stopPrank();

console2.log("Tax Raio:", _domainPrice.getTaxRatio());
console2.log("Converting 1 USD (18 decimals) to RON:", _domainPrice.convertUSDToRON(1e18));
console2.log("Converting 1 RON to USD (18 decimals):", _domainPrice.convertRONToUSD(1 ether));
console2.log("Converting 1m USD (18 decimals) to RON:", _domainPrice.convertUSDToRON(1e18 * 1e6));
console2.log("Converting 1m RON to USD (18 decimals):", _domainPrice.convertRONToUSD(1 ether * 1e6));
console2.log(unicode"✅ Domain price checks are passed");
console.log("Tax Raio:", _domainPrice.getTaxRatio());
console.log("Converting 1 USD (18 decimals) to RON:", _domainPrice.convertUSDToRON(1e18));
console.log("Converting 1 RON to USD (18 decimals):", _domainPrice.convertRONToUSD(1 ether));
console.log("Converting 1m USD (18 decimals) to RON:", _domainPrice.convertUSDToRON(1e18 * 1e6));
console.log("Converting 1m RON to USD (18 decimals):", _domainPrice.convertRONToUSD(1 ether * 1e6));
console.log(unicode"✅ Domain price checks are passed");
}

function _validateNameChecker() internal logFn("validateNameChecker") {
Expand All @@ -208,9 +207,9 @@ contract Migration__20231015_Deploy is RNSDeploy {
uint256 expectedMax;
uint256 expectedMin = type(uint256).max;

console2.log(StdStyle.blue("Blacklisted words count"), blacklistedWords.length);
console2.log(StdStyle.blue("Word"), "RONRegistrarController::valid()", "NameChecker::forbidden()");
console2.log(StdStyle.blue("Word Range"), string.concat("min: ", min.toString(), " ", "max: ", max.toString()));
console.log(StdStyle.blue("Blacklisted words count"), blacklistedWords.length);
console.log(StdStyle.blue("Word"), "RONRegistrarController::valid()", "NameChecker::forbidden()");
console.log(StdStyle.blue("Word Range"), string.concat("min: ", min.toString(), " ", "max: ", max.toString()));

for (uint256 i; i < blacklistedWords.length;) {
word = blacklistedWords[i];
Expand All @@ -220,7 +219,7 @@ contract Migration__20231015_Deploy is RNSDeploy {
forbidden = _nameChecker.forbidden(word);

if (i % 50 == 0) {
console2.log(StdStyle.blue(word), valid ? unicode"" : unicode"", forbidden ? unicode"" : unicode"");
console.log(StdStyle.blue(word), valid ? unicode"" : unicode"", forbidden ? unicode"" : unicode"");
}

assertTrue(!valid);
Expand All @@ -234,6 +233,6 @@ contract Migration__20231015_Deploy is RNSDeploy {
assertEq(min, expectedMin);
assertEq(max, expectedMax);

console2.log(unicode"✅ NameChecker checks are passed");
console.log(unicode"✅ NameChecker checks are passed");
}
}
10 changes: 5 additions & 5 deletions script/20231020-rns-upgrade/20231020_RNSUpgrade.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";
import { Contract } from "script/utils/Contract.sol";
import { Migration } from "script/Migration.s.sol";

contract Migration__20231020_RNSUpgrade is RNSDeploy {
function run() public trySetUp {
_upgradeProxy(ContractKey.RNSUnified, EMPTY_ARGS);
contract Migration__20231020_RNSUpgrade is Migration {
function run() public {
_upgradeProxy(Contract.RNSUnified.key());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";
import { Contract } from "script/utils/Contract.sol";
import { Migration } from "script/Migration.s.sol";

contract Migration__20231021_UpgradeDomainPriceAndAuction is RNSDeploy {
function run() public trySetUp {
_upgradeProxy(ContractKey.RNSAuction, EMPTY_ARGS);
_upgradeProxy(ContractKey.RNSDomainPrice, EMPTY_ARGS);
contract Migration__20231021_UpgradeDomainPriceAndAuction is Migration {
function run() public {
_upgradeProxy(Contract.RNSAuction.key());
_upgradeProxy(Contract.RNSDomainPrice.key());
}
}
10 changes: 5 additions & 5 deletions script/20231024-upgrade-auction/20231024_UpgradeAuction.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";
import { Contract } from "script/utils/Contract.sol";
import { Migration } from "script/Migration.s.sol";

contract Migration__20231024_UpgradeAuction is RNSDeploy {
function run() public trySetUp {
_upgradeProxy(ContractKey.RNSAuction, EMPTY_ARGS);
contract Migration__20231024_UpgradeAuction is Migration {
function run() public {
_upgradeProxy(Contract.RNSAuction.key());
}
}
23 changes: 14 additions & 9 deletions script/20231024-upgrade-domain-price/20231024_Config.s.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { Network, RNSDeploy } from "script/RNSDeploy.s.sol";
import { ISharedArgument, DefaultNetwork, Migration } from "script/Migration.s.sol";

abstract contract Config__20231024 is RNSDeploy {
function _buildMigrationConfig() internal view virtual override returns (Config memory config) {
config = super._buildMigrationConfig();
if (_network == Network.RoninTestnet) {
config.overrider = config.operator;
} else if (_network == Network.RoninMainnet) {
revert("Missing config");
abstract contract Config__20231024 is Migration {
function _sharedArguments() internal view virtual override returns (bytes memory rawArgs) {
rawArgs = super._sharedArguments();

ISharedArgument.SharedParameter memory param = abi.decode(rawArgs, (ISharedArgument.SharedParameter));

if (network() == DefaultNetwork.RoninTestnet.key()) {
param.overrider = param.operator;
} else if (network() == DefaultNetwork.RoninMainnet.key()) {
revert("Missing param");
} else {
revert("Missing config");
revert("Missing param");
}

rawArgs = abi.encode(param);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { console2 } from "forge-std/console2.sol";
import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { console2 as console } from "forge-std/console2.sol";
import { Contract } from "script/utils/Contract.sol";
import { RNSDomainPrice } from "@rns-contracts/RNSDomainPrice.sol";
import { Config__20231024 } from "./20231024_Config.s.sol";
import { ISharedArgument, Config__20231024 } from "./20231024_Config.s.sol";

contract Migration__20231024_UpgradeDomainPrice is Config__20231024 {
function run() public trySetUp {
Config memory config = getConfig();
_upgradeProxy(ContractKey.RNSDomainPrice, EMPTY_ARGS);
function run() public {
ISharedArgument.SharedParameter memory param = config.sharedArguments();
_upgradeProxy(Contract.RNSDomainPrice.key());

console2.log("operator", config.operator);
console2.log("overrider", config.overrider);
console.log("operator", param.operator);
console.log("overrider", param.overrider);

RNSDomainPrice domainPrice = RNSDomainPrice(_config.getAddressFromCurrentNetwork(ContractKey.RNSDomainPrice));
RNSDomainPrice domainPrice = RNSDomainPrice(config.getAddressFromCurrentNetwork(Contract.RNSDomainPrice.key()));
address admin = domainPrice.getRoleMember(0x00, 0);
bytes32 overriderRole = domainPrice.OVERRIDER_ROLE();
vm.broadcast(admin);
domainPrice.grantRole(overriderRole, config.overrider);
domainPrice.grantRole(overriderRole, param.overrider);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";
import { Contract } from "script/utils/Contract.sol";
import { Migration } from "script/Migration.s.sol";

contract Migration__20231024_UpgradeRNSUnified is RNSDeploy {
function run() public trySetUp {
_upgradeProxy(ContractKey.RNSUnified, EMPTY_ARGS);
contract Migration__20231024_UpgradeRNSUnified is Migration {
function run() public {
_upgradeProxy(Contract.RNSUnified.key());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";
import { Contract } from "script/utils/Contract.sol";
import { Migration } from "script/Migration.s.sol";

contract Migration__20231025_UpgradeController is RNSDeploy {
function run() public trySetUp {
_upgradeProxy(ContractKey.RONRegistrarController, EMPTY_ARGS);
contract Migration__20231025_UpgradeController is Migration {
function run() public {
_upgradeProxy(Contract.RONRegistrarController.key());
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";
import { Contract } from "script/utils/Contract.sol";
import { ISharedArgument, Migration } from "script/Migration.s.sol";
import { RNSDomainPrice } from "@rns-contracts/RNSDomainPrice.sol";

contract Migration__20231106_RevertRenewalFees is RNSDeploy {
contract Migration__20231106_RevertRenewalFees is Migration {
function run() public {
RNSDomainPrice domainPrice = RNSDomainPrice(_config.getAddressFromCurrentNetwork(ContractKey.RNSDomainPrice));
RNSDomainPrice domainPrice = RNSDomainPrice(config.getAddressFromCurrentNetwork(Contract.RNSDomainPrice.key()));

Config memory config = getConfig();
ISharedArgument.SharedParameter memory param = config.sharedArguments();
vm.broadcast(domainPrice.getRoleMember(domainPrice.DEFAULT_ADMIN_ROLE(), 0));
vm.resumeGasMetering();
domainPrice.setRenewalFeeByLengths(config.renewalFees);
vm.pauseGasMetering();
domainPrice.setRenewalFeeByLengths(param.renewalFees);
}
}
Loading

0 comments on commit 40d7d4a

Please sign in to comment.