Skip to content

Commit

Permalink
refactor(scratch deploy): persistNetworkState2 and deployed-x.json fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
arwer13 committed Oct 24, 2023
1 parent d215e08 commit 33f6be9
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 128 deletions.
6 changes: 4 additions & 2 deletions deployed-goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@
"0xb75A55EFab5A8f5224Ae93B34B25741EDd3da98b"
]
},
"lidoApmAddress": "0x64361389f8Bb7A1ff64e0Ad97FfAa432399D45E7",
"lidoApmDeployTx": "0x5177a441fbf121e4064979f53756cc2ee807c68684edae33f50868a40ebae013",
"lidoApm": {
"deployTx": "0x5177a441fbf121e4064979f53756cc2ee807c68684edae33f50868a40ebae013",
"address": "0x64361389f8Bb7A1ff64e0Ad97FfAa432399D45E7"
},
"lidoApmEnsName": "lidopm-testnet-prater.eth",
"lidoLocator": {
"contract": "LidoLocator",
Expand Down
14 changes: 8 additions & 6 deletions deployed-holesky.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,14 @@
"lastCompletedEpochId": 0
}
},
"lidoApmAddress": "0x4605Dc9dC4BD0442F850eB8226B94Dd0e27C3Ce7",
"lidoApmDeployArguments": [
"0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae",
"0x90a9580abeb24937fc658e497221c81ce8553b560304f9525821f32b17dbdaec"
],
"lidoApmDeployTx": "0x2fac1c172a250736c34d16d3a721d2916abac0de0dea67d79955346a1f4345a2",
"lidoApm": {
"deployArguments": [
"0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae",
"0x90a9580abeb24937fc658e497221c81ce8553b560304f9525821f32b17dbdaec"
],
"deployTx": "0x2fac1c172a250736c34d16d3a721d2916abac0de0dea67d79955346a1f4345a2",
"address": "0x4605Dc9dC4BD0442F850eB8226B94Dd0e27C3Ce7"
},
"lidoApmEnsName": "lidopm.eth",
"lidoApmEnsRegDurationSec": 94608000,
"lidoLocator": {
Expand Down
6 changes: 4 additions & 2 deletions deployed-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@
}
},
"ipfsAPI": "https://ipfs.infura.io:5001/api/v0",
"lidoApmAddress": "0x0cb113890b04B49455DfE06554e2D784598A29C9",
"lidoApmDeployTx": "0xfa66476569ecef5790f2d0634997b952862bbca56aa088f151b8049421eeb87b",
"lidoApm": {
"deployTx": "0xfa66476569ecef5790f2d0634997b952862bbca56aa088f151b8049421eeb87b",
"address": "0x0cb113890b04B49455DfE06554e2D784598A29C9"
},
"lidoApmEnsName": "lidopm.eth",
"lidoApmEnsRegDurationSec": 94608000,
"lidoLocator": {
Expand Down
15 changes: 7 additions & 8 deletions scripts/helpers/deploy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { readNetworkState, persistNetworkState, persistNetworkState2 } = require('./persisted-network-state')
const { readNetworkState, persistNetworkState } = require('./persisted-network-state')
const { artifacts, ethers } = require('hardhat')
const fs = require('fs').promises
const chalk = require('chalk')
Expand Down Expand Up @@ -118,12 +118,11 @@ async function assertDeployedBytecode(address, artifact, desc = '') {
const bytecode = await web3.eth.getCode(address)
const nameDesc = artifact.contractName ? chalk.yellow(artifact.contractName) : 'the expected one'
const checkDesc = `${desc ? desc + ': ' : ''}the bytecode at ${chalk.yellow(address)} matches ${nameDesc}`
// TODO: restore the check
// if (bytecode.toLowerCase() !== artifact.deployedBytecode.toLowerCase()) {
// console.log({bytecode: bytecode.toLowerCase()})
// console.log({deployedBytecode: artifact.deployedBytecode.toLowerCase()})
// }
// assert.isTrue(bytecode.toLowerCase() === artifact.deployedBytecode.toLowerCase(), checkDesc)
if (bytecode.toLowerCase() !== artifact.deployedBytecode.toLowerCase()) {
console.log({bytecode: bytecode.toLowerCase()})
console.log({deployedBytecode: artifact.deployedBytecode.toLowerCase()})
}
assert.isTrue(bytecode.toLowerCase() === artifact.deployedBytecode.toLowerCase(), checkDesc)
log.success(checkDesc)
}

Expand Down Expand Up @@ -235,7 +234,7 @@ async function deployImplementation(nameInState, artifactName, deployer, constru
address: contract.address,
constructorArgs: constructorArgs,
}
persistNetworkState2(network.name, netId, state)
persistNetworkState(network.name, netId, state)
return contract
}

