Skip to content

Commit

Permalink
Merge pull request #173 from privacy-scaling-explorations/fix/default…
Browse files Browse the repository at this point in the history
…-config

fix(env-docs): removed auth variables and improved docs
  • Loading branch information
ctrlc03 authored Jun 25, 2024
2 parents defe62d + 127e0a6 commit c280402
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 53 deletions.
9 changes: 3 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ NEXT_PUBLIC_ROUND_ORGANIZER="PSE"
# Name of the token you want to allocate (only updates UI)
NEXT_PUBLIC_TOKEN_NAME="Votes"

# How many votes each ballot can hold
NEXT_PUBLIC_MAX_VOTES_TOTAL=150
# How many votes each project can receive
NEXT_PUBLIC_MAX_VOTES_PROJECT=50


# Voting periods
# Determine when users can register applications, admins review them, voters vote, and results are published
NEXT_PUBLIC_START_DATE=2024-01-01T00:00:00.000Z
Expand Down Expand Up @@ -98,5 +92,8 @@ NEXT_PUBLIC_MACI_START_BLOCK=

NEXT_PUBLIC_MACI_SUBGRAPH_URL=

# Vercel Store token to store the application images
BLOB_READ_WRITE_TOKEN=""

# URL with tally-{pollId}.json hosted
NEXT_PUBLIC_TALLY_URL=https://upblxu2duoxmkobt.public.blob.vercel-storage.com
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ typechain-types
commitlint.config.js
subgraph/generated
public/mockServiceWorker.js

zkeys
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ deployed-contracts.json

# typescript
*.tsbuildinfo
zkeys
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pnpm-lock.yaml
CHANGELOG.md
CODEOWNERS
.eslintignore

