Skip to content

Commit

Permalink
Optimize Contracts Directory (#247)
Browse files Browse the repository at this point in the history
* optimization script

* import ABI utility

* custom ABI import

* remove bytecode option

* formatting

* cli fixes

* scripts

* no whitespace + do everything

* export noWhitespace

* no duplicates rc.34 & rc.35

* linter fixes

* fix

* revert duplicate optimization

* contracts-optimized directory

* revert

* revert

* added to migration
  • Loading branch information
dOrgJelli authored and ben-kaufman committed Dec 23, 2019
1 parent 4032b11 commit 2dc5d1a
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ verify.js.map
verify.js
flattened.*.sol
deployment-state.json
contracts-optimized
63 changes: 35 additions & 28 deletions migrate-base.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
async function migrateBase ({ arcVersion, web3, spinner, confirm, opts, logTx, previousMigration, getArcVersionNumber }) {
const utils = require('./utils')

async function migrateBase ({ arcVersion, web3, spinner, confirm, opts, logTx, previousMigration, getArcVersionNumber, optimizedAbis }) {
if (!(await confirm('About to migrate base contracts. Continue?'))) {
return
}

let contractsDir = 'contracts'
if (optimizedAbis) {
contractsDir = 'contracts-optimized'
}

const addresses = {}
const network = await web3.eth.net.getNetworkType()

Expand Down Expand Up @@ -60,15 +67,15 @@ async function migrateBase ({ arcVersion, web3, spinner, confirm, opts, logTx, p

if (network === 'private') {
GENToken = await deploy(
require(`./contracts/${arcVersion}/DAOToken.json`),
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOToken.json`),
[],
'DAOstack',
'GEN',
web3.utils.toWei('100000000')
)

const GENTokenContract = await new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAOToken.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOToken.json`).abi,
GENToken,
opts
)
Expand All @@ -94,25 +101,25 @@ async function migrateBase ({ arcVersion, web3, spinner, confirm, opts, logTx, p
}

await deploy(
require(`./contracts/${arcVersion}/DAORegistry.json`),
utils.importAbi(`./${contractsDir}/${arcVersion}/DAORegistry.json`),
[],
web3.eth.accounts.wallet[0].address
)
if (getArcVersionNumber(arcVersion) >= 29) {
DAOTracker = await deploy(require(`./contracts/${arcVersion}/DAOTracker.json`))
DAOTracker = await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/DAOTracker.json`))
}
} else {
addresses['GEN'] = GENToken
if (network === 'main') {
await deploy(
require(`./contracts/${arcVersion}/DAORegistry.json`),
utils.importAbi(`./${contractsDir}/${arcVersion}/DAORegistry.json`),
[],
'0x85e7fa550b534656d04d143b9a23a11e05077da3' // DAOstack's controlled account
)
if (getArcVersionNumber(arcVersion) >= 29) {
DAOTracker = await deploy(require(`./contracts/${arcVersion}/DAOTracker.json`))
DAOTracker = await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/DAOTracker.json`))
const daoTracker = new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAOTracker.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOTracker.json`).abi,
DAOTracker,
opts
)
Expand All @@ -124,14 +131,14 @@ async function migrateBase ({ arcVersion, web3, spinner, confirm, opts, logTx, p
}
} else {
await deploy(
require(`./contracts/${arcVersion}/DAORegistry.json`),
utils.importAbi(`./${contractsDir}/${arcVersion}/DAORegistry.json`),
[],
'0x73Db6408abbea97C5DB8A2234C4027C315094936'
)
if (getArcVersionNumber(arcVersion) >= 29) {
DAOTracker = await deploy(require(`./contracts/${arcVersion}/DAOTracker.json`))
DAOTracker = await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/DAOTracker.json`))
const daoTracker = new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAOTracker.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOTracker.json`).abi,
DAOTracker,
opts
)
Expand All @@ -144,50 +151,50 @@ async function migrateBase ({ arcVersion, web3, spinner, confirm, opts, logTx, p
}
}

const ControllerCreator = await deploy(require(`./contracts/${arcVersion}/ControllerCreator.json`))
const ControllerCreator = await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/ControllerCreator.json`))

if (getArcVersionNumber(arcVersion) >= 29) {
await deploy(
require(`./contracts/${arcVersion}/DaoCreator.json`),
utils.importAbi(`./${contractsDir}/${arcVersion}/DaoCreator.json`),
['ControllerCreator', 'DAOTracker'],
ControllerCreator,
DAOTracker
)
} else {
await deploy(
require(`./contracts/${arcVersion}/DaoCreator.json`),
utils.importAbi(`./${contractsDir}/${arcVersion}/DaoCreator.json`),
['ControllerCreator'],
ControllerCreator
)
}
if (getArcVersionNumber(arcVersion) < 34) {
await deploy(require(`./contracts/${arcVersion}/UController.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/UController.json`))
}
await deploy(
require(`./contracts/${arcVersion}/GenesisProtocol.json`),
utils.importAbi(`./${contractsDir}/${arcVersion}/GenesisProtocol.json`),
['DAOToken'],
GENToken
)
await deploy(require(`./contracts/${arcVersion}/SchemeRegistrar.json`))
await deploy(require(`./contracts/${arcVersion}/UpgradeScheme.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/SchemeRegistrar.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/UpgradeScheme.json`))
await deploy(
require(`./contracts/${arcVersion}/GlobalConstraintRegistrar.json`)
utils.importAbi(`./${contractsDir}/${arcVersion}/GlobalConstraintRegistrar.json`)
)
await deploy(require(`./contracts/${arcVersion}/ContributionReward.json`))
await deploy(require(`./contracts/${arcVersion}/AbsoluteVote.json`))
await deploy(require(`./contracts/${arcVersion}/QuorumVote.json`))
await deploy(require(`./contracts/${arcVersion}/TokenCapGC.json`))
await deploy(require(`./contracts/${arcVersion}/VoteInOrganizationScheme.json`))
await deploy(require(`./contracts/${arcVersion}/OrganizationRegister.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/ContributionReward.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/AbsoluteVote.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/QuorumVote.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/TokenCapGC.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/VoteInOrganizationScheme.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/OrganizationRegister.json`))
if (getArcVersionNumber(arcVersion) >= 22) {
await deploy(require(`./contracts/${arcVersion}/Redeemer.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/Redeemer.json`))
}
if (getArcVersionNumber(arcVersion) >= 24) {
if (getArcVersionNumber(arcVersion) < 34) {
await deploy(require(`./contracts/${arcVersion}/UGenericScheme.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/UGenericScheme.json`))
}
} else {
await deploy(require(`./contracts/${arcVersion}/GenericScheme.json`))
await deploy(utils.importAbi(`./${contractsDir}/${arcVersion}/GenericScheme.json`))
}
let migration = { 'base': previousMigration.base || {} }
migration.base[arcVersion] = addresses
Expand Down
63 changes: 34 additions & 29 deletions migrate-dao.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
const utils = require('./utils.js')
const sanitize = require('./sanitize')

async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migrationParams, logTx, previousMigration, customAbisLocation, restart, getState, setState, cleanState, sendTx, getArcVersionNumber }) {
async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migrationParams, logTx, previousMigration, customAbisLocation, restart, getState, setState, cleanState, sendTx, getArcVersionNumber, optimizedAbis }) {
const network = await web3.eth.net.getNetworkType()
if (restart) {
cleanState(network)
}

let contractsDir = 'contracts'
if (optimizedAbis) {
contractsDir = 'contracts-optimized'
}

let deploymentState = getState(network)

// sanitize the parameters
Expand Down Expand Up @@ -46,49 +51,49 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
} = base[arcVersion]

