|
1 |
| -## Deploying the Solidity Smart Contracts via Truffle |
| 1 | +## Deploying the Solidity Smart Contracts |
2 | 2 |
|
3 | 3 | ### Running
|
4 | 4 |
|
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. |
6 | 6 |
|
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. |
8 | 34 |
|
9 | 35 | ### Networks
|
10 | 36 |
|
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. |
12 | 38 |
|
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. |
14 | 51 |
|
15 | 52 | ### Configuration
|
16 | 53 |
|
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 |
45 | 60 | ```
|
46 | 61 |
|
| 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 | + |
47 | 140 | ### Order of deployment
|
48 | 141 |
|
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: |
50 | 143 |
|
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 |
0 commit comments