-
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
Conversation
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
src/DeploymentUtils.ts
Outdated
| try { | ||
| // If this does not match then try search on a Regex on SpokePool to let the caller exclude the chain name. | ||
| for (const _contractName of Object.keys(deployments[networkId.toString()])) | ||
| if (/.*_SpokePool/.test(_contractName)) return deployments[networkId.toString()][_contractName].address; |
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.
this could error because of a typo, and then the user ends up getting spoke pool address when maybe they meant somethign completely different, which could be bad.
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.
the only way that would happen is if you added SpokePool to the search. this regex will ONLY pass if *_SpokePool is set. you are right though that you could do something silly like HubPool_SpokePool which would return the spoke pool on that chain.
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.
however, I have modified this to export the name of the contract as SpokePool on each respective chain to avoid needing this workaround alltogether.
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.
I see, i missed that check
| 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 comment
The 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
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.
fixed. see above comments
| } | ||
|
|
||
| // 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 comment
The 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.
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.
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.
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.
Does the PolygonTokenBridger break this? It has the same address on multiple chains
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.
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
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.
Gotcha. Makes sense.
mrice32
left a comment
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.
One comment!
src/DeploymentUtils.ts
Outdated
| } catch (_) { | ||
| try { | ||
| // If this does not match then try search on a Regex on SpokePool to let the caller exclude the chain name. | ||
| for (const _contractName of Object.keys(deployments[networkId.toString()])) |
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.
I think this is confusing. Can we just make aliases in the generation? Aka save an identical deployment under a different name using deployments.save?
Something like:
const spokePoolDeployment = await deploy("Optimism_SpokePool", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [
hubPool.address, // Set hub pool as cross domain admin since it delegatecalls the Optimism_Adapter logic.
hubPool.address,
"0x0000000000000000000000000000000000000000", // timer
],
});
await hre.deployments.save("SpokePool", spokePoolDeployment);Thoughts?
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.
hhmm. I personally think the deployment artefacts should be named according to the contract file names i.e the json files produced during a migration should be a 1:1 mapping to the contracts in the contracts directory. this is what hardhat expects and could break other things if we modify this.
what we could do is modify the export of the deployments.json file, that is constructed here:
https://github.com/across-protocol/contracts-v2/blob/master/scripts/processHardhatExport.ts
this could be modified to export the *_SpokePool to simply be SpokePool on the respective chain, thereby mitigating the need for this logic all together within the export.
I've implemented this change, please take a look.
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.
I don't think this will break anything. We're just adding a second record of the same contract.
So you'll have "Polygon_SpokePool" and "SpokePool" on polygon with all the same details.
Hardhat will still have the artifact it expects, but we will also export a second artifact under a more generic name.
| "Arbitrum_Adapter": { "address": "0x937958992799bF4A9a656E6596FD10d7Da5c2216", "blockNumber": 14704380 }, | ||
| "Boba_Adapter": { "address": "0x33B0Ec794c15D6Cc705818E70d4CaCe7bCfB5Af3", "blockNumber": 14716798 }, | ||
| "Ethereum_Adapter": { "address": "0x527E872a5c3f0C7c24Fe33F2593cFB890a285084", "blockNumber": 14704381 }, | ||
| "Ethereum_SpokePool": { "address": "0x931A43528779034ac9eb77df799d133557406176", "blockNumber": 14704425 }, |
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.
| 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. |
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.
change to modify the export without changing the artefacts.
nicholaspai
left a comment
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.
LGTM sorry for not seeing this as I should have rebased off this into master
| } | ||
|
|
||
| // 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Makes sense.
getDeployedAddressto let you ignore the network name when fetching aSpokePooladdress.