Utilities

Oracle Utility Functions

The Oracle Utility Functions module provides methods for interacting with price oracles, including oracle enumeration, address lookup, and price feed operations.

Oracle Enumeration

getAllOracleNames

Retrieves all available oracle names from the configuration.

getAllOracleNames(): string[]

Example:

const oracleNames = mirageClient.oracle.getAllOracleNames()

Oracle Address Operations

getOracleNameFromAddress

Retrieves the oracle name for a given oracle object address.

getOracleNameFromAddress(
  oracleObjectAddress: string
): string

Example:

const oracleName = mirageClient.oracle.getOracleNameFromAddress(
  "0x123..."      // Oracle object address
)

Price Feed Operations

getPriceFeedId

Retrieves the price feed ID for a given oracle name.

getPriceFeedId(
  oracleName: string
): string

Example:

const feedId = mirageClient.oracle.getPriceFeedId(
  "APT_USD"       // Oracle name
)

getPriceFeedUpdateData

Retrieves the latest price feed update data for a given oracle.

async getPriceFeedUpdateData(
  oracleName: string
): Promise<number[]>

Example:

const updateData = await mirageClient.oracle.getPriceFeedUpdateData(
  "APT_USD"       // Oracle name
)

getPrice

Retrieves the current price for a given oracle.

async getPrice(
  oracleName: string
): Promise<number>

Example:

const price = await mirageClient.oracle.getPrice(
  "APT_USD"       // Oracle name
)
console.log(price) // Current price value

Oracle Views

The Oracle Views provide methods for retrieving on-chain oracle data and configurations.

getAllOracles

Retrieves all oracle objects from the blockchain.

async getAllOracles(): Promise<MoveObjectType[]>

Example:

const oracles = await mirageClient.oracle.views.getAllOracles()

getPriceFeedId

Retrieves the on-chain price feed ID for a given oracle object.

async getPriceFeedId(
  oracleObjectAddress: MoveObjectType
): Promise<string>

Example:

const feedId = await mirageClient.oracle.views.getPriceFeedId(
  oracleObject     // MoveObjectType
)

getOracleName

Retrieves the on-chain oracle name for a given oracle object.

async getOracleName(
  oracleObjAddress: MoveObjectType
): Promise<string>

Example:

const name = await mirageClient.oracle.views.getOracleName(
  oracleObject     // MoveObjectType
)

getOraclePriceMultiplier

Retrieves the price multiplier for a given oracle object.

async getOraclePriceMultiplier(
  oracleObjAddress: MoveObjectType
): Promise<number>

Example:

const multiplier = await mirageClient.oracle.views.getOraclePriceMultiplier(
  oracleObject     // MoveObjectType
)

Error Handling

The Oracle Utility Functions will throw errors in the following cases:

  • When attempting to get an oracle name for a non-existent oracle address
  • When attempting to get price feed information for a non-existent oracle name

All methods that interact with specific oracles validate the oracle existence before performing operations.