Skip to main content

Task

Represents a singular operation performed by an oracle to yield an eventual numerical result.


See the Task typescript definition in @switchboard-xyz/common

Fields

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

Input: None

Returns: String representation of the http response.

Example: Basic HttpTask

{
"httpTask": {
"url": "https://mywebsite.org/path"
}
}

Example: HttpTask example with headers

{
"httpTask": {
"url": "https://mywebsite.org/path",
"method": "METHOD_POST",
"headers": [
{
"key": "MY_HEADER_KEY",
"value": "MY_HEADER_VALUE"
}
],
"body": "{\"MY_BODY_KEY\":\"MY_BODY_VALUE\"}"
}
}
 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.

Input: String representation of a JSON object.

Returns: A numerical result.

Example: Parses the price field from a JSON object

{
"jsonParse": {
"path": "$.price"
}
}
 medianTask

Returns the median (middle) of all the results returned by the provided subtasks and subjobs. Nested tasks or jobs must return a Number.

Input: None

Returns: A numerical result.

Example: Returns the median numerical result of 3 tasks.

{
"medianTask": {
"tasks": [
{
"valueTask": {
"value": 10
}
},
{
"valueTask": {
"value": 20
}
},
{
"valueTask": {
"value": 30
}
}
]
}
}

Example: Returns the median numerical result of 3 jobs.

{
"medianTask": {
"jobs": [
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.com/api/v3/ticker/price?symbol=SOLUSDT"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.us/api/v3/ticker/price?symbol=SOLUSD"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://api-pub.bitfinex.com/v2/tickers?symbols=tSOLUSD"
}
},
{
"jsonParseTask": {
"path": "$[0][7]"
}
}
]
}
]
}
}
 meanTask

Returns the mean (average) of all the results returned by the provided subtasks and subjobs. Nested tasks or jobs must return a Number.

Input: None

Returns: A numerical result.

Example: Returns the mean numerical result of 3 tasks.

{
"meanTask": {
"tasks": [
{
"valueTask": {
"value": 10
}
},
{
"valueTask": {
"value": 20
}
},
{
"valueTask": {
"value": 30
}
}
]
}
}

Example: Returns the mean numerical result of 3 jobs.

{
"meanTask": {
"jobs": [
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.com/api/v3/ticker/price?symbol=SOLUSDT"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.us/api/v3/ticker/price?symbol=SOLUSD"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://api-pub.bitfinex.com/v2/tickers?symbols=tSOLUSD"
}
},
{
"jsonParseTask": {
"path": "$[0][7]"
}
}
]
}
]
}
}
 websocketTask

Opens and maintains a websocket for light speed data retrieval.

Input: None

Returns: String representation of the websocket subscription message.

Example: Opens a coinbase websocket

{
"websocketTask": {
"url": "wss://ws-feed.pro.coinbase.com",
"subscription": "{\"type\":\"subscribe\",\"product_ids\":[\"BTC-USD\"],\"channels\":[\"ticker\",{\"name\":\"ticker\",\"product_ids\":[\"BTC-USD\"]}]}",
"maxDataAgeSeconds": 15,
"filter": "$[?(@.type == 'ticker' && @.product_id == 'BTC-USD')]"
}
}
 divideTask

This task will divide a numerical input by a scalar value from a job of subtasks, an aggregator, or a big.

Input: The current running numerical result output from a scalar value, an aggregator, a job of subtasks or a big.

Returns: A numerical result.

Example: Returns the numerical result by dividing by a job of subtasks.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"divideTask": {
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
}
]
}

Example: Returns the numerical result by dividing by an aggregator.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"divideTask": {
"aggregatorPubkey": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
}
}
]
}

Example: Returns the numerical result by dividing by a big.

