From a34c9cf54a94cdacc9f303760fe073eec9b28893 Mon Sep 17 00:00:00 2001 From: Etienne Donneger Date: Mon, 25 Nov 2024 11:49:20 -0500 Subject: [PATCH] Support parsing full path contract name from block explorers --- .changeset/cyan-spoons-greet.md | 5 +++++ packages/cli/src/command-helpers/abi.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/cyan-spoons-greet.md diff --git a/.changeset/cyan-spoons-greet.md b/.changeset/cyan-spoons-greet.md new file mode 100644 index 000000000..c4161fd56 --- /dev/null +++ b/.changeset/cyan-spoons-greet.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +Support parsing full path contract name from block explorers diff --git a/packages/cli/src/command-helpers/abi.ts b/packages/cli/src/command-helpers/abi.ts index b30dcb6de..c69781b56 100644 --- a/packages/cli/src/command-helpers/abi.ts +++ b/packages/cli/src/command-helpers/abi.ts @@ -151,7 +151,12 @@ export const getContractNameForAddress = async ( ): Promise => { try { const contractSourceCode = await fetchSourceCodeFromEtherscan(network, address); - const contractName = contractSourceCode.result[0].ContractName; + let contractName = contractSourceCode.result[0].ContractName; + // Some explorers will return the full path of the contract instead of just the name + const regex = /^contracts\/(?.+)\.sol:\1$/; + + if (regex.test(contractName)) contractName = regex.exec(contractName)?.groups?.contract; + logger('Successfully getContractNameForAddress. contractName: %s', contractName); return contractName; } catch (error) {