> For the complete documentation index, see [llms.txt](https://mars-protocol.gitbook.io/mars-protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mars-protocol.gitbook.io/mars-protocol/contracts-core/oracle.md).

# Oracle

The Oracle contract provides prices in uusd for assets used in the protocol.

## Links

* package (msgs and types): <https://github.com/mars-protocol/mars-core/blob/master/packages/mars-core/src/oracle.rs>
* contract:  <https://github.com/mars-protocol/mars-core/blob/master/contracts/mars-oracle/src/contract.rs>
* schema: <https://github.com/mars-protocol/mars-core/tree/master/contracts/mars-oracle/schema>

## Config

| Key     | Type          | Description    |
| ------- | ------------- | -------------- |
| `owner` | CanonicalAddr | Contract owner |

## InstantiateMsg

{% tabs %}
{% tab title="Rust" %}

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "owner": "terra...", 
}
```

{% endtab %}
{% endtabs %}

| Key     | Type   | Description    |
| ------- | ------ | -------------- |
| `owner` | String | Contract owner |

## ExecuteMsg

### `UpdateConfig`

Updates the configuration of the contract. Can only be issued by the owner.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    UpdateConfig { 
        owner: Option<String> 
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "update_config": {
    "owner": "terra..." 
  }
}
```

{% endtab %}
{% endtabs %}

| Key       | Type   | Description          |
| --------- | ------ | -------------------- |
| `owner`\* | String | Address of new owner |

\* = optional

### `SetAsset`

Specifies parameters to query asset price.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    SetAsset {
        asset: Asset,
        price_source: PriceSourceUnchecked,
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "set_asset": {
    "asset": "terra...", 
    "price_source": {}
  }
}
```

{% endtab %}
{% endtabs %}

| Key            | Type   | Description                              |
| -------------- | ------ | ---------------------------------------- |
| `asset`        | String | Contract address for asset being queried |
| `price_source` | String | Price source unchecked                   |

### `RecordTwapSnapshots`

Fetches cumulative prices from Astroport pairs and records in contract storage.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    RecordTwapSnapshots {
        assets: Vec<Asset>
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "record_twap_snapshots": {
    "assets": [
      ["terra..."], 
      ["terra..."] 
    ]
  }
}
```

{% endtab %}
{% endtabs %}

| Key      | Type          | Description      |
| -------- | ------------- | ---------------- |
| `assets` | Vec<(String)> | Vector of assets |

## QueryMsg

### `Config`

Gets the Oracle contract configuration.

{% tabs %}
{% tab title="Rust" %}

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "config": {}
}
```

{% endtab %}
{% endtabs %}

### `AssetPriceSource`

Get asset's price source.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    AssetPriceSource {
        asset: Asset  
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "asset_price_source": {
    "asset": "terra..." 
  }
}
```

{% endtab %}
{% endtabs %}

| Key     | Type   | Description                           |
| ------- | ------ | ------------------------------------- |
| `asset` | String | Asset to get price source information |

### `AssetPrice`

Gets asset price given an asset.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    AssetPrice {
        asset: Asset
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "asset_price": {
    "asset": "terra..." 
  }
}
```

{% endtab %}
{% endtabs %}

| Key     | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| `asset` | String | Asset to get price information |

### `AssetPriceByReference`

Gets asset price given its internal reference. Meant to be used by protocol contracts only.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    AssetPriceByReference {
       asset_reference: Vec<u8> 
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "asset_price_by_reference": {
    "asset_reference": [
      [123], 
      [123] 
    ]
  }
}
```

{% endtab %}
{% endtabs %}

| Key               | Type     | Description     |
| ----------------- | -------- | --------------- |
| `asset_reference` | Vec\<u8> | Asset reference |
