Skip to content

Commit

Permalink
feat: dockerise the project
Browse files Browse the repository at this point in the history
  • Loading branch information
IronJam11 committed Feb 23, 2025
1 parent dafdbcd commit a216d84
Show file tree
Hide file tree
Showing 342 changed files with 305,398 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
Binary file added .gitlab/.DS_Store
Binary file not shown.
27 changes: 27 additions & 0 deletions .gitlab/issue_templates/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: bug
assignees: ""
---

**Describe the bug**
A clear and concise description of what the bug is.

Area Where Bug Occurred

- [ ] UI/UX
- [ ] Business Logic

**How to reproduce the error/bug**
(add a step here if exist)

**Additional context**
Add any other context about the problem here.

**Before submitting an issue check the below**

- [ ] I have synced all my node versions as mentioned in the project"
- [ ] I am using the same version of npm as is the project
- [ ] My current branch is in sync with the development branch
16 changes: 16 additions & 0 deletions .gitlab/issue_templates/new_feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: New Feature
about: Create a issue for adding new feature
title: "[New Feature]"
labels: new-feature
assignees: ""
---

**Describe the purpose**
(A clear and concise description of purpose of the feature you want to add.)

**Possible Implementation**
(Add the approach for implementing this.)

**Additional context**
(Add any other context about the problem here.)
21 changes: 21 additions & 0 deletions .gitlab/merge_request_templates/merge_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Description

Include a summary of the change and which issue is fixed. List any dependencies that are required for this change.

Fixes # (issue)

## Type of change

Please mark the options that are relevant.

- [ ] Updated UI/UX
- [ ] Improved the business logic of code
- [ ] Added new feature
- [ ] Other

## Checklist:

- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.24+commit.e11b9ed9"
}
180 changes: 179 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,180 @@
# agora-blockchain
# Agora Blockchain

## Introduction

Agora is a library of voting algorithms like `Moore's`, `Oklahoma` , `Borda` , `IRV` etc. Some of these voting algorithms are already implemented by AOSSIE in a centralized manner using Scala as their backend. Our vision is to take these algorithms on a decentralized platform, so that, crucial votes of the voters could not be tampered with by admins, hackers, or anyone with access to the database. Blockchain technology would make the ballots immutable and hence more secure.

## Tech Stack

- ### Backend

