Skip to content

Commit

Permalink
v0.6.3-testnet (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxqbao authored Sep 25, 2023
2 parents 1762246 + 77e6083 commit e414ad3
Show file tree
Hide file tree
Showing 11 changed files with 916 additions and 122 deletions.
10 changes: 10 additions & 0 deletions contracts/interfaces/IProfile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ interface IProfile {
* - Only contract admin can call this method.
*/
function addNewProfile(CandidateProfile memory profile) external;

/**
* @notice The candidate admin registers a new profile.
*
* @dev Requirements:
* - The profile must not be existent before.
* - Only user with candidate admin role can call this method.
*/

function registerProfile(CandidateProfile memory profile) external;
}
21 changes: 20 additions & 1 deletion contracts/ronin/profile/Profile.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "../../interfaces/staking/IStaking.sol";
import "../../interfaces/validator/IRoninValidatorSet.sol";
import "../../interfaces/IProfile.sol";
import { ErrUnauthorized, RoleAccess } from "../../utils/CommonErrors.sol";
import "./ProfileStorage.sol";

pragma solidity ^0.8.9;
Expand All @@ -12,6 +13,10 @@ contract Profile is IProfile, ProfileStorage, Initializable {
_disableInitializers();
}

function initialize(address validatorContract) external initializer {
_setContract(ContractType.VALIDATOR, validatorContract);
}

/**
* @inheritdoc IProfile
*/
Expand All @@ -27,4 +32,18 @@ contract Profile is IProfile, ProfileStorage, Initializable {
if (_profile.id != address(0)) revert ErrExistentProfile();
_addNewProfile(_profile, profile);
}

/**
* @inheritdoc IProfile
*/
function registerProfile(CandidateProfile memory profile) external {
CandidateProfile storage _profile = _id2Profile[profile.id];
if (_profile.id != address(0)) revert ErrExistentProfile();
if (
msg.sender != profile.admin ||
!IRoninValidatorSet(getContract(ContractType.VALIDATOR)).isCandidateAdmin(profile.consensus, profile.admin)
) revert ErrUnauthorized(msg.sig, RoleAccess.ADMIN);

_addNewProfile(_profile, profile);
}
}
2 changes: 1 addition & 1 deletion contracts/ronin/validator/CoinbaseExecution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ abstract contract CoinbaseExecution is
* - This method is only called once each epoch.
*/
function _syncFastFinalityReward(uint256 epoch, address[] memory validators) private {
uint256[] memory voteCounts = IFastFinalityTracking(getContract(ContractType.FAST_FINALTIY_TRACKING))
uint256[] memory voteCounts = IFastFinalityTracking(getContract(ContractType.FAST_FINALITY_TRACKING))
.getManyFinalityVoteCounts(epoch, validators);
uint256 divisor = _numberOfBlocksInEpoch * validators.length;
uint256 iReward;
Expand Down
2 changes: 1 addition & 1 deletion contracts/ronin/validator/RoninValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract RoninValidatorSet is Initializable, CoinbaseExecution, SlashingExecutio
}

