Switchboard v2 Guide
Last updated
Last updated
Creating a Switchboard oracle for Solend is easy by relying on their publisher here. Take note that creating oracles costs SOL, ~0.04 SOL a day will be consumed based on our configs.
This process might be a bit tough, so feel free to get help from Soju on Discord!
Before we can start listing the oracle, we need to decide where the oracle will pull prices from. This would mainly be from centralized exchanges like binance or Gate.io, or decentralized exchanges like Raydium or Orca.
Pull up Coingecko’s Markets tab for your token, like the following for SLND:
We can see that most of the trading volume for SLND takes place on Gate and MXC for centralized exchanges, and Raydium for decentralized exchanges.
Let’s pull prices from these sites.
To pull prices from centralized exchanges, we will use pre-built scripts for each exchange listed on the Appendix of this page. Alternatively, you can do a Web2 fetch under the Switchboard UI (centralized exchanges are Web2).
For Gate, we need to add an extra step for the “multiplyTask”. Gate quotes SLND in terms of USDT, so we need to convert USDT to USD. We do this via the second half of the script, where it says:
In the Appendix, we have the oracle aggregators for USDC/USD, USDT/USD, and SOL/USD. Since Gate quotes in terms of USDT, we need to add in the USDT/USD oracle to convert the USDT price to the USD price. Simply make sure that the “aggregatorPubkey: <USDT/USD Oracle>”.
For Orca or Raydium LPs, we will need to fetch the “LpExchangeRate” of a liquidity pair, such as SLND/USDC, and do the same multiply task as above.
Select the AMM you are pulling data from before proceeding to Solscan’s DeFi page for the respective AMM. Quick links: Raydium or Orca.
Search for the liquidity pair and copy and paste the address at the LpExchangeRateTask.
Next, put the same switchboard aggregator to convert to USD. As this pair is SLND/USDC, we will need to input the USDC/USD oracle into the aggregator pubkey.
Oracle for Raydium SLND/USD is done!
Once you have repeated all the steps above for each price source, it is time to publish the oracle. First step is to press “Test” and make sure each oracle provides you with an accurate price.
The configs we usually use are:
Update Interval: 1 min
Variance Threshold: 0.5%
Force Report Period: 1 min
This means that your oracle will be updated every minute, or when a price move of 0.5% occurs and has the same configs as what the core team uses.
The final step is to copy and paste the oracle ID where you need to use it.
You can also confirm that the oracle is working properly by checking the “Recent Value” against Coingecko. Expect a slight variance due to the different sources & frequency of update.
Huobi:
Binance:
MEXC:
AscendEX:
Bitfinex: