Skip to main content

Switchboard Tasks

Switchboard oracles read on-chain job accounts to determine how to fetch and respond to update request. An OracleJob is a collection of tasks that are chained together to arrive at a single numerical value.

Switchboard tasks are executed sequentially with the output of the previous task provided as the input to the next task in a chain. After the final task, the TaskRunner will attempt to convert the running result to a numeric value.

NOTE: Some task do not consume the running input such as HttpTask, WebsocketTask, and most of the fetch tasks. If the TaskRunner sees one of these task types in the middle of a job definition, it will effectively reset the running result.

FieldTypeLabelDescription
tasksTaskrepeatedThe chain of tasks to perform for this OracleJob.

Switchboard tasks can be divided into the following categories:

  • Web2 Fetch: Retrieve data from the web
  • Web3 Fetch: Retrieve on-chain data
  • Parse: Extract a value from a response
  • Logic: Perform some logical operation like if..else clauses
  • Utils: Helpful utility tasks like caching values or calculating a timestamp
  • Historical: Parse an on-chain history buffer and perform some calculation
  • Math: Perform a mathematical operation like taking the maximum value of a list or raising a value to an exponent.

📦Web2 Fetch​

🛠HttpTask​

The adapter will report the text body of a successful HTTP request to the specified url, or return an error if the response status code is greater than or equal to 400. @return string representation of it's output.

FieldTypeLabelDescription
urlstringoptionalA string containing the URL to direct this HTTP request to.
methodMethodoptionalThe type of HTTP request to make.
headersHeaderrepeatedA list of headers to add to this HttpTask.
bodystringoptionalA stringified body (if any) to add to this HttpTask.

An object that represents a header to add to an HTTP request.

FieldTypeLabelDescription
keystringoptional
valuestringoptional

Method​

An enumeration representing the types of HTTP requests available to make.

NameNumberDescription
METHOD_UNKOWN0Unset HTTP method will default to METHOD_GET
METHOD_GET1Perform an HTTP 'GET' request.
METHOD_POST2Perform an HTTP 'POST' request.

🛠WebsocketTask​

Opens and maintains a websocket for light speed data retrieval.

FieldTypeLabelDescription
urlstringoptionalThe websocket url.
subscriptionstringoptionalThe websocket message to notify of a new subscription.
max_data_age_secondsint32optionalMinimum amount of time required between when the horses are taking out.
filterstringoptionalIncoming message JSONPath filter. Example: "$[?(@.channel == 'ticker' && @.market == 'BTC/USD')]"

📦Web3 Fetch​

🛠AnchorFetchTask​

Load a parse an Anchor based solana account.

FieldTypeLabelDescription
program_idstringoptionalOwning program of the account to parse.
account_addressstringoptionalThe account to parse.

🛠OracleTask​

Fetch the current price of a Solana oracle protocol.

FieldTypeLabelDescription
switchboard_addressstringoptionalMainnet address of a Switchboard V2 feed. Switchboard is decentralized and allows anyone to build their own feed. A small subset of feeds is available here: https://switchboard.xyz/explorer
pyth_addressstringoptionalMainnet address for a Pyth feed. A full list can be found here: https://pyth.network/price-feeds/
chainlink_addressstringoptionalMainnet address for a Chainlink feed. A full list can be found here: https://docs.chain.link/docs/solana/data-feeds-solana
pyth_allowed_confidence_intervaldoubleoptionalValue (as a percentage) that the lower bound confidence interval is of the actual value. Confidence intervals that are larger that this treshold are rejected.

🛠SolanaAccountDataFetchTask​

Fetch the account data in a stringified buffer format.

FieldTypeLabelDescription
pubkeystringoptionalThe on-chain account to fetch the account data from.

🛠JupiterSwapTask​

Fetch the simulated price for a swap on JupiterSwap.

FieldTypeLabelDescription
in_token_addressstringoptionalThe input token address.
out_token_addressstringoptionalThe output token address.
base_amountdoubleoptionalThe amount of tokens to swap.
allow_listFilterListoptional
deny_listFilterListoptional