function initializeV3(address fastFinalityTrackingContract) external reinitializer(3) {
_setContract(ContractType.FAST_FINALTIY_TRACKING, fastFinalityTrackingContract);
_setContract(ContractType.FAST_FINALITY_TRACKING, fastFinalityTrackingContract);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/ContractType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ enum ContractType {
/* 11 */ BRIDGE_MANAGER,
/* 12 */ BRIDGE_SLASH,
/* 13 */ BRIDGE_REWARD,
/* 14 */ FAST_FINALTIY_TRACKING,
/* 14 */ FAST_FINALITY_TRACKING,
/* 15 */ PROFILE
}
128 changes: 96 additions & 32 deletions deployments/ronin-testnet/ProfileLogic.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

170 changes: 85 additions & 85 deletions logs/contract_code_sizes.log

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/deploy/proxy/profile-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';

import { generalRoninConf, roninchainNetworks } from '../../configs/config';
import { Address } from 'hardhat-deploy/dist/types';
import { Network } from '../../utils';
import { Profile__factory } from '../../types';

const deploy = async ({ getNamedAccounts, deployments }: HardhatRuntimeEnvironment) => {
if (!roninchainNetworks.includes(network.name!)) {
Expand All @@ -23,11 +25,21 @@ const deploy = async ({ getNamedAccounts, deployments }: HardhatRuntimeEnvironme
governanceAdmin = GADepl.address;
}

let validatorContractAddress: Address;
if (network.name == Network.Hardhat) {
validatorContractAddress = generalRoninConf[network.name]!.validatorContract?.address!;
} else {
const validatorContractDeployment = await deployments.get('RoninValidatorSetProxy');
validatorContractAddress = validatorContractDeployment.address;
}

const data = new Profile__factory().interface.encodeFunctionData('initialize', [validatorContractAddress]);

await deploy('ProfileProxy', {
contract: 'TransparentUpgradeableProxyV2',
from: deployer,
log: true,
args: [logicContract.address, governanceAdmin, []],
args: [logicContract.address, governanceAdmin, data],
});
};

Expand Down
53 changes: 53 additions & 0 deletions src/upgrades/REP-003/230925-upgrade-and-init-profile-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { explorerUrl, proxyInterface } from '../upgradeUtils';
import { VoteType } from '../../script/proposal';
import { roninchainNetworks } from '../../configs/config';
import { network } from 'hardhat';
import { Profile__factory } from '../../types';

const deploy = async ({ getNamedAccounts, deployments, ethers }: HardhatRuntimeEnvironment) => {
if (!roninchainNetworks.includes(network.name!)) {
return;
}

const { execute } = deployments;
let { governor } = await getNamedAccounts(); // NOTE: Should double check the `governor` account in the `hardhat.config.ts` file
console.log('Governor:', governor);

const validatorContractAddress = (await deployments.get('RoninValidatorSetProxy')).address;

// Upgrade Profile Contract
const ProfileProxy = await deployments.get('ProfileProxy');
const ProfileLogic = await deployments.get('ProfileLogic');
const ProfileInstr = [
proxyInterface.encodeFunctionData('upgradeToAndCall', [
ProfileLogic.address,
new Profile__factory().interface.encodeFunctionData('initialize', [validatorContractAddress]),
]),
];
console.info('ProfileInstr', ProfileInstr);

// Propose the proposal
const blockNumBefore = await ethers.provider.getBlockNumber();
const blockBefore = await ethers.provider.getBlock(blockNumBefore);
const timestampBefore = blockBefore.timestamp;
const proposalExpiryTimestamp = timestampBefore + 3600 * 24 * 10; // expired in 10 days

const tx = await execute(
'RoninGovernanceAdmin',
{ from: governor, log: true },
'proposeProposalForCurrentNetwork',
proposalExpiryTimestamp, // expiryTimestamp
[...ProfileInstr.map(() => ProfileProxy.address)], // targets
[...ProfileInstr].map(() => 0), // values
[...ProfileInstr], // datas
[...ProfileInstr].map(() => 1_000_000), // gasAmounts
VoteType.For // ballot type
);
deployments.log(`${explorerUrl[network.name!]}/tx/${tx.transactionHash}`);
};

// yarn hardhat deploy --tags 230925_UpgradeAndInitV1ProfileContractV0_6_3 --network ronin-testnet
deploy.tags = ['230925_UpgradeAndInitV1ProfileContractV0_6_3'];

export default deploy;
2 changes: 2 additions & 0 deletions test/hardhat_test/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export enum ContractType {
/* 11 */ BRIDGE_MANAGER,
/* 12 */ BRIDGE_SLASH,
/* 13 */ BRIDGE_REWARD,
/* 14 */ FAST_FINALITY_TRACKING,
/* 15 */ PROFILE,
}

export const getProxyImplementation = async (proxy: string): Promise<string> =>
Expand Down

0 comments on commit e414ad3

Please sign in to comment.