Skip to content

Commit

Permalink
Address lookup review comments (#2074)
Browse files Browse the repository at this point in the history
* feat: return null if passed address doesn't match with a deployed Balancer contract

* docs: add `lookupBalancerContractByAddress` to the changelog

* refactor: throw rather than returning null on unknown addresses
  • Loading branch information
TomAFrench authored Nov 29, 2022
1 parent d67a0e6 commit cd16d44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/deployments/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Made `getBalancerContractAbi`, `getBalancerContractBytecode`, `getBalancerContractAddress` and `getBalancerDeployment` synchronous rather than asynchronous functions.
- Added `getBalancerContractArtifact` which returns a artifact file for the contract in the same format used by Hardhat.
- Deprecated `getBalancerContractBytecode` in favour of `getBalancerContractArtifact`.
- Added `lookupBalancerContractByAddress` which returns the contract's name and the relevant deployment task if it is a tracked Balancer contract.

## 3.0.0 (2022-10-25)

Expand Down
9 changes: 7 additions & 2 deletions pkg/deployments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import { Contract } from 'ethers';
import { Artifact } from 'hardhat/types';

/**
* @dev Returns the task id and contract name for a canonical contract deployed on a specific network
* @dev Returns the task id and contract name for a canonical contract deployed on a specific network.
* Throws if the address doesn't match any known Balancer deployment.
* @param address Address of the contract to be fetched
* @param network Name of the network looking the deployment for (e.g. mainnet, polygon, goerli, etc)
*/
export function lookupBalancerContractByAddress(address: string, network: string): { task: string; name: string } {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const networkAddresses = require(getBalancerContractAddresses(network));
return networkAddresses[address];
const deploymentInfo = networkAddresses[address];
if (deploymentInfo === undefined) {
throw new Error(`Unable to connect ${address} to any Balancer deployment on ${network}`);
}
return deploymentInfo;
}

/**
Expand Down

0 comments on commit cd16d44

Please sign in to comment.