Skip to content

Commit 14b517a

Browse files
authored
refactor: update index node to indexer (#194)
1 parent 2a8b626 commit 14b517a

14 files changed

+299
-712
lines changed

README.md

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,113 +4,116 @@
44
![WIP Badge](https://img.shields.io/badge/status-POC-blue.svg)
55
[![Build Status](https://travis-ci.com/graphprotocol/contracts.svg?token=wbxCaTb68vuvzoN4HDgt&branch=master)](https://travis-ci.com/graphprotocol/contracts)
66

7-
**Authors**:
8-
- [Bryant Eisenbach](https://github.com/fubuloubu)
9-
- [Reuven Etzion](https://github.com/retzion)
10-
- [Ashoka Finley](https://github.com/shkfnly)
11-
12-
## Subgraph
7+
## Subgraph
8+
139
The subgraph can be found https://github.com/graphprotocol/graph-network-subgraph. The addresses
1410
for the subgraph need to be the most up to date. This includes grabbing the latest ABIs from here,
15-
as well as pointing the addresses in the subgraph manifest to the latest addresses. You can find
16-
the latest subgraph addresses below.
11+
as well as pointing the addresses in the subgraph manifest to the latest addresses. You can find
12+
the latest subgraph addresses below.
1713

1814
There are currently two networks we deploy to - Ropsten, and Ganache. The Ropsten addresses will
19-
change whenever there are updates to the contract, and we need to redeploy. This needs to be
15+
change whenever there are updates to the contract, and we need to redeploy. This needs to be
2016
done in sync with deploying a new subgraph. The new GNS should point `thegraph` domain to the
2117
latest subgraph.
2218

23-
We want to also run some test scripts to populate data each time new contracts are deployed (WIP,
24-
Jorge has something that will work for this. Also, running the tests in this repo will populate
25-
data.
19+
We want to also run some test scripts to populate data each time new contracts are deployed (WIP,
20+
Jorge has something that will work for this. Also, running the tests in this repo will populate
21+
data.
2622

27-
You will need two files to deploy anything and run `truffle`, they are `.privkey.txt` and
28-
`.infurakey.txt`. Privkey is a 12 word mneumonic, you should grab you 12 words from metamask, so
23+
You will need two files to deploy anything and run `truffle`, they are `.privkey.txt` and
24+
`.infurakey.txt`. Privkey is a 12 word mneumonic, you should grab you 12 words from metamask, so
2925
that your metamask keys will work in the browser with what you deployed as a governor. The infura
3026
key is just the key you get from the infura website that lets you query up to 100,000 queries a day
3127
for free.
3228

3329
### Current Contract Addresses
3430

35-
See https://github.com/graphprotocol/contracts/blob/master/addresses.json.
36-
31+
See https://github.com/graphprotocol/contracts/blob/master/addresses.json.
32+
3733
### Subgraph Deployment Instructions
34+
3835
#### Ganache
39-
Note, ganache MUST be ran with `ganache-cli -d -i 3859`. `-d` Makes the accounts the same for any
40-
instance of ganache, which allows us to have deterministic contract addresses. Therefore anyone can
41-
use the same subgraph manifest for ganache on their own laptop. `-i 99` is used to make the
42-
network ID constant, which helps with the subgraph. If you update the subgraph, you can just
43-
close ganache and start it up again and you can deploy. If you use the same subgraph ID though and
44-
reset ganche, you will have to drop the DB because it will have old data saved in it, with a new
45-
instance of ganache.
36+
37+
Note, ganache MUST be ran with `ganache-cli -d -i 3859`. `-d` Makes the accounts the same for any
38+
instance of ganache, which allows us to have deterministic contract addresses. Therefore anyone can
39+
use the same subgraph manifest for ganache on their own laptop. `-i 99` is used to make the
40+
network ID constant, which helps with the subgraph. If you update the subgraph, you can just
41+
close ganache and start it up again and you can deploy. If you use the same subgraph ID though and
42+
reset ganche, you will have to drop the DB because it will have old data saved in it, with a new
43+
instance of ganache.
4644

4745
1. Run `ipfs daemon`
4846
2. In a new terminal run postrgres with `pg_ctl -D /usr/local/var/postgres -l logfile start`
4947
3. Create a database with `createdb graph-network-ganache`
5048
4. In a new terminal, run ganache with `ganche-cli -d -i 99`
5149
5. In a new terminal go to the `graph-node` repository start the subgraph with
52-
```
53-
cargo run -p graph-node --release -- \
54-
--postgres-url postgresql://davidkajpust@localhost:5432/graph-network-ganache \
55-
--ethereum-rpc ganache:http://127.0.0.1:8545 \
56-
--ipfs 127.0.0.1:5001 \
57-
--debug \
58-
```
50+
51+
```
52+
cargo run -p graph-node --release -- \
53+
--postgres-url postgresql://davidkajpust@localhost:5432/graph-network-ganache \
54+
--ethereum-rpc ganache:http://127.0.0.1:8545 \
55+
--ipfs 127.0.0.1:5001 \
56+
--debug \
57+
```
58+
5959
6. In a new terminal go to the `graph-network-subgraph` repository, and create the subgraph with
60-
` yarn create-local` (NOTE - MAKE SURE THE CONTRACT ADDRESSES IN THE MANIFEST ARE SET TO THE
61-
GANACHE ADDRESSES!)
60+
`yarn create-local` (NOTE - MAKE SURE THE CONTRACT ADDRESSES IN THE MANIFEST ARE SET TO THE
61+
GANACHE ADDRESSES!)
6262
7. Then deploy it with `yarn deploy-local`
6363

6464
At this point, everything is setup. You can then interact with the contracts through Remix, or
6565
our graph explorer UI, or through our automated scripts. Real automated scripts will be added soon,
66-
but for now you can run `truffle test` and it will run all the tests, and execute transactions,
66+
but for now you can run `truffle test` and it will run all the tests, and execute transactions,
6767
which will allow the subgraph to store data.
6868

6969
#### Ropsten
70+
7071
(Note we use the graph hosted service right now to deploy to. We do not use the new Dapp explorer UI
7172
to create and deploy subgraphs. It can be found [here](https://staging.thegraph.com/explorer/subgraph/graphprotocol/explorer-dapp)
7273
]. The subgraph is already created, so we will only mention how to update the subgraph here.
7374

74-
1. Deploy new contracts to Ropsten with `truffle deploy --network ropsten`. Truffle stores the
75-
addresses for networks, so if you are trying to re-deploy you may have to run
76-
`truffle networks —clean`, and then deploy
75+
1. Deploy new contracts to Ropsten with `truffle deploy --network ropsten`. Truffle stores the
76+
addresses for networks, so if you are trying to re-deploy you may have to run
77+
`truffle networks —clean`, and then deploy
7778
2. Get the new contract addresses from the deployment. They are logged in the terminal output from
78-
deploying. Put these contract addresses into the subgraph manifest
79+
deploying. Put these contract addresses into the subgraph manifest
7980
3. Make sure you are a member of `graphprotocol` for the staging explorer application
80-
4. Then make sure you have the right access token for `graphprotocol`. You can set this up with
81-
`graph auth https://api.thegraph.com/deploy/ <ACCESS_TOKEN>`. You can get it from the dashbaord in the
82-
UI, just pick `graphprotocol` instead of your own account, and you will see the token.
81+
4. Then make sure you have the right access token for `graphprotocol`. You can set this up with
82+
`graph auth https://api.thegraph.com/deploy/ <ACCESS_TOKEN>`. You can get it from the dashbaord in the
83+
UI, just pick `graphprotocol` instead of your own account, and you will see the token.
8384
5. Then in the `graph-network-subgraph` repository, just run `yarn deploy` to update a new version
8485
6. You will also have to update information in the `graph-explorer-dapp` repo. You must update
85-
the contract addresses in the `.env.development` file, and you need to update the contract addresses
86-
in the cloud build file
87-
https://github.com/graphprotocol/graph-explorer-dapp/blob/master/cloudbuild.staging.yaml
86+
the contract addresses in the `.env.development` file, and you need to update the contract addresses
87+
in the cloud build file
88+
https://github.com/graphprotocol/graph-explorer-dapp/blob/master/cloudbuild.staging.yaml
8889

8990
At some point in the future we will work on having scripts that will populate data in the subgraph
90-
on ropsten, so we can better test.
91+
on ropsten, so we can better test.
9192

9293
## Installation &amp; Deployment of Contracts
94+
9395
1. Install Node.js `^11.0.0`
9496
1. Run `npm install` at project root directory
9597
1. Install and run `testrpc`, `ganache-cli`, or similar blockchain emulator
96-
- Configure to run on port `8545` or edit `truffle.js` to change the port used by Truffle
98+
- Configure to run on port `8545` or edit `truffle.js` to change the port used by Truffle
9799
1. Install Truffle 5.0.0
98-
- `npm install -g truffle`
100+
- `npm install -g truffle`
99101
1. Truffle project commands
100-
- `truffle install` (installs ethPM dependencies)
101-
- `truffle compile` (compiles without deploying, local blockchain emulator not neccessary)
102-
- `truffle migrate [--reset] [--compile-all]` (deploys contracts to your local emulator or specified blockchain)
103-
- `truffle test` (runs tests)
102+
- `truffle install` (installs ethPM dependencies)
103+
- `truffle compile` (compiles without deploying, local blockchain emulator not neccessary)
104+
- `truffle migrate [--reset] [--compile-all]` (deploys contracts to your local emulator or specified blockchain)
105+
- `truffle test` (runs tests)
104106
1. See [DEPLOYMENT.md](./DEPLOYMENT.md) for instructions on deploying the contracts to the blockchain.
105107

106108
## Abstract
109+
107110
This repository will contain the Solidity smart contracts needed to facilitate the processes defined in the Product Requirements Document provided by The Graph.
108111
(see: [PRD on Notion](https://www.notion.so/Hybrid-POC-Smart-Contracts-18646757d3644f73bf9fdfb2e98b93eb))
109112

110113
![Imgur](https://i.imgur.com/9uwiie1.png)
111114

112-
113115
## Graph Protocol Solidity Contracts
116+
114117
1. [Graph Token Contract](./contracts/GraphToken.sol)
115118
1. [Staking / Dispute Resolution Contract](./contracts/Staking.sol)
116119
1. [Graph Name Service (GNS) Registry Contract](./contracts/GNS.sol)
@@ -119,19 +122,20 @@ This repository will contain the Solidity smart contracts needed to facilitate t
119122
1. [Governance Contract](./contracts/Governed.sol)
120123

121124
### Supporting Contracts
125+
122126
1. [MultiSig Contract](./contracts/MultiSigWallet.sol) (by Gnosis)
123127
1. [Detailed, Mintable, Burnable ERC20 Token](./contracts/openzeppelin/) (by Open Zeppelin)
124128
1. [Bonding Curve Formulas](./contracts/bancor/) (by Bancor)
125129
1. [Solidity-Bytes-Utils Library](./installed_contracts/bytes/) (by ConsenSys)
126130

127-
*[See ./contracts/README.md for full list of contracts](./contracts/)*
131+
_[See ./contracts/README.md for full list of contracts](./contracts/)_
128132

129133
## Requirement and Implementation Annotations
130-
Each contract includes docstring-like comments with requirements listed at the top of the file.
134+
135+
Each contract includes docstring-like comments with requirements listed at the top of the file.
131136

132137
Example: `@req c01 Any User can stake Graph Tokens to be included as a Curator for a given subgraphId.`
133138

134139
Explanation: The `c01` denotes a section and number for the requirement. `c` in this case stands for `curation` and later in the contract we see `@req s01` used for a `staking` requirement.
135140

136141
Farther down in the code you should see annotations for the implementation of each requirement written as `@imp c01` (and so on). This is meant to be a simple way of defining and matching requirements and their implementations.
137-

contracts/Curation.sol

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ contract Curation is Governed, BancorFormula {
8080

8181
/**
8282
* @dev Emitted when `tokens` amount were collected for `subgraphID` as part of fees
83-
* distributed by index node from the settlement of query fees on the subgraph.
83+
* distributed by indexer from the settlement of query fees on the subgraph.
8484
*/
8585
event Collected(bytes32 indexed subgraphID, uint256 tokens);
8686

@@ -161,10 +161,11 @@ contract Curation is Governed, BancorFormula {
161161
* @param _data Extra data payload
162162
* @return true if token transfer is processed
163163
*/
164-
function tokensReceived(address _from, uint256 _value, bytes calldata _data)
165-
external
166-
returns (bool)
167-
{
164+
function tokensReceived(
165+
address _from,
166+
uint256 _value,
167+
bytes calldata _data
168+
) external returns (bool) {
168169
// Make sure the token is the caller of this function
169170
require(msg.sender == address(token), "Caller is not the GRT token contract");
170171

@@ -290,10 +291,11 @@ contract Curation is Governed, BancorFormula {
290291
* @param _tokens Amount of tokens
291292
* @return Number of shares bought
292293
*/
293-
function _buyShares(address _curator, bytes32 _subgraphID, uint256 _tokens)
294-
private
295-
returns (uint256)
296-
{
294+
function _buyShares(
295+
address _curator,
296+
bytes32 _subgraphID,
297+
uint256 _tokens
298+
) private returns (uint256) {
297299
Subgraph storage subgraph = subgraphs[_subgraphID];
298300
uint256 shares = tokensToShares(_subgraphID, _tokens);
299301

@@ -314,10 +316,11 @@ contract Curation is Governed, BancorFormula {
314316
* @param _shares Amount of shares
315317
* @return Number of tokens received
316318
*/
317-
function _sellShares(address _curator, bytes32 _subgraphID, uint256 _shares)
318-
private
319-
returns (uint256)
320-
{
319+
function _sellShares(
320+
address _curator,
321+
bytes32 _subgraphID,
322+
uint256 _shares
323+
) private returns (uint256) {
321324
Subgraph storage subgraph = subgraphs[_subgraphID];
322325
uint256 tokens = sharesToTokens(_subgraphID, _shares);
323326

@@ -352,7 +355,11 @@ contract Curation is Governed, BancorFormula {
352355
* @param _curator Address of staking party
353356
* @param _tokens Amount of Graph Tokens to stake
354357
*/
355-
function _stake(address _curator, bytes32 _subgraphID, uint256 _tokens) private {
358+
function _stake(
359+
address _curator,
360+
bytes32 _subgraphID,
361+
uint256 _tokens
362+
) private {
356363
Subgraph storage subgraph = subgraphs[_subgraphID];
357364

358365
// If this subgraph hasn't been curated before then initialize the curve

contracts/DisputeManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ contract DisputeManager is Governed {
206206
* @return Amount of tokens to slash
207207
*/
208208
function getTokensToSlash(address _indexer) public view returns (uint256) {
209-
uint256 tokens = staking.getIndexNodeStakeTokens(_indexer); // slashable tokens
209+
uint256 tokens = staking.getIndexerStakeTokens(_indexer); // slashable tokens
210210
return slashingPercentage.mul(tokens).div(MAX_PPM);
211211
}
212212

0 commit comments

Comments
 (0)