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";
* @title AddressDictator
*/
contract AddressDictator {
/*********
* Types *
*********/
struct NamedAddress {
string name;
address addr;
}
/*************
* Variables *
*************/
Lib_AddressManager public manager;
address public finalOwner;
string[] public names;
address[] public addresses;
NamedAddress[] namedAddresses;
/***************
* Constructor *
......@@ -41,8 +49,9 @@ contract AddressDictator {
_names.length == _addresses.length,
"AddressDictator: Must provide an equal number of names and addresses."
);
names = _names;
addresses = _addresses;
for (uint256 i = 0; i < _names.length; i++) {
namedAddresses.push(NamedAddress({ name: _names[i], addr: _addresses[i] }));
}
}
/********************
......@@ -50,8 +59,8 @@ contract AddressDictator {
********************/
function setAddresses() external {
for (uint256 i = 0; i < names.length; i++) {
manager.setAddress(names[i], addresses[i]);
for (uint256 i = 0; i < namedAddresses.length; i++) {
manager.setAddress(namedAddresses[i].name, namedAddresses[i].addr);
}
// note that this will revert if _finalOwner == currentOwner
manager.transferOwnership(finalOwner);
......@@ -69,11 +78,7 @@ contract AddressDictator {
* View Functions *
******************/
function getNames() external view returns (string[] memory) {
return names;
}
function getAddresses() external view returns (address[] memory) {
return addresses;
function getNamedAddresses() external view returns (NamedAddress[] memory) {
return namedAddresses;
}
}
......@@ -10,10 +10,7 @@ import {
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getLiveContract(
hre,
'Lib_AddressManager'
)
const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager')
await deployAndPostDeploy({
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
// check that this operation was correctly executed by calling `messenger()` and checking
// 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
// Critical error, should never happen.
......
......@@ -12,8 +12,7 @@ const deployFn: DeployFunction = async (hre) => {
signerOrProvider: deployer,
})
const libAddressManager = await getLiveContract(hre, 'Lib_AddressManager')
const names = await addressDictator.getNames()
const addresses = await addressDictator.getAddresses()
const namedAddresses = await addressDictator.getNamedAddresses()
const finalOwner = await addressDictator.finalOwner()
let currentOwner = await libAddressManager.owner()
......@@ -21,8 +20,10 @@ const deployFn: DeployFunction = async (hre) => {
'\n',
'An Address Dictator contract has been deployed, with the following name/address pairs:'
)
for (let i = 0; i < names.length; i++) {
console.log(`${addresses[i]} <=> ${names[i]}`)
for (const namedAddress of namedAddresses) {
// Set alignment for readability
const padding = ' '.repeat(40 - namedAddress.name.length)
console.log(`${namedAddress.name}${padding} ${namedAddress.addr}`)
}
console.log(
'\n',
......
......@@ -3,20 +3,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */
import {
getLiveContract,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'
import { getLiveContract, waitUntilTrue } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
const Lib_AddressManager = await getLiveContract(
hre,
'Lib_AddressManager',
{
const Lib_AddressManager = await getLiveContract(hre, 'Lib_AddressManager', {
signerOrProvider: deployer,
}
)
})
const owner = (hre as any).deployConfig.ovmAddressManagerOwner
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