solana-flux-aggregator/README.md

137 lines
2.9 KiB
Markdown
Raw Normal View History

2020-11-26 14:21:05 -08:00
# solana-flux-aggregator
2020-12-09 03:41:15 -08:00
2020-11-27 01:38:49 -08:00
Solnana Flux Aggregator
2020-12-08 18:39:39 -08:00
## Install
2020-12-09 03:41:15 -08:00
```
yarn install
```
## Admin Wallet Setup
Setup a wallet for the flux aggregator admin:
```
yarn solink generate-wallet
2020-12-09 03:41:15 -08:00
address: 7YMUUCzZir7AAuoy4CtZih9JFBqYwtQiCxjA5dtqwRxU
mnemonic: wine vault fancy enhance trade dolphin hard traffic social butter client pave
```
```
yarn solink airdrop 7YMUUCzZir7AAuoy4CtZih9JFBqYwtQiCxjA5dtqwRxU
```
Create `.env` configuration file for the deploy script.
```
NETWORK=dev
DEPLOY_FILE=deploy.json
ADMIN_MNEMONIC="wine vault fancy enhance trade dolphin hard traffic social butter client pave"
```
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
## Aggregator Setup
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
Build and deploy the flux aggregator:
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
yarn build:program
```
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
yarn solink deploy-program
2020-12-08 18:39:39 -08:00
2020-12-10 03:39:52 -08:00
deployed aggregator program. program id: HFHbe2uckzz9Xh633mbJPYcukzpyJRVcwL87fUrVddiq
2020-12-09 03:41:15 -08:00
```
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
Create the `btc:usd` feed (that accepts max and min u64 as valid submission values):
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
yarn solink add-aggregator \
--feedName btc:usd \
--submitInterval 6 \
--minSubmissionValue 0 \
--maxSubmissionValue 18446744073709551615
2020-12-08 18:39:39 -08:00
2020-12-10 03:39:52 -08:00
feed initialized, pubkey: 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v
2020-12-09 03:41:15 -08:00
```
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
## Adding an oracle
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
Next, we create a separate wallet to control oracles:
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
yarn solink generate-wallet
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
address: FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4
mnemonic: amount smoke bar coil current trial toward minimum model pass moral liberty
```
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
```
yarn solink airdrop FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4
```
2020-12-08 18:39:39 -08:00
2020-12-09 03:41:15 -08:00
Add this wallet to `.env`:
2020-12-08 23:52:28 -08:00
2020-12-09 03:41:15 -08:00
```
ORACLE_MNEMONIC="amount smoke bar coil current trial toward minimum model pass moral liberty"
```
2020-12-08 23:52:28 -08:00
2020-12-09 03:41:15 -08:00
Next we create a new oracle to the feed we've created previously, and set its owner to be the new oracle wallet that we've generated:
2020-12-08 23:52:28 -08:00
2020-12-09 03:41:15 -08:00
```
yarn solink add-oracle \
--index 0 \
2020-12-10 03:39:52 -08:00
--feedAddress 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v \
2020-12-09 03:41:15 -08:00
--oracleName solink-test \
--oracleOwner FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4
2020-12-08 23:52:28 -08:00
2020-12-10 03:39:52 -08:00
added oracle. pubkey: 4jWLbd2Vm98RrqunVvaSXZuP1AFbgQSM2hAHMvZSdNCu
2020-12-09 03:41:15 -08:00
```
2020-12-08 18:39:39 -08:00
2020-12-10 03:39:52 -08:00
Start submitting data from a price feed (e.g. coinbase BTC-USDT):
2020-12-09 03:41:15 -08:00
```
yarn solink feed \
2020-12-10 03:39:52 -08:00
--feedAddress 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v \
--oracleAddress 4jWLbd2Vm98RrqunVvaSXZuP1AFbgQSM2hAHMvZSdNCu
```
## Read price
Poll the latest aggregated (median) value from a feed:
```
yarn solink feed-poll \
--feedAddress 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v
```
## Remove oracle
```
yarn solink remove-oracle \
--index 0 \
--feedAddress 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v
2020-12-09 03:41:15 -08:00
```
2020-12-09 19:49:38 -08:00
2020-12-10 01:20:07 -08:00
## Test Token
2020-12-10 03:44:36 -08:00
For testing purposes, create a test token held by the aggregator program to reward:
2020-12-10 01:20:07 -08:00
```
yarn solink testToken --amount 10000000000
```
2020-12-09 19:49:38 -08:00
## Program Integration
2020-12-10 03:44:36 -08:00
Refer to the [integration-example][./integration-example].
The gist is to pass in the feed address to the program, and call `get_median` from the flux_aggregator crate.
```rust
use flux_aggregator;
let feed_info = next_account_info(accounts_iter)?;
let value = flux_aggregator::get_median(feed_info)?;
```