Skip to content

Commit

Permalink
adding initial files from tribute-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiacodes committed Sep 14, 2021
1 parent a3b2495 commit bb404cc
Show file tree
Hide file tree
Showing 34 changed files with 68,197 additions and 2 deletions.
167 changes: 167 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Logs

_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log\*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# TypeScript v1 declaration files

typings/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variables file

.env
.env.test

# parcel-bundler cache (https://parceljs.org/)

.cache

# Next.js build output

.next

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and _not_ Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Build/Contracts

build/
generated/

# Test Coverage Reports

coverage
coverage.json
coverageEnv
contracts-backup
.coverage_artifacts
.coverage_contracts

.env

docker/data
artifacts
cache
typechain

# this subgraph.yaml is created during the hardhat test; ignore it

<!-- subgraph.yaml -->

.DS_Store
.vscode

# Logs of the contract deployment

\*-deploy.log
81 changes: 79 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,79 @@
# tribute-subgraph
Tribute DAO Framework Subgraph
# Tribute DAO Framework Subgraph

> Graph definition for the Tribute DAO Framework
## Subgraph Setup

You need to install Graph CLI with either npm or yarn.

> Note: You need version 0.21.0 or above
NPM Install:

```
npm install -g @graphprotocol/graph-cli
```

Yarn Install:

```
yarn global add @graphprotocol/graph-cli
```

### Multiple Ethereum Networks Setup

