Skip to main content

Oracle API

import {JsonRpcClient} from '@defichain/jellyfish-api-jsonrpc'
const client = new JsonRpcClient('http://foo:bar@localhost:8554')

// Using client.oracle.
const something = await client.oracle.method()

appointOracle

Creates a price oracle for relay of real time price data.

client.oracle.appointOracle()
interface oracle {
appointOracle (address: string, priceFeeds: OraclePriceFeed[], options: AppointOracleOptions = {}): Promise<string>
}

interface OraclePriceFeed {
token: string
currency: string
}

interface AppointOracleOptions {
weightage?: number
utxos?: UTXO[]
}

interface UTXO {
txid: string
vout: number
}

removeOracle

Removes oracle.

client.oracle.removeOracle()
interface oracle {
removeOracle (oracleId: string, utxos: UTXO[] = []): Promise<string>
}

interface UTXO {
txid: string
vout: number
}

updateOracle

Update a price oracle for relay of real time price data.

client.oracle.updateOracle()
interface oracle {
updateOracle (oracleId: string, address: string, options: UpdateOracleOptions = {}): Promise<string>
}

interface UpdateOracleOptions {
priceFeeds?: OraclePriceFeed[]
weightage?: number
utxos?: UTXO[]
}

interface OraclePriceFeed {
token: string
currency: string
}

interface UTXO {
txid: string
vout: number
}

setOracleData

Set oracle data transaction.

client.oracle.setOracleData()
interface oracle {
setOracleData (oracleId: string, timestamp: number, options: SetOracleDataOptions = {}): Promise<string>
}

interface SetOracleDataOptions {
prices?: OraclePrice[]
utxos?: UTXO[]
}

interface OraclePrice {
tokenAmount: string
currency: string
}

interface UTXO {
txid: string
vout: number
}

getOracleData

Returns oracle data.

client.oracle.getOracleData()
interface oracle {
getOracleData (oracleId: string): Promise<OracleData>
}

interface OracleData {
oracleid: string
address: string
priceFeeds: OraclePriceFeed[]
tokenPrices: OracleTokenPrice[]
weightage: number
}

interface OraclePriceFeed {
token: string
currency: string
}

interface OracleTokenPrice {
token: string
currency: string
amount: number
timestamp: number
}

listOracles

Returns array of oracle ids.

client.oracle.listOracles()
interface oracle {
listOracles (): Promise<string[]>
}

listLatestRawPrices

Returns latest raw price updates from oracles.

client.oracle.listLatestRawPrices()
interface oracle {
listLatestRawPrices (priceFeed?: OraclePriceFeed): Promise<OracleRawPrice[]>
}

enum OracleRawPriceState {
LIVE = 'live',
EXPIRED = 'expired'
}

interface OracleRawPrice {
oracleid: string
priceFeeds: OraclePriceFeed
rawprice: BigNumber
weightage: BigNumber
state: OracleRawPriceState
timestamp: BigNumber
}

interface OraclePriceFeed {
token: string
currency: string
}

getPrice

Returns aggregated price from oracles.

client.oracle.getPrice()
interface oracle {
getPrice (priceFeed: OraclePriceFeed): Promise<BigNumber>
}

interface OraclePriceFeed {
token: string
currency: string
}

listPrices

List all aggregated prices.

client.oracle.listPrices()
interface oracle {
listPrices (): Promise<ListPricesData[]>
}

interface ListPricesData {
token: string
currency: string
price?: BigNumber
ok: boolean | string
}

getFixedIntervalPrice

Get fixed interval price.

client.oracle.getFixedIntervalPrice()
interface oracle {
getFixedIntervalPrice (id: string): Promise<FixedIntervalPrice>
}

interface FixedIntervalPrice {
activePriceBlock: number
nextPriceBlock: number
fixedIntervalPriceId: string
activePrice: BigNumber
nextPrice: BigNumber
timestamp: number
isLive: boolean
}

listFixedIntervalPrices

List all fixed interval prices.

client.oracle.listFixedIntervalPrices()
interface oracle {
listFixedIntervalPrices (
pagination: FixedIntervalPricePagination = {
limit: 100
}): Promise<ListFixedIntervalPrice[]>
}

interface FixedIntervalPricePagination {
start?: string
limit?: number
}

interface ListFixedIntervalPrice {
priceFeedId: string
activePrice: BigNumber
nextPrice: BigNumber
timestamp: number
isLive: boolean
}

getFutureSwapBlock

Get the next block that futures will execute and update on.

client.oracle.getFutureSwapBlock()
interface oracle {
getFutureSwapBlock (): Promise<number>
}