{
"tasks": [
{
"cacheTask": {
"cacheItems": [
{
"variableName": "TEN",
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
]
}
},
{
"valueTask": {
"value": 100
}
},
{
"divideTask": {
"big": "${TEN}"
}
}
]
}
 multiplyTask

This task will multiply a numerical input by a scalar value from a job of subtasks, an aggregator, or a big.

Input: The current running numerical result output from a scalar value, an aggregator, a job of subtasks or a big.

Returns: A numerical result.

Example: Returns the numerical result by multiplying by a job of subtasks.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"multiplyTask": {
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
}
]
}

Example: Returns the numerical result by multiplying by an aggregator.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"multiplyTask": {
"aggregatorPubkey": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
}
}
]
}

Example: Returns the numerical result by multiplying by a big.

{
"tasks": [
{
"cacheTask": {
"cacheItems": [
{
"variableName": "TEN",
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
]
}
},
{
"valueTask": {
"value": 100
}
},
{
"multiplyTask": {
"big": "${TEN}"
}
}
]
}
 lpTokenPriceTask

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

See our blog post on Fair LP Token Oracles

NOTE*: This is not the swap price but the price of the underlying LP token.

Input: None

Returns: The price of an LP token for a given AMM pool.

Example: Fetch the Orca LP token price of the SOL/USDC pool

{
"lpTokenPriceTask": {
"orcaPoolAddress": "APDFRM3HMr8CAGXwKHiu2f5ePSpaiEJhaURwhsRrUUt9"
}
}

Example: Fetch the fair price Orca LP token price of the SOL/USDC pool

{
"lpTokenPriceTask": {
"orcaPoolAddress": "APDFRM3HMr8CAGXwKHiu2f5ePSpaiEJhaURwhsRrUUt9",
"useFairPrice": true,
"priceFeedAddresses": [
"GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR",
"BjUgj6YCnFBZ49wF54ddBVA9qu8TeqkFtkbqmZcee8uW"
]
}
}

Example: Fetch the fair price Raydium LP token price of the SOL/USDC pool

{
"lpTokenPriceTask": {
"raydiumPoolAddress": "58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2",
"useFairPrice": true,
"priceFeedAddresses": [
"GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR",
"BjUgj6YCnFBZ49wF54ddBVA9qu8TeqkFtkbqmZcee8uW"
]
}
}
 lpExchangeRateTask

Fetch the current swap price for a given liquidity pool

Input: None

Returns: The swap price for a given AMM pool.

Example: Fetch the exchange rate from the Orca SOL/USDC pool

{
"lpExchangeRateTask": {
"orcaPoolAddress": "APDFRM3HMr8CAGXwKHiu2f5ePSpaiEJhaURwhsRrUUt9"
}
}

Example: Fetch the exchange rate from the Raydium SOL/USDC pool

{
"lpExchangeRateTask": {
"raydiumPoolAddress": "58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2"
}
}
 conditionalTask

This task will run the attempt on the 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.

Input: The current running numerical result output from a task.

Returns: A numerical result, else run on_failure subtasks.

Example: Returns the numerical result from the conditionalTask’s subtasks, else on_failure returns the numerical result from its subtasks.

{
"conditionalTask": {
"attempt": [
{
"tasks": [
{
"jupiterSwapTask": {
"inTokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outTokenAddress": "DUALa4FC2yREwZ59PHeu1un4wis36vHRv5hWVBmzykCJ"
}
}
]
}
],
"onFailure": [
{
"lpExchangeRateTask": {
"orcaPoolAddress": "7yJ4gMRJhEoCR48aPE3EAWRmCoygakik81ZS1sajaTnE"
}
}
]
}
}
 valueTask

Returns a specified value.

Input: None

Returns: A numerical result.

Example: Returns the value 10

{
"valueTask": {
"value": 10
}
}

Example: Returns the currentRound result of an aggregator

{
"valueTask": {
"aggregatorPubkey": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
}
}

Example: Returns the value stored in a CacheTask variable

{
"valueTask": {
"big": "${ONE}"
}
}
 maxTask

Returns the maximum value of all the results returned by the provided subtasks and subjobs. Nested tasks or jobs must return a Number.

Input: None

Returns: A numerical result.

Example: Returns the maximum numerical result from 3 tasks.

{
"maxTask": {
"tasks": [
{
"valueTask": {
"value": 10
}
},
{
"valueTask": {
"value": 20
}
},
{
"valueTask": {
"value": 30
}
}
]
}
}

Example: Returns the minimum numerical result from 3 jobs.

{
"maxTask": {
"jobs": [
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.com/api/v3/ticker/price?symbol=SOLUSDT"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.us/api/v3/ticker/price?symbol=SOLUSD"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://api-pub.bitfinex.com/v2/tickers?symbols=tSOLUSD"
}
},
{
"jsonParseTask": {
"path": "$[0][7]"
}
}
]
}
]
}
}
 regexExtractTask
 xstepPriceTask
 addTask

