Skip to content

Commit

Permalink
Fix truffle migration async scripts (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaamani authored and sohkai committed Jul 24, 2018
1 parent 6f4bfa8 commit e98b67c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
56 changes: 29 additions & 27 deletions migrations/2_apm.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
const namehash = require('eth-ens-namehash').hash
const keccak256 = require('js-sha3').keccak_256

module.exports = async (deployer, network, accounts, arts = null) => {
if (arts != null) artifacts = arts // allow running outside
module.exports = function (deployer, network, accounts, arts = null) {
return deployer.then(async () => {
if (arts != null) artifacts = arts // allow running outside

const getContract = name => artifacts.require(name)
const getContract = name => artifacts.require(name)

const bases = ['APMRegistry', 'Repo', 'ENSSubdomainRegistrar']
const baseContracts = bases.map(getContract)
const bases = ['APMRegistry', 'Repo', 'ENSSubdomainRegistrar']
const baseContracts = bases.map(getContract)

await deployer.deploy(baseContracts)
await deployer.deploy(baseContracts)

const baseDeployed = baseContracts.map(c => c.address)
const baseDeployed = baseContracts.map(c => c.address)

// TODO: Take into account networks with ENS deployed
const ENSFactory = getContract('ENSFactory')
await deployer.deploy(ENSFactory)
// TODO: Take into account networks with ENS deployed
const ENSFactory = getContract('ENSFactory')
await deployer.deploy(ENSFactory)

const APMRegistryFactory = getContract('APMRegistryFactory')
const ensAddr = '0x0' // so ensfactory creates one
const APMRegistryFactory = getContract('APMRegistryFactory')
const ensAddr = '0x0' // so ensfactory creates one

const kernelBase = await getContract('Kernel').new()
const aclBase = await getContract('ACL').new()
const daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, '0x00')
const kernelBase = await getContract('Kernel').new()
const aclBase = await getContract('ACL').new()
const daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, '0x00')

await deployer.deploy(APMRegistryFactory, daoFactory.address, ...baseDeployed, ensAddr, ENSFactory.address)
const factory = await APMRegistryFactory.deployed()
await deployer.deploy(APMRegistryFactory, daoFactory.address, ...baseDeployed, ensAddr, ENSFactory.address)
const factory = await APMRegistryFactory.deployed()


console.log('Deploying APM...')
const root = '0xffffffffffffffffffffffffffffffffffffffff' // public
const receipt = await factory.newAPM(namehash('eth'), '0x'+keccak256('aragonpm'), root)
const apmAddr = receipt.logs.filter(l => l.event == 'DeployAPM')[0].args.apm
console.log('Deployed APM at:', apmAddr)
console.log('Deploying APM...')
const root = '0xffffffffffffffffffffffffffffffffffffffff' // public
const receipt = await factory.newAPM(namehash('eth'), '0x'+keccak256('aragonpm'), root)
const apmAddr = receipt.logs.filter(l => l.event == 'DeployAPM')[0].args.apm
console.log('Deployed APM at:', apmAddr)

const apm = getContract('APMRegistry').at(apmAddr)
console.log('Kernel:', await apm.kernel())
const apm = getContract('APMRegistry').at(apmAddr)
console.log('Kernel:', await apm.kernel())

const ensSub = getContract('ENSSubdomainRegistrar').at(await apm.registrar())
console.log('ENS:', await ensSub.ens())
const ensSub = getContract('ENSSubdomainRegistrar').at(await apm.registrar())
console.log('ENS:', await ensSub.ens())

return { apm, ensAddr: await ensSub.ens() }
return { apm, ensAddr: await ensSub.ens() }
})
}
30 changes: 16 additions & 14 deletions migrations/3_factory.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
const getContract = name => artifacts.require(name)

module.exports = async (deployer, network, accounts, arts = null) => {
if (arts != null) artifacts = arts // allow running outside
module.exports = function (deployer, network, accounts, arts = null) {
return deployer.then(async () => {
if (arts != null) artifacts = arts // allow running outside

const DAOFactory = artifacts.require('DAOFactory')
const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory')
const DAOFactory = artifacts.require('DAOFactory')
const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory')

const kernelBase = await getContract('Kernel').new()
const aclBase = await getContract('ACL').new()
const kernelBase = await getContract('Kernel').new()
const aclBase = await getContract('ACL').new()

const regFact = await EVMScriptRegistryFactory.new()
const daoFact = await DAOFactory.new(kernelBase.address, aclBase.address, regFact.address)
const regFact = await EVMScriptRegistryFactory.new()
const daoFact = await DAOFactory.new(kernelBase.address, aclBase.address, regFact.address)

if (!arts) { // Running standalone in aOS repo
const receipt = await daoFact.newDAO(accounts[0])
daoAddr = receipt.logs.filter(l => l.event == 'DeployDAO')[0].args.dao
console.log('deployed DAO at', daoAddr)
}
if (!arts) { // Running standalone in aOS repo
const receipt = await daoFact.newDAO(accounts[0])
daoAddr = receipt.logs.filter(l => l.event == 'DeployDAO')[0].args.dao
console.log('deployed DAO at', daoAddr)
}

return { daoFact }
return { daoFact }
})
}
8 changes: 5 additions & 3 deletions migrations/4_links.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const ScriptHelpers = artifacts.require('ScriptHelpers')
const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory')

module.exports = async (deployer, network) => {
deployer.deploy(ScriptHelpers)
deployer.link(ScriptHelpers, EVMScriptRegistryFactory)
module.exports = function (deployer, network) {
return deployer.then(async () => {
await deployer.deploy(ScriptHelpers)
await deployer.link(ScriptHelpers, EVMScriptRegistryFactory)
})
}

0 comments on commit e98b67c

Please sign in to comment.