-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gateio_feeder
- Loading branch information
Showing
23 changed files
with
1,485 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CHAIN_ID="nibiru-localnet-0" | ||
GRPC_ENDPOINT="localhost:9090" | ||
WEBSOCKET_ENDPOINT="ws://localhost:26657/websocket" | ||
FEEDER_MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host" | ||
EXCHANGE_SYMBOLS_MAP='{"bitfinex": {"ubtc:unusd": "tBTCUSD", "ueth:unusd": "tETHUSD", "uusd:unusd": "tUSTUSD"}}' | ||
DATASOURCE_CONFIG_MAP='{"coingecko": {"api_key": "0123456789"}}' | ||
VALIDATOR_ADDRESS="nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
FROM golang:1.19 | ||
FROM golang:alpine AS builder | ||
|
||
WORKDIR /feeder | ||
|
||
COPY go.sum go.mod ./ | ||
RUN go mod download | ||
COPY . . | ||
RUN go build -o ./build/feeder ./cmd/feeder/. | ||
ENTRYPOINT ["./build/feeder"] | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg \ | ||
go build -o ./build/feeder ./cmd/feeder/ | ||
|
||
FROM gcr.io/distroless/static:nonroot | ||
|
||
WORKDIR / | ||
COPY --from=builder /feeder/build/feeder . | ||
USER nonroot:nonroot | ||
ENTRYPOINT ["/feeder"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
# Nibiru x/oracle Price Feeder | ||
# NibiruChain/pricefeeder for the Oracle Module | ||
|
||
Submits prices to the nibiru decentralized oracle. | ||
<img src="./repo-banner.png"> | ||
|
||
## Configuration using `.env` | ||
The `pricefeeder` is a tool developed for Nibiru's [Oracle Module consensus](https://nibiru.fi/docs/ecosystem/oracle/) that runs a process to pull data from various external sources and then broadcasts transactions to vote on exchange rates. | ||
|
||
Feeder requires the following environment variables to run: | ||
- [NibiruChain/pricefeeder for the Oracle Module](#nibiruchainpricefeeder-for-the-oracle-module) | ||
- [Quick Start - Local Development](#quick-start---local-development) | ||
- [Configuration for the `.env`](#configuration-for-the-env) | ||
- [Run](#run) | ||
- [Hacking](#hacking) | ||
- [Build](#build) | ||
- [Delegating "feeder" consent](#delegating-feeder-consent) | ||
- [Enabling TLS](#enabling-tls) | ||
- [Configuring specific exchanges](#configuring-specific-exchanges) | ||
|
||
## Quick Start - Local Development | ||
|
||
### Configuration for the `.env` | ||
|
||
Running a `feeder` requires the setting environment variables in your `.env` in like the following: | ||
|
||
```ini | ||
CHAIN_ID="nibiru-localnet-0" | ||
|
@@ -14,46 +28,88 @@ FEEDER_MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole g | |
EXCHANGE_SYMBOLS_MAP='{"bitfinex": {"ubtc:unusd": "tBTCUSD", "ueth:unusd": "tETHUSD", "uusd:unusd": "tUSTUSD"}}' | ||
``` | ||
|
||
### Delegating post pricing | ||
This would allow you to run `pricefeeder` using a local instance of the network. To set up a local network, you can run: | ||
|
||
In order to be able to delegate the post pricing you need to set the | ||
env variable for the validator that delegated you the post pricing: | ||
```bash | ||
git clone [email protected]:NibiruChain/nibiru.git | ||
cd nibiru | ||
git checkout v0.19.2 | ||
make localnet | ||
``` | ||
|
||
```ini | ||
VALIDATOR_ADDRESS="nibiruvaloper1..." | ||
### Run | ||
|
||
With your environment set to a live network, you can now run the price feeder: | ||
```sh | ||
make run | ||
``` | ||
|
||
And from your validator node, you need to delegate responsibilites to the feeder address | ||
#### Or, to run the tool as a daemon: | ||
|
||
1. Build a docker image for use with docker compose. | ||
```bash | ||
make build-docker | ||
``` | ||
|
||
2. Run the 'price_feeder' service defined in the `docker-compose.yaml`. | ||
```bash | ||
make docker-compose up -d price_feeder | ||
``` | ||
|
||
## Hacking | ||
|
||
Connecters for data sources like Binance and Bitfinex are defined in the `feeder/priceprovider/sources` directory. Each of these sources must implement a `FetchPricesFunc` function for querying external data. | ||
|
||
### Build | ||
|
||
Builds the binary for the package: | ||
|
||
```sh | ||
nibid tx oracle set-feeder <feeder address> --from validator | ||
make build | ||
``` | ||
|
||
### Configuring specific exchanges | ||
### Delegating "feeder" consent | ||
|
||
#### CoinGecko | ||
Votes for exhange rates in the [Oracle Module](https://nibiru.fi/docs/ecosystem/oracle/) are posted by validator nodes, however a validator can give consent a `feeder` account to post prices on its behalf. This way, the validator won't have to use their validator's mnemonic to send transactions. | ||
|
||
Coingecko source allows to use paid api key to get more requests per minute. In order to configure it, | ||
you need to set env var: | ||
In order to be able to delegate consent to post prices, you need to set the | ||
`VALIDATOR_ADDRESS` env variable to the "valoper" address the `feeder` will represent. | ||
|
||
```ini | ||
DATASOURCE_CONFIG_MAP='{"coingecko": {"api_key": "0123456789"}}' | ||
VALIDATOR_ADDRESS="nibivaloper1..." | ||
``` | ||
|
||
## Build | ||
To delegate consent from a validator node to some `feeder` address, you must execute a `MsgDelegateFeedConsent` message: | ||
```go | ||
type MsgDelegateFeedConsent struct { | ||
Operator string | ||
Delegate string | ||
} | ||
``` | ||
|
||
```sh | ||
make build-feeder | ||
This is possible using the `set-feeder` subcommand of the `nibid` CLI: | ||
|
||
```bash | ||
nibid tx oracle set-feeder [feeder-address] --from validator | ||
``` | ||
|
||
## Run | ||
### Enabling TLS | ||
|
||
```sh | ||
make run | ||
To enable TLS, you need to set the following env vars: | ||
|
||
```ini | ||
TLS_ENABLED="true" | ||
``` | ||
|
||
or to run as a daemon: | ||
|
||
```sh | ||
make docker-compose up -d price_feeder | ||
### Configuring specific exchanges | ||
|
||
#### CoinGecko | ||
|
||
Coingecko source allows to use paid api key to get more requests per minute. In order to configure it, | ||
you need to set env var: | ||
|
||
```ini | ||
DATASOURCE_CONFIG_MAP='{"coingecko": {"api_key": "0123456789"}}' | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.