# Governance Reference

Pharo protocol is governed and upgraded by PHRO token holders, using three distinct components; the PHRO token, governance module and timelock. Together these contracts allow the community to propose, vote, and implement changes to the Pharo protocol.

Any addresses with more than 10M gPHRO delegated to it may propose governance actions.&#x20;

### Timelock

The Timelock contract can modify system parameters, logic, and contracts in a 'time-delayed, opt-out' upgrade pattern. Timelock has a hard-coded minimum delay of 2 days, which is the least amount of notice possible for a governance action. Each proposed action will be published at a minimum of 2 days in the future from the time of announcement. Major upgrades, such as changing the risk system, may have up to a 30 day delay. Timelock is controlled by the governance module; pending and completed governance actions can be monitored on the Timelock Dashboard (coming soon!).

![](/files/-MgYyDpoidoCCoYHqEVN)

## Key Events

### Delegate Changed

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

Emitted when an account changes delegate.

### DelegateVotesChanged

```erlang
DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance)
```

Emitted when a delegate account's vote balance changes.

### PropsalCreated

```erlang
ProposalCreated(uint id, address proposer, address[] targets, uint[] values, string[] signatures, bytes[] calldatas, uint startBlock, uint endBlock, string description)
```

Emitted when a new proposal is created.

### VoteCast

```erlang
VoteCast(address voter, uint proposalId, bool support, uint votes)
```

Emitted when a vote has been casted on a proposal.

### ProposalCancelled

```erlang
ProposalCanceled(uint id)
```

Emitted when a proposal has been cancelled.

### ProposalQueued

```erlang
ProposalQueued(uint id, uint eta)
```

Emitted when a proposal has been queued.

### ProposalExecuted

```erlang
ProposalExecuted(uint id)
```

Emitted when a proposal has been executed in the timelock.

## Read-Only Functions: PHRO

### Get Current Votes

```javascript
function getCurrentVotes(address account) returns (uint96)
```

Returns the balance of votes for an account as of the current block.

| Name    | Type    |                                                                  |
| ------- | ------- | ---------------------------------------------------------------- |
| account | address | Address of the account of which to retrieve the number of votes. |

#### Solidity

```javascript
PHRO phro = PHRO(0x123...); // contract address
uint votes = phro.getCurrentVotes(0xabc...);
```

#### Web3

```javascript
const account = '0x123...'; // user address
const votes = await phro.methods.getCurrentVotes(account).call();
```

### Get Prior Votes

```javascript
function getPriorVotes(address account, uint blockNumber) returns (uint96)
```

Returns the prior number of votes for an account at a specific block number. The block number passed must be a finalized block or the function will revert.

| Name        | Type    |                                                                        |
| ----------- | ------- | ---------------------------------------------------------------------- |
| account     | address | Address of the account of which to retrieve the prior number of votes. |
| blocknumber | uint    | The block number at which to retrieve the prior number of votes.       |
|             |         |                                                                        |
| RETURN      | uint96  | The number of prior votes                                              |

#### Solidity

```javascript
PHRO phro = PHRO(0x123...); // contract address
uint priorVotes = phro.getPriorVotes(0xabc..., blockNumber);
```

#### Web3

```javascript
const priorVotes = await phro.methods.getCurrentVotes(account, blockNumber).call();
```

## State-Changing Functions: gPHRO

### Delegate

```javascript
function delegate(address delegatee)
```

Delegate votes from the sender to the delegatee. Users can delegate to 1 address at a time, and the number of votes added to the delegatee’s vote count is equivalent to the balance of gPHRO in the user’s account. Votes are delegated from the current block and onward, until the sender delegates again, or transfers their gPHRO.

| Name      | Type    |                                                        |
| --------- | ------- | ------------------------------------------------------ |
| delegatee | address | The address to which msg.sender wishes to delegate to. |
| RETURN    | no      | Reverts on error.                                      |

#### Solidity

```javascript
PHRO phro = PHRO(0x123...); // contract address
phro.delegate(delegateeAddress);
```

#### Web3

```javascript
const tx = await phro.methods.delegate(delegateeAddress).send({ from: sender });
```

####

### Delegate By Signature

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

Delegate votes from the sender to the delegatee. Users can delegate to 1 address at a time, and the number of votes added to the delegatee’s vote count is equivalent to the balance of gPHRO in the user’s account. Votes are delegated from the current block and onward, until the sender delegates again, or transfers their gPHRO.

| Name      | Type    |                                                                                                                      |
| --------- | ------- | -------------------------------------------------------------------------------------------------------------------- |
| delegatee | address | The address to which `msg.sender` wishes to delegate to.                                                             |
| nonce     | uint    | The contract state required to match the signature. This can be retrieved from the contract's public nonces mapping. |
| expiry    | uint    | The time when the signature expires. A block timestamp in seconds since the UNIX epoch.                              |
| v         | uint    | The recovery byte of the signature.                                                                                  |
| r         | bytes32 | Half of the ECDSA signature pair.                                                                                    |
| s         | bytes32 | Half of the ECDSA signature pair.                                                                                    |
| RETURN    | no      | Reverts on error.                                                                                                    |

