Skip to content

Commit

Permalink
Merge branch 'release/v3.0.0-beta.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerEther committed Feb 8, 2023
2 parents c0f4988 + de71a5b commit 55187b1
Show file tree
Hide file tree
Showing 21 changed files with 3,028 additions and 271 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Adrastia Core

[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
![2904 out of 2904 tests passing](https://img.shields.io/badge/tests-2904/2904%20passing-brightgreen.svg?style=flat-square)
![3060 out of 3060 tests passing](https://img.shields.io/badge/tests-3060/3060%20passing-brightgreen.svg?style=flat-square)
![test-coverage 100%](https://img.shields.io/badge/test%20coverage-100%25-brightgreen.svg?style=flat-square)

Adrastia Core is a set of Solidity smart contracts for building EVM oracle solutions.
Expand Down
57 changes: 57 additions & 0 deletions contracts/interfaces/IHistoricalLiquidityAccumulationOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

import "../libraries/AccumulationLibrary.sol";

/**
* @title IHistoricalLiquidityAccumulationOracle
* @notice An interface that defines an oracle contract that stores historical liquidity accumulations.
*/
interface IHistoricalLiquidityAccumulationOracle {
/// @notice Gets a liquidity accumulation for a token at a specific index.
/// @param token The address of the token to get the accumulation for.
/// @param index The index of the accumulation to get, where index 0 contains the latest accumulation, and the last
/// index contains the oldest accumulation (uses reverse chronological ordering).
/// @return The accumulation for the token at the specified index.
function getLiquidityAccumulationAt(
address token,
uint256 index
) external view returns (AccumulationLibrary.LiquidityAccumulator memory);

/// @notice Gets the latest liquidity accumulations for a token.
/// @param token The address of the token to get the accumulations for.
/// @param amount The number of accumulations to get.
/// @return The latest accumulations for the token, in reverse chronological order, from newest to oldest.
function getLiquidityAccumulations(
address token,
uint256 amount
) external view returns (AccumulationLibrary.LiquidityAccumulator[] memory);

/// @notice Gets the latest liquidity accumulations for a token.
/// @param token The address of the token to get the accumulations for.
/// @param amount The number of accumulations to get.
/// @param offset The index of the first accumulations to get (default: 0).
/// @param increment The increment between accumulations to get (default: 1).
/// @return The latest accumulations for the token, in reverse chronological order, from newest to oldest.
function getLiquidityAccumulations(
address token,
uint256 amount,
uint256 offset,
uint256 increment
) external view returns (AccumulationLibrary.LiquidityAccumulator[] memory);

/// @notice Gets the number of liquidity accumulations for a token.
/// @param token The address of the token to get the number of accumulations for.
/// @return count The number of accumulations for the token.
function getLiquidityAccumulationsCount(address token) external view returns (uint256);

/// @notice Gets the capacity of liquidity accumulations for a token.
/// @param token The address of the token to get the capacity of accumulations for.
/// @return capacity The capacity of accumulations for the token.
function getLiquidityAccumulationsCapacity(address token) external view returns (uint256);

/// @notice Sets the capacity of liquidity accumulations for a token.
/// @param token The address of the token to set the capacity of accumulations for.
/// @param amount The new capacity of accumulations for the token.
function setLiquidityAccumulationsCapacity(address token, uint256 amount) external;
}
57 changes: 57 additions & 0 deletions contracts/interfaces/IHistoricalOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

import "../libraries/ObservationLibrary.sol";

/**
* @title IHistoricalOracle
* @notice An interface that defines an oracle contract that stores historical observations.
*/
interface IHistoricalOracle {
/// @notice Gets an observation for a token at a specific index.
/// @param token The address of the token to get the observation for.
/// @param index The index of the observation to get, where index 0 contains the latest observation, and the last
/// index contains the oldest observation (uses reverse chronological ordering).
/// @return observation The observation for the token at the specified index.
function getObservationAt(
address token,
uint256 index
) external view returns (ObservationLibrary.Observation memory);

/// @notice Gets the latest observations for a token.
/// @param token The address of the token to get the observations for.
/// @param amount The number of observations to get.
/// @return observations The latest observations for the token, in reverse chronological order, from newest to oldest.
function getObservations(
address token,
uint256 amount
) external view returns (ObservationLibrary.Observation[] memory);

/// @notice Gets the latest observations for a token.
/// @param token The address of the token to get the observations for.
/// @param amount The number of observations to get.
/// @param offset The index of the first observation to get (default: 0).
/// @param increment The increment between observations to get (default: 1).
/// @return observations The latest observations for the token, in reverse chronological order, from newest to oldest.
function getObservations(
address token,
uint256 amount,
uint256 offset,
uint256 increment
) external view returns (ObservationLibrary.Observation[] memory);

/// @notice Gets the number of observations for a token.
/// @param token The address of the token to get the number of observations for.
/// @return count The number of observations for the token.
function getObservationsCount(address token) external view returns (uint256);

/// @notice Gets the capacity of observations for a token.
/// @param token The address of the token to get the capacity of observations for.
/// @return capacity The capacity of observations for the token.
function getObservationsCapacity(address token) external view returns (uint256);

/// @notice Sets the capacity of observations for a token.
/// @param token The address of the token to set the capacity of observations for.
/// @param amount The new capacity of observations for the token.
function setObservationsCapacity(address token, uint256 amount) external;
}
57 changes: 57 additions & 0 deletions contracts/interfaces/IHistoricalPriceAccumulationOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

import "../libraries/AccumulationLibrary.sol";

/**
* @title IHistoricalPriceAccumulationOracle
* @notice An interface that defines an oracle contract that stores historical price accumulations.
*/
interface IHistoricalPriceAccumulationOracle {
/// @notice Gets a price accumulation for a token at a specific index.
/// @param token The address of the token to get the accumulation for.
/// @param index The index of the accumulation to get, where index 0 contains the latest accumulation, and the last
/// index contains the oldest accumulation (uses reverse chronological ordering).
/// @return The accumulation for the token at the specified index.
function getPriceAccumulationAt(
address token,
uint256 index
) external view returns (AccumulationLibrary.PriceAccumulator memory);

/// @notice Gets the latest price accumulations for a token.
/// @param token The address of the token to get the accumulations for.
/// @param amount The number of accumulations to get.
/// @return The latest accumulations for the token, in reverse chronological order, from newest to oldest.
function getPriceAccumulations(
address token,
uint256 amount
) external view returns (AccumulationLibrary.PriceAccumulator[] memory);

/// @notice Gets the latest price accumulations for a token.
/// @param token The address of the token to get the accumulations for.
/// @param amount The number of accumulations to get.
/// @param offset The index of the first accumulations to get (default: 0).
/// @param increment The increment between accumulations to get (default: 1).
/// @return The latest accumulations for the token, in reverse chronological order, from newest to oldest.
function getPriceAccumulations(
address token,
uint256 amount,
uint256 offset,
uint256 increment
) external view returns (AccumulationLibrary.PriceAccumulator[] memory);

/// @notice Gets the number of price accumulations for a token.
/// @param token The address of the token to get the number of accumulations for.
/// @return count The number of accumulations for the token.
function getPriceAccumulationsCount(address token) external view returns (uint256);

/// @notice Gets the capacity of price accumulations for a token.
/// @param token The address of the token to get the capacity of accumulations for.
/// @return capacity The capacity of accumulations for the token.
function getPriceAccumulationsCapacity(address token) external view returns (uint256);

/// @notice Sets the capacity of price accumulations for a token.
/// @param token The address of the token to set the capacity of accumulations for.
/// @param amount The new capacity of accumulations for the token.
function setPriceAccumulationsCapacity(address token, uint256 amount) external;
}
4 changes: 4 additions & 0 deletions contracts/interfaces/IPeriodic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ interface IPeriodic {
/// @notice Gets the period, in seconds.
/// @return periodSeconds The period, in seconds.
function period() external view returns (uint256 periodSeconds);

// @notice Gets the number of observations made every period.
// @return granularity The number of observations made every period.
function granularity() external view returns (uint256 granularity);
}
20 changes: 11 additions & 9 deletions contracts/oracles/AbstractOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import "../libraries/ObservationLibrary.sol";
import "../utils/SimpleQuotationMetadata.sol";

abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {
mapping(address => ObservationLibrary.Observation) public observations;

constructor(address quoteToken_) SimpleQuotationMetadata(quoteToken_) {}

/// @param data The encoded address of the token for which to perform the update.
Expand All @@ -25,12 +23,16 @@ abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {
/// @inheritdoc IUpdateable
function canUpdate(bytes memory data) public view virtual override returns (bool);

function getLatestObservation(
address token
) public view virtual returns (ObservationLibrary.Observation memory observation);

/// @param data The encoded address of the token for which the update relates to.
/// @inheritdoc IUpdateable
function lastUpdateTime(bytes memory data) public view virtual override returns (uint256) {
address token = abi.decode(data, (address));

return observations[token].timestamp;
return getLatestObservation(token).timestamp;
}

/// @param data The encoded address of the token for which the update relates to.
Expand All @@ -42,7 +44,7 @@ abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {
function consultPrice(address token) public view virtual override returns (uint112 price) {
if (token == quoteTokenAddress()) return uint112(10 ** quoteTokenDecimals());

ObservationLibrary.Observation storage observation = observations[token];
ObservationLibrary.Observation memory observation = getLatestObservation(token);

require(observation.timestamp != 0, "AbstractOracle: MISSING_OBSERVATION");

Expand All @@ -59,7 +61,7 @@ abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {
return price;
}

ObservationLibrary.Observation storage observation = observations[token];
ObservationLibrary.Observation memory observation = getLatestObservation(token);

require(observation.timestamp != 0, "AbstractOracle: MISSING_OBSERVATION");
require(block.timestamp <= observation.timestamp + maxAge, "AbstractOracle: RATE_TOO_OLD");
Expand All @@ -73,7 +75,7 @@ abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {
) public view virtual override returns (uint112 tokenLiquidity, uint112 quoteTokenLiquidity) {
if (token == quoteTokenAddress()) return (0, 0);

ObservationLibrary.Observation storage observation = observations[token];
ObservationLibrary.Observation memory observation = getLatestObservation(token);

require(observation.timestamp != 0, "AbstractOracle: MISSING_OBSERVATION");

Expand All @@ -94,7 +96,7 @@ abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {
return (tokenLiquidity, quoteTokenLiquidity);
}

ObservationLibrary.Observation storage observation = observations[token];
ObservationLibrary.Observation memory observation = getLatestObservation(token);

require(observation.timestamp != 0, "AbstractOracle: MISSING_OBSERVATION");
require(block.timestamp <= observation.timestamp + maxAge, "AbstractOracle: RATE_TOO_OLD");
Expand All @@ -109,7 +111,7 @@ abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {
) public view virtual override returns (uint112 price, uint112 tokenLiquidity, uint112 quoteTokenLiquidity) {
if (token == quoteTokenAddress()) return (uint112(10 ** quoteTokenDecimals()), 0, 0);

ObservationLibrary.Observation storage observation = observations[token];
ObservationLibrary.Observation memory observation = getLatestObservation(token);

require(observation.timestamp != 0, "AbstractOracle: MISSING_OBSERVATION");

Expand All @@ -127,7 +129,7 @@ abstract contract AbstractOracle is IERC165, IOracle, SimpleQuotationMetadata {

if (maxAge == 0) return instantFetch(token);

ObservationLibrary.Observation storage observation = observations[token];
ObservationLibrary.Observation memory observation = getLatestObservation(token);

require(observation.timestamp != 0, "AbstractOracle: MISSING_OBSERVATION");
require(block.timestamp <= observation.timestamp + maxAge, "AbstractOracle: RATE_TOO_OLD");
Expand Down
Loading

0 comments on commit 55187b1

Please sign in to comment.