Skip to content

Commit

Permalink
inherit and override
Browse files Browse the repository at this point in the history
  • Loading branch information
belactriple9 committed Sep 18, 2024
1 parent 00e7e4b commit 5492240
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions contracts/oracles/SolidlyOracleNoCreate2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,30 @@ 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;

Check failure on line 17 in contracts/oracles/SolidlyOracleNoCreate2.sol

View workflow job for this annotation

GitHub Actions / lint

'_FACTORY' should not start with _

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);
} else {
(srcBalance, dstBalance) = (1, 0);
}
}
}
}

0 comments on commit 5492240

Please sign in to comment.