Skip to content

Commit 86798d6

Browse files
authored
Merge branch 'dev' into ariel/delegation-no-shares
2 parents 059f634 + d7a7e49 commit 86798d6

File tree

79 files changed

+930
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+930
-417
lines changed

.github/workflows/npmtest.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ jobs:
2020
uses: actions/setup-node@v1
2121
with:
2222
node-version: ${{ matrix.node-version }}
23-
- run: yarn install --non-interactive --frozen-lockfile
23+
- name: Install packages
24+
run: yarn install --non-interactive --frozen-lockfile
2425
env:
2526
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
26-
- run: yarn test
27+
- name: Run tests
28+
run: yarn test:coverage
29+
- name: Upload coverage report
30+
uses: codecov/codecov-action@v2
31+
with:
32+
token: ${{ secrets.CODECOV_TOKEN }}
33+
files: ./coverage.json
34+
flags: unittests
35+
name: graphprotocol-contracts
36+
fail_ci_if_error: true

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
# Ignore zeppelin contracts
21
node_modules/
32

43
# Ignore build stuff
54
cache/
65
build/
76
dist/
87

9-
# Coverage tests
10-
coverage/
11-
128
# Hardhat cache
139
cached/
1410

@@ -20,5 +16,6 @@ bin/
2016
.DS_Store
2117
.vscode
2218

23-
# Sliter
19+
# Coverage and other reports
2420
/reports
21+
coverage.json

DEPLOYMENT.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
## Deploying the Solidity Smart Contracts
2-
32
### Running
43

5-
A CLI in `cli/cli.ts` deploys the contracts to the specified network when used with the `migrate` command.
6-
7-
This script accepts multiple commands that you can print using:
4+
Deploy functionality exists in `cli/cli.ts`. You can deploy the contracts to the specified network
5+
when used with the `migrate` command. This script accepts multiple commands that you can print using:
86