- [Solidity](https://docs.soliditylang.org/en/v0.8.24/): A programming language used for developing smart contracts on the Ethereum ecosystem.
- [Hardhat](https://hardhat.org/): A development environment for testing, deploying, and managing smart contracts.
- [ChainLink](https://docs.chain.link/ccip): Facilitates cross-chain interoperability within the ecosystem.
- [EIPs](https://eips.ethereum.org/): Utilized for implementing the latest Ethereum Improvement Proposals.
- [OpenZeppelin](https://www.openzeppelin.com/): Provides a collection of well-audited, secure smart contracts that are easy to integrate and use.

- ### Client

- [Next.js](https://nextjs.org/): A React framework used for developing the frontend of the application.
- [Node.js](https://nodejs.org/en/) (v10.16 or later): A JavaScript runtime required for server-side development.
- [MetaMask](https://metamask.io): A browser extension for managing Ethereum accounts and interacting with the blockchain.
- [Vercel](https://vercel.com/) - The platform used for deploying the Next.js frontend, offering seamless deployment and hosting with serverless functions.
- [Wagmi](https://wagmi.sh/): A set of React hooks for working with Ethereum contracts.
- [TailwindCSS](https://tailwindcss.com/): A utility-first CSS framework for efficient styling.
- [zustand](https://zustand.docs.pmnd.rs/getting-started/introduction): A state management library for React, used for managing global state in the Next.js application.

Here's a refined version of the development guide:

## Development Guide

### Running Locally

**Clone the Repository**:

```bash
git clone https://github.com/AOSSIE-Org/Agora-Blockchain
```
### Option 1: Docker Setup

1. **Clone the Repository**:
```bash
git clone https://github.com/AOSSIE-Org/Agora-Blockchain
cd Agora-Blockchain
```

2. **Set up Environment Variables**:

Create `.env.local` in the `blockchain` directory:
```
PRIVATE_KEY=<your_private_key>
RPC_URL_SEPOLIA=<your_sepolia_rpc_url>
RPC_URL_FUJI=<your_fuji_rpc_url>
ETHERSCAN_KEY=<your_etherscan_api_key>
```

Create `.env.local` in the `client` directory:
```
NEXT_PUBLIC_PINATA_JWT=<your_pinata_jwt>
```

3. **Run with Docker Compose**:
```bash
docker-compose up --build
```

4. **Access the Application**:
- Frontend: http://localhost:3000
- Blockchain Node: http://localhost:8545

The application will automatically reload when you make changes to the source code.

### Option 2: Manual Setup
## Backend
1. **Navigate to the Blockchain Directory**:

```bash
cd blockchain
```

2. **Install Dependencies**:

```bash
npm install
```

3. **Test the Contracts**:

```bash
npx hardhat test
```

4. **Create an `.env.local` file** with the following environment variables:

```bash
PRIVATE_KEY=<your_private_key>
RPC_URL_SEPOLIA=<your_sepolia_rpc_url>
RPC_URL_FUJI=<your_fuji_rpc_url>
ETHERSCAN_KEY=<your_etherscan_api_key>
```

5. **Compile & Deploy Contracts**:
```bash
npx hardhat ignition deploy ./ignition/modules/<ContractModule> --network <Network> --verify
```

## Frontend

1. **Navigate to the Client Directory**:

```bash
cd client
```

2. **Install Dependencies**:

```bash
npm install
```

3. **Run the Application**:

```bash
npm run dev
```

4. **Create an `.env.local` file** with the following environment variables:

```bash
NEXT_PUBLIC_PINATA_JWT=<your_pinata_jwt>
```

5. **Visit the Live App at**:
**[localhost](http://localhost:3000/)**

## About smart contracts

The architecture of your Election Factory contract is designed to facilitate the creation and management of elections on the blockchain, incorporating cross-chain voting capabilities through Chainlink's Cross-Chain Interoperability Protocol (CCIP). Below is a detailed explanation:

### Overview

The `ElectionFactory` contract serves as the core component of the election creation and management system. It is responsible for generating new election instances, handling cross-chain voting, and maintaining a record of active elections. The contract leverages several other contracts and libraries to achieve its functionality, including the `Election`, `BallotGenerator`, and `ResultCalculator` contracts, as well as Chainlink's CCIP components.

- ### Key Features:

- Election Creation: Utilizes a clonable election template (electionGenerator) to efficiently create new election contracts.
- Ballot and Result Handling: Generates ballots using the BallotGenerator contract and calculates election results with a dedicated ResultCalculator contract.
- Cross-Chain Voting: Implements Chainlink's Cross-Chain Interoperability Protocol (CCIP) to allow voting from multiple blockchain networks.

- ### Efficiency and Security:

- Clonable Contracts: Reduces deployment costs and resource usage by cloning a pre-deployed election template.
- Owner Management: Ensures only the election creator can delete or modify their election, providing security and control.
- Whitelisted Cross-Chain Communication: Only allows approved contracts to send votes across chains, preventing unauthorized access.

## Deployed Instances

- **Election Factory**: [Sepolia Testnet](https://sepolia.etherscan.io/address/0x64c720eBD5227bba57a5E8282893e71087cCcBb8#code)
- **CCIP Contract**: [FUJI Testnet](https://testnet.snowtrace.io//address/0xf267f0603672E791779E52B153BD9A39C9928767#code)
- **Frontend**: [Live URL](https://agora-blockchain.vercel.app/)

## How to Contribute

1. **Create an Issue**: For any feature requests, bugs, security concerns, or other issues, please create an issue in the repository and wait to be assigned before proceeding.
2. **Branch Management**: Always create a new branch on your forked repository to commit your changes.
3. **Pull Request Descriptions**: When submitting a pull request (PR), provide a detailed explanation in the description, outlining all changes and the reasons behind them.
4. **Community Engagement**: Post your issues and PR updates on the Agora-Blockchain [Discord channel](https://discord.gg/HrJ6eKJ28a) for visibility and discussion.

## Additional Points to Remember

1. **Testing and Code Quality**: Ensure all changes are thoroughly tested, and avoid introducing code smells.
2. **Small Changes**: If a frontend change involves fewer than 20 lines of code or if you are making documentation updates, you may directly create a PR without prior assignment.
3. **Assignment Requirement**: Do not submit unassigned PRs; they will be closed without review.
4. **Avoiding Overlap**: Before starting work, check existing issues and PRs to avoid duplicating efforts or conflicting changes.
5. **Open Review Period**: A new issue or PR will remain open for one week to allow other contributors to review and suggest improvements.
6. **Mentor Notification**: If your PR is left unattended for more than 1-2 weeks, depending on the contribution size, feel free to tag the mentors of Agora-Blockchain to get their attention.
7. **Completion Timeline**: An issue is expected to be completed within 5-30 days, depending on its complexity. If not completed within this timeframe, it may be reassigned to another contributor.
8. **Progress Updates**: If your work on an issue is taking longer than expected, ensure you provide regular updates in the issue’s or PR's comments to keep everyone informed.
9. **Working on Blockchain Components**:
- **Error Interface Changes**: If modifying an interface for errors, ensure the corresponding error is added to `client/app/helper/ErrorMessage.ts`.
- **Contract ABI Updates**: For changes to `ElectionFactory`, `Election`, or `CCIPSender` contracts, manually update the ABI files in `client/abi/artifacts/` (do not configure Hardhat to generate these paths automatically in the client directory).
Binary file added anonymousVoting/.DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions anonymousVoting/clientAnonymousVoting/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions anonymousVoting/clientAnonymousVoting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
1 change: 1 addition & 0 deletions anonymousVoting/clientAnonymousVoting/abi/B.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[],"name":"stateB","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
1 change: 1 addition & 0 deletions anonymousVoting/clientAnonymousVoting/abi/Hasher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"uint256[5]","name":"array","type":"uint256[5]"}],"name":"hash5","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"array","type":"uint256[]"}],"name":"hash11","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"_left","type":"uint256"},{"internalType":"uint256","name":"_right","type":"uint256"}],"name":"hashLeftRight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"uint8","name":"_treeLevels","type":"uint8"},{"internalType":"uint256","name":"_zeroValue","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"leaf","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"leafIndex","type":"uint256"}],"name":"LeafInsertion","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"root","type":"uint256"}],"name":"NewRoot","type":"event"},{"inputs":[],"name":"root","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rootHistory","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRoots","outputs":[{"internalType":"uint256[10]","name":"","type":"uint256[10]"}],"stateMutability":"view","type":"function"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"uint8","name":"_treeLevels","type":"uint8"},{"internalType":"uint256","name":"_zeroValue","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"leaf","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"leafIndex","type":"uint256"}],"name":"LeafInsertion","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"uint256[]","name":"array","type":"uint256[]"}],"name":"hash11","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256[5]","name":"array","type":"uint256[5]"}],"name":"hash5","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"_left","type":"uint256"},{"internalType":"uint256","name":"_right","type":"uint256"}],"name":"hashLeftRight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"root","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rootHistory","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_leaf","type":"uint256"}],"name":"insertLeaf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
1 change: 1 addition & 0 deletions anonymousVoting/clientAnonymousVoting/abi/MiMC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"uint256","name":"in_xL","type":"uint256"},{"internalType":"uint256","name":"in_xR","type":"uint256"}],"name":"MiMCSponge","outputs":[{"internalType":"uint256","name":"xL","type":"uint256"},{"internalType":"uint256","name":"xR","type":"uint256"}],"stateMutability":"pure","type":"function","constant":true}]
Loading

0 comments on commit a216d84

Please sign in to comment.