Skip to content

Commit

Permalink
Added script to generate Networks.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Sep 11, 2020
1 parent d3d11ca commit 8ae816a
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -15,3 +15,4 @@ abis
test-results.xml
.DS_Store
deployments/local*
Networks.md
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.6.4;
import "./CompoundPrizePool.sol";
import "../../external/openzeppelin/ProxyFactory.sol";

/// @title Compound Prize Pool Factory
/// @title Compound Prize Pool Proxy Factory
/// @notice Minimal proxy pattern for creating new Compound Prize Pools
contract CompoundPrizePoolProxyFactory is ProxyFactory {

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -50,6 +50,7 @@
"deploy-eip-1820": "1.0.0",
"ethereum-waffle": "^3.0.2",
"ethers": "^5.0.8",
"find": "^0.3.0",
"minimist": "^1.2.5",
"mocha-junit-reporter": "1.23.3",
"oz-console": "2.0.1",
Expand Down
110 changes: 110 additions & 0 deletions scripts/generateDeploymentMarkdown.js
@@ -0,0 +1,110 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const glob = require('glob')
const find = require('find')

const networks = ['rinkeby', 'ropsten', 'kovan']

const ignoreContracts = [
'ProxyAdmin',
'ProxyFactory',
'Comptroller',
'ComptrollerImplementation',
'CompoundPrizePoolProxyFactory',
'ControlledTokenProxyFactory',
'SingleRandomWinnerProxyFactory',
'TicketProxyFactory'
]

const baseUrl = "https://github.com/pooltogether/pooltogether-pool-contracts/tree/version-3"
const outputFile = `./Networks.md`

const networkPoolConfig = {
rinkeby: [
{
address: '0xe19d8b62Bbb53F3e5d2c62e361240a6d3Ad4084F',
name: 'Compound cDAI Prize Pool'
},
{
address: '0x5f4d901082229b7FBf2afd4d3Ac970De2eB2AB92',
name: 'Compound cUSDC Prize Pool'
},
{
address: '0x832B459C0Bc3FB10F2Aa62c70eDf5918085315c1',
name: 'Compound cUSDT Prize Pool'
}
]
}

function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

async function generate() {
const out = fs.openSync(outputFile, 'w')
const append = (str) => {
fs.writeSync(out, str + "\n")
}

for (let ni = 0; ni < networks.length; ni++) {
const network = networks[ni]

console.log(chalk.yellow(`Generating network ${network}...`))

append(`# ${capitalizeFirstLetter(network)}`)
append('')

append(`| Contract | Address | Artifact |`)
append(`| :--- | :--- | :--- |`)

if (networkPoolConfig[network] && networkPoolConfig[network].length) {
for (let npi = 0; npi < networkPoolConfig[network].length; npi++) {
const pool = networkPoolConfig[network][npi]
append(`| [${pool.name}](${baseUrl + '/contracts/prize-pool/PrizePool.sol'}) | [${pool.address}](https://${network}.etherscan.io/address/${pool.address}) | [ABI](/.gitbook/assets/prizepoolabi.json) |`)
}
}

const contractPaths = glob.sync(`${__dirname}/../deployments/${network}/*.json`)

for (let cpi = 0; cpi < contractPaths.length; cpi++) {
const contractPath = contractPaths[cpi]

const contract = JSON.parse(fs.readFileSync(contractPath))
const contractName = path.basename(contractPath, ".json")


if (!ignoreContracts.includes(contractName)) {
console.log(chalk.dim(`Found contract ${contractName}...`))

const solidityFilepaths = find.fileSync(`${contractName}.sol`, `${__dirname}/../contracts`)
let contractLink
if (solidityFilepaths.length > 0) {
const solidityFilePath = solidityFilepaths[0].split("/contracts")[1]
contractLink = `[${contractName}](${baseUrl}/contracts${solidityFilePath})`
} else {
contractLink = contractName
}

append(`| ${contractLink} | [${contract.address}](https://${network}.etherscan.io/address/${contract.address}) | [Artifact](${baseUrl + `/deployments/${network}/${path.basename(contractPath)}`}) |`)
} else {
console.log(chalk.dim(`Ignoring contract ${contractName}`))
}
}

console.log(chalk.green(`Done ${network}!`))
append('')
}

append('')
append('')
append('')
append(`*This document was generated using a [script](${baseUrl + `scripts/generateDeploymentMarkdown.js`})*`)
append('')

fs.closeSync(out)
}

generate()
16 changes: 14 additions & 2 deletions yarn.lock
Expand Up @@ -5627,6 +5627,13 @@ find-yarn-workspace-root@^1.2.1:
fs-extra "^4.0.3"
micromatch "^3.1.4"

find@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/find/-/find-0.3.0.tgz#4082e8fc8d8320f1a382b5e4f521b9bc50775cb8"
integrity sha512-iSd+O4OEYV/I36Zl8MdYJO0xD82wH528SaCieTVHhclgiYNe9y+yPKSwK+A7/WsmHL1EZ+pYUJBXWTL5qofksw==
dependencies:
traverse-chain "~0.1.0"

firebase@^7.8.0:
version "7.20.0"
resolved "https://registry.yarnpkg.com/firebase/-/firebase-7.20.0.tgz#ac1557a0962070d19d61d150c69421a5503710ec"
Expand Down Expand Up @@ -10497,6 +10504,11 @@ tough-cookie@^2.3.3, tough-cookie@~2.5.0:
psl "^1.1.28"
punycode "^2.1.1"

traverse-chain@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/traverse-chain/-/traverse-chain-0.1.0.tgz#61dbc2d53b69ff6091a12a168fd7d433107e40f1"
integrity sha1-YdvC1Ttp/2CRoSoWj9fUMxB+QPE=

trim-repeated@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/trim-repeated/-/trim-repeated-1.0.0.tgz#e3646a2ea4e891312bf7eace6cfb05380bc01c21"
Expand Down Expand Up @@ -11845,9 +11857,9 @@ web3-provider-engine@14.2.1:
xhr "^2.2.0"
xtend "^4.0.1"

"web3-provider-engine@git+https://github.com/trufflesuite/provider-engine.git#web3-one":
"web3-provider-engine@https://github.com/trufflesuite/provider-engine#web3-one":
version "14.0.6"
resolved "git+https://github.com/trufflesuite/provider-engine.git#9694f5b4e5500651bd2ff689df8529bb5cf6b96f"
resolved "https://github.com/trufflesuite/provider-engine#9694f5b4e5500651bd2ff689df8529bb5cf6b96f"
dependencies:
async "^2.5.0"
backoff "^2.5.0"
Expand Down

0 comments on commit 8ae816a

Please sign in to comment.