diff --git a/contracts/oracles/SolidlyOracleNoCreate2.sol b/contracts/oracles/SolidlyOracleNoCreate2.sol index 8926946..a4c5918 100644 --- a/contracts/oracles/SolidlyOracleNoCreate2.sol +++ b/contracts/oracles/SolidlyOracleNoCreate2.sol @@ -6,34 +6,25 @@ import "@openzeppelin/contracts/utils/math/Math.sol"; import "./OracleBase.sol"; import "../interfaces/ISolidlyFactory.sol"; import "../interfaces/IOracle.sol"; +import "./SolidlyOracle.sol"; import "../interfaces/IUniswapV2Pair.sol"; import "../libraries/OraclePrices.sol"; -contract SolidlyOracleNoCreate2 is IOracle { +contract SolidlyOracleNoCreate2 is SolidlyOracle { using OraclePrices for OraclePrices.Data; using Math for uint256; - ISolidlyFactory public immutable FACTORY; + ISolidlyFactory public immutable _FACTORY; IERC20 private constant _NONE = IERC20(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF); - constructor(ISolidlyFactory _factory) { - FACTORY = _factory; + constructor(address _factory) SolidlyOracle(_factory, bytes32(0)) { + _FACTORY = ISolidlyFactory(_factory); } - function getRate(IERC20 srcToken, IERC20 dstToken, IERC20 connector, uint256 thresholdFilter) external view override returns (uint256 rate, uint256 weight) { - if(connector != _NONE) revert ConnectorShouldBeNone(); - OraclePrices.Data memory ratesAndWeights = OraclePrices.init(2); - (uint256 b0, uint256 b1) = _getBalances(srcToken, dstToken, true); - ratesAndWeights.append(OraclePrices.OraclePrice(Math.mulDiv(b1, 1e18, b0), (b0 * b1).sqrt())); - (b0, b1) = _getBalances(srcToken, dstToken, false); - ratesAndWeights.append(OraclePrices.OraclePrice(Math.mulDiv(b1, 1e18, b0), (b0 * b1).sqrt())); - return ratesAndWeights.getRateAndWeight(thresholdFilter); - } - - function _getBalances(IERC20 srcToken, IERC20 dstToken, bool stable) internal view returns (uint256 srcBalance, uint256 dstBalance) { + function _getBalances(IERC20 srcToken, IERC20 dstToken, bool stable) internal view override returns (uint256 srcBalance, uint256 dstBalance) { (IERC20 token0, IERC20 token1) = srcToken < dstToken ? (srcToken, dstToken) : (dstToken, srcToken); - (bool success, bytes memory data) = FACTORY.getPair(token0, token1, stable).staticcall(abi.encodeWithSelector(IUniswapV2Pair.getReserves.selector)); + (bool success, bytes memory data) = _FACTORY.getPair(token0, token1, stable).staticcall(abi.encodeWithSelector(IUniswapV2Pair.getReserves.selector)); if (success && data.length == 96) { (srcBalance, dstBalance) = abi.decode(data, (uint256, uint256)); (srcBalance, dstBalance) = srcToken == token0 ? (srcBalance, dstBalance) : (dstBalance, srcBalance); @@ -41,4 +32,4 @@ contract SolidlyOracleNoCreate2 is IOracle { (srcBalance, dstBalance) = (1, 0); } } -} +} \ No newline at end of file