# Oracle について ###### tags: `Yellow paper` `oracle` ## 構成 ### core オラクルノードの本体 ### contracts 実際に Rollup 場にデプロイされるコントラクト本体 ### tools oracle ノード運用をサポートする外部ツール。 integration/forks - integration test for ommers and re-orgs tools - Chainlink tools Ref: https://github.com/smartcontractkit/chainlink -> ## 最小構成 Oracle node + Agregator contract + その wrap した `oracle`. Aggregator contract を任意の情報の oracle format として扱う。 https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol この情報について、正式に採用されたもの(Governance で決まったもの)について `oracle` library に追加される。 `oracle` library の変更は接頭辞 `oracle.` の指し示すコントラクトアドレスの変更を示す特殊なコードを追加する。 ## Example ### How to use ```solidity= import "oracle"; ... function getUSDPrice() returns (uint256) { return oracle.usd.price(); } function getETHPrice() returns (uint256) { return oracle.eth.price(); } ``` ### `oracle` ```solidity= library oracle is Governance { address usd_oracle; function usd() returns (Pricer) { return Pricer(usd_oracle); } function migration(address nextOracle) onlyGovernance { // It will change the address that other contracts call `oracle` lib. this.migrate(nextOracle); } } contract Pricer { address root; function price() returns (uint256) { reutrn AggregatorV3Interface(root).latestRoundData().answer; } } ``` ### 備考 柔軟性のため `migrate` を新規導入した。 library の示すアドレスを変更する OPCODE. > https://hackmd.io/e548XcYzSvW3o63Pj4Nwnw?view 価格の合意形成は投票の中央値