@@ -24,7 +24,7 @@ contract RocketUpgradeOneDotFour is RocketBase {
2424
2525 bool public lockedB = false ;
2626 address [18 ] public addressesB;
27- string [18 ] public abisB;
27+ string [19 ] public abisB;
2828
2929 // Construct
3030 constructor (
@@ -50,7 +50,7 @@ contract RocketUpgradeOneDotFour is RocketBase {
5050 // @notice Sets the B addresses and ABIs of the upgrade
5151 function setB (
5252 address [18 ] memory _addressesB ,
53- string [18 ] memory _abisB
53+ string [19 ] memory _abisB
5454 ) external {
5555 require (msg .sender == deployer, "Only deployer can set " );
5656 require (! lockedB, "Already set " );
@@ -83,6 +83,9 @@ contract RocketUpgradeOneDotFour is RocketBase {
8383 _addContract ("rocketMegapoolPenalties " , addressesB[15 ], abisB[15 ]);
8484 _addContract ("rocketNetworkSnapshotsTime " , addressesB[16 ], abisB[16 ]);
8585
86+ // Add rocketMegapool convenience ABI
87+ _addABI ("rocketMegapool " , abisB[18 ]);
88+
8689 // Upgrade existing contracts
8790 _upgradeContract ("rocketNodeManager " , addressesA[4 ], abisA[4 ]);
8891 _upgradeContract ("rocketNodeDeposit " , addressesA[5 ], abisA[5 ]);
@@ -232,4 +235,20 @@ contract RocketUpgradeOneDotFour is RocketBase {
232235 setAddress (keccak256 (abi.encodePacked ("contract.address " , _name)), _contractAddress);
233236 setString (keccak256 (abi.encodePacked ("contract.abi " , _name)), _contractAbi);
234237 }
238+
239+ /// @dev Adds a new ABI to the protocol
240+ function _addABI (string memory _name , string memory _contractAbi ) internal {
241+ // Check ABI name
242+ bytes32 nameHash = keccak256 (abi.encodePacked (_name));
243+ require (bytes (_name).length > 0 , "Invalid ABI name " );
244+ // Sanity check
245+ require (bytes (_contractAbi).length > 0 , "Empty ABI is invalid " );
246+ // Cannot add ABI if name is already used for an existing network contract
247+ require (getAddress (keccak256 (abi.encodePacked ("contract.address " , _name))) == address (0x0 ), "ABI name is already in use " );
248+ // Cannot add ABI if ABI already exists for this name (use upgradeABI instead)
249+ string memory existingAbi = getString (keccak256 (abi.encodePacked ("contract.abi " , _name)));
250+ require (bytes (existingAbi).length == 0 , "ABI name is already in use " );
251+ // Set ABI
252+ setString (keccak256 (abi.encodePacked ("contract.abi " , _name)), _contractAbi);
253+ }
235254}
0 commit comments