Injective | Documentation
InjectiveGithub
Injective | 中文文档
Injective | 中文文档
  • 关于 Injective
  • 快速入门
    • 钱包
      • 创建钱包
      • 账户
      • 质押
      • 治理
      • 拍卖
    • 代币标准
      • INJ 代币
      • Token Factory
      • CW20 标准
    • 交易
      • Gas 和 Fees
  • 指南
    • 创建钱包
    • 桥接
      • From Ethereum
      • Using Wormhole
      • Using IBC
      • From Solana
    • 发布代币
    • 发布市场
    • Denom 元数据
    • 获取INJ
  • 工具包
    • injectived
      • 安装 injectived
      • 使用 injectived
      • 指令
    • Injective TS SDK
    • Injective Go SDK
    • Injective Python SDK
    • Injective CW SDK
    • The Graph
  • 参考
  • 术语表
  • 开发者
    • 快速入门
      • 指南
        • 测试网提案
        • 转换地址
        • 计算
          • 最低价格刻度
          • 最低数量刻度
    • 交易所开发者
      • 构建 DEX
      • 预言机提供方
    • Cosmwasm 开发者
      • 您的首个智能合约
      • 指南
        • 本地开发
        • 主网开发
        • 给部署地址白名单
        • 创建您的 Swap 合约
        • 创建 UIs
      • CW20 适配器
      • Injective Test Tube
    • 模块
      • Injective
        • 拍卖(Auction)
          • State
          • 消息
          • EndBlock
          • 事件
          • 参数
        • 交易所(Exchange)
          • 衍生品市场概念
          • 现货市场概念
          • 二元期权市场概念
          • 其他概念
          • 状态
          • 状态转换
          • 消息
          • 提案
          • BeginBlock
          • EndBlock
          • 事件
          • 参数
          • MsgPrivilegedExecuteContract
        • 保险(Insurance)
          • 状态
          • 状态转换
          • 消息
          • EndBlock
          • 事件
          • 参数
          • 改进
        • OCR
          • 概念
          • 状态
          • 消息
          • 提案
          • BeginBlock
          • 钩子(Hooks)
          • 事件
          • 参数
        • 预言机(Oracle)
          • 状态
          • Keeper
          • 消息
          • 提案
          • 事件
          • 改进
        • Peggy
          • 定义
          • 工作流
          • 状态
          • 消息
          • 处罚
          • EndBlock
          • 事件
          • 参数
          • 中继语义
          • 改进
        • 权限(Permissions)
          • 概念
          • 状态
          • 状态转换
        • 代币工厂(TokenFactory)
          • 概念
          • 状态
          • 消息
          • 事件
          • 参数
        • WasmX
          • 概念
          • 数据
          • 提案
          • 消息
          • 参数
      • 核心
        • Auth
        • AuthZ
        • 银行(Bank)
        • 共识(Consensus)
        • 危机(Crisis)
        • 分发(Distribution)
        • 证据(Evidence)
        • 费用授权(Feegrant)
        • 治理(Gov)
        • 群组(Group)
        • 铸造(Mint)
        • NFT
        • 参数(Params)
        • 惩罚(Slashing)
        • 质押(Staking)
        • 升级(Upgrade)
        • Circuit
        • Genutils
    • dApps 开发文档
  • 节点
    • 快速入门
      • 和节点交互
      • 运行节点
        • 设置密钥环
        • 加入网络
        • Cosmovisor
        • 升级您的节点
    • 验证者
      • 主网
        • Peggo
        • 规范链升级
          • Upgrade to 10002-rc1
          • Upgrade to 10002-rc2
          • Upgrade to 10003-rc1
          • Upgrade to 10004-rc1
          • Upgrade to 10004-rc1-patch
          • Upgrade to 10005-rc1
          • Upgrade to 10006-rc1
          • Upgrade to 10007-rc1
          • Upgrade to 10008 - Camelot
          • Upgrade to 10009
          • Upgrade to v1.10
          • Upgrade to v1.11
          • Upgrade to v1.12.0 - Volan
          • Upgrade to v1.12.1
          • Upgrade to v1.13.0 - Altaris
          • Upgrade to v1.13.2
          • Upgrade to v1.13.3
          • Upgrade to v1.14.0
          • Upgrade to v1.14.1
      • 测试网
        • 测试网 Peggo
    • 公共端点
    • 高级端点
    • Injective 索引器设置
  • 交易员
    • 快速入门
    • 文档
    • API 参考
  • 常用链接
    • Injective 101
    • Injective Hub
    • Injective 浏览器
    • Chain API Reference
    • Indexer API Reference
    • 测试网水龙头
