• Stars
    star
    316
  • Rank 132,587 (Top 3 %)
  • Language
    TypeScript
  • License
    GNU General Publi...
  • Created almost 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Contracts repository for The Graph protocol

License: GPL Version Badge CI Status codecov

Graph Protocol Contracts

The Graph is an indexing protocol for querying networks like Ethereum, IPFS, Polygon, and other blockchains. Anyone can build and Publish open APIs, called subgraphs, making data easily accessible.

The Graph Protocol Smart Contracts are a set of Solidity contracts that exist on the Ethereum Blockchain. The contracts enable an open and permissionless decentralized network that coordinates Graph Nodes to Index any subgraph that is added to the network. Graph Nodes then provide queries to users for those Subgraphs. Users pay for queries with the Graph Token (GRT).

The protocol allows Indexers to Stake, Delegators to Delegate, and Curators to Signal on Subgraphs. The Signal informs Indexers which Subgraphs they should index.

You can learn more by heading to the documentation, or checking out some of the blog posts on the protocol.

Contracts

The contracts are upgradable, following the Open Zeppelin Proxy Upgrade Pattern. Each contract will be explained in brief detail below.

Curation

Allows Curators to Signal GRT towards a Subgraph Deployment they want indexed on The Graph. Curators are often Subgraph Developers, but anyone can participate. Curators also receive a portion of the query fees that are earned on the Subgraph. Signaled GRT goes into a bonding curve, which returns a Graph Curation Share (GCS) to the Curator.

Graph Name Service (GNS)

Wraps around the Curation contract to provide pooling of Curator Signaled tokens towards a single Subgraph. This allows an owner to deploy a Subgraph, and upgrade their Subgraph to a new version. The upgrade will move all Curator tokens to a new Subgraph Deployment with a new bonding curve.

Service Registry

Allows Indexers to tell the network the location of their node. This allows end users to choose a node close to themselves, lowering the latency for queries.

Dispute Manager

Provides a way for Indexers to be slashed or incorrect or malicious behaviour. There are two types of disputes: Query Disputes and Indexing Disputes.

Epoch Manager

Keeps track of protocol Epochs. Epochs are configured to be a certain block length, which is configurable by The Governor.

Controller

The Controller is a contract that has a registry of all protocol contract addresses. It also is the owner of all the contracts. The owner of the Controller is The Governor, which makes The Governor the address that can configure the whole protocol. The Governor is The Graph Council.

Rewards Manager

Tracks how inflationary GRT rewards should be handed out. It relies on the Curation contract and the Staking contract. Signaled GRT in Curation determine what percentage of inflationary tokens go towards each subgraph. Each Subgraph can have multiple Indexers Staked on it. Thus, the total rewards for the Subgraph are split up for each Indexer based on much they have Staked on that Subgraph.

Staking

The Staking contract allows Indexers to Stake on Subgraphs. Indexers Stake by creating Allocations on a Subgraph. It also allows Delegators to Delegate towards an Indexer. The contract also contains the slashing functionality.

Graph Token

An ERC-20 token (GRT) that is used as a work token to power the network incentives. The token is inflationary.

NPM package

The NPM package contains contract interfaces and addresses for the testnet and mainnet. It also contains typechain generated objects to easily interact with the contracts. This allows for anyone to install the package in their repository and interact with the protocol. It is updated and released whenever a change to the contracts occurs.

yarn add @graphprotocol/contracts

Contract Addresses

The testnet runs on Goerli, while mainnet is on Ethereum Mainnet. The addresses for both of these can be found in ./addresses.json.

Local Setup

To setup the contracts locally, checkout the dev branch, then run:

yarn
yarn build

Testing

For testing details see TESTING.md.

Deploying Contracts

In order to run deployments, see DEPLOYMENT.md.

Interacting with the contracts

There are three ways to interact with the contracts through this repo:

Hardhat

The most straightforward way to interact with the contracts is through the hardhat console. We have extended the hardhat runtime environment to include all of the contracts. This makes it easy to run the console with autocomplete for all contracts and all functions. It is a quick and easy way to read and write to the contracts.

# A console to interact with testnet contracts
npx hardhat console --network goerli

Hardhat Tasks

There are hardhat tasks under the /tasks folder. Most tasks are for complex queries to get back data from the protocol.

CLI

There is a CLI that can be used to read or write to the contracts. It includes scripts to help with deployment.

Environment

When running the Hardhat console or tasks you can set what network and accounts to use when sending transactions.

Network

Selecting a network requires just passing --network <name> when running Hardhat. It's important that the network exists in the Hardhat configuration file.

There is a special network called localhost that connects it to a node running on localhost.

Accounts

The accounts used depends on a few environment variables:

  • If MNEMONIC is set you will have available the set of addresses derived from the seed.
  • If PRIVATE_KEY is set, just that account is imported. MNEMONIC always takes precedence over PRIVATE_KEY.
  • If no MNEMONIC or PRIVATE_KEY is set it will use the remote accounts from the provider node.
  • You can always get an account using ethers.getSigner(<address>)

Considerations when forking a chain:

  • When running on the localhost network it will use by default a deterministic seed for testing purposes. If you want to connect to a local node that is forking while retaining the capability to impersonate accounts or use local accounts you need to set the FORK=true environment variable.

Contributing

Contributions are welcomed and encouraged! You can do so by:

  • Creating an issue
  • Opening a PR

If you are opening a PR, it is a good idea to first go to The Graph Discord or The Graph Forum and discuss your idea! Discussions on the forum or Discord are another great way to contribute.

Security Disclosure

If you have found a bug / security issue, please go through the official channel, The Graph Security Bounties on Immunefi. Responsible disclosure procedures must be followed to receive bounties.

Copyright

Copyright Β© 2021 The Graph Foundation

Licensed under GPL license.

More Repositories

1

graph-node

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
Rust
2,882
star
2

graph-tooling

Monorepo for various tools used by subgraph developers.
TypeScript
387
star
3

indexer

Graph Protocol indexer components and infrastructure
TypeScript
236
star
4

graph-ts

TypeScript/AssemblyScript library for writing mappings for The Graph
214
star
5

example-subgraph

An example to help you get started with The Graph
Solidity
179
star
6

graph-client

The Graph library for building GraphQL-based dapps in a decentralized way.
TypeScript
172
star
7

uniswap-subgraph

This is for uniswap-v1. If you are looking for the uniswap v2 subgraph, please go to https://github.com/uniswap/uniswap-v2-subgraph
TypeScript
105
star
8

everest

Registry of crypto projects
JavaScript
98
star
9

docs

Documentation for The Graph
MDX
78
star
10

graph-network-subgraph

The subgraph, the smart contracts, the tests, and documents for the Graph Explorer Decentralized Application
TypeScript
69
star
11

research

Research, proposals, papers, and specs
TeX
48
star
12

ipfs-sync

Script to sync files from one IPFS node to another
JavaScript
48
star
13

ethdenver-dapp

ETHDenver example dApp built on The Graph
JavaScript
43
star
14

erc20-subgraph

TypeScript
33
star
15

hardhat-graph

TypeScript
33
star
16

decentraland-subgraph

Decentraland data source for The Graph
TypeScript
29
star
17

common-ts

Common TypeScript library for use in Graph Protocol components
TypeScript
24
star
18

ens-rainbow

Rust
22
star
19

ens-subgraph

Official repo: https://github.com/ensdomains/ens-subgraph
TypeScript
22
star
20

aragon-subgraph

DAO - subgraph
TypeScript
21
star
21

mission-control-indexer

Technical indexer documentation and infrastructure templates for the Mission Control testnet
TypeScript
21
star
22

indexer-rs

Rewrite of indexer-service in Rust with TAP payments implementation
Rust
21
star
23

token-distribution

Token distribution contracts
TypeScript
21
star
24

agora

Cost model
Rust
20
star
25

rfcs

Graph Protocol RFCs and Engineering Plans
CSS
16
star
26

mission-control-curator

15
star
27

0x-subgraph

Subgraph that tracks events of the 0x protocol
TypeScript
15
star
28

example-subgraphs

TypeScript
14
star
29

allocation-optimizer