9-
```
7+
```bash
108
cli/cli.ts --help
119
```
1210

LICENSE

Lines changed: 342 additions & 18 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,134 @@
1-
# Graph Protocol Solidity Smart Contracts
1+
![License: GPL](https://img.shields.io/badge/license-GPL-blue)
2+
![Version Badge](https://img.shields.io/badge/version-1.6.0-lightgrey.svg)
3+
![CI Status](https://github.com/graphprotocol/contracts/actions/workflows/npmtest.yml/badge.svg)
4+
[![codecov](https://codecov.io/gh/graphprotocol/contracts/branch/dev/graph/badge.svg?token=S8JWGR9SBN)](https://codecov.io/gh/graphprotocol/contracts)
25

3-
![Version Badge](https://img.shields.io/badge/version-1.0.0-lightgrey.svg)
6+
# Graph Protocol Contracts
47

5-
## Contracts
8+
[The Graph](https://thegraph.com/) 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.
69

7-
This repository contains The Graph Protocol solidity contracts. It is based on the
8-
[PRD outlined here](https://www.notion.so/thegraph/Public-Network-Contracts-PRD-5eb8466aa4b44a1da7f16a28acd6674f),
9-
There are many other smaller, more detailed PRDs that these contracts implement, that can also be
10-
found on notion.
10+
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](https://github.com/graphprotocol/graph-node) 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).
1111

12-
The contracts enable a staking protocol build on top of Ethereum, using The Graph Network Token
13-
(GRT). The network enables a decentralized network of Graph Nodes
14-
to index and serve queries for subgraphs.
15-
[Graph node's repository can be found here](https://github.com/graphprotocol/graph-node).
12+
The protocol allows Indexers to Stake, Delegators to Delegate, and Curators to Signal on Subgraphs. The Signal informs Indexers which Subgraphs they should index.
1613

17-
The Graph Network enables smart contract development to happen alongside subgraph development.
18-
It is a new and improved way to develop dapps. It allows developers to move some logic into the
19-
subgraph for resolving data based on events, or past storage data on Ethereum. Therefore,
20-
the contracts and the subgraph rely on each other, to show to end users the current data and state
21-
of The Graph Network.
14+
You can learn more by heading to [the documentation](https://thegraph.com/docs/about/introduction), or checking out some of the [blog posts on the protocol](https://thegraph.com/blog/the-graph-network-in-depth-part-1).
2215

23-
### Contracts Testing
16+
# Contracts
17+
18+
The contracts are upgradable, following the [Open Zeppelin Proxy Upgrade Pattern](https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies). Each contract will be explained in brief detail below.
19+
20+
**_Curation_**
21+
22+
> 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.
23+
24+
**_Graph Name Service (GNS)_**
25+
26+
> 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.
27+
28+
**_Service Registry_**
29+
30+
> 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.
31+
32+
**_Dispute Manager_**
33+
34+
> Provides a way for Indexers to be slashed or incorrect or malicious behaviour. There are two types of disputes: _Query Disputes_ and _Indexing Disputes_.
35+
36+
**_Epoch Manager_**
37+
38+
> Keeps track of protocol Epochs. Epochs are configured to be a certain block length, which is configurable by The Governor.
39+
40+
**_Controller_**
41+
42+
> 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](https://thegraph.com/blog/introducing-the-graph-council).
43+
44+
**_Rewards Manager_**
45+
46+
> 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.
47+
48+
**_Staking_**
49+
50+
> 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.
51+
52+
**_Graph Token_**
53+
54+
> An ERC-20 token (GRT) that is used as a work token to power the network incentives. The token is inflationary.
55+
56+
# NPM package
57+
58+
The [NPM package](https://www.npmjs.com/package/@graphprotocol/contracts) contains contract interfaces and addresses for the testnet and mainnet. It also contains [typechain](https://github.com/ethereum-ts/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.
59+
60+
```
61+
yarn add @graphprotocol/contracts
62+
```
63+
64+
# Contract Addresses
65+
66+
The testnet runs on Rinkeby, while mainnet is on Ethereum Mainnet. The addresses for both of these can be found in `./addresses.json`.
67+
68+
# Local Setup
69+
70+
To setup the contracts locally, checkout the `dev` branch, then run:
71+
72+
```bash
73+
yarn
74+
yarn build
75+
```
76+
77+
# Testing
2478

2579
Testing is done with the following stack:
2680

27-
- Waffle
28-
- Hardhat
29-
- Typescript
30-
- Ethers
81+
- [Waffle](https://getwaffle.io/)
82+
- [Hardhat](https://hardhat.org/)
83+
- [Typescript](https://www.typescriptlang.org/)
84+
- [Ethers](https://docs.ethers.io/v5/)
3185

3286
To test all files, use `yarn test`. To test a single file run:
33-
`npx hardhat test test/<FILE_NAME>.ts`.
3487

35-
### Contract addresses
88+
```bash
89+
npx hardhat test test/<FILE_NAME>.ts
90+
```
91+
92+
# Interacting with the contracts
93+
94+
There are three ways to interact with the contracts through this repo:
95+
96+
**Hardhat**
3697

37-
Currently we are running our testnet on Rinkeby. Contract addresses can be found in this repository at
38-
`./addresses.json`. However, addresses should be obtained from the NPM Package.
98+
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.
3999

40-
### Deploying Contracts
100+
```
101+
# A console to interact with testnet contracts
102+
npx hardhat console --network rinkeby
103+
```
41104

42-
In order to run deployments, see `./DEPLOYMENT.md`. We use a custom deployment script, which
43-
allowed us to completely remove `truffle` as a dependency.
105+
**Hardhat Tasks**
44106

45-
## Subgraph
107+
There are hardhat tasks under the `/tasks` folder. Most tasks are for complex queries to get back data from the protocol.
46108

47-
The subgraph repository can be [found here](https://github.com/graphprotocol/graph-network-subgraph).
109+
**cli**
48110

49-
Great care must be taken to ensure all the code and data the subgraph refers to is in sync with
50-
the current contracts on the correct network. For tracking all of this, we have an NPM package.
111+
There is a cli that can be used to read or write to the contracts. It includes scripts to help with deployment.
51112

52-
The addresses
53-
for the subgraph need to be the most up to date. This includes grabbing the latest ABIs and
54-
typechain bindings, as well as pointing the addresses in the subgraph manifest to the latest
55-
addresses. You can find the latest subgraph addresses in `addresses.json`, and they are also
56-
in the NPM package.
113+
# Deploying Contracts
57114

58-
Currently the contracts are being tested on Rinkeby. We test on ganache as well. We used to use
59-
Kovan, but it is somewhat deprecated.
115+
In order to run deployments, see [`./DEPLOYMENT.md`](./DEPLOYMENT.md).
60116

61-
## NPM package
117+
# Contributing
62118

63-
The NPM package will be release in versions, and the version will be coordinated to be the same
64-
version as the contracts and the subgraph. Anyone wanting to tie into the graph network contracts
65-
or subgraph should install the npm package into their repository, and refer to the same version
66-
number for the contracts and subgraph.
119+
Contributions are welcomed and encouraged! You can do so by:
67120

68-
**New development work on the contracts and subgraph will be merged to master. Thus, when developing**
69-
**on the network, you should not rely on the master code as it might break between the subgraph repo**
70-
**and the contracts repo. Please use a version that is tagged.**
121+
- Creating an issue
122+
- Opening a PR
71123

72-
The NPM package will contain the following files/information:
124+
If you are opening a PR, it is a good idea to first go to [The Graph Discord](https://discord.com/invite/vtvv7FP) or [The Graph Forum](https://forum.thegraph.com/) and discuss your idea! Discussions on the forum or Discord are another great way to contribute.
73125

74-
- The contracts
75-
- The ABIs for those contracts
76-
- The typechain autogenerated functions. These are typescript functions that are created based off
77-
the ABIs, and are very useful for their type checking and the fact they are tied to a version
78-
- The deployed addresses for each network, the date of deployment, and the commit hash.
79-
- Metadata JSON objects for Graph Account and Subgraph metadata
80-
**This is the only place you should grab contract addresses from.**
126+
# Security Disclosure
81127

82-
We will also release versions for specific releases, such as `@graphprotocol/contracts@beta`.
128+
If you have found a bug / security issue, please go through the official channel, [The Graph Security Bounties on Immunefi](https://immunefi.com/bounty/thegraph/). Responsible disclosure procedures must be followed to receive bounties.
83129

84130
# Copyright
85131

86-
Copyright &copy; 2020 The Graph Foundation
132+
Copyright &copy; 2021 The Graph Foundation
87133

88-
Licensed under [MIT license](LICENSE).
134+
Licensed under [GPL license](LICENSE).
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)