FilterList​

A list of Jupiter AMM labels to allow or deny (e.g. 'Raydium', 'Orca')

FieldTypeLabelDescription
labelsstringrepeated
info

Note: Jupiter currently supports the following AMMs which can be inputted into the allow_list or deny_list property to change the route selection:

  • Aldrin
  • Crema
  • Cropper
  • Cykura
  • DeltaFi
  • GooseFX
  • Invariant
  • Lifinity
  • Lifinity V2
  • Marinade
  • Mercurial
  • Meteora
  • Raydium
  • Saber
  • Serum
  • Orca
  • Step
  • Penguin
  • Saros
  • Stepn
  • Orca (Whirlpools)
  • Sencha
  • Saber (Decimals)
  • Dradex
  • Balansol
  • Unknown

🛠SerumSwapTask​

Fetch the latest swap price on Serum's orderbook.

FieldTypeLabelDescription
serum_pool_addressstringoptionalThe serum pool to fetch swap price for
info

Update (11/17/2022): This task now points to the community fork of Serum.

🛠UniswapExchangeRateTask​

Fetch the swap price from UniSwap.

FieldTypeLabelDescription
in_token_addressstringoptionalThe input token address.
out_token_addressstringoptionalThe output token address.
in_token_amountdoubleoptionalThe amount of tokens to swap.
slippagedoubleoptionalThe allowable slippage in percent for the swap.
providerstringoptionalThe RPC provider to use for the swap.

🛠SushiSwapExchangeRateTask​

Fetch the swap price from SushiSwap.

FieldTypeLabelDescription
in_token_addressstringoptionalThe input token address.
out_token_addressstringoptionalThe output token address.
in_token_amountdoubleoptionalThe amount of tokens to swap.
slippagedoubleoptionalThe allowable slippage in percent for the swap.
providerstringoptionalThe RPC provider to use for the swap.

🛠PancakeswapExchangeRateTask​

Fetch the swap price from PancakeSwap.

FieldTypeLabelDescription
in_token_addressstringoptionalThe input token address.
out_token_addressstringoptionalThe output token address.
in_token_amountdoubleoptionalThe amount of tokens to swap.
slippagedoubleoptionalThe allowable slippage in percent for the swap.
providerstringoptionalThe RPC provider to use for the swap.

🛠DefiKingdomsTask​

Fetch the swap price from DefiKingdoms.

FieldTypeLabelDescription
providerstringoptionalThe RPC provider to use for the swap.
in_tokenTokenoptionalThe input token of the swap.
out_tokenTokenoptionalThe output token of the swap.

Token​

FieldTypeLabelDescription
addressstringoptionalThe address of the token.
decimalsint32optionalThe number of decimal places for a token.

🛠MangoPerpTask​

Fetch the current price for a Mango perpetual market

FieldTypeLabelDescription
perp_market_addressstringoptionalMainnet address for a mango perpetual market. A full list can be found here: https://github.com/blockworks-foundation/mango-client-v3/blob/main/src/ids.json

🛠LendingRateTask​

Fetch the lending rates for various Solana protocols

FieldTypeLabelDescription
protocolstringoptional01, apricot, francium, jet, larix, mango, port, solend, tulip
asset_mintstringoptionalA token mint address supported by the chosen protocol
fieldFieldoptional

Field​

NameNumberDescription
FIELD_DEPOSIT_RATE0deposit lending rate
FIELD_BORROW_RATE1borrow lending rate

🛠XStepPriceTask​

FieldTypeLabelDescription
step_jobMedianTaskoptionalmedian task containing the job definitions to fetch the STEP/USD price
step_aggregator_pubkeystringoptionalexisting aggregator pubkey for STEP/USD

🛠SplTokenParseTask​

Fetch the JSON representation of an SPL token mint.

FieldTypeLabelDescription
token_account_addressstringoptionalThe publicKey of a token account to fetch the mintInfo for.
mint_addressstringoptionalThe publicKey of the token mint address.

