Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local dev env setup #2923

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ node_modules
dist/
coverage/
.eslintcache

bun.lockb
tmp
bun.lockb
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
15 changes: 15 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Allo V1

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 "$@"

Loading