npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@openzeppelin/subgraphs

v0.1.8-5

Published

Subgraph templates for @openzeppelin/contracts

Downloads

3,873

Readme

OpenZeppelin Subgraphs

Introduction

This repo contains subgraph schema and templates to index the activity of OpenZeppelin Contracts. For each of the supported OpenZeppelin modules x, this repo provides:

  • Primitives to generate a graphql schema: src/datasource/x.gql.json

    In order to allow composability, the schema are not defined in the graphql format but rather in a dedicated json format which is can be assembled and compiled to graphql using the graph-compiler tool from @amxx/graphprotocol-utils. Graphql version for each modules are also available in generated/x.schema.graphql

  • Template to generate a subgraph manifest: src/datasource/x.yaml

    This file lists all the events that the datasources should listen to, and links that to the corresponding indexing logic. Similarly to the schema, the manifest can be generated procedurally from a JSON app description.

  • Indexing logic: src/datasources/x.ts and (optionally) src/fetch/x.ts

    This is the core logic that processes the events and to index the onchain activity.

Suported modules

  • AccessControl
  • ERC20
  • ERC721
  • ERC1155
  • ERC1967Upgrade
  • Governor
  • Ownable
  • Pausable
  • Timelock

Usage

To use OpenZeppelin Subgraphs, install them in your local project directory and follow the steps outlined in How to build my app's subgraph:

npm install @openzeppelin/subgraphs

How to build my app's subgraph

In order to build your subgraph, the first step is to create a JSON file listing the modules you want to index. Examples of such config can be found in the config folder.

For example, configs/sample.json describes an app with 4 contracts, the first one is an ERC20 with AccessControl, while the 3 others are ERC721 registries.

{
  "output": "generated/sample.",
  "chain": "mainnet",
  "datasources": [
    { "address": "0xA3B26327482312f70E077aAba62336f7643e41E1", "startBlock": 11633151, "module": [ "erc20", "accesscontrol" ] },
    { "address": "0xB1C52075b276f87b1834919167312221d50c9D16", "startBlock":  9917641, "module": "erc721" },
    { "address": "0x799DAa22654128d0C64d5b79eac9283008158730", "startBlock":  9917642, "module": "erc721" },
    { "address": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4", "startBlock":  9917639, "module": "erc721" }
  ]
}

It can be compiled by doing

npx graph-compiler \
  --config configs/sample.json \
  --include node_modules/@openzeppelin/subgraphs/src/datasources \
  --export-schema \
  --export-subgraph

This will create two files, generated/sample.schema.graphql and generated/sample.subgraph.yaml that can be used to build and deploy the corresponding subgraph.

Note: startBlock is optional but will improve your subgraph initial indexing speed.

Live deployments

Admin (Access Control + Ownable + ERC1967)

| Network | Config | Queries (HTTP) | Subscriptions (WS) | |---------|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------| | Mainnet | configs/live/mainnet/admin.json | https://api.thegraph.com/subgraphs/name/amxx/access-control | wss://api.thegraph.com/subgraphs/name/amxx/access-control | | BSC | configs/live/bsc/admin.json | https://api.thegraph.com/subgraphs/name/amxx/access-control-bsc | wss://api.thegraph.com/subgraphs/name/amxx/access-control-bsc | | Matic | configs/live/matic/admin.json | https://api.thegraph.com/subgraphs/name/amxx/access-control-matic | wss://api.thegraph.com/subgraphs/name/amxx/access-control-matic | | XDai | configs/live/xdai/admin.json | https://api.thegraph.com/subgraphs/name/amxx/access-control-xdai | wss://api.thegraph.com/subgraphs/name/amxx/access-control-xdai |

NFTs (ERC721 + ERC1155)

| Network | Config | Queries (HTTP) | Subscriptions (WS) | |---------|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------| | Mainnet | configs/live/mainnet/nfts.json | https://api.thegraph.com/subgraphs/name/amxx/nft-mainnet | wss://api.thegraph.com/subgraphs/name/amxx/nft-mainnet | | BSC | configs/live/bsc/nfts.json | https://api.thegraph.com/subgraphs/name/amxx/nft-bsc | wss://api.thegraph.com/subgraphs/name/amxx/nft-bsc | | Matic | configs/live/matic/nfts.json | https://api.thegraph.com/subgraphs/name/amxx/nft-matic | wss://api.thegraph.com/subgraphs/name/amxx/nft-matic | | XDai | configs/live/xdai/nfts.json | https://api.thegraph.com/subgraphs/name/amxx/nft-xdai | wss://api.thegraph.com/subgraphs/name/amxx/nft-xdai |

ERC721 only

| Network | Config | Queries (HTTP) | Subscriptions (WS) | |---------|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------| | Mainnet | configs/live/mainnet/eip721.json | https://api.thegraph.com/subgraphs/name/amxx/eip721-subgraph | wss://api.thegraph.com/subgraphs/name/amxx/eip721-subgraph |

ERC1155 only

| Network | Config | Queries (HTTP) | Subscriptions (WS) | |---------|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------| | Mainnet | configs/live/mainnet/eip1155.json | https://api.thegraph.com/subgraphs/name/amxx/eip1155-subgraph | wss://api.thegraph.com/subgraphs/name/amxx/eip1155-subgraph |