Skip to content

Commit

Permalink
feat: add LibCollateralOracle skeleton
Browse files Browse the repository at this point in the history
To be used by LibUbiquityPool to fetch collateral token prices
  • Loading branch information
gitcoindev committed Dec 1, 2023
1 parent a4c0ba8 commit 8ad4be8
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/contracts/src/dollar/interfaces/AggregatorV3Interface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
// ChainLink price feed interface
// @dev Original implementation https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol

pragma solidity 0.8.19;

interface AggregatorV3Interface {
function decimals() external view returns (uint8);

function description() external view returns (string memory);

function version() external view returns (uint256);

function getRoundData(
uint80 _roundId
)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);

function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
24 changes: 24 additions & 0 deletions packages/contracts/src/dollar/interfaces/ICollateralOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

/**
* @notice Collateral Oracle interface
* @notice Returns price quotes for all registered collaterals
*/

interface ICollateralOracle {
/**
* @notice Updates the following state variables for each of the collaterals to the latest values
* - collateral token / 3CRV LP quote
* - cumulative prices
* - update timestamp
*/
function update() external;

/**
* @notice Returns the quote for the provided `token` address
* @param token Token address
* @return amountOut Token price
*/
function consult(address token) external view returns (uint256 amountOut);
}
55 changes: 55 additions & 0 deletions packages/contracts/src/dollar/libraries/LibCollateralOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {IMetaPool} from "../../dollar/interfaces/IMetaPool.sol";
import {AggregatorV3Interface} from "../../dollar/interfaces/AggregatorV3Interface.sol";
import {LibAppStorage} from "./LibAppStorage.sol";

/**
* @notice Library used for Collateral price oracles
* @dev Initially supports ChainLink price feeds
* @dev This library may combine in the future different price feeds and Curve Metapool TWAPs
* @dev List of available collateral tokens and their price is stored in LibUbiquityPool
*/
library LibCollateralOracle {
/// @notice Struct used as a storage for this library
struct CollateralOracleStorage {
mapping(address => AggregatorV3Interface) priceFeeds;
}

/// @notice Emitted when collateral token price was updated
event CollateralPriceUpdated(address token, uint256 price);

/// @notice Storage slot used to store data for this library
bytes32 constant COLLATERAL_ORACLE_STORAGE_POSITION =
bytes32(
uint256(keccak256("diamond.standard.collateral.oracle.storage")) - 1
);

/**
* @notice Returns struct used as a storage for this library
* @return ds Struct used as a storage
*/
function collateralOracleStorage()
internal
pure
returns (collateralOracleStorage storage ds)
{
bytes32 position = COLLATERAL_ORACLE_STORAGE_POSITION;
assembly {
ds.slot := position
}
}

/**
* @notice Updates all registered collateral prices from ChainLink
*/
function update() internal {}

/**
* @notice Returns the quote for the provided `token` address
* @param token Token address
* @return amountOut Token price vs 3CRV LP
*/
function consult(address token) internal view returns (uint256) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {IERC20Ubiquity} from "../interfaces/IERC20Ubiquity.sol";
import {UBIQUITY_POOL_PRICE_PRECISION} from "./Constants.sol";
import {LibAppStorage} from "./LibAppStorage.sol";
import {LibTWAPOracle} from "./LibTWAPOracle.sol";
import {LibCollateralOracle} from "./LibCollateralOracle.sol";

/**
* @notice Ubiquity pool library
Expand Down

0 comments on commit 8ad4be8

Please sign in to comment.