🛠SplStakePoolTask​

Fetch the JSON representation of an SPL Stake Pool account.

FieldTypeLabelDescription
pubkeystringoptionalThe pubkey of the SPL Stake Pool.

🛠LpExchangeRateTask​

Fetch the current swap price for a given liquidity pool

FieldTypeLabelDescription
in_token_addressstringoptionalUsed alongside mercurial_pool_address to specify the input token for a swap.
out_token_addressstringoptionalUsed alongside mercurial_pool_address to specify the output token for a swap.
mercurial_pool_addressstringoptionalMercurial finance pool address. A full list can be found here: https://github.com/mercurial-finance/stable-swap-n-pool-js
saber_pool_addressstringoptionalSaber pool address. A full list can be found here: https://github.com/saber-hq/saber-registry-dist
orca_pool_token_mint_addressstringoptionalDeprecated. Orca pool address.
raydium_pool_addressstringoptionalThe Raydium liquidity pool ammId. A full list can be found here: https://sdk.raydium.io/liquidity/mainnet.json
orca_pool_addressstringoptionalPool address for an Orca LP pool or whirlpool. A full list of Orca LP pools can be found here: https://www.orca.so/pools

🛠LpTokenPriceTask​

Fetch LP token price info from a number of supported exchanges.

FieldTypeLabelDescription
mercurial_pool_addressstringoptionalMercurial finance pool address. A full list can be found here: https://github.com/mercurial-finance/stable-swap-n-pool-js
saber_pool_addressstringoptionalSaber pool address. A full list can be found here: https://github.com/saber-hq/saber-registry-dist
orca_pool_addressstringoptionalOrca pool address. A full list can be found here: https://www.orca.so/pools
raydium_pool_addressstringoptionalThe Raydium liquidity pool ammId. A full list can be found here: https://sdk.raydium.io/liquidity/mainnet.json
price_feed_addressesstringrepeatedA list of Switchboard aggregator accounts used to calculate the fair LP price. This ensures the price is based on the previous round to mitigate flash loan price manipulation.
price_feed_jobsOracleJobrepeated
use_fair_pricebooloptionalIf enabled and price_feed_addresses provided, the oracle will calculate the fair LP price based on the liquidity pool reserves. See our blog post for more information: https://switchboardxyz.medium.com/fair-lp-token-oracles-94a457c50239

📦Parse​

🛠JsonParseTask​

The adapter walks the path specified and returns the value found at that result. If returning JSON data from the HttpGet or HttpPost adapters, you must use this adapter to parse the response.

FieldTypeLabelDescription
pathstringoptionalJSONPath formatted path to the element. https://t.ly/uLtw https://www.npmjs.com/package/jsonpath-plus
aggregation_methodAggregationMethodoptionalThe technique that will be used to aggregate the results if walking the specified path returns multiple numerical results.

AggregationMethod​

The methods of combining a list of numerical results.

NameNumberDescription
NONE0
MIN1Grab the minimum value of the results.
MAX2Grab the maximum value of the results.
SUM3Sum up all of the results.
MEAN4Average all of the results.
MEDIAN5Grab the median of the results.

🛠RegexExtractTask​

Find a pattern within a string of a previous task and extract a group number.

FieldTypeLabelDescription
patternstringoptionalRegex pattern to find.
group_numberint32optionalGroup number to extract.

🛠BufferLayoutParseTask​

Return the deserialized value from a stringified buffer.

FieldTypeLabelDescription
offsetuint32optionalThe buffer offset to start deserializing from.
endianEndianoptionalThe endianness of the stored value.
typeBufferParseTypeoptionalThe type of value to deserialize.

BufferParseType​

