From 3b9513dd8d3723533a66cd62081be087fb704a60 Mon Sep 17 00:00:00 2001 From: De Facto Date: Sun, 21 Feb 2021 09:48:14 +0800 Subject: [PATCH] setup instruction --- README.md | 4 ++ SETUP.md | 86 +++++++++++++++++++++++++++++++ config/setup.private.json.example | 31 +++++++++++ 3 files changed, 121 insertions(+) create mode 100644 SETUP.md create mode 100644 config/setup.private.json.example diff --git a/README.md b/README.md index ab290e4..bcd3fda 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Solnana Flux Aggregator yarn install ``` +# Setup + +If you want to setup the whole thing, read: [SETUP.md](./SETUP.md) + # Submit Prices As Oracle (devnet) There are price oracles already deployed on the devnet, you can see their deploy diff --git a/SETUP.md b/SETUP.md new file mode 100644 index 0000000..08fbaa7 --- /dev/null +++ b/SETUP.md @@ -0,0 +1,86 @@ +# Setup Your Own Aggregators + +Let's assume that you are deploying to devnet, you can configure your own +private aggregators by being both the admin and the oracle. + +Generate a new wallet (if you want): + +``` +NETWORK=dev yarn solink new-wallet + +info: address: 9QYPHz91uGZMSueGBhtxmy17L4ynJoWXdTE7mU21kizc +info: mnemonic: fix toward apology left between video girl novel seminar best sick gap +info: airdrop 10 SOL {"address":"9QYPHz91uGZMSueGBhtxmy17L4ynJoWXdTE7mU21kizc"} +``` + +You `.env` should contain the followings: + +``` +NETWORK=dev + +DEPLOY_FILE=deploy.private.json + +# 9QYPHz91uGZMSueGBhtxmy17L4ynJoWXdTE7mU21kizc +ADMIN_MNEMONIC="fix toward apology left between video girl novel seminar best sick gap" +ORACLE_MNEMONIC="fix toward apology left between video girl novel seminar best sick gap" +``` + +Then copy the setup file: + +``` +cp config/setup.private.json.example config/setup.private.json +``` + +NOTE: Change the oracle owner key of [config/setup.private.json](config/setup.private.json) + +Finally, run the setup process: + +``` +yarn solink setup config/setup.private.json +``` + +## Redeploy An Aggregator + +If successful, the setup process should create the `deploy.private.json` file +that contains all the account addresses associated with the deployment. + +If you need to redeploy an aggregator (e.g. `btc:usd`), remove the corresponding +object in `aggregators` in `deploy.private.json`, namely: + +``` +"btc:usd": { + "decimals": 2, + "minSubmissions": 1, + "maxSubmissions": 3, + "restartDelay": 0, + "rewardAmount": 10000, + "rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1", + "oracles": [ + "tester" + ] +} +``` + +Then rerun setup: + +``` +yarn solink setup config/setup.private.json +``` + +## Implement Your PriceFeed + +You may need to implement your own price feed to test liquidation. We will +support custom feeds in the future... for now edit the code manually. + +1. Create an EventEmitter that emits an IPrice: + +https://github.com/czl1378/solana-flux-aggregator/blob/91712880abbb16b3c620995cabcca6e4a8582ad8/src/feeds.ts#L48 + +2. Wrap the EventEmitter instance as an async iterator + +https://github.com/czl1378/solana-flux-aggregator/blob/91712880abbb16b3c620995cabcca6e4a8582ad8/src/PriceFeeder.ts#L38 + + +3. In `PriceFeeder` change `coinbase` to your custom price feed + +https://github.com/czl1378/solana-flux-aggregator/blob/91712880abbb16b3c620995cabcca6e4a8582ad8/src/PriceFeeder.ts#L38 diff --git a/config/setup.private.json.example b/config/setup.private.json.example new file mode 100644 index 0000000..3bb625d --- /dev/null +++ b/config/setup.private.json.example @@ -0,0 +1,31 @@ +{ + "aggregators": { + "btc:usd": { + "decimals": 2, + "minSubmissions": 1, + "maxSubmissions": 3, + "restartDelay": 0, + "rewardAmount": 10000, + "rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1", + "oracles": [ + "testerA" + ] + }, + "eth:usd": { + "decimals": 2, + "minSubmissions": 1, + "maxSubmissions": 3, + "restartDelay": 0, + "rewardAmount": 10000, + "rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1", + "oracles": [ + "testerA" + ] + } + }, + "oracles": { + "testerA": { + "owner": "9QYPHz91uGZMSueGBhtxmy17L4ynJoWXdTE7mU21kizc" + } + } +} \ No newline at end of file