From a50715ba2ad4182a7c4c121ebcb62c9966997858 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Tue, 22 Nov 2022 23:09:58 +0000 Subject: [PATCH] Make unnecessarily async functions sync (#2030) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: make unnecessarily async functions sync * docs: update readme to use new function signatures * chore: update changelog * Update pkg/deployments/CHANGELOG.md Co-authored-by: Nicolás Venturo Co-authored-by: Nicolás Venturo --- pkg/deployments/CHANGELOG.md | 4 ++++ pkg/deployments/README.md | 8 ++++---- pkg/deployments/index.ts | 10 +++++----- pkg/deployments/src/network.ts | 6 +++--- pkg/deployments/src/task.ts | 4 ++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/deployments/CHANGELOG.md b/pkg/deployments/CHANGELOG.md index 4a4ab1d272..14ab5569f4 100644 --- a/pkg/deployments/CHANGELOG.md +++ b/pkg/deployments/CHANGELOG.md @@ -11,6 +11,10 @@ - Deployed `AaveLinearPoolFactory` to all networks. - Deployed `PoolRecoveryHelper` to all networks. +### API Changes + +- Made `getBalancerContractAbi`, `getBalancerContractBytecode`, `getBalancerContractAddress` and `getBalancerDeployment` synchronous rather than asynchronous functions. + ## 3.0.0 (2022-10-25) ### New Deployments diff --git a/pkg/deployments/README.md b/pkg/deployments/README.md index 55b2d85529..5c31854fd6 100644 --- a/pkg/deployments/README.md +++ b/pkg/deployments/README.md @@ -47,19 +47,19 @@ Returns an [Ethers](https://docs.ethers.io/v5/) contract object for a contract d _Note: requires using [Hardhat](https://hardhat.org/) with the [`hardhat-ethers`](https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html) plugin._ -- **async function getBalancerContractAbi(taskID, contract)** +- **function getBalancerContractAbi(taskID, contract)** Returns a contract's [ABI](https://docs.soliditylang.org/en/latest/abi-spec.html). -- **async function getBalancerContractBytecode(taskID, contract)** +- **function getBalancerContractBytecode(taskID, contract)** Returns a contract's [creation code](https://docs.soliditylang.org/en/latest/contracts.html#creating-contracts). -- **async function getBalancerContractAddress(taskID, contract, network)** +- **function getBalancerContractAddress(taskID, contract, network)** Returns the address of a contract's canonical deployment. -- **async function getBalancerDeployment(taskID, network)** +- **function getBalancerDeployment(taskID, network)** Returns an object with all contracts from a deployment and their addresses. diff --git a/pkg/deployments/index.ts b/pkg/deployments/index.ts index ff2eab5942..a79c7dcff9 100644 --- a/pkg/deployments/index.ts +++ b/pkg/deployments/index.ts @@ -28,7 +28,7 @@ export async function getBalancerContractAt(task: string, contract: string, addr * @param task ID of the task to look the ABI of the required contract * @param contract Name of the contract to looking the ABI of */ -export async function getBalancerContractAbi(task: string, contract: string): Promise { +export function getBalancerContractAbi(task: string, contract: string): unknown[] { return require(getBalancerContractAbiPath(task, contract)); } @@ -37,7 +37,7 @@ export async function getBalancerContractAbi(task: string, contract: string): Pr * @param task ID of the task to look the creation code of the required contract * @param contract Name of the contract to looking the creation code of */ -export async function getBalancerContractBytecode(task: string, contract: string): Promise { +export function getBalancerContractBytecode(task: string, contract: string): string { // eslint-disable-next-line @typescript-eslint/no-var-requires return require(getBalancerContractBytecodePath(task, contract)).creationCode; } @@ -48,8 +48,8 @@ export async function getBalancerContractBytecode(task: string, contract: string * @param contract Name of the contract to fetched the address of * @param network Name of the network looking the deployment for (e.g. mainnet, rinkeby, ropsten, etc) */ -export async function getBalancerContractAddress(task: string, contract: string, network: string): Promise { - const output = await getBalancerDeployment(task, network); +export function getBalancerContractAddress(task: string, contract: string, network: string): string { + const output = getBalancerDeployment(task, network); return output[contract]; } @@ -58,7 +58,7 @@ export async function getBalancerContractAddress(task: string, contract: string, * @param task ID of the task to look the deployment output of the required network * @param network Name of the network looking the deployment output for (e.g. mainnet, rinkeby, ropsten, etc) */ -export async function getBalancerDeployment(task: string, network: string): Promise<{ [key: string]: string }> { +export function getBalancerDeployment(task: string, network: string): { [key: string]: string } { return require(getBalancerDeploymentPath(task, network)); } diff --git a/pkg/deployments/src/network.ts b/pkg/deployments/src/network.ts index 3580d6806d..51b6a6a01a 100644 --- a/pkg/deployments/src/network.ts +++ b/pkg/deployments/src/network.ts @@ -5,11 +5,11 @@ import { Network } from './types'; const DEPLOYMENT_TXS_DIRECTORY = path.resolve(__dirname, '../deployment-txs'); -export async function saveContractDeploymentTransactionHash( +export function saveContractDeploymentTransactionHash( deployedAddress: string, deploymentTransactionHash: string, network: Network -): Promise { +): void { if (network === 'hardhat') return; const filePath = path.join(DEPLOYMENT_TXS_DIRECTORY, `${network}.json`); @@ -24,7 +24,7 @@ export async function saveContractDeploymentTransactionHash( fs.writeFileSync(filePath, JSON.stringify(newFileContents, null, 2)); } -export async function getContractDeploymentTransactionHash(deployedAddress: string, network: Network): Promise { +export function getContractDeploymentTransactionHash(deployedAddress: string, network: Network): string { const filePath = path.join(DEPLOYMENT_TXS_DIRECTORY, `${network}.json`); const fileExists = fs.existsSync(filePath) && fs.statSync(filePath).isFile(); if (!fileExists) { diff --git a/pkg/deployments/src/task.ts b/pkg/deployments/src/task.ts index 8fd16e62af..813f0919e8 100644 --- a/pkg/deployments/src/task.ts +++ b/pkg/deployments/src/task.ts @@ -121,7 +121,7 @@ export default class Task { logger.success(`Deployed ${name} at ${instance.address}`); if (this.mode === TaskMode.LIVE) { - await saveContractDeploymentTransactionHash(instance.address, instance.deployTransaction.hash, this.network); + saveContractDeploymentTransactionHash(instance.address, instance.deployTransaction.hash, this.network); } } else { logger.info(`${name} already deployed at ${output[name]}`); @@ -168,7 +168,7 @@ export default class Task { const { ethers } = await import('hardhat'); const deployedAddress = this.output()[name]; - const deploymentTxHash = await getContractDeploymentTransactionHash(deployedAddress, this.network); + const deploymentTxHash = getContractDeploymentTransactionHash(deployedAddress, this.network); const deploymentTx = await ethers.provider.getTransaction(deploymentTxHash); const expectedDeploymentAddress = getContractAddress(deploymentTx);