generate-markdown.js 3.24 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
  1: 'mainnet',
  3: 'ropsten',
  4: 'rinkeby',
  5: 'goerli',
  42: 'kovan',
18
  42069: 'mainnet-trial',
19
}
20

21 22
const publicDeployments = ['mainnet', 'mainnet-trial', 'kovan', 'kovan-trial']

23 24
;(async () => {
  console.log(`Writing contract addresses`)
25 26 27

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

  let md = `# Optimistic Ethereum Deployments`

  md += `
  ## LAYER 2
40

41 42 43 44
  ### Chain IDs
  - Mainnet: 10
  - Kovan: 69
  - Goerli: 420
45

46 47 48 49 50 51 52
  ### Pre-deployed Contracts

  **NOTE**: Pre-deployed contract addresses are the same on every Optimistic Ethereum network.

  | Contract | Address |
  | -------- | ------- |
  `
53

54 55 56
  for (const [name, addr] of Object.entries(predeploys)) {
    md += `|${name}|${addr}|\n`
  }
57

58 59 60
  md += `
  ## LAYER 1
  `
61

62 63
  for (const deployment of deployments) {
    md += `## ${deployment.toUpperCase()}\n\n`
64 65 66

    const chainId = Number(
      fs.readFileSync(`./deployments/${deployment}/.chainId`)
67 68
    )
    const network = networks[chainId]
69

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

72 73
    md += `| Contract | Address |\n`
    md += `| -------- | ------- |\n`
74 75 76

    const contracts = dirtree(`./deployments/${deployment}`)
      .children.filter((child) => {
77
        return child.extension === '.json'
78 79
      })
      .map((child) => {
80 81
        return child.name.replace('.json', '')
      })
82

83
    proxiedContracts = []
84
    for (let i = 0; i < contracts.length; i++) {
85
      if (contracts[i].startsWith('OVM_L1CrossDomainMessenger')) {
86 87
        proxiedContracts.push(contracts.splice(i, 1)[0])
      }
88
      if (contracts[i].startsWith('L1StandardBridge')) {
89 90
        proxiedContracts.push(contracts.splice(i, 1)[0])
      }
91 92
    }

93
    for (const contract of contracts) {
94
      const colonizedName = contract.split(':').join('-')
95

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

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

103
    md += `<!--\nImplementation addresses. DO NOT use these addresses directly.\nUse their proxied counterparts seen above.\n\n`
104 105

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

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

110 111 112
      const escPrefix = chainId !== 1 ? `${network}.` : ''
      const etherscanUrl = `https://${escPrefix}etherscan.io/address/${deploymentInfo.address}`
      md += `${colonizedName}: \n - ${deploymentInfo.address}\n - ${etherscanUrl})\n`
113 114
    }

115
    md += `-->\n`
116 117
  }

118 119
  fs.writeFileSync(`./deployments/README.md`, md)
})().catch(console.error)