API

The api of governance module

esLBR

Lybra governance token

Key Events

Event
Description

DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate)

An event thats emitted when an account changes its delegate.

DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance)

An event thats emitted when a delegate account’s vote balance changes.

Read-Only Functions

Function
Description

checkpoints(address account, uint32 pos)

Get the pos-th checkpoint for account.

delegates(address account)

Get the address account is currently delegating to.

getPastTotalSupply(uint256 timepoint)

Retrieve the totalSupply at the end of timepoint. Note, this value is the sum of all balances. It is NOT the sum of all the delegated votes!

Requirements:

  • timepoint must be in the past

getPastVotes(address account, uint256 timepoint)

Retrieve the number of votes for account at the end of timepoint.

Requirements:

  • timepoint must be in the past

getVotes(address account)

Gets the current votes balance for account

State-Changing Functions

Function
Description

delegate(address delegatee)

Delegate votes from the sender to delegatee.

delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s)

Delegate votes from the signatory to the delegatee. This method has the same purpose as Delegate but it instead enables offline signatures to participate in Lybra governance vote delegation.

Lybra Governance Contract

LybraGovernance.sol

Key Events

Event
Description

ProposalCreated(uint256 proposalId, address proposer, address[] targets, uint[] values, string[] signatures, bytes[] calldatas, uint256 voteStart, uint256 voteEnd, string description)

An event emitted when a new proposal is created.

VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason)

An event emitted when a vote has been cast on a proposal.

VoteCastWithParams(voter, proposalId, support, weight, reason, params)

An event emitted when a vote has been cast with params on a proposal.

ProposalCanceled(uint256 proposalId)

An event emitted when a proposal has been canceled.

ProposalQueued(uint256 proposalId, uint256 eta)

An event emitted when a proposal has been queued in the Timelock.

ProposalExecuted(uint256 proposalId)

An event emitted when a proposal has been executed in the Timelock.

Read-Only Functions

Function
Description

clock()

Clock used for flagging checkpoints.

CLOCK_MODE()

Description of the clock.

COUNTING_MODE()

A description of the possible support values for castVote and the way these votes are counted, meant to be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of key-value pairs that each describe one aspect, for example support=bravo&quorum=for,abstain.

There are 2 standard keys: support and quorum.

  • support=bravo refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in GovernorBravo.

  • quorum=bravo means that only For votes are counted towards quorum.

  • quorum=for,abstain means that both For and Abstain votes are counted towards quorum.

If a counting module makes use of encoded params, it should include this under a params key with a unique name that describes the behavior. For example:

  • params=fractional might refer to a scheme where votes are divided fractionally between for/against/abstain.

  • params=erc721 might refer to a scheme where specific NFTs are delegated to vote.

getVotes(address account, uint256 timepoint)

Voting power of an account at a specific timepoint.

getVotesWithParams(address account, uint256 timepoint, bytes params)

Voting power of an account at a specific timepoint given additional encoded parameters.

getReceipt(uint256 proposalId, address account)

Ballot receipt record for a voter.

  • voted Whether or not a vote has been cast.

  • support refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in GovernorBravo.

  • votes The number of votes the voter had, which were cast.

hashProposal(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)

The proposal id is produced by hashing the ABI encoded targets array, the values array, the calldatas array and the descriptionHash (bytes32 which itself is the keccak256 hash of the description string). This proposal id can be produced from the proposal data which is part of the ProposalCreated event. It can even be computed in advance, before the proposal is submitted.

Note that the chainId and the governor address are not part of the proposal id computation. Consequently, the same proposal (with same operation and same description) will have the same id if submitted on multiple governors across multiple networks. This also means that in order to execute the same operation twice (on the same governor) the proposer will have to change the description in order to avoid proposal id conflicts.

hasVoted(uint256 proposalId, address account)

Returns whether account has cast a vote on proposalId.

proposals(uint256 proposalId)

proposalDeadline(uint256 proposalId)