The Graph have launched their decentralized product called Subgraph Studio, for publishing, and curating on the decentralized (mainnet) network. See [here](https://thegraph.com/docs/developer/deploy-subgraph-studio) for more information.

The batch-deploy.ts script has been updated to deploy to both testnet and mainnet networks.

Managing different network deployments for the contracts, is currently setup using a config file in `config/subgraph-config.json`, providing the network, start block, subgraph directory, github username, and contract address for the DaoFactory and optional adapters:

For example:

```
[
{
"network": "rinkeby",
"daoFactoryAddress": "0x10a14A1665DE72faeDb866Fc75c57036813E2Eb2",
"daoFactoryStartBlock": 6204221,
"couponOnboardingAddress": "0x20a14A1665DE72faeDb866Fc75c57036813E2Eb3",
"couponOnboardingStartBlock": 7204228,
"GITHUB_USERNAME": "openlawteam",
"SUBGRAPH_NAME_OR_SLUG": "tribute-dev"
},
{
"network": "mainnet",
"daoFactoryAddress": "0xac665be1e44cc4eec388e34c3899c271fee847f4",
"daoFactoryStartBlock": 8332211,
"SUBGRAPH_NAME_OR_SLUG": "tribute-prod"
}
]
```

In `.env` (create `.env` file if necessary):

```
# For testnet (rinkeby, ropsten, etc)
GRAPH_ACCESS_TOKEN=...
# For mainnet
GRAPH_DEPLOYMENT_KEY=...
```

Then from the `subgraph` directory, simply run the following command to deploy the subgraphs:

```
npx ts-node subgraph-deployer.ts
```

_IMPORTANT_: If deploying to mainnet the command line will prompt for an input for the `✔ Version Label (e.g. v0.0.1)`, enter the version and the deployment will resume.

See [here](https://thegraph.com/docs/deploy-a-subgraph#redeploying-a-subgraph) for more information.

### Local Development Graph Setup

Check out the setup guide [here](https://github.com/openlawteam/tribute-contracts/blob/master/subgraph/docker/README.md)

## Subgraph Tests

TODO
30 changes: 30 additions & 0 deletions config/subgraph-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"network": "rinkeby",
"daoFactoryAddress": "0x392E9D1c7FaE6C62853e089466FFAE3F0a93c680",
"daoFactoryStartBlock": 8705810,
"GITHUB_USERNAME": "openlawteam",
"SUBGRAPH_NAME_OR_SLUG": "tribute-dev"
},
{
"network": "rinkeby",
"daoFactoryAddress": "0xC97Aa4e619A9c7B6c6c2A823e361FC9B7f8f724B",
"daoFactoryStartBlock": 8706002,
"GITHUB_USERNAME": "openlawteam",
"SUBGRAPH_NAME_OR_SLUG": "museo-dev"
},
{
"network": "rinkeby",
"daoFactoryAddress": "0x9a1Bae2B9C69eE18D44792993cA7a0B4DA353038",
"daoFactoryStartBlock": 8706110,
"GITHUB_USERNAME": "openlawteam",
"SUBGRAPH_NAME_OR_SLUG": "alien-dev"
},
{
"network": "rinkeby",
"daoFactoryAddress": "0xD1588E0F31604E14F85Ed116D2B8AE816673B57F",
"daoFactoryStartBlock": 8686996,
"GITHUB_USERNAME": "openlawteam",
"SUBGRAPH_NAME_OR_SLUG": "darkhorse-dev"
}
]
79 changes: 79 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Full build with debuginfo for graph-node
#
# The expectation if that the docker build uses the parent directory as PWD
# by running something like the following
# docker build --target STAGE -f docker/Dockerfile .

FROM rust:latest as graph-node-build

ARG COMMIT_SHA=unknown
ARG REPO_NAME=unknown
ARG BRANCH_NAME=unknown
ARG TAG_NAME=unknown

ADD . /graph-node

RUN cd /graph-node \
&& RUSTFLAGS="-g" cargo install --locked --path node \
&& cargo clean \
&& objcopy --only-keep-debug /usr/local/cargo/bin/graph-node /usr/local/cargo/bin/graph-node.debug \
&& strip -g /usr/local/cargo/bin/graph-node \
&& cd /usr/local/cargo/bin \
&& objcopy --add-gnu-debuglink=graph-node.debug graph-node \
&& echo "REPO_NAME='$REPO_NAME'" > /etc/image-info \
&& echo "TAG_NAME='$TAG_NAME'" >> /etc/image-info \
&& echo "BRANCH_NAME='$BRANCH_NAME'" >> /etc/image-info \
&& echo "COMMIT_SHA='$COMMIT_SHA'" >> /etc/image-info \
&& echo "CARGO_VERSION='$(cargo --version)'" >> /etc/image-info \
&& echo "RUST_VERSION='$(rustc --version)'" >> /etc/image-info

# The graph-node runtime image with only the executable
FROM debian:buster-slim as graph-node
ENV RUST_LOG ""
ENV GRAPH_LOG ""
ENV EARLY_LOG_CHUNK_SIZE ""
ENV ETHEREUM_RPC_PARALLEL_REQUESTS ""
ENV ETHEREUM_BLOCK_CHUNK_SIZE ""

ENV postgres_host ""
ENV postgres_user ""
ENV postgres_pass ""
ENV postgres_db ""
# The full URL to the IPFS node
ENV ipfs ""
# The etherum network(s) to connect to. Set this to a space-separated
# list of the networks where each entry has the form NAME:URL
ENV ethereum ""
# The role the node should have, one of index-node, query-node, or
# combined-node
ENV node_role "combined-node"
# The name of this node
ENV node_id "default"
# The ethereum network polling interval (in milliseconds)
ENV ethereum_polling_interval ""

# HTTP port
EXPOSE 8000
# WebSocket port
EXPOSE 8001
# JSON-RPC port
EXPOSE 8020
# Indexing status port
EXPOSE 8030

RUN apt-get update \
&& apt-get install -y libpq-dev ca-certificates netcat

ADD docker/wait_for docker/start /usr/local/bin/
COPY --from=graph-node-build /usr/local/cargo/bin/graph-node /usr/local/bin
COPY --from=graph-node-build /etc/image-info /etc/image-info
COPY docker/Dockerfile /Dockerfile
CMD start

# Debug image to access core dumps
FROM graph-node-build as graph-node-debug
RUN apt-get update \
&& apt-get install -y curl gdb postgresql-client

COPY docker/Dockerfile /Dockerfile
COPY docker/bin/* /usr/local/bin/
38 changes: 38 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Graph Node Docker Image

Preconfigured Docker image for running a Graph Node.

## Usage

Start ganache with `ganache-cli --host 0.0.0.0 --port 7545 --networkId 1337 --blockTime 10 --mnemonic "twelve words including quotes"` in one terminal window.

> Note that -h 0.0.0.0 is necessary for Ganache to be accessible from within Docker and from other machines. By default, Ganache only binds to 127.0.0.1, which can only be accessed from the host machine that Ganache runs on. [The Graph]
[the graph]: https://thegraph.com/docs/quick-start#1.-set-up-ganache-cli

In a new terminal window, `npm run deploy:ganache` and copy the `DaoFactory` contract address and block number into the respective `address` and `startBlock` (important: make sure the block number starts from 1 previous block, for example, if the block number is 19 add 18 as the `startBlock`) for the `DaoFactory` source in `subgraph/subgraph.yaml`.

Then, `cd subgraph/docker/` and `docker-compose up`.

This will start IPFS, Postgres and Graph Node in Docker and create persistent
data directories for IPFS and Postgres in `./data/ipfs` and `./data/postgres`. You
can access these via:

- Graph Node:
- GraphiQL: `http://localhost:8000/`
- HTTP: `http://localhost:8000/subgraphs/name/<subgraph-name>`
- WebSockets: `ws://localhost:8001/subgraphs/name/<subgraph-name>`
- Admin: `http://localhost:8020/`
- IPFS:
- `127.0.0.1:5001` or `/ip4/127.0.0.1/tcp/5001`
- Postgres:
- `postgresql://graph-node:let-me-in@localhost:5432/graph-node`

Once this is up and running, you can create and deploy your subgraph to the running Graph Node. To do this, in another terminal window from the project root directory, `truffle compile` to build the contracts, if they aren't already built.

Then from the `subgraph` directory:

- `npm ci` to install dependencies
- `npm run codegen` to run the code generation
- `yarn create-local` to allocate the subgraph name in the Graph Node
- `yarn deploy-local` to deploy the subgraph to your local Graph Node
Loading

0 comments on commit bb404cc

Please sign in to comment.