Skip to content

Commit

Permalink
Make unnecessarily async functions sync (#2030)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Nicolás Venturo <[email protected]>
  • Loading branch information
TomAFrench and nventuro authored Nov 22, 2022
1 parent 0d155b6 commit a50715b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions pkg/deployments/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/deployments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions pkg/deployments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown[]> {
export function getBalancerContractAbi(task: string, contract: string): unknown[] {
return require(getBalancerContractAbiPath(task, contract));
}

Expand All @@ -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<string> {
export function getBalancerContractBytecode(task: string, contract: string): string {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require(getBalancerContractBytecodePath(task, contract)).creationCode;
}
Expand All @@ -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<string> {
const output = await getBalancerDeployment(task, network);
export function getBalancerContractAddress(task: string, contract: string, network: string): string {
const output = getBalancerDeployment(task, network);
return output[contract];
}

Expand All @@ -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));
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/deployments/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
): void {
if (network === 'hardhat') return;

const filePath = path.join(DEPLOYMENT_TXS_DIRECTORY, `${network}.json`);
Expand All @@ -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<string> {
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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployments/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a50715b

Please sign in to comment.