Use a lookback of 900 seconds for an instantaneous price query for manipulation resistance. we are not using 900 in our code.
function getEthUsdPrice(uint256 lookback) internal view returns (uint256) {
uint256 chainlinkPrice = lookback > 0 ?
LibChainlinkOracle.getEthUsdTwap(lookback) :
LibChainlinkOracle.getEthUsdPrice();
// Check if the chainlink price is broken or frozen.
if (chainlinkPrice == 0) return 0;
// Use a lookback of 900 seconds for an instantaneous price query for manipulation resistance.
if (lookback == 0) lookback = INSTANT_LOOKBACK;
if (lookback > type(uint32).max) return 0;
@>> uint256 usdcPrice = LibUniswapOracle.getEthUsdcPrice(uint32(lookback));
uint256 usdcChainlinkPercentDiff = getPercentDifference(usdcPrice, chainlinkPrice);
// Check if the USDC price and the Chainlink Price are sufficiently close enough
// to warrant using the greedy approach.
if (usdcChainlinkPercentDiff < MAX_GREEDY_DIFFERENCE) {
return chainlinkPrice.add(usdcPrice).div(2);
}
uint256 usdtPrice = LibUniswapOracle.getEthUsdtPrice(uint32(lookback));
uint256 usdtChainlinkPercentDiff = getPercentDifference(usdtPrice, chainlinkPrice);
// Check whether the USDT or USDC price is closer to the Chainlink price.
if (usdtChainlinkPercentDiff < usdcChainlinkPercentDiff) {
// Check whether the USDT price is too far from the Chainlink price.
if (usdtChainlinkPercentDiff < MAX_DIFFERENCE) {
return chainlinkPrice.add(usdtPrice).div(2);
}
return chainlinkPrice;
} else {
// Check whether the USDC price is too far from the Chainlink price.
if (usdcChainlinkPercentDiff < MAX_DIFFERENCE) {
return chainlinkPrice.add(usdcPrice).div(2);
}
return chainlinkPrice;
}
}
Use a lookback of 900 seconds for an instantaneous price query for manipulation resistance.
if (lookback == 0 ||lookback<900) lookback = INSTANT_LOOKBACK;
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.