NameNumberDescription
pubkey1A public key.
bool2A boolean.
u83An 8-bit unsigned value.
i84An 8-bit signed value.
u165A 16-bit unsigned value.
i166A 16-bit signed value.
u327A 32-bit unsigned value.
i328A 32-bit signed value.
f329A 32-bit IEEE floating point value.
u6410A 64-bit unsigned value.
i6411A 64-bit signed value.
f6412A 64-bit IEEE floating point value.
u12813A 128-bit unsigned value.
i12814A 128-bit signed value.

Endian​

NameNumberDescription
LITTLE_ENDIAN0
BIG_ENDIAN1

📦Logic​

🛠BoundTask​

Bound a final result to a min or max. If an onExceeds field is not provided then the job will fail if the result is outside the bounds.

FieldTypeLabelDescription
lower_boundOracleJoboptional
lower_bound_valuestringoptional
upper_boundOracleJoboptional
upper_bound_valuestringoptional
on_exceeds_upper_boundOracleJoboptional
on_exceeds_upper_bound_valuestringoptional
on_exceeds_lower_boundOracleJoboptional
on_exceeds_lower_bound_valuestringoptional

🛠ConditionalTask​

This task will run the attempt subtasks in an effort to produce a valid numerical result. If attempt fails to produce an acceptable result, on_failure subtasks will be run instead.

FieldTypeLabelDescription
attemptTaskrepeatedA list of subtasks to process in an attempt to produce a valid numerical result.
on_failureTaskrepeatedA list of subtasks that will be run if attempt subtasks are unable to produce an acceptable result.

🛠ComparisonTask​

Perform a numerical comparison on two values

FieldTypeLabelDescription
opComparisonTask.Operationoptional
lhsOracleJoboptional
lhs_valuestringoptional
rhsOracleJoboptional
rhs_valuestringoptional
on_trueOracleJoboptional
on_true_valuestringoptional
on_falseOracleJoboptional
on_false_valuestringoptional
on_failureOracleJoboptional
on_failure_valuestringoptional

ComparisonTask.Operation​

NameNumberDescription
OPERATION_EQ0
OPERATION_GT1
OPERATION_LT2

📦Utils​

🛠CacheTask​

Execute a job and store the result in a variable to reference later.

FieldTypeLabelDescription
cache_itemsCacheItemrepeatedA list of cached variables to reference in the job with ${VARIABLE_NAME}.

CacheItem​

FieldTypeLabelDescription
variable_namestringoptionalThe name of the variable to store in cache to reference later with ${VARIABLE_NAME}.
jobOracleJoboptionalThe OracleJob to execute to yield the value to store in cache.

🛠SysclockOffsetTask​

Return the difference between an oracle's clock and the current timestamp at SYSVAR_CLOCK_PUBKEY.

🛠CronParseTask​

Return a timestamp from a crontab instruction.

FieldTypeLabelDescription
cron_patternstringoptionalThe cron pattern to parse
clock_offsetint32optionalThe timestamp offset to calculate the next run
clockClockTypeoptionalThe type of clock to use, oracle or the solana cluster sysclock.

ClockType​

The type of clock.

NameNumberDescription
ORACLE0The oracles current clock.
SYSCLOCK1The solana cluster's sysclock.

🛠TpsTask​

Fetch the current transactions per second.

📦Historical​

Task types which parse historical data from an on-chain history buffer

🛠TwapTask​

Takes a twap over a set period for a certain aggregator.

FieldTypeLabelDescription
aggregator_pubkeystringoptionalThe target aggregator for the TWAP.
periodint32optionalPeriod, in seconds, the twap should account for
weight_by_propagation_timebooloptionalWeight samples by their propagation time
min_samplesuint32optionalMinimum number of samples in the history to calculate a valid result
ending_unix_timestampint32optionalEnding unix timestamp to collect values up to
ending_unix_timestamp_taskCronParseTaskoptionalExecute the task to get the ending unix timestamp

🛠EwmaTask​

NOT LIVE, IN DEVELOPMENT.

FieldTypeLabelDescription
aggregator_addressstringoptional
periodint32optional
lambdadoubleoptional

🛠HistoryFunctionTask​

NOT LIVE, IN DEVELOPMENT.

