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

CLI: Update protocol to v1.0.0-beta.3 #19

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/app/src/web3/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Protocol from '@aragon/protocol-backend-shared/models/Protocol'
import Environment from '@aragon/protocol-backend-shared/models/environments/BrowserEnvironment'

const FAUCET = {
staging: '0x19420Cf68cf6a8d18882730c8e8BAd169eeb1bdC',
ropsten: '0xeBB0e629958469f28508d13f8497f9473AAd1A49',
rinkeby: '0x555Fc80D37b7Cd5Bc13E27BD899539BB6280aa58',
staging: '0xe350061440B68B23bE0Eab5a497f04c573f439c7',
ropsten: '0x9096366248a74B31bE66A02E208d99c9f6924677',
rinkeby: '0x69db98BaDA6c639C1bc9482eA79C61E2E85BE61C',
}

const Network = {
Expand Down
11 changes: 7 additions & 4 deletions packages/cli/bin/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const logger = Logger('setup')
const { network, guardians: guardiansNumber, disputes } = yargs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find documentation on this script in the package's README, so wasn't sure when this was meant to be used. This is just for setting up an environment on the local chain?

.help()
.option('network', { alias: 'n', describe: 'Network name', type: 'string', demand: true })
.option('guardians', { alias: 'j', describe: 'Number of guardians to activate', type: 'string', default: 5 })
.option('guardians', { alias: 'g', describe: 'Number of guardians to activate', type: 'string', default: 5 })
.option('disputes', { alias: 'd', describe: 'Number of disputes to create', type: 'string', default: 5 })
.strict()
.argv
Expand All @@ -31,8 +31,8 @@ async function setup() {
for (let i = 0; i < guardians.length; i++) {
const guardian = guardians[i]
const amount = (i + 1) * 10000
execSync(`node ./bin/index.js stake -a ${amount} -j ${guardian} -n ${network}`)
execSync(`node ./bin/index.js activate -a ${amount} -f ${guardian} -n ${network}`)
execSync(`node ./bin/index.js stake -a ${amount} -g ${guardian} -n ${network}`)
execSync(`node ./bin/index.js activate -a ${amount} -g ${guardian} -f ${guardian} -n ${network}`)
}

// check protocol has started
Expand All @@ -41,9 +41,12 @@ async function setup() {
if (currentTermId.eq(bn(0)) && neededTransitions.eq(bn(0))) {
logger.warn('Protocol has not started yet, please make sure Protocol is at term 1 to create disputes and run the script again.')
} else {

// create disputes
for (let i = 0; i < disputes; i++) {
const arbitrable = arbitrables[i]
const output = execSync(`node ./bin/index.js arbitrable -n ${network}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure, but does this deploy a new ArbitrableMock? Why aren't we able to use the previous arbitrables[i]?

Looking at the old code, was this just broken code?

const arbitrable = output.toString().match(/0x[a-fA-F0-9]{40}/g)
console.log(arbitrable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth logging a bit more info here :)

execSync(`node ./bin/index.js mint -t fee -a 5000 -r ${arbitrable} -n ${network}`)
execSync(`node ./bin/index.js dispute -a ${arbitrable} -m 'Testing dispute #${i}' -e 'http://github.com/aragon/aragon-protocol' -c -n ${network}`)
}
Expand Down
16 changes: 5 additions & 11 deletions packages/cli/src/commands/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ const describe = 'Activate tokens to the Protocol'

const builder = {
amount: { alias: 'a', describe: 'Number of tokens to activate', type: 'string', demand: true },
guardian: { alias: 'g', describe: 'Optional address of the guardian activating the tokens for', type: 'string' },
guardian: { alias: 'g', describe: 'Optional address of the guardian activating the tokens for (sender by default)', type: 'string' },
}

const handlerAsync = async (environment, { from, guardian, amount }) => {
const handlerAsync = async (environment, { guardian, amount }) => {
const protocol = await environment.getProtocol()

if (!guardian || guardian === from) {
await protocol.activate(amount)
logger.success(`Activated ${amount}`)
}
else {
await protocol.activateFor(guardian, amount)
logger.success(`Activated ${amount} for ${guardian}`)
}
const to = guardian || await protocol.environment.getSender()
await protocol.activate(to, amount)
logger.success(`Activated ${amount} for ${to}`)
}

module.exports = {
Expand Down
9 changes: 3 additions & 6 deletions packages/cli/src/commands/arbitrable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ const logger = require('@aragon/protocol-backend-shared/helpers/logger')('arbitr

const command = 'arbitrable'
const describe = 'Create new Arbitrable instance for the Protocol'
const builder = {}

const builder = {
owner: { alias: 'o', describe: 'Address owner of the Arbitrable', type: 'string' },
}

const handlerAsync = async (environment, { owner }) => {
const handlerAsync = async (environment, {}) => {
const protocol = await environment.getProtocol()
const arbitrable = await protocol.deployArbitrable(owner)
const arbitrable = await protocol.deployArbitrable()
logger.success(`Created Arbitrable instance ${arbitrable.address}`)
console.log(arbitrable.address)
}
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ const builder = {
dispute: { alias: 'd', describe: 'Dispute committing a vote for', type: 'string', demand: true },
outcome: { alias: 'o', describe: 'Voting outcome', type: 'string', demand: true },
password: { alias: 'p', describe: 'Password to hash the vote to commit', type: 'string', demand: true },
voter: { alias: 'v', describe: 'Address of the voter committing a vote for (sender by default)', type: 'string' },
}

const handlerAsync = async (environment, { dispute, outcome, password }) => {
const handlerAsync = async (environment, { dispute, voter, outcome, password }) => {
const protocol = await environment.getProtocol()
await protocol.commit(dispute, outcome, password)
logger.success(`Committed vote for dispute #${dispute}`)
const to = voter || await protocol.environment.getSender()
await protocol.commit(dispute, voter, outcome, password)
logger.success(`Committed vote for dispute #${dispute} for voter ${to}`)
}

module.exports = {
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/commands/deactivate.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const logger = require('@aragon/protocol-backend-shared/helpers/logger')('deactivate')

const command = 'deactivate'
const describe = 'Deactivate tokens to the Protocol'
const describe = 'Deactivate tokens from the Protocol'

const builder = {
amount: { alias: 'a', describe: 'Number of tokens to deactivate', type: 'string', demand: true },
guardian: { alias: 'g', describe: 'Optional address of the guardian deactivating the tokens from (sender by default)', type: 'string' },
}

const handlerAsync = async (environment, { amount }) => {
const handlerAsync = async (environment, { guardian, amount }) => {
const protocol = await environment.getProtocol()
await protocol.deactivate(amount)
logger.success(`Requested ${amount} tokens for deactivation`)
const from = guardian || await protocol.environment.getSender()
await protocol.deactivate(from, amount)
logger.success(`Requested ${amount} tokens for deactivation for ${from}`)
}

module.exports = {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ const command = 'reveal'
const describe = 'Reveal committed vote'

const builder = {
guardian: { alias: 'g', describe: 'Address of the guardian revealing for', type: 'string' },
dispute: { alias: 'd', describe: 'Dispute identification number', type: 'string', demand: true },
outcome: { alias: 'o', describe: 'Committed outcome to reveal', type: 'string', demand: true },
password: { alias: 'p', describe: 'Password used to commit the vote', type: 'string', demand: true },
voter: { alias: 'v', describe: 'Address of the voter revealing for (sender by default)', type: 'string' },
}

const handlerAsync = async (environment, { guardian, dispute, outcome, password }) => {
const handlerAsync = async (environment, { voter, dispute, outcome, password }) => {
const protocol = await environment.getProtocol()
const onBehalfOf = guardian || await protocol.environment.getSender()
await protocol.reveal(dispute, onBehalfOf, outcome, password)
logger.success(`Vote revealed for dispute #${dispute} for guardian ${onBehalfOf}`)
const to = voter || await protocol.environment.getSender()
await protocol.reveal(dispute, to, outcome, password)
logger.success(`Vote revealed for dispute #${dispute} for ${to}`)
}

module.exports = {
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/commands/stake.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ const command = 'stake'
const describe = 'Stake tokens for a guardian'

const builder = {
guardian: { alias: 'g', describe: 'Address of the guardian staking the tokens', type: 'string' },
amount: { alias: 'a', describe: 'Number of tokens to stake', type: 'string', demand: true },
data: { alias: 'd', describe: 'Optional data that can be used to ask for token activation', type: 'string' },
guardian: { alias: 'g', describe: 'Address of the guardian staking the tokens for (sender by default)', type: 'string' },
}

const handlerAsync = async (environment, { guardian, amount, data }) => {
const handlerAsync = async (environment, { guardian, amount }) => {
const protocol = await environment.getProtocol()
const to = guardian || await protocol.environment.getSender()
await protocol.stake(to, amount, data)
await protocol.stake(to, amount)
logger.success(`Staked ${amount} for ${to}`)
}

Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/commands/unstake.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ const describe = 'Unstake tokens for a guardian'

const builder = {
amount: { alias: 'a', describe: 'Number of tokens to unstake', type: 'string', demand: true },
data: { alias: 'd', describe: 'Optional data that can be used to ask for token activation', type: 'string' },
guardian: { alias: 'g', describe: 'Address of the guardian unstaking the tokens for (sender by default)', type: 'string' },
}

const handlerAsync = async (environment, { amount, data }) => {
const handlerAsync = async (environment, { guardian, amount }) => {
const protocol = await environment.getProtocol()
await protocol.unstake(amount, data)
logger.success(`Unstaked ${amount} tokens`)
const from = guardian || await protocol.environment.getSender()
await protocol.unstake(from, amount)
logger.success(`Unstaked ${amount} tokens for ${from}`)
}

module.exports = {
Expand Down
55 changes: 22 additions & 33 deletions packages/shared/models/Protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = class {
async token() {
if (!this._token) {
const registry = await this.registry()
const address = await registry.token()
const address = await registry.guardiansToken()
const ERC20 = await this.environment.getArtifact('ERC20Mock', '@aragon/protocol-evm')
this._token = await ERC20.at(address)
}
Expand Down Expand Up @@ -185,51 +185,40 @@ module.exports = class {
return Math.min(heartbeats, needed)
}

async stake(guardian, amount, data = '0x') {
async stake(guardian, amount) {
const token = await this.token()
const decimals = await token.decimals()
const registry = await this.registry()
const symbol = await token.symbol()
await this._approve(token, bigExp(amount, decimals), registry.address)
logger.info(`Staking ${amount} ${symbol} for ${guardian}...`)
return registry.stakeFor(guardian, bigExp(amount, decimals), data)
return registry.stake(guardian, bigExp(amount, decimals))
}

async unstake(amount, data = '0x') {
async unstake(guardian, amount) {
const token = await this.token()
const decimals = await token.decimals()
const registry = await this.registry()
const symbol = await token.symbol()
logger.info(`Unstaking ${amount} ${symbol} for ${await this.environment.getSender()}...`)
return registry.unstake(bigExp(amount, decimals), data)
logger.info(`Unstaking ${amount} ${symbol} for ${guardian}...`)
return registry.unstake(guardian, bigExp(amount, decimals))
}

async activate(amount) {
async activate(guardian, amount) {
const token = await this.token()
const decimals = await token.decimals()
const registry = await this.registry()
const symbol = await token.symbol()
logger.info(`Activating ${amount} ${symbol} for ${await this.environment.getSender()}...`)
return registry.activate(bigExp(amount, decimals))
logger.info(`Activating ${amount} ${symbol} for guardian ${guardian}...`)
return registry.activate(guardian, bigExp(amount, decimals))
}

async activateFor(address, amount) {
async deactivate(guardian, amount) {
const token = await this.token()
const decimals = await token.decimals()
const registry = await this.registry()
const symbol = await token.symbol()
await this._approve(token, bigExp(amount, decimals), registry.address)
const ACTIVATE_DATA = sha3('activate(uint256)').slice(0, 10)
logger.info(`Activating ${amount} ${symbol} for ${address}...`)
return registry.stakeFor(address, bigExp(amount, decimals), ACTIVATE_DATA)
}

async deactivate(amount) {
const token = await this.token()
const decimals = await token.decimals()
const registry = await this.registry()
logger.info(`Requesting ${amount} from ${await this.environment.getSender()} for deactivation...`)
return registry.deactivate(bigExp(amount, decimals))
logger.info(`Requesting ${amount} from ${guardian} for deactivation...`)
return registry.deactivate(guardian, bigExp(amount, decimals))
}

async pay(tokenAddress, amount, payer, data) {
Expand All @@ -246,7 +235,7 @@ module.exports = class {

async deployArbitrable() {
logger.info(`Creating new Arbitrable instance...`)
const Arbitrable = await this.environment.getArtifact('Arbitrable', '@aragon/protocol-evm')
const Arbitrable = await this.environment.getArtifact('ArbitrableMock', '@aragon/protocol-evm')
return Arbitrable.new(this.instance.address)
}

Expand All @@ -258,7 +247,7 @@ module.exports = class {
await feeToken.transfer(subject, totalFees)

logger.info(`Creating new dispute for subject ${subject} ...`)
const Arbitrable = await this.environment.getArtifact('Arbitrable', '@aragon/protocol-evm')
const Arbitrable = await this.environment.getArtifact('ArbitrableMock', '@aragon/protocol-evm')
const arbitrable = await Arbitrable.at(subject)
const { hash } = await arbitrable.createDispute(rulings, utf8ToHex(metadata))
const receipt = await this.environment.getTransaction(hash)
Expand Down Expand Up @@ -288,22 +277,22 @@ module.exports = class {
return getEvents(receipt, 'GuardianDrafted', { decodeForAbi: disputeManager.interface.abi }).map(event => event.args.guardian)
}

async commit(disputeId, outcome, password) {
async commit(disputeId, voter, outcome, password) {
const voteId = await this.getLastRoundVoteId(disputeId)
logger.info(`Committing a vote for dispute #${disputeId} on vote ID ${voteId}...`)
const voting = await this.voting()
return voting.commit(voteId, hashVote(outcome, soliditySha3(password)))
return voting.commit(voteId, voter, hashVote(outcome, soliditySha3(password)))
}

async reveal(disputeId, guardian, outcome, password) {
async reveal(disputeId, voter, outcome, password) {
const voteId = await this.getLastRoundVoteId(disputeId)
return this.revealFor(voteId, guardian, outcome, soliditySha3(password))
return this.revealFor(voteId, voter, outcome, soliditySha3(password))
}

async revealFor(voteId, guardian, outcome, salt) {
logger.info(`Revealing vote for guardian ${guardian} on vote ID ${voteId}...`)
async revealFor(voteId, voter, outcome, salt) {
logger.info(`Revealing vote for ${voter} on vote ID ${voteId}...`)
const voting = await this.voting()
return voting.reveal(voteId, guardian, outcome, salt)
return voting.reveal(voteId, voter, outcome, salt)
}

async appeal(disputeId, outcome) {
Expand Down Expand Up @@ -360,7 +349,7 @@ module.exports = class {

async execute(disputeId) {
logger.info(`Executing ruling of dispute #${disputeId}...`)
return this.instance.executeRuling(disputeId)
return this.instance.rule(disputeId)
}

async settle(disputeId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Aragon One",
"license": "(GPL-3.0-or-later OR AGPL-3.0-or-later)",
"dependencies": {
"@aragon/protocol-evm": "1.0.0-beta.2",
"@aragon/protocol-evm": "1.0.0-beta.3",
"@aragon/contract-helpers-test": "^0.1.0",
"@aragon/truffle-config-v5": "^1.0.1",
"@aragonone/erc20-faucet": "^1.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ config.networks.staging = Object.assign({}, { ...config.networks.rinkeby })
const { networks: { ganache, ropsten, rinkeby, staging, mainnet } } = config

ganache.protocol = undefined
staging.protocol = '0x2057Fa53c5c85bB2cff125f9DB2D0cA7E4eeBE02'
ropsten.protocol = '0x7639480251C12f8168eeEc5e815Ab96072E5fe62'
rinkeby.protocol = '0xDB56c4d44ba23133805A38d837aBeC811D6c28b9'
mainnet.protocol = '0xee4650cBe7a2B23701D416f58b41D8B76b617797'
staging.protocol = '0x3E5D4a431f955C1eaB2BF919e174426572c4714F'
ropsten.protocol = '0xc236205f7f1c4a4B0A857c350BF64bB0FF385702'
rinkeby.protocol = '0x3F5E248BB5cd3c1275304e692d6cacC708E004d0'
mainnet.protocol = undefined

module.exports = config
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
web3-eth-abi "1.2.5"
web3-utils "1.2.5"

"@aragon/[email protected].2":
version "1.0.0-beta.2"
resolved "https://registry.yarnpkg.com/@aragon/protocol-evm/-/protocol-evm-1.0.0-beta.2.tgz#3cfdcfcbbaebc2b651fb3f1b9d200f17533ca95f"
integrity sha512-2EyoiAUDOZV8zZPqAZpVP9ih/H+AhYRQde7sapMJJv124yd7QdfAVxDuthq92bf5Jpppty1uuWKw9Ne2MBSQQA==
"@aragon/[email protected].3":
version "1.0.0-beta.3"
resolved "https://registry.yarnpkg.com/@aragon/protocol-evm/-/protocol-evm-1.0.0-beta.3.tgz#674443d03160917a63bd969dab87790e4f7478ac"
integrity sha512-WH/w6oqgNhJOwmfpVlPaLjEfnKEjnWO5PXZ7gWa9lsPZp7Qm4U03miLmJ4UcbExV2clrBXX/ikU9VM05ehQqUw==

"@aragon/truffle-config-v5@^1.0.1":
version "1.0.1"
Expand Down