From 841d6a89f4995e4f666902d27cb7dbfc3efd77e5 Mon Sep 17 00:00:00 2001 From: Will Cory Date: Sat, 15 Jul 2023 00:31:47 -0700 Subject: [PATCH] :bug: fix: Remove undefined etherscan links (#298) ## Description Fix bugs with undefined etherscan links like devnet showing up as undefined ## Testing Explain the quality checks that have been done on the code changes ## Additional Information - [ ] I read the [contributing docs](../docs/contributing.md) (if this is your first contribution) Your ENS/address: Co-authored-by: Will Cory --- .changeset/empty-rivers-poke.md | 6 ++++++ bundlers/bundler/src/solc/solcPlugin.ts | 21 +++++++------------ .../bundler/src/utils/getEtherscanLinks.ts | 17 ++++++++------- 3 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 .changeset/empty-rivers-poke.md diff --git a/.changeset/empty-rivers-poke.md b/.changeset/empty-rivers-poke.md new file mode 100644 index 0000000000..49bdaa1b80 --- /dev/null +++ b/.changeset/empty-rivers-poke.md @@ -0,0 +1,6 @@ +--- +"@evmts/bundler": patch +"@evmts/ts-plugin": patch +--- + +Fixed bug with etherscan links showing as undefined if they didn't exist diff --git a/bundlers/bundler/src/solc/solcPlugin.ts b/bundlers/bundler/src/solc/solcPlugin.ts index 3deeceec00..8fe93304ac 100644 --- a/bundlers/bundler/src/solc/solcPlugin.ts +++ b/bundlers/bundler/src/solc/solcPlugin.ts @@ -29,11 +29,18 @@ function compileContractSync( config.libs, ) + /** + * Known bug!!! This can hit a stack error + * We should make this iterative instead of recursive + */ const getAllModulesRecursively = ( m = entryModule, modules: Record = {}, ) => { modules[m.id] = m + /** + * This could get cached + */ for (const dep of m.resolutions) { getAllModulesRecursively(dep, modules) } @@ -79,7 +86,6 @@ function compileContractSync( return output.contracts[entryModule.id] } -// Remove writeFileSync and readFileSync, instead, keep artifacts in memory const resolveArtifactsSync = ( solFile: string, basedir: string, @@ -88,7 +94,6 @@ const resolveArtifactsSync = ( ): | Record | undefined => { - // Compile the contract if (!solFile.endsWith('.sol')) { throw new Error('Not a solidity file') } @@ -101,10 +106,8 @@ const resolveArtifactsSync = ( return Object.fromEntries( Object.entries(contracts).map(([contractName, contract]) => { - // Keep artifacts in memory const abi = (contract as any).abi const bytecode = (contract as any).evm.bytecode.object - return [contractName, { contractName, abi, bytecode }] }), ) @@ -122,15 +125,7 @@ const resolveArtifacts = async ( return resolveArtifactsSync(solFile, basedir, logger, config) } -// type Address = `0x${string}` -// type AddressMap = Record - -// Refactor all methods in the solcModules object to use the revised resolveArtifactsSync function. -// TODO add address resolution -export const solcModules: SolidityResolver = ( - config, - logger /*, addresses: AddressMap*/, -) => { +export const solcModules: SolidityResolver = (config, logger) => { return { name: solcModules.name, config, diff --git a/bundlers/bundler/src/utils/getEtherscanLinks.ts b/bundlers/bundler/src/utils/getEtherscanLinks.ts index e043dc58a9..a6c7b9b990 100644 --- a/bundlers/bundler/src/utils/getEtherscanLinks.ts +++ b/bundlers/bundler/src/utils/getEtherscanLinks.ts @@ -1,6 +1,6 @@ export const getEtherscanLinks = ( addresses: Record, -) => { +): [chainId: number, link: string][] => { const etherscanBaseUris: Record = { 1: 'https://etherscan.io', 5: 'https://goerli.etherscan.io', @@ -23,13 +23,14 @@ export const getEtherscanLinks = ( 534353: 'https://blockscout.scroll.io', } - return Object.entries(addresses).map(([networkId, address]) => { - return [ - networkId, - etherscanBaseUris[networkId as unknown as number] && + return Object.entries(addresses) + .map(([networkId, address]) => { + const link = + etherscanBaseUris[networkId as unknown as number] && `${ etherscanBaseUris[networkId as unknown as number] - }/address/${address}`, - ] - }) + }/address/${address}` + return link && [networkId, link] + }) + .filter(Boolean) as [number, string][] }