Skip to content

Commit d59900d

Browse files
authored
build: use buidler + waffle + typescript (#211)
* refactor: use buidler+waffle * refactor: curation test to ts * refactor: serviceRegistry tests to ts * refactor: graphtokens tests to ts * refactor: epochManager tests to ts * refactor: update disputeManager to ts and update typechain * refactor: gns tests to ts * refactor: staking tests to ts * refactor: fix curation tests in ts * build: build script improvements * build: add truffle only for deployments, update README
1 parent e9f5b7b commit d59900d

30 files changed

+23835
-9963
lines changed

.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"globals": {
1111
"artifacts": false,
1212
"contract": false,
13-
"assert": false,
14-
"web3": false
13+
"assert": false
1514
},
1615
"rules": {
1716
// Strict mode

.prettierrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
"explicitTypes": "always"
1414
}
1515
},
16+
{
17+
"files": "*.ts",
18+
"options": {
19+
"semi": false,
20+
"trailingComma": "all",
21+
"tabWidth": 2,
22+
"singleQuote": true,
23+
"explicitTypes": "always"
24+
}
25+
},
1626
{
1727
"files": "*.sol",
1828
"options": {

.solcover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const skipFiles = ['bancor', 'bytes']
1+
const skipFiles = ['bancor', 'bytes', 'abdk-libraries-solidity']
22

33
module.exports = {
44
providerOptions: {

DEPLOYMENT.md

+50-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
11
## Deploying the Solidity Smart Contracts via Truffle
22

3-
`/migrations/2_deploy_contracts.js` contains the parameters needed to deploy the contracts. Please edit these params as you see fit.
3+
### Running
4+
5+
A script in `/migrations/2_deploy_contracts.js` deploys the contracts to the specified network.
6+
7+
The script can be run with `npm run deploy`.
8+
9+
### Networks
10+
11+
By default, `npm run deploy` will deploy the contracts to the development network. To deploy to a different network run `npm run deploy -- --network {networkName}`, for example `npm run deploy -- --network ropsten`.
12+
13+
- `{networkName}` must exist as valid network in the `truffle.js` config file.
14+
15+
### Configuration
16+
17+
A configuration file in the `/migrations/deploy.config.js` contains the parameters needed to deploy the contracts. Please edit these params as you see fit.
418

519
```
6-
const initialSupply = 1000000, // total supply of Graph Tokens at time of deployment
7-
minimumCurationStakingAmount = 100, // minimum amount allowed to be staked by Market Curators
8-
defaultReserveRatio = 500000, // reserve ratio (percent as PPM)
9-
minimumIndexingStakingAmount = 100, // minimum amount allowed to be staked by Indexing Nodes
10-
maximumIndexers = 10, // maximum number of Indexing Nodes staked higher than stake to consider
11-
slashingPercentage = 10, // percent of stake to slash in successful dispute
12-
thawingPeriod = 60 * 60 * 24 * 7, // amount of seconds to wait until indexer can finish stake logout
13-
multiSigRequiredVote = 0, // votes required (setting a required amount here will override a formula used later)
14-
multiSigOwners = [] // add addresses of the owners of the multisig contract here
15-
```
20+
const TOKEN_UNIT = new BN('10').pow(new BN('18'))
1621
17-
The `MultiSigWallet` contract is deployed first in order to retain its address for use in deploying the remaining contracts.
22+
{
23+
curation: {
24+
reserveRatio: 500000,
25+
minimumCurationStake: new BN('100').mul(TOKEN_UNIT),
26+
withdrawalFeePercentage: 50000,
27+
},
28+
dispute: {
29+
minimumDeposit: new BN('100').mul(TOKEN_UNIT),
30+
fishermanRewardPercentage: 1000, // in basis points
31+
slashingPercentage: 1000, // in basis points
32+
},
33+
epochs: {
34+
lengthInBlocks: (24 * 60 * 60) / 15, // One day in blocks
35+
},
36+
staking: {
37+
channelDisputeEpochs: 1,
38+
maxAllocationEpochs: 5,
39+
thawingPeriod: 20, // in blocks
40+
},
41+
token: {
42+
initialSupply: new BN('10000000').mul(TOKEN_UNIT),
43+
},
44+
}
45+
```
1846

19-
The `Staking` contract requires both the address of the `MultiSigWallet` and the `GraphToken`.
47+
### Order of deployment
2048

21-
The order of deployment is as follows:
49+
Due to some of the contracts require the address of other contracts, they are deployed in the following order:
2250

23-
1. Deploy MultiSigWallet contract
24-
2. Deploy GraphToken Contract
25-
3. Deploy all remaining contracts with the address of the MultiSigWallet, and in the case of the `Staking` contract, use the `GraphToken` address retained previously.
51+
1. GraphToken
52+
2. EpochManager
53+
3. Curation
54+
4. Staking
55+
5. RewardsManager
56+
6. DisputeManager
57+
7. ServiceRegistry
58+
8. GNS

README.md

+23-38
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ change whenever there are updates to the contract, and we need to redeploy. This
1616
done in sync with deploying a new subgraph. The new GNS should point `thegraph` domain to the
1717
latest subgraph.
1818

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.
19+
We want to also run some test scripts to populate data each time new contracts are deployed.
2220

2321
You will need two files to deploy anything and run `truffle`, they are `.privkey.txt` and
2422
`.infurakey.txt`. Privkey is a 12 word mneumonic, you should grab you 12 words from metamask, so
@@ -72,14 +70,14 @@ which will allow the subgraph to store data.
7270
to create and deploy subgraphs. It can be found [here](https://staging.thegraph.com/explorer/subgraph/graphprotocol/explorer-dapp)
7371
]. The subgraph is already created, so we will only mention how to update the subgraph here.
7472

75-
1. Deploy new contracts to Ropsten with `truffle deploy --network ropsten`. Truffle stores the
73+
1. Deploy new contracts to Ropsten with `npm run deploy -- --network ropsten`. Truffle stores the
7674
addresses for networks, so if you are trying to re-deploy you may have to run
77-
`truffle networks —clean`, and then deploy
75+
`truffle networks —clean`, and then deploy.
7876
2. Get the new contract addresses from the deployment. They are logged in the terminal output from
7977
deploying. Put these contract addresses into the subgraph manifest
8078
3. Make sure you are a member of `graphprotocol` for the staging explorer application
8179
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
80+
`graph auth https://api.thegraph.com/deploy/ <ACCESS_TOKEN>`. You can get it from the dashboard in the
8381
UI, just pick `graphprotocol` instead of your own account, and you will see the token.
8482
5. Then in the `graph-network-subgraph` repository, just run `yarn deploy` to update a new version
8583
6. You will also have to update information in the `graph-explorer-dapp` repo. You must update
@@ -92,18 +90,15 @@ on ropsten, so we can better test.
9290

9391
## Installation &amp; Deployment of Contracts
9492

95-
1. Install Node.js `^11.0.0`
96-
1. Run `npm install` at project root directory
97-
1. Install and run `testrpc`, `ganache-cli`, or similar blockchain emulator
98-
- Configure to run on port `8545` or edit `truffle.js` to change the port used by Truffle
99-
1. Install Truffle 5.0.0
100-
- `npm install -g truffle`
101-
1. Truffle project commands
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)
106-
1. See [DEPLOYMENT.md](./DEPLOYMENT.md) for instructions on deploying the contracts to the blockchain.
93+
1. Install Node.js `v10.15.1`.
94+
2. Run `npm install` at project root directory.
95+
3. 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.
97+
4. Build
98+
- `npm run build` (compile contracts, flatten code, export ABIs and create Typescript bindings)
99+
- `npm run deploy` (deploy contracts to local blockchain emulator)
100+
- `npm run test` (runs tests)
101+
5. See [DEPLOYMENT.md](./DEPLOYMENT.md) for instructions on deploying the contracts to the blockchain.
107102

108103
## Abstract
109104

@@ -112,30 +107,20 @@ This repository will contain the Solidity smart contracts needed to facilitate t
112107

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

115-
## Graph Protocol Solidity Contracts
110+
## Graph Protocol Contracts
116111

117-
1. [Graph Token Contract](./contracts/GraphToken.sol)
118-
1. [Staking / Dispute Resolution Contract](./contracts/Staking.sol)
119-
1. [Graph Name Service (GNS) Registry Contract](./contracts/GNS.sol)
120-
1. [Rewards Manager Contract](./contracts/RewardsManager.sol)
121-
1. [Service Registry Contract](./contracts/ServiceRegistry.sol)
122-
1. [Governance Contract](./contracts/Governed.sol)
112+
1. [Graph Token](./contracts/GraphToken.sol)
113+
2. [Staking](./contracts/Staking.sol)
114+
3. [Dispute Resolution](./contracts/DisputeManager.sol)
115+
4. [Graph Name Service (GNS)](./contracts/GNS.sol)
116+
5. [Rewards Manager](./contracts/RewardsManager.sol)
117+
6. [Service Registry](./contracts/ServiceRegistry.sol)
118+
7. [Governance](./contracts/Governed.sol)
123119

124120
### Supporting Contracts
125121

126122
1. [MultiSig Contract](./contracts/MultiSigWallet.sol) (by Gnosis)
127-
1. [Detailed, Mintable, Burnable ERC20 Token](./contracts/openzeppelin/) (by Open Zeppelin)
128-
1. [Bonding Curve Formulas](./contracts/bancor/) (by Bancor)
129-
1. [Solidity-Bytes-Utils Library](./installed_contracts/bytes/) (by ConsenSys)
123+
2. [Detailed, Mintable, Burnable ERC20 Token](./contracts/openzeppelin/) (by Open Zeppelin)
124+
3. [Bonding Curve Formulas](./contracts/bancor/) (by Bancor)
130125

131126
_[See ./contracts/README.md for full list of contracts](./contracts/)_
132-
133-
## Requirement and Implementation Annotations
134-
135-
Each contract includes docstring-like comments with requirements listed at the top of the file.
136-
137-
Example: `@req c01 Any User can stake Graph Tokens to be included as a Curator for a given subgraphId.`
138-
139-
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.
140-
141-
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.

buidler.config.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { BuidlerConfig, task, usePlugin } from '@nomiclabs/buidler/config'
2+
3+
usePlugin('@nomiclabs/buidler-waffle')
4+
usePlugin('solidity-coverage')
5+
6+
// This is a sample Buidler task. To learn how to create your own go to
7+
// https://buidler.dev/guides/create-task.html
8+
task('accounts', 'Prints the list of accounts', async (taskArgs, bre) => {
9+
const accounts = await bre.ethers.getSigners()
10+
11+
for (const account of accounts) {
12+
console.log(await account.getAddress())
13+
}
14+
})
15+
16+
// You have to export an object to set up your config
17+
// This object can have the following optional entries:
18+
// defaultNetwork, networks, solc, and paths.
19+
// Go to https://buidler.dev/config/ to learn more
20+
const config: BuidlerConfig = {
21+
paths: {
22+
sources: './contracts',
23+
tests: './test',
24+
artifacts: './build/contracts',
25+
},
26+
solc: {
27+
version: '0.6.4',
28+
optimizer: {
29+
enabled: true,
30+
runs: 500,
31+
},
32+
},
33+
defaultNetwork: 'buidlerevm',
34+
networks: {
35+
buidlerevm: {
36+
chainId: 31337,
37+
loggingEnabled: false,
38+
gas: 'auto',
39+
gasPrice: 'auto',
40+
blockGasLimit: 9500000,
41+
},
42+
ganache: {
43+
chainId: 1337,
44+
url: 'http://localhost:8545',
45+
},
46+
},
47+
}
48+
49+
export default config

0 commit comments

Comments
 (0)