solana-flux-aggregator/README.md

135 lines
3.9 KiB
Markdown
Raw Permalink Normal View History

2020-11-26 14:21:05 -08:00
# solana-flux-aggregator
2020-12-09 03:41:15 -08:00
2021-02-06 00:13:12 -08:00
Solnana Flux Aggregator
2021-01-04 03:57:32 -08:00
2021-02-20 05:48:37 -08:00
## Install Dependencies
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
yarn install
```
2021-02-20 17:48:14 -08:00
# Setup
If you want to setup the whole thing, read: [SETUP.md](./SETUP.md)
2021-02-20 05:48:37 -08:00
# Submit Prices As Oracle (devnet)
2020-12-09 03:41:15 -08:00
2021-02-20 05:48:37 -08:00
There are price oracles already deployed on the devnet, you can see their deploy
configuration and addresses at [./deploy.sandbox.json](./deploy.sandbox.json)
2020-12-09 03:41:15 -08:00
2021-02-20 05:48:37 -08:00
Configure `.env` to use the devnet:
2020-12-09 03:41:15 -08:00
```
2021-02-20 05:48:37 -08:00
cp .env.sandbox .env
2020-12-09 03:41:15 -08:00
```
2021-02-20 05:48:37 -08:00
The `.env` will set the price oracle to be the account:
2020-12-09 03:41:15 -08:00
```
2021-02-20 05:48:37 -08:00
FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4
2020-12-09 03:41:15 -08:00
```
2020-12-08 18:39:39 -08:00
2021-02-20 05:48:37 -08:00
Then run the oracle:
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
2021-02-20 05:48:37 -08:00
yarn solink oracle
2020-12-09 03:41:15 -08:00
```
2020-12-08 18:39:39 -08:00
2021-02-20 05:48:37 -08:00
The oracle should submit updates if the price changes by more than $1. You should see:
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
2021-02-20 05:48:37 -08:00
info: Starting a new round {"aggregator":"btc:usd","round":"9"}
info: Submit value {"aggregator":"btc:usd","round":"9","value":"5748914"}
info: Submit OK {"aggregator":"btc:usd","withdrawable":"90000","rewardToken":"3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1"}
info: Starting a new round {"aggregator":"btc:usd","round":"10"}
info: Submit value {"aggregator":"btc:usd","round":"10","value":"5749313"}
info: Submit OK {"aggregator":"btc:usd","withdrawable":"100000","rewardToken":"3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1"}
2020-12-09 03:41:15 -08:00
```
2020-12-08 18:39:39 -08:00
2021-02-20 05:48:37 -08:00
NOTE: This is a "sandbox" environment on the devnet to make it easy for you to
try running the price oracle. Anyone reading this README has access to the
private key of the account `FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4`. Do
not use this key for production!
2020-12-08 18:39:39 -08:00
2021-02-20 05:48:37 -08:00
NOTE 2: You might get error messages if somebody else is also running the
oracle.
2020-12-08 18:39:39 -08:00
### Manual price feed
Alternatively, you can submit prices to the oracle manually by instructing the oracle to watch for changes to a local file.
This can be useful for testing specific behaviour (such as triggering liquidations).
Run the oracle:
```
yarn solink oracle-file {pair} {filepath}
```
{pair} must be one of the aggregator pairs in deploy.sandbox.json
Then you can update prices by running
```
echo {price} > {filepath}
```
2021-02-20 05:48:37 -08:00
# Observe The Aggregators
2020-12-08 18:39:39 -08:00
2021-02-20 05:48:37 -08:00
With the oracle running, you can subscribe to price changes. In another
terminal, run:
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
2021-02-20 05:48:37 -08:00
yarn solink observe
2020-12-09 03:41:15 -08:00
```
2020-12-08 18:39:39 -08:00
2021-02-20 05:48:37 -08:00
You should get prices pushed to you when they update:
2020-12-10 03:39:52 -08:00
2020-12-09 03:41:15 -08:00
```
2021-02-20 05:48:37 -08:00
info: update {"description":"btc:usd","decimals":2,"roundID":"21","median":"5744000","updatedAt":"37820525","createdAt":"37820525"}
info: update {"description":"eth:usd","decimals":2,"roundID":"9","median":"202600","updatedAt":"37820513","createdAt":"37820513"}
info: update {"description":"btc:usd","decimals":2,"roundID":"22","median":"5743803","updatedAt":"37820552","createdAt":"37820552"}
info: update {"description":"btc:usd","decimals":2,"roundID":"23","median":"5740350","updatedAt":"37820565","createdAt":"37820565"}
2021-02-06 00:13:12 -08:00
```
2021-02-20 05:57:39 -08:00
# Devnet Oracles
The sandbox environment could be modified by anyone, and is not suitable for
development purposes. For a reliable devnet price feed, use [./deploy.dev.json](./deploy.dev.json).
Observe the devnet prices by running:
```
NETWORK=dev DEPLOY_FILE=deploy.dev.json yarn solink observe
2021-02-20 06:03:44 -08:00
```
* `btc:usd` => 8tawJxhUbVJV7Aiss8DBkYoN4ZA1vpNVwjNmUdgpMw7J
2021-02-20 06:11:16 -08:00
* `eth:usd` => 4X5QRNHs3saF35fhL7FJtPR58PeqoFmzgq82EiHqa9a9
2021-02-24 22:32:47 -08:00
## Using Your Own RPC
By default the oracle uses the public RPC host. If you run many price feeds, you
may hit the rate limit of the public RPC.
For better stability, you should run use your own private RPC instead.
Configure in `.env`:
```
# (Optional) Specify the RPC host you want to use for your network
SOLANA_RPC_HOST=http://localhost:8899
```
2021-02-20 06:11:16 -08:00
## Joining Devnet
If you want to become a testnet oracle, generate a solana devnet wallet (10 SOL will be airdropped):
```
NETWORK=dev yarn solink new-wallet
info: address: 8CGZz277PT6yA7nU6HEdpbwQsNYLvyJhP1guoUNxt9mF
info: mnemonic: ....
info: airdrop 10 SOL {"address":"8CGZz277PT6yA7nU6HEdpbwQsNYLvyJhP1guoUNxt9mF"}
```
Save the mnemonic in your `.env` file, and give the address to me. I'll add
2021-02-24 22:32:47 -08:00
you to the oracle list so you can submit.