Skip to content

Commit e414ad3

Browse files
authored
v0.6.3-testnet (#286)
2 parents 1762246 + 77e6083 commit e414ad3

File tree

11 files changed

+916
-122
lines changed

11 files changed

+916
-122
lines changed

contracts/interfaces/IProfile.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,14 @@ interface IProfile {
4747
* - Only contract admin can call this method.
4848
*/
4949
function addNewProfile(CandidateProfile memory profile) external;
50+
51+
/**
52+
* @notice The candidate admin registers a new profile.
53+
*
54+
* @dev Requirements:
55+
* - The profile must not be existent before.
56+
* - Only user with candidate admin role can call this method.
57+
*/
58+
59+
function registerProfile(CandidateProfile memory profile) external;
5060
}

contracts/ronin/profile/Profile.sol

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// SPDX-License-Identifier: MIT
22

33
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
4-
import "../../interfaces/staking/IStaking.sol";
4+
import "../../interfaces/validator/IRoninValidatorSet.sol";
55
import "../../interfaces/IProfile.sol";
6+
import { ErrUnauthorized, RoleAccess } from "../../utils/CommonErrors.sol";
67
import "./ProfileStorage.sol";
78

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

16+
function initialize(address validatorContract) external initializer {
17+
_setContract(ContractType.VALIDATOR, validatorContract);
18+
}
19+
1520
/**
1621
* @inheritdoc IProfile
1722
*/
@@ -27,4 +32,18 @@ contract Profile is IProfile, ProfileStorage, Initializable {
2732
if (_profile.id != address(0)) revert ErrExistentProfile();
2833
_addNewProfile(_profile, profile);
2934
}
35+
36+
/**
37+
* @inheritdoc IProfile
38+
*/
39+
function registerProfile(CandidateProfile memory profile) external {
40+
CandidateProfile storage _profile = _id2Profile[profile.id];
41+
if (_profile.id != address(0)) revert ErrExistentProfile();
42+
if (
43+
msg.sender != profile.admin ||
44+
!IRoninValidatorSet(getContract(ContractType.VALIDATOR)).isCandidateAdmin(profile.consensus, profile.admin)
45+
) revert ErrUnauthorized(msg.sig, RoleAccess.ADMIN);
46+
47+
_addNewProfile(_profile, profile);
48+
}
3049
}

contracts/ronin/validator/CoinbaseExecution.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ abstract contract CoinbaseExecution is
148148
* - This method is only called once each epoch.
149149
*/
150150
function _syncFastFinalityReward(uint256 epoch, address[] memory validators) private {
151-
uint256[] memory voteCounts = IFastFinalityTracking(getContract(ContractType.FAST_FINALTIY_TRACKING))
151+
uint256[] memory voteCounts = IFastFinalityTracking(getContract(ContractType.FAST_FINALITY_TRACKING))
152152
.getManyFinalityVoteCounts(epoch, validators);
153153
uint256 divisor = _numberOfBlocksInEpoch * validators.length;
154154
uint256 iReward;

contracts/ronin/validator/RoninValidatorSet.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ contract RoninValidatorSet is Initializable, CoinbaseExecution, SlashingExecutio
7070
}
7171

7272
function initializeV3(address fastFinalityTrackingContract) external reinitializer(3) {
73-
_setContract(ContractType.FAST_FINALTIY_TRACKING, fastFinalityTrackingContract);
73+
_setContract(ContractType.FAST_FINALITY_TRACKING, fastFinalityTrackingContract);
7474
}
7575

7676
/**

contracts/utils/ContractType.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ enum ContractType {
1616
/* 11 */ BRIDGE_MANAGER,
1717
/* 12 */ BRIDGE_SLASH,
1818
/* 13 */ BRIDGE_REWARD,
19-
/* 14 */ FAST_FINALTIY_TRACKING,
19+
/* 14 */ FAST_FINALITY_TRACKING,
2020
/* 15 */ PROFILE
2121
}

deployments/ronin-testnet/ProfileLogic.json

Lines changed: 96 additions & 32 deletions
Large diffs are not rendered by default.

