Skip to content

Commit 068abc3

Browse files
authored
build: contract deploy script using ethers (#217)
* build: custom deploy script * build: add ts linter * build: reorganize buidler config * build: load artifacts * build: update command
1 parent ed147ff commit 068abc3

31 files changed

+1537
-755
lines changed

.eslintignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
build/
22
cache/
33
coverage/
4-
node_modules/
5-
truffle.js
6-
cache/
4+
node_modules/

.eslintrc

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,13 @@
11
{
2-
"extends": ["standard", "plugin:promise/recommended"],
3-
"plugins": ["mocha-no-only", "promise"],
4-
"env": {
5-
"browser": true,
6-
"node": true,
7-
"mocha": true,
8-
"jest": true
9-
},
10-
"globals": {
11-
"artifacts": false,
12-
"contract": false,
13-
"assert": false
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 2020,
5+
"sourceType": "module"
146
},
15-
"ignorePatterns": ["./cache", "./build"],
7+
"extends": ["plugin:@typescript-eslint/recommended"],
168
"rules": {
17-
// Strict mode
18-
"strict": ["error", "global"],
19-
20-
// Code style
21-
"array-bracket-spacing": ["off"],
22-
"camelcase": ["error", { "properties": "always" }],
23-
"comma-dangle": ["error", "always-multiline"],
24-
"comma-spacing": ["error", { "before": false, "after": true }],
25-
"dot-notation": ["error", { "allowKeywords": true, "allowPattern": "" }],
26-
"eol-last": ["error", "always"],
27-
"eqeqeq": ["error", "smart"],
28-
"generator-star-spacing": ["error", "before"],
29-
"indent": ["error", 2, { "SwitchCase": 1 }],
30-
"linebreak-style": ["error", "unix"],
31-
"max-len": ["warn", 100, 2],
32-
"no-debugger": "off",
33-
"no-dupe-args": "error",
34-
"no-dupe-keys": "error",
35-
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
36-
"no-redeclare": ["error", { "builtinGlobals": true }],
37-
"no-trailing-spaces": ["error", { "skipBlankLines": false }],
38-
"no-undef": "error",
39-
"no-use-before-define": "off",
40-
"no-var": "error",
41-
"object-curly-spacing": ["error", "always"],
42-
"prefer-const": "error",
43-
"quotes": ["error", "single"],
44-
"semi": ["error", "never"],
45-
"space-before-function-paren": [
46-
"error",
47-
{
48-
"anonymous": "ignore",
49-
"named": "ignore",
50-
"asyncArrow": "ignore"
51-
}
52-
],
53-
54-
"mocha-no-only/mocha-no-only": ["error"],
55-
56-
"promise/always-return": "off",
57-
"promise/avoid-new": "off"
58-
},
59-
"parserOptions": {
60-
"ecmaVersion": 2018
9+
"prefer-const": "warn",
10+
"@typescript-eslint/no-inferrable-types": "warn",
11+
"@typescript-eslint/no-empty-function": "warn"
6112
}
6213
}

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Ignore zeppelin contracts
22
node_modules/
33

4-
# Ignore truffle stuff
4+
# Ignore build stuff
5+
cache/
56
build/
67
dist/
78

8-
# Ignore buidler stuff
9-
cache/
10-
119
# Coverage tests
1210
coverage/
1311

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Ignore zeppelin contracts
22
node_modules/
33

4-
# Ignore truffle stuff
4+
# Ignore build stuff
55
build/
6+
cache/
67

78
# Coverage tests
89
coverage/

.solcover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const skipFiles = ['bancor', 'bytes', 'abdk-libraries-solidity']
1+
const skipFiles = ['abdk-libraries-solidity', 'bancor', 'ens', 'erc1056']
22

33
module.exports = {
44
providerOptions: {

.soliumignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
node_modules
22
contracts/abdk-libraries-solidity
33
contracts/bancor
4+
contracts/ens
5+
contracts/erc1056
46
contracts/openzeppelin
5-
contracts/Migrations.sol
67
contracts/MultiSigWallet.sol
78
contracts/Staking.sol
89
contracts/connext/IndexerMultiAssetInterpreter.sol

DEPLOYMENT.md

Lines changed: 140 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,156 @@
1-
## Deploying the Solidity Smart Contracts via Truffle
1+
## Deploying the Solidity Smart Contracts
22

33
### Running
44

5-
A script in `/migrations/2_deploy_contracts.js` deploys the contracts to the specified network.
5+
A script in `./scripts/cli/cli.ts` deploys the contracts to the specified network when used with the `migrate` command.
66

7-
The script can be run with `npm run deploy`.
7+
This script accepts multiple commands that you can print using:
8+
9+
```
10+
/scripts/cli/cli.ts --help
11+
```
12+
13+
For convenience, the script can also be used as a buidler command with `buidler migrate` and it can be also run with:
14+
15+
```
16+
npm run migrate
17+
```
18+
19+
The **migrate** command will:
20+
21+
- Read contracts configuration from a file.
22+
- Parse command-line options to select which network to deploy and the wallet to use.
23+
- Check if contracts were already deployed and skip them.
24+
- Deploy the contracts and wait for each transaction to be mined.
25+
- Write an address book file with the deployed contracts data.
26+
27+
The script accepts multiple parameters that allow to override default values, print the available options with:
28+
29+
```
30+
npm run migrate -- --help
31+
```
32+
33+
NOTE: Please run `npm run build` at least once before running migrate as this command relies on artifacts produced in the compilation process.
834

935
### Networks
1036

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`.
37+
By default, `npm run migrate` will deploy the contracts to a localhost instance of a development network.
1238

13-
- `{networkName}` must exist as valid network in the `truffle.js` config file.
39+
To deploy to a different network execute:
40+
41+
```
42+
npm run migrate -- --network {networkName}
43+
44+
# Example
45+
npm run migrate -- --network kovan
46+
```
47+
48+
The network must be configured in the `builder.config.ts` as explained in https://buidler.dev/config/#networks-configuration.
49+
50+
To deploy using your own wallet add the HD Wallet Config to the `builder.config.ts` file according to https://buidler.dev/config/#hd-wallet-config.
1451

1552
### Configuration
1653

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.
18-
19-
```
20-
const TOKEN_UNIT = new BN('10').pow(new BN('18'))
21-
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-
}
54+
A configuration file called `graph.config.yml` contains the parameters needed to deploy the contracts. Please edit these params as you see fit.
55+
56+
You can use a different set of configuration options by specifying the file location in the command line:
57+
58+
```
59+
npm run migrate -- --graph-config another-graph.config.yml
4560
```
4661

62+
Rules:
63+
64+
- Under the `contracts` key every contract configuration is defined by its name.
65+
- Every key under a contract name are parameters sent in the contract constructor in the order they are declared.
66+
- YAML anchors can be used to set common values like \*governor.
67+
- A special key called `__calls` let you define a list of parameters that will be set at the end of all the contracts deployment by calling the function defined in the `fn` key.
68+
- The configuration file can set a parameter to a value read from the AddressBook by using `${{ContractName.AttributeName}}`. For example `${{GraphToken.address}}`.
69+
70+
Example:
71+
72+
```
73+
general:
74+
governor: &governor "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"
75+
nodeSignerAddress: &nodeSignerAddress "0x0000000000000000000000000000000000000000"
76+
77+
contracts:
78+
Curation:
79+
governor: *governor
80+
token: "${{GraphToken.address}}"
81+
reserveRatio: 500000
82+
minimumCurationStake: "100000000000000000000" # 100 GRT
83+
__calls:
84+
- fn: "setWithdrawalFeePercentage"
85+
withdrawalFeePercentage: 50000
86+
DisputeManager:
87+
governor: *governor
88+
arbitrator: *governor
89+
token: "${{GraphToken.address}}"
90+
staking: "${{Staking.address}}"
91+
minimumDeposit: "100000000000000000000" # 100 GRT
92+
fishermanRewardPercentage: 1000 # in basis points
93+
slashingPercentage: 1000 # in basis points
94+
EpochManager:
95+
governor: *governor
96+
lengthInBlocks: 5760 # One day in blocks
97+
GNS:
98+
governor: *governor
99+
GraphToken:
100+
governor: *governor
101+
initialSupply: "10000000000000000000000000" # 10000000 GRT
102+
RewardManager:
103+
governor: *governor
104+
Staking:
105+
governor: *governor
106+
token: "${{GraphToken.address}}"
107+
epochManager: "${{EpochManager.address}}"
108+
__calls:
109+
- fn: "setCuration"
110+
curation: "${{Curation.address}}"
111+
- fn: "setChannelDisputeEpochs"
112+
channelDisputeEpochs: 1
113+
- fn: "setMaxAllocationEpochs"
114+
maxAllocationEpochs: 5
115+
- fn: "setThawingPeriod"
116+
thawingPeriod: 20 # in blocks
117+
MinimumViableMultisig:
118+
node: *nodeSignerAddress
119+
staking: "${{Staking.address}}"
120+
CTDT: "${{IndexerCTDT.address}}"
121+
singleAssetInterpreter: "${{IndexerSingleAssetInterpreter.address}}"
122+
multiAssetInterpreter: "${{IndexerMultiAssetInterpreter.address}}"
123+
withdrawInterpreter: "${{IndexerWithdrawInterpreter.address}}"
124+
```
125+
126+
### Address book
127+
128+
After running the migrate script it will print debugging information on the console and the resulting contract information will be saved on the `addresses.json` file.
129+
130+
The upmost key of that file is the **chainID**. This allows to accommodate the deployment information of multiple networks in the same address book.
131+
132+
For each contract deployed, the address book will contain:
133+
134+
- Contract address.
135+
- Constructor arguments.
136+
- Creation code hash.
137+
- Runtime code hash.
138+
- Transaction hash of the deployment.
139+
47140
### Order of deployment
48141

49-
Due to some of the contracts require the address of other contracts, they are deployed in the following order:
142+
Some contracts require the address from previously deployed contracts. For that reason, the order of deployment is as below:
50143

51-
1. GraphToken
52-
2. EpochManager
53-
3. Curation
54-
4. Staking
55-
5. RewardsManager
56-
6. DisputeManager
57-
7. ServiceRegistry
58-
8. GNS
144+
- EpochManager
145+
- GNS
146+
- GraphToken
147+
- ServiceRegistry
148+
- Curation
149+
- RewardManager
150+
- Staking
151+
- DisputeManager
152+
- IndexerCTDT
153+
- IndexerSingleAssetInterpreter
154+
- IndexerMultiAssetInterpreter
155+
- IndexerWithdrawInterpreter
156+
- MinimumViableMultisig

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ latest subgraph.
1818

1919
We want to also run some test scripts to populate data each time new contracts are deployed.
2020

21-
You will need two files to deploy anything and run `truffle`, they are `.privkey.txt` and
22-
`.infurakey.txt`. Privkey is a 12 word mneumonic, you should grab you 12 words from metamask, so
23-
that your metamask keys will work in the browser with what you deployed as a governor. The infura
24-
key is just the key you get from the infura website that lets you query up to 100,000 queries a day
25-
for free.
21+
See [DEPLOYMENT.md](./DEPLOYMENT.md) for instructions on deploying the contracts to the blockchain.
2622

2723
### Current Contract Addresses
2824

@@ -61,7 +57,7 @@ cargo run -p graph-node --release -- \
6157

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

6763
#### Ropsten
@@ -93,10 +89,10 @@ on ropsten, so we can better test.
9389
1. Install Node.js `v10.15.1`.
9490
2. Run `npm install` at project root directory.
9591
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.
92+
- Configure to run on port `8545` or edit `buidler.config.ts` to change the port used by Buidler.
9793
4. Build
9894
- `npm run build` (compile contracts, flatten code, export ABIs and create Typescript bindings)
99-
- `npm run deploy` (deploy contracts to local blockchain emulator)
95+
- `npm run migrate` (deploy contracts to local blockchain emulator)
10096
- `npm run test` (runs tests)
10197
5. See [DEPLOYMENT.md](./DEPLOYMENT.md) for instructions on deploying the contracts to the blockchain.
10298

0 commit comments

Comments
 (0)