Powered by GitBook
On this page
  • Params
  • PriceState
  • Band
  • Band IBC
  • Coinbase
  • Pricefeed
  • Provider
  • Pyth
  • Stork
Export as PDF
  1. 开发者
  2. 模块
  3. Injective
  4. 预言机(Oracle)

状态

Params

oracle模块参数:

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

  string pyth_contract = 1;
}

PriceState

PriceState是一个通用类型,用于管理所有oracle类型的累计价格、最新价格及其时间戳。

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;
}

其中:

  • Price 表示标准化的小数价格

  • CumulativePrice 表示自oracle价格源创建以来的累计价格

  • Timestamp 表示价格状态被中继的区块时间

公式:

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

Band

给定符号的Band价格数据表示和存储如下:

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

message BandPriceState {
    string symbol = 1;
    string rate = 2 [(gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false];
    uint64 resolve_time = 3;
    uint64 request_ID = 4;
    PriceState price_state = 5 [(gogoproto.nullable) = false];
}

请注意,Rate 是从Band链获取的符号的原始USD汇率,经过1e9的缩放(例如,1.42的价格为1420000000),而PriceState 存储的是标准化的小数价格(例如,1.42)。

Band中继者通过其地址存储如下:

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

Band IBC

本节描述了通过IBC连接到Band链以维护价格的所有状态管理。

  • LatestClientID 用于管理Band IBC数据包的唯一clientID。当发送价格请求数据包到bandchain时,它会增加1。

  • LatestClientID: 0x32 -> 格式化(LatestClientID)

  • LatestRequestID 用于管理唯一的BandIBCOracleRequests。在创建新的BandIBCOracleRequest时,值会增加1。

  • LatestRequestID: 0x36 -> 格式化(LatestRequestID)

给定符号的Band IBC价格数据存储如下:

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

message BandPriceState {
  string symbol = 1;
  string rate = 2 [(gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false];
  uint64 resolve_time = 3;
  uint64 request_ID = 4;
  PriceState price_state = 5 [(gogoproto.nullable) = false];
}
  • 当发送价格请求数据包到bandchain时,BandIBCCallDataRecord 存储如下

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

message CalldataRecord {
  uint64 client_id = 1;
  bytes calldata = 2;
}
  • 当治理配置oracle请求发送时,BandIBCOracleRequest 存储如下:

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

message BandOracleRequest {
  // Unique Identifier for band ibc oracle request
  uint64 request_id = 1;

  // OracleScriptID is the unique identifier of the oracle script to be executed.
  int64 oracle_script_id = 2;

  // Symbols is the list of symbols to prepare in the calldata
  repeated string symbols = 3;

  // AskCount is the number of validators that are requested to respond to this
  // oracle request. Higher value means more security, at a higher gas cost.
  uint64 ask_count = 4;

  // MinCount is the minimum number of validators necessary for the request to
  // proceed to the execution phase. Higher value means more security, at the
  // cost of liveness.
  uint64 min_count = 5;

  // FeeLimit is the maximum tokens that will be paid to all data source providers.
  repeated cosmos.base.v1beta1.Coin fee_limit = 6 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];

  // PrepareGas is amount of gas to pay to prepare raw requests
  uint64 prepare_gas = 7;
  // ExecuteGas is amount of gas to reserve for executing
  uint64 execute_gas = 8;
}
  • BandIBCParams 存储如下,并由治理配置:

  • BandIBCParams: 0x35 -> ProtocolBuffer(BandIBCParams)

BandIBCParams 包含与band链的IBC连接信息。

message BandIBCParams {
  // true if Band IBC should be enabled
  bool band_ibc_enabled = 1;
  // block request interval to send Band IBC prices
  int64 ibc_request_interval = 2;
  // band IBC source channel
  string ibc_source_channel = 3;
  // band IBC version
  string ibc_version = 4;
  // band IBC portID
  string ibc_port_id = 5;
}

注意:

  • BandIbcEnabled 描述了band IBC连接的状态

  • IbcSourceChannel、IbcVersion、IbcPortId 是IBC连接所需的常见参数

  • IbcRequestInterval 描述了在Injective链的BeginBlock时自动触发的价格获取请求间隔

Coinbase

给定符号("key")的Coinbase价格数据表示和存储如下:

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

message CoinbasePriceState {
  // kind should always be "prices"
  string kind = 1;
  // timestamp of the when the price was signed by coinbase
  uint64 timestamp = 2;
  // the symbol of the price, e.g. BTC
  string key = 3;
  // the value of the price scaled by 1e6
  uint64 value = 4;
  // the price state
  PriceState price_state = 5 [(gogoproto.nullable) = false];
}

请注意,Value 是从Coinbase获取的原始USD价格数据,经过1e6的缩放(例如,1.42的价格为1420000),而PriceState 存储的是标准化的小数价格(例如,1.42)。

Pricefeed

给定基础报价对的价格源数据表示和存储如下:

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

message PriceFeedInfo {
  string base = 1;
  string quote = 2;
}
  • PriceFeedPriceState: 0x12 + Keccak256Hash(base + quote) -> PriceFeedPriceState

message PriceFeedState {
  string base = 1;
  string quote = 2;
  PriceState price_state = 3;
  repeated string relayers = 4;
}
  • PriceFeedRelayer: 0x13 + Keccak256Hash(base + quote) + relayerAddr -> relayerAddr

Provider

提供者价格源数据表示和存储如下:

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

message ProviderInfo {
  string provider = 1;
  repeated string relayers = 2;
}
  • ProviderIndex: 0x62 + relayerAddress -> provider

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

message ProviderPriceState {
  string symbol = 1;
  PriceState state = 2;
}

Pyth

Pyth价格数据表示和存储如下:

  • PythPriceState: 0x71 + priceID -> PythPriceState

message PythPriceState {
  bytes price_id = 1;
  string ema_price = 2 [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false];
  string ema_conf = 3 [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false];
  string conf = 4 [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false];
  uint64 publish_time = 5;
  PriceState price_state = 6 [(gogoproto.nullable) = false];
}

Stork

Stork价格数据表示和存储如下:

  • StorkPriceState: 0x81 + symbol -> PythPriceState

message StorkPriceState {
  // timestamp of the when the price was signed by stork
  uint64 timestamp = 1;
  // the symbol of the price, e.g. BTC
  string symbol = 2;
  // the value of the price scaled by 1e18
  string value = 3 [
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  // the price state
  PriceState price_state = 5 [ (gogoproto.nullable) = false ];
}

Stork发布者数据表示和存储如下:

  • Publisher: 0x82 + stork_publisher -> publisher

string stork_publisher
Previous预言机(Oracle)NextKeeper

Last updated 2 months ago

请注意,CumulativePrice 值遵循设定的约定,并用于允许模块计算两个任意区块时间间隔(t1,t2)之间的时间加权平均价格(TWAP)。

关于Coinbase价格oracle的更多详细信息可以在以及这篇解释性中找到。

Uniswap V2 Oracle
Coinbase API文档
博客文章