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
2021-02-06 00:13:12 -08:00
Solnana Flux Aggregator
2021-01-04 03:57:32 -08:00
Price Feeds: [https://sol.link](https://sol.link)
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
2021-01-20 03:47:12 -08:00
deployed aggregator program. program id: DErMSHHbyVisohfM6miHaxstZEAxD5GBq2RrkdcXEasy
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 \
2021-02-06 00:13:12 -08:00
--feedName btc:usd
2020-12-08 18:39:39 -08:00
2021-01-20 03:47:12 -08:00
feed initialized, pubkey: 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx
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 \
2021-02-15 00:17:45 -08:00
--aggregatorAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx \
2020-12-09 03:41:15 -08:00
--oracleName solink-test \
--oracleOwner FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4
2020-12-08 23:52:28 -08:00
2021-01-20 03:47:12 -08:00
added oracle. pubkey: 7bsB4v6nvHuVC5cWwRheg8opJgmvKVP27pjxiGgoXLoq
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 \
2021-01-20 03:47:12 -08:00
--feedAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx \
--oracleAddress 7bsB4v6nvHuVC5cWwRheg8opJgmvKVP27pjxiGgoXLoq \
2021-01-14 04:17:25 -08:00
--pairSymbol BTC/USD
2020-12-10 03:39:52 -08:00
```
## Read price
Poll the latest aggregated (median) value from a feed:
```
yarn solink feed-poll \
2021-01-20 03:47:12 -08:00
--feedAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx
2020-12-10 03:39:52 -08:00
```
## Remove oracle
```
yarn solink remove-oracle \
2021-01-20 03:47:12 -08:00
--feedAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx \
--oracleAddress 7bsB4v6nvHuVC5cWwRheg8opJgmvKVP27pjxiGgoXLoq
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)?;
2021-02-06 00:13:12 -08:00
```