Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Weighted Voting

A smart contract that implements weighted voting based on Token-V2 amounts.

It implements a ballot-style election where voters can either vote "for" or "against" the proposal. In the case of a tie, the ballot is rejected.

During initialization a Token-V2 contract is specified. When the election is live, voters can submit votes "for" or "against" the ballot. During counting, each voter's vote is weighted by the amount of tokens they own at the end of the election.

The interface closely mimics that of the voting example contract.

Example

A voter that owns 10 tokens casts in favor of the ballot.

A voter that owns 15 tokens casts in opposition of the ballot.

Once the deadline has passed and the results are counted, the ballot is rejected since the final result is -5, calculated by subtracting the votes against the ballot from the votes for the ballot.

Initialization

A configuration of the token contract must be given when initializing the voting contract. This initialization includes the address of the token, the shortname and what the return type is.

When using with a token-v2 MPC20 contract these must be set to:

  • address: Address of the deployed token.
  • shortname_u32: 8 (Shortname of balance_of.)
  • token_type: U128 (Because token-v2 supports u128 token amounts.)

When using with the MPC token contract, for doing MPC weighted votes , these fields must be set to:

  • address: 01a4082d9d560749ecd0ffa1dcaaaee2c2cb25d881
  • shortname_u32: 80 (Shortname of get_stakes_for_jobs.)
  • token_type: U64 (Because MPC token uses u64 token amounts.)

Other contracts can easily be used by setting these fields to the appropriate values.

Security

The voting weights are pulled at the end of the election during counting. This may incentivize voters to buy more tokens towards the end of the election and then sell them afterwards.

Moreover, this implies that voters with 0 tokens must be included in the election until the end because they could later buy tokens. Because of this, a malicious actor could potentially flood the election with voters who will never purchase tokens. However, the gas cost of voting is intended to be an incentive against this scenario.

The gas cost of counting the votes scales with the number of votes. Thus, if an election is large, the entity who calls the smart contract action to count the election may incur a large cost. This can be remedied by the voters privately between themselves or by charging extra gas up front from each voter that goes towards counting costs.