From f30f4292b9c12ebb9fc97684ca959ea47db14eb3 Mon Sep 17 00:00:00 2001 From: Facu Spagnuolo Date: Mon, 9 Nov 2020 19:40:15 -0300 Subject: [PATCH] cli: update protocol to v1.0.0-beta.3 --- packages/app/src/web3/Network.js | 6 +-- packages/cli/bin/setup.js | 11 +++-- packages/cli/src/commands/activate.js | 16 +++---- packages/cli/src/commands/arbitrable.js | 9 ++-- packages/cli/src/commands/commit.js | 8 ++-- packages/cli/src/commands/deactivate.js | 10 +++-- packages/cli/src/commands/reveal.js | 10 ++--- packages/cli/src/commands/stake.js | 7 ++-- packages/cli/src/commands/unstake.js | 9 ++-- packages/shared/models/Protocol.js | 55 ++++++++++--------------- packages/shared/package.json | 2 +- packages/shared/truffle-config.js | 8 ++-- yarn.lock | 8 ++-- 13 files changed, 73 insertions(+), 86 deletions(-) diff --git a/packages/app/src/web3/Network.js b/packages/app/src/web3/Network.js index 57577b0..b433b7c 100644 --- a/packages/app/src/web3/Network.js +++ b/packages/app/src/web3/Network.js @@ -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 = { diff --git a/packages/cli/bin/setup.js b/packages/cli/bin/setup.js index 71ae764..4b18eaf 100644 --- a/packages/cli/bin/setup.js +++ b/packages/cli/bin/setup.js @@ -11,7 +11,7 @@ const logger = Logger('setup') const { network, guardians: guardiansNumber, disputes } = yargs .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 @@ -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 @@ -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}`) + const arbitrable = output.toString().match(/0x[a-fA-F0-9]{40}/g) + console.log(arbitrable) 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}`) } diff --git a/packages/cli/src/commands/activate.js b/packages/cli/src/commands/activate.js index 332a23b..59d5638 100644 --- a/packages/cli/src/commands/activate.js +++ b/packages/cli/src/commands/activate.js @@ -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 = { diff --git a/packages/cli/src/commands/arbitrable.js b/packages/cli/src/commands/arbitrable.js index 6ca9bf1..53259e2 100644 --- a/packages/cli/src/commands/arbitrable.js +++ b/packages/cli/src/commands/arbitrable.js @@ -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) } diff --git a/packages/cli/src/commands/commit.js b/packages/cli/src/commands/commit.js index 42b3f67..2a77c1f 100644 --- a/packages/cli/src/commands/commit.js +++ b/packages/cli/src/commands/commit.js @@ -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 = { diff --git a/packages/cli/src/commands/deactivate.js b/packages/cli/src/commands/deactivate.js index add0242..38dcc19 100644 --- a/packages/cli/src/commands/deactivate.js +++ b/packages/cli/src/commands/deactivate.js @@ -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 = { diff --git a/packages/cli/src/commands/reveal.js b/packages/cli/src/commands/reveal.js index c5c7fda..aaefd8c 100644 --- a/packages/cli/src/commands/reveal.js +++ b/packages/cli/src/commands/reveal.js @@ -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 = { diff --git a/packages/cli/src/commands/stake.js b/packages/cli/src/commands/stake.js index 8e26e77..4bb5d68 100644 --- a/packages/cli/src/commands/stake.js +++ b/packages/cli/src/commands/stake.js @@ -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}`) } diff --git a/packages/cli/src/commands/unstake.js b/packages/cli/src/commands/unstake.js index 5e3a6b0..03a57f8 100644 --- a/packages/cli/src/commands/unstake.js +++ b/packages/cli/src/commands/unstake.js @@ -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 = { diff --git a/packages/shared/models/Protocol.js b/packages/shared/models/Protocol.js index d1507d2..ce06af3 100644 --- a/packages/shared/models/Protocol.js +++ b/packages/shared/models/Protocol.js @@ -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) } @@ -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) { @@ -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) } @@ -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) @@ -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) { @@ -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) { diff --git a/packages/shared/package.json b/packages/shared/package.json index 4f56619..06a73fe 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -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", diff --git a/packages/shared/truffle-config.js b/packages/shared/truffle-config.js index 7ea72b4..ca7a37c 100644 --- a/packages/shared/truffle-config.js +++ b/packages/shared/truffle-config.js @@ -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 diff --git a/yarn.lock b/yarn.lock index 1f24a01..1a2a958 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,10 +10,10 @@ web3-eth-abi "1.2.5" web3-utils "1.2.5" -"@aragon/protocol-evm@1.0.0-beta.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/protocol-evm@1.0.0-beta.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"