Agents and algorithms for optimizing Indexer decision problems.
Julia
14
star
30

firehose-cosmos

Cosmos Firehose integration
Go
11
star
31

support

Community support for the Hosted Service of The Graph
10
star
32

full-stack-graph-app

Deploy a full stack app leveraging The Graph with one click.
TypeScript
10
star
33

compound-v1-subgraph

Compound is an open-source protocol for algorithmic, efficient Money Markets on the Ethereum blockchain.
TypeScript
9
star
34

crypto-buddies

Gatsby React app interview challenge
JavaScript
8
star
35

augur-subgraph

Subgraph for the Augur protocol
TypeScript
8
star
36

qlog

A tool to summarize and analyze graph-node query logs
Rust
8
star
37

bitsausage

Bitsausage auction project
JavaScript
7
star
38

registry-starter

Starting point for apps that curate data
JavaScript
7
star
39

graph-network-analytics-subgraph

Analytics subgraph for Graph Network
TypeScript
6
star
40

stable-hash

A structured hash that is platform independent and has backward compatibility
Rust
6
star
41

common-subgraphs

Subgraphs that are generally useful and/or good examples
Shell
6
star
42

sportx-subgraph

SportX provides a sports betting platform for Ethereum.
TypeScript
6
star
43

block-oracle

Rust
6
star
44

graph-improvement-proposals

The canonical repository for The Graph's protocol governance. Read more about it: https://thegraph.com/ecosystem/governance/
5
star
45

FOAM-subgraph

The FOAM Proof of Location protocol empowers a permissionless and autonomous network of radio beacons that can offer secure location services.
TypeScript
5
star
46

hackathon-react-apollo-app

React, Apollo & Material UI example app
JavaScript
5
star
47

solidity-bindgen

Rust
5
star
48

hardhat-graph-demo

Demo repository for the hardhat-graph plugin
TypeScript
4
star
49

dharma-subgraph

Dharma protocol subgraph
TypeScript
4
star
50

hackathon-scaffold

A starting point for building dApps on The Graph
JavaScript
4
star
51

mutations

TypeScript
4
star
52

compound-subgraph-wrapper

A wrapper service that extends the Compound subgraph with custom resolvers
TypeScript
4
star
53

cosmoshub-ts

TypeScript
4
star
54

memefactory-subgraph

Memefactory subgraph for The Graph
TypeScript
3
star
55

eip-712-derive

Easy EIP-712
Rust
3
star
56

ipfs-mgm

IPFS cli for content syncing
Go
3
star
57

graph-node-docker

Preconfigured Docker image for running a Graph Node
Dockerfile
3
star
58

adchain-subgraph

Example subgraph project for querying the AdChain TCR
TypeScript
3
star
59

graph-local-state

Shell
2
star
60

thegarii

The Graph Arweave Integration Implementation
Rust
2
star
61

codex

2
star
62

maker-subgraph

Subgraph for maker
TypeScript
2
star
63

governance-subgraph

Subgraph for graph governance
TypeScript
2
star
64

firehose-arweave

The firehose integration with the garii
Go
2
star
65

autotasks

A collection of Defender Autotasks to interact with The Graph protocol contracts
TypeScript
2
star
66

query-examples

Provides examples of how to query Subgraphs published to The Graph Network in a variety of frameworks/languages
2
star
67

DEPRECATED-compound-v2-subgraph

Compound is an open-source protocol for algorithmic, efficient Money Markets on the Ethereum blockchain. DEPRECATED - see the repository under compound-finances github for the current repository https://github.com/graphprotocol/compound-v2-subgraph-1
TypeScript
2
star
68

everest-subgraph

Subgraph for the MetaCartel Everest project registry
1
star
69

hack-for-freedom

1
star
70

ethcc-hackathon

1
star
71

gitcoin-beyond-blockchain-hackathon

A three week virtual hackathon running from June 24th to July 10th powered by Gitcoin
1
star
72

network-support

Graph Network issues and feature requests
1
star
73

subgraph-oracle

The Subgraph Oracle
Rust
1
star
74

graph-pino

Pino log message formatter for The Graph
JavaScript
1
star