Skip to main content

SourceOracle

SourceOracle#

The intended client of this contract is some off-chain bot watching for resolved price events on the DVM. Once that bot sees a price has resolved, it can call publishPrice() on this contract which will call the local Bridge contract to signal to an off-chain relayer to bridge a price request to another network. This contract must be a registered financial contract in order to call DVM methods.

Functions#

constructor(address _finderAddress, uint8 _chainID) (public)

Constructor.

Parameters:#

  • _finderAddress: Address of Finder that this contract uses to locate Bridge.
  • _chainID: Chain ID for this contract. This is configurable by the deployer, rather than automatically detected via block.chainid because the type of currentChainId should match any sinkChainId's submitted as input to publishPrice(). publishPrice() calls Bridge.deposit() which expects a uint8 chainID passed as the first param, but block.chainid returns a uint256 value. Due to the possibility that a uint256 --> uint28 conversion leads to data loss and the complexity of mapping safely from uint256 --> uint8 on-chain, we opt to allow the user to specify a unique uint8 ID for this chain. It follows that the _chainID may not match with block.chainid.
publishPrice(uint8 sinkChainID, bytes32 identifier, uint256 time, bytes ancillaryData) (public)

This is the first method that should be called in order to publish a price request to another network marked by sinkChainID.

Publishes the DVM resolved price for the price request, or reverts if not resolved yet. Will call the local Bridge's deposit() method which will emit a Deposit event in order to signal to an off-chain relayer to begin the cross-chain process.

Parameters:#

  • sinkChainID: Chain ID of SinkOracle that this price should ultimately be sent to.
  • identifier: Identifier of price request to resolve.
  • time: Timestamp of price request to resolve.
  • ancillaryData: extra data of price request to resolve.
validateDeposit(uint8 sinkChainID, bytes32 identifier, uint256 time, bytes ancillaryData, int256 price) (public)

This method will ultimately be called after publishPrice calls Bridge.deposit(), which will call GenericHandler.deposit() and ultimately this method.

This method should basically check that the Bridge.deposit() was triggered by a valid publish event.

Parameters:#

  • sinkChainID: Chain ID of SinkOracle that this price should ultimately be sent to.
  • identifier: Identifier of price request to resolve.
  • time: Timestamp of price request to resolve.
  • ancillaryData: extra data of price request to resolve.
  • price: Price resolved on DVM to send to SinkOracle.
executeRequestPrice(uint8 sinkChainID, bytes32 identifier, uint256 time, bytes ancillaryData) (public)

This method will ultimately be called after a requestPrice has been bridged cross-chain from non-Mainnet to this network via an off-chain relayer. The relayer will call Bridge.executeProposal on this local network, which call GenericHandler.executeProposal() and ultimately this method.

This method should prepare this oracle to receive a published price and then forward the price request to the DVM. Can only be called by the GenericHandler.

Parameters:#

  • sinkChainID: Chain ID of SinkOracle that originally sent price request.
  • identifier: Identifier of price request.
  • time: Timestamp of price request.
  • ancillaryData: extra data of price request.
getResourceId() โ†’ bytes32 (public)

Convenience method to get cross-chain Bridge resource ID linking this contract with its SinkOracles.

More details about Resource ID's here: https://chainbridge.chainsafe.io/spec/#resource-id

_getOracle() โ†’ contract OracleAncillaryInterface (internal)

Return DVM for this network.

formatMetadata(uint8 chainID, bytes32 identifier, uint256 time, bytes ancillaryData, int256 price) โ†’ bytes (public)

This helper method is useful for shaping metadata that is passed into Bridge.deposit() that will ultimately be used to publish a price on the SinkOracle.

GenericHandler.deposit() expects data to be formatted as: len(data) uint256 bytes 0 - 32 data bytes bytes 32 - END

Parameters:#

  • chainID: Chain ID of SinkOracle to publish price to.
  • identifier: Identifier of price request to publish.
  • time: Timestamp of price request to publish.
  • ancillaryData: extra data of price request to publish.
_requestPrice(uint8 chainID, bytes32 identifier, uint256 time, bytes ancillaryData) (internal)

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

_finalizeRequest(uint8 chainID, bytes32 identifier, uint256 time, bytes ancillaryData) (internal)

Derived contract needs call this method in order to advance state from PendingRequest --> Requested before _publishPrice can be called.

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

Publishes price for a requested query. Will revert if request hasn't been requested yet or has been resolved already.

_finalizePublish(uint8 chainID, bytes32 identifier, uint256 time, bytes ancillaryData) (internal)
_getBridge() โ†’ contract IBridge (internal)

Returns Bridge contract on network.

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

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

Events#

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

Modifiers#

onlyGenericHandlerContract()