FieldTypeLabelDescription
methodHistoryFunctionTask.Methodoptional
aggregator_addressstringoptional
perioduint32optional

HistoryFunctionTask.Method​

NameNumberDescription
METHOD_MIN0
METHOD_MAX1

🛠VwapTask​

NOT LIVE, IN DEVELOPMENT.

FieldTypeLabelDescription
price_aggregator_addressstringoptional
volume_aggregator_addressstringoptional
perioduint32optional

📦Math​

🛠MaxTask​

Returns the maximum value of all the results returned by the provided subtasks and subjobs.

FieldTypeLabelDescription
tasksTaskrepeatedA list of subtasks to process and produce a list of result values.
jobsOracleJobrepeatedA list of subjobs to process and produce a list of result values.

🛠MeanTask​

Returns the mean of all the results returned by the provided subtasks and subjobs.

FieldTypeLabelDescription
tasksTaskrepeatedA list of subtasks to process and produce a list of result values.
jobsOracleJobrepeatedA list of subjobs to process and produce a list of result values.

🛠MedianTask​

Returns the median of all the results returned by the provided subtasks and subjobs. Nested tasks must return a Number.

FieldTypeLabelDescription
tasksTaskrepeatedA list of subtasks to process and produce a list of result values.
jobsOracleJobrepeatedA list of subjobs to process and produce a list of result values.
min_successful_requiredint32optional

🛠AddTask​

This task will add a numerical input by a scalar value or by another aggregate.

FieldTypeLabelDescription
scalardoubleoptionalSpecifies a scalar to add by.
aggregator_pubkeystringoptionalSpecifies an aggregator to add by.
jobOracleJoboptionalA job whose result is computed before adding our numerical input by that result.
bigstringoptionalA stringified big.js. Accepts variable expansion syntax.

🛠SubtractTask​

This task will subtract a numerical input by a scalar value or by another aggregate.

FieldTypeLabelDescription
scalardoubleoptionalSpecifies a scalar to subtract by.
aggregator_pubkeystringoptionalSpecifies an aggregator to subtract by.
jobOracleJoboptionalA job whose result is computed before subtracting our numerical input by that result.
bigstringoptionalA stringified big.js. Accepts variable expansion syntax.

🛠MultiplyTask​

This task will multiply a numerical input by a scalar value or by another aggregator.

FieldTypeLabelDescription
scalardoubleoptionalSpecifies a scalar to multiply by.
aggregator_pubkeystringoptionalSpecifies an aggregator to multiply by.
jobOracleJoboptionalA job whose result is computed before multiplying our numerical input by that result.
bigstringoptionalA stringified big.js. Accepts variable expansion syntax.

🛠DivideTask​

This task will divide a numerical input by a scalar value or by another aggregate.

FieldTypeLabelDescription
scalardoubleoptionalSpecifies a basic scalar denominator to divide by.
aggregator_pubkeystringoptionalSpecifies another aggregator resut to divide by.
jobOracleJoboptionalA job whose result is computed before dividing our numerical input by that result.
bigstringoptionalA stringified big.js. Accepts variable expansion syntax.

🛠PowTask​

Take the power of the working value.

FieldTypeLabelDescription
scalardoubleoptionalTake the working value to the exponent of value.
aggregator_pubkeystringoptionalTake the working value to the exponent of the aggregators value.
bigstringoptionalA stringified big.js. Accepts variable expansion syntax.

🛠ValueTask​

Returns a specified value.

FieldTypeLabelDescription
valuedoubleoptionalThe value that will be returned from this task.
aggregator_pubkeystringoptionalSpecifies an aggregatorr to pull the value of.
bigstringoptionalA stringified big.js. Accepts variable expansion syntax.

🛠RoundTask​

FieldTypeLabelDescription
methodRoundTask.Methodoptional
decimalsint32optional

RoundTask.Method​

NameNumberDescription
METHOD_ROUND_UP0
METHOD_ROUND_DOWN1