Skip to content

Commit

Permalink
feat: apr oracle governed
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Jan 5, 2024
1 parent b1ed340 commit e414a93
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/AprOracle/AprOracle.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.18;

import {Governance} from "../utils/Governance.sol";
import {IVault} from "@yearn-vaults/interfaces/IVault.sol";
import {IStrategy} from "@tokenized-strategy/interfaces/IStrategy.sol";

Expand Down Expand Up @@ -28,14 +29,16 @@ interface IOracle {
* NOTE: All values are just at the specific time called and subject
* to change.
*/
contract AprOracle {
contract AprOracle is Governance {
// Mapping of a strategy to its specific apr oracle.
mapping(address => address) public oracles;

// Used to get the Current and Expected APR'S.
uint256 internal constant MAX_BPS_EXTENDED = 1_000_000_000_000;
uint256 internal constant SECONDS_PER_YEAR = 31_556_952;

constructor(address _governance) Governance(_governance) {}

/**
* @notice Get the current APR a strategy is earning.
* @dev Will revert if an oracle has not been set for that strategy.
Expand All @@ -58,7 +61,9 @@ contract AprOracle {
// Get the oracle set for this specific strategy.
address oracle = oracles[_strategy];

// Will revert if a oracle is not set.
// Don't revert if a oracle is not set.
if (oracle == address(0)) return 0;

return IOracle(oracle).aprAfterDebtChange(_strategy, _debtChange);
}

Expand All @@ -79,15 +84,18 @@ contract AprOracle {

/**
* @notice Set a custom APR `_oracle` for a `_strategy`.
* @dev Can only be called by the management of the `_strategy`.
* @dev Can only be called by the oracle's `governance` or
* management of the `_strategy`.
*
* The `_oracle` will need to implement the IOracle interface.
*
* @param _strategy Address of the strategy.
* @param _oracle Address of the APR Oracle.
*/
function setOracle(address _strategy, address _oracle) external virtual {
require(msg.sender == IStrategy(_strategy).management(), "!authorized");
if(governance != msg.sender) {
require(msg.sender == IStrategy(_strategy).management(), "!authorized");
}

oracles[_strategy] = _oracle;
}
Expand Down

0 comments on commit e414a93

Please sign in to comment.