diff --git a/docs/scratch-deploy.md b/docs/scratch-deploy.md index 10658b68d..bbbf171c5 100644 --- a/docs/scratch-deploy.md +++ b/docs/scratch-deploy.md @@ -88,7 +88,7 @@ yarn hardhat node To do Holešky deployment, the following parameters must be set up via env variables: -- `DEPLOYER`. The deployer address. The deployer must own its private key. It must have enough ether. +- `DEPLOYER`. The deployer address. The deployer must own its private key. To ensure proper operation, it should have an adequate amount of ether. The total deployment gas cost is approximately 100,000,000 gas, and this cost can vary based on whether specific components of the environment, such as the DepositContract, are deployed or not. - `RPC_URL`. Address of of the Ethereum RPC node to use. E.g. for Infura it is `https://holesky.infura.io/v3/` - `GAS_PRIORITY_FEE`. Gas priority fee. By default set to `2` - `GAS_MAX_FEE`. Gas max fee. By default set to `100` diff --git a/scripts/helpers/deploy.js b/scripts/helpers/deploy.js index 1fd2f70d7..b10a63e5b 100644 --- a/scripts/helpers/deploy.js +++ b/scripts/helpers/deploy.js @@ -4,7 +4,7 @@ const fs = require('fs').promises const chalk = require('chalk') const { assert } = require('chai') -const { log, logDeploy, logDeployTxData } = require('./log') +const { log, logDeploy, logDeployTxData, OK } = require('./log') const { getTxData } = require('./tx-data') @@ -12,10 +12,34 @@ const GAS_PRICE = process.env.GAS_PRICE || null const GAS_PRIORITY_FEE = process.env.GAS_PRIORITY_FEE || null const GAS_MAX_FEE = process.env.GAS_MAX_FEE || null -let TOTAL_GAS_USED = 0 -function getTotalGasUsed() { - return TOTAL_GAS_USED +class TotalGasCounterPrivate { + constructor() { + this.totalGasUsed = 0 + } +} +class TotalGasCounter { + constructor() { + throw new Error('Use TotalGasCounter.getInstance()'); + } + static getInstance() { + if (!TotalGasCounter.instance) { + TotalGasCounter.instance = new TotalGasCounterPrivate() + } + return TotalGasCounter.instance + } + static add(gasUsed) { + return this.getInstance().totalGasUsed += gasUsed + } + static getTotalGasUsed() { + return this.getInstance().totalGasUsed + } + static async incrementTotalGasUsedInStateFile() { + const netId = await web3.eth.net.getId() + const state = readNetworkState(network.name, netId) + state.initialDeployTotalGasUsed += TotalGasCounter.getTotalGasUsed() + persistNetworkState(network.name, netId, state) + } } async function getDeploymentGasUsed(contract) { @@ -50,6 +74,19 @@ async function getDeployTx(artifactName, opts = {}) { return await getTxData(txObj) } +async function makeTx(contract, funcName, args, txParams) { + console.log(`${contract.constructor._json.contractName}[${contract.address}].${funcName}()...`) + const receipt = await contract[funcName](...args, txParams) + const gasUsed = receipt.gasUsed ? receipt.gasUsed : receipt.receipt.gasUsed + if (gasUsed === undefined) { + console.log({ receipt }) + assert(false) + } + console.log(`${OK} tx: ${receipt.tx} (gasUsed ${gasUsed})`) + TotalGasCounter.add(gasUsed) + return receipt +} + async function deploy(artifactName, artifacts, deploy) { const Artifact = artifacts.require(artifactName) return await logDeploy(artifactName, deploy ? deploy(Artifact) : Artifact.new()) @@ -202,7 +239,7 @@ async function deployWithoutProxy(nameInState, artifactName, deployer, construct const gasUsed = await getDeploymentGasUsed(contract) console.log(`done: ${contract.address} (gas used ${gasUsed})`) - TOTAL_GAS_USED += gasUsed + TotalGasCounter.add(gasUsed) state[nameInState] = { ...state[nameInState], @@ -222,10 +259,8 @@ async function deployImplementation(nameInState, artifactName, deployer, constru process.stdout.write(`Deploying implementation for proxy of ${artifactName}... `) const contract = await deployContract(artifactName, constructorArgs, deployer) - const gasUsed = await getDeploymentGasUsed(contract) - TOTAL_GAS_USED += gasUsed - + TotalGasCounter.add(gasUsed) console.log(`done: ${contract.address} (gas used ${gasUsed})`) state[nameInState] = { ...state[nameInState] } @@ -246,12 +281,12 @@ async function deployBehindOssifiableProxy(nameInState, artifactName, proxyOwner if (implementation === null) { process.stdout.write(`Deploying implementation for proxy of ${artifactName}... `) const contract = await deployContract(artifactName, constructorArgs, deployer) - const gasUsed = await getDeploymentGasUsed(contract) - TOTAL_GAS_USED += gasUsed + TotalGasCounter.add(gasUsed) implementation = contract.address console.log(`done: ${implementation} (gas used ${gasUsed})`) + } else { console.log(`Using pre-deployed implementation of ${artifactName}: ${implementation}`) } @@ -260,7 +295,7 @@ async function deployBehindOssifiableProxy(nameInState, artifactName, proxyOwner const proxyConstructorArgs = [implementation, proxyOwner, '0x'] const proxy = await deployContract(proxyContractName, proxyConstructorArgs, deployer) const gasUsed = await getDeploymentGasUsed(proxy) - TOTAL_GAS_USED += gasUsed + TotalGasCounter.add(gasUsed) console.log(`done: ${proxy.address} (gas used ${gasUsed})`) state[nameInState] = { ...state[nameInState] } @@ -287,8 +322,10 @@ async function updateProxyImplementation(nameInState, artifactName, proxyAddress const proxy = await artifacts.require('OssifiableProxy').at(proxyAddress) const implementation = await deployContract(artifactName, constructorArgs, proxyOwner) + const gasUsed = await getDeploymentGasUsed(implementation) + TotalGasCounter.add(gasUsed) - await log.makeTx(proxy, 'proxy__upgradeTo', [implementation.address], { from: proxyOwner }) + await makeTx(proxy, 'proxy__upgradeTo', [implementation.address], { from: proxyOwner }) state[nameInState] = { ...state[nameInState] } state[nameInState].implementation = { @@ -318,6 +355,7 @@ module.exports = { deployImplementation, deployBehindOssifiableProxy, updateProxyImplementation, - getTotalGasUsed, getContractPath, + makeTx, + TotalGasCounter, } diff --git a/scripts/helpers/log.js b/scripts/helpers/log.js index 6bd27e5c0..d1689d9a3 100644 --- a/scripts/helpers/log.js +++ b/scripts/helpers/log.js @@ -93,15 +93,7 @@ async function logTx(desc, promise) { return result } -async function txWithLog(contract, funcName, args, txParams) { - console.log(`${contract.constructor._json.contractName}[${contract.address}].${funcName}()...`) - const receipt = await contract[funcName](...args, txParams) - console.log(`${OK} tx: ${receipt.tx}`) - return receipt -} - log.tx = logTx -log.makeTx = txWithLog async function logDeployTxData(contractName, txData) { logSplitter(`To deploy ${yl(contractName)}, send the following transaction:`) @@ -127,7 +119,6 @@ module.exports = { logDeploy, logDeployTxData, logTx, - txWithLog, rd, yl, gr, diff --git a/scripts/scratch/01-deploy-lido-template-and-bases.js b/scripts/scratch/01-deploy-lido-template-and-bases.js index 94ccbeb61..3150492bd 100644 --- a/scripts/scratch/01-deploy-lido-template-and-bases.js +++ b/scripts/scratch/01-deploy-lido-template-and-bases.js @@ -1,8 +1,8 @@ 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 { log } = require('../helpers/log') +const { deployImplementation, deployWithoutProxy, TotalGasCounter } = require('../helpers/deploy') const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') const { APP_NAMES } = require('../constants') @@ -51,6 +51,8 @@ async function deployTemplate({ web3, artifacts }) { }) log.splitter() + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(deployTemplate, module) diff --git a/scripts/scratch/02-obtain-deployed-instances.js b/scripts/scratch/02-obtain-deployed-instances.js index 899bd35ae..fdc42c142 100644 --- a/scripts/scratch/02-obtain-deployed-instances.js +++ b/scripts/scratch/02-obtain-deployed-instances.js @@ -1,10 +1,9 @@ const chalk = require('chalk') - const runOrWrapScript = require('../helpers/run-or-wrap-script') -const { log, logSplitter, logWideSplitter, logHeader, logTx } = require('../helpers/log') -const { useOrGetDeployed, assertDeployedBytecode, getTxBlock } = require('../helpers/deploy') +const { log, logWideSplitter, logHeader } = require('../helpers/log') +const { assertDeployedBytecode } = require('../helpers/deploy') const { assert } = require('../helpers/assert') -const { readNetworkState, persistNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') +const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') const { APP_NAMES } = require('../constants') const { network } = require('hardhat') diff --git a/scripts/scratch/03-register-ens-domain.js b/scripts/scratch/03-register-ens-domain.js index c8bb41bf5..9fdd4af8f 100644 --- a/scripts/scratch/03-register-ens-domain.js +++ b/scripts/scratch/03-register-ens-domain.js @@ -6,7 +6,8 @@ const keccak256 = require('js-sha3').keccak_256 const runOrWrapScript = require('../helpers/run-or-wrap-script') const { assert } = require('../helpers/assert') const { log, yl, gr } = require('../helpers/log') -const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') +const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') const TLD = 'eth' const CONTROLLER_INTERFACE_ID = '0x018fac06' @@ -100,9 +101,9 @@ async function deployTemplate({ web3, artifacts }) { log.splitter() - await log.makeTx(controller, 'commit', [commitment], { from: state.deployer }) + await makeTx(controller, 'commit', [commitment], { from: state.deployer }) - await log.makeTx(controller, 'register', [domainLabel, domainOwner, domainRegDuration, salt], { + await makeTx(controller, 'register', [domainLabel, domainOwner, domainRegDuration, salt], { from: state.deployer, value: '0x' + registerTxValue.toString(16), }) @@ -112,14 +113,16 @@ async function deployTemplate({ web3, artifacts }) { log(`ENS domain new owner:`, yl(domainOwner)) if ((await ens.owner(node)) === state.deployer) { log(`Transferring name ownership from owner ${chalk.yellow(state.deployer)} to template ${chalk.yellow(domainOwner)}`) - await log.makeTx(ens, 'setOwner', [node, domainOwner], { from: state.deployer }) + await makeTx(ens, 'setOwner', [node, domainOwner], { from: state.deployer }) } else { log(`Creating the subdomain and assigning it to template ${chalk.yellow(domainOwner)}`) - await log.makeTx(ens, 'setSubnodeOwner', [tldNode, labelHash, domainOwner], { from: state.deployer }) + await makeTx(ens, 'setSubnodeOwner', [tldNode, labelHash, domainOwner], { from: state.deployer }) } log.splitter() } + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } const HOUR = 60 * 60 diff --git a/scripts/scratch/05-deploy-apm.js b/scripts/scratch/05-deploy-apm.js index 7a5de1112..fe0f54d99 100644 --- a/scripts/scratch/05-deploy-apm.js +++ b/scripts/scratch/05-deploy-apm.js @@ -8,6 +8,7 @@ const { log, logSplitter, logWideSplitter } = require('../helpers/log') const { assertNoEvents } = require('../helpers/events') const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') const { getENSNodeOwner } = require('../components/ens') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const REQUIRED_NET_STATE = [ 'deployer', @@ -59,7 +60,7 @@ async function deployAPM({ web3, artifacts }) { const from = state.deployer const lidoApmDeployArguments = [parentHash, subHash] - const receipt = await log.makeTx(template, 'deployLidoAPM', lidoApmDeployArguments, { from }) + const receipt = await makeTx(template, 'deployLidoAPM', lidoApmDeployArguments, { from }) state.lidoApm = { ...state.lidoApm, @@ -67,6 +68,8 @@ async function deployAPM({ web3, artifacts }) { deployTx: receipt.tx, } persistNetworkState(network.name, netId, state) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } function splitDomain(domain) { diff --git a/scripts/scratch/07-create-app-repos.js b/scripts/scratch/07-create-app-repos.js index c4c1686e0..8e632c6b8 100644 --- a/scripts/scratch/07-create-app-repos.js +++ b/scripts/scratch/07-create-app-repos.js @@ -5,6 +5,7 @@ const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log, logSplitter, logWideSplitter } = require('../helpers/log') const { assertLastEvent } = require('../helpers/events') const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const { APP_NAMES } = require('../constants') @@ -63,7 +64,7 @@ async function createAppRepos({ web3, artifacts }) { console.log({arguments, from}) - const lidoAppsReceipt = await log.makeTx(template, 'createRepos', createReposArguments, { from }) + const lidoAppsReceipt = await makeTx(template, 'createRepos', createReposArguments, { from }) console.log(`=== Aragon Lido Apps Repos (Lido, AccountingOracle, NodeOperatorsRegistry deployed: ${lidoAppsReceipt.tx} ===`) const createStdAragonReposArguments = [ @@ -73,12 +74,14 @@ async function createAppRepos({ web3, artifacts }) { state['app:aragon-voting'].implementation.address, ] - const aragonStdAppsReceipt = await log.makeTx(template, 'createStdAragonRepos', createStdAragonReposArguments, { from }) + const aragonStdAppsReceipt = await makeTx(template, 'createStdAragonRepos', createStdAragonReposArguments, { from }) console.log(`=== Aragon Std Apps Repos (Agent, Finance, TokenManager, Voting deployed: ${aragonStdAppsReceipt.tx} ===`) state.lidoTemplateCreateStdAppReposTx = aragonStdAppsReceipt.tx logSplitter() persistNetworkState(network.name, netId, state) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(createAppRepos, module) diff --git a/scripts/scratch/08-deploy-dao.js b/scripts/scratch/08-deploy-dao.js index 0fe8e3418..b50a44e48 100644 --- a/scripts/scratch/08-deploy-dao.js +++ b/scripts/scratch/08-deploy-dao.js @@ -3,7 +3,7 @@ const chalk = require('chalk') const { assert } = require('chai') const { getEvents } = require('@aragon/contract-helpers-test') const { hash: namehash } = require('eth-ens-namehash') -const { toChecksumAddress } = require('web3-utils') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log } = require('../helpers/log') @@ -64,13 +64,15 @@ async function deployDAO({ web3, artifacts }) { log(`Using DAO token settings:`, daoInitialSettings.token) log(`Using DAO voting settings:`, daoInitialSettings.voting) - const receipt = await log.makeTx(template, 'newDAO', [ + const receipt = await makeTx(template, 'newDAO', [ daoInitialSettings.token.name, daoInitialSettings.token.symbol, votingSettings, ], { from: state.deployer }) state.lidoTemplateNewDaoTx = receipt.tx persistNetworkState(network.name, netId, state) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } async function checkAppRepos(state) { diff --git a/scripts/scratch/10-issue-tokens.js b/scripts/scratch/10-issue-tokens.js index a36339300..c50ee80bb 100644 --- a/scripts/scratch/10-issue-tokens.js +++ b/scripts/scratch/10-issue-tokens.js @@ -1,15 +1,11 @@ const BN = require('bn.js') -const path = require('path') const chalk = require('chalk') -const { assert } = require('chai') -const { getEvents } = require('@aragon/contract-helpers-test') -const { hash: namehash } = require('eth-ens-namehash') -const { toChecksumAddress } = require('web3-utils') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log } = require('../helpers/log') const { assertLastEvent } = require('../helpers/events') -const { readNetworkState, persistNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') +const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') const { APP_NAMES } = require('../constants') const VALID_APP_NAMES = Object.entries(APP_NAMES).map((e) => e[1]) @@ -76,11 +72,13 @@ async function issueTokens({ web3, artifacts }) { endTotalSupply.iadd(bigSum(iAmounts)) - await log.makeTx(template, 'issueTokens', + await makeTx(template, 'issueTokens', [iHolders, iAmounts, vesting.start, vesting.cliff, vesting.end, vesting.revokable, '0x' + endTotalSupply.toString(16)] , { from: state.deployer }, ) } + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } function bigSum(amounts, initialAmount = 0) { diff --git a/scripts/scratch/11-finalize-dao.js b/scripts/scratch/11-finalize-dao.js index f5c24f861..c0ae3a41a 100644 --- a/scripts/scratch/11-finalize-dao.js +++ b/scripts/scratch/11-finalize-dao.js @@ -5,6 +5,7 @@ const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log } = require('../helpers/log') const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') const { assertLastEvent } = require('../helpers/events') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const { APP_NAMES } = require('../constants') const { assertVesting } = require('./checks/dao-token') @@ -62,14 +63,15 @@ async function finalizeDAO({ web3, artifacts }) { unvestedTokensAmount: '0' // since we're minting them during the finalizeDAO call below } }) - log.splitter() - await log.makeTx(template, 'finalizeDAO', [ + await makeTx(template, 'finalizeDAO', [ state.daoAragonId, state.vestingParams.unvestedTokensAmount, state.stakingRouter.proxy.address ], { from: state.deployer }) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(finalizeDAO, module) diff --git a/scripts/scratch/12-check-dao.js b/scripts/scratch/12-check-dao.js index 08ed67e12..d97b49625 100644 --- a/scripts/scratch/12-check-dao.js +++ b/scripts/scratch/12-check-dao.js @@ -4,7 +4,6 @@ const BN = require('bn.js') const { assertBn } = require('@aragon/contract-helpers-test/src/asserts') const { getEvents } = require('@aragon/contract-helpers-test') const { hash: namehash } = require('eth-ens-namehash') -const { toChecksumAddress } = require('web3-utils') const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log, yl } = require('../helpers/log') @@ -170,6 +169,8 @@ async function checkDAO({ web3, artifacts }) { }) log.splitter() + + console.log(`Total gas used during scratch deployment: ${state.initialDeployTotalGasUsed}`) } async function assertLidoAPMPermissions({ registry, votingAddress }, fromBlock = 4532202) { diff --git a/scripts/scratch/13-deploy-non-aragon-contracts.js b/scripts/scratch/13-deploy-non-aragon-contracts.js index 6339ef405..e9c4c58e1 100644 --- a/scripts/scratch/13-deploy-non-aragon-contracts.js +++ b/scripts/scratch/13-deploy-non-aragon-contracts.js @@ -1,7 +1,7 @@ const runOrWrapScript = require('../helpers/run-or-wrap-script') -const { log, logSplitter, logWideSplitter, yl, gr } = require('../helpers/log') +const { log, logWideSplitter, yl, gr } = require('../helpers/log') const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') -const { deployWithoutProxy, deployBehindOssifiableProxy, updateProxyImplementation, deployImplementation, deployContract, getContractPath } = require('../helpers/deploy') +const { deployWithoutProxy, deployBehindOssifiableProxy, updateProxyImplementation, deployImplementation, deployContract, getContractPath, TotalGasCounter } = require('../helpers/deploy') const { APP_NAMES } = require('../constants') @@ -268,6 +268,8 @@ async function deployNewContracts({ web3, artifacts }) { oracleDaemonConfigAddress, ] await updateProxyImplementation("lidoLocator", "LidoLocator", locatorAddress, proxyContractsOwner, [locatorConfig]) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(deployNewContracts, module) diff --git a/scripts/scratch/13-gate-seal.js b/scripts/scratch/13-gate-seal.js index f13b6280d..0c92a42b8 100644 --- a/scripts/scratch/13-gate-seal.js +++ b/scripts/scratch/13-gate-seal.js @@ -2,6 +2,7 @@ const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log, logSplitter, logWideSplitter, yl, gr } = require('../helpers/log') const { readNetworkState, assertRequiredNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') const { getEventArgument } = require('@aragon/contract-helpers-test') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const { APP_NAMES } = require('../constants') @@ -33,7 +34,7 @@ async function deployNewContracts({ web3, artifacts }) { const GateSealFactory = await artifacts.require("IGateSealFactory") const gateSealFactory = await GateSealFactory.at(gateSealFactoryAddress) - const receipt = await log.makeTx(gateSealFactory, "create_gate_seal", [ + const receipt = await makeTx(gateSealFactory, "create_gate_seal", [ state.gateSeal.sealingCommittee, state.gateSeal.sealDuration, sealables, @@ -43,6 +44,8 @@ async function deployNewContracts({ web3, artifacts }) { console.log(`GateSeal created: ${gateSealAddress}`) state.gateSeal.address = gateSealAddress persistNetworkState(network.name, netId, state) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(deployNewContracts, module) diff --git a/scripts/scratch/14-initialize-non-aragon-contracts.js b/scripts/scratch/14-initialize-non-aragon-contracts.js index 406525b98..e4c0c5150 100644 --- a/scripts/scratch/14-initialize-non-aragon-contracts.js +++ b/scripts/scratch/14-initialize-non-aragon-contracts.js @@ -1,8 +1,9 @@ const runOrWrapScript = require('../helpers/run-or-wrap-script') -const { log, logSplitter, logWideSplitter, yl, gr } = require('../helpers/log') +const { log, logWideSplitter, yl, gr } = require('../helpers/log') const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') const { hexPaddedToByte } = require('../../test/helpers/utils') const { APP_NAMES } = require('../constants') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const DEPLOYER = process.env.DEPLOYER || '' @@ -72,7 +73,7 @@ async function deployNewContracts({ web3, artifacts }) { nodeOperatorsRegistryParams.stuckPenaltyDelay, ] const nodeOperatorsRegistry = await artifacts.require('NodeOperatorsRegistry').at(nodeOperatorsRegistryAddress) - await log.makeTx(nodeOperatorsRegistry, 'initialize', nodeOperatorsRegistryArgs, { from: DEPLOYER }) + await makeTx(nodeOperatorsRegistry, 'initialize', nodeOperatorsRegistryArgs, { from: DEPLOYER }) // // === Lido: initialize === @@ -83,7 +84,7 @@ async function deployNewContracts({ web3, artifacts }) { ] const bootstrapInitBalance = 10 // wei const lido = await artifacts.require('Lido').at(lidoAddress) - await log.makeTx(lido, 'initialize', lidoInitArgs, { value: bootstrapInitBalance, from: DEPLOYER }) + await makeTx(lido, 'initialize', lidoInitArgs, { value: bootstrapInitBalance, from: DEPLOYER }) logWideSplitter() // @@ -94,7 +95,7 @@ async function deployNewContracts({ web3, artifacts }) { hashConsensusForAccountingAddress, ] const legacyOracle = await artifacts.require('LegacyOracle').at(legacyOracleAddress) - await log.makeTx(legacyOracle, 'initialize', legacyOracleArgs, { from: DEPLOYER }) + await makeTx(legacyOracle, 'initialize', legacyOracleArgs, { from: DEPLOYER }) const zeroLastProcessingRefSlot = 0 @@ -109,7 +110,7 @@ async function deployNewContracts({ web3, artifacts }) { accountingOracleParams.consensusVersion, zeroLastProcessingRefSlot, ] - await log.makeTx(accountingOracle, 'initializeWithoutMigration', accountingOracleArgs, { from: DEPLOYER }) + await makeTx(accountingOracle, 'initializeWithoutMigration', accountingOracleArgs, { from: DEPLOYER }) // // === ValidatorsExitBusOracle: initialize === @@ -121,7 +122,7 @@ async function deployNewContracts({ web3, artifacts }) { validatorsExitBusOracleParams.consensusVersion, zeroLastProcessingRefSlot, ] - await log.makeTx(validatorsExitBusOracle, 'initialize', validatorsExitBusOracleArgs, { from: DEPLOYER }) + await makeTx(validatorsExitBusOracle, 'initialize', validatorsExitBusOracleArgs, { from: DEPLOYER }) // // === WithdrawalQueue initialize === @@ -130,7 +131,7 @@ async function deployNewContracts({ web3, artifacts }) { withdrawalQueueAdmin, // _admin ] const withdrawalQueue = await artifacts.require('WithdrawalQueueERC721').at(withdrawalQueueAddress) - await log.makeTx(withdrawalQueue, 'initialize', withdrawalQueueArgs, { from: DEPLOYER }) + await makeTx(withdrawalQueue, 'initialize', withdrawalQueueArgs, { from: DEPLOYER }) // // === StakingRouter: initialize === @@ -142,7 +143,7 @@ async function deployNewContracts({ web3, artifacts }) { withdrawalCredentials, // _withdrawalCredentials ] const stakingRouter = await artifacts.require('StakingRouter').at(stakingRouterAddress) - await log.makeTx(stakingRouter, 'initialize', stakingRouterArgs, { from: DEPLOYER }) + await makeTx(stakingRouter, 'initialize', stakingRouterArgs, { from: DEPLOYER }) logWideSplitter() // @@ -150,11 +151,13 @@ async function deployNewContracts({ web3, artifacts }) { // const oracleDaemonConfig = await artifacts.require('OracleDaemonConfig').at(oracleDaemonConfigAddress) const CONFIG_MANAGER_ROLE = await oracleDaemonConfig.CONFIG_MANAGER_ROLE() - await log.makeTx(oracleDaemonConfig, 'grantRole', [CONFIG_MANAGER_ROLE, testnetAdmin], { from: testnetAdmin }) + await makeTx(oracleDaemonConfig, 'grantRole', [CONFIG_MANAGER_ROLE, testnetAdmin], { from: testnetAdmin }) for (const [key, value] of Object.entries(state.oracleDaemonConfig.deployParameters)) { - await log.makeTx(oracleDaemonConfig, 'set', [key, hexPaddedToByte(value)], { from: DEPLOYER }) + await makeTx(oracleDaemonConfig, 'set', [key, hexPaddedToByte(value)], { from: DEPLOYER }) } - await log.makeTx(oracleDaemonConfig, 'renounceRole', [CONFIG_MANAGER_ROLE, testnetAdmin], { from: testnetAdmin }) + await makeTx(oracleDaemonConfig, 'renounceRole', [CONFIG_MANAGER_ROLE, testnetAdmin], { from: testnetAdmin }) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(deployNewContracts, module) diff --git a/scripts/scratch/15-grant-roles.js b/scripts/scratch/15-grant-roles.js index a9d7eb770..ee8611d8e 100644 --- a/scripts/scratch/15-grant-roles.js +++ b/scripts/scratch/15-grant-roles.js @@ -3,6 +3,7 @@ const { log, logSplitter, logWideSplitter, yl, gr } = require('../helpers/log') const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') const { APP_NAMES } = require('../constants') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const REQUIRED_NET_STATE = [ @@ -51,25 +52,25 @@ async function deployNewContracts({ web3, artifacts }) { // === StakingRouter // const stakingRouter = await artifacts.require('StakingRouter').at(stakingRouterAddress) - await log.makeTx(stakingRouter, 'grantRole', [await stakingRouter.STAKING_MODULE_PAUSE_ROLE(), depositSecurityModuleAddress], { from: deployer }) - await log.makeTx(stakingRouter, 'grantRole', [await stakingRouter.REPORT_EXITED_VALIDATORS_ROLE(), accountingOracleAddress], { from: deployer }) - await log.makeTx(stakingRouter, 'grantRole', [await stakingRouter.REPORT_REWARDS_MINTED_ROLE(), lidoAddress], { from: deployer }) + await makeTx(stakingRouter, 'grantRole', [await stakingRouter.STAKING_MODULE_PAUSE_ROLE(), depositSecurityModuleAddress], { from: deployer }) + await makeTx(stakingRouter, 'grantRole', [await stakingRouter.REPORT_EXITED_VALIDATORS_ROLE(), accountingOracleAddress], { from: deployer }) + await makeTx(stakingRouter, 'grantRole', [await stakingRouter.REPORT_REWARDS_MINTED_ROLE(), lidoAddress], { from: deployer }) logWideSplitter() // // === ValidatorsExitBusOracle // const validatorsExitBusOracle = await artifacts.require('ValidatorsExitBusOracle').at(validatorsExitBusOracleAddress) - await log.makeTx(validatorsExitBusOracle, 'grantRole', [await validatorsExitBusOracle.PAUSE_ROLE(), gateSealAddress], { from: deployer }) + await makeTx(validatorsExitBusOracle, 'grantRole', [await validatorsExitBusOracle.PAUSE_ROLE(), gateSealAddress], { from: deployer }) logWideSplitter() // // === WithdrawalQueue // const withdrawalQueue = await artifacts.require('WithdrawalQueueERC721').at(withdrawalQueueAddress) - await log.makeTx(withdrawalQueue, 'grantRole', [await withdrawalQueue.PAUSE_ROLE(), gateSealAddress], { from: deployer }) - await log.makeTx(withdrawalQueue, 'grantRole', [await withdrawalQueue.FINALIZE_ROLE(), lidoAddress], { from: deployer }) - await log.makeTx(withdrawalQueue, 'grantRole', [await withdrawalQueue.ORACLE_ROLE(), accountingOracleAddress], { from: deployer }) + await makeTx(withdrawalQueue, 'grantRole', [await withdrawalQueue.PAUSE_ROLE(), gateSealAddress], { from: deployer }) + await makeTx(withdrawalQueue, 'grantRole', [await withdrawalQueue.FINALIZE_ROLE(), lidoAddress], { from: deployer }) + await makeTx(withdrawalQueue, 'grantRole', [await withdrawalQueue.ORACLE_ROLE(), accountingOracleAddress], { from: deployer }) logWideSplitter() // @@ -77,8 +78,9 @@ async function deployNewContracts({ web3, artifacts }) { // const burner = await artifacts.require('Burner').at(burnerAddress) // NB: REQUEST_BURN_SHARES_ROLE is already granted to Lido in Burner constructor - await log.makeTx(burner, 'grantRole', [await burner.REQUEST_BURN_SHARES_ROLE(), nodeOperatorsRegistryAddress], { from: deployer }) + await makeTx(burner, 'grantRole', [await burner.REQUEST_BURN_SHARES_ROLE(), nodeOperatorsRegistryAddress], { from: deployer }) + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(deployNewContracts, module) diff --git a/scripts/scratch/16-plug-curated-staking-module.js b/scripts/scratch/16-plug-curated-staking-module.js index 66ee12a71..d1cd011df 100644 --- a/scripts/scratch/16-plug-curated-staking-module.js +++ b/scripts/scratch/16-plug-curated-staking-module.js @@ -3,6 +3,7 @@ const { log, logSplitter, logWideSplitter, yl, gr } = require('../helpers/log') const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') const { APP_NAMES } = require('../constants') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const REQUIRED_NET_STATE = [ @@ -43,16 +44,18 @@ async function deployNewContracts({ web3, artifacts }) { const stakingRouter = await artifacts.require('StakingRouter').at(state.stakingRouter.proxy.address) const nodeOperatorsRegistry = await artifacts.require('NodeOperatorsRegistry').at(state['app:node-operators-registry'].proxy.address) - await log.makeTx(stakingRouter, 'grantRole', [STAKING_MODULE_MANAGE_ROLE, deployer], { from: deployer }) + await makeTx(stakingRouter, 'grantRole', [STAKING_MODULE_MANAGE_ROLE, deployer], { from: deployer }) - await log.makeTx(stakingRouter, 'addStakingModule', [ + await makeTx(stakingRouter, 'addStakingModule', [ state.nodeOperatorsRegistry.deployParameters.stakingModuleTypeId, nodeOperatorsRegistry.address, NOR_STAKING_MODULE_TARGET_SHARE_BP, NOR_STAKING_MODULE_MODULE_FEE_BP, NOR_STAKING_MODULE_TREASURY_FEE_BP, ], { from: deployer }) - await log.makeTx(stakingRouter, 'renounceRole', [STAKING_MODULE_MANAGE_ROLE, deployer], { from: deployer }) + await makeTx(stakingRouter, 'renounceRole', [STAKING_MODULE_MANAGE_ROLE, deployer], { from: deployer }) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(deployNewContracts, module) diff --git a/scripts/scratch/17-transfer-roles.js b/scripts/scratch/17-transfer-roles.js index 3a2637509..ae1cf7c15 100644 --- a/scripts/scratch/17-transfer-roles.js +++ b/scripts/scratch/17-transfer-roles.js @@ -1,6 +1,7 @@ const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log, logSplitter, logWideSplitter, yl, gr, OK } = require('../helpers/log') const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') +const { makeTx, TotalGasCounter } = require('../helpers/deploy') const REQUIRED_NET_STATE = [ "app:aragon-agent", @@ -21,22 +22,22 @@ const DEFAULT_ADMIN_ROLE = "0x00" async function transferOZAdmin(contractName, contractAddress, currentAdmin, newAdmin) { console.log(`Transferring OZ admin of ${contractAddress} from ${currentAdmin} to ${newAdmin}:`) const contract = await artifacts.require(contractName).at(contractAddress) - await log.makeTx(contract, 'grantRole', [DEFAULT_ADMIN_ROLE, newAdmin], { from: currentAdmin }) - await log.makeTx(contract, 'renounceRole', [DEFAULT_ADMIN_ROLE, currentAdmin], { from: currentAdmin }) + await makeTx(contract, 'grantRole', [DEFAULT_ADMIN_ROLE, newAdmin], { from: currentAdmin }) + await makeTx(contract, 'renounceRole', [DEFAULT_ADMIN_ROLE, currentAdmin], { from: currentAdmin }) console.log() } async function changeOssifiableProxyAdmin(contractAddress, currentAdmin, newAdmin) { console.log(`Transferring OssifiableProxy admin of ${contractAddress} from ${currentAdmin} to ${newAdmin}...`) const contract = await artifacts.require('OssifiableProxy').at(contractAddress) - await log.makeTx(contract, 'proxy__changeAdmin', [newAdmin], { from: currentAdmin }) + await makeTx(contract, 'proxy__changeAdmin', [newAdmin], { from: currentAdmin }) console.log() } async function changeDepositSecurityModuleAdmin(contractAddress, currentAdmin, newAdmin) { console.log(`Changing DepositSecurityModule owner of ${contractAddress} from ${currentAdmin} to ${newAdmin}...`) const depositSecurityModule = await artifacts.require('DepositSecurityModule').at(contractAddress) - await log.makeTx(depositSecurityModule, 'setOwner', [newAdmin], { from: currentAdmin } ) + await makeTx(depositSecurityModule, 'setOwner', [newAdmin], { from: currentAdmin } ) console.log() } @@ -67,6 +68,8 @@ async function deployNewContracts({ web3, artifacts }) { await changeOssifiableProxyAdmin(state.withdrawalQueueERC721.proxy.address, deployer, agent) await changeDepositSecurityModuleAdmin(state.depositSecurityModule.address, deployer, agent) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } module.exports = runOrWrapScript(deployNewContracts, module) diff --git a/scripts/scratch/deploy-aragon-env.js b/scripts/scratch/deploy-aragon-env.js index 6e674d589..8b1de9522 100644 --- a/scripts/scratch/deploy-aragon-env.js +++ b/scripts/scratch/deploy-aragon-env.js @@ -5,7 +5,7 @@ const getAccounts = require('@aragon/os/scripts/helpers/get-accounts') const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log, logSplitter, logWideSplitter, logHeader, logTx } = require('../helpers/log') -const { deploy, useOrDeploy, withArgs, deployImplementation } = require('../helpers/deploy') +const { deploy, useOrDeploy, withArgs, deployImplementation, TotalGasCounter } = require('../helpers/deploy') const { readNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') const { deployAPM } = require('../components/apm') @@ -167,6 +167,8 @@ async function deployAragonEnv({ web3, artifacts, networkStateFile = NETWORK_STA constructorArgs: aragonID.constructorArgs, } persistNetworkState(network.name, netId, state) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } async function useOrDeployENS({ artifacts, owner, ensAddress }) { diff --git a/scripts/scratch/deploy-aragon-std-apps.js b/scripts/scratch/deploy-aragon-std-apps.js index e4e9b3b1e..33534cc5c 100644 --- a/scripts/scratch/deploy-aragon-std-apps.js +++ b/scripts/scratch/deploy-aragon-std-apps.js @@ -1,9 +1,6 @@ - - const runOrWrapScript = require('../helpers/run-or-wrap-script') const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state') -const { deployImplementation } = require('../helpers/deploy') - +const { deployImplementation, TotalGasCounter } = require('../helpers/deploy') const REQUIRED_NET_STATE = [ 'deployer', @@ -19,6 +16,8 @@ async function deployAragonStdApps({ web3, artifacts, }) { await deployImplementation("app:aragon-finance", "Finance", deployer) await deployImplementation("app:aragon-token-manager", "TokenManager", deployer) await deployImplementation("app:aragon-voting", "Voting", deployer) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } diff --git a/scripts/scratch/deploy-deposit-contract.js b/scripts/scratch/deploy-deposit-contract.js index 9cd486355..ec72f029f 100644 --- a/scripts/scratch/deploy-deposit-contract.js +++ b/scripts/scratch/deploy-deposit-contract.js @@ -2,7 +2,7 @@ const chalk = require('chalk') const runOrWrapScript = require('../helpers/run-or-wrap-script') const { log, logSplitter, logWideSplitter } = require('../helpers/log') -const { deploy, withArgs } = require('../helpers/deploy') +const { deployWithoutProxy, TotalGasCounter } = require('../helpers/deploy') const { readNetworkState, persistNetworkState } = require('../helpers/persisted-network-state') const NETWORK_STATE_FILE = process.env.NETWORK_STATE_FILE || 'deployed.json' @@ -20,25 +20,26 @@ async function deployBeaconDepositContract({ web3, artifacts, networkStateFile = if (chainSpec.depositContract) { depositContractAddress = chainSpec.depositContract } - const { depositContract } = await useOrDeployDepositContract({ + depositContractAddress = await useOrDeployDepositContract({ artifacts, owner: firstAccount, - depositContractAddress: depositContractAddress, + depositContractAddress, }) - chainSpec.depositContract = depositContract.address + state.chainSpec.depositContract = depositContractAddress + persistNetworkState(network.name, netId, state) logSplitter() - persistNetworkState(network.name, netId, state, { chainSpec }) + + await TotalGasCounter.incrementTotalGasUsedInStateFile() } async function useOrDeployDepositContract({ artifacts, owner, depositContractAddress }) { if (depositContractAddress) { log(`Using DepositContract at: ${chalk.yellow(depositContractAddress)}`) const depositContract = await artifacts.require('DepositContract').at(depositContractAddress) - return { depositContract } + return depositContract.address } - const depositContract = await deploy('DepositContract', artifacts, withArgs({ from: owner })) - return { depositContract } + return await deployWithoutProxy('depositContract', 'DepositContract', owner) } module.exports = runOrWrapScript(deployBeaconDepositContract, module)