> ## Documentation Index
> Fetch the complete documentation index at: https://docs.initia.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# ConnectOracle

GitHub:
[ConnectOracle](https://github.com/initia-labs/minievm/blob/main/x/evm/contracts/connect_oracle/ConnectOracle.sol)

## Overview

The `ConnectOracle` contract interacts with the Cosmos blockchain to fetch and
process price data for various currency pairs from the Connect Oracle.

## Imports

| Import File      | Description                                                 |
| ---------------- | ----------------------------------------------------------- |
| `ICosmos.sol`    | Interface for interacting with the Cosmos blockchain.       |
| `JsmnSolLib.sol` | Library for JSON parsing.                                   |
| `IsoToUnix.sol`  | Library for converting ISO date strings to Unix timestamps. |

## Structs

### Price

A struct to hold price information.

* `uint256 price`: The price value.
* `uint256 timestamp`: The timestamp of the price.
* `uint64 height`: The block height at which the price was recorded.
* `uint64 nonce`: A unique identifier for the price record.
* `uint64 decimal`: The decimal precision of the price.
* `uint64 id`: The ID of the price record.

## Constructor

```solidity theme={null}
constructor() {}
```

The constructor initializes the contract. It does not take any parameters or
perform any actions upon deployment.

## Functions

### get\_price

Fetches the price for a specific currency pair from the Cosmos blockchain.

```solidity theme={null}
function get_price(string memory base, string memory quote) external returns (Price memory)
```

#### Parameters

| Name    | Type            | Description                     |
| ------- | --------------- | ------------------------------- |
| `base`  | `string memory` | The base currency of the pair.  |
| `quote` | `string memory` | The quote currency of the pair. |

#### Returns

| Type           | Description                                |
| -------------- | ------------------------------------------ |
| `Price memory` | A struct containing the price information. |

### get\_prices

Fetches prices for multiple currency pairs from the Cosmos blockchain.

```solidity theme={null}
function get_prices(string[] memory pair_ids) external returns (Price[] memory)
```

#### Parameters

| Name       | Type              | Description                    |
| ---------- | ----------------- | ------------------------------ |
| `pair_ids` | `string[] memory` | An array of currency pair IDs. |

#### Returns

| Type             | Description                                                                 |
| ---------------- | --------------------------------------------------------------------------- |
| `Price[] memory` | An array of `Price` structs containing the price information for each pair. |

### join

Concatenates an array of strings with a specified separator.

```solidity theme={null}
function join(string[] memory strs, string memory separator) internal pure returns (string memory)
```

#### Parameters

| Name        | Type              | Description                                 |
| ----------- | ----------------- | ------------------------------------------- |
| `strs`      | `string[] memory` | An array of strings to be concatenated.     |
| `separator` | `string memory`   | A separator to be used between the strings. |

#### Returns

| Type            | Description              |
| --------------- | ------------------------ |
| `string memory` | The concatenated string. |

### get\_price\_from\_tokens

Parses a JSON string to extract price information and populate a `Price` struct.

```solidity theme={null}
function get_price_from_tokens(
    string memory json,
    JsmnSolLib.Token[] memory tokens,
    uint256 priceObjectIndex
) internal pure returns (Price memory)
```

#### Parameters

| Name               | Type                        | Description                                                 |
| ------------------ | --------------------------- | ----------------------------------------------------------- |
| `json`             | `string memory`             | The JSON string containing the price information.           |
| `tokens`           | `JsmnSolLib.Token[] memory` | An array of JSON tokens.                                    |
| `priceObjectIndex` | `uint256`                   | The starting index of the price object in the tokens array. |

#### Returns

| Type           | Description                                       |
| -------------- | ------------------------------------------------- |
| `Price memory` | A struct containing the parsed price information. |
