DataFeed

An overview of the core Warlock Oracle DataFeed contract.

DataFeed.sol serves as a central contract that facilitates all primary oracle related functionality:

  • Price updates

  • Price requests

    • Recent

    • Historic

  • Submitted data verification

With a single entry point for all activity Warlock is able to offer the scalable addition of assets, and a predictable request structure for consumers.

Unlike competitors/contemporaries which require unique deployments for every market pair, a consumer can request a price for any given market asset and base currency:

For example:

function getWarlockPrice() public returns(uint256) {
           address base = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; // USDC
           address asset = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; // WETH
           address DataFeed = "0xC0ffeEBABE5D496B2DDE509f9fa189C25cF29671";
           
           return (IDataFeed.getRecentPrice(asset,base));
}

Alongside this streamlined Oracle design, our batched liquidation system allows us to provide pricing for niche assets that may not be economically feasible in other contexts.

If you would like us to support a niche market for you, please reach out through our discord or telegram.


Technical Documentation

DataFeed

Git Source


State Variables

dataFeedSigner

The address of the Sauron dataFeedSigner Multisig / EOA which is authorized to sign price data.

address public dataFeedSigner;

dataFeedExecutor

The address of the Sauron executor Multisig / EOA which is authorized to execute price data updates.

address public dataFeedExecutor;

maximumDelay

The maximum delay in seconds that is allowed between the calculatedTimestamp and the submittedTimestamp.

uint256 public maximumDelay;

updateThreshold

The threshold in seconds that is used to determine if the price data is stale.

uint256 public updateThreshold;

admin

The address of the admin which is authorized to change the dataFeedSigner & maximumDelay.

address public admin;

prices

A mapping of asset -> base that returns priceData.

mapping(address => mapping(address => PriceData)) public prices;

historicPrices

A mapping of asset -> base -> timestamp that returns historic priceData.

mapping(address => mapping(address => mapping(uint128 => PriceData))) public historicPrices;

lastUpdated

A mapping of asset -> base that returns the lastUpdated timestamp.

mapping(address => mapping(address => uint128)) public lastUpdated;

nonces

We use a separate mapping for nonces to reduce gas costs on push.

mapping(address => mapping(address => uint128)) public nonces;

NAME

The EIP-712 domain name.

string public constant NAME = "SauronDataFeed";

domain

The EIP-712 domain separator, computed on construction.

bytes32 public immutable domain;

Functions

constructor

constructor(string memory version, address signer, address executor, uint256 delay, uint256 threshold);

setAdmin

Sets Admin.

function setAdmin(address _admin) public authorized(admin);

Parameters

NameTypeDescription

_admin

address

The new admin address

setSigner

Sets Signer.

function setSigner(address signer) public authorized(admin);

Parameters

NameTypeDescription

signer

address

The new signer address

setMaximumDelay

Sets maximum delay.

function setMaximumDelay(uint256 delay) public authorized(admin);

Parameters

NameTypeDescription

delay

uint256

The new maximum delay

getRecentPrice

Returns the most recent price data for a given asset/base pair.

function getRecentPrice(address asset, address base) public view returns (PriceData memory);

Parameters

NameTypeDescription

asset

address

The asset which a user is requesting the price of

base

address

The base currency that the asset is priced against

getHistoricPrice

Returns the historic price data for a given asset/base pair and nonce.

function getHistoricPrice(address asset, address base, uint128 nonce) public view returns (PriceData memory);

Parameters

NameTypeDescription

asset

address

The asset which a user is requesting the price of

base

address

The base currency that the asset is priced against

nonce

uint128

The timestamp of the requested historic price data

push

Allows any party to push a price update provided the data is valid and the updateThreshold has been exceeded.

function push(Hash.SubmittedData calldata submitted, Sig.Components calldata sig) public;

Parameters

NameTypeDescription

submitted

Hash.SubmittedData

The submitted price data

sig

Sig.Components

The dataFeedSigner's signature associated with the submitted price data

authPush

Allows only the authorized executor to push a price update without validating the updateThreshold.

function authPush(Hash.SubmittedData calldata submitted, Sig.Components calldata sig)
    public
    authorized(dataFeedExecutor);

Parameters

NameTypeDescription

submitted

Hash.SubmittedData

The submitted price data

sig

Sig.Components

The dataFeedSigner's signature associated with the submitted price data

validate

Checks the validity of submitted price data and it's signature.

function validate(Hash.SubmittedData calldata submitted, Sig.Components calldata sig) public view;

Parameters

NameTypeDescription

submitted

Hash.SubmittedData

The submitted price data

sig

Sig.Components

The dataFeedSigner's signature associated with the submitted price data

authorized

Allows only the authorized contract to execute the method.

modifier authorized(address a);

Parameters

NameTypeDescription

a

address

The authorized address


Events

PriceUpdate

event PriceUpdate(PriceData priceData);

Errors

Exception

A single custom error capable of indicating a wide range of detected errors by providing an error code value whose string representation is documented, and any possible other values that are pertinent to the error.

error Exception(uint8, uint256, uint256, address, address);

Structs

PriceData

A struct that contains the price data for a given asset/base pair round.

calculatedTimestamp The timestamp that the price data was calculated at

submittedTimestamp The block.timestamp that the price data was submitted at

submittedBlock The block number that the price data was submitted at

price The price of the asset/base pair

asset The asset which a user is requesting the price of

base The base currency that the asset is priced against

struct PriceData {
    uint128 calculatedTimestamp;
    uint128 submittedTimestamp;
    uint256 price;
    address asset;
    address base;
}

Last updated