Introduction

Keep3rV1Oracle is an on-chain oracle for UniswapV2 pairs.

Keep3rV1Oracle

Keep3rV1Oracles are sliding window oracles that use observations collected over a window to provide moving price averages in the past windowSize with a precision of windowSize / granularity.

The windowSize is based on the granularity supplied by the user. There is a reading every periodSize minutes.

Price Feeds

Data Freshness

Contract: Keep3rV1Oracle

// returns the amount out corresponding to the amount in for a given token using the moving average over the time
function current(address tokenIn, uint amountIn, address tokenOut) external view returns (uint amountOut)

Example;

interface IUniswapV2Oracle {
  function current(address tokenIn, uint amountIn, address tokenOut) external view returns (uint amountOut);
}

Security

Contract: Keep3rV1Oracle

A quote allows the caller to specify the granularity or amount of points to take. Each point is periodSize, so 24 points would be 24 * periodSize windowSize

Data freshness is decreased for increased security

// returns the amount out corresponding to the amount in for a given token using the moving average over the time taking granularity samples
function quote(address tokenIn, uint amountIn, address tokenOut, uint granularity) external view returns (uint amountOut)

Price points

Returns a set of price points equal to points * periodSize, so for the points in the last 24 hours use points = 48

// returns an amount of price points equal to periodSize * points
prices(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)

Hourly

Returns a set of price points equal to points * hours, so for the points in the last 24 hours use points = 24

// returns an amount of price points equal to hour * points
function hourly(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)

Daily

Returns a set of price points equal to points * days, so for the points in the last 24 hours use points = 1

// returns an amount of price points equal to days * points
function daily(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)

Weekly

Returns a set of price points equal to points * weeks, so for the points in the last week use points = 1

// returns an amount of price points equal to days * points
function weekly(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)

Volatility

Contract: Keep3rV1Volatility

Realized Volatility

Returns the realized volatility over the last amount of points per window * periodSize, so volatility over last hour would be points = 1 & window = 2

// returns realized volatility over points * window
function rVol(address tokenIn, address tokenOut, uint points, uint window) external view returns (uint)

Hourly Realized Volatility

Returns the realized volatility over the last amount of points per hour, so volatility over last hour would be points = 1

// returns realized volatility over points * window
function rVolHourly(address tokenIn, address tokenOut, uint points) external view returns (uint);

Daily Realized Volatility

Returns the realized volatility over the last amount of points per days, so volatility over last day would be points = 1

// returns realized volatility over points * window
function rVolDaily(address tokenIn, address tokenOut, uint points) external view returns (uint);

Weekly Realized Volatility

Returns the realized volatility over the last amount of points per weeks, so volatility over last day week be points = 1

// returns realized volatility over points * window
function rVolWeekly(address tokenIn, address tokenOut, uint points) external view returns (uint);

Pricing

Black Scholes Estimate

Contract: Keep3rV1Oracle

/**
 * @dev blackScholesEstimate calculates a rough price estimate for an ATM option
 * @dev input parameters should be transformed prior to being passed to the function
 * @dev so as to remove decimal places otherwise results will be far less accurate
 * @param _vol uint256 volatility of the underlying converted to remove decimals
 * @param _underlying uint256 price of the underlying asset
 * @param _time uint256 days to expiration in years multiplied to remove decimals
 */
function blackScholesEstimate(
    uint256 _vol,
    uint256 _underlying,
    uint256 _time
) external pure returns (uint256 estimate);

Options Pricing

Contract: Keep3rV1Volatility

function C(uint t, uint v, uint sp, uint st) external pure returns (uint);
function quoteAll(uint t, uint v, uint sp, uint st) external pure returns (uint call, uint put);
function quotePrice(address tokenIn, address tokenOut, uint t, uint sp, uint st) external view returns (uint call, uint put);
function price(address tokenIn, address tokenOut) external view returns (uint);
function quote(address tokenIn, address tokenOut, uint t) external view returns (uint call, uint put);

Math libs

function optimalExp(uint256 x) external pure returns (uint256);
function ln(uint256 x) external pure returns (uint);
function ncdf(uint x) external pure returns (uint);
function cdf(int x) external pure returns (uint);
function generalLog(uint256 x) external pure returns (uint);

Beta Deployment

UniswapKeep3rV1Oracle 0x73353801921417F465377c8d898c6f4C0270282C UniswapKeep3rV1Volatility 0xCCdfCB72753CfD55C5afF5d98eA5f9C43be9659d SushiswapKeep3rV1Oracle 0xf67Ab1c914deE06Ba0F264031885Ea7B276a7cDa SushiswapKeep3rV1Volatility 0x173ed6531818456f29Fc74011a3B1FB4B6132Dc9

Tokens

Last updated