Skip to content

Commit

Permalink
Acre subgraph (#280)
Browse files Browse the repository at this point in the history
Closes #263

This PR adds a basic subgraph configuration for the
[AcreBitcoinDepositor](https://sepolia.etherscan.io/address/0x37E34EbC743FFAf96b56b3f62854bb7E733a4B50)
contract. The code was generated automatically by using [graph init
](https://thegraph.com/docs/en/developing/creating-a-subgraph/#from-an-example-subgraph)command.
The project also includes eslint and prettier configurations. Docker was
used to run the subgraph locally. Currently, `AcreBitcoinDepositor` is
deployed on the Sepolia Testnet network but it will eventually be on the
Ethereum Mainnet.


During the work there were a lot of problems over setting up the RPC
correctly. Using the RPC from Alchemy there was a problem with the error
429 too many requests. Therefore, for this reason, it was decided to set
some extra
[parameters](https://github.com/graphprotocol/graph-node/blob/master/docs/environment-variables.md)
to reduce requests. However, if you have any suggestions on which RPC we
should use or see another solution let me know. Currently, this solution
seems the simplest to unblock the next work on data fetching with
subgraph.

<img width="1722" alt="Screenshot 2024-03-04 at 10 38 28"
src="https://github.com/thesis/acre/assets/23117945/7b110819-560e-4d17-8f78-78bd9f4ba851">
  • Loading branch information
nkuba authored Mar 18, 2024
2 parents 5dcfc76 + 8df7eb8 commit 81717eb
Show file tree
Hide file tree
Showing 23 changed files with 3,066 additions and 44 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Subgraph

on:
push:
branches:
- main
paths:
- "subgraph/**"
pull_request:

defaults:
run:
working-directory: ./subgraph

jobs:
subgraph-codegen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v3

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: "subgraph/.nvmrc"
cache: "pnpm"

- name: Install Dependencies
run: pnpm install --prefer-offline --frozen-lockfile

- name: Codegen
run: pnpm run codegen

- name: Upload Codegen Artifacts
uses: actions/upload-artifact@v4
with:
name: subgraph-codegen
path: |
subgraph/generated
if-no-files-found: error

subgraph-format:
needs: [subgraph-codegen]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v3

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: "subgraph/.nvmrc"
cache: "pnpm"

- name: Download Codegen Artifacts
uses: actions/download-artifact@v4
with:
name: subgraph-codegen
path: subgraph/generated

- name: Install Dependencies
run: pnpm install --prefer-offline --frozen-lockfile

- name: Format
run: pnpm run format

subgraph-build:
needs: [subgraph-codegen]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v3

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: "subgraph/.nvmrc"
cache: "pnpm"

- name: Download Codegen Artifacts
uses: actions/download-artifact@v4
with:
name: subgraph-codegen
path: subgraph/generated

- name: Install Dependencies
run: pnpm install --prefer-offline --frozen-lockfile

- name: Build
run: pnpm run build

subgraph-test:
needs: [subgraph-codegen]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v3

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: "subgraph/.nvmrc"
cache: "pnpm"

- name: Download Codegen Artifacts
uses: actions/download-artifact@v4
with:
name: subgraph-codegen
path: subgraph/generated

- name: Install Dependencies
run: pnpm install --prefer-offline --frozen-lockfile

- name: Tests
run: pnpm run test

18 changes: 17 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: root-lint
name: "lint root"
entry: /usr/bin/env bash -c "npm run format"
exclude: (^core/|^dapp/|^website/)
exclude: (^core/|^dapp/|^website/|^subgraph/)
language: script
description: "Checks code according to the package's linter configuration"
# Core
Expand Down Expand Up @@ -75,3 +75,19 @@ repos:
types_or: [json, yaml]
language: script
description: "Checks JSON/YAML code according to the package's linter configuration"
# Subgraph
- id: subgraph-lint-js
name: "lint subgraph ts/js"
entry: /usr/bin/env bash -c "npm --prefix ./subgraph/ run lint:js"
files: ^subgraph/
types_or: [ts, javascript]
language: script
description: "Checks TS/JS code according to the package's linter configuration"
- id: subgraph-lint-config
name: "lint subgraph json/yaml"
entry: /usr/bin/env bash -c "npm --prefix ./subgraph/ run lint:config"
files: ^subgraph/
types_or: [json, yaml]
language: script
description: "Checks JSON/YAML code according to the package's linter configuration"

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ core/
dapp/
website/
sdk/
subgraph/

# Auto-generated files.
pnpm-lock.yaml
Loading

0 comments on commit 81717eb

Please sign in to comment.