Skip to content

Commit a322fe1

Browse files
committed
feat: dev tooling to run entire stack locally, removal of depcheck
1 parent 5ff3925 commit a322fe1

27 files changed

+789
-529
lines changed

.husky/pre-commit

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn lint-staged \
5-
&& yarn depcheck
4+
yarn lint-staged

README.md

+131-22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@
2727

2828
---
2929

30+
## Deployments
31+
32+
##### ⛓️ [Contracts addresses](contracts/README.md#deployed-addresses)
33+
34+
##### 🗃️ [Subgraph endpoints](subgraph/README.md#deployments)
35+
36+
##### ⚖️ [Web frontend](https://app.netlify.com/sites/kleros-v2/deploys)
37+
38+
## Content
39+
40+
| Package | Description |
41+
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
42+
| **[bots](/bots)** | Automation of the on-chain upkeep of the smart contracts. Anyone willing to spend some gas may run these bots and contribute to the upkeep operations. |
43+
| **[bot-pinner](/bot-pinner)** | Replication and pinning of the IPFS content produced by the court, such as the pieces of evidence submitted in a case. |
44+
| **[contracts](/contracts)** | Smart contracts of the arbitration protocol. |
45+
| **[evidence-display](/evidence-display)** | display interface that should be used to render the evidence for arbitrators, as described by [ERC-1497: Evidence Standard](https://github.com/ethereum/EIPs/issues/1497). |
46+
| **[dynamic-script](/dynamic-script)** | allows fetching the dynamic content for the arbitration, as described by [ERC-1497: Evidence Standard](https://github.com/ethereum/EIPs/issues/1497). |
47+
| **[subgraph](/subgraph)** | The indexing layer. |
48+
| **[web](/web)** | The court frontend intended for the jurors and parties in a dispute. |
49+
3050
## Toolchain:
3151

3252
- Solidity 0.8
@@ -39,19 +59,31 @@
3959

4060
## Contributing
4161

42-
### Pre-Requisites
62+
### Prerequisites
4363

4464
- Install NodeJS 16:
45-
- on Red Hat Linux: `dnf module install nodejs:16`
65+
- on Red Hat Linux: `sudo dnf module install nodejs:16`
4666
- on Ubuntu Linux: `sudo snap install node --classic`
4767
- on MacOS via [brew](https://brew.sh/): `brew install node`
48-
- on Windows via [Chocolatey](https://chocolatey.org/): `choco install nvs`
4968
- Install Yarn v1.22: `npm install -g yarn`
50-
- [Upgrade](https://yarnpkg.com/getting-started/install#updating-to-the-latest-versions) Yarn to v3: `yarn set version berry`
69+
- Then [upgrade](https://yarnpkg.com/getting-started/install#updating-to-the-latest-versions) Yarn to v3: `yarn set version berry`
70+
- Install Volta.sh: `curl https://get.volta.sh | bash`
71+
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) to run the local graph node.
72+
- Shell utilities: [jq](https://stedolan.github.io/jq/), [yq](https://mikefarah.gitbook.io/yq/)
73+
- on Red Hat Linux: `sudo dnf install jq yq`
74+
- on Ubuntu Linux: `sudo snap install jq yq`
75+
- on MacOS via [brew](https://brew.sh/): `brew install jq yq`
76+
77+
### Install the dependencies
5178

52-
### Optional Steps
79+
```bash
80+
$ yarn install
81+
82+
# Foundry libraries
83+
$ git submodule update --init --recursive -j 4
84+
```
5385

54-
#### [Hardhat CLI auto-completion](https://hardhat.org/guides/shorthand.html)
86+
### [Hardhat CLI auto-completion](https://hardhat.org/guides/shorthand.html) (optional)
5587

5688
```bash
5789
$ npm i -g hardhat-shorthand
@@ -60,32 +92,109 @@ $ hardhat-completion install
6092
✔ Which Shell do you use ? · bash
6193
✔ We will install completion to ~/.bashrc, is it ok ? (y/N) · true
6294

63-
$ . ~/.bashrc
95+
$ exec bash
6496
```
6597

66-
### Getting Started
98+
### Full Stack Local Deployment
6799

68-
#### Install the dependencies
100+
Run the commands below from the top-level folder. Alternatively, it is possible to `cd` into the relevant package first and then call yarn without `workspace @kleros/xxxx`.
101+
102+
#### Shortcut using tmux
103+
104+
If you have **[tmux](https://github.com/tmux/tmux/wiki)** installed, you can get started quickly with a single command.
69105

70106
```bash
71-
$ npm install -g depcheck
107+
$ yarn local-stack
108+
```
72109

73-
# sets up yarn version
74-
$ yarn prepare
110+
![terminal](/docs/local-stack-2.png)
75111

76-
$ yarn install
112+
#### Shell 1 - Local RPC with Contracts Deployed
113+
114+
```bash
115+
$ yarn workspace @kleros/kleros-v2-contracts start-local
116+
...
117+
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/
118+
119+
```
120+
121+
⏳ Wait until deployment is complete.
122+
123+
#### Shell 2 - Local Graph Node
124+
125+
```bash
126+
$ yarn workspace @kleros/kleros-v2-subgraph start-local-indexer
127+
...
128+
graph-node-graph-node-1 | INFO Successfully connected to IPFS node at: http://ipfs:5001/
129+
graph-node-graph-node-1 | INFO Pool successfully connected to Postgres, pool: main, shard: primary, component: Store
130+
...
131+
graph-node-graph-node-1 | INFO Connected to Ethereum, capabilities: archive, traces, network_version: 31337, provider: mainnet-rpc-0
132+
```
133+
134+
⏳ Wait until the graph service is ready.
135+
136+
#### Shell 3 - Subgraph Rebuild and Local Deploy
137+
138+
:warning: This step modifies `subgraph.yaml` and creates a backup file. See further down on how to restore it.
139+
140+
```bash
141+
$ yarn workspace @kleros/kleros-v2-subgraph rebuild-deploy-local
142+
...
143+
✔ Upload subgraph to IPFS
144+
145+
Build completed: QmZVaZQ9qcXPia9YnFEKk7D1dEDHbfyDiJi1sqJ6E1NydB
146+
147+
Deployed to http://localhost:8000/subgraphs/name/kleros/kleros-v2-core-local/graphql
148+
149+
Subgraph endpoints:
150+
Queries (HTTP): http://localhost:8000/subgraphs/name/kleros/kleros-v2-core-local
151+
```
152+
153+
#### Shell 4 - Frontend Pointing to the Local Subgraph
154+
155+
```bash
156+
$ yarn workspace @kleros/kleros-v2-web start-local
157+
158+
Server running at http://localhost:1234
159+
✨ Built in 2.35s
77160
```
78161

79-
## Repo Structure
162+
### Redeploying
163+
164+
```bash
165+
# Contracts
166+
$ yarn workspace @kleros/kleros-v2-contracts deploy-local
167+
168+
# Subgraph
169+
$ yarn workspace @kleros/kleros-v2-subgraph rebuild-deploy-local
170+
171+
```
172+
173+
### Simulating Arbitration Activity
174+
175+
```bash
176+
$ yarn workspace @kleros/kleros-v2-contracts simulate-local
177+
178+
```
179+
180+
### Stopping
181+
182+
Just press `Ctrl + c` in each terminal.
183+
184+
#### Docker containers and data removal
185+
186+
`yarn workspace @kleros/kleros-v2-subgraph stop-local-indexer`
187+
188+
#### Restoring subgraph.yaml
189+
190+
##### From a backup file
191+
192+
Every versions were saved as `subgraph.yaml.bak.<timestamp>`.
80193

81-
Each directory at the root of this repository contains code for each individual part that enables this integration:
194+
##### Based on the ArbitrumGoerli deployment artifacts
82195

83-
- **`bots/`**: service to automate some steps of the flow which otherwise would required manual intervention from users.
84-
- **Notice:** while this is a centralized service, it exists only for convenience. Anyone can fulfill the role of the bots if they wish to do so.
85-
- **`contracts/`**: Smart contracts running the arbitration system [Learn more](contracts/README.md).
86-
- **`dynamic-script/`**: allows fetching the dynamic content for the arbitration, as described by [ERC-1497: Evidence Standard](https://github.com/ethereum/EIPs/issues/1497).
87-
- **`evidence-display/`**: display interface that should be used to render the evidence for arbitrators, as described by [ERC-1497: Evidence Standard](https://github.com/ethereum/EIPs/issues/1497).
196+
`yarn workspace @kleros/kleros-v2-subgraph update`
88197

89-
## Deployment
198+
##### Based on the last commit
90199

91-
See [contracts/README.md](contracts/README.md#deployed-addresses).
200+
`git restore subgraph.yaml`

contracts/deploy/00-home-chain-arbitrable.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2929
};
3030

3131
deployArbitration.tags = ["HomeArbitrable"];
32+
deployArbitration.dependencies = ["Arbitration"];
3233
deployArbitration.skip = async ({ getChainId }) => {
3334
const chainId = Number(await getChainId());
3435
return !HomeChains[chainId];

contracts/foundry.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ libs = ['../node_modules', 'lib']
77
[rpc_endpoints]
88
arbitrumGoerli = "https://goerli-rollup.arbitrum.io/rpc"
99
arbitrum = "https://arb1.arbitrum.io/rpc"
10-
goerli = "https://goerli.infura.io/v3/${process.env.INFURA_API_KEY}"
11-
mainnet = "https://mainnet.infura.io/v3/${process.env.INFURA_API_KEY}"
10+
goerli = "https://goerli.infura.io/v3/${INFURA_API_KEY}"
11+
mainnet = "https://mainnet.infura.io/v3/${INFURA_API_KEY}"
1212
chiado = "https://rpc.chiadochain.net"
1313
gnosischain = "https://xdai-rpc.gateway.pokt.network"
1414

contracts/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
"clean": "hardhat clean",
2020
"check": "solhint src/**/*.sol",
2121
"test": "TS_NODE_TRANSPILE_ONLY=1 hardhat test",
22+
"start": "hardhat node",
23+
"start-local": "hardhat node --tags Arbitration,HomeArbitrable",
2224
"deploy": "hardhat deploy",
23-
"deploy:staging": "run-s \"deploy --network rinkeby {@}\" \"deploy --network arbitrumRinkeby {@}\" --",
25+
"deploy-local": "hardhat deploy --tags Arbitration,HomeArbitrable --network localhost",
26+
"simulate": "hardhat simulate:all",
27+
"simulate-local": "hardhat simulate:all --network localhost",
2428
"etherscan-verify": "hardhat etherscan-verify",
2529
"size": "hardhat size-contracts --no-compile",
2630
"watch": "hardhat watch",
@@ -47,7 +51,6 @@
4751
"ethereum-waffle": "^3.4.4",
4852
"ethereumjs-util": "^7.1.4",
4953
"ethers": "^5.6.7",
50-
"follow-redirects": "^1.15.0",
5154
"hardhat": "^2.11.2",
5255
"hardhat-contract-sizer": "^2.6.1",
5356
"hardhat-deploy": "^0.11.18",
@@ -57,10 +60,7 @@
5760
"hardhat-gas-reporter": "^1.0.9",
5861
"hardhat-tracer": "^1.1.1",
5962
"hardhat-watcher": "^2.5.0",
60-
"json-schema": "^0.4.0",
61-
"mocha": "^10.1.0",
6263
"node-fetch": "^3.3.0",
63-
"npm-run-all": "^4.1.5",
6464
"shelljs": "^0.8.5",
6565
"solhint": "^3.3.7",
6666
"solidity-coverage": "^0.8.2",

contracts/scripts/docPreprocess.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44

contracts/scripts/generateDeploymentArtifact.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44
source $SCRIPT_DIR/../.env
55

66
if [[ $# < 2 ]]
77
then
8-
echo "usage: $(basename $0) <network> <address>"
8+
echo "usage: $(basename $0) network address"
99
exit 1
1010
fi
1111

contracts/scripts/generateDeploymentsMarkdown.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44

docs/local-stack-2.png

980 KB
Loading

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"contracts",
2222
"dynamic-script",
2323
"evidence-display",
24-
"klerosts",
24+
"kleros-ts",
2525
"subgraph",
2626
"web"
2727
],
@@ -34,7 +34,6 @@
3434
"@commitlint/cli": "^17.2.0",
3535
"@commitlint/config-conventional": "^17.2.0",
3636
"conventional-changelog-cli": "^2.1.1",
37-
"depcheck": "^1.4.2",
3837
"eslint": "^8.27.0",
3938
"eslint-config-prettier": "^8.3.0",
4039
"eslint-config-standard": "^16.0.3",
@@ -65,9 +64,10 @@
6564
"eth-sig-util@npm:^1.4.2": "3.0.0"
6665
},
6766
"scripts": {
68-
"depcheck": "depcheck .",
67+
"check-prerequisites": "scripts/check-prerequisites.sh",
68+
"local-stack": "scripts/tmux-local-stack.sh",
6969
"changelog": "conventional-changelog --infile CHANGELOG.md --same-file --release-count 0 && prettier --write CHANGELOG.md",
70-
"postinstall": "husky install",
70+
"postinstall": "yarn check-prerequisites; husky install",
7171
"reinstall": "YARN_CHECKSUM_BEHAVIOR=update yarn install --no-immutable"
7272
}
7373
}

scripts/check-prerequisites.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
status=0
4+
5+
function require() #cmd
6+
{
7+
local cmd=$1
8+
if [ ! -x "$(command -v $cmd)" ]; then
9+
>&2 echo "error: $cmd not installed"
10+
status=1
11+
fi
12+
}
13+
14+
require docker
15+
require docker-compose
16+
require jq
17+
require yq
18+
require volta
19+
20+
exit $status

scripts/tmux-local-stack.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
session="local-stack"
4+
5+
tmux has-session -t $session 2>/dev/null
6+
if [ $? != 0 ]; then
7+
# Session does not exist, set it up your session
8+
tmux new-session -d -s $session -x $(tput cols) -y $(tput lines)
9+
10+
tmux set-window-option automatic-rename off
11+
tmux set pane-border-status top
12+
tmux set pane-border-format " #{pane_index} - #{pane_title} "
13+
14+
tmux split-window -h
15+
tmux split-window -v
16+
tmux select-pane -t 1
17+
tmux split-window -v
18+
19+
tmux select-pane -t 1 -T "HARDHAT RPC"
20+
tmux send-keys -t 1 'yarn workspace @kleros/kleros-v2-contracts start-local'
21+
22+
tmux select-pane -t 2 -T "GRAPH NODE"
23+
tmux send-keys -t 2 'yarn workspace @kleros/kleros-v2-subgraph start-local-indexer'
24+
25+
tmux select-pane -t 3 -T "SUBGRAPH DEPLOY"
26+
tmux send-keys -t 3 'yarn workspace @kleros/kleros-v2-subgraph rebuild-deploy-local'
27+
28+
tmux select-pane -t 4 -T "WEB"
29+
tmux send-keys -t 4 'yarn workspace @kleros/kleros-v2-web start-local'
30+
fi
31+
32+
tmux attach-session -t $session
33+

services/graph-node/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data

0 commit comments

Comments
 (0)