Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# #11005

Closed
wants to merge 3 commits into from
Closed

# #11005

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { EthHdWallet } from 'eth-hd-wallet'
import { createLog, getMatchingNetwork, buildGetTxParamsHandler, updateDeployedAddressesJson, getAccounts } from './utils'
import { getCurrentAcl, ensureAclIsDeployed, addMultisigAddressAsSystemAdmin } from './modules/acl'
import { getCurrentSettings, ensureSettingsIsDeployed } from './modules/settings'
import { getCurrentEntityDeployer, ensureEntityDeployerIsDeployed } from './modules/entityDeployer'
import { ensureMarketIsDeployed } from './modules/market'
import { ensureFeeBankIsDeployed } from './modules/feeBank'
import { ensureEntityImplementationsAreDeployed } from './modules/entityImplementations'
import { ensurePolicyImplementationsAreDeployed } from './modules/policyImplementations'

async function main() {
// copy artifacts
require('../scripts/copyArtifacts')

// setup logger
const log = createLog(console.log.bind(console))

// load release config
const releaseConfig = require('../releaseConfig.json')

// load and check network
const network = getMatchingNetwork(await hre.ethers.provider.getNetwork())

switch (network.name) {
case 'mainnet':
if (releaseConfig.deployNetwork !== 'mainnet') {
throw new Error('Release config does not allow Mainnet deployment')
}
break
case 'rinkeby':
if (releaseConfig.deployNetwork !== 'rinkeby') {
throw new Error('Release config does not allow Rinkeby deployment')
}
break
default:
// do nothing
}

let hdWallet
let multisig

// if trying to do multisig
if (releaseConfig.multisig && !releaseConfig.freshDeployment) {
if (!process.env.MNEMONIC) {
throw new Error('MNEMONIC env var must be set')
}

// generate HD wallet for use with multisig signing
hdWallet = EthHdWallet.fromMnemonic(process.env.MNEMONIC)
hdWallet.generateAddresses(1)

// multisig enabled
multisig = releaseConfig.multisig
}

const accounts = await getAccounts()

// getTxParams() handler
const getTxParams = await buildGetTxParamsHandler(network, { log })

// context ctx
const ctx = {
artifacts,
accounts,
log,
network,
getTxParams,
onlyDeployingUpgrades: !releaseConfig.freshDeployment,
multisig,
hdWallet,
}

if (!ctx.onlyDeployingUpgrades) {
await log.task('Re-deploying all contracts', async () => {
ctx.acl = await ensureAclIsDeployed(ctx)
ctx.settings = await ensureSettingsIsDeployed(ctx)

;[ctx.entityDeployer] = await Promise.all([
ensureEntityDeployerIsDeployed(ctx),
])
})
} else {
await log.task('Deploying upgrades only', async () => {
;[ctx.acl, ctx.settings, ctx.entityDeployer] = await Promise.all([
getCurrentAcl(ctx),
getCurrentSettings(ctx),
getCurrentEntityDeployer(ctx),
])
})
}

ctx.market = await ensureMarketIsDeployed(ctx)
ctx.feeBank = await ensureFeeBankIsDeployed(ctx)

await ensureEntityImplementationsAreDeployed(ctx)
await ensurePolicyImplementationsAreDeployed(ctx)

if (releaseConfig.extractDeployedAddresses) {
await updateDeployedAddressesJson(ctx)
}

// add multisig as sysadmin
if (releaseConfig.freshDeployment && releaseConfig.multisig) {
await addMultisigAddressAsSystemAdmin(ctx, {
multisig: releaseConfig.multisig,
// on rinkeby we append, on mainnet we replace
replaceExisting: (releaseConfig.deployNetwork === 'mainnet'),
})
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})