This task will add a numerical input by a scalar value from a job of subtasks, an aggregator, or a big.

Input: The current running numerical result output from a scalar value, an aggregator, a job of subtasks or a big.

Returns: A numerical result.

Example: Returns the numerical result by adding by a job of subtasks.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"addTask": {
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
}
]
}

Example: Returns the numerical result by multiplying by an aggregator.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"addTask": {
"aggregatorPubkey": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
}
}
]
}

Example: Returns the numerical result by multiplying by a big.

{
"tasks": [
{
"cacheTask": {
"cacheItems": [
{
"variableName": "TEN",
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
]
}
},
{
"valueTask": {
"value": 100
}
},
{
"addTask": {
"big": "${TEN}"
}
}
]
}
 subtractTask

This task will subtract a numerical input by a scalar value from a job of subtasks, an aggregator, or a big.

Input: The current running numerical result output from a scalar value, an aggregator, a job of subtasks or a big.

Returns: A numerical result.

Example: Returns the numerical result by subtracting by a job of subtasks.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"subtractTask": {
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
}
]
}

Example: Returns the numerical result by multiplying by an aggregator.

{
"tasks": [
{
"valueTask": {
"value": 100
}
},
{
"subtractTask": {
"aggregatorPubkey": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
}
}
]
}

Example: Returns the numerical result by multiplying by a big.

{
"tasks": [
{
"cacheTask": {
"cacheItems": [
{
"variableName": "TEN",
"job": {
"tasks": [
{
"valueTask": {
"value": 10
}
}
]
}
}
]
}
},
{
"valueTask": {
"value": 100
}
},
{
"subtractTask": {
"big": "${TEN}"
}
}
]
}
 twapTask

Takes a twap over a set period for a certain aggregator. Aggregators have an optional history buffer account storing the last N accepted results. The TwapTask will iterate over an aggregators history buffer and calculate the time weighted average of the samples within a given time period.

Input: None

Returns: The time weighted average of an aggregator over a given time period.

Example: The 1hr Twap of the SOL/USD Aggregator, requiring at least 60 samples.

{
"twapTask": {
"aggregatorPubkey": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR",
"period": 3600,
"minSamples": 60,
"weightByPropagationTime": true
}
}
 serumSwapTask
 powTask

Round the current running result to an exponential power.

Input: The current running numerical result.

Returns: The input raised to an exponential power.

Example: Raise 2 to the power of 3, 2^3

{
"tasks": [
{
"valueTask": {
"value": 2
}
},
{
"powTask": {
"scalar": 3
}
}
]
}
 lendingRateTask
 mangoPerpMarketTask

MangoPerpMarketTask

 jupiterSwapTask

Fetch the simulated price for a swap on JupiterSwap.

Input: None

Returns: The swap price on Jupiter for a given input and output token mint address.

Example: Fetch the JupiterSwap price for exchanging 1 SOL into USDC.

{
"jupiterSwapTask": {
"inTokenAddress": "So11111111111111111111111111111111111111112",
"outTokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
}
}

Example: Fetch the JupiterSwap price for exchanging 1000 SOL into USDC.

