Skip to content

Commit

Permalink
🐛 fix: Remove undefined etherscan links (#298)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
roninjin10 and Will Cory authored Jul 15, 2023
1 parent 85c340d commit 841d6a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/empty-rivers-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@evmts/bundler": patch
"@evmts/ts-plugin": patch
---

Fixed bug with etherscan links showing as undefined if they didn't exist
21 changes: 8 additions & 13 deletions bundlers/bundler/src/solc/solcPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ModuleInfo> = {},
) => {
modules[m.id] = m
/**
* This could get cached
*/
for (const dep of m.resolutions) {
getAllModulesRecursively(dep, modules)
}
Expand Down Expand Up @@ -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,
Expand All @@ -88,7 +94,6 @@ const resolveArtifactsSync = (
):
| Record<string, { contractName: string; abi: any; bytecode: string }>
| undefined => {
// Compile the contract
if (!solFile.endsWith('.sol')) {
throw new Error('Not a solidity file')
}
Expand All @@ -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 }]
}),
)
Expand All @@ -122,15 +125,7 @@ const resolveArtifacts = async (
return resolveArtifactsSync(solFile, basedir, logger, config)
}

// type Address = `0x${string}`
// type AddressMap = Record<string, Address>

// 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,
Expand Down
17 changes: 9 additions & 8 deletions bundlers/bundler/src/utils/getEtherscanLinks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const getEtherscanLinks = (
addresses: Record<number, `0x${string}` | undefined>,
) => {
): [chainId: number, link: string][] => {
const etherscanBaseUris: Record<number, string> = {
1: 'https://etherscan.io',
5: 'https://goerli.etherscan.io',
Expand All @@ -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][]
}

1 comment on commit 841d6a8

@vercel
Copy link

@vercel vercel bot commented on 841d6a8 Jul 15, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

evmts-docs – ./

evmts-docs-evmts.vercel.app
evmts.dev
evmts-docs-git-main-evmts.vercel.app

Please sign in to comment.