hyperledger-labs / blockchain-carbon-accounting

This project implements blockchain applications for climate action and accounting, including emissions calculations, carbon trading, and validation of climate claims. It is part of the Linux Foundation's Hyperledger Climate Action and Accounting SIG.
https://wiki.hyperledger.org/display/CASIG/Carbon+Accounting+and+Certification+WG
Apache License 2.0
188 stars 104 forks source link

set quorum for DAO proposals #146

Closed sichen1234 closed 3 years ago

sichen1234 commented 3 years ago

The contract owner should have the ability to set quorum for voting on DAO proposals. A default could be set for all proposals during a period of time until changed.

sichen1234 commented 3 years ago

This can be done as a parameter from command line using hardhat

jamesondh commented 3 years ago

See commits: https://github.com/opentaps/blockchain-carbon-accounting/commit/6f84285b6036ac49fd27b681d6b909ef7079c6d3 https://github.com/opentaps/blockchain-carbon-accounting/commit/600e98759d7d6a4b9f96ea9158df89e9224bf570

sichen1234 commented 3 years ago

I tried $ npx hardhat setQuorum --network localhost --contract 0x610178dA211FEF7D417bC0e6FeD39F05609AD788 --value 500.000000000000000000 but got error { Error: invalid BigNumber string (argument="value", value="500.000000000000000000", code=INVALID_ARGUMENT, version=bignumber/5.1.0) at Logger.makeError (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/logger/src.ts/index.ts:205:28) at Logger.throwError (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/logger/src.ts/index.ts:217:20) at Logger.throwArgumentError (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/logger/src.ts/index.ts:221:21) at Function.BigNumber.from (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:240:27) at NumberCoder.encode (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/abi/src.ts/coders/number.ts:25:27) at /Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19 at Array.forEach (<anonymous>) at Object.pack (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12) at TupleCoder.encode (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:16) at AbiCoder.encode (/Users/sichen/hyperledger/blockchain-carbon-accounting/net-emissions-token-network/node_modules/@ethersproject/abi/src.ts/abi-coder.ts:112:15) reason: 'invalid BigNumber string', code: 'INVALID_ARGUMENT', argument: 'value', value: '500.000000000000000000' }

Can you give an example that works?

jamesondh commented 3 years ago

If I run npx hardhat getQuorum --network localhost --contract 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 immediately after npx hardhat node I get the value 632000000000 which is 632 (or about sqrt(400000)) with 9 zeros.

If I want to lower quorum to 100 votes, I put 100 followed by 9 zeros: npx hardhat setQuorum --network localhost --contract 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 --value 100000000000

sichen1234 commented 3 years ago

So I reduced my quroum to 100 votes, then had:

  1. Proposer vote 3600 in favor = 60 votes for
  2. Consumer 1 vote 2500 against = 50 votes against
  3. Consumer 2 vote 100 votes for = 10 votes for Total is 70 votes for, 50 votes against, but it was defeated. Screen Shot 2021-04-26 at 2 09 06 PM
sichen1234 commented 3 years ago

A second proposal was just "defeated" because it didn't have enough votes. Does "defeated" mean it didn't meet quorum threshold? Screen Shot 2021-04-26 at 2 14 34 PM

jamesondh commented 3 years ago

Defeated can either mean for votes < against votes or for votes < quorum. For example, here I lowered the quorum to 100, voted 98 votes on proposal 1, and it failed. I voted 100 votes for proposal 2 and it succeeded (although the reward calculation needs to be fixed since it just counts votes currently). Quorum is the minimum of for votes rather than minimum total votes on a proposal.

Screenshot from 2021-04-27 07-58-35

sichen1234 commented 3 years ago

Implemented a new Quorum Failed state to distinguish between Defeated and not met Quorum. This is all working now.