TeFi Oracle

The TeFi oracle is a set of smart contracts that support price oracles used across multiple DeFi protocols built on top of Terra blockchain, providing an interface for accessing the latest reported prices for the assets provided by its whitelisted oracle services. Price quotes are kept up-to-date by oracle providers that fetch exchange rates for real-world assets from reputable sources.

On the Mirror Protocol, these prices are used for CDP operations (mint, burn, short, deposit, withdraw) while the price feed is active. Prices are considered stale when there is no new valid price for 60 seconds.

Smart Contracts

Hub

The Hub contract is a central directory for all oracle price providers and their proxies. On the Mirror Protocol, the Hub contract is owned by the Mirror Governance contract, and transactions can only be called through Mirror’s governance consensus.

Through the interaction with the Hub contract, the following actions can happen:

  • Whitelisting a new oracle service provider

  • Registering new price sources on an existing proxy

  • Removing and changing priorities of already existing prices

InstantiateMsg

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InstantiateMsg {
    pub owner: String,
    pub base_denom: String,
    pub max_proxies_per_symbol: u8,
}

ExecuteMsg

All Oracle Hub contract operations can be only called by owner - Mirror Factory, which is owned by Mirror Governance.

UpdateOwner

Operation to update owner of the Hub contract.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
UpdateOwner { 
    owner: String 
    },

UpdateMaxProxies

Operation used to update the maximum number of price sources that can be registered per mAsset

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	UpdateMaxProxies { max_proxies_per_symbol: u8 },

RegisterSource

The operation used to register a new price source for an asset. Source can only be registered once a proxy is whitelisted to the Hub contract through the WhitelistProxy operation.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	RegisterSource {
        symbol: String,
        proxy_addr: String,
        priority: Option<u8>,
    }

BulkRegisterSource

Registers multiple sources in one transaction.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	BulkRegisterSource {
        sources: Vec<(String, String, Option<u8>)>, // (symbol, proxy_addr, priority)
    },

UpdateSourcePriorityList

Updates the priorities for proxies that are already registered

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	UpdateSourcePriorityList {
        symbol: String,
        priority_list: Vec<(String, u8)>,
    }

RemoveSource

Removes a price source of a specified asset symbol from a proxy address.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	RemoveSource { 
		symbol: String, 
		proxy_addr: String 
},

WhitelistProxy

Whitelists a new proxy contract as a price source. After the proxy is whitelisted, it can be registered as a source.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	WhitelistProxy {
        proxy_addr: String,
        provider_name: String,
    },

RemoveProxy

Removes a whitelisted proxy contract entirely from the Hub contract. This is different from RemoveSource which only removes a single price of an asset, instead of removing the entire set of prices from the proxy.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	RemoveProxy { 
		proxy_addr: String
},

InsertAssetSymbolMap

Updates the map of asset_token to symbol. Asset mapping storage is overwritten by this operation if it already exists.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubExecuteMsg {
	InsertAssetSymbolMap {
        map: Vec<(String, String)>, // (address, symbol)
    },

QueryMsg

Config

Returns the configuration of the Oracle Hub contract

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    Config {},

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ConfigResponse {
    pub owner: String,
    pub base_denom: String,
    pub max_proxies_per_symbol: u8,
}

ProxyWhitelist

Returns the list of whitelisted proxies / oracle providers.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    ProxyWhitelist {},

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ProxyWhitelistResponse {
    pub proxies: Vec<ProxyInfoResponse>,
}

//ProxyInfoResponse
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ProxyInfoResponse {
    pub address: String,
    pub provider_name: String,
}

AllSources

Returns the list of all symbols with all the sources

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
        AllSources {
        start_after: Option<String>, // symbol for pagination
        limit: Option<u32>,
    },

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct AllSourcesResponse {
    pub list: Vec<SourcesResponse>,
}

//SourceResponse
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct PriceListResponse {
    pub price_list: Vec<(u8, ProxyInfoResponse, PriceQueryResult)>, // (priority, proxy_info, result)
}

Sources

Returns the information all registered proxies for the provided asset_token.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    Sources { asset_token: String },

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct SourcesResponse {
    pub symbol: String,
    pub proxies: Vec<(u8, ProxyInfoResponse)>,
}

SourcesBySymbol

Returns the information of all registered proxies for a provided asset_token.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    SourcesBySymbol { symbol: String },

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct SourcesResponse {
    pub symbol: String,
    pub proxies: Vec<(u8, ProxyInfoResponse)>,
}

Price

Queries the highest priority available price within the timeframe. If timeframe is not provided, the age of the price will be ignored.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    Price {
        asset_token: String,
        timeframe: Option<u64>,
    },

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct PriceResponse {
    pub rate: Decimal,
    pub last_updated: u64,
}

PriceBySymbol

Returns the highest priority available price within the time frame, using the symbol instead of the asset token address. If timeframe is not provided, it will be ignored.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
        PriceBySymbol {
        symbol: String,
        timeframe: Option<u64>,
    },

Response

Same as Price QueryMsg

PriceList

Returns all registered proxy prices for the provided asset_token

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    PriceList { asset_token: String },

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct PriceListResponse {
    pub price_list: Vec<(u8, ProxyInfoResponse, PriceQueryResult)>, // (priority, proxy_info, result)
}

PriceListBySymbol

Returns all registered proxy prices for the provided asset_token.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    PriceListBySymbol { symbol: String },

Response

Same as PriceList

AssetSymbolMap

Returns the map of asset_token to symbol

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    AssetSymbolMap {
        start_after: Option<String>, // address for pagination
        limit: Option<u32>,
    },

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct AssetSymbolMapResponse {
    pub map: Vec<(String, String)>, // address, symbol
}

CheckSource

Check to see if proxy_addr is whitelisted and has price feed for the specified symbol. Returns the PriceResponse or error to check if the price feed is valid or not.

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HubQueryMsg {
    CheckSource { proxy_addr: String, symbol: String },

Response

Same as PriceResponse or an Error

Last updated