Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unnecessarily async functions sync #2030

Merged
merged 4 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/deployments/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Deployed core Pool factories (`WeightedPoolFactory`, `ComposableStablePoolFactory`, `LiquidityBootstrappingPool`, `AaveLinearPool`) to BNB.
- Deployed `AuthorizerAdaptorEntrypoint` to all networks.
- Deployed `AaveLinearPoolFactory` to all networks.
- Made `getBalancerContractAbi`, `getBalancerContractBytecode`, `getBalancerContractAddress` and `getBalancerDeployment` synchronous rather than asynchronous functions.
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved

## 3.0.0 (2022-10-25)

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[] {
nventuro marked this conversation as resolved.
Show resolved Hide resolved
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