Timepoint at which votes close. If using block number, votes close at the end of this block, so it is possible to cast a vote during this block.

proposalEta(uint256 proposalId)

Public accessor to check the eta of a queued proposal

proposalProposer(uint256 proposalId)

The account that created a proposal.

proposalSnapshot(uint256 proposalId)

Timepoint used to retrieve user’s votes and quorum. If using block number , the snapshot is performed at the end of this block. Hence, voting for this proposal starts at the beginning of the following block.

proposalThreshold()

The number of votes required in order for a voter to become a proposer.

quorum(uint256 timepoint)

Minimum number of cast voted required for a proposal to be successful.

state(uint256 proposalId)

Current state of a proposal.

timelock()

Public accessor to check the address of the timelock

votingDelay()

Delay, between the proposal is created and the vote starts. The unit this duration is expressed in depends on the clock (see EIP-6372) this contract uses.

This can be increased to leave time for users to buy voting power, or delegate it, before the voting of a proposal starts.

votingPeriod()

Delay between the vote start and vote end. The unit this duration is expressed in depends on the clock (see EIP-6372) this contract uses.

State-Changing Functions

Function
Description

castVote(uint256 proposalId, uint8 support)

Cast a vote

Emits a VoteCast event.

castVoteBySig(uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s)

Cast a vote using the user’s cryptographic signature.

Emits a VoteCast event.

castVoteWithReason(uint256 proposalId, uint8 support, string reason)

Cast a vote with a reason

Emits a VoteCast event.

castVoteWithReasonAndParams(uint256 proposalId, uint8 support, string reason,bytes params)

Cast a vote with a reason and additional encoded parameters

Emits a VoteCast or VoteCastWithParams event depending on the length of params.

castVoteWithReasonAndParamsBySig(uint256 proposalId, uint8 support, string reason,bytes params, uint8 v, bytes32 r, bytes32 s)

Cast a vote with a reason and additional encoded parameters using the user’s cryptographic signature.

Emits a VoteCast or VoteCastWithParams event depending on the length of params.

propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)

Create a new proposal. Vote start after a delay specified by votingDelay and lasts for a duration specified by votingPeriod.

Emits a ProposalCreated event.

queue(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)

Function to queue a proposal to the timelock.

execute(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)

checkOnlyRole(keccak256("TIMELOCK")). Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the deadline to be reached.

Emits a ProposalExecuted event.

Note: some module can modify the requirements for execution, for example by adding an additional timelock.

cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)

Cancel a proposal. A proposal is cancellable by the proposer, but only while it is Pending state, i.e. before the vote starts.

Emits a ProposalCanceled event.

updateTimelock(address newTimelock)

Public endpoint to update the underlying timelock instance. Restricted to the timelock itself, so updates must be proposed, scheduled, and executed through governance proposals.

Timelock

GovernanceTimelock.sol inherit TimelockController.sol

Key Events

Event
Description

CallScheduled(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data, bytes32 predecessor, uint256 delay)

Emitted when a call is scheduled as part of operation id.

CallExecuted(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data)

Emitted when a call is performed as part of operation id.

CallSalt(bytes32 indexed id, bytes32 salt)

Emitted when new proposal is scheduled with non-zero salt.

Cancelled(bytes32 indexed id)

Emitted when operation id is cancelled.

MinDelayChange(uint256 oldDuration, uint256 newDuration)

Emitted when the minimum delay for future operations is modified.

RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole)

Emitted when newAdminRole is set as role's admin role, replacing previousAdminRole

DEFAULT_ADMIN_ROLE is the starting admin for all roles, despite RoleAdminChanged not being emitted signaling this.

RoleGranted(bytes32 indexed role, address indexed account, address indexed sender)

Emitted when account is granted role.

sender is the account that originated the contract call, an admin role bearer except when using _setupRole.

RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender)

Emitted when account is revoked role.

