1
1
// SPDX-License-Identifier: MIT
2
2
3
3
import "@openzeppelin/contracts/proxy/utils/Initializable.sol " ;
4
+ import "../../interfaces/validator/ICandidateManager.sol " ;
4
5
import "../../interfaces/validator/IRoninValidatorSet.sol " ;
5
6
import "../../interfaces/IProfile.sol " ;
6
7
import { ErrUnauthorized, RoleAccess } from "../../utils/CommonErrors.sol " ;
7
- import "./ProfileStorage.sol " ;
8
+ import { ContractType } from "../../utils/ContractType.sol " ;
9
+ import "./ProfileHandler.sol " ;
8
10
9
11
pragma solidity ^ 0.8.9 ;
10
12
11
- contract Profile is IProfile , ProfileStorage , Initializable {
13
+ contract Profile is IProfile , ProfileHandler , Initializable {
12
14
constructor () {
13
15
_disableInitializers ();
14
16
}
@@ -17,6 +19,68 @@ contract Profile is IProfile, ProfileStorage, Initializable {
17
19
_setContract (ContractType.VALIDATOR, validatorContract);
18
20
}
19
21
22
+ function migrateTestnet () external {
23
+ require (block .chainid == 2021 , "mismatch chainID " );
24
+ require (msg .sender == 0x968D0Cd7343f711216817E617d3f92a23dC91c07 , "not testnet admin " );
25
+
26
+ CandidateProfile storage _profile;
27
+
28
+ address [10 ] memory consensusList = [
29
+ 0xCaba9D9424D6bAD99CE352A943F59279B533417a ,
30
+ 0x9f1Abc67beA4db5560371fF3089F4Bfe934c36Bc ,
31
+ 0xA85ddDdCeEaB43DccAa259dd4936aC104386F9aa ,
32
+ 0xAcf8Bf98D1632e602d0B1761771049aF21dd6597 ,
33
+ 0xE9bf2A788C27dADc6B169d52408b710d267b9bff ,
34
+ 0xD086D2e3Fac052A3f695a4e8905Ce1722531163C ,
35
+ // 0x9687e8C41fa369aD08FD278a43114C4207856a61, // missing
36
+ 0xa325Fd3a2f4f5CafE2c151eE428b5CeDeD628193 ,
37
+ 0x9422d990AcDc3f2b3AA3B97303aD3060F09d7ffC ,
38
+ 0xc3C97512421BF3e339E9fd412f18584e53138bFA ,
39
+ 0x78fD38faa30ea66702cc39383D2E84f9a4A56fA6
40
+ ];
41
+
42
+ for (uint i; i < consensusList.length ; i++ ) {
43
+ _migrateTestnetHelper (consensusList[i]);
44
+ }
45
+
46
+ {
47
+ _profile = _getId2ProfileHelper (0xCaba9D9424D6bAD99CE352A943F59279B533417a );
48
+ _setGovernor (_profile, 0xb033ba62EC622dC54D0ABFE0254e79692147CA26 );
49
+ }
50
+ {
51
+ _profile = _getId2ProfileHelper (0x9f1Abc67beA4db5560371fF3089F4Bfe934c36Bc );
52
+ _setGovernor (_profile, 0x087D08e3ba42e64E3948962dd1371F906D1278b9 );
53
+ }
54
+ {
55
+ _profile = _getId2ProfileHelper (0xA85ddDdCeEaB43DccAa259dd4936aC104386F9aa );
56
+ _setGovernor (_profile, 0x52ec2e6BBcE45AfFF8955Da6410bb13812F4289F );
57
+ }
58
+ {
59
+ _profile = _getId2ProfileHelper (0xAcf8Bf98D1632e602d0B1761771049aF21dd6597 );
60
+ _setGovernor (_profile, 0xd24D87DDc1917165435b306aAC68D99e0F49A3Fa );
61
+ }
62
+ }
63
+
64
+ function migrateTestnetManual (address consensus , address governor ) external {
65
+ require (block .chainid == 2021 , "mismatch chainID " );
66
+ require (msg .sender == 0x968D0Cd7343f711216817E617d3f92a23dC91c07 , "not testnet admin " );
67
+
68
+ _migrateTestnetHelper (consensus);
69
+ if (governor != address (0 )) {
70
+ CandidateProfile storage _profile = _getId2ProfileHelper (consensus);
71
+ _setGovernor (_profile, governor);
72
+ }
73
+ }
74
+
75
+ function _migrateTestnetHelper (address consensus ) internal {
76
+ CandidateProfile storage _profile = _getId2ProfileHelper (consensus);
77
+ ICandidateManager.ValidatorCandidate memory info = IRoninValidatorSet (getContract (ContractType.VALIDATOR))
78
+ .getCandidateInfo (consensus);
79
+ _setConsensus (_profile, consensus);
80
+ _setAdmin (_profile, info.admin);
81
+ _setTreasury (_profile, payable (info.treasuryAddr));
82
+ }
83
+
20
84
/**
21
85
* @inheritdoc IProfile
22
86
*/
@@ -37,13 +101,28 @@ contract Profile is IProfile, ProfileStorage, Initializable {
37
101
* @inheritdoc IProfile
38
102
*/
39
103
function registerProfile (CandidateProfile memory profile ) external {
104
+ if (profile.id != profile.consensus) revert ErrIdAndConsensusDiffer ();
105
+
40
106
CandidateProfile storage _profile = _id2Profile[profile.id];
41
107
if (_profile.id != address (0 )) revert ErrExistentProfile ();
42
108
if (
43
109
msg .sender != profile.admin ||
44
110
! IRoninValidatorSet (getContract (ContractType.VALIDATOR)).isCandidateAdmin (profile.consensus, profile.admin)
45
111
) revert ErrUnauthorized (msg .sig , RoleAccess.ADMIN);
112
+ _checkDuplicatedInRegistry (profile);
46
113
47
114
_addNewProfile (_profile, profile);
48
115
}
116
+
117
+ /**
118
+ * @inheritdoc IProfile
119
+ */
120
+ function changePubkey (address id , bytes memory pubkey ) external {
121
+ CandidateProfile storage _profile = _getId2ProfileHelper (id);
122
+ if (msg .sender != _profile.admin) revert ErrUnauthorized (msg .sig , RoleAccess.ADMIN);
123
+ _checkNonDuplicatedPubkey (pubkey);
124
+ _setPubkey (_profile, pubkey);
125
+
126
+ emit PubkeyChanged (id, pubkey);
127
+ }
49
128
}
0 commit comments