#### Solidity

```javascript
PHRO phro = PHRO(0x123...); // contract address
phro.delegateBySig(delegateeAddress, nonce, expiry, v, r, s);
```

#### Web3

```javascript
const tx = await phro.methods.delegateBySig(delegateeAddress, nonce, expiry, v, r, s).send({});
```

## Read-Only Functions: Governor Alpha

### Quorum Votes

```javascript
function quorumVotes() public pure returns (uint)
```

Returns the minimum number of votes required for a proposal to succeed.

#### Solidity

```javascript
GovernorAlpah gov = GovernorAlpha(0x123...); // contract address
uint quorum = gov.quorumVotes();
```

#### Web3

```javascript
const quorum = await gov.methods.quorumVotes().call();
```

### Proposal Threshold

```javascript
function proposalThreshold() returns (uint)
```

Returns the minimum number of votes for an account to create a proposal.

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpah(0x123...); // contract address
uint threshold = gov.proposalThreshold();
```

#### Web3

```javascript
const threshold = await gov.methods.proposalThreshold().call();
```

### Proposal Max Operations

```javascript
function proposalMaxOperations() returns (uint)
```

Returns the maximum number of actions that can be included in a proposal. Actions are function calls that will be made when a proposal succeeds and executes.

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
uint operations = gov.proposalMaxOperations();
```

#### Web3

```javascript
const operations = await gov.methods.proposalMaxOperations().call();
```

### Voting Delay

```javascript
function votingDelay() returns (uint)
```

Returns the number of blocks to wait before voting on a proposal may begin. This value is added to the current block number when a proposal is created.

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlphaconst blocks = await gov.methods.votingPeriod().call();
(0x123...); // contract address
uint blocks = gov.votingDelay();
```

#### Web3

```javascript
const blocks = await gov.methods.votingDelay().call();
```

### Voting Period

```javascript
function votingPeriod() returns (uint)
```

Returns the duration of voting on a proposal, in blocks.

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
uint blocks = gov.votingPeriod();
```

#### Web3

```javascript
const blocks = await gov.methods.votingPeriod().call();
```

### Get Actions

```javascript
function getActions(uint proposalId) returns (uint proposalId) public view returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas)
```

Gets the actions of a selected proposal. Pass a proposal ID and get the targets, values, signatures and calldatas of that proposal.

| Name       | Type |                     |
| ---------- | ---- | ------------------- |
| proposalid | uint | ID of the proposal. |

Returns:

* Array of addresses of contracts the proposal calls.
* Array of unsigned integers the proposal uses as values.
* Array of strings of the proposal's signatures.
* Array of calldata bytes of the proposal.

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
uint proposalId = 123;
(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas) = gov.getActions(proposalId);
```

#### Web3

```javascript
const {0: targets, 1: values, 2: signatures, 3: calldatas} = gov.methods.getActions(proposalId).call();
```

### Get Receipt

```javascript
function getReceipt(uint proposalId, address voter) returns (Receipt memory)
```

Returns a proposal ballot receipt of a given voter.

| Name       | Type    |                                                              |
| ---------- | ------- | ------------------------------------------------------------ |
| proposalid | uint    | ID of the proposal in which to get a voter's ballot receipt. |
| voter      | address | Address of the account of a proposal voter.                  |
| Receipt    | struct  | A Receipt struct for the ballot of the voter address.        |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
Receipt ballot = gov.getReceipt(proposalId, voterAddress);
```

#### Web3

```javascript
const proposalId = 11;
const voterAddress = '0x123...';
const result = await gov.methods.getReceipt(proposalId, voterAddress).call();
const { hasVoted, support, votes } = result;
```

### State

```javascript
function state(uint proposalId) returns (ProposalState)
```

Returns enum of the type ProposalState, possible types are; Pending, Active, Canceled, Defeated, Succeeded, Queued, Expired and Executed.

| Name       | Type |                     |
| ---------- | ---- | ------------------- |
| proposalid | uint | ID of the proposal. |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
GovernorAlpha.ProposalState state = gov.state(123);
```

#### Web3

```javascript
const proposalStates = ['Pending', 'Active', 'Canceled', 'Defeated', 'Succeeded', 'Queued', 'Expired', 'Executed'];
const proposalId = 123;
result = await gov.methods.state(proposalId).call();
const proposalState = proposalStates[result];const tx = gov.methods.castVote(proposalId, 0).send({ from: sender });

```

## State-Changing Functions: Governor Alpha

### Propose

```javascript
function propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description) returns (uint)
```

Creates a proposal to create a market, issue a grant or change the protocol.

Proposals will be voted on by delegated voters. If there is sufficient support before the voting period ends, the proposal shall be automatically enacted. Enacted proposals are queued and executed in the Timelock contract.

The sender must hold more gPHRO than the current proposal threshold (`proposalThreshold()`) as of the immediate previous block. If the threshold is 2,000,000 gPHRO, the sender must have been delegated more than 1% of all gPHRO in order to create a proposal. The proposal can have up to 10 actions (based on `proposalMaxOperations()`).

| Name        | Type    |                                                                                                                                                                                              |
| ----------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| targets     | address | The ordered list of target addresses for calls to be made during proposal execution. This array must be the same length of all other array parameters in this function.                      |
| values      | uint    | The ordered list of values (i.e. msg.value) to be passed to the calls made during the proposal execution. This array must be the same length of all other array parameters in this function. |
| signatures  | string  | The ordered list of function signatures to be passed during proposal execution. This array must be the same length of all other array parameters in this function.                           |
| calldatas   | bytes   | The ordered list of data to be passed to each individual function call during proposal execution. This array must be the same length of all other array parameters in this function.         |
| description | string  | A human readable description of the proposal and the changes it will enact.                                                                                                                  |
| RETURN      | uint    | Returns the ID of the new proposal.                                                                                                                                                          |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
uint proposalId = gov.propose(targets, values, signatures, calldatas, description);
```

#### Web3

```javascript
const tx = gov.methods.propose(targets, values, signatures, calldatas, description).send({ from: sender });
```

### Queue

```javascript
function queue(uint proposalId)
```

After a proposal has succeeded, any address can call the queue method to move the proposal into the Timelock queue. A proposal can only be queued&#x20;

| Name       | Type |                                    |
| ---------- | ---- | ---------------------------------- |
| proposalid | uint | ID of a given successful proposal. |
| RETURN     | no   | Reverts on error.                  |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
gov.queue(proposalId);
```

#### Web3

```javascript
const tx = gov.methods.queue(proposalId).send({ from: sender });
```

### Execute

```javascript
function execute(uint proposalId) payable
```

After the Timelock delay period, any account may invoke the execute method to apply the changes from the proposal to the target contracts. This will invoke each of the actions described in the proposal.&#x20;

The execute function can be called by any Ethereum address.

This function is payable so the Timelock contract can invoke payable functions that were selected in the proposal.

| Name       | Type |                 |
| ---------- | ---- | --------------- |
| proposalid | uint | ID of a given s |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
gov.execute(proposalId).value(999).gas(999)();
```

#### Web3

```javascript
const tx = gov.methods.execute(proposalId).send({ from: sender, value: 1 });
```

### Cancel

```javascript
function queue(uint proposalId)
```

A proposal is eligible to be cancelled at any time prior to its execution, including while queued in the Timelock, using this function.

The cancel function can be called by the proposal creator, or any Ethereum address, if the proposal creator fails to maintain more delegated votes than the proposal threshold (e.g. 2,000,000).<br>

| Name       | Type |                             |
| ---------- | ---- | --------------------------- |
| proposalid | uint | ID of a proposal to cancel. |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlppha(0x123...); // contract address
gov.cancel(proposalId);
```

#### Web3

```javascript
const tx = gov.methods.cancel(proposalId).send({ from: sender });
```

### Cast Vote

```javascript
function castVote(uint proposalId, bool support)
```

Cast a vote on a proposal. The account's voting weight is determined by its number of delegated votes at the time the proposal becomes active.

| Name       | Type |                                                                      |
| ---------- | ---- | -------------------------------------------------------------------- |
| proposalid | uint | ID of a given successful proposal.                                   |
| support    | bool | A boolean of true for 'yes' and false for 'no' on the proposal vote. |
| RETURN     | no   | Reverts on error.                                                    |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
gov.castVote(proposalId, 1);
```

#### Web3

```javascript
const tx = gov.methods.castVote(proposalId, 0).send({ from: sender });
```

### Cast Vote By Signature

```javascript
function castVoteBySig(uint proposalId, bool support, uint8 v, bytes32 r, bytes32 s)
```

Cast a vote on a proposal. The account's voting weight is determined its number of delegated votes at the time the proposal became active. This method has the same purpose as Cast Vote, but instead enables offline signatures to participate in governance voting. For more details on how to create an offline signature, review EIP-712.

| Name       | Type    |                                                                                         |
| ---------- | ------- | --------------------------------------------------------------------------------------- |
| proposalid | uint    | ID of a given successful proposal.                                                      |
| support    | bool    | A boolean of true for 'yes' and false for 'no' on the proposal vote.                    |
| expiry     | uint    | The time when the signature expires. A block timestamp in seconds since the UNIX epoch. |
| v          | uint    | The recovery byte of the signature.                                                     |
| r          | bytes32 | Half of the ECDSA signature pair.                                                       |
| s          | bytes32 | Half of the ECDSA signature pair.                                                       |

#### Solidity

```javascript
GovernorAlpha gov = GovernorAlpha(0x123...); // contract address
gov.castVoteBySig(proposalId, 0, v, r, s);
```

#### Web3

```javascript
const tx = await gov.methods.castVoteBySig(proposalId, 1, v, r, s).send({});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pharo.tech/governance/governance-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
