Skip to content

Commit

Permalink
Merge branch 'testnet' into feat/profile
Browse files Browse the repository at this point in the history
  • Loading branch information
nxqbao committed Sep 25, 2023
2 parents a49cb6c + e414ad3 commit 84bfe67
Show file tree
Hide file tree
Showing 14 changed files with 925 additions and 140 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on:
branches:
- mainnet
- testnet
- 'release/**'
- "release/**"
pull_request:
branches:
- mainnet
- testnet
- 'release/**'
- "release/**"

permissions:
packages: read
Expand Down
9 changes: 9 additions & 0 deletions contracts/interfaces/IProfile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ interface IProfile {
* Emit an {ProfileAddressChanged}.
*/
function requestChangeConsensusAddr(address id, TConsensus newConsensusAddr) 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;
}
20 changes: 20 additions & 0 deletions contracts/ronin/profile/Profile.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// SPDX-License-Identifier: MIT

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

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

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

/**
* @dev Initializes the contract storage.
*/
Expand Down Expand Up @@ -97,4 +103,18 @@ contract Profile is IProfile, ProfileStorage, ProfileXComponents, Initializable

emit ProfileAddressChanged(id, RoleAccess.CONSENSUS);
}

/**
* @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 @@ -150,7 +150,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);
}

function initializeV4(address profileContract) external reinitializer(4) {
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.

14 changes: 7 additions & 7 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ const compilerConfig: SolcUserConfig = {
enabled: true,
runs: 200,
},
/// @dev see: https://github.com/Uniswap/v3-core/blob/main/hardhat.config.ts
metadata: {
// do not include the metadata hash, since this is machine dependent
// and we want all generated code to be deterministic
// https://docs.soliditylang.org/en/v0.8.17/metadata.html
bytecodeHash: 'none',
},
},
};

Expand All @@ -123,6 +116,13 @@ const config: HardhatUserConfig = {
enabled: true,
runs: 10,
},
/// @dev see: https://github.com/Uniswap/v3-core/blob/main/hardhat.config.ts
metadata: {
// do not include the metadata hash, since this is machine dependent
// and we want all generated code to be deterministic
// https://docs.soliditylang.org/en/v0.8.17/metadata.html
bytecodeHash: 'none',
},
},
},
},
Expand Down
170 changes: 85 additions & 85 deletions logs/contract_code_sizes.log

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions logs/storage_layout.log
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ PauseEnforcer:_initializing (storage_slot: 2) (offset: 1) (type: t_bool) (number
PauseEnforcer:target (storage_slot: 2) (offset: 2) (type: t_contract(IPauseTarget)) (numberOfBytes: 20)
PauseEnforcer:emergency (storage_slot: 2) (offset: 22) (type: t_bool) (numberOfBytes: 1)
Profile:_id2Profile (storage_slot: 0) (offset: 0) (type: t_mapping(t_addresst_struct(CandidateProfile)_storage)) (numberOfBytes: 32)
Profile:_consensus2Id (storage_slot: 1) (offset: 0) (type: t_mapping(t_userDefinedValueType(TConsensus)42965t_address)) (numberOfBytes: 32)
Profile:_consensus2Id (storage_slot: 1) (offset: 0) (type: t_mapping(t_userDefinedValueType(TConsensus)43049t_address)) (numberOfBytes: 32)
Profile:__gap (storage_slot: 2) (offset: 0) (type: t_array(t_bytes32)_storage) (numberOfBytes: 1600)
Profile:_initialized (storage_slot: 52) (offset: 0) (type: t_uint8) (numberOfBytes: 1)
Profile:_initializing (storage_slot: 52) (offset: 1) (type: t_bool) (numberOfBytes: 1)
ProfileStorage:_id2Profile (storage_slot: 0) (offset: 0) (type: t_mapping(t_addresst_struct(CandidateProfile)_storage)) (numberOfBytes: 32)
ProfileStorage:_consensus2Id (storage_slot: 1) (offset: 0) (type: t_mapping(t_userDefinedValueType(TConsensus)42965t_address)) (numberOfBytes: 32)
ProfileStorage:_consensus2Id (storage_slot: 1) (offset: 0) (type: t_mapping(t_userDefinedValueType(TConsensus)43049t_address)) (numberOfBytes: 32)
ProfileStorage:__gap (storage_slot: 2) (offset: 0) (type: t_array(t_bytes32)_storage) (numberOfBytes: 1600)
ProfileXComponents:_id2Profile (storage_slot: 0) (offset: 0) (type: t_mapping(t_addresst_struct(CandidateProfile)_storage)) (numberOfBytes: 32)
ProfileXComponents:_consensus2Id (storage_slot: 1) (offset: 0) (type: t_mapping(t_userDefinedValueType(TConsensus)42965t_address)) (numberOfBytes: 32)
ProfileXComponents:_consensus2Id (storage_slot: 1) (offset: 0) (type: t_mapping(t_userDefinedValueType(TConsensus)43049t_address)) (numberOfBytes: 32)
ProfileXComponents:__gap (storage_slot: 2) (offset: 0) (type: t_array(t_bytes32)_storage) (numberOfBytes: 1600)
ProxyAdmin:_owner (storage_slot: 0) (offset: 0) (type: t_address) (numberOfBytes: 20)
ReentrancyGuard:_status (storage_slot: 0) (offset: 0) (type: t_uint256) (numberOfBytes: 32)
Expand Down
19 changes: 12 additions & 7 deletions src/deploy/proxy/profile-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';

import { generalRoninConf, roninchainNetworks } from '../../configs/config';
import { verifyAddress } from '../../script/verify-address';
import { Profile__factory } from '../../types';
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 @@ -25,17 +26,21 @@ const deploy = async ({ getNamedAccounts, deployments }: HardhatRuntimeEnvironme
governanceAdmin = GADepl.address;
}

const data = new Profile__factory().interface.encodeFunctionData('initialize', [
generalRoninConf[network.name]!.stakingContract?.address,
generalRoninConf[network.name]!.validatorContract?.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]);

const deployment = await deploy('ProfileProxy', {
contract: 'TransparentUpgradeableProxyV2',
from: deployer,
log: true,
args: [logicContract.address, generalRoninConf[network.name]!.governanceAdmin?.address, data],
nonce,
args: [logicContract.address, governanceAdmin, data],
});
verifyAddress(deployment.address, generalRoninConf[network.name].profileContract?.address);
};
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: 1 addition & 1 deletion test/hardhat_test/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export enum ContractType {
/* 11 */ BRIDGE_MANAGER,
/* 12 */ BRIDGE_SLASH,
/* 13 */ BRIDGE_REWARD,
/* 14 */ FAST_FINALTIY_TRACKING,
/* 14 */ FAST_FINALITY_TRACKING,
/* 15 */ PROFILE,
}

Expand Down

0 comments on commit 84bfe67

Please sign in to comment.