deployments/ronin-testnet/solcInputs/6d67256db1844d3deb1c932d686229ba.json

Lines changed: 634 additions & 0 deletions
Large diffs are not rendered by default.

logs/contract_code_sizes.log

Lines changed: 85 additions & 85 deletions
Large diffs are not rendered by default.

src/deploy/proxy/profile-proxy.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
33

44
import { generalRoninConf, roninchainNetworks } from '../../configs/config';
55
import { Address } from 'hardhat-deploy/dist/types';
6+
import { Network } from '../../utils';
7+
import { Profile__factory } from '../../types';
68

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

28+
let validatorContractAddress: Address;
29+
if (network.name == Network.Hardhat) {
30+
validatorContractAddress = generalRoninConf[network.name]!.validatorContract?.address!;
31+
} else {
32+
const validatorContractDeployment = await deployments.get('RoninValidatorSetProxy');
33+
validatorContractAddress = validatorContractDeployment.address;
34+
}
35+
36+
const data = new Profile__factory().interface.encodeFunctionData('initialize', [validatorContractAddress]);
37+
2638
await deploy('ProfileProxy', {
2739
contract: 'TransparentUpgradeableProxyV2',
2840
from: deployer,
2941
log: true,
30-
args: [logicContract.address, governanceAdmin, []],
42+
args: [logicContract.address, governanceAdmin, data],
3143
});
3244
};
3345

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
2+
import { explorerUrl, proxyInterface } from '../upgradeUtils';
3+
import { VoteType } from '../../script/proposal';
4+
import { roninchainNetworks } from '../../configs/config';
5+
import { network } from 'hardhat';
6+
import { Profile__factory } from '../../types';
7+
8+
const deploy = async ({ getNamedAccounts, deployments, ethers }: HardhatRuntimeEnvironment) => {
9+
if (!roninchainNetworks.includes(network.name!)) {
10+
return;
11+
}
12+
13+
const { execute } = deployments;
14+
let { governor } = await getNamedAccounts(); // NOTE: Should double check the `governor` account in the `hardhat.config.ts` file
15+
console.log('Governor:', governor);
16+
17+
const validatorContractAddress = (await deployments.get('RoninValidatorSetProxy')).address;
18+
19+
// Upgrade Profile Contract
20+
const ProfileProxy = await deployments.get('ProfileProxy');
21+
const ProfileLogic = await deployments.get('ProfileLogic');
22+
const ProfileInstr = [
23+
proxyInterface.encodeFunctionData('upgradeToAndCall', [
24+
ProfileLogic.address,
25+
new Profile__factory().interface.encodeFunctionData('initialize', [validatorContractAddress]),
26+
]),
27+
];
28+
console.info('ProfileInstr', ProfileInstr);
29+
30+
// Propose the proposal
31+
const blockNumBefore = await ethers.provider.getBlockNumber();
32+
const blockBefore = await ethers.provider.getBlock(blockNumBefore);
33+
const timestampBefore = blockBefore.timestamp;
34+
const proposalExpiryTimestamp = timestampBefore + 3600 * 24 * 10; // expired in 10 days
35+
36+
const tx = await execute(
37+
'RoninGovernanceAdmin',
38+
{ from: governor, log: true },
39+
'proposeProposalForCurrentNetwork',
40+
proposalExpiryTimestamp, // expiryTimestamp
41+
[...ProfileInstr.map(() => ProfileProxy.address)], // targets
42+
[...ProfileInstr].map(() => 0), // values
43+
[...ProfileInstr], // datas
44+
[...ProfileInstr].map(() => 1_000_000), // gasAmounts
45+
VoteType.For // ballot type
46+
);
47+
deployments.log(`${explorerUrl[network.name!]}/tx/${tx.transactionHash}`);
48+
};
49+
50+
// yarn hardhat deploy --tags 230925_UpgradeAndInitV1ProfileContractV0_6_3 --network ronin-testnet
51+
deploy.tags = ['230925_UpgradeAndInitV1ProfileContractV0_6_3'];
52+
53+
export default deploy;

0 commit comments

Comments
 (0)