Go to file
De Facto dc206c7666 update the example price feed address 2021-02-15 17:29:43 +08:00
integration-example remove primitive-types 2021-01-22 07:00:16 +08:00
program remove primitive-types 2021-01-22 07:00:16 +08:00
src fix 2021-02-15 16:57:38 +08:00
.env.example move specific deployment data to .example files 2020-12-10 11:54:21 +00:00
.gitignore remove primitive-types 2021-01-22 07:00:16 +08:00
README.md update example 2021-01-20 19:47:12 +08:00
deploy.json.example update the example price feed address 2021-02-15 17:29:43 +08:00
package.json fix solray install bug 2020-12-28 21:25:16 +08:00
tsconfig.json feed polling and oracle removal 2020-12-10 11:39:52 +00:00

README.md

solana-flux-aggregator

Solnana Flux Aggregator

Price Feeds: https://sol.link

Install

yarn install

Admin Wallet Setup

Setup a wallet for the flux aggregator admin:

yarn solink generate-wallet

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"

Aggregator Setup

Build and deploy the flux aggregator:

yarn build:program
yarn solink deploy-program

deployed aggregator program. program id: DErMSHHbyVisohfM6miHaxstZEAxD5GBq2RrkdcXEasy

Create the btc:usd feed (that accepts max and min u64 as valid submission values):

yarn solink add-aggregator \
  --feedName btc:usd \
  --submitInterval 6 \
  --minSubmissionValue 0 \
  --maxSubmissionValue 18446744073709551615 \
  --submissionDecimals 2

feed initialized, pubkey: 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx

Adding an oracle

Next, we create a separate wallet to control oracles:

yarn solink generate-wallet

address: FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4
mnemonic: amount smoke bar coil current trial toward minimum model pass moral liberty
yarn solink airdrop FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4

Add this wallet to .env:

ORACLE_MNEMONIC="amount smoke bar coil current trial toward minimum model pass moral liberty"

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:

yarn solink add-oracle \
  --feedAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx \
  --oracleName solink-test \
  --oracleOwner FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4

added oracle. pubkey: 7bsB4v6nvHuVC5cWwRheg8opJgmvKVP27pjxiGgoXLoq

Start submitting data from a price feed (e.g. coinbase BTC-USDT):

yarn solink feed \
  --feedAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx \
  --oracleAddress 7bsB4v6nvHuVC5cWwRheg8opJgmvKVP27pjxiGgoXLoq \
  --pairSymbol BTC/USD

Read price

Poll the latest aggregated (median) value from a feed:

yarn solink feed-poll \
  --feedAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx

Remove oracle

yarn solink remove-oracle \
  --feedAddress 3aTBom2uodyWkuVPiUkwCZ2HiFywdUx9tp7su7U2H4Nx \
  --oracleAddress 7bsB4v6nvHuVC5cWwRheg8opJgmvKVP27pjxiGgoXLoq

Test Token

For testing purposes, create a test token held by the aggregator program to reward:

yarn solink testToken --amount 10000000000

Program Integration

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.

use flux_aggregator;

let feed_info = next_account_info(accounts_iter)?;
let value = flux_aggregator::get_median(feed_info)?;