This contract provides a way to elect a "chief" contract via approval voting.
Voters lock up voting tokens to give their votes weight. The voting mechanism is approval voting.
Approval voting is when each voter selects which candidates they approve of,
with the top n
"most approved" candidates being elected. Each voter can cast
up to n + k
votes, where k
is some non-zero positive integer. This allows
voters to move their approval from one candidate to another without needing to
first withdraw support from the candidate being replaced. Without this, moving
approval to a new candidate could result in a less-approved candidate moving
momentarily into the set of elected candidates.
In the case of chief
, n
is 1.
In addition, chief
weights votes according to the quantity of a voting
token they've chosen to lock up in the Chief
contract.
It's important to note that the voting token used in a chief
deployment
must be specified at the time of deployment and cannot be changed afterward.
If you are writing a frontend for this smart contract, please note that the
address[]
parameters passed to the etch
and vote
functions must be
byte-ordered sets. E.g., [0x0, 0x1, 0x2, ...]
is valid, [0x1, 0x0, ...]
and [0x0, 0x0, 0x1, ...]
are not. This ordering constraint allows the contract
to cheaply ensure voters cannot multiply their weights by listing the same
candidate on their slate multiple times.
Chief
provides the following public properties:
live
: Indicates if the system is already active or not (1 == active, 0 == inactive).hat
: Contains the address of the current "chief".slates
: A mapping ofbytes32
toaddress
arrays. Represents sets of candidates. Weighted votes are given to slates.votes
: A mapping of voter addresses to the slate they have voted for.approvals
: A mapping of candidate addresses to theiruint256
weight.deposits
: A mapping of voter addresses touint256
number of tokens locked.last
: A record representing the last block whenlift
orlaunch
was called.gov
:Token
used for voting.maxYays
: Maximum number of candidates a slate can hold.launchThreshold
: Initial amount to lock inaddress(0)
for activating thechief
.liftCooldown
: Minimum number of blocks between blocks containing alift
.
The following events are triggered:
Launch()
: Fired when thechief
is activated.Lock(uint256 wad)
: Fired when someone depositsgov
tokens.Free(uint256 wad)
: Fired when someone withdrawsgov
tokens.Etch(bytes32 indexed slate, address[] yays)
: Fired when a slate is created.Vote(bytes32 indexed slate)
: Fired when a slated is voted.Lift(address indexed whom)
: Fired when a newhat
is elected.
Its public functions are as follows:
It is the function that will be used by other contracts to verify if caller can execute an action.
In this case, it will return true if the system is active and caller equals to hat
.
Launches the system when the conditions are met (approvals
on address(0)
are >= launchThreshold
).
Transfers from the user wad
gov
tokens and adds wad
weight to the candidates on the user's selected slate.
Returns wad
amount of gov
tokens to the user and subtracts wad
weight from the candidates on the user's selected slate.
Requires that there hasn't been a launch
or lift
call previously done in the same block.
Save a set of ordered addresses and return a unique identifier (slate) for it.
Save a set of ordered addresses as a slate, moves the voter's weight from their current slate to the new slate, and returns the slate's identifier.
Removes voter's weight from their current slate and adds it to the specified slate.
Checks the given address and promotes it as the hat
of the chief
if it has more weight than the current hat
.
Requires that there hasn't been a launch
or another lift
call done during the previous X blocks (defined in an immutable).