const daoCreator = new web3.eth.Contract(
require(`./contracts/${arcVersion}/DaoCreator.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DaoCreator.json`).abi,
DaoCreator,
opts
)

const uController = getArcVersionNumber(arcVersion) < 34 ? new web3.eth.Contract(
require(`./contracts/${arcVersion}/UController.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/UController.json`).abi,
UController,
opts
) : null

const schemeRegistrar = new web3.eth.Contract(
require(`./contracts/${arcVersion}/SchemeRegistrar.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/SchemeRegistrar.json`).abi,
SchemeRegistrar,
opts
)

const contributionReward = new web3.eth.Contract(
require(`./contracts/${arcVersion}/ContributionReward.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/ContributionReward.json`).abi,
ContributionReward,
opts
)

const genericScheme = new web3.eth.Contract(
getArcVersionNumber(arcVersion) >= 24 && getArcVersionNumber(arcVersion) < 34 ? require(`./contracts/${arcVersion}/UGenericScheme.json`).abi : require(`./contracts/${arcVersion}/GenericScheme.json`).abi,
getArcVersionNumber(arcVersion) >= 24 && getArcVersionNumber(arcVersion) < 34 ? utils.importAbi(`./${contractsDir}/${arcVersion}/UGenericScheme.json`).abi : utils.importAbi(`./${contractsDir}/${arcVersion}/GenericScheme.json`).abi,
getArcVersionNumber(arcVersion) >= 24 && getArcVersionNumber(arcVersion) < 34 ? UGenericScheme : GenericScheme,
opts
)

const globalConstraintRegistrar = new web3.eth.Contract(
require(`./contracts/${arcVersion}/GlobalConstraintRegistrar.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/GlobalConstraintRegistrar.json`).abi,
GlobalConstraintRegistrar,
opts
)

const upgradeScheme = new web3.eth.Contract(
require(`./contracts/${arcVersion}/UpgradeScheme.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/UpgradeScheme.json`).abi,
UpgradeScheme,
opts
)

const genesisProtocol = new web3.eth.Contract(
require(`./contracts/${arcVersion}/GenesisProtocol.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/GenesisProtocol.json`).abi,
GenesisProtocol,
opts
)
Expand Down Expand Up @@ -172,19 +177,19 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
}

avatar = new web3.eth.Contract(
require(`./contracts/${arcVersion}/Avatar.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Avatar.json`).abi,
deploymentState.Avatar,
opts
)

daoToken = new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAOToken.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOToken.json`).abi,
await avatar.methods.nativeToken().call(),
opts
)

reputation = new web3.eth.Contract(
require(`./contracts/${arcVersion}/Reputation.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Reputation.json`).abi,
await avatar.methods.nativeReputation().call(),
opts
)
Expand All @@ -194,7 +199,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
} else {
spinner.start('Deploying Controller')
controller = new web3.eth.Contract(
require(`./contracts/${arcVersion}/Controller.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Controller.json`).abi,
await avatar.methods.owner().call(),
opts
)
Expand All @@ -203,11 +208,11 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
} else {
if (deploymentState.DAOToken === undefined) {
let { receipt, result } = await sendTx(new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAOToken.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOToken.json`).abi,
undefined,
opts
).deploy({
data: require(`./contracts/${arcVersion}/DAOToken.json`).bytecode,
data: utils.importAbi(`./${contractsDir}/${arcVersion}/DAOToken.json`).bytecode,
arguments: [tokenName, tokenSymbol, 0]
}), 'Deploying DAO Token')
daoToken = result
Expand All @@ -217,18 +222,18 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
setState(deploymentState, network)
}
daoToken = new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAOToken.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOToken.json`).abi,
deploymentState.DAOToken,
opts
)

if (deploymentState.Reputation === undefined) {
let { receipt, result } = await sendTx(new web3.eth.Contract(
require(`./contracts/${arcVersion}/Reputation.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Reputation.json`).abi,
undefined,
opts
).deploy({
data: require(`./contracts/${arcVersion}/Reputation.json`).bytecode
data: utils.importAbi(`./${contractsDir}/${arcVersion}/Reputation.json`).bytecode
}), 'Deploying Reputation')
reputation = result
await logTx(receipt, `${reputation.options.address} => Reputation`)
Expand All @@ -237,18 +242,18 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
setState(deploymentState, network)
}
reputation = new web3.eth.Contract(
require(`./contracts/${arcVersion}/Reputation.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Reputation.json`).abi,
deploymentState.Reputation,
opts
)

if (deploymentState.Avatar === undefined) {
let { receipt, result } = await sendTx(new web3.eth.Contract(
require(`./contracts/${arcVersion}/Avatar.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Avatar.json`).abi,
undefined,
opts
).deploy({
data: require(`./contracts/${arcVersion}/Avatar.json`).bytecode,
data: utils.importAbi(`./${contractsDir}/${arcVersion}/Avatar.json`).bytecode,
arguments: [orgName, daoToken.options.address, reputation.options.address]
}), 'Deploying Avatar.')
avatar = result
Expand All @@ -258,7 +263,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
setState(deploymentState, network)
}
avatar = new web3.eth.Contract(
require(`./contracts/${arcVersion}/Avatar.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Avatar.json`).abi,
deploymentState.Avatar,
opts
)
Expand Down Expand Up @@ -305,11 +310,11 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
} else {
if (deploymentState.Controller === undefined) {
let { receipt, result } = await sendTx(new web3.eth.Contract(
require(`./contracts/${arcVersion}/Controller.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Controller.json`).abi,
undefined,
opts
).deploy({
data: require(`./contracts/${arcVersion}/Controller.json`).bytecode,
data: utils.importAbi(`./${contractsDir}/${arcVersion}/Controller.json`).bytecode,
arguments: [avatar.options.address]
}), 'Deploying Controller')
controller = result
Expand All @@ -319,15 +324,15 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
setState(deploymentState, network)
}
controller = new web3.eth.Contract(
require(`./contracts/${arcVersion}/Controller.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/Controller.json`).abi,
deploymentState.Controller,
opts
)
}

if (migrationParams.noTrack !== true && getArcVersionNumber(arcVersion) >= 29 && deploymentState.trackedDAO !== true) {
const daoTracker = new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAOTracker.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAOTracker.json`).abi,
DAOTracker,
opts
)
Expand Down Expand Up @@ -370,7 +375,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration

