Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nik-suri committed Mar 13, 2024
0 parents commit c9396d1
Show file tree
Hide file tree
Showing 261 changed files with 54,018 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Frontend Tests
on:
pull_request:
push:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
container:
image: jetprotocol/builder:rust-1.68.0-node-18.15.0-solana-1.14.17-anchor-0.27.0-1
env:
PGUSER: ${{ env.PGUSER }}
PGPASSWORD: ${{ env.PGPASSWORD }}
PGDATABASE: ${{ env.PGDATABASE }}
PROGRAM_ID: ${{ env.PROGRAM_ID }}
PGHOST: postgres
ENDPOINT: http://localhost:8899

env:
PGUSER: myuser
PGPASSWORD: mypass
PGDATABASE: mydb
PROGRAM_ID: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: ${{ env.PGUSER }}
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }}
POSTGRES_DB: ${{ env.PGDATABASE }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
defaults:
run:
working-directory: ./frontend

steps:
- uses: actions/checkout@v3
- name: setup os dependencies
run: apt-get update && apt-get install -y jq
- uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Install deps
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm run test:ci
19 changes: 19 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Pre-commit checks

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-07-23
components: rustfmt, clippy
- uses: pre-commit/[email protected]
38 changes: 38 additions & 0 deletions .github/workflows/push-token-dispenser-datadog-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and Push Token Dispenser Datadog image
on:
push:
branches:
- main
workflow_dispatch:
inputs:
dispatch_description:
description: "Dispatch description"
required: true
type: string
permissions:
contents: read
id-token: write
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: haya14busa/action-cond@v1
id: image_tag
with:
cond: ${{ startsWith(github.ref, 'refs/tags/') }}
if_true: ${{ github.ref_name }}
if_false: ${{ github.sha }}
- uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::192824654885:role/github-actions-ecr
aws-region: eu-west-2
- uses: aws-actions/amazon-ecr-login@v1
id: ecr_login
- run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f ./frontend/Dockerfile.datadog ./frontend
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
env:
ECR_REGISTRY: ${{ steps.ecr_login.outputs.registry }}
ECR_REPOSITORY: token-dispenser-datadog
IMAGE_TAG: ${{ steps.image_tag.outputs.value }}
26 changes: 26 additions & 0 deletions .github/workflows/token-dispenser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check Token Dispenser
on:
pull_request:
paths: [token-dispenser/**]
push:
branches: [main]
paths: [token-dispenser/**]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.66.1
components: rustfmt, clippy
override: true
- name: Install Solana
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.14.18/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
- name: Build
run: |
cargo test-bpf
working-directory: token-dispenser
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# IntelliJ
.idea
*.iml
.DS_Store
.DS_Store
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
exclude: |
(?x)^(
frontend/public/orb.png |
frontend/package-lock.json
)$
- repo: local
hooks:
# Hooks for the token dispenser
- id: cargo-fmt-token-dispenser
name: Cargo format for token dispenser
language: "rust"
entry: cargo +nightly-2023-07-23 fmt --manifest-path ./token-dispenser/Cargo.toml --all -- --config-path ./token-dispenser/rustfmt.toml
pass_filenames: false
files: token-dispenser
- id: cargo-clippy-token-dispenser
name: Cargo clippy for token dispenser
language: "rust"
entry: cargo +nightly-2023-07-23 clippy --manifest-path ./token-dispenser/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
pass_filenames: false
files: token-dispenser
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
hooks:
- id: prettier
additional_dependencies:
- "[email protected]"
- "prettier-plugin-tailwindcss@^0.1.13"
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
frontend/claim_sdk/idl/token_dispenser.ts
frontend/claim_sdk/idl/token_dispenser.json
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2023 Pyth Contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# grant-program

Launch a community grant program that allows users to claim tokens by verifying their identity across multiple ecosystems.

## Local Development

The grant program has two components:

- The `token_dispenser` solana program that verifies identities, checks claim amounts and transfers tokens.
The on-chain program uses a merkle tree to verify claim membership.
- A web frontend for verifying identities, retrieving claim proofs, and submitting claim transactions.
The frontend connects to a postgres database to retrieve merkle proofs for claims that can be verified on-chain.

### Configuration

Copy `frontend/.env.sample` to `frontend/.env` and edit the configuration variables therein.

### Dependencies

First, install both the [Solana CLI tools](https://docs.solana.com/cli/install-solana-cli-tools) and [Anchor](https://www.anchor-lang.com/docs/installation). We recommend `v1.14.20` for Solana and `v0.27.0` for Anchor.

Node : We recommend using [nvm](https://github.com/nvm-sh/nvm#installing-and-updating). Node version needs to be `< v17.0.0`.

Install [Docker](https://docs.docker.com/engine/install/).

Install jq and gsed.

```bash
brew install gnu-sed
brew install jq
```

### Web Frontend

The frontend depends on a postgres database for storing claims and on an instance of Solana to send on-chain transactions.
Here is how to run a local postgres database as a Docker container and a Solana test validator for development.

Install dependencies for the frontend. From the `frontend/` directory, run:

```bash
npm install
```

Start Docker Desktop.

From the `frontend/` directory run:

```
./scripts/setup.sh --dev
```

This script starts both a postgres container and a Solana test validator. It also deploys the program and populates the database with the keys stored in `frontend/integration/keys/`.

On a different terminal tab, run :

```
npm run dev
```

Navigate your browser to `http://localhost:3000` to see the frontend.
The frontend also uses vercel edge functions for its backend API.
The code for this API lives in the `frontend/pages/api` directory.
The functions in that directory are available under the URL `http://localhost:3000/api/`, e.g.,
`http://localhost:3000/api/grant/v1/amount_and_proof`.
You can import the wallets from `frontend/integration/keys/` into your browser wallets to be able to claim tokens in the test environment.

## Unit tests

You can run the unit tests for the `token_dispenser` program as follows:

```bash
cd token_dispenser
cargo test-bpf
```

## Integration tests

From the `frontend/` directory run :

```
./scripts/setup.sh --test
```
3 changes: 3 additions & 0 deletions frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["next/babel"]
}
39 changes: 39 additions & 0 deletions frontend/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

ENDPOINT=http://localhost:8899
CLUSTER=localnet

# Postgres connection variables. These default values should work for local development.
PGHOST=localhost
PGPORT=5432
PGDATABASE=postgres
PGUSER=postgresUser
PGPASSWORD=password
PGSSLMODE="require"

# THE URL OF PYTH SITE
NEXTAUTH_URL=http://localhost:3000

# Used to encrypt the NextAuth.js JWT
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
NEXTAUTH_SECRET= ...

# We have to register our web app on Discord Developer Portal.
# Once registered, we can read the id and secret on its dashboard.
DISCORD_ID=...
DISCORD_SECRET=...
DISCORD_USER_ID=a_discord_userid
# This Discord hash salt is used to keep Discord users anonymous. Instead of storing user ids in the tree we store a hash of the user id with this salt.
DISCORD_HASH_SALT=[177,24,94,160,230,142,37,36,253,97,48,93,127,154,119,45,22,104,86,96,134,14,134,60,195,123,148,222,134,54,45,82,144,129,234,187,168,134,237,16,96,71,64,13,29,228,100,101,228,48,90,249,86,119,74,174,64,169,182,200,227,156,61,16]

# Dispenser guard private key for Discord verification
DISPENSER_GUARD=[128,47,82,29,168,187,15,46,104,227,206,117,172,71,34,235,23,50,248,80,128,0,97,123,11,98,101,163,119,14,167,57,42,97,234,25,212,67,158,180,116,19,127,93,129,233,27,64,49,229,212,43,238,163,218,145,158,47,48,12,235,58,153,212]
FUNDER_KEYPAIR=[145,197,43,77,224,103,196,174,132,195,48,31,177,97,237,163,15,196,217,142,181,204,104,107,98,82,213,0,155,140,218,180,30,119,201,38,51,176,207,221,193,222,235,244,163,250,125,66,68,196,45,208,212,201,232,178,100,163,24,21,106,83,66,174]
DEPLOYER_WALLET=[145,197,43,77,224,103,196,174,132,195,48,31,177,97,237,163,15,196,217,142,181,204,104,107,98,82,213,0,155,140,218,180,30,119,201,38,51,176,207,221,193,222,235,244,163,250,125,66,68,196,45,208,212,201,232,178,100,163,24,21,106,83,66,174]


PROGRAM_ID=Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS
CSV_DIR=/tmp

# Datadog Event Subscriber Configs
TIME_WINDOW_SECS=600
CHUNK_SIZE=50
3 changes: 3 additions & 0 deletions frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
40 changes: 40 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# env
.env

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel

# typescript
*.tsbuildinfo
4 changes: 4 additions & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache
package.json
package-lock.json
public
4 changes: 4 additions & 0 deletions frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}
Loading

0 comments on commit c9396d1

Please sign in to comment.