You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A voting machine is used to to determine the outcome of a dao proposal.
The proposals are submitted through schemes.
Each scheme has voting parameters and a staking token balance and ETH balance.
The proposals can be executed in two final states, Queue or Boost.
A boosted proposal is a proposal that received a favorable stake on an option.
An stake is deposit done in the staking token, this adds a financial incentive
and risk on a proposal to be executed faster.
A proposal in queue needs at least 50% (or more) of votes in favour in order to
be executed.
A proposal in boost state might need a % of votes in favour in order to be executed.
If a proposal ended and it has staked tokens on it the tokens can be redeemed by
the stakers.
If a staker staked on the winning option it receives a reward.
If a staker staked on a loosing option it lose his stake.
function setParameters(uint256[10] _params) externalreturns (bytes32paramsHash)
Hash the parameters, save them if necessary, and return the hash value
Parameters
Name
Type
Description
_params
uint256[10]
A parameters array
_params[0] - _queuedVoteRequiredPercentage,
_params[1] - _queuedVotePeriodLimit, //the time limit for a proposal to be in an absolute voting mode.
_params[2] - _boostedVotePeriodLimit, //the time limit for a proposal to be in an relative voting mode.
_params[3] - _preBoostedVotePeriodLimit, //the time limit for a proposal to be in an preparation state (stable) before boosted.
_params[4] -_thresholdConst
_params[5] -_quietEndingPeriod
_params[6] -_proposingRepReward
_params[7] -_minimumDaoBounty
_params[8] -_daoBountyConst
_params[9] - _boostedVoteRequiredPercentage |
Return Values
Name
Type
Description
paramsHash
bytes32
Hash of the given parameters
redeem
function redeem(bytes32_proposalId, address_beneficiary) publicreturns (uint256[2] rewards)
Redeem a reward for a successful stake, vote or proposing.
The function use a beneficiary address as a parameter (and not msg.sender) to enable users to redeem on behalf of someone else.
function redeemDaoBounty(bytes32_proposalId, address_beneficiary) publicreturns (uint256redeemedAmount, uint256potentialAmount)
redeemDaoBounty a reward for a successful stake.
The function use a beneficiary address as a parameter (and not msg.sender) to enable users to redeem on behalf of someone else.
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
_beneficiary
address
The beneficiary address
Return Values
Name
Type
Description
redeemedAmount
uint256
Redeem token amount
potentialAmount
uint256
Potential redeem token amount (if there is enough tokens bounty at the dao owner of the scheme )
calcExecuteCallBounty
function calcExecuteCallBounty(bytes32_proposalId) publicviewreturns (uint256executeCallBounty)
Calculate the execute boosted call bounty
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
executeCallBounty
uint256
The execute boosted call bounty
shouldBoost
function shouldBoost(bytes32_proposalId) publicviewreturns (boolshouldProposalBeBoosted)
Check if a proposal should be shifted to boosted phase.
Parameters
Name
Type
Description
_proposalId
bytes32
the ID of the proposal
Return Values
Name
Type
Description
shouldProposalBeBoosted
bool
True or false depending on whether the proposal should be boosted or not.
threshold
function threshold(bytes32_paramsHash, bytes32_schemeId) publicviewreturns (uint256schemeThreshold)
Returns the scheme's score threshold which is required by a proposal to shift to boosted state.
This threshold is dynamically set and it depend on the number of boosted proposal.
Parameters
Name
Type
Description
_paramsHash
bytes32
The scheme parameters hash
_schemeId
bytes32
The scheme identifier
Return Values
Name
Type
Description
schemeThreshold
uint256
Scheme's score threshold as real number.
stake
function stake(bytes32_proposalId, uint256_vote, uint256_amount) externalreturns (boolproposalExecuted)
Staking function
Parameters
Name
Type
Description
_proposalId
bytes32
id of the proposal
_vote
uint256
NO(1) or YES(2).
_amount
uint256
The betting amount
Return Values
Name
Type
Description
proposalExecuted
bool
true if the proposal was executed, false otherwise.
stakeWithSignature
function stakeWithSignature(bytes32proposalId, addressstaker, uint256stakeDecision, uint256amount, uint256nonce, bytessignature) externalreturns (boolproposalExecuted)
stakeWithSignature function
Parameters
Name
Type
Description
proposalId
bytes32
Id of the proposal
staker
address
Address of staker
stakeDecision
uint256
NO(1) or YES(2).
amount
uint256
The betting amount
nonce
uint256
Nonce value ,it is part of the signature to ensure that a signature can be received only once.
signature
bytes
Signed data by the staker
Return Values
Name
Type
Description
proposalExecuted
bool
True if the proposal was executed, false otherwise.
setSchemeRefund
function setSchemeRefund(addressavatar, addressscheme, uint256_voteGas, uint256_maxGasPrice) externalpayable
Allows the voting machine to receive ether to be used to refund voting costs
Config the vote refund for each scheme
Parameters
Name
Type
Description
avatar
address
Avatar contract address
scheme
address
Scheme contract address to set vote refund config
_voteGas
uint256
The amount of gas that will be used as vote cost
_maxGasPrice
uint256
The maximum amount of gas price to be paid, if the gas used is higher than this value only a portion of the total gas would be refunded
withdrawRefundBalance
function withdrawRefundBalance(addressscheme) public
Withdraw scheme refund balance
Parameters
Name
Type
Description
scheme
address
Scheme contract address to withdraw refund balance from
vote
function vote(bytes32_proposalId, uint256_vote, uint256_amount) externalreturns (boolproposalExecuted)
Voting function from old voting machine changing only the logic to refund vote after vote done
Parameters
Name
Type
Description
_proposalId
bytes32
id of the proposal
_vote
uint256
NO(1) or YES(2).
_amount
uint256
The reputation amount to vote with, 0 will use all available REP
Return Values
Name
Type
Description
proposalExecuted
bool
True if the proposal was executed, false otherwise.
execute
function execute(bytes32_proposalId) externalreturns (boolproposalExecuted)
Check if the proposal has been decided, and if so, execute the proposal
Parameters
Name
Type
Description
_proposalId
bytes32
The id of the proposal
Return Values
Name
Type
Description
proposalExecuted
bool
True if the proposal was executed, false otherwise.
voteInfo
function voteInfo(bytes32_proposalId, address_voter) externalviewreturns (uint256voterVote, uint256voterReputation)
Returns the vote and the amount of reputation of the user committed to this proposal
Parameters
Name
Type
Description
_proposalId
bytes32
the ID of the proposal
_voter
address
The address of the voter
Return Values
Name
Type
Description
voterVote
uint256
The voters vote
voterReputation
uint256
Amount of reputation committed by _voter to _proposalId
voteStatus
function voteStatus(bytes32_proposalId, uint256_choice) externalviewreturns (uint256voted)
Returns the reputation voted for a proposal for a specific voting choice.
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
_choice
uint256
The index in the voting choice
Return Values
Name
Type
Description
voted
uint256
Reputation for the given choice
isVotable
function isVotable(bytes32_proposalId) externalviewreturns (boolisProposalVotable)
Check if the proposal is votable
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
isProposalVotable
bool
True or false depending on whether the proposal is voteable
shareSignedAction
function shareSignedAction(bytes32proposalId, addressvoter, uint256voteDecision, uint256amount, uint256nonce, uint256actionType, bytessignature) external
Share the vote of a proposal for a voting machine on a event log
Parameters
Name
Type
Description
proposalId
bytes32
id of the proposal
voter
address
Address of voter
voteDecision
uint256
The vote decision, NO(1) or YES(2).
amount
uint256
The reputation amount to vote with, 0 will use all available REP
nonce
uint256
Nonce value ,it is part of the signature to ensure that a signature can be received only once.
actionType
uint256
1=vote, 2=stake
signature
bytes
The encoded vote signature
signalVote
function signalVote(bytes32proposalId, uint256voteDecision, uint256amount) external
Signal the vote of a proposal in this voting machine to be executed later
Parameters
Name
Type
Description
proposalId
bytes32
Id of the proposal to vote
voteDecision
uint256
The vote decisions, NO(1) or YES(2).
amount
uint256
The reputation amount to vote with, 0 will use all available REP
executeSignedVote
function executeSignedVote(bytes32proposalId, addressvoter, uint256voteDecision, uint256amount, uint256nonce, bytessignature) external
Execute a signed vote
Parameters
Name
Type
Description
proposalId
bytes32
Id of the proposal to execute the vote on
voter
address
The signer of the vote
voteDecision
uint256
The vote decision, NO(1) or YES(2).
amount
uint256
The reputation amount to vote with, 0 will use all available REP
nonce
uint256
Nonce value ,it is part of the signature to ensure that a signature can be received only once.
signature
bytes
The signature of the hashed vote
propose
function propose(uint256_totalOptions, bytes32_paramsHash, address_proposer, address_avatar) externalreturns (bytes32proposalId)
Register a new proposal with the given parameters. Every proposal has a unique ID which is being generated by calculating keccak256 of a incremented counter.
Parameters
Name
Type
Description
_totalOptions
uint256
The amount of options to be voted on
_paramsHash
bytes32
parameters hash
_proposer
address
address
_avatar
address
address
Return Values
Name
Type
Description
proposalId
bytes32
ID of the new proposal registered
internalVote
function internalVote(bytes32_proposalId, address_voter, uint256_vote, uint256_rep) internalreturns (boolproposalExecuted)
Vote for a proposal, if the voter already voted, cancel the last vote and set a new one instead
Parameters
Name
Type
Description
_proposalId
bytes32
id of the proposal
_voter
address
used in case the vote is cast for someone else
_vote
uint256
a value between 0 to and the proposal's number of choices.
_rep
uint256
how many reputation the voter would like to stake for this vote. if _rep==0 the voter full reputation will be use.
Return Values
Name
Type
Description
proposalExecuted
bool
true if the proposal was executed, false otherwise.
Throws if proposal is not open or if it has been executed
NB: executes the proposal if a decision has been reached
executeSignaledVote
function executeSignaledVote(bytes32proposalId, addressvoter) external
Execute a signaled vote on a votable proposal
Parameters
Name
Type
Description
proposalId
bytes32
id of the proposal to vote
voter
address
The signer of the vote
hashAction
function hashAction(bytes32proposalId, addresssigner, uint256option, uint256amount, uint256nonce, uint256actionType) publicviewreturns (bytes32actionHash)
Hash the vote data that is used for signatures
Parameters
Name
Type
Description
proposalId
bytes32
id of the proposal
signer
address
The signer of the vote
option
uint256
The vote decision, NO(1) or YES(2).
amount
uint256
The reputation amount to vote with, 0 will use all available REP
nonce
uint256
Nonce value, it is part of the signature to ensure that a signature can be received only once.
actionType
uint256
The governance action type to hash
Return Values
Name
Type
Description
actionHash
bytes32
Hash of the action
score
function score(bytes32_proposalId) publicviewreturns (uint256proposalScore)
Returns the proposal score
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
proposalScore
uint256
Proposal score as real number.
_execute
function _execute(bytes32_proposalId) internalreturns (boolproposalExecuted)
Check if the proposal has been decided, and if so, execute the proposal
Parameters
Name
Type
Description
_proposalId
bytes32
The id of the proposal
Return Values
Name
Type
Description
proposalExecuted
bool
True if the proposal was executed, false otherwise.
_score
function _score(bytes32_proposalId) internalviewreturns (uint256proposalScore)
Returns the proposal score (Confidence level)
For dual choice proposal S = (S+)/(S-)
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
proposalScore
uint256
Proposal score as real number.
_isVotable
function _isVotable(bytes32_proposalId) internalviewreturns (boolisProposalVotable)
Check if the proposal is votable
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
isProposalVotable
bool
True or false depending on whether the proposal is voteable
_stake
function _stake(bytes32_proposalId, uint256_vote, uint256_amount, address_staker) internalreturns (boolproposalExecuted)
staking function
Parameters
Name
Type
Description
_proposalId
bytes32
id of the proposal
_vote
uint256
NO(1) or YES(2).
_amount
uint256
The betting amount
_staker
address
Address of the staker
Return Values
Name
Type
Description
proposalExecuted
bool
True if the proposal was executed, false otherwise.
_propose
function _propose(uint256_choicesAmount, bytes32_paramsHash, address_proposer, address_avatar) internalreturns (bytes32proposalId)
Register a new proposal with the given parameters. Every proposal has a unique ID which is being generated by calculating keccak256 of a incremented counter.
Parameters
Name
Type
Description
_choicesAmount
uint256
the total amount of choices for the proposal
_paramsHash
bytes32
parameters hash
_proposer
address
Proposer address
_avatar
address
Avatar address
Return Values
Name
Type
Description
proposalId
bytes32
ID of the new proposal registered
_refundVote
function _refundVote(bytes32schemeId) internal
Refund a vote gas cost to an address
Parameters
Name
Type
Description
schemeId
bytes32
The id of the scheme that should do the refund
getParametersHash
function getParametersHash(uint256[10] _params) publicpurereturns (bytes32paramsHash)
Returns a hash of the given parameters
Parameters
Name
Type
Description
_params
uint256[10]
Array of params (10) to hash
Return Values
Name
Type
Description
paramsHash
bytes32
Hash of the given parameters
getProposalTimes
function getProposalTimes(bytes32_proposalId) externalviewreturns (uint256[3] times)
Returns proposals times variables.
Parameters
Name
Type
Description
_proposalId
bytes32
ID of the proposal
Return Values
Name
Type
Description
times
uint256[3]
Times array
getProposalSchemeId
function getProposalSchemeId(bytes32_proposalId) externalviewreturns (bytes32schemeId)
Returns the schemeId for a given proposal
Parameters
Name
Type
Description
_proposalId
bytes32
ID of the proposal
Return Values
Name
Type
Description
schemeId
bytes32
Scheme identifier
getStaker
function getStaker(bytes32_proposalId, address_staker) externalviewreturns (uint256vote, uint256amount)
Returns the vote and stake amount for a given proposal and staker
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
_staker
address
Staker address
Return Values
Name
Type
Description
vote
uint256
Proposal staker vote
amount
uint256
Proposal staker amount
getAllowedRangeOfChoices
function getAllowedRangeOfChoices() externalpurereturns (uint256min, uint256max)
Returns the allowed range of choices for a voting machine.
Return Values
Name
Type
Description
min
uint256
minimum number of choices
max
uint256
maximum number of choices
getNumberOfChoices
function getNumberOfChoices(bytes32_proposalId) publicviewreturns (uint256proposalChoicesNum)
Returns the number of choices possible in this proposal
Parameters
Name
Type
Description
_proposalId
bytes32
The proposal id
Return Values
Name
Type
Description
proposalChoicesNum
uint256
Number of choices for given proposal
proposalStatus
function proposalStatus(bytes32_proposalId) externalviewreturns (uint256preBoostedVotesNo, uint256preBoostedVotesYes, uint256totalStakesNo, uint256totalStakesYes)
Returns the total votes and stakes for a given proposal
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
preBoostedVotesNo
uint256
preBoostedVotes NO
preBoostedVotesYes
uint256
preBoostedVotes YES
totalStakesNo
uint256
Total stakes NO
totalStakesYes
uint256
Total stakes YES
proposalStatusWithVotes
function proposalStatusWithVotes(bytes32_proposalId) externalviewreturns (uint256votesNo, uint256votesYes, uint256preBoostedVotesNo, uint256preBoostedVotesYes, uint256totalStakesNo, uint256totalStakesYes)
Returns the total votes, preBoostedVotes and stakes for a given proposal
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
votesNo
uint256
Proposal votes NO
votesYes
uint256
Proposal votes YES
preBoostedVotesNo
uint256
Proposal pre boosted votes NO
preBoostedVotesYes
uint256
Proposal pre boosted votes YES
totalStakesNo
uint256
Proposal total stakes NO
totalStakesYes
uint256
Proposal total stakes YES
voteStake
function voteStake(bytes32_proposalId, uint256_vote) externalviewreturns (uint256totalStakeAmount)
Returns the amount stakes for a given proposal and vote
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
_vote
uint256
Vote number
Return Values
Name
Type
Description
totalStakeAmount
uint256
Total stake amount
winningVote
function winningVote(bytes32_proposalId) externalviewreturns (uint256winningVote)
Returns the winningVote for a given proposal
Parameters
Name
Type
Description
_proposalId
bytes32
The ID of the proposal
Return Values
Name
Type
Description
winningVote
uint256
Winning vote for given proposal
state
function state(bytes32_proposalId) externalviewreturns (enum DXDVotingMachine.ProposalState state)