Switchboard v2 Guide

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!

Deciding Where to Pull Prices from

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.

Fetching Prices from Web2

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:

    {
      "multiplyTask": {
        "aggregatorPubkey": "ETAaeeuQBwsh9mC2gCov9WdhJENZuffRMXY2HgjCcSL9"
      }

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>”.

Fetching Prices from Web3

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!

Publishing the Oracle

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.

Getting the Oracle ID

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.

Appendix

Commonly used Switchboard Oracle Aggregators:
USDC/USD: BjUgj6YCnFBZ49wF54ddBVA9qu8TeqkFtkbqmZcee8uW
SOL/USD: GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR
USDT/USD: ETAaeeuQBwsh9mC2gCov9WdhJENZuffRMXY2HgjCcSL9

Huobi:

{
  "name": "Huobi GST/USD",
  "tasks": [
    {
      "httpTask": {
        "url": "https://api.huobi.pro/market/detail/merged?symbol=gstusdt"
      }
    },
    {
      "medianTask": {
        "tasks": [
          {
            "jsonParseTask": {
              "path": "$.tick.bid[0]"
            }
          },
          {
            "jsonParseTask": {
              "path": "$.tick.ask[0]"
            }
          }
        ]
      }
    },
    {
      "multiplyTask": {
        "aggregatorPubkey": "ETAaeeuQBwsh9mC2gCov9WdhJENZuffRMXY2HgjCcSL9"
      }
    }
  ]
}

Binance:

{
  "name": "BinanceCom BTC/USD",
  "tasks": [
    {
      "httpTask": {
        "url": "https://www.binance.com/api/v3/ticker/price?symbol=BTCUSDT"
      }
    },
    {
      "jsonParseTask": {
        "path": "$.price"
      }
    },
    {
      "multiplyTask": {
        "aggregatorPubkey": "ETAaeeuQBwsh9mC2gCov9WdhJENZuffRMXY2HgjCcSL9"
      }
    }
  ]
}

MEXC:

{
  "name": "Mxc BTC/USD",
  "tasks": [
    {
      "httpTask": {
        "url": "https://www.mexc.com/open/api/v2/market/ticker?symbol=LARIX_USDT"
      }
    },
    {
      "medianTask": {
        "tasks": [
          {
            "jsonParseTask": {
              "path": "$.data[0].ask"
            }
          },
          {
            "jsonParseTask": {
              "path": "$.data[0].bid"
            }
          },
          {
            "jsonParseTask": {
              "path": "$.data[0].last"
            }
          }
        ]
      }
    },
          {
            "multiplyTask": {
              "aggregatorPubkey": "ETAaeeuQBwsh9mC2gCov9WdhJENZuffRMXY2HgjCcSL9"
            }
          }
        ]
      }

AscendEX:

{
  "tasks": [
    {
      "httpTask": {
        "url": "https://ascendex.com/api/pro/v1/spot/ticker?symbol=JET/USDT"
      }
    },
    {
      "medianTask": {
        "tasks": [
          {
            "jsonParseTask": {
              "path": "$.data.close"
            }
          },
          {
            "jsonParseTask": {
              "path": "$.data.ask[0]"
            }
          },
          {
            "jsonParseTask": {
              "path": "$.data.bid[0]"
            }
          },
          {
            "multiplyTask": {
              "aggregatorPubkey": "ETAaeeuQBwsh9mC2gCov9WdhJENZuffRMXY2HgjCcSL9"
            }
          }
        ]
      }
    }
  ]
}

Bitfinex:

{
  "name": "Bitfinex BTC/USD",
  "tasks": [
    {
      "httpTask": {
        "url": "https://api-pub.bitfinex.com/v2/tickers?symbols=tOXYUST"
      }
    },
    {
      "medianTask": {
        "tasks": [
          {
            "jsonParseTask": {
              "path": "$[0][1]"
            }
          },
          {
            "jsonParseTask": {
              "path": "$[0][3]"
            }
          },
          {
            "jsonParseTask": {
              "path": "$[0][7]"
            }
          },
          {
            "multiplyTask": {
              "aggregatorPubkey": "ETAaeeuQBwsh9mC2gCov9WdhJENZuffRMXY2HgjCcSL9"
            }
          }
        ]
      }
    }
  ]
}

Last updated