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][] }