Skip to content

Conversation

@chrismaree
Copy link
Member

@chrismaree chrismaree commented May 10, 2022

  • adds a helper function to find info about a deployed contract from it's address.
  • refines getDeployedAddress to let you ignore the network name when fetching a SpokePool address.

chrismaree added 2 commits May 6, 2022 16:24
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree changed the title chrismaree/add additional token util feat: add reverse look up for contract info from address May 10, 2022
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree requested review from mrice32 and nicholaspai May 10, 2022 16:27
Signed-off-by: chrismaree <christopher.maree@gmail.com>
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;
Copy link

@daywiss daywiss May 10, 2022

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link

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;
Copy link

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

Copy link
Member Author

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 } {
Copy link

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.

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Makes sense.

Copy link
Contributor

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment!

} 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()]))
Copy link
Contributor

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?

Copy link
Member Author

@chrismaree chrismaree May 11, 2022

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.

Copy link
Contributor

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.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
"Arbitrum_Adapter": { "address": "0x937958992799bF4A9a656E6596FD10d7Da5c2216", "blockNumber": 14704380 },
"Boba_Adapter": { "address": "0x33B0Ec794c15D6Cc705818E70d4CaCe7bCfB5Af3", "blockNumber": 14716798 },
"Ethereum_Adapter": { "address": "0x527E872a5c3f0C7c24Fe33F2593cFB890a285084", "blockNumber": 14704381 },
"Ethereum_SpokePool": { "address": "0x931A43528779034ac9eb77df799d133557406176", "blockNumber": 14704425 },
Copy link
Member Author

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.
Copy link
Member Author

@chrismaree chrismaree May 11, 2022

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.

Copy link
Member

@nicholaspai nicholaspai left a 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

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
}

// Returns the chainId and contract name for a given contract address.
export function getContractInfoFromAddress(contractAddress: string): { chainId: Number; contractName: string } {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Makes sense.

@chrismaree chrismaree merged commit 087ceef into master May 12, 2022
@chrismaree chrismaree deleted the chrismaree/add-additional-token-util branch May 12, 2022 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants