Skip to content

Commit

Permalink
Local dev env setup (#2923)
Browse files Browse the repository at this point in the history
* local dev env setup

* rename dev commands

* update readme

---------

Co-authored-by: jaxcoder / <[email protected]>
  • Loading branch information
gravityblast and codenamejason authored Feb 15, 2024
1 parent af7ce95 commit a2ebf84
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 39 deletions.
97 changes: 62 additions & 35 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,87 @@
version: '3.8'

# Ports
# Dev chain 1: 8545
# Dev chain 2: 8546
# Builder: 3000
# Explorer: 3001
# Manager: 3002
# Pinata: 3003
# Indexer: 3004
# Dev chain 1: 3005
# Subgraph dev chain 1: 3006
# Dev chain 2: 3007
# Subgraph dev chain 2: 3008

services:
pinata:
pina:
image: ghcr.io/gitcoinco/pina:main
networks:
- grants-stack

ports:
- '127.0.0.1:3003:8000'

localchain-1:
image: ghcr.io/gitcoinco/allo-contracts-v1:main
local-chain-1:
image: ghcr.io/foundry-rs/foundry:nightly-b174c3a4f80938636f18b3c9e49d45e6643f64a9
networks:
- grants-stack
ports:
- '127.0.0.1:3005:8545'
- '127.0.0.1:8545:8545'
environment:
- DEV_CHAIN_ID=313371
entrypoint: ["anvil", "--host", "0.0.0.0", "--chain-id", "313371"]

# initializes localchain deploying contracts and populates with test data
dev-setup-1:
image: ghcr.io/gitcoinco/allo-contracts-v1:main
depends_on:
- pinata
- localchain-1
local-chain-2:
image: ghcr.io/foundry-rs/foundry:nightly-b174c3a4f80938636f18b3c9e49d45e6643f64a9
networks:
- grants-stack
ports:
- '127.0.0.1:8546:8545'
environment:
- PINATA_HOST=pinata
- PINATA_PORT=8000
- DEV_CHAIN_HOST=localchain-1
- DEV_CHAIN_ID=313371
restart: "no"
entrypoint: [ "bash", "-c", "sleep 2 && corepack enable && exec ./docker/deploy-contracts.sh"]
- DEV_CHAIN_ID=313372
entrypoint: ["anvil", "--host", "0.0.0.0", "--chain-id", "313372"]

localchain-2:
image: ghcr.io/gitcoinco/allo-contracts-v1:pr-1
indexer-db:
image: postgres:13
networks:
- grants-stack
ports:
- '127.0.0.1:3007:8545'
- "127.0.0.1:5432:5432"
environment:
- DEV_CHAIN_ID=313372
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres

# initializes localchain deploying contracts and populates with test data
dev-setup-2:
image: ghcr.io/gitcoinco/allo-contracts-v1:pr-1
indexer:
image: ghcr.io/gravityblast/grants-stack-indexer:main
networks:
- grants-stack
ports:
- '127.0.0.1:3004:4000'
depends_on:
- pinata
- localchain-2
- indexer-db
- pina
- local-chain-1
- local-chain-2
volumes:
- ./tmp/indexer/passport_scores.leveldb:/var/indexer/passport_scores.leveldb
environment:
- PINATA_HOST=pinata
- PINATA_PORT=8000
- DEV_CHAIN_HOST=localchain-2
- DEV_CHAIN_ID=313372
restart: "no"
entrypoint: [ "bash", "-c", "sleep 2 && corepack enable && exec ./docker/deploy-contracts.sh"]
- STORAGE_DIR=/var/indexer
- DATABASE_URL=postgres://postgres:postgres@indexer-db:5432/postgres
- INDEXED_CHAINS=dev1,dev2
- DEV1_RPC_URL=http://local-chain-1:8545
- DEV2_RPC_URL=http://local-chain-2:8545
- IPFS_GATEWAY=http://pina:8000
- PASSPORT_SCORER_ID=335
- PASSPORT_API_KEY=xn9e7AFv.aEfS0ioNhaVtww1jdwnsWtxnrNHspVsS
- COINGECKO_API_KEY=CG-9B9jhrcgAbCdN1QX9bVa1o7v
- PORT=4000
- DEPLOYMENT_ENVIRONMENT=local
- LOG_LEVEL=debug
- ENABLE_RESOURCE_MONITOR=false
- BUILD_TAG=local

entrypoint: ["bash", "-c", "sleep 2 && node dist/src/index.js --http-wait-for-sync=false --drop-db | ./node_modules/.bin/pino-pretty"]

networks:
grants-stack:
name: grants-stack
driver: bridge

8 changes: 4 additions & 4 deletions packages/common/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ export const devChain1: Chain = {
symbol: "ETH",
},
rpcUrls: {
default: { http: ["http://localhost:3005"] },
public: { http: ["http://localhost:3005"] },
default: { http: ["http://localhost:8545"] },
public: { http: ["http://localhost:8545"] },
},
blockExplorers: {
default: {
Expand All @@ -360,8 +360,8 @@ export const devChain2: Chain = {
symbol: "ETH",
},
rpcUrls: {
default: { http: ["http://localhost:3007"] },
public: { http: ["http://localhost:3007"] },
default: { http: ["http://localhost:8546"] },
public: { http: ["http://localhost:8546"] },
},
blockExplorers: {
default: {
Expand Down
49 changes: 49 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Summary

Adds a full local development environment setup allowing local testing with all the services running on `docker-compose` and scripts to populate the environment with test data.

With docker compose we run:

* `piña`: a local dev only IPFS implementation with the Pinata API endpoint to pin files (https://github.com/gitcoinco/pina).
* 2 anvil instances running local chains with id `313371` and `313372`
* 1 postgres database used by the indexer
* an instance of our Indexer indexing the 2 local chains

The `scripts/dev` script contains commands to:

* deploy Allo V1 contracts to the 2 local chains
* populate the 2 chains with Allo V1 projects
* deploy Allo V2 contracts to the 2 local chains
* populate the 2 chains with Allo V2 profiles

## Commands

* `./scripts/dev start`: starts all the services with `docker-compose` in detached mode and follow logs.
* `./scripts/dev stop`: stops the services.
* `./scripts/dev setup`: calls the subcommands to deploy and populate Allo V1 and V2 in the 2 local chains.

## Additional work

* Dockerized allo-v1 scripts to deploy and populate Allo V1 https://github.com/gitcoinco/grants-stack-allo-contracts-v1
* Dockerized allo-v2 scripts to deploy and populate Allo V2 https://github.com/gitcoinco/grants-stack-allo-contracts-v2
* Custom dev-only ipfs server with the same Pinata APIs we use https://github.com/gitcoinco/pina
* Indexer with local chains support and with a temporary fix to make it work locally https://github.com/gravityblast/grants-stack-indexer

## Allo V1

| Contract | Address |
| --- | --- |
| ProjectRegistry | 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 |
| ProgramFactory | 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9 |
| ProgramImplementation | 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 |
| QuadraticFundingVotingStrategyFactory | 0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6 |
| QuadraticFundingVotingStrategyImplementation | 0x8A791620dd6260079BF849Dc5567aDC3F2FdC318 |
| MerklePayoutStrategyFactory | 0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0 |
| MerklePayoutStrategyImplementation | 0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82 |
| DirectPayoutStrategyFactory | 0x0B306BF915C4d645ff596e518fAf3F9669b97016 |
| DirectPayoutStrategyImplementation | 0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1 |
| AlloSettings | 0x3Aa5ebB10DC797CAC828524e59A333d0A371443c |
| RoundFactory | 0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f |
| RoundImplementation | 0x4A679253410272dd5232B3Ff7cF5dbB88f295319 |


189 changes: 189 additions & 0 deletions scripts/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/usr/bin/env bash

ALLO_V1_SETUP_IMAGE="ghcr.io/gitcoinco/grants-stack-allo-contracts-v1:main"
ALLO_V2_SETUP_IMAGE="ghcr.io/gitcoinco/grants-stack-allo-contracts-v2:main"

NETWORK_NAME="grants-stack"

# We use the first two accounts from the test mnemonic
# test test test test test test test test test test test junk
#
# Account 0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
# Account 1: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
#
# To make sure the addresses of the deployed contracts are deterministic,
# we use ACCOUNT_0 to deploy V1 and ACCOUNT_1 to deploy V2.
# We also use ACCOUNT_0 to populate V1 and V2 with test data.
ACCOUNT_0_PK="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
ACCOUNT_1_PK="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"

# Deploy all Allo V1 contracts using the account 0
deploy_v1() {
echo "👷 Deploying V1 contracts to dev chain 1..."
docker run \
--network $NETWORK_NAME \
-e DEPLOYER_PRIVATE_KEY="$ACCOUNT_0_PK" \
-e DEV_CHAIN_HOST=${NETWORK_NAME}-local-chain-1-1 \
-e DEV_CHAIN_ID=313371 \
-e DEV_CHAIN_PORT=8545 \
-e INFURA_ID="NOT_USED" \
$ALLO_V1_SETUP_IMAGE \
bash -c "./docker/deploy-contracts.sh"

echo "👷 Deploying V1 contracts to dev chain 2..."
docker run \
--network $NETWORK_NAME \
-e DEPLOYER_PRIVATE_KEY="$ACCOUNT_0_PK" \
-e DEV_CHAIN_HOST=${NETWORK_NAME}-local-chain-2-1 \
-e DEV_CHAIN_ID=313372 \
-e DEV_CHAIN_PORT=8545 \
-e INFURA_ID="NOT_USED" \
$ALLO_V1_SETUP_IMAGE \
bash -c "./docker/deploy-contracts.sh"
}

# Deploy all Allo V2 contracts using the account at index 1
deploy_v2() {
echo "👷 Deploying V2 contracts to dev chain 1 and 2..."
docker run \
--network $NETWORK_NAME \
-e DEPLOYER_PRIVATE_KEY="$ACCOUNT_1_PK" \
-e DEV1_CHAIN_ID=313371 \
-e DEV1_CHAIN_HOST=${NETWORK_NAME}-local-chain-1-1 \
-e DEV1_CHAIN_PORT=8545 \
-e DEV2_CHAIN_ID=313372 \
-e DEV2_CHAIN_HOST=${NETWORK_NAME}-local-chain-2-1 \
-e DEV2_CHAIN_PORT=8545 \
$ALLO_V2_SETUP_IMAGE \
bash -c "./scripts/dev/deployAllDevNetworks.sh"
}

# Populate Allo V1 using the account account 0
populate_v1() {
echo "👷 Populating V1 in dev chain 1..."
docker run \
--network $NETWORK_NAME \
-e DEPLOYER_PRIVATE_KEY="$ACCOUNT_0_PK" \
-e PINATA_HOST=pina \
-e PINATA_PORT=8000 \
-e DEV_CHAIN_HOST=${NETWORK_NAME}-local-chain-1-1 \
-e DEV_CHAIN_ID=313371 \
-e DEV_CHAIN_PORT=8545 \
-e INFURA_ID="NOT_USED" \
$ALLO_V1_SETUP_IMAGE \
pnpm hardhat run scripts/dev/populate/projects.ts --network dev

echo "👷 Populating V1 in dev chain 2..."
docker run \
--network $NETWORK_NAME \
-e DEPLOYER_PRIVATE_KEY="$ACCOUNT_0_PK" \
-e PINATA_HOST=pina \
-e PINATA_PORT=8000 \
-e DEV_CHAIN_HOST=${NETWORK_NAME}-local-chain-2-1 \
-e DEV_CHAIN_ID=313372 \
-e DEV_CHAIN_PORT=8545 \
-e INFURA_ID="NOT_USED" \
$ALLO_V1_SETUP_IMAGE \
pnpm hardhat run scripts/dev/populate/projects.ts --network dev
}

# Populate Allo V2 contracts using account 0
populate_v2() {
echo "👷 Populating V2 on dev chain 1..."
docker run \
--network $NETWORK_NAME \
-e DEPLOYER_PRIVATE_KEY="$ACCOUNT_0_PK" \
-e PINATA_HOST=pina \
-e PINATA_PORT=8000 \
-e DEV1_CHAIN_ID=313371 \
-e DEV1_CHAIN_HOST=${NETWORK_NAME}-local-chain-1-1 \
-e DEV1_CHAIN_PORT=8545 \
-e DEV2_CHAIN_ID=313372 \
-e DEV2_CHAIN_HOST=${NETWORK_NAME}-local-chain-2-1 \
-e DEV2_CHAIN_PORT=8545 \
$ALLO_V2_SETUP_IMAGE \
bash -c "npx hardhat run scripts/dev/populate.ts --no-compile --network dev1"

echo "👷 Populating V2 on dev chain 2..."
docker run \
--network $NETWORK_NAME \
-e DEPLOYER_PRIVATE_KEY="$ACCOUNT_0_PK" \
-e PINATA_HOST=pina \
-e PINATA_PORT=8000 \
-e DEV1_CHAIN_ID=313371 \
-e DEV1_CHAIN_HOST=${NETWORK_NAME}-local-chain-1-1 \
-e DEV1_CHAIN_PORT=8545 \
-e DEV2_CHAIN_ID=313372 \
-e DEV2_CHAIN_HOST=${NETWORK_NAME}-local-chain-2-1 \
-e DEV2_CHAIN_PORT=8545 \
$ALLO_V2_SETUP_IMAGE \
bash -c "npx hardhat run scripts/dev/populate.ts --no-compile --network dev2"
}

start() {
echo "Starting all services..."
docker-compose up -d
docker-compose logs -f
}

stop() {
echo "Stopping all services..."
docker-compose down
}

init() {
deploy_v1 &&
deploy_v2 &&
populate_v1 &&
populate_v2
}

print_help() {
echo "Usage: $0 <command>"
echo "Commands:"
echo " init Deploy and populate Allo V1 and V2"
echo " deploy-v1 Deploy Allo V1 contracts"
echo " deploy-v2 Deploy Allo V2 contracts"
echo " populate-v1 Populate Allo V1 contracts"
echo " populate-v2 Populate Allo V2 contracts"
echo " start Start all Docker Compose services and follow logs"
echo " stop Stop all Docker Compose services"
echo " help Display this help message"
}

main() {
case "$1" in
init)
init
;;
deploy-v1)
deploy_v1
;;
deploy-v2)
deploy_v2
;;
populate-v1)
populate_v1
;;
populate-v2)
populate_v2
;;
start)
start
;;
stop)
stop
;;
help)
print_help
;;
*)
echo "Error: Unknown command '$1'"
print_help
exit 1
;;
esac
}

main "$@"

0 comments on commit a2ebf84

Please sign in to comment.