Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
059f634
Revert when not enough precision to assign a delegation share
abarmat Aug 5, 2021
66d2a3b
effective reserve ratio for mint
jona Aug 28, 2021
15a4229
set initialization period through initialize
jona Aug 28, 2021
a70410c
use effectiveReserveRatio for burn
jona Aug 28, 2021
2976c1d
update _getEffectiveReserveRatio parameters passed, add natspec for _…
jona Aug 28, 2021
216caaa
update curationPool.reserveRatio use on curation pool init
jona Aug 28, 2021
0cdbeb5
update natspec for signalToTokens
jona Aug 28, 2021
3780a14
update curation tests to support createdAt
jona Aug 28, 2021
7fa6532
initialize blocksPerDay in Curation contract
jona Aug 28, 2021
185032c
undo update to addresses.json
jona Aug 28, 2021
daa3629
fix curation tests
jona Aug 28, 2021
204113e
refactor calcBondingCurve to helper lib, fix gns tests
jona Aug 28, 2021
7753b34
use MAX_PPM instead of RESERVE_RATIO_ONE, remove unused BLOCKS_PER_DAY
jona Aug 29, 2021
68e62d2
add tests for initialization phase, allow initialization variables to…
jona Aug 29, 2021
dcf2fcb
use effective reserve ratio helper functions
jona Aug 29, 2021
750360f
add precision to effective reserve ratio
jona Aug 30, 2021
8e4a3fd
tests: code coverage reports
abarmat Aug 29, 2021
637beeb
docs: update badges
abarmat Aug 29, 2021
eb24762
build(deps-dev): bump @openzeppelin/contracts from 3.4.1 to 3.4.2
dependabot[bot] Aug 30, 2021
0ddc118
only need 6 precision
jona Aug 31, 2021
cad7435
update test description
jona Aug 31, 2021
d811f48
add governor only functions for initialization properties
jona Sep 1, 2021
1a29726
rework to keep public functions the same
jona Sep 1, 2021
f30360d
only gns contract can call setCreatedAt
jona Sep 1, 2021
84181a9
add CurationV2Storage
jona Sep 1, 2021
9576171
shift struct property
jona Sep 1, 2021
9039215
no need for gns.getAddress
jona Sep 1, 2021
662c60a
fix emit for blocksPerDay
jona Sep 1, 2021
f632beb
Update license
abarmat Sep 2, 2021
81eef3a
docs: updated README (#500)
davekay100 Sep 3, 2021
a2d65aa
docs: update license in README
abarmat Sep 3, 2021
8be0588
docs: small title update to README
abarmat Sep 3, 2021
310326d
cli: remove query tasks from the repo
abarmat Sep 4, 2021
329e92f
Allow batch transactions using multicall in the GNS (#485)
abarmat Sep 7, 2021
b1e0632
test: fix check in one of the tests as coverage returns a different r…
abarmat Sep 7, 2021
089586a
docs: add Consensys Diligence initial review
abarmat Sep 7, 2021
5d73b10
v1.7.0
abarmat Sep 7, 2021
40a2a72
docs: add GNS batch call improvements audit
abarmat Sep 7, 2021
ca25cab
cli: fix extending environment when using the console
abarmat Sep 7, 2021
77b0b1f
docs: update README
abarmat Sep 10, 2021
d60e5a1
build: fix slither report (#501)
glmaljkovich Sep 17, 2021
02c1681
tests: add additional test for GNS
abarmat Sep 21, 2021
c7b772b
tests: add event tracing support for tests
abarmat Sep 21, 2021
744e58c
add mythril reports and slither VSCode config (#504)
glmaljkovich Sep 21, 2021
3cbda32
build(deps): bump tar from 4.4.15 to 4.4.19
dependabot[bot] Sep 21, 2021
9ed77d4
build(deps): bump semver-regex from 3.1.2 to 3.1.3
dependabot[bot] Sep 21, 2021
d7a7e49
docs: add upgrade audits for GIP proposals
abarmat Sep 22, 2021
86798d6
Merge branch 'dev' into ariel/delegation-no-shares
abarmat Sep 22, 2021
834854a
Merge pull request #491 from graphprotocol/ariel/delegation-no-shares
abarmat Sep 22, 2021
f34e90b
Allow unstake passing a larger amount than available (#487)
abarmat Sep 22, 2021
9aabeb1
config: upgrade GNS implementation
abarmat Sep 28, 2021
ec7f51a
v1.8.0
abarmat Sep 28, 2021
e971351
Merge branch 'dev' into feature/initialization-phase
jona Sep 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/npmtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --non-interactive --frozen-lockfile
- name: Install packages
run: yarn install --non-interactive --frozen-lockfile
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
- run: yarn test
- name: Run tests
run: yarn test:coverage
- name: Upload coverage report
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.json
flags: unittests
name: graphprotocol-contracts
fail_ci_if_error: true
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Ignore zeppelin contracts
node_modules/

# Ignore build stuff
cache/
build/
dist/

# Coverage tests
coverage/

# Hardhat cache
cached/

Expand All @@ -20,5 +16,6 @@ bin/
.DS_Store
.vscode

# Sliter
# Coverage and other reports
/reports
coverage.json
8 changes: 3 additions & 5 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
## Deploying the Solidity Smart Contracts

### Running

A CLI in `cli/cli.ts` deploys the contracts to the specified network when used with the `migrate` command.

This script accepts multiple commands that you can print using:
Deploy functionality exists in `cli/cli.ts`. You can deploy the contracts to the specified network
when used with the `migrate` command. This script accepts multiple commands that you can print using:

```
```bash
cli/cli.ts --help
```

Expand Down
360 changes: 342 additions & 18 deletions LICENSE

Large diffs are not rendered by default.

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

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

## Contracts
[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.

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

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

The Graph Network enables smart contract development to happen alongside subgraph development.
It is a new and improved way to develop dapps. It allows developers to move some logic into the
subgraph for resolving data based on events, or past storage data on Ethereum. Therefore,
the contracts and the subgraph rely on each other, to show to end users the current data and state
of The Graph Network.
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).

### Contracts Testing
# Contracts

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.

**_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](https://thegraph.com/blog/introducing-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](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.

```
yarn add @graphprotocol/contracts
```

# Contract Addresses

The testnet runs on Rinkeby, 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:

```bash
yarn
yarn build
```

# Testing

Testing is done with the following stack:

- Waffle
- Hardhat
- Typescript
- Ethers
- [Waffle](https://getwaffle.io/)
- [Hardhat](https://hardhat.org/)
- [Typescript](https://www.typescriptlang.org/)
- [Ethers](https://docs.ethers.io/v5/)

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

### Contract addresses
```bash
npx hardhat test test/<FILE_NAME>.ts
```

# Interacting with the contracts

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

**Hardhat**

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

### Deploying Contracts
```
# A console to interact with testnet contracts
npx hardhat console --network rinkeby
```

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

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

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

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

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

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

## NPM package
# Contributing

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

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

The NPM package will contain the following files/information:
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.

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

We will also release versions for specific releases, such as `@graphprotocol/contracts@beta`.
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.

# Copyright

Copyright &copy; 2020 The Graph Foundation
Copyright &copy; 2021 The Graph Foundation

Licensed under [MIT license](LICENSE).
Licensed under [GPL license](LICENSE).
4 changes: 2 additions & 2 deletions addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@
"txHash": "0x7ef90b0477e5c5d05bbd203af7d2bf15224640204e12abb07331df11425d2d00",
"proxy": true,
"implementation": {
"address": "0x28037b93702335E55fe6319e1C144B8A4d05DAEB",
"address": "0x8F0031C8A936e3f78Db1E0670135CCad27E5b689",
"creationCodeHash": "0x94893fd38fff869e917edd9efecfbec10407d1484572b7dce9455fa88898c310",
"runtimeCodeHash": "0xd3367702add6bae5bbe1d8048cb34975ca8b53b560603b07694f1679a1418b24",
"txHash": "0x2b997e8470285c174732616c9977b13ad99959a7ea83c39d2647675853389f23"
"txHash": "0xc0072042ee9b46a6f5b3d3846c6117353d7060e2b4a497c620a361e866d46244"
}
},
"Staking": {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added audits/OpenZeppelin/2021-08-graph-gns-audit.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions contracts/base/IMulticall.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.3;
pragma experimental ABIEncoderV2;

/**
* @title Multicall interface
* @notice Enables calling multiple methods in a single call to the contract
*/
interface IMulticall {
/**
* @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
* @param data The encoded function data for each of the calls to make to this contract
* @return results The results from each of the calls passed in via data
*/
function multicall(bytes[] calldata data) external returns (bytes[] memory results);
}
34 changes: 34 additions & 0 deletions contracts/base/Multicall.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.3;
pragma experimental ABIEncoderV2;

import "./IMulticall.sol";

// Inspired by https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/base/Multicall.sol
// Note: Removed payable from the multicall

/**
* @title Multicall
* @notice Enables calling multiple methods in a single call to the contract
*/
abstract contract Multicall is IMulticall {
/// @inheritdoc IMulticall
function multicall(bytes[] calldata data) external override returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);

if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}

results[i] = result;
}
}
}
Loading