From ede02e7670c3af1bbc6aeb54130bb94622613f8f Mon Sep 17 00:00:00 2001 From: Yuri Tkachenko Date: Fri, 4 Oct 2024 17:19:45 +0100 Subject: [PATCH] chore: remove duplication in getting contracts --- lib/contract.ts | 5 ----- lib/deploy.ts | 10 ++-------- .../scratch/steps/0020-deploy-aragon-env.ts | 4 ++-- scripts/scratch/steps/0060-create-app-repos.ts | 4 ++-- scripts/scratch/steps/0070-deploy-dao.ts | 6 +++--- scripts/scratch/steps/0080-issue-tokens.ts | 4 ++-- scripts/scratch/steps/0100-gate-seal.ts | 4 ++-- scripts/scratch/steps/0110-finalize-dao.ts | 4 ++-- .../0120-initialize-non-aragon-contracts.ts | 18 +++++++++--------- scripts/scratch/steps/0130-grant-roles.ts | 10 +++++----- .../steps/0140-plug-curated-staking-module.ts | 6 +++--- scripts/scratch/steps/0150-transfer-roles.ts | 8 ++++---- scripts/upgrade/steps/0000-deploy-locator.ts | 7 +++++-- 13 files changed, 41 insertions(+), 49 deletions(-) diff --git a/lib/contract.ts b/lib/contract.ts index 9503d5a6a..a52d4afc7 100644 --- a/lib/contract.ts +++ b/lib/contract.ts @@ -45,11 +45,6 @@ export async function loadContract( return (await addContractHelperFields(result, name)) as unknown as LoadedContract; } -export async function getContractAt(name: string, address: string): Promise { - const contract = await ethers.getContractAt(name, address); - return await addContractHelperFields(contract, name); -} - export async function getContractPath(contractName: string) { const artifact = await artifacts.readArtifact(contractName); return artifact.sourceName; diff --git a/lib/deploy.ts b/lib/deploy.ts index b544fe5a3..a44266eba 100644 --- a/lib/deploy.ts +++ b/lib/deploy.ts @@ -1,13 +1,7 @@ import { ContractFactory, ContractTransactionReceipt } from "ethers"; import { ethers } from "hardhat"; -import { - addContractHelperFields, - DeployedContract, - getContractAt, - getContractPath, - LoadedContract, -} from "lib/contract"; +import { addContractHelperFields, DeployedContract, getContractPath, loadContract, LoadedContract } from "lib/contract"; import { ConvertibleToString, cy, gr, log, yl } from "lib/log"; import { incrementGasUsed, Sk, updateObjectInState } from "lib/state-file"; @@ -212,7 +206,7 @@ export async function updateProxyImplementation( const implementation = await deployContract(artifactName, constructorArgs, proxyOwner); - const proxy = await getContractAt(PROXY_CONTRACT_NAME, proxyAddress); + const proxy = await loadContract(PROXY_CONTRACT_NAME, proxyAddress); await makeTx(proxy, "proxy__upgradeTo", [implementation.address], { from: proxyOwner }); updateObjectInState(nameInState, { diff --git a/scripts/scratch/steps/0020-deploy-aragon-env.ts b/scripts/scratch/steps/0020-deploy-aragon-env.ts index 8a7b2e325..7d3996216 100644 --- a/scripts/scratch/steps/0020-deploy-aragon-env.ts +++ b/scripts/scratch/steps/0020-deploy-aragon-env.ts @@ -3,7 +3,7 @@ import { ethers } from "hardhat"; import { DAOFactory, ENS } from "typechain-types"; -import { getContractAt, loadContract, LoadedContract } from "lib/contract"; +import { loadContract, LoadedContract } from "lib/contract"; import { deployImplementation, deployWithoutProxy, makeTx } from "lib/deploy"; import { assignENSName } from "lib/ens"; import { findEvents } from "lib/event"; @@ -33,7 +33,7 @@ async function deployAPM( log(`Using APMRegistry: ${cy(apmAddress)}`); log.emptyLine(); - const apmRegistry = await getContractAt("APMRegistry", apmAddress); + const apmRegistry = await loadContract("APMRegistry", apmAddress); return { apmRegistry, diff --git a/scripts/scratch/steps/0060-create-app-repos.ts b/scripts/scratch/steps/0060-create-app-repos.ts index 7dddd51ed..3bb9b7239 100644 --- a/scripts/scratch/steps/0060-create-app-repos.ts +++ b/scripts/scratch/steps/0060-create-app-repos.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib/contract"; import { makeTx } from "lib/deploy"; import { readNetworkState, setValueInState, Sk } from "lib/state-file"; @@ -11,7 +11,7 @@ export async function main() { const deployer = (await ethers.provider.getSigner()).address; const state = readNetworkState({ deployer }); - const template = await getContractAt("LidoTemplate", state[Sk.lidoTemplate].address); + const template = await loadContract("LidoTemplate", state[Sk.lidoTemplate].address); // Create Lido app repos const lidoAppsReceipt = await makeTx( diff --git a/scripts/scratch/steps/0070-deploy-dao.ts b/scripts/scratch/steps/0070-deploy-dao.ts index fc426469a..baab075ee 100644 --- a/scripts/scratch/steps/0070-deploy-dao.ts +++ b/scripts/scratch/steps/0070-deploy-dao.ts @@ -4,7 +4,7 @@ import { ethers } from "hardhat"; import { ERCProxy, EVMScriptRegistryFactory, Kernel } from "typechain-types"; -import { getContractAt, getContractPath, loadContract, LoadedContract } from "lib/contract"; +import { getContractPath, loadContract, LoadedContract } from "lib/contract"; import { makeTx } from "lib/deploy"; import { findEvents, findEventsWithInterfaces } from "lib/event"; import { cy, log, yl } from "lib/log"; @@ -192,7 +192,7 @@ async function saveStateFromNewDAOTx(newDAOReceipt: ContractTransactionReceipt) appName = Sk.aragonEvmScriptRegistry; } - const proxy = await getContractAt(proxyContractName, e.args.proxy); + const proxy = await loadContract(proxyContractName, e.args.proxy); state[appName] = { ...state[appName], @@ -225,7 +225,7 @@ export async function main() { const deployer = (await ethers.provider.getSigner()).address; const state = readNetworkState({ deployer }); - const template = await getContractAt("LidoTemplate", state[Sk.lidoTemplate].address); + const template = await loadContract("LidoTemplate", state[Sk.lidoTemplate].address); if (state[Sk.lidoTemplate].deployBlock) { log(`Using LidoTemplate deploy block: ${yl(state.lidoTemplate.deployBlock)}`); } diff --git a/scripts/scratch/steps/0080-issue-tokens.ts b/scripts/scratch/steps/0080-issue-tokens.ts index 6cbb05364..333b4ee3b 100644 --- a/scripts/scratch/steps/0080-issue-tokens.ts +++ b/scripts/scratch/steps/0080-issue-tokens.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib"; import { makeTx } from "lib/deploy"; import { cy, log, yl } from "lib/log"; import { readNetworkState, Sk } from "lib/state-file"; @@ -47,7 +47,7 @@ export async function main() { log(` Total batches:`, yl(totalTransactions)); log.emptyLine(); - const template = await getContractAt("LidoTemplate", state[Sk.lidoTemplate].address); + const template = await loadContract("LidoTemplate", state[Sk.lidoTemplate].address); let endTotalSupply = 0n; // Issue tokens in batches diff --git a/scripts/scratch/steps/0100-gate-seal.ts b/scripts/scratch/steps/0100-gate-seal.ts index 038ec2535..c19051a65 100644 --- a/scripts/scratch/steps/0100-gate-seal.ts +++ b/scripts/scratch/steps/0100-gate-seal.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib"; import { makeTx } from "lib/deploy"; import { findEvents } from "lib/event"; import { cy, log } from "lib/log"; @@ -26,7 +26,7 @@ export async function main() { // Create new GateSeal instance const sealableContracts = [state.withdrawalQueueERC721.proxy.address, state.validatorsExitBusOracle.proxy.address]; - const gateSealFactory = await getContractAt("IGateSealFactory", state[Sk.gateSeal].factoryAddress); + const gateSealFactory = await loadContract("IGateSealFactory", state[Sk.gateSeal].factoryAddress); const receipt = await makeTx( gateSealFactory, diff --git a/scripts/scratch/steps/0110-finalize-dao.ts b/scripts/scratch/steps/0110-finalize-dao.ts index 59a32d418..5c5f28f83 100644 --- a/scripts/scratch/steps/0110-finalize-dao.ts +++ b/scripts/scratch/steps/0110-finalize-dao.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib/contract"; import { makeTx } from "lib/deploy"; import { readNetworkState, Sk } from "lib/state-file"; @@ -8,7 +8,7 @@ export async function main() { const deployer = (await ethers.provider.getSigner()).address; const state = readNetworkState({ deployer }); - const template = await getContractAt("LidoTemplate", state[Sk.lidoTemplate].address); + const template = await loadContract("LidoTemplate", state[Sk.lidoTemplate].address); // Finalize the DAO by calling the finalizeDAO function on the template await makeTx( diff --git a/scripts/scratch/steps/0120-initialize-non-aragon-contracts.ts b/scripts/scratch/steps/0120-initialize-non-aragon-contracts.ts index e3ddadb46..e88628697 100644 --- a/scripts/scratch/steps/0120-initialize-non-aragon-contracts.ts +++ b/scripts/scratch/steps/0120-initialize-non-aragon-contracts.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib/contract"; import { makeTx } from "lib/deploy"; import { readNetworkState, Sk } from "lib/state-file"; import { en0x } from "lib/string"; @@ -41,7 +41,7 @@ export async function main() { "0x" + ethers.AbiCoder.defaultAbiCoder().encode(["string"], [nodeOperatorsRegistryParams.stakingModuleTypeId]).slice(-64); - const nodeOperatorsRegistry = await getContractAt("NodeOperatorsRegistry", nodeOperatorsRegistryAddress); + const nodeOperatorsRegistry = await loadContract("NodeOperatorsRegistry", nodeOperatorsRegistryAddress); await makeTx( nodeOperatorsRegistry, "initialize", @@ -51,20 +51,20 @@ export async function main() { // Initialize Lido const bootstrapInitBalance = 10n; // wei - const lido = await getContractAt("Lido", lidoAddress); + const lido = await loadContract("Lido", lidoAddress); await makeTx(lido, "initialize", [lidoLocatorAddress, eip712StETHAddress], { value: bootstrapInitBalance, from: deployer, }); // Initialize LegacyOracle - const legacyOracle = await getContractAt("LegacyOracle", legacyOracleAddress); + const legacyOracle = await loadContract("LegacyOracle", legacyOracleAddress); await makeTx(legacyOracle, "initialize", [lidoLocatorAddress, hashConsensusForAccountingAddress], { from: deployer }); const zeroLastProcessingRefSlot = 0; // Initialize AccountingOracle - const accountingOracle = await getContractAt("AccountingOracle", accountingOracleAddress); + const accountingOracle = await loadContract("AccountingOracle", accountingOracleAddress); await makeTx( accountingOracle, "initializeWithoutMigration", @@ -78,7 +78,7 @@ export async function main() { ); // Initialize ValidatorsExitBusOracle - const validatorsExitBusOracle = await getContractAt("ValidatorsExitBusOracle", ValidatorsExitBusOracleAddress); + const validatorsExitBusOracle = await loadContract("ValidatorsExitBusOracle", ValidatorsExitBusOracleAddress); await makeTx( validatorsExitBusOracle, "initialize", @@ -92,7 +92,7 @@ export async function main() { ); // Initialize WithdrawalQueue - const withdrawalQueue = await getContractAt("WithdrawalQueueERC721", withdrawalQueueAddress); + const withdrawalQueue = await loadContract("WithdrawalQueueERC721", withdrawalQueueAddress); await makeTx(withdrawalQueue, "initialize", [withdrawalQueueAdmin], { from: deployer }); // Set WithdrawalQueue base URI if provided @@ -106,13 +106,13 @@ export async function main() { // Initialize StakingRouter const withdrawalCredentials = `0x010000000000000000000000${withdrawalVaultAddress.slice(2)}`; - const stakingRouter = await getContractAt("StakingRouter", stakingRouterAddress); + const stakingRouter = await loadContract("StakingRouter", stakingRouterAddress); await makeTx(stakingRouter, "initialize", [stakingRouterAdmin, lidoAddress, withdrawalCredentials], { from: deployer, }); // Set OracleDaemonConfig parameters - const oracleDaemonConfig = await getContractAt("OracleDaemonConfig", oracleDaemonConfigAddress); + const oracleDaemonConfig = await loadContract("OracleDaemonConfig", oracleDaemonConfigAddress); const CONFIG_MANAGER_ROLE = await oracleDaemonConfig.getFunction("CONFIG_MANAGER_ROLE")(); await makeTx(oracleDaemonConfig, "grantRole", [CONFIG_MANAGER_ROLE, testnetAdmin], { from: testnetAdmin }); diff --git a/scripts/scratch/steps/0130-grant-roles.ts b/scripts/scratch/steps/0130-grant-roles.ts index 4a364dd65..39c073b7a 100644 --- a/scripts/scratch/steps/0130-grant-roles.ts +++ b/scripts/scratch/steps/0130-grant-roles.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib/contract"; import { makeTx } from "lib/deploy"; import { log } from "lib/log"; import { readNetworkState, Sk } from "lib/state-file"; @@ -20,7 +20,7 @@ export async function main() { const depositSecurityModuleAddress = state[Sk.depositSecurityModule].address; // StakingRouter - const stakingRouter = await getContractAt("StakingRouter", stakingRouterAddress); + const stakingRouter = await loadContract("StakingRouter", stakingRouterAddress); await makeTx( stakingRouter, "grantRole", @@ -48,7 +48,7 @@ export async function main() { // ValidatorsExitBusOracle if (gateSealAddress) { - const validatorsExitBusOracle = await getContractAt("ValidatorsExitBusOracle", validatorsExitBusOracleAddress); + const validatorsExitBusOracle = await loadContract("ValidatorsExitBusOracle", validatorsExitBusOracleAddress); await makeTx( validatorsExitBusOracle, "grantRole", @@ -61,7 +61,7 @@ export async function main() { } // WithdrawalQueue - const withdrawalQueue = await getContractAt("WithdrawalQueueERC721", withdrawalQueueAddress); + const withdrawalQueue = await loadContract("WithdrawalQueueERC721", withdrawalQueueAddress); if (gateSealAddress) { await makeTx(withdrawalQueue, "grantRole", [await withdrawalQueue.getFunction("PAUSE_ROLE")(), gateSealAddress], { from: deployer, @@ -83,7 +83,7 @@ export async function main() { ); // Burner - const burner = await getContractAt("Burner", burnerAddress); + const burner = await loadContract("Burner", burnerAddress); // NB: REQUEST_BURN_SHARES_ROLE is already granted to Lido in Burner constructor await makeTx( burner, diff --git a/scripts/scratch/steps/0140-plug-curated-staking-module.ts b/scripts/scratch/steps/0140-plug-curated-staking-module.ts index 8e3dd7f1d..f9180f1f0 100644 --- a/scripts/scratch/steps/0140-plug-curated-staking-module.ts +++ b/scripts/scratch/steps/0140-plug-curated-staking-module.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib/contract"; import { makeTx } from "lib/deploy"; import { streccak } from "lib/keccak"; import { readNetworkState, Sk } from "lib/state-file"; @@ -15,8 +15,8 @@ export async function main() { const state = readNetworkState({ deployer }); // Get contract instances - const stakingRouter = await getContractAt("StakingRouter", state.stakingRouter.proxy.address); - const nodeOperatorsRegistry = await getContractAt( + const stakingRouter = await loadContract("StakingRouter", state.stakingRouter.proxy.address); + const nodeOperatorsRegistry = await loadContract( "NodeOperatorsRegistry", state[Sk.appNodeOperatorsRegistry].proxy.address, ); diff --git a/scripts/scratch/steps/0150-transfer-roles.ts b/scripts/scratch/steps/0150-transfer-roles.ts index ee6a70b97..e7804196d 100644 --- a/scripts/scratch/steps/0150-transfer-roles.ts +++ b/scripts/scratch/steps/0150-transfer-roles.ts @@ -1,6 +1,6 @@ import { ethers } from "hardhat"; -import { getContractAt } from "lib/contract"; +import { loadContract } from "lib/contract"; import { makeTx } from "lib/deploy"; import { readNetworkState, Sk } from "lib/state-file"; @@ -26,7 +26,7 @@ export async function main() { ]; for (const contract of ozAdminTransfers) { - const contractInstance = await getContractAt(contract.name, contract.address); + const contractInstance = await loadContract(contract.name, contract.address); await makeTx(contractInstance, "grantRole", [DEFAULT_ADMIN_ROLE, agent], { from: deployer }); await makeTx(contractInstance, "renounceRole", [DEFAULT_ADMIN_ROLE, deployer], { from: deployer }); } @@ -41,13 +41,13 @@ export async function main() { ]; for (const proxyAddress of ossifiableProxyAdminChanges) { - const proxy = await getContractAt("OssifiableProxy", proxyAddress); + const proxy = await loadContract("OssifiableProxy", proxyAddress); await makeTx(proxy, "proxy__changeAdmin", [agent], { from: deployer }); } // Change DepositSecurityModule admin if not using predefined address if (state[Sk.depositSecurityModule].deployParameters.usePredefinedAddressInstead === null) { - const depositSecurityModule = await getContractAt("DepositSecurityModule", state.depositSecurityModule.address); + const depositSecurityModule = await loadContract("DepositSecurityModule", state.depositSecurityModule.address); await makeTx(depositSecurityModule, "setOwner", [agent], { from: deployer }); } } diff --git a/scripts/upgrade/steps/0000-deploy-locator.ts b/scripts/upgrade/steps/0000-deploy-locator.ts index 51dcabbf3..e548b1ca6 100644 --- a/scripts/upgrade/steps/0000-deploy-locator.ts +++ b/scripts/upgrade/steps/0000-deploy-locator.ts @@ -1,7 +1,10 @@ import { assert } from "chai"; import { ethers } from "hardhat"; -import { deployImplementation, getContractAt, LoadedContract, log, readNetworkState, Sk } from "lib"; +import { log } from "lib"; +import { loadContract, LoadedContract } from "lib/contract"; +import { deployImplementation } from "lib/deploy"; +import { readNetworkState, Sk } from "lib/state-file"; const VIEW_NAMES_AND_CTOR_ARGS = [ "accountingOracle", @@ -56,7 +59,7 @@ export async function main(): Promise { const state = readNetworkState(); const locatorAddress = state[Sk.lidoLocator].proxy.address; - const locator = await getContractAt("LidoLocator", locatorAddress); + const locator = await loadContract("LidoLocator", locatorAddress); const ctorArgs = await getConstructorArgs(locator); if (Object.keys(g_newAddresses).length === 0) {