zkeys
public/mockServiceWorker.js
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<a href="https://maci-rpgf.vercel.app/">View demo</a>
<span>|</span>
<a href="https://discord.com/invite/sF5CT5rzrR">Discord (#🗳️-maci channel)</a>
<span>|</span>
<a href="https://www.youtube.com/watch?v=86VBbO1E4Vk">Video Tutorial</a>
</div>

[<img src="./docs/images/screenshot.png"/>](https://easy-retro-pgf.vercel.app)
Expand All @@ -12,6 +14,12 @@

MACI-RPGF uses EAS as backbone to run Retroactive Public Goods Funding to reward contributors ([As used by the Optimism Collective](https://community.optimism.io/docs/governance/citizens-house/#how-retro-funding-works)) while adding a privacy layer to reduce bribery and collusion using MACI.

## Video Tutorial

A complete installation tutorial can be seen here:

[![Watch the Video](https://img.youtube.com/vi/86VBbO1E4Vk/0.jpg)](https://www.youtube.com/watch?v=86VBbO1E4Vk)

### MACI-RPGF docs

- [Setup & Deployment](./docs/01_setup.md)
Expand Down Expand Up @@ -61,7 +69,7 @@ cp .env.example .env # and update .env variables

```

At the very minimum you need to configure a postgres database, nextauth, admin address, maci address and the voting periods. For more details head to [Setup & Deployment](./docs/01_setup.md). Once you have set everything run:
At the very minimum you need to configure the subgraph url, admin address, maci address and the voting periods. For more details head to [Setup & Deployment](./docs/01_setup.md). Once you have set everything run:

```sh
pnpm install
Expand Down
103 changes: 67 additions & 36 deletions docs/01_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,20 @@

Follow these instructions to deploy your own instance of MACI-RPGF.

## Video Tutorial

A complete installation tutorial can be seen here:

[![Watch the Video](https://img.youtube.com/vi/86VBbO1E4Vk/0.jpg)](https://www.youtube.com/watch?v=86VBbO1E4Vk)

## 1. Fork Repo

[Fork MACI-RPGF](https://github.com/privacy-scaling-explorations/maci-rpgf/tree/main)

1. Click to view the `.env.example` file in your newly created repo
2. Copy its contents and paste into a text editor

## 2. Configuration

The `.env.example` file contains instructions for most of these steps.

At the very minimum you need to configure a postgres database, nextauth, admin address, MACI address, the EAS Schema and the voting periods under App Configuration.

#### Network

The default configuration is Optimism Sepolia for development and Optimism for production.

You can find supported networks on the EAS documentation website: https://docs.attest.sh/docs/quick--start/contracts

#### App

Configure how many votes each voter receives and how many votes each project can receive.
You can also find configurations for when voting starts and ends as well as the registration and review period.

Here, you can also configure who your admins are. These are the users who will approve applications and voters.

To create your own round you need to do a few things:

- Update `NEXT_PUBLIC_ADMIN_ADDRESS` a wallet address that approve the applications and voters (badgeholders)
- Set `NEXT_PUBLIC_ROUND_ID` to a unique identifier that will group the applications you want to list
- Set `NEXT_PUBLIC_MACI_ADDRESS` - your deployed maci contract
- Set `NEXT_PUBLIC_MACI_START_BLOCK` - block where your maci contract is deployed (optional)
- Set `NEXT_PUBLIC_MACI_SUBGRAPH_URL` - maci subgraph url (optional). This is recommended to have and you can setup it using [maci-subgraph](https://github.com/privacy-scaling-explorations/maci/tree/dev/subgraph).
- Set `NEXT_PUBLIC_TALLY_URL` - your endpoint for vote results, where you host `tally-{pollId}.json` files.

#### EAS

If you are running on a different network than Optimism you need to update the contract addresses for EAS. These addresses are used whenever an attestation is created.

You can also configure your own schemas here if you wish to, or deploy the EAS contracts to a network that doesn't have them.

## 3. Deploy MACI
## 2. Deploy MACI

As a coordinator you need to deploy a MACI instance and poll.

Expand Down Expand Up @@ -133,6 +105,65 @@ pnpm deploy-poll:NETWORK

See [MACI docs](https://maci.pse.dev/docs/v1.2/integrating#deployment) for more information.

## 3. Configuration

The `.env.example` file contains instructions for most of these steps.

At the very minimum you need to configure a subgraph, admin address, MACI address, the EAS Schema and the voting periods under App Configuration.

### Subgraph

In the MACI repo and head to the subgraph folder.

> [!IMPORTANT]
> If you are using the v1.2.4 branch, you will need to checkout to dev and build in order to deploy a subgraph, once deployed remember to switch back to v1.2.4 in order to finalize the round. The following steps focus on The Graph, but you can deploy a subgraph using Alchemy.
1. Make sure you have `{network}.json` file in `config` folder, where network is a CLI name supported for subgraph network [https://thegraph.com/docs/en/developing/supported-networks/](https://thegraph.com/docs/en/developing/supported-networks/).

2. Create subgraph in [the graph studio](https://thegraph.com/studio/).

3. Add network, maci contract address and maci contract deployed block.

```json
{
"network": "optimism-sepolia",
"maciContractAddress": "0xD18Ca45b6cC1f409380731C40551BD66932046c3",
"maciContractStartBlock": 11052407
}
```

4. Run `pnpm run build`. You can use env variables `NETWORK` and `VERSION` to switch config files.
- Create an `.env` file, and run the follow command in the console `export $(xargs < .env)`
5. Run `graph auth --studio {key}`. You can find the key in subgraph studio dashboard.
6. Run `pnpm run deploy` to deploy subgraph

#### Network

The default configuration is Optimism Sepolia for development and Optimism for production.

You can find supported networks on the EAS documentation website: https://docs.attest.sh/docs/quick--start/contracts

#### App

Configure the round timelines such as starts and end dates, as well as the registration and review period.

Here, you can also configure the admin address who will approve applications and voters.

To create your own round you need to do the following:

- Update `NEXT_PUBLIC_ADMIN_ADDRESS` a wallet address that approves the applications and voters (badgeholders)
- Set `NEXT_PUBLIC_ROUND_ID` to a unique identifier that will group the applications you want to list
- Set `NEXT_PUBLIC_MACI_ADDRESS` - your deployed maci contract
- Set `NEXT_PUBLIC_MACI_START_BLOCK` - block where your maci contract is deployed - optional but very much recommended (as it's a fallback to subgraph not setup/working)
- Set `NEXT_PUBLIC_MACI_SUBGRAPH_URL` - maci subgraph url (optional). This is recommended to have and you can setup it using [maci-subgraph](https://github.com/privacy-scaling-explorations/maci/tree/dev/subgraph).
- Set `NEXT_PUBLIC_TALLY_URL` - your endpoint for vote results, where you host `tally-{pollId}.json` files.

#### EAS

If you are running on a different network than Optimism you need to update the contract addresses for EAS. These addresses are used whenever an attestation is created.

You can also configure your own schemas here if you wish to, or deploy the EAS contracts to a network that doesn't have them.

## 4. Deploy Frontend

https://vercel.com/new
Expand All @@ -157,7 +188,7 @@ pnpm merge:[network] --poll [poll-id]
```

> [!IMPORTANT]
> For version 1.2.3 you need to deploy a new MACI contract for a new round.
> For version 1.2 you need to deploy a new MACI contract for a new round.
Then the coordinator generates proofs for the message processing, and tally calculations. This allows to publish the poll results on-chain and then everyone can verify the results when the poll is over:

Expand Down
2 changes: 1 addition & 1 deletion docs/06_maci_troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ There's no description in detail for signing up reverted by the contract. The fo

If you found it displays "Voting is over", but you actually just started a poll:

- Make sure that you are deploying through **MACI v1.2.2**.
- Make sure that you are deploying using **MACI v1.2.4**.

## Fail to process message and tally result

Expand Down
2 changes: 1 addition & 1 deletion public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = "2.3.0";
const PACKAGE_VERSION = "2.3.1";
const INTEGRITY_CHECKSUM = "26357c79639bfa20d64c0efca2a87423";
const IS_MOCKED_RESPONSE = Symbol("isMockedResponse");
const activeClientIds = new Set();
Expand Down
4 changes: 0 additions & 4 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export const env = createEnv({
]),
NEXT_PUBLIC_SIGN_STATEMENT: z.string().optional(),

NEXT_PUBLIC_MAX_VOTES_TOTAL: z.string().default("150"),
NEXT_PUBLIC_MAX_VOTES_PROJECT: z.string().default("50"),
NEXT_PUBLIC_FEEDBACK_URL: z.string().default("#"),

// EAS Schemas
Expand Down Expand Up @@ -83,8 +81,6 @@ export const env = createEnv({
NEXT_PUBLIC_CHAIN_NAME: process.env.NEXT_PUBLIC_CHAIN_NAME,
NEXT_PUBLIC_SIGN_STATEMENT: process.env.NEXT_PUBLIC_SIGN_STATEMENT,

NEXT_PUBLIC_MAX_VOTES_TOTAL: process.env.NEXT_PUBLIC_MAX_VOTES_TOTAL,
NEXT_PUBLIC_MAX_VOTES_PROJECT: process.env.NEXT_PUBLIC_MAX_VOTES_PROJECT,
NEXT_PUBLIC_FEEDBACK_URL: process.env.NEXT_PUBLIC_FEEDBACK_URL,

NEXT_PUBLIC_APPROVED_APPLICATIONS_SCHEMA: process.env.NEXT_PUBLIC_APPROVED_APPLICATIONS_SCHEMA,
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/routers/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function calculateMaciResults(pollId?: string | null): Promise<{
}

const results = tallyData.results.tally.reduce((acc, tally, index) => {
if (projects[index]) {
if (projects[index]?.id) {
acc.set(projects[index]!.id, { votes: Number(tally), voters: 0 });
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
".next/types/**/*.ts",
"src/pages/api/indexer/webhook._ts"
],
"exclude": ["node_modules", "./public/mockServiceWorker.js", "./commitlint.config.cjs"]
"exclude": ["node_modules", "./public/mockServiceWorker.js", "./commitlint.config.cjs", "zkeys"]
}

0 comments on commit c280402

Please sign in to comment.