{
"jupiterSwapTask": {
"inTokenAddress": "So11111111111111111111111111111111111111112",
"outTokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"baseAmount": "1000"
}
}
 perpMarketTask

PerpMarketTask

 oracleTask

Fetch the current price of a Solana oracle protocol.

Input: None

Returns: The current price of an on-chain oracle.

Example: The Switchboard SOL/USD oracle price.

{
"oracleTask": {
"switchboardAddress": "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
}
}

Example: The Pyth SOL/USD oracle price.

{
"oracleTask": {
"pythAddress": "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"
}
}

Example: The Chainlink SOL/USD oracle price.

{
"oracleTask": {
"chainlinkAddress": "CcPVS9bqyXbD9cLnTbhhHazLsrua8QMFUHTutPtjyDzq"
}
}
 anchorFetchTask
 defiKingdomsTask
 tpsTask
 splStakePoolTask
 splTokenParseTask
 uniswapExchangeRateTask
 sushiswapExchangeRateTask
 pancakeswapExchangeRateTask
 cacheTask

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

Input: None

Returns: The input

Example: CacheTask storing ${ONE} = 1

{
"cacheTask": {
"cacheItems": [
{
"variableName": "ONE",
"job": {
"tasks": [
{
"valueTask": {
"value": 1
}
}
]
}
}
]
}
}
 sysclockOffsetTask
 marinadeStateTask
 solanaAccountDataFetchTask
 bufferLayoutParseTask
 cronParseTask

Return a timestamp from a crontab instruction.

Input: None

Returns: A timestamp

Example: Return the unix timestamp for the on-chain SYSCLOCK

{
"cronParseTask": {
"cronPattern": "* * * * * *",
"clockOffset": 0,
"clock": "SYSCLOCK"
}
}

Example: Return the unix timestamp for next friday at 5pm UTC

{
"cronParseTask": {
"cronPattern": "0 17 * * 5",
"clockOffset": 0,
"clock": 0
}
}
 minTask

Returns the minimum value of all the results returned by the provided subtasks and subjobs. Nested tasks or jobs must return a Number.

Input: None

Returns: A numerical result.

Example: Returns the minimum numerical result from 3 tasks.

{
"minTask": {
"tasks": [
{
"valueTask": {
"value": 10
}
},
{
"valueTask": {
"value": 20
}
},
{
"valueTask": {
"value": 30
}
}
]
}
}

Example: Returns the minimum numerical result from 3 jobs.

{
"minTask": {
"jobs": [
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.com/api/v3/ticker/price?symbol=SOLUSDT"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://www.binance.us/api/v3/ticker/price?symbol=SOLUSD"
}
},
{
"jsonParseTask": {
"path": "$.price"
}
}
]
},
{
"tasks": [
{
"httpTask": {
"url": "https://api-pub.bitfinex.com/v2/tickers?symbols=tSOLUSD"
}
},
{
"jsonParseTask": {
"path": "$[0][7]"
}
}
]
}
]
}
}
 historyFunctionTask

HistoryFunctionTask

 vwapTask

VwapTask

 ewmaTask
 comparisonTask
 roundTask

Round the current running result to a set number of decimal places.

Input: The current running numerical result.

Returns: The running result rounded to a set number of decimal places.

Example: Round down the running resul to 8 decimal places

{
"roundTask": {
"method": "METHOD_ROUND_DOWN",
"decimals": 8
}
}
 boundTask

Bound the running result to an upper/lower bound. This is typically the last task in an OracleJob.

Input: The current running numerical result.

Returns: The running result bounded to an upper or lower bound if it exceeds a given threshold.

Example: Bound the running result to a value between 0.90 and 1.10

{
"boundTask": {
"lowerBoundValue": "0.90",
"onExceedsLowerBoundValue": "0.90",
"upperBoundValue": "1.10",
"onExceedsUpperBoundValue": "1.10"
}
}