Skip to main content

OracleSpoke

OracleSpoke#

This contract is primarily intended to receive messages on the child chain from a parent chain and allow contracts deployed on the child chain to interact with this contract as an Oracle. Moreover, this contract gives child chain contracts the ability to trigger cross-chain price requests to the mainnet DVM. This Spoke knows how to communicate with the parent chain via a "ChildMessenger" contract which directly communicates with the "ParentMessenger" on mainnet.

The intended client of this contract is an OptimisticOracle on sidechain that needs price resolution secured by the DVM on mainnet.

Functions#

constructor(address _finderAddress) (public)
requestPrice(bytes32 identifier, uint256 time, bytes ancillaryData) (public)

This is called to bridge a price request to mainnet. This method will enqueue a new price request or return silently if already requested. Price requests are relayed to mainnet (the "Parent" chain) via the ChildMessenger contract.

Can be called only by a registered contract that is allowed to make DVM price requests. Will mark this price request as Requested, and therefore able to receive the price resolution data from mainnet. Contract registration enables the DVM to validate that the calling contract correctly pays final fees. Therefore, this function does not directly attempt to pull a final fee from the caller.

Parameters:#

  • identifier: Identifier of price request.
  • time: Timestamp of price request.
  • ancillaryData: extra data of price request.
requestPrice(bytes32 identifier, uint256 time) (public)

Overloaded function to provide backwards compatibility for legacy financial contracts that do not use ancillary data.

processMessageFromParent(bytes data) (public)

Resolves a price request originating from a message sent by the DVM on the parent chain.

Can only be called by the ChildMessenger contract which is designed to communicate only with the ParentMessenger contract on Mainnet. See the SpokeBase for the onlyMessenger modifier.

Parameters:#

  • data: ABI encoded params with which to call _publishPrice.
hasPrice(bytes32 identifier, uint256 time, bytes ancillaryData) โ†’ bool (public)

Returns whether a price has resolved for the request. This method will not revert.

Parameters:#

  • identifier: Identifier of price request.
  • time: Timestamp of price request
  • ancillaryData: extra data of price request.
hasPrice(bytes32 identifier, uint256 time) โ†’ bool (public)

Overloaded function to provide backwards compatibility for legacy financial contracts that do not use ancillary data.

getPrice(bytes32 identifier, uint256 time, bytes ancillaryData) โ†’ int256 (public)

Returns resolved price for the request. Reverts if price is not available.

Parameters:#

  • identifier: Identifier of price request.
  • time: Timestamp of price request
  • ancillaryData: extra data of price request.
getPrice(bytes32 identifier, uint256 time) โ†’ int256 (public)

Overloaded function to provide backwards compatibility for legacy financial contracts that do not use ancillary data.

stampAncillaryData(bytes ancillaryData) โ†’ bytes (public)

Generates stamped ancillary data in the format that it would be used in the case of a price request.

Parameters:#

  • ancillaryData: ancillary data of the price being requested.
_stampAncillaryData(bytes ancillaryData) โ†’ bytes (internal)

We don't handle specifically the case where ancillaryData is not already readily translatable in utf8. For those cases, we assume that the client will be able to strip out the utf8-translatable part of the ancillary data that this contract stamps.

_preEntranceCheck() (internal)
_preEntranceSet() (internal)
_postEntranceReset() (internal)
getChildMessenger() โ†’ contract ChildMessengerInterface (public)

Returns the child messenger address set in the finder.

_requestPrice(bytes32 identifier, uint256 time, bytes ancillaryData) โ†’ bool (internal)

Enqueues a request (if a request isn't already present) for the given (identifier, time, ancillary data) combination. Will only emit an event if the request has never been requested.

_publishPrice(bytes32 identifier, uint256 time, bytes ancillaryData, int256 price) (internal)

Publishes price for a requested query.

Does not update price state if price is already resolved.

_encodePriceRequest(bytes32 identifier, uint256 time, bytes ancillaryData) โ†’ bytes32 (internal)

Returns the convenient way to store price requests, uniquely identified by {identifier, time, ancillaryData }.

Events#

PriceRequestAdded(bytes32 identifier, uint256 time, bytes ancillaryData, bytes32 requestHash)
PushedPrice(bytes32 identifier, uint256 time, bytes ancillaryData, int256 price, bytes32 requestHash)

Modifiers#

onlyRegisteredContract()
nonReentrant()

Prevents a contract from calling itself, directly or indirectly. Calling a nonReentrant function from another nonReentrant function is not supported. It is possible to prevent this from happening by making the nonReentrant function external, and making it call a private function that does the actual state modification.

nonReentrantView()

Designed to prevent a view-only method from being re-entered during a call to a nonReentrant() state-changing method.

onlyMessenger()