# xGov Beta Architecture

This document describes the architecture of the xGov process (Beta).

Specifically, the architecture aims to solve the following main requirement:

> The xGov process is _a trustless_ voting system to manage grant proposals funding and polls for the Algorand ecosystem.

The design takes a step towards this end goal, which is a _fully decentralized application_ relying uniquely on a front-end and the Algorand Virtual Machine (AVM).

The current design minimizes the trust model and the off-chain footprint to a few operations, carried out by a back-end controlled by the Algorand Foundation, which could be pushed on the AVM in future iterations.

It is worth noting that the residual trusted off-chain operations are _fully accountable_ on the Algorand public Ledger.

The old xGov process (Alpha) has shown some weaknesses concerning the incentive alignment, the gamification risks of the voting system, and low-quality proposals.

Moreover, the old grant proposal submission and funding mechanism were based on a per-quarter schedule, making the whole process slow and inflexible.

Therefore, a more robust process with a continuous stream of grant proposals, votes, and funding is desirable.

Finally, given the shift of the Algorand protocol towards consensus incentivization, the xGov (Beta) voting power will be based on active consensus participation instead of ALGO locking periods (Alpha).

The xGov Architecture consists of the following components:

| COMPONENT                                              | IMPLEMENTATION                       |
|--------------------------------------------------------|-------------------------------------|
| [xGov Portal](https://xgov.algorand.co/)               | Front-End                           |
| [xGov Registry](https://docs.xgov.algorand.co/print#xgov-registry) | Algorand Application (Factory)      |
| [xGov Treasury](https://docs.xgov.algorand.co/print#treasury)      | Algorand Application Account        |
| [xGov Manager](https://docs.xgov.algorand.co/print#xgov-manager)    | Algorand Address                    |
| [xGov Committee Manager](https://docs.xgov.algorand.co/print#xgov-committee-manager)| Algorand Address                    |
| [xGov Daemon](https://docs.xgov.algorand.co/print#xgov-daemon)  | Algorand Address, Back-End + DB    |
| [xGov Council](https://docs.xgov.algorand.co/print#xgov-council)  | Algorand Address                    |
| [xGov Payor](https://docs.xgov.algorand.co/print#xgov-payor)      | Algorand Address                    |
| [xGov Subscriber](https://docs.xgov.algorand.co/print#xgov-subscriber)| Algorand Address                    |
| [xGov](https://docs.xgov.algorand.co/print#xgovs)                | Algorand Address + Box              |
| [Managed Subscriber](https://docs.xgov.algorand.co/print#subscription)| Algorand Address                    |
| [xGov (Un)Subscription Request](https://docs.xgov.algorand.co/print#xgov-managed-subscription)| Box                                 |
| [xGov Committee](https://docs.xgov.algorand.co/print#xgov-committee)| JSON (ARC-86)                     |
| [Proposer](https://docs.xgov.algorand.co/print#proposers)         | Algorand Address + Box              |
| [KYC Provider](https://docs.xgov.algorand.co/print#kyc)        | Algorand Address                    |
| [Proposal](https://docs.xgov.algorand.co/print#proposal)        | Algorand Application (Child)       |
| [Proposal Metadata](https://docs.xgov.algorand.co/print#metadata)| Box                                 |
| [Proposal Escrow](https://docs.xgov.algorand.co/print#escrow)   | Algorand Application Account        |
| [Proposal Voters](https://docs.xgov.algorand.co/print#submission)| Boxes                               |

The _on-chain_ components are used for:

1. On/off-boarding xGovs;
2. Whitelisting Proposers (KYC required);
3. Creating and submitting Proposals;
4. Binding xGov Committees to Proposals;
5. Voting on Proposals;
6. Managing the xGov Treasury and funding approved Proposals.

The _off-chain_ components are used for:

1. Selecting xGov Committees periodically and verifiably, according to [ARC-86](https://dev.algorand.co/arc-standards/arc-0086);
2. Intermediate Proposers’ KYC;
3. Intermediate on/off-boarding of xGovs that cannot execute a self-subscription or self-unsubscription.

The keywords “ **MUST**”, “ **MUST NOT**”, “ **REQUIRED**”, “ **SHALL**”, “ **SHALL NOT**”, “ **SHOULD**”, “ **SHOULD NOT**”, “ **RECOMMENDED**”, “ **MAY**”, and “ **OPTIONAL**” in this document, are to be interpreted as described in [RFC 2119](https://datatracker.ietf.org/doc/html/rfc2119).

The data types (like `uint64`, `byte[]`, etc.) in this document are to be interpreted as specified in [ARC-4](https://dev.algorand.co/arc-standards/arc-0004).

> Note
>
> Notes like this are non-normative

> Tip
>
> Sections like this are examples aiming to clarify the specifications.

```text

Sections like this are either pseudo-code or data structures.
```

The xGov Registry is the orchestrator of the xGov process. It is used to:

- Manage the [role-based access control](https://docs.xgov.algorand.co/print#roles) of the process;
- Onboard and offboard [xGovs](https://docs.xgov.algorand.co/print#xgovs);
- Onboard and enable [Proposers](https://docs.xgov.algorand.co/print#proposers) (KYC required);
- Create [Proposals](https://docs.xgov.algorand.co/print#creation);
- Bind the [xGov Committees](https://docs.xgov.algorand.co/print#discussion) to Proposals;
- [Vote on Proposals](https://docs.xgov.algorand.co/print#votes);
- Manage the [xGov Treasury](https://docs.xgov.algorand.co/print#treasury) and funding approved Proposals.

The xGov Registry is implemented as an Application, deployed by the original [xGov\Manager](https://docs.xgov.algorand.co/print#xgov-manager).

The xGov Manager is an Algorand Address controlled by the Algorand Foundation. It represents the _root of trust_ for the xGov process.

The xGov Manager **MAY** rotate itself.

The xGov Manager **MUST** provide and **MAY** update the [xGov Committee Manager](https://docs.xgov.algorand.co/print#xgov-committee-manager) Address.

The xGov Manager **MUST** provide and **MAY** update the [xGov Daemon](https://docs.xgov.algorand.co/print#xgov-daemon) Address.

The xGov Manager **MUST** provide and **MAY** update the [xGov Council](https://docs.xgov.algorand.co/print#xgov-council) Address.

The xGov Manager **MUST** provide and **MAY** update the [xGov Payor](https://docs.xgov.algorand.co/print#xgov-payor).

The xGov Manager **MUST** provide and **MAY** update the [xGov Subscriber](https://docs.xgov.algorand.co/print#xgov-subscriber) Address.

The xGov Manager **MUST** provide and **MAY** update the [KYC Provider](https://docs.xgov.algorand.co/print#kyc) Address.

The xGov Manager **MAY** pause the [xGov Registry](https://docs.xgov.algorand.co/print#xgov-registry).

The xGov Manager **MAY** pause the creation of new [Proposals](https://docs.xgov.algorand.co/print#proposal).

The xGov Manager **MAY** update the xGov Registry anytime.

The xGov Manager **MAY** reconfigure the parameters of the xGov Registry.

The xGov Committee Manager is an Algorand Address controlled by the Algorand Foundation.

The xGov Committee Manager **SHALL** declare the xGov Committee currently in charge on the xGov Registry (see [xGov Committee section](https://docs.xgov.algorand.co/print#declaration)).

The xGov Daemon is an Algorand Address controlled by the Algorand Foundation (back-end).

The xGov Daemon **SHALL** assign the xGov Committee currently in charge (voters and their voting power) to open Proposals.

The xGov Daemon **SHOULD** delete absentees (voters) after Proposals scrutiny.

The xGov Council is an Algorand Address representing a group of elected Councilors.

The xGov Council **MUST** have an odd number of Councilors.

The xGov Council **MUST** review approved Proposals (see [Proposal review section](https://docs.xgov.algorand.co/print#review)).

The xGov Council **MAY** apply a veto against approved Proposals according to the _terms and conditions_ of the xGov process.

The xGov Council majority vote is **REQUIRED** to apply a veto against approved proposals.

The xGov Payor is an Algorand Address controlled by the Algorand Foundation.

The xGov Payor **MAY** disburse the requested funds for approved and reviewed Proposals if there are enough funds in the xGov Treasury.

The xGov Payor **MAY** execute withdrawals of outstanding funds from the [xGov\Treasury](https://docs.xgov.algorand.co/print#treasury).

The xGov Subscriber is an Algorand Address controlled by the Algorand Foundation.

The xGov Subscriber **MAY** onboard or offboard xGovs who cannot execute a self-subscription or self-unsubscription (e.g., due to contract immutability or other restrictions).

The xGov Treasury is an Algorand Address controlled by the xGov Registry.

The xGov Architecture provides the following classes of [ARC-28](https://dev.algorand.co/arc-standards/arc-0028) events:

- **xGov Registry Events**, emitted by the [xGov Registry singleton application](https://docs.xgov.algorand.co/print#xgov-registry).

- **Proposal Events**, emitted by the [Proposal applications](https://docs.xgov.algorand.co/print#proposal).

Clients can subscribe to these ARC-28 events using the [AlgoKit Subscriber Library](https://dev.algorand.co/algokit/subscribers/typescript/overview/#arc-28-event-subscription-and-reads).

The xGov Architecture source code is released on the official [GitHub repository](https://github.com/algorandfoundation/xgov-beta-sc/).

Issues can be submitted on the [GitHub issues page](https://github.com/algorandfoundation/xgov-beta-sc/issues).

External contributions are welcome. If you would like to contribute, please read these guidelines and consider submitting a [Pull Request](https://github.com/algorandfoundation/xgov-beta-sc/pulls).

> ⚠️ Commits must be signed!

The xGov Architecture is implemented in Algorand Python.

Any external contributions **MUST**:

1. Be submitted as a [Pull Request](https://github.com/algorandfoundation/xgov-beta-sc/pulls).  
2. Pass the [CI/CD pipeline](https://docs.xgov.algorand.co/print#cicd);  
3. Update the relevant documentation;  
4. Be approved by the xGov Architecture maintainers.