if (network === 'private') {
const daoRegistry = new web3.eth.Contract(
require(`./contracts/${arcVersion}/DAORegistry.json`).abi,
utils.importAbi(`./${contractsDir}/${arcVersion}/DAORegistry.json`).abi,
DAORegistry,
opts
)
Expand Down Expand Up @@ -654,7 +659,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
const path = require('path')
let contractJson
if (standAlone.fromArc) {
contractJson = require(`./contracts/${standAlone.arcVersion ? standAlone.arcVersion : arcVersion}/${standAlone.name}.json`)
contractJson = utils.importAbi(`./${contractsDir}/${standAlone.arcVersion ? standAlone.arcVersion : arcVersion}/${standAlone.name}.json`)
} else {
contractJson = require(path.resolve(`${customAbisLocation}/${standAlone.name}.json`))
}
Expand Down Expand Up @@ -728,7 +733,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
const path = require('path')
let contractJson
if (customeScheme.fromArc) {
contractJson = require(`./contracts/${customeScheme.arcVersion ? customeScheme.arcVersion : arcVersion}/${customeScheme.name}.json`)
contractJson = utils.importAbi(`./${contractsDir}/${customeScheme.arcVersion ? customeScheme.arcVersion : arcVersion}/${customeScheme.name}.json`)
} else {
contractJson = require(path.resolve(`${customAbisLocation}/${customeScheme.name}.json`))
}
Expand Down
Loading

0 comments on commit 2dc5d1a

Please sign in to comment.