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
1
// returns the amount out corresponding to the amount in for a given token using the moving average over the time
2
function current(address tokenIn, uint amountIn, address tokenOut) external view returns (uint amountOut)
Copied!
Example;
1
interface IUniswapV2Oracle {
2
function current(address tokenIn, uint amountIn, address tokenOut) external view returns (uint amountOut);
3
}
Copied!

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
1
// returns the amount out corresponding to the amount in for a given token using the moving average over the time taking granularity samples
2
function quote(address tokenIn, uint amountIn, address tokenOut, uint granularity) external view returns (uint amountOut)
Copied!

Price points

Returns a set of price points equal to points * periodSize, so for the points in the last 24 hours use points = 48
1
// returns an amount of price points equal to periodSize * points
2
prices(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)
Copied!

Hourly

Returns a set of price points equal to points * hours, so for the points in the last 24 hours use points = 24
1
// returns an amount of price points equal to hour * points
2
function hourly(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)
Copied!

Daily

Returns a set of price points equal to points * days, so for the points in the last 24 hours use points = 1
1
// returns an amount of price points equal to days * points
2
function daily(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)
Copied!

Weekly

Returns a set of price points equal to points * weeks, so for the points in the last week use points = 1
1
// returns an amount of price points equal to days * points
2
function weekly(address tokenIn, uint amountIn, address tokenOut, uint points) external view returns (uint[] memory)
Copied!

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
1
// returns realized volatility over points * window
2
function rVol(address tokenIn, address tokenOut, uint points, uint window) external view returns (uint)
Copied!

Hourly Realized Volatility

Returns the realized volatility over the last amount of points per hour, so volatility over last hour would be points = 1
1
// returns realized volatility over points * window
2
function rVolHourly(address tokenIn, address tokenOut, uint points) external view returns (uint);
Copied!

Daily Realized Volatility

Returns the realized volatility over the last amount of points per days, so volatility over last day would be points = 1
1
// returns realized volatility over points * window
2
function rVolDaily(address tokenIn, address tokenOut, uint points) external view returns (uint);
Copied!

Weekly Realized Volatility

Returns the realized volatility over the last amount of points per weeks, so volatility over last day week be points = 1
1
// returns realized volatility over points * window
2
function rVolWeekly(address tokenIn, address tokenOut, uint points) external view returns (uint);
Copied!

Pricing

Black Scholes Estimate

Contract: Keep3rV1Oracle
1
/**
2
* @dev blackScholesEstimate calculates a rough price estimate for an ATM option
3
* @dev input parameters should be transformed prior to being passed to the function
4
* @dev so as to remove decimal places otherwise results will be far less accurate
5
* @param _vol uint256 volatility of the underlying converted to remove decimals
6
* @param _underlying uint256 price of the underlying asset
7
* @param _time uint256 days to expiration in years multiplied to remove decimals
8
*/
9
function blackScholesEstimate(
10
uint256 _vol,
11
uint256 _underlying,
12
uint256 _time
13
) external pure returns (uint256 estimate);
Copied!

Options Pricing

Contract: Keep3rV1Volatility
1
function C(uint t, uint v, uint sp, uint st) external pure returns (uint);
2
function quoteAll(uint t, uint v, uint sp, uint st) external pure returns (uint call, uint put);
3
function quotePrice(address tokenIn, address tokenOut, uint t, uint sp, uint st) external view returns (uint call, uint put);
4
function price(address tokenIn, address tokenOut) external view returns (uint);
5
function quote(address tokenIn, address tokenOut, uint t) external view returns (uint call, uint put);
Copied!

Math libs

1
function optimalExp(uint256 x) external pure returns (uint256);
2
function ln(uint256 x) external pure returns (uint);
3
function ncdf(uint x) external pure returns (uint);
4
function cdf(int x) external pure returns (uint);
5
function generalLog(uint256 x) external pure returns (uint);
Copied!

Beta Deployment

Tokens

Last modified 9mo ago