-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add LibCollateralOracle skeleton
To be used by LibUbiquityPool to fetch collateral token prices
- Loading branch information
1 parent
a4c0ba8
commit 8ad4be8
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/contracts/src/dollar/interfaces/AggregatorV3Interface.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
packages/contracts/src/dollar/interfaces/ICollateralOracle.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
packages/contracts/src/dollar/libraries/LibCollateralOracle.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters