-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command: change-controller (#339)
- Loading branch information
1 parent
83e3696
commit 4551da1
Showing
4 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { | ||
manifestMiddleware, | ||
moduleMiddleware, | ||
environmentMiddleware, | ||
} = require('../../middleware') | ||
|
||
const MIDDLEWARES = [ | ||
manifestMiddleware, | ||
moduleMiddleware, | ||
environmentMiddleware, | ||
] | ||
|
||
exports.command = 'token <command>' | ||
|
||
exports.describe = 'Create and interact with MiniMe tokens' | ||
|
||
exports.builder = function(yargs) { | ||
return yargs | ||
.commandDir('token_cmds', { | ||
visit: cmd => { | ||
cmd.middlewares = MIDDLEWARES | ||
return cmd | ||
}, | ||
}) | ||
.demandCommand(1, 'You need to specify a command') | ||
} |
82 changes: 82 additions & 0 deletions
82
packages/aragon-cli/src/commands/dao_cmds/token_cmds/change-controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const TaskList = require('listr') | ||
const { ensureWeb3 } = require('../../../helpers/web3-fallback') | ||
const { getContract } = require('../../../util') | ||
const listrOpts = require('../../../helpers/listr-options') | ||
const chalk = require('chalk') | ||
|
||
exports.command = 'change-controller <token-address> <new-controller>' | ||
|
||
exports.describe = 'Change the controller of a MiniMe token' | ||
|
||
exports.builder = yargs => { | ||
return yargs | ||
.positional('token-address', { | ||
description: 'Address of the MiniMe token', | ||
}) | ||
.positional('new-controller', { | ||
description: 'Address of the new controller', | ||
}) | ||
} | ||
|
||
exports.task = async ({ web3, tokenAddress, newController, silent, debug }) => { | ||
// Decode sender | ||
const accounts = await web3.eth.getAccounts() | ||
const from = accounts[0] | ||
|
||
return new TaskList( | ||
[ | ||
{ | ||
title: 'Changing the MiniMe token controller', | ||
task: async (ctx, task) => { | ||
let artifact = getContract('@aragon/os', 'MiniMeToken') | ||
let contract = new web3.eth.Contract(artifact.abi, tokenAddress) | ||
|
||
const tx = contract.methods.changeController(newController) | ||
// this fails if from is not passed | ||
const gas = await tx.estimateGas({ from }) | ||
|
||
const sendPromise = tx.send({ from, gas }) | ||
sendPromise | ||
.on('transactionHash', transactionHash => { | ||
ctx.txHash = transactionHash | ||
}) | ||
.on('error', function(error) { | ||
throw error | ||
}) | ||
|
||
task.output = `Waiting for the transaction to be mined...` | ||
return sendPromise | ||
}, | ||
}, | ||
], | ||
listrOpts(silent, debug) | ||
) | ||
} | ||
|
||
exports.handler = async function({ | ||
reporter, | ||
network, | ||
tokenAddress, | ||
newController, | ||
silent, | ||
debug, | ||
}) { | ||
const web3 = await ensureWeb3(network) | ||
|
||
const task = await exports.task({ | ||
web3, | ||
reporter, | ||
tokenAddress, | ||
newController, | ||
silent, | ||
debug, | ||
}) | ||
return task.run().then(ctx => { | ||
reporter.success( | ||
`Successfully changed the controller of ${tokenAddress} to ${newController}` | ||
) | ||
reporter.info(`Transaction hash: ${chalk.bold(ctx.txHash)}`) | ||
|
||
process.exit() | ||
}) | ||
} |
150 changes: 150 additions & 0 deletions
150
packages/aragon-cli/src/commands/dao_cmds/token_cmds/new.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
const TaskList = require('listr') | ||
const { ensureWeb3 } = require('../../../helpers/web3-fallback') | ||
const { getContract } = require('../../../util') | ||
const listrOpts = require('../../../helpers/listr-options') | ||
const chalk = require('chalk') | ||
|
||
const ZERO_ADDR = '0x0000000000000000000000000000000000000000' | ||
|
||
exports.command = 'new <token-name> <symbol> [decimal-units] [transfer-enabled]' | ||
|
||
exports.describe = 'Create a new MiniMe token' | ||
|
||
exports.builder = yargs => { | ||
return yargs | ||
.positional('token-name', { | ||
description: 'Full name of the new Token', | ||
}) | ||
.positional('symbol', { | ||
description: 'Symbol of the new Token', | ||
}) | ||
.option('transfer-enabled', { | ||
description: 'Whether the new token will have transfers enabled', | ||
default: true, | ||
}) | ||
.option('decimal-units', { | ||
description: 'Total decimal units the new token will use', | ||
default: 18, | ||
}) | ||
} | ||
|
||
exports.task = async ({ | ||
web3, | ||
reporter, | ||
tokenName, | ||
symbol, | ||
transferEnabled, | ||
decimalUnits, | ||
silent, | ||
debug, | ||
}) => { | ||
// Decode sender | ||
const accounts = await web3.eth.getAccounts() | ||
const from = accounts[0] | ||
|
||
return new TaskList( | ||
[ | ||
{ | ||
title: 'Deploy the MiniMeTokenFactory contract', | ||
task: async (ctx, task) => { | ||
let artifact = getContract('@aragon/os', 'MiniMeTokenFactory') | ||
let contract = new web3.eth.Contract(artifact.abi) | ||
|
||
const deployTx = contract.deploy({ data: artifact.bytecode }) | ||
const gas = await deployTx.estimateGas() | ||
|
||
const deployPromise = deployTx.send({ from, gas }) | ||
deployPromise | ||
.on('receipt', function(receipt) { | ||
ctx.factoryAddress = receipt.contractAddress | ||
}) | ||
.on('transactionHash', transactionHash => { | ||
ctx.factoryTxHash = transactionHash | ||
}) | ||
.on('error', function(error) { | ||
throw error | ||
}) | ||
|
||
task.output = `Waiting for the transaction to be mined...` | ||
return deployPromise | ||
}, | ||
}, | ||
{ | ||
title: 'Deploy the MiniMeToken contract', | ||
task: async (ctx, task) => { | ||
let artifact = getContract('@aragon/os', 'MiniMeToken') | ||
let contract = new web3.eth.Contract(artifact.abi) | ||
|
||
const deployTx = contract.deploy({ | ||
data: artifact.bytecode, | ||
arguments: [ | ||
ctx.factoryAddress, | ||
ZERO_ADDR, | ||
0, | ||
tokenName, | ||
decimalUnits, | ||
symbol, | ||
transferEnabled, | ||
], | ||
}) | ||
const gas = await deployTx.estimateGas() | ||
|
||
const deployPromise = deployTx.send({ from, gas: gas + 1e6 }) | ||
deployPromise | ||
.on('receipt', function(receipt) { | ||
ctx.tokenAddress = receipt.contractAddress | ||
}) | ||
.on('transactionHash', transactionHash => { | ||
ctx.tokenTxHash = transactionHash | ||
}) | ||
.on('error', function(error) { | ||
throw error | ||
}) | ||
|
||
task.output = `Waiting for the transaction to be mined...` | ||
return deployPromise | ||
}, | ||
}, | ||
], | ||
listrOpts(silent, debug) | ||
) | ||
} | ||
|
||
exports.handler = async function({ | ||
reporter, | ||
network, | ||
tokenName, | ||
symbol, | ||
transferEnabled, | ||
decimalUnits, | ||
silent, | ||
debug, | ||
}) { | ||
const web3 = await ensureWeb3(network) | ||
|
||
const task = await exports.task({ | ||
web3, | ||
reporter, | ||
tokenName, | ||
symbol, | ||
transferEnabled, | ||
decimalUnits, | ||
silent, | ||
debug, | ||
}) | ||
return task.run().then(ctx => { | ||
reporter.success( | ||
`Successfully deployed the token at ${chalk.bold(ctx.tokenAddress)}` | ||
) | ||
reporter.info(`Token transaction hash: ${ctx.tokenTxHash}`) | ||
|
||
reporter.success( | ||
`Successfully deployed the token factory at ${chalk.bold( | ||
ctx.factoryAddress | ||
)}` | ||
) | ||
reporter.info(`Token factory transaction hash: ${ctx.factoryTxHash}`) | ||
|
||
process.exit() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters