State

Params

The oracle module parameters.

message Params {
  option (gogoproto.equal) = true;

  string pyth_contract = 1;
}

PriceState

PriceState is common type to manage cumulative price and latest price along with timestamp for all oracle types.

message PriceState {
    string price = 1 [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false];
    
    string cumulative_price = 2 [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false];
    
    int64 timestamp = 3;
}

where

  • Price represents the normalized decimal price

  • CumulativePrice represents the cumulative price for a given oracle price feed since the start of the oracle price feed's creation.

  • Timestamp represents the time at which the blocktime at which the price state was relayed.

Note that the CumulativePrice value follows the convention set by the Uniswap V2 Oracle and is used to allows modules to calculate Time-Weighted Average Price (TWAP) between 2 arbitrary block time intervals (t1, t2).

$\mathrm{TWAP = \frac{CumulativePrice_2 - CumulativePrice_1}{Timestamp_2 - Timestamp_1}}$

Band

Band price data for a given symbol are represented and stored as follows:

  • BandPriceState: 0x01 | []byte(symbol) -> ProtocolBuffer(BandPriceState)

Note that the Rate is the raw USD rate for the Symbol obtained from the Band chain which has is scaled by 1e9 (e.g. a price of 1.42 is 1420000000) while the PriceState has the normalized decimal price (e.g. 1.42).

Band relayers are stored by their address as follows.

  • BandRelayer: 0x02 | RelayerAddr -> []byte{}

Band IBC

This section describes all the state management to maintain the price by connecting to Band chain via IBC.

  • LatestClientID is maintained to manage unique clientID for band IBC packets. It is increased by 1 when sending price request packet into bandchain.

  • LatestClientID: 0x32 -> Formated(LatestClientID)

  • LatestRequestID is maintained to manage unique BandIBCOracleRequests. Incremented by 1 when creating a new BandIBCOracleRequest.

  • LatestRequestID: 0x36 -> Formated(LatestRequestID)

  • Band IBC price data for a given symbol is stored as follows:

  • BandPriceState: 0x31 | []byte(symbol) -> ProtocolBuffer(BandPriceState)

  • BandIBCCallDataRecord is stored as follows when sending price request packet into bandchain:

  • CalldataRecord: 0x33 | []byte(ClientId) -> ProtocolBuffer(CalldataRecord)

  • BandIBCOracleRequest is stored as follows when the governance configure oracle requests to send:

  • BandOracleRequest: 0x34 | []byte(RequestId) -> ProtocolBuffer(BandOracleRequest)

  • BandIBCParams is stored as follows and configured by governance:

  • BandIBCParams: 0x35 -> ProtocolBuffer(BandIBCParams)

BandIBCParams contains the information for IBC connection with band chain.

Note:

  1. BandIbcEnabled describes the status of band ibc connection

  2. IbcSourceChannel, IbcVersion, IbcPortId are common parameters required for IBC connection.

  3. IbcRequestInterval describes the automatic price fetch request interval that is automatically triggered on injective chain on beginblocker.

Coinbase

Coinbase price data for a given symbol ("key") are represented and stored as follows:

  • CoinbasePriceState: 0x21 | []byte(key) -> CoinbasePriceState

More details about the Coinbase price oracle can be found in the Coinbase API docs as well as this explanatory blog post.

Note that the Value is the raw USD price data obtained from Coinbase which has is scaled by 1e6 (e.g. a price of 1.42 is 1420000) while the PriceState has the normalized decimal price (e.g. 1.42).

Pricefeed

Pricefeed price data for a given base quote pair are represented and stored as follows:

  • PriceFeedInfo: 0x11 + Keccak256Hash(base + quote) -> PriceFeedInfo

  • PriceFeedPriceState: 0x12 + Keccak256Hash(base + quote) -> PriceFeedPriceState

  • PriceFeedRelayer: 0x13 + Keccak256Hash(base + quote) + relayerAddr -> relayerAddr

Provider

Provider price feeds are represented and stored as follows:

  • ProviderInfo: 0x61 + provider + @@@ -> ProviderInfo

  • ProviderIndex: 0x62 + relayerAddress -> provider

  • ProviderPrices: 0x63 + provider + @@@ + symbol -> ProviderPriceState

Pyth

Pyth prices are represented and stored as follows:

  • PythPriceState: 0x71 + priceID -> PythPriceState

Stork

Stork prices are represented and stored as follows:

  • StorkPriceState: 0x81 + symbol -> PythPriceState

Stork publishers are represented and stored as follows:

  • Publisher: 0x82 + stork_publisher -> publisher

Last updated