Skip to content

Instantly share code, notes, and snippets.

@adklempner
Created April 26, 2020 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adklempner/8154c99799334ab895c99b61830eabbe to your computer and use it in GitHub Desktop.
Save adklempner/8154c99799334ab895c99b61830eabbe to your computer and use it in GitHub Desktop.
/*
* These hooks are called by the Aragon Buidler plugin during the start task's lifecycle. Use them to perform custom tasks at certain entry points of the development build process, like deploying a token before a proxy is initialized, etc.
*
* Link them to the main buidler config file (buidler.config.js) in the `aragon.hooks` property.
*
* All hooks receive two parameters:
* 1) A params object that may contain other objects that pertain to the particular hook.
* 2) A "bre" or BuidlerRuntimeEnvironment object that contains enviroment objects like web3, Truffle artifacts, etc.
*
* Please see AragonConfigHooks, in the plugin's types for further details on these interfaces.
* https://github.com/aragon/buidler-aragon/blob/develop/src/types.ts#L31
*/
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
let pct16
let tokens, accounts, voting
module.exports = {
// Called before a dao is deployed.
preDao: async ({ log }, { web3, artifacts }) => { },
// Called after a dao is deployed.
postDao: async ({ dao, _experimentalAppInstaller, log }, { web3, artifacts }) => {
const bigExp = (x, y) =>
web3.utils
.toBN(x)
.mul(web3.utils.toBN(10).pow(web3.utils.toBN(y)))
pct16 = (x) => bigExp(x, 16)
// Retrieve accounts.
accounts = await web3.eth.getAccounts()
// Deploy a minime token an generate tokens to root account
const minime = await _deployMinimeToken({ web3, artifacts })
await minime.generateTokens(accounts[1], pct16(100))
log(`> Minime token deployed: ${minime.address}`)
tokens = await _experimentalAppInstaller('token-manager', {
skipInitialize: true,
})
await minime.changeController(tokens.address)
log(`> Change minime controller to tokens app`)
await tokens.initialize([minime.address, true, 0])
log(`> Tokens app installed: ${tokens.address}`)
voting = await _experimentalAppInstaller('voting', {
skipInitialize: false,
initializeArgs: [
minime.address,
pct16(50), // support 50%
pct16(25), // quorum 15%
604800, // 7 d
]
})
// voting.initialize([
// minime.address,
// pct16(50), // support 50%
// pct16(25), // quorum 15%
// 604800, // 7 days
// ]);
log(`> Voting app installed: ${voting.address}`)
},
// Called after the app's proxy is created, but before it's initialized.
preInit: async (
{ proxy, _experimentalAppInstaller, log },
{ web3, artifacts }
) => { },
// Called after the app's proxy is initialized.
postInit: async (
{ proxy, _experimentalAppInstaller, log },
{ web3, artifacts }
) => {
await tokens.createPermission('MINT_ROLE', proxy.address)
},
// Called when the start task needs to know the app proxy's init parameters.
// Must return an array with the proxy's init parameters.
getInitParams: async ({ log }, { web3, artifacts }) => {
return [
42
]
},
// Called after the app's proxy is updated with a new implementation.
postUpdate: async ({ proxy, log }, { web3, artifacts }) => { },
}
async function _deployMinimeToken(bre) {
const MiniMeTokenFactory = await bre.artifacts.require('MiniMeTokenFactory')
const MiniMeToken = await bre.artifacts.require('MiniMeToken')
const factory = await MiniMeTokenFactory.new()
const token = await MiniMeToken.new(
factory.address,
ZERO_ADDRESS,
0,
'MiniMe Test Token',
18,
'MMT',
true
)
return token
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment