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

/**
 *
 * 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 = {
13 14 15 16 17 18
  1: 'mainnet',
  3: 'ropsten',
  4: 'rinkeby',
  5: 'goerli',
  42: 'kovan',
}
19

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

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

  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|
41 42 43 44
|--|--|\n`
  for (const [name, addr] of Object.entries(predeploys)) {
    md += `|${name}|${addr}|\n`
  }
45

46
  md += `\n---
47 48
---

49
## LAYER 1\n\n`
50

51 52
  for (const deployment of deployments) {
    md += `## ${deployment.toUpperCase()}\n\n`
53 54 55

    const chainId = Number(
      fs.readFileSync(`./deployments/${deployment}/.chainId`)
56 57
    )
    const network = networks[chainId]
58

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

61 62
    md += `|Contract|Address|\n`
    md += `|--|--|\n`
63 64 65

    const contracts = dirtree(`./deployments/${deployment}`)
      .children.filter((child) => {
66
        return child.extension === '.json'
67 68
      })
      .map((child) => {
69 70
        return child.name.replace('.json', '')
      })
71

72
    proxiedContracts = []
73
    for (let i = 0; i < contracts.length; i++) {
74
      if (contracts[i] === 'OVM_L1CrossDomainMessenger') {
75 76
        proxiedContracts.push(contracts.splice(i, 1)[0])
      }
77
      if (contracts[i] === 'OVM_L1ETHGateway') {
78 79
        proxiedContracts.push(contracts.splice(i, 1)[0])
      }
80 81
    }

82
    for (const contract of contracts) {
83
      const colonizedName = contract.split(':').join('-')
84

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

87 88 89
      const escPrefix = chainId !== 1 ? `${network}.` : ''
      const etherscanUrl = `https://${escPrefix}etherscan.io/address/${deploymentInfo.address}`
      md += `|${colonizedName}|[${deploymentInfo.address}](${etherscanUrl})|\n`
90
    }
91

92
    md += `<!--\nImplementation addresses. DO NOT use these addresses directly.\nUse their proxied counterparts seen above.\n\n`
93 94

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

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

99 100 101
      const escPrefix = chainId !== 1 ? `${network}.` : ''
      const etherscanUrl = `https://${escPrefix}etherscan.io/address/${deploymentInfo.address}`
      md += `${colonizedName}: \n - ${deploymentInfo.address}\n - ${etherscanUrl})\n`
102 103
    }

104 105
    md += `-->\n`
    md += `---\n`
106 107
  }

108 109
  fs.writeFileSync(`./deployments/README.md`, md)
})().catch(console.error)