Skip to content

Commit

Permalink
Updates to Oracle and RewardsDistro, test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Apr 12, 2024
1 parent 45777d7 commit 69aa656
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
3 changes: 1 addition & 2 deletions src/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.24;

import {Math} from "lib/openzeppelin-contracts/contracts/utils/math/Math.sol";
import {Initializable} from "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import {AccessControlUpgradeable} from "lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";
import {RewardsReceiver} from "src/RewardsReceiver.sol";
import {IynETH} from "src/interfaces/IynETH.sol";
Expand All @@ -15,7 +14,7 @@ interface RewardsDistributorEvents {
}


contract RewardsDistributor is Initializable, AccessControlUpgradeable, RewardsDistributorEvents {
contract RewardsDistributor is AccessControlUpgradeable, RewardsDistributorEvents {

//--------------------------------------------------------------------------------------
//---------------------------------- ERRORS ------------------------------------------
Expand Down
37 changes: 28 additions & 9 deletions src/YieldNestOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,39 @@ interface IYieldNestOracleEvents {
}

contract YieldNestOracle is AccessControlUpgradeable, IYieldNestOracleEvents {
struct AssetPriceFeed {
AggregatorV3Interface priceFeed;
uint256 maxAge; // in seconds
}

//--------------------------------------------------------------------------------------
//---------------------------------- ERRORS -------------------------------------------
//--------------------------------------------------------------------------------------

error PriceFeedTooStale(uint256 age, uint256 maxAge);
error ZeroAddress();
error ZeroAge();
error ArraysLengthMismatch(uint256 assetsLength, uint256 priceFeedAddressesLength, uint256 maxAgesLength);
error PriceFeedNotSet();
error InvalidPriceValue(int256 price);
error InvalidPriceValue(int256 price);

//--------------------------------------------------------------------------------------
//---------------------------------- VARIABLES ---------------------------------------
//--------------------------------------------------------------------------------------

struct AssetPriceFeed {
AggregatorV3Interface priceFeed;
uint256 maxAge; // in seconds
}

mapping(address => AssetPriceFeed) public assetPriceFeeds;

//--------------------------------------------------------------------------------------
//---------------------------------- ROLES -------------------------------------------
//--------------------------------------------------------------------------------------

bytes32 public constant ORACLE_MANAGER_ROLE = keccak256("ORACLE_MANAGER_ROLE");

//--------------------------------------------------------------------------------------
//---------------------------------- INITIALIZATION ----------------------------------
//--------------------------------------------------------------------------------------

struct Init {
address[] assets;
address[] priceFeedAddresses;
Expand All @@ -31,9 +50,6 @@ contract YieldNestOracle is AccessControlUpgradeable, IYieldNestOracleEvents {
address oracleManager;
}

bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant ORACLE_MANAGER_ROLE = keccak256("ORACLE_MANAGER_ROLE");

constructor() {
_disableInitializers();
}
Expand All @@ -44,7 +60,7 @@ contract YieldNestOracle is AccessControlUpgradeable, IYieldNestOracleEvents {
notZeroAddress(init.oracleManager)
initializer {
__AccessControl_init();
_grantRole(ADMIN_ROLE, init.admin);
_grantRole(DEFAULT_ADMIN_ROLE, init.admin);
_grantRole(ORACLE_MANAGER_ROLE, init.oracleManager);

if (init.assets.length != init.priceFeedAddresses.length || init.assets.length != init.maxAges.length) {
Expand All @@ -55,6 +71,9 @@ contract YieldNestOracle is AccessControlUpgradeable, IYieldNestOracleEvents {
}
}

//--------------------------------------------------------------------------------------
//---------------------------------- FUNCTIONS ---------------------------------------
//--------------------------------------------------------------------------------------

/**
* @notice Sets the price feed for a given asset.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/IntegrationBaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ contract IntegrationBaseTest is Test, Utils {
vm.prank(actors.STAKING_ADMIN); // StakingNodesManager is the only contract that can register a staking node implementation contract
stakingNodesManager.registerStakingNodeImplementationContract(address(stakingNodeImplementation));
}

function setupYieldNestOracleAndYnLSD() public {
IERC20[] memory assets = new IERC20[](2);
address[] memory assetsAddresses = new address[](2);
Expand Down
23 changes: 3 additions & 20 deletions test/integration/Roles.t.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
// SPDX-License-Identifier: BSD 3-Clause License
pragma solidity ^0.8.24;
import {IntegrationBaseTest} from "./IntegrationBaseTest.sol";
import {StakingNodesManager} from "src/StakingNodesManager.sol";
import {ynETH} from "src/ynETH.sol";
import {ynLSD} from "src/ynLSD.sol";
import {YieldNestOracle} from "src/YieldNestOracle.sol";
import {MockYnETHERC4626} from "test/mocks/MockYnETHERC4626.sol";
import {MockERC20} from "test/mocks/MockERC20.sol";
import {RewardsDistributor} from "src/RewardsDistributor.sol";
import {ProxyAdmin} from "lib/openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {IRewardsDistributor} from "src/interfaces/IRewardsDistributor.sol";
import {IStakingNodesManager} from "src/interfaces/IStakingNodesManager.sol";
import {IStrategy} from "src/external/eigenlayer/v0.1.0/interfaces/IStrategy.sol";
import {TransparentUpgradeableProxy} from "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ITransparentUpgradeableProxy} from "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {TestStakingNodesManagerV2} from "test/mocks/TestStakingNodesManagerV2.sol";

contract RolesTest is IntegrationBaseTest {

function testRoleChangeYnETH() public {
address newOperator = address(0x123);
bytes32 ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 STAKING_NODES_MANAGER_ROLE = keccak256("STAKING_NODES_MANAGER_ROLE");
bytes32 REWARDS_DISTRIBUTOR_ROLE = keccak256("REWARDS_DISTRIBUTOR_ROLE");

assertTrue(stakingNodesManager.hasRole(stakingNodesManager.DEFAULT_ADMIN_ROLE(), actors.ADMIN));
Expand Down Expand Up @@ -115,18 +98,18 @@ contract RolesTest is IntegrationBaseTest {
}

function testRoleChangeYieldNestOracle() public {
address newOracleAdmin = address(0xDEF);
address newOracleManager = address(0xDEF);
bytes32 ORACLE_MANAGER_ROLE = keccak256("ORACLE_MANAGER_ROLE");

assertTrue(yieldNestOracle.hasRole(yieldNestOracle.DEFAULT_ADMIN_ROLE(), actors.ADMIN));
assertTrue(yieldNestOracle.hasRole(ORACLE_MANAGER_ROLE, actors.ORACLE_MANAGER));

vm.startPrank(actors.ADMIN);
yieldNestOracle.grantRole(ORACLE_MANAGER_ROLE, newOracleAdmin);
yieldNestOracle.grantRole(ORACLE_MANAGER_ROLE, newOracleManager);
yieldNestOracle.revokeRole(ORACLE_MANAGER_ROLE, actors.ORACLE_MANAGER);
vm.stopPrank();

assertTrue(yieldNestOracle.hasRole(ORACLE_MANAGER_ROLE, newOracleAdmin));
assertTrue(yieldNestOracle.hasRole(ORACLE_MANAGER_ROLE, newOracleManager));
assertFalse(yieldNestOracle.hasRole(ORACLE_MANAGER_ROLE, actors.ORACLE_MANAGER));
}
}
Expand Down

0 comments on commit 69aa656

Please sign in to comment.