sender is the account that originated the contract call: - if using revokeRole, it is the admin role bearer - if using renounceRole, it is the role bearer (i.e. account)

Read-Only Functions

Function
Description

isOperation(bytes32 id)

Returns whether an id correspond to a registered operation. This includes both Pending, Ready and Done operations.

isOperationPending(bytes32 id)

Returns whether an operation is pending or not. Note that a "pending" operation may also be "ready".

isOperationReady(bytes32 id)

Returns whether an operation is ready for execution. Note that a "ready" operation is also "pending".

isOperationDone(bytes32 id)

Returns whether an operation is done or not.

getTimestamp(bytes32 id)

Returns the timestamp at which an operation becomes ready (0 for unset operations, 1 for done operations).

getMinDelay()

Returns the minimum delay for an operation to become valid.

This value can be changed by executing an operation that calls updateDelay.

hashOperation(address target, uint256 value, bytes calldata data, bytes32 predecessor, bytes32 salt, uint256 delay)

Returns the identifier of an operation containing a single transaction.

hashOperationBatch(address[] calldata targets, uint256[] calldata values, bytes[] calldata payloads, bytes32 predecessor, bytes32 salt)

Returns the identifier of an operation containing a batch of transactions.

hasRole(bytes32 role, address cccount)

Returns true if account has been granted role.

checkOnlyRole(bytes32 role, address _sender)

Revert with a standard message if account is missing role.

The format of the revert reason is given by the following regular expression:

/^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/

checkRole(bytes32 role, address _sender)

Revert with a standard message if account is missing role.

The format of the revert reason is given by the following regular expression:

/^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/

getRoleAdmin(bytes32 role)

Returns the admin role that controls role. See grantRole and revokeRole.

To change a role’s admin, use _setRoleAdmin.

State-Changing Functions

Function
Description

cancel(bytes32 id)

Cancel an operation.

Requirements:

  • the caller must have the 'canceller' role.

execute(address target, uint256 value, bytes calldata payload, bytes32 predecessor, bytes32 salt)

Execute an (ready) operation containing a single transaction.

Emits a CallExecuted event.

Requirements:

  • the caller must have the 'executor' role.

executeBatch(address[] memory targets, uint256[] memory values, bytes[] memory payloads, bytes32 predecessor, bytes32 salt)

Execute an (ready) operation containing a batch of transactions.

Emits one CallExecuted event per transaction in the batch.

Requirements:

  • the caller must have the 'executor' role.

grantRole(bytes32 role, address account)

Grants role to account.

If account had not been already granted role, emits a RoleGranted event.

Requirements:

  • the caller must have role's admin role.

revokeRole(bytes32 role, address account)

Revokes role from account.

If account had been granted role, emits a RoleRevoked event.

Requirements:

  • the caller must have role's admin role.

renounceRole(bytes32 role, address account)

Revokes role from the calling account.

Roles are often managed via grantRole and revokeRole: this function’s purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced).

If the calling account had been granted role, emits a RoleRevoked event.

Requirements:

  • the caller must be account.

schedule(address target, uint256 value, bytes32 data, bytes32 predecessor, bytes32 salt, uint256 delay)

Schedule an operation containing a single transaction.

Emits CallSalt if salt is nonzero, and CallScheduled.

Requirements:

  • the caller must have the 'proposer' role.

scheduleBatch(address[] calldata targets, uint256[] calldata values, bytes[] calldata payloads, bytes32 predecessor, bytes32 salt, uint256 delay)

Schedule an operation containing a batch of transactions.

Emits CallSalt if salt is nonzero, and one CallScheduled event per transaction in the batch.

Requirements:

  • the caller must have the 'proposer' role.

updateDelay(uint256 newDelay)

Changes the minimum timelock duration for future operations.

Emits a MinDelayChange event.

Requirements:

  • the caller must be the timelock itself. This can only be achieved by scheduling and later executing an operation where the timelock is the target and the data is the ABI-encoded call to this function.

Last updated