Skip to content

Governance calls reference

Egor Lysenko edited this page Jan 19, 2021 · 3 revisions

Governance contract calls reference

Place a vote

Create a proposal vote.

Parameters:

  1. Address of a voter which receives the delegation. If sender is a self-voter, then sender address should be used
  2. Proposal ID (number)
  3. An array of choices. Number of choices must be equal to the number of options. Index of a choice in the array corresponds to an index of option. Example: [0, 3, 4] represents "0 for option 0, 3 for option 1, 4 for option 2"

Creation of a vote from a self-voter:

gov.vote(voter, proposalID, choices, {from: voter});

Creation of a vote from a delegator:

gov.vote(delegatedTo, proposalID, choices, {from: voter});

Check out voting model for additional details.

Checks

  • Voter has a non-zero weight
  • Vote with a tuple {voter, delegatedTo, proposalID} must not exist
  • Proposal isn't finalized
  • Proposal voting has started
  • Number of choices is equal to the number of options
  • Every opinion is smaller than a number of opinion scales for the proposal

Cancel a vote

Cancel a proposal vote.

Parameters:

  1. Address of a voter which receives the delegation. If sender is a self-voter, then sender address should be used
  2. Proposal ID (number)

Cancellation of a vote from a self-voter:

gov.cancelVote(voter, proposalID, {from: voter});

Cancellation of a vote from a delegator:

gov.vote(delegatedTo, proposalID, {from: voter});

Checks

  • Vote with a tuple {voter, delegatedTo, proposalID} must exist
  • Proposal isn't finalized

Create a proposal

Create a proposal using a proposal contract.

Each proposal creation will require a cost (called fee), which is a contract instant. 50% of the proposal fee is burnt, 40% is rewarded to a task handler, 10% is rewarded to a task eraser.

// Artifacts of the proposal contract
proposalAbi = JSON.parse('ABI_HERE');
proposalBin = '0xBYTECODE_HERE';
// Create new proposal contract
proposal = web3.ftm.contract(proposalAbi).new(proposal_parameters_here, { from: account, data: proposalBin });
// wait until transaction is confirmed and the contract has received its address
proposal.address;
// Create proposal, transfering proposal fee during this operation
// The call will revert if proposal verification fails
proposalFee = gov.proposalFee();
gov.createProposal(proposal.address, {from: account, value: proposalFee});
// Find your proposal ID
id = gov.lastProposalID();
// Ensure that id points to your proposal
gov.proposalParams(id);

After the call, proposal ID may retrieved with gov.lastProposalID(). There might be multiple proposals deployed at the same time, thus double-check the proposal ID by matching its parameters with your arguments: gov.proposalParams(id). If parameters do not match, check higher or lower proposal IDs.

Checks

  • Proposal parameters and proposal contract passed the verification
  • Proposal creation fee is equal to gov.proposalFee()

Cancel a proposal

Cancels a proposal if it has no votes.

The call doesn't refund proposal fee.

The governance contract allowes proposal cancellation only if it's called by the proposal contract.

Cancellation of a proposal which implements the Cancelable interface:

// ABI of the proposal
proposalAbi = JSON.parse('ABI_HERE');

proposalAddress = gov.proposalParams(proposalID)[6];
proposal = web3.ftm.contract(proposalAbi).at(proposalAddress);

proposal.cancel(proposalID, gov.address, {from: proposalCreator});

Checks

  • Proposal exists
  • Proposal isn't finalised
  • Proposal has no votes
  • Caller is the proposal contract