// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../../libraries/Fixed.sol";
import "./FiatCollateral.sol";
/**
* @title EURFiatCollateral
* @notice Collateral plugin for a EUR fiatcoin collateral, like EURT
* Expected: {tok} == {ref}, {ref} is pegged to {target} or defaults, {target} != {UoA}
*/
contract EURFiatCollateral is FiatCollateral {
using FixLib for uint192;
using OracleLib for AggregatorV3Interface;
AggregatorV3Interface public immutable targetUnitChainlinkFeed; // {UoA/target}
uint48 public immutable targetUnitOracleTimeout; // {s}
/// @param config.chainlinkFeed Feed units:{UoA/ref}
/// @param targetUnitChainlinkFeed_ Feed units: {UoA/target}
/// @param targetUnitOracleTimeout_ {s} oracle timeout to use for targetUnitChainlinkFeed
constructor(
CollateralConfig memory config,
AggregatorV3Interface targetUnitChainlinkFeed_,
uint48 targetUnitOracleTimeout_
) FiatCollateral(config) {
Erequire(address(targetUnitChainlinkFeed_) != address(0), "missing targetUnit feed");
Erequire(targetUnitOracleTimeout_ > 0, "targetUnitOracleTimeout zero");
targetUnitChainlinkFeed = targetUnitChainlinkFeed_;
targetUnitOracleTimeout = targetUnitOracleTimeout_;
}
/// Can revert, used by other contract functions in order to catch errors
/// @return low {UoA/tok} The low price estimate
/// @return high {UoA/tok} The high price estimate
/// @return pegPrice {UoA/ref}
function tryPrice()
external
view
override
returns (
uint192 low,
uint192 high,
uint192 pegPrice
)
{
uint192 pricePerRef = chainlinkFeed.price(oracleTimeout); // {UoA/ref}
// {UoA/target}
uint192 pricePerTarget = targetUnitChainlinkFeed.price(targetUnitOracleTimeout);
// div-by-zero later
if (pricePerTarget == 0) {
return (0, FIX_MAX, 0);
}
uint192 err = pricePerRef.mul(oracleError, CEIL);
low = pricePerRef - err;
high = pricePerRef + err;
// assert(low <= high); obviously true just by inspection
// {target/ref} = {UoA/ref} / {UoA/target}
pegPrice = pricePerRef.div(pricePerTarget);
}
}
|