Skip to content

Commit

Permalink
Refactor oracle for multichain support (#53)
Browse files Browse the repository at this point in the history
* Refactor oracle for multichain support

* Multichain compose

* Update

* Fix ipfs profiles

* Update eth2 nodes in envs

* Update ETH2 aliases

* Fix missing parameters

Co-authored-by: Andrey Pronin <[email protected]>
  • Loading branch information
tsudmi and unxnn authored Feb 15, 2022
1 parent 5d2077b commit 31ae985
Show file tree
Hide file tree
Showing 38 changed files with 1,631 additions and 797 deletions.
89 changes: 22 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Oracle

Oracles are responsible for voting on the new ETH2 rewards for the StakeWise sETH2 tokens holders and calculating Merkle
Oracles are responsible for voting on the new rewards for the StakeWise staked tokens holders and calculating Merkle
root and proofs for the additional token distributions through the
[Merkle Distributor](https://github.com/stakewise/contracts/blob/master/contracts/merkles/MerkleDistributor.sol)
contract.
Expand Down Expand Up @@ -31,57 +31,37 @@ supports [ETH2 Beacon Node API specification](https://ethereum.github.io/beacon-
- [Teku](https://launchpad.ethereum.org/en/teku)
- [Infura](https://infura.io/docs/eth2) (hosted)

### Usage
### Oracle Usage

1. Move to `deploy` directory
1. Move to `deploy/<network>` directory

```shell script
cd deploy
cd deploy/mainnet
```

2. Create an edit environment file (see `Oracle Settings` below)
2. Create an edit environment file

```shell script
cp .env.example .env
```

3. Enable `pushover` alerts in `configs/alertmanager.yml`
3. Enable `pushover` alerts in `deploy/configs/alertmanager.yml`

4. Run with [docker-compose](https://docs.docker.com/compose/)
1. Register an account on [pushover](https://pushover.net/).
2. Create an [Application/API Token](https://pushover.net/apps/build).
3. Add `User Key` and `API Token` to `deploy/configs/alertmanager.yml` file.

4. Run with [docker-compose](https://docs.docker.com/compose/). The docker-compose version must be **v1.27.0+**.

```shell script
docker-compose -f docker-compose.yml up -d
COMPOSE_PROFILES=lighthouse docker-compose up -d
```

### Oracle Settings

| Variable | Description | Required | Default |
|-------------------------|------------------------------------------------------------------------------------|----------|-------------------------------------------------------------------------|
| NETWORK | The network that the oracle is currently operating on. Choices are goerli, mainnet | No | mainnet |
| ENABLE_HEALTH_SERVER | Defines whether to enable health server | No | True |
| HEALTH_SERVER_PORT | The port where the health server will run | No | 8080 |
| HEALTH_SERVER_HOST | The host where the health server will run | No | 127.0.0.1 |
| IPFS_PIN_ENDPOINTS | The IPFS endpoint where the rewards will be uploaded | No | /dns/ipfs.infura.io/tcp/5001/https |
| IPFS_FETCH_ENDPOINTS | The IPFS endpoints from where the rewards will be fetched | No | https://gateway.pinata.cloud,http://cloudflare-ipfs.com,https://ipfs.io |
| IPFS_PINATA_API_KEY | The Pinata API key for uploading reward proofs for the redundancy | No | - |
| IPFS_PINATA_SECRET_KEY | The Pinata Secret key for uploading reward proofs for the redundancy | No | - |
| ETH2_ENDPOINT | The ETH2 node endpoint | No | http://localhost:3501 |
| ETH2_CLIENT | The ETH2 client used. Choices are prysm, lighthouse, teku. | No | prysm |
| ORACLE_PRIVATE_KEY | The ETH1 private key of the oracle | Yes | - |
| AWS_ACCESS_KEY_ID | The AWS access key used to make the oracle vote public | Yes | - |
| AWS_SECRET_ACCESS_KEY | The AWS secret access key used to make the oracle vote public | Yes | - |
| STAKEWISE_SUBGRAPH_URL | The StakeWise subgraph URL | No | https://api.thegraph.com/subgraphs/name/stakewise/stakewise-mainnet |
| UNISWAP_V3_SUBGRAPH_URL | The Uniswap V3 subgraph URL | No | https://api.thegraph.com/subgraphs/name/stakewise/uniswap-v3-mainnet |
| RARI_FUSE_SUBGRAPH_URL | Rari Capital Fuse subgraph URL | No | https://api.thegraph.com/subgraphs/name/stakewise/rari-fuse-mainnet |
| ETHEREUM_SUBGRAPH_URL | The Ethereum subgraph URL | No | https://api.thegraph.com/subgraphs/name/stakewise/ethereum-mainnet |
| ORACLE_PROCESS_INTERVAL | How long to wait before processing again (in seconds) | No | 180 |
| CONFIRMATION_BLOCKS | The required number of confirmation blocks used to fetch the data | No | 15 |
| LOG_LEVEL | The log level of the oracle | No | INFO |

## Keeper

Keeper is an oracle that aggregates votes that were submitted by all the oracles and submits the update transaction.
The keeper does not require any additional role, and can be executed by any of the oracles.
It helps save the gas cost and stability as there is no need for every oracle to submit vote.

### Dependencies

Expand All @@ -91,49 +71,24 @@ The ETH1 node is used to submit the transactions on chain. Any of the ETH1 clien

- [Go-ethereum](https://github.com/ethereum/go-ethereum)
- [OpenEthereum](https://github.com/openethereum/openethereum)
- [Nethermind](https://github.com/NethermindEth/nethermind)
- [Infura](https://infura.io/docs/eth2) (hosted)
- [Alchemy](https://www.alchemy.com/) (hosted)

### Usage

1. Move to `deploy` directory

```shell script
cd deploy
```
### Keeper Usage

2. Create an edit environment file (see `Keeper Settings` below)
1. Make sure keeper has enough balance to submit the transactions

```shell script
cp .env.example .env
```
2. Go through the [oracle usage](#oracle-usage) steps above

3. Enable `pushover` alerts in `configs/alertmanager.yml`
3. Configure keeper section in the `deploy/<network>/.env` file

4. Uncomment `keeper` sections in the following files:
* configs/rules.yml
* configs/prometheus.yml
* configs/rules.yml
* docker-compose.yml
* `deploy/configs/prometheus.yml`
* `deploy/configs/rules.yml`

5. Run with [docker-compose](https://docs.docker.com/compose/)
5. Run with [docker-compose](https://docs.docker.com/compose/). The docker-compose version must be **v1.27.0+**.

```shell script
docker-compose -f docker-compose.yml up -d
COMPOSE_PROFILES=lighthouse,keeper docker-compose up -d
```

### Keeper Settings

| Variable | Description | Required | Default |
|-------------------------|------------------------------------------------------------------------------------|----------|-----------|
| NETWORK | The network that the keeper is currently operating on. Choices are goerli, mainnet | No | mainnet |
| WEB3_ENDPOINT | The endpoint of the ETH1 node. | Yes | - |
| MAX_FEE_PER_GAS_GWEI | The max fee per gas keeper is willing to pay. Specified in GWEI. | No | 150 |
| ENABLE_HEALTH_SERVER | Defines whether to enable health server | No | True |
| HEALTH_SERVER_PORT | The port where the health server will run | No | 8080 |
| HEALTH_SERVER_HOST | The host where the health server will run | No | 127.0.0.1 |
| ORACLE_PRIVATE_KEY | The ETH1 private key of the oracle | Yes | - |
| KEEPER_PROCESS_INTERVAL | How long to wait before processing again (in seconds) | No | 180 |
| CONFIRMATION_BLOCKS | The required number of confirmation blocks used to fetch the data | No | 15 |
| KEEPER_MIN_BALANCE_WEI | The minimum balance keeper must have for votes submission | No | 0.1 ETH |
| LOG_LEVEL | The log level of the keeper | No | INFO |
43 changes: 0 additions & 43 deletions deploy/.env.example

This file was deleted.

22 changes: 0 additions & 22 deletions deploy/README.md

This file was deleted.

Binary file added deploy/configs/genesis.ssz
Binary file not shown.
79 changes: 79 additions & 0 deletions deploy/gnosis/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
##########
# Oracle #
##########
LOG_LEVEL=INFO
ENABLED_NETWORKS=gnosis
ENABLE_HEALTH_SERVER=true
HEALTH_SERVER_PORT=8080
HEALTH_SERVER_HOST=0.0.0.0

# Remove ",/dns/ipfs/tcp/5001/http" if you don't use "ipfs" profile
IPFS_PIN_ENDPOINTS=/dns/ipfs.infura.io/tcp/5001/https,/dns/ipfs/tcp/5001/http

# Optionally pin merkle proofs to the pinata service for redundancy
IPFS_PINATA_API_KEY=<pinata_api_key>
IPFS_PINATA_SECRET_KEY=<pinata_secret_key>

# Change https://api.thegraph.com to http://graph-node:8000 if running local graph node
GNOSIS_STAKEWISE_SUBGRAPH_URL=https://api.thegraph.com/subgraphs/name/stakewise/stakewise-gnosis
GNOSIS_ETHEREUM_SUBGRAPH_URL=https://api.thegraph.com/subgraphs/name/stakewise/ethereum-gnosis

# Ethereum private key
# NB! You must use a different private key for every network
GNOSIS_ORACLE_PRIVATE_KEY=0x<private_key>

# ETH2 (consensus) client endpoint
# Change if running an external ETH2 node
GNOSIS_ETH2_ENDPOINT=http://eth2-node:5052

# AWS bucket to publish oracle votes to
GNOSIS_AWS_ACCESS_KEY_ID=<access_id>
GNOSIS_AWS_SECRET_ACCESS_KEY=<secret_key>
GNOSIS_AWS_BUCKET_NAME=oracle-votes-gnosis
GNOSIS_AWS_REGION=us-east-2

##########
# Keeper #
##########
# Change if running an external ETH1 node
GNOSIS_KEEPER_ETH1_ENDPOINT=http://eth1-node:8545
# Use https://eth-converter.com/ to calculate
GNOSIS_KEEPER_MIN_BALANCE_WEI=1000000000000000000
GNOSIS_KEEPER_MAX_FEE_PER_GAS_GWEI=150

########
# IPFS #
########
IPFS_URL=http://ipfs:5001
IPFS_PROFILE=server
IPFS_FD_MAX=8192

##############
# Graph Node #
##############
GRAPH_LOG=info
GRAPH_NODE_URL=http://graph-node:8020
# Change if running remote IPFS node
ipfs=ipfs:5001
# Change if running an external ETH1 node
# NB! If syncing graph node from scratch archive node must be used.
# It can be switched to fast-sync node once fully synced.
ethereum=xdai:http://eth1-node:8545
# Postgres DB settings for graph node
postgres_host=postgres
postgres_user=graph
postgres_pass=strong-password
postgres_db=graph-node

############
# Postgres #
############
# postgres is used by local graph node
POSTGRES_DB=graph-node
POSTGRES_USER=graph
POSTGRES_PASSWORD=strong-password

#############
# ETH2 NODE #
#############
ETH1_ENDPOINT=http://eth1-node:8545
Loading

0 comments on commit 31ae985

Please sign in to comment.