Expand Down
31 changes: 3 additions & 28 deletions scripts/helpers/persisted-network-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs')
const path = require('path')

const { log } = require('./log')
const { assert } = require('../../test/helpers/assert')

const NETWORK_STATE_FILE_BASENAME = process.env.NETWORK_STATE_FILE_BASENAME || 'deployed'
const NETWORK_STATE_FILE_DIR = process.env.NETWORK_STATE_FILE_DIR || '.'
Expand All @@ -13,24 +14,15 @@ function readNetworkState(netName, netId) {
}

function persistNetworkState(netName, netId, state, updates = undefined) {
state.networkId = netId
assert.equal(netId, state.networkId, `Network id ${netId} does not match one in state file ${state.networkId}`)
if (updates) {
updateNetworkState(state, updates)
}
const fileName = _getFileName(netName, NETWORK_STATE_FILE_BASENAME, NETWORK_STATE_FILE_DIR)
_writeNetworkStateFile(fileName, state)
}

function persistNetworkState2(netName, netId, state, updates = undefined) {
state.networkId = netId
if (updates) {
updateNetworkState2(state, updates)
}
const fileName = _getFileName(netName, NETWORK_STATE_FILE_BASENAME, NETWORK_STATE_FILE_DIR)
_writeNetworkStateFile(fileName, state)
}

function updateNetworkState2(state, newState) {
function updateNetworkState(state, newState) {
Object.keys(newState).forEach((key) => {
const previousValue = state[key]
const value = newState[key]
Expand All @@ -40,22 +32,6 @@ function updateNetworkState2(state, newState) {
})
}

function updateNetworkState(state, newState) {
Object.keys(newState).forEach((key) => {
const value = newState[key]
if (value != null) {
if (value.address) {
state[`${key}Address`] = value.address
if (value.constructorArgs) {
state[`${key}ConstructorArgs`] = value.constructorArgs
}
} else {
state[key] = value
}
}
})
}

function assertRequiredNetworkState(state, requiredStateNames) {
const missingState = requiredStateNames.filter((key) => !state[key])
if (missingState.length) {
Expand Down Expand Up @@ -106,7 +82,6 @@ function _writeNetworkStateFile(fileName, state) {
module.exports = {
readNetworkState,
persistNetworkState,
persistNetworkState2,
updateNetworkState,
assertRequiredNetworkState,
readStateFile,
Expand Down
1 change: 1 addition & 0 deletions scripts/scratch/00-populate-deploy-artifact-from-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function saveDeployParameters({ web3, artifacts }) {
const gateSealAddress = (GATE_SEAL_FACTORY === null || GATE_SEAL_FACTORY === ZERO_ADDRESS)
? ZERO_ADDRESS : ''

state.networkId = await web3.eth.net.getId()
state.chainId = CHAIN_ID
state.deployer = DEPLOYER
state.gateSeal = {
Expand Down
24 changes: 12 additions & 12 deletions scripts/scratch/01-deploy-lido-template-and-bases.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const chalk = require('chalk')
const runOrWrapScript = require('../helpers/run-or-wrap-script')
const { log, yl, gr } = require('../helpers/log')
const { deployImplementation, deployWithoutProxy } = require('../helpers/deploy')
const { readNetworkState, assertRequiredNetworkState, persistNetworkState2 } = require('../helpers/persisted-network-state')
const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = require('../helpers/persisted-network-state')
const { APP_NAMES } = require('../constants')

const REQUIRED_NET_STATE = [
'ensAddress',
'daoFactoryAddress',
'miniMeTokenFactoryAddress',
'aragonIDAddress',
'apmRegistryFactoryAddress',
'ens',
'daoFactory',
'miniMeTokenFactory',
'aragonID',
'apmRegistryFactory',
'deployer'
]

Expand All @@ -26,11 +26,11 @@ async function deployTemplate({ web3, artifacts }) {

const daoTemplateConstructorArgs = [
state.deployer,
state.daoFactoryAddress,
state.ensAddress,
state.miniMeTokenFactoryAddress,
state.aragonIDAddress,
state.apmRegistryFactoryAddress
state.daoFactory.address,
state.ens.address,
state.miniMeTokenFactory.address,
state.aragonID.address,
state.apmRegistryFactory.address
]

log.splitter()
Expand All @@ -44,7 +44,7 @@ async function deployTemplate({ web3, artifacts }) {

await deployImplementation(`app:${APP_NAMES.NODE_OPERATORS_REGISTRY}`, 'NodeOperatorsRegistry', state.deployer)

persistNetworkState2(network.name, netId, readNetworkState(network.name, netId), {
persistNetworkState(network.name, netId, readNetworkState(network.name, netId), {
lidoTemplate: {
deployBlock: daoTemplateDeployBlock,
}
Expand Down
20 changes: 10 additions & 10 deletions scripts/scratch/02-obtain-deployed-instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const { APP_NAMES } = require('../constants')
const { network } = require('hardhat')

const REQUIRED_NET_STATE = [
'ensAddress',
'daoFactoryAddress',
'miniMeTokenFactoryAddress',
'aragonIDAddress',
'apmRegistryFactoryAddress',
'ens',
'daoFactory',
'miniMeTokenFactory',
'aragonID',
'apmRegistryFactory',
'deployer',
'lidoTemplate',
`app:${APP_NAMES.LIDO}`,
Expand All @@ -39,11 +39,11 @@ async function deployTemplate({ web3, artifacts }) {
await assertDeployedBytecode(daoTemplate.address, 'LidoTemplate')
const templateConfig = await daoTemplate.getConfig()
assert.addressEqual(templateConfig._owner, state.deployer, 'tmpl: owner')
assert.addressEqual(templateConfig._daoFactory, state.daoFactoryAddress, 'tmpl: daoFactory')
assert.addressEqual(templateConfig._ens, state.ensAddress, 'tmpl: ens')
assert.addressEqual(templateConfig._miniMeFactory, state.miniMeTokenFactoryAddress, 'tmpl: miniMeFactory')
assert.addressEqual(templateConfig._aragonID, state.aragonIDAddress, 'tmpl: aragonId')
assert.addressEqual(templateConfig._apmRegistryFactory, state.apmRegistryFactoryAddress, 'tmpl: apmRegistryFactory')
assert.addressEqual(templateConfig._daoFactory, state.daoFactory.address, 'tmpl: daoFactory')
assert.addressEqual(templateConfig._ens, state.ens.address, 'tmpl: ens')
assert.addressEqual(templateConfig._miniMeFactory, state.miniMeTokenFactory.address, 'tmpl: miniMeFactory')
assert.addressEqual(templateConfig._aragonID, state.aragonID.address, 'tmpl: aragonId')
assert.addressEqual(templateConfig._apmRegistryFactory, state.apmRegistryFactory.address, 'tmpl: apmRegistryFactory')
log.success(`the config`)
}

Expand Down
6 changes: 3 additions & 3 deletions scripts/scratch/03-register-ens-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const TLD = 'eth'
const CONTROLLER_INTERFACE_ID = '0x018fac06'

const REQUIRED_NET_STATE = [
'ensAddress',
'ens',
'lidoApmEnsName',
'lidoApmEnsRegDurationSec',
'deployer',
Expand All @@ -30,8 +30,8 @@ async function deployTemplate({ web3, artifacts }) {

log.splitter()

log(`Using ENS:`, yl(state.ensAddress))
const ens = await artifacts.require('ENS').at(state.ensAddress)
log(`Using ENS:`, yl(state.ens.address))
const ens = await artifacts.require('ENS').at(state.ens.address)

const tldNode = namehash(TLD)

Expand Down
14 changes: 8 additions & 6 deletions scripts/scratch/05-deploy-apm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { getENSNodeOwner } = require('../components/ens')
const REQUIRED_NET_STATE = [
'deployer',
'lidoTemplate',
'ensAddress',
'ens',
'lidoApmEnsName',
]

Expand All @@ -37,7 +37,7 @@ async function deployAPM({ web3, artifacts }) {
log.splitter()
await assertNoEvents(template, null, state.lidoTemplate.deployBlock)

const ens = await artifacts.require('ENS').at(state.ensAddress)
const ens = await artifacts.require('ENS').at(state.ens.address)
const lidoApmEnsNode = namehash(state.lidoApmEnsName)
const lidoApmEnsNodeOwner = await getENSNodeOwner(ens, lidoApmEnsNode)
const checkDesc = `ENS node is owned by the DAO template`
Expand All @@ -61,10 +61,12 @@ async function deployAPM({ web3, artifacts }) {
const lidoApmDeployArguments = [parentHash, subHash]
const receipt = await log.makeTx(template, 'deployLidoAPM', lidoApmDeployArguments, { from })

persistNetworkState(network.name, netId, state, {
lidoApmDeployArguments,
lidoApmDeployTx: receipt.tx,
})
state.lidoApm = {
...state.lidoApm,
deployArguments: lidoApmDeployArguments,
deployTx: receipt.tx,
}
persistNetworkState(network.name, netId, state)
}

function splitDomain(domain) {
Expand Down
19 changes: 10 additions & 9 deletions scripts/scratch/06-obtain-deployed-apm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { getENSNodeOwner } = require('../components/ens')

const { assertAPMRegistryPermissions } = require('./checks/apm')

const REQUIRED_NET_STATE = ['ensAddress', 'lidoApmEnsName', 'lidoTemplate']
const REQUIRED_NET_STATE = ['ens', 'lidoApmEnsName', 'lidoTemplate']

async function obtainDeployedAPM({ web3, artifacts }) {
const netId = await web3.eth.net.getId()
Expand All @@ -35,12 +35,8 @@ async function obtainDeployedAPM({ web3, artifacts }) {
log(`Using LidoTemplate deploy block: ${chalk.yellow(state.lidoTemplate.deployBlock)}`)
}

// if (!state.lidoApmDeployTx) {
const apmDeployedEvt = await assertLastEvent(template, 'TmplAPMDeployed', null, state.lidoTemplate.deployBlock)
state.lidoApmDeployTx = apmDeployedEvt.transactionHash
// }
log(`Using deployLidoAPM transaction: ${chalk.yellow(state.lidoApmDeployTx)}`)
persistNetworkState(network.name, netId, state)
log(`Using deployLidoAPM transaction: ${chalk.yellow(state.lidoApm.deployTx)}`)

const registryAddress = apmDeployedEvt.args.apm
log.splitter(`Using APMRegistry: ${chalk.yellow(registryAddress)}`)
Expand All @@ -52,15 +48,15 @@ async function obtainDeployedAPM({ web3, artifacts }) {
await assertProxiedContractBytecode(registry.address, proxyArtifact, registryArtifact)

const ensAddress = await registry.ens()
assert.addressEqual(ensAddress, state.ensAddress, 'APMRegistry ENS address')
assert.addressEqual(ensAddress, state.ens.address, 'APMRegistry ENS address')
log.success(`registry.ens: ${chalk.yellow(ensAddress)}`)

const registrarAddress = await registry.registrar()
const registrar = await artifacts.require('ENSSubdomainRegistrar').at(registrarAddress)
log.success(`registry.registrar: ${chalk.yellow(registrarAddress)}`)

const registrarEnsAddress = await registrar.ens()
assert.addressEqual(registrarEnsAddress, state.ensAddress, 'ENSSubdomainRegistrar: ENS address')
assert.addressEqual(registrarEnsAddress, state.ens.address, 'ENSSubdomainRegistrar: ENS address')
log.success(`registry.registrar.ens: ${chalk.yellow(registrarEnsAddress)}`)

const rootNode = await registrar.rootNode()
Expand Down Expand Up @@ -97,7 +93,12 @@ async function obtainDeployedAPM({ web3, artifacts }) {
)

log.splitter()
persistNetworkState(network.name, netId, state, { lidoApmAddress: registryAddress })

state.lidoApm = {
...state.lidoApm,
address: registryAddress,
}
persistNetworkState(network.name, netId, state)
}

module.exports = runOrWrapScript(obtainDeployedAPM, module)
8 changes: 4 additions & 4 deletions scripts/scratch/07-create-app-repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = re

const { APP_NAMES } = require('../constants')

const DULL_CONTENT_URI = "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
const NULL_CONTENT_URI = "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"


const REQUIRED_NET_STATE = [
Expand Down Expand Up @@ -52,13 +52,13 @@ async function createAppRepos({ web3, artifacts }) {
[1, 0, 0],
// Lido app
lidoAppState.implementation.address,
DULL_CONTENT_URI,
NULL_CONTENT_URI,
// NodeOperatorsRegistry app
nodeOperatorsAppState.implementation.address,
DULL_CONTENT_URI,
NULL_CONTENT_URI,
// LegacyOracle app
oracleAppState.implementation.address,
DULL_CONTENT_URI,
NULL_CONTENT_URI,
]
const from = state.deployer

Expand Down
4 changes: 2 additions & 2 deletions scripts/scratch/08-deploy-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { APP_NAMES } = require('../constants')
const VALID_APP_NAMES = Object.entries(APP_NAMES).map((e) => e[1])

const REQUIRED_NET_STATE = [
'ensAddress',
'ens',
'deployer',
'lidoTemplate',
`app:${APP_NAMES.LIDO}`,
Expand Down Expand Up @@ -119,7 +119,7 @@ async function checkAppRepos(state) {
log.success(contentCheckDesc)
}

const ens = await artifacts.require('ENS').at(state.ensAddress)
const ens = await artifacts.require('ENS').at(state.ens.address)

for (const app of aragonApps) {
const upstreamRepoName = `${app.appName.substring(7)}.${ARAGON_APM_ENS_DOMAIN}`
Expand Down
Loading

0 comments on commit 33f6be9

Please sign in to comment.