Skip to content

Commit

Permalink
Support parsing full path contract name from block explorers (#1771)
Browse files Browse the repository at this point in the history
* Replace regex with index and substring

In case name of the file doesn't match the actual contract name,
the regex would not be valid.

Instead, we just pick the contract name following colon.
  • Loading branch information
0237h authored Nov 25, 2024
1 parent 098b433 commit 93271b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cyan-spoons-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Support parsing full path contract name from block explorers
8 changes: 7 additions & 1 deletion packages/cli/src/command-helpers/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ export const getContractNameForAddress = async (
): Promise<string> => {
try {
const contractSourceCode = await fetchSourceCodeFromEtherscan(network, address);
const contractName = contractSourceCode.result[0].ContractName;
let contractName: string = contractSourceCode.result[0].ContractName;

// Some explorers will return the full path of the contract instead of just the name
// Example: contracts/SyncSwapRouter.sol:SyncSwapRouter
if (contractName.includes(':'))
contractName = contractName.substring(contractName.lastIndexOf(':') + 1);

logger('Successfully getContractNameForAddress. contractName: %s', contractName);
return contractName;
} catch (error) {
Expand Down

0 comments on commit 93271b0

Please sign in to comment.