Skip to content

Commit

Permalink
fix: use sfrxEthFraxOracle oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
web3rover committed May 8, 2024
1 parent c6215f9 commit fc52a39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
6 changes: 6 additions & 0 deletions contracts/interfaces/ISfrxEthFraxOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.25;

interface ISfrxEthFraxOracle {
function getPrices() external view returns (bool _isbadData, uint256 _priceLow, uint256 _priceHigh);
}
32 changes: 26 additions & 6 deletions contracts/oracles/SFrxETHOracle.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.25;

import { ISfrxETH } from "../interfaces/ISfrxETH.sol";
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
import { ISfrxEthFraxOracle } from "../interfaces/ISfrxEthFraxOracle.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol";

/**
Expand All @@ -11,19 +12,38 @@ import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants
* @notice This oracle fetches the price of sfrxETH
*/
contract SFrxETHOracle is CorrelatedTokenOracle {
/// @notice Address of SfrxEthFraxOracle
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
ISfrxEthFraxOracle public immutable SFRXETH_FRAX_ORACLE;

/// @notice Thrown if the price data is invalid
error BadPriceData();

/// @notice Constructor for the implementation contract.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
address sfrxEthFraxOracle,
address sfrxETH,
address frxETH,
address frax,
address resilientOracle
) CorrelatedTokenOracle(sfrxETH, frxETH, resilientOracle) {}
) CorrelatedTokenOracle(sfrxETH, frax, resilientOracle) {
ensureNonzeroAddress(sfrxEthFraxOracle);
SFRXETH_FRAX_ORACLE = ISfrxEthFraxOracle(sfrxEthFraxOracle);
}

/**
* @notice Gets the frxETH for 1 sfrxETH
* @return amount Amount of frxETH
* @notice Gets the FRAX for 1 sfrxETH
* @return amount Amount of FRAX
*/
function _getUnderlyingAmount() internal view override returns (uint256) {
return ISfrxETH(CORRELATED_TOKEN).convertToAssets(EXP_SCALE);
(bool isBadData, uint256 priceLow, uint256 priceHigh) = SFRXETH_FRAX_ORACLE.getPrices();

if (isBadData) revert BadPriceData();

// calculate average price
uint256 averagePrice = (priceLow + priceHigh) / 2;

// return (1 / averagePrice) as the average price is in sfraxETH
return EXP_SCALE * 2 / averagePrice;
}
}

0 comments on commit fc52a39

Please sign in to comment.