-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add reverse look up for contract info from address #155
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
Changes from all commits
c758657
219fefe
953adf7
670fd92
9fd590b
1b92407
a84d244
1c66296
c84f6ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ export async function run(): Promise<void> { | |
| if (!processedOutput[chainId]) processedOutput[chainId] = {}; | ||
| const address = castExport[chainId][0]?.contracts[contractName].address; | ||
| const blockNumber = findDeploymentBlockNumber(castExport[chainId][0].name, contractName); | ||
| if (/.*_SpokePool/.test(contractName)) contractName = "SpokePool"; // Strip the network name from the spoke pool in the contractName. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to modify the export without changing the artefacts. |
||
| processedOutput[chainId][contractName] = { address, blockNumber }; | ||
| }); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,38 @@ | ||
| import * as deployments from "../deployments/deployments.json"; | ||
| import * as deployments_ from "../deployments/deployments.json"; | ||
| interface DeploymentExport { | ||
| [chainId: string]: { [contractName: string]: { address: string; blockNumber: number } }; | ||
| } | ||
| const deployments: DeploymentExport = deployments_ as any; | ||
|
|
||
| // Returns the deployed address of any contract on any network. | ||
| export function getDeployedAddress(contractName: string, networkId: number): string { | ||
| try { | ||
| return (deployments as any)[networkId.toString()][contractName].address; | ||
| return deployments[networkId.toString()][contractName].address; | ||
| } catch (_) { | ||
| throw new Error(`Contract ${contractName} not found on ${networkId} in deployments.json`); | ||
| } | ||
| } | ||
|
|
||
| // Returns the deployment block number of any contract on any network. | ||
| export function getDeployedBlockNumber(contractName: string, networkId: number): string { | ||
| export function getDeployedBlockNumber(contractName: string, networkId: number): number { | ||
| try { | ||
| return (deployments as any)[networkId.toString()][contractName].blockNumber; | ||
| return deployments[networkId.toString()][contractName].blockNumber; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should have the same behavior as getDeployedAddress. imo we might just want a way to look up the correct contract name, then you dont have to modify thsese 2 functions at all
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. see above comments |
||
| } catch (_) { | ||
| throw new Error(`Contract ${contractName} not found on ${networkId} in deployments.json`); | ||
| } | ||
| } | ||
|
|
||
| // Returns the chainId and contract name for a given contract address. | ||
| export function getContractInfoFromAddress(contractAddress: string): { chainId: Number; contractName: string } { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like this solves my issues since im usually given the contract address and chain ( at least for spoke pools). It would be a problem if hubpools also had different names, but they dont currently.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ye, this method assumes that the deployment addresses on each chain are unique enabling you to go backwards from a known address to the contract name and chainId.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the PolygonTokenBridger break this? It has the same address on multiple chains
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ye that contract would not work with this method but that's ok. This method is only used in the bots to enhance logs and the bots never directly call those polygon contracts so it won't be an issue. I'll add an error that is thrown if multiple addresses are found to prevent any confusion
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Makes sense. |
||
| let returnValue: { chainId: number; contractName: string }[] = []; | ||
|
|
||
| Object.keys(deployments).forEach((_chainId) => | ||
| Object.keys(deployments[_chainId]).forEach((_contractName) => { | ||
| if (deployments[_chainId][_contractName].address == contractAddress) | ||
| returnValue.push({ chainId: Number(_chainId), contractName: _contractName }); | ||
| }) | ||
| ); | ||
| if (returnValue.length == 0) throw new Error(`Contract ${contractAddress} not found in deployments.json`); | ||
| if (returnValue.length > 1) throw new Error(`Multiple deployments found for ${contractAddress}`); | ||
| return returnValue[0]; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrice32 see the changes made here.