Skip to main content

SinkOracle

SinkOracle#

The intended client of this contract is an OptimisticOracle on a non-Mainnet network that needs price resolution secured by the DVM on Mainnet. If a registered contract, such as the OptimisticOracle, calls requestPrice() on this contract, then it will call the network's Bridge contract to signal to an off-chain relayer to bridge a price request to Mainnet.

Functions#

constructor(address _finderAddress, uint8 _chainID, uint8 _destinationChainID) (public)

Constructor.

Parameters:#

  • _finderAddress: Address of Finder that this contract uses to locate Bridge.
  • _chainID: Chain ID for this contract.
  • _destinationChainID: Chain ID for SourceOracle that will resolve price requests sent from this contract.
requestPrice(bytes32 identifier, uint256 time, bytes ancillaryData) (public)

This is the first method that should be called in order to bridge a price request to Mainnet.

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 ultimate price resolution data, and also calls 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:#

  • identifier: Identifier of price request.
  • time: Timestamp of price request.
  • ancillaryData: extra data of price request.
validateDeposit(uint8 sinkChainID, bytes32 identifier, uint256 time, bytes ancillaryData) (public)

This method will ultimately be called after requestPrice 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 price request, specifically one that has not resolved yet and was called by a registered contract. Without this check, Bridge.deposit() could be called by non-registered contracts to make price requests to the DVM.

Parameters:#

  • sinkChainID: Chain ID for this contract.
  • identifier: Identifier of price request.
  • time: Timestamp of price request.
  • ancillaryData: extra data of price request.
executePublishPrice(uint8 sinkChainID, bytes32 identifier, uint256 time, bytes ancillaryData, int256 price) (public)

This method will ultimately be called after a publishPrice has been bridged cross-chain from 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 publish the price data for a requested price request. If this method fails for some reason, then it means that the price was never requested. Can only be called by the GenericHandler.

Parameters:#

  • sinkChainID: Chain ID for this contract.
  • identifier: Identifier of price request to resolve.
  • time: Timestamp of price request to resolve.
  • ancillaryData: extra data of price request to resolve.
  • price: Price to publish to this oracle.
hasPrice(bytes32 identifier, uint256 time, bytes ancillaryData) โ†’ bool (public)

Returns whether a price has resolved for the request.

Parameters:#

  • identifier: Identifier of price request.
  • time: Timestamp of price request
  • ancillaryData: extra data of price request.
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.
getResourceId() โ†’ bytes32 (public)

Convenience method to get cross-chain Bridge resource ID linking this contract with the SourceOracle.

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

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

This helper method is useful for calling Bridge.deposit().

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

Parameters:#

  • chainID: Chain ID for this contract.
  • identifier: Identifier of price request.
  • time: Timestamp of price request.
  • ancillaryData: extra data of price request.
_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#

onlyRegisteredContract()
onlyGenericHandlerContract()