GitHub: ConnectOracle

Overview

The ConnectOracle contract is designed to interact with the Cosmos blockchain to fetch and process price data for various currency pairs from the Connect oracle.

Imports

Import FileDescription
ICosmos.solInterface for interacting with the Cosmos blockchain.
JsmnSolLib.solLibrary for JSON parsing.
IsoToUnix.solLibrary 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

constructor() {}

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

Functions

get_all_currency_pairs

Fetches all available currency pairs from the Cosmos blockchain.

function get_all_currency_pairs() external returns (string memory)

Returns

TypeDescription
string memoryA JSON string containing all currency pairs

get_price

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

function get_price(string memory base, string memory quote) external returns (Price memory)

Parameters

NameTypeDescription
basestring memoryThe base currency of the pair
quotestring memoryThe quote currency of the pair

Returns

TypeDescription
Price memoryA struct containing the price information

get_prices

Fetches prices for multiple currency pairs from the Cosmos blockchain.

function get_prices(string[] memory pair_ids) external returns (Price[] memory)

Parameters

NameTypeDescription
pair_idsstring[] memoryAn array of currency pair IDs

Returns

TypeDescription
Price[] memoryAn array of Price structs containing the price information for each pair

join

Concatenates an array of strings with a specified separator.

function join(string[] memory strs, string memory separator) internal pure returns (string memory)

Parameters

NameTypeDescription
strsstring[] memoryAn array of strings to be concatenated
separatorstring memoryA separator to be used between the strings

Returns

TypeDescription
string memoryThe concatenated string

get_price_from_tokens

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

function get_price_from_tokens(
    string memory json,
    JsmnSolLib.Token[] memory tokens,
    uint256 priceObjectIndex
) internal pure returns (Price memory)

Parameters

NameTypeDescription
jsonstring memoryThe JSON string containing the price information
tokensJsmnSolLib.Token[] memoryAn array of JSON tokens
priceObjectIndexuint256The starting index of the price object in the tokens array

Returns

TypeDescription
Price memoryA struct containing the parsed price information