> For the complete documentation index, see [llms.txt](https://agora-staged.vercel.app/app/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://agora-staged.vercel.app/app/docs/project-structure/core.md).

# Core

The core component of Agora is the smart contract infrastructure, built using Hardhat and TypeScript. It provides the decentralized backend for private proposals and secure voting.

## Overview

AGORA enables secure, private voting on proposals within decentralized spaces. Votes are encrypted on the client-side and remain private on-chain until the proposal ends, at which point they are decrypted and tallied. The system supports multiple voting types (non-weighted, weighted single-choice, weighted fractional) and integrates with Agora Names Services (MockENS) for space management.

## Features

* **Privacy-First Voting**: FHE ensures votes are encrypted and computed without revealing individual choices.
* **Flexible Voting Types**: Support for equal-weight, weighted single-choice, and weighted fractional voting.
* **Prediction Markets**: Optional encrypted prediction markets where users stake tokens on voting outcomes with winner-takes-all distribution.
* **Decentralized Spaces**: Create and manage proposal spaces with various membership types (Public, Whitelist, TokenHolder, NFTHolder).
* **Automated Resolution**: Chainlink Automation handles timely proposal resolution and decryption.
* **ENS Integration**: Spaces are tied to ENS names for decentralized naming.
* **Threshold and Abstain Support**: Configurable passing thresholds and abstain options.

## Architecture

### Core Components

* **SpaceRegistry**: Manages decentralized spaces and membership.
* **PrivateProposal**: Handles encrypted voting and proposal logic.
* **PrivateProposalFactory**: Deploys proposals and integrates with Chainlink Automation.

For detailed contract architecture, FHE usage, and resolution process, see [Contract Architecture](/app/docs/project-structure/core/contract.md).

## Quick Start

### Prerequisites

* **Node.js**: Version 20 or higher
* **npm or yarn/pnpm**: Package manager

### Installation

1. **Clone the repository**

   ```bash
   git clone https://github.com/ElioMargiotta/agora_monorepo.git
   cd agora_monorepo
   ```
2. **Install dependencies**

   ```bash
   npm install
   ```
3. **Set up environment variables**

   ```bash
   npx hardhat vars set MNEMONIC
   npx hardhat vars set INFURA_API_KEY
   npx hardhat vars set ETHERSCAN_API_KEY  # Optional for verification
   ```
4. **Compile contracts**

   ```bash
   npm run compile
   ```
5. **Run tests**

   ```bash
   npm run test
   ```

### Deployment

* **Local Network**:

  ```bash
  npx hardhat node
  npx hardhat deploy --network localhost
  ```
* **Sepolia Testnet**:

  ```bash
  npx hardhat deploy --network sepolia ##verify automatically
  npx hardhat verify --network sepolia <CONTRACT_ADDRESS>
  npx hardhat proposal --network sepolia ## Create .agora ENS name, Space ID with this name and proposal in the space
  ```

  **Deployed Contracts on Sepolia**

  These are the addresses of the contracts deployed on the Sepolia testnet using the `deploy/deploy.ts` script. The script deploys and verifies each contract on Etherscan.

  * **MockENS**: 0xB94ccA29A9eCCb65AC9548DAb2d1ab768F3b494D
  * **SpaceRegistry**: 0xB1480EF7694d9e57b871fdD1a779eb5f278C8308
  * **ProposalAutomation**: 0xA3ea6b9255b606Eda856eb699DD62efc72D39167
  * **PrivateProposalFactory**: 0x6f27646A29501Ee4aF0e4b6ABC2B28c71F723A1A
  * **MockGovernanceToken**: 0x24b8aE269ad0284762AfcAC32b5c1EF42875fa7D
  * **MockUSDC**: 0xb2A0eeC6637326E2195096c9F8D03F8fA133c740

## Available Scripts

| Script                | Description           |
| --------------------- | --------------------- |
| `npx hardhat compile` | Compile all contracts |
| `npx hardhat test`    | Run all tests         |
| `npx hardhat lint`    | Run linting checks    |
| `npx hardhat clean`   | Clean build artifacts |

## Testing

The core contracts include a comprehensive test suite with 93 passing tests covering all major functionality. Tests are written using Hardhat and include:

* **ENS Management**: MockENS subdomain creation and ownership
* **Space Management**: Space creation, membership, and administration
* **Proposal Factory**: Proposal creation, validation, and Chainlink Automation
* **Voting & Resolution**: All voting types (non-weighted, weighted single-choice, weighted fractional) with FHE encryption
* **Prediction Markets**: Encrypted prediction staking, cancellation with fees, winner payouts, and proportional distribution

For detailed test results and coverage, see [Test Summary](/app/docs/project-structure/core/test-summary.md).

## Tasks

The project includes custom Hardhat tasks for streamlined deployment and interaction:

* **Proposal Deployment**: Automated task to create ENS domains, spaces, and proposals on testnet
* **Contract Verification**: Automatic Etherscan verification for deployed contracts

For detailed information about deployment tasks, see [Proposal Deployment Task](/app/docs/project-structure/core/task_deploy_proposal.md).

## Documentation

* [Chainlink Documentation](https://docs.chain.link/) - Smart contract automation and oracles
* [Zama FHE Documentation](https://docs.zama.ai/) - Fully Homomorphic Encryption for blockchain
* [OpenZeppelin Documentation](https://docs.openzeppelin.com/) - Secure smart contract development


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://agora-staged.vercel.app/app/docs/project-structure/core.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
