Skip to content

Commit

Permalink
feat: cleanup external oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Aug 9, 2024
1 parent 93a819d commit dda9171
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
21 changes: 3 additions & 18 deletions src/periphery/contracts/static-a-token/StataOracle.sol
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;

import {IPool} from '../../../core/contracts/interfaces/IPool.sol';
import {IPoolAddressesProvider} from '../../../core/contracts/interfaces/IPoolAddressesProvider.sol';
import {IAaveOracle} from '../../../core/contracts/interfaces/IAaveOracle.sol';
import {IStaticATokenLM} from './interfaces/IStaticATokenLM.sol';
import {IStataOracle} from './interfaces/IStataOracle.sol';
import {IERC4626} from './interfaces/IERC4626.sol';

/**
* @title StataOracle
* @author BGD Labs
* @notice Contract to get asset prices of stata tokens
*/
contract StataOracle is IStataOracle {
/// @inheritdoc IStataOracle
IPool public immutable POOL;
/// @inheritdoc IStataOracle
IAaveOracle public immutable AAVE_ORACLE;

constructor(IPoolAddressesProvider provider) {
POOL = IPool(provider.getPool());
AAVE_ORACLE = IAaveOracle(provider.getPriceOracle());
}

/// @inheritdoc IStataOracle
function getAssetPrice(address asset) public view returns (uint256) {
address underlying = IERC4626(asset).asset();
return
(AAVE_ORACLE.getAssetPrice(underlying) * POOL.getReserveNormalizedIncome(underlying)) / 1e27;
return uint256(IStaticATokenLM(asset).latestAnswer());
}

/// @inheritdoc IStataOracle
function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory) {
uint256[] memory prices = new uint256[](assets.length);
for (uint256 i = 0; i < assets.length; i++) {
prices[i] = getAssetPrice(assets[i]);
prices[i] = uint256(IStaticATokenLM(assets[i]).latestAnswer());
}
return prices;
}
Expand Down
13 changes: 0 additions & 13 deletions src/periphery/contracts/static-a-token/interfaces/IStataOracle.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {IPool} from '../../../../core/contracts/interfaces/IPool.sol';
import {IAaveOracle} from '../../../../core/contracts/interfaces/IAaveOracle.sol';

interface IStataOracle {
/**
* @return The pool used for fetching the rate on the aggregator oracle
*/
function POOL() external view returns (IPool);

/**
* @return The aave oracle used for fetching the price of the underlying
*/
function AAVE_ORACLE() external view returns (IAaveOracle);

/**
* @notice Returns the prices of an asset address
* @param asset The asset address
Expand Down
2 changes: 1 addition & 1 deletion tests/periphery/static-a-token/StataOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract StataOracleTest is BaseTest {

function setUp() public override {
super.setUp();
oracle = new StataOracle(contracts.poolAddressesProvider);
oracle = new StataOracle();

vm.prank(address(roleList.marketOwner));
contracts.poolConfiguratorProxy.setSupplyCap(UNDERLYING, 1_000_000);
Expand Down

0 comments on commit dda9171

Please sign in to comment.