generate-markdown.js 3.58 KB
Newer Older
1
#!/usr/bin/env node
2 3
const dirtree = require('directory-tree')
const fs = require('fs')
4 5 6 7 8 9 10 11

/**
 *
 * takes a directory of hardhat artifacts and builds a markdown table that shows the name of the contract in one column and its address in another column with a hyperlink to etherscan
 *
 */

const networks = {
12 13 14 15 16 17
  1: 'mainnet',
  3: 'ropsten',
  4: 'rinkeby',
  5: 'goerli',
  42: 'kovan',
}
18

19 20
;(async () => {
  console.log(`Writing contract addresses`)
21 22 23

  const deployments = dirtree(`./deployments`)
    .children.filter((child) => {
24
      return child.type === 'directory'
25 26
    })
    .map((d) => d.name)
27
    .reverse()
28 29 30 31 32 33 34 35 36 37 38 39 40 41

  let md = `# Optimism Regenesis Deployments
## LAYER 2

### Chain IDs:
- Mainnet: 10
- Kovan: 69
- Goerli: 420
*The contracts relevant for the majority of developers are \`OVM_ETH\` and the cross-domain messengers. The L2 addresses don't change.*

### Predeploy contracts:
|Contract|Address|
|--|--|
|OVM_ETH: | \`0x4200000000000000000000000000000000000006\`
42
|OVM_L2StandardBridge: | \`0x4200000000000000000000000000000000000010\`
43 44 45 46 47 48 49 50 51 52 53 54
|OVM_L2CrossDomainMessenger: | \`0x4200000000000000000000000000000000000007\`
|OVM_L2ToL1MessagePasser: | \`0x4200000000000000000000000000000000000000\`
|OVM_L1MessageSender: | \`0x4200000000000000000000000000000000000001\`
|OVM_DeployerWhitelist: | \`0x4200000000000000000000000000000000000002\`
|OVM_ECDSAContractAccount: | \`0x4200000000000000000000000000000000000003\`
|OVM_SequencerEntrypoint: | \`0x4200000000000000000000000000000000000005\`
|Lib_AddressManager: | \`0x4200000000000000000000000000000000000008\`
|ERC1820Registry: | \`0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24\`

---
---

55
## LAYER 1\n\n`
56

57 58
  for (const deployment of deployments) {
    md += `## ${deployment.toUpperCase()}\n\n`
59 60 61

    const chainId = Number(
      fs.readFileSync(`./deployments/${deployment}/.chainId`)
62 63
    )
    const network = networks[chainId]
64

65
    md += `Network : __${network} (chain id: ${chainId})__\n\n`
66

67 68
    md += `|Contract|Address|\n`
    md += `|--|--|\n`
69 70 71

    const contracts = dirtree(`./deployments/${deployment}`)
      .children.filter((child) => {
72
        return child.extension === '.json'
73 74
      })
      .map((child) => {
75 76
        return child.name.replace('.json', '')
      })
77

78
    proxiedContracts = []
79
    for (let i = 0; i < contracts.length; i++) {
80
      if (contracts[i] === 'OVM_L1CrossDomainMessenger') {
81 82
        proxiedContracts.push(contracts.splice(i, 1)[0])
      }
83
      if (contracts[i] === 'OVM_L1ETHGateway') {
84 85
        proxiedContracts.push(contracts.splice(i, 1)[0])
      }
86 87
    }

88
    for (const contract of contracts) {
89
      const colonizedName = contract.split(':').join('-')
90

91
      const deploymentInfo = require(`../deployments/${deployment}/${contract}.json`)
92

93 94 95
      const escPrefix = chainId !== 1 ? `${network}.` : ''
      const etherscanUrl = `https://${escPrefix}etherscan.io/address/${deploymentInfo.address}`
      md += `|${colonizedName}|[${deploymentInfo.address}](${etherscanUrl})|\n`
96
    }
97

98
    md += `<!--\nImplementation addresses. DO NOT use these addresses directly.\nUse their proxied counterparts seen above.\n\n`
99 100

    for (const proxy of proxiedContracts) {
101
      const colonizedName = proxy.split(':').join('-')
102

103
      const deploymentInfo = require(`../deployments/${deployment}/${proxy}.json`)
104

105 106 107
      const escPrefix = chainId !== 1 ? `${network}.` : ''
      const etherscanUrl = `https://${escPrefix}etherscan.io/address/${deploymentInfo.address}`
      md += `${colonizedName}: \n - ${deploymentInfo.address}\n - ${etherscanUrl})\n`
108 109
    }

110 111
    md += `-->\n`
    md += `---\n`
112 113
  }

114 115
  fs.writeFileSync(`./deployments/README.md`, md)
})().catch(console.error)