Commit 644c9042 authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

feat(contracts): Replace two arrays with a single array of structs

parent af445ece
...@@ -7,14 +7,22 @@ import { Lib_AddressManager } from "../resolver/Lib_AddressManager.sol"; ...@@ -7,14 +7,22 @@ import { Lib_AddressManager } from "../resolver/Lib_AddressManager.sol";
* @title AddressDictator * @title AddressDictator
*/ */
contract AddressDictator { contract AddressDictator {
/*********
* Types *
*********/
struct NamedAddress {
string name;
address addr;
}
/************* /*************
* Variables * * Variables *
*************/ *************/
Lib_AddressManager public manager; Lib_AddressManager public manager;
address public finalOwner; address public finalOwner;
string[] public names; NamedAddress[] namedAddresses;
address[] public addresses;
/*************** /***************
* Constructor * * Constructor *
...@@ -41,8 +49,9 @@ contract AddressDictator { ...@@ -41,8 +49,9 @@ contract AddressDictator {
_names.length == _addresses.length, _names.length == _addresses.length,
"AddressDictator: Must provide an equal number of names and addresses." "AddressDictator: Must provide an equal number of names and addresses."
); );
names = _names; for (uint256 i = 0; i < _names.length; i++) {
addresses = _addresses; namedAddresses.push(NamedAddress({ name: _names[i], addr: _addresses[i] }));
}
} }
/******************** /********************
...@@ -50,8 +59,8 @@ contract AddressDictator { ...@@ -50,8 +59,8 @@ contract AddressDictator {
********************/ ********************/
function setAddresses() external { function setAddresses() external {
for (uint256 i = 0; i < names.length; i++) { for (uint256 i = 0; i < namedAddresses.length; i++) {
manager.setAddress(names[i], addresses[i]); manager.setAddress(namedAddresses[i].name, namedAddresses[i].addr);
} }
// note that this will revert if _finalOwner == currentOwner // note that this will revert if _finalOwner == currentOwner
manager.transferOwnership(finalOwner); manager.transferOwnership(finalOwner);
...@@ -69,11 +78,7 @@ contract AddressDictator { ...@@ -69,11 +78,7 @@ contract AddressDictator {
* View Functions * * View Functions *
******************/ ******************/
function getNames() external view returns (string[] memory) { function getNamedAddresses() external view returns (NamedAddress[] memory) {
return names; return namedAddresses;
}
function getAddresses() external view returns (address[] memory) {
return addresses;
} }
} }
...@@ -10,10 +10,7 @@ import { ...@@ -10,10 +10,7 @@ import {
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getLiveContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
hre,
'Lib_AddressManager'
)
await deployAndPostDeploy({ await deployAndPostDeploy({
hre, hre,
......
...@@ -62,7 +62,10 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -62,7 +62,10 @@ const deployFn: DeployFunction = async (hre) => {
// Next we need to set the `messenger` address by executing a setStorage operation. We'll // Next we need to set the `messenger` address by executing a setStorage operation. We'll
// check that this operation was correctly executed by calling `messenger()` and checking // check that this operation was correctly executed by calling `messenger()` and checking
// that the result matches the value we initialized. // that the result matches the value we initialized.
const l1CrossDomainMessenger = await getLiveContract(hre, 'Proxy__OVM_L1CrossDomainMessenger') const l1CrossDomainMessenger = await getLiveContract(
hre,
'Proxy__OVM_L1CrossDomainMessenger'
)
const l1CrossDomainMessengerAddress = l1CrossDomainMessenger.address const l1CrossDomainMessengerAddress = l1CrossDomainMessenger.address
// Critical error, should never happen. // Critical error, should never happen.
......
...@@ -12,8 +12,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -12,8 +12,7 @@ const deployFn: DeployFunction = async (hre) => {
signerOrProvider: deployer, signerOrProvider: deployer,
}) })
const libAddressManager = await getLiveContract(hre, 'Lib_AddressManager') const libAddressManager = await getLiveContract(hre, 'Lib_AddressManager')
const names = await addressDictator.getNames() const namedAddresses = await addressDictator.getNamedAddresses()
const addresses = await addressDictator.getAddresses()
const finalOwner = await addressDictator.finalOwner() const finalOwner = await addressDictator.finalOwner()
let currentOwner = await libAddressManager.owner() let currentOwner = await libAddressManager.owner()
...@@ -21,8 +20,10 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -21,8 +20,10 @@ const deployFn: DeployFunction = async (hre) => {
'\n', '\n',
'An Address Dictator contract has been deployed, with the following name/address pairs:' 'An Address Dictator contract has been deployed, with the following name/address pairs:'
) )
for (let i = 0; i < names.length; i++) { for (const namedAddress of namedAddresses) {
console.log(`${addresses[i]} <=> ${names[i]}`) // Set alignment for readability
const padding = ' '.repeat(40 - namedAddress.name.length)
console.log(`${namedAddress.name}${padding} ${namedAddress.addr}`)
} }
console.log( console.log(
'\n', '\n',
......
...@@ -3,20 +3,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,20 +3,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { hexStringEquals } from '@eth-optimism/core-utils' import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */ /* Imports: Internal */
import { import { getLiveContract, waitUntilTrue } from '../src/hardhat-deploy-ethers'
getLiveContract,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
const Lib_AddressManager = await getLiveContract( const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager', {
hre, signerOrProvider: deployer,
'Lib_AddressManager', })
{
signerOrProvider: deployer,
}
)
const owner = (hre as any).deployConfig.ovmAddressManagerOwner const owner = (hre as any).deployConfig.ovmAddressManagerOwner
const remoteOwner = await Lib_AddressManager.owner() const remoteOwner = await Lib_AddressManager.owner()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment