Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quant audit fixes #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ docker-compose up
docker-compose exec contracts-env bash

# A new Bash terminal is prompted, connected to the container
npm run compile
npm run test
```

Expand Down
4 changes: 2 additions & 2 deletions contracts/adapters/BaseUniswapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt

// Max slippage percent allowed
uint256 public constant override MAX_SLIPPAGE_PERCENT = 3000; // 30%
// FLash Loan fee set in lending pool
// Flash Loan fee set in lending pool
uint256 public constant override FLASHLOAN_PREMIUM_TOTAL = 9;
// USD oracle asset address
address public constant override USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
Expand Down Expand Up @@ -207,7 +207,7 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
.div(fromAssetPrice.mul(10**toAssetDecimals))
.percentMul(PercentageMath.PERCENTAGE_FACTOR.add(MAX_SLIPPAGE_PERCENT));

require(maxAmountToSwap < expectedMaxAmountToSwap, 'maxAmountToSwap exceed max slippage');
require(maxAmountToSwap <= expectedMaxAmountToSwap, 'maxAmountToSwap exceed max slippage');

// Approves the transfer for the swap. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.
IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), 0);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ILendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ interface ILendingPool {
address from,
address to,
uint256 amount,
uint256 balanceFromAfter,
uint256 balanceFromBefore,
uint256 balanceToBefore
) external;

Expand Down
5 changes: 4 additions & 1 deletion contracts/misc/AaveOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';
import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';
import {IChainlinkAggregator} from '../interfaces/IChainlinkAggregator.sol';
import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
import {SafeMath} from '../dependencies/openzeppelin/contracts/SafeMath.sol';

/// @title AaveOracle
/// @author Aave
Expand All @@ -17,6 +18,7 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
/// and change the fallbackOracle
contract AaveOracle is IPriceOracleGetter, Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint256;

event WethSet(address indexed weth);
event AssetSourceUpdated(address indexed asset, address indexed source);
Expand Down Expand Up @@ -89,7 +91,8 @@ contract AaveOracle is IPriceOracleGetter, Ownable {
return _fallbackOracle.getAssetPrice(asset);
} else {
int256 price = IChainlinkAggregator(source).latestAnswer();
if (price > 0) {
uint256 reportTime = IChainlinkAggregator(source).latestTimestamp();
if (price > 0 && (block.timestamp.sub(reportTime) < 10 minutes)) {
return uint256(price);
} else {
return _fallbackOracle.getAssetPrice(asset);
Expand Down
2 changes: 1 addition & 1 deletion contracts/misc/UiPoolDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {

// reserve configuration

// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
// we're getting this info from the aToken, because some of assets can be not compliant with ERC20Detailed
reserveData.symbol = IERC20Detailed(reserveData.aTokenAddress).symbol();
reserveData.name = '';

Expand Down
6 changes: 3 additions & 3 deletions contracts/misc/WETHGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ contract WETHGateway is IWETHGateway, Ownable {
* @dev borrow WETH, unwraps to ETH and send both the ETH and DebtTokens to msg.sender, via `approveDelegation` and onBehalf argument in `LendingPool.borrow`.
* @param lendingPool address of the targeted underlying lending pool
* @param amount the amount of ETH to borrow
* @param interesRateMode the interest rate mode
* @param interestRateMode the interest rate mode
* @param referralCode integrators are assigned a referral code and can potentially receive rewards
*/
function borrowETH(
address lendingPool,
uint256 amount,
uint256 interesRateMode,
uint256 interestRateMode,
uint16 referralCode
) external override {
ILendingPool(lendingPool).borrow(
address(WETH),
amount,
interesRateMode,
interestRateMode,
referralCode,
msg.sender
);
Expand Down
29 changes: 0 additions & 29 deletions contracts/misc/interfaces/IUiPoolDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ interface IUiPoolDataProvider {
uint256 stableRateSlope1;
uint256 stableRateSlope2;
}
//
// struct ReserveData {
// uint256 averageStableBorrowRate;
// uint256 totalLiquidity;
// }

struct UserReserveData {
address underlyingAsset;
Expand All @@ -58,15 +53,6 @@ interface IUiPoolDataProvider {
uint256 stableBorrowLastUpdateTimestamp;
}

//
// struct ATokenSupplyData {
// string name;
// string symbol;
// uint8 decimals;
// uint256 totalSupply;
// address aTokenAddress;
// }

function getReservesData(ILendingPoolAddressesProvider provider, address user)
external
view
Expand All @@ -75,19 +61,4 @@ interface IUiPoolDataProvider {
UserReserveData[] memory,
uint256
);

// function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
// external
// view
// returns (UserReserveData[] memory);
//
// function getAllATokenSupply(ILendingPoolAddressesProvider provider)
// external
// view
// returns (ATokenSupplyData[] memory);
//
// function getATokenSupply(address[] calldata aTokens)
// external
// view
// returns (ATokenSupplyData[] memory);
}
4 changes: 2 additions & 2 deletions contracts/mocks/oracle/PriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity 0.6.12;
import {IPriceOracle} from '../../interfaces/IPriceOracle.sol';

contract PriceOracle is IPriceOracle {
mapping(address => uint256) prices;
uint256 ethPriceUsd;
mapping(address => uint256) internal prices;
uint256 internal ethPriceUsd;

event AssetPriceUpdated(address _asset, uint256 _price, uint256 timestamp);
event EthPriceUpdated(uint256 _price, uint256 timestamp);
Expand Down
4 changes: 2 additions & 2 deletions contracts/protocol/lendingpool/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
/**
* @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa
* @param asset The address of the underlying asset borrowed
* @param rateMode The rate mode that the user wants to swap to
* @param rateMode The rate mode that the user wants to swap from
**/
function swapBorrowRateMode(address asset, uint256 rateMode) external override whenNotPaused {
DataTypes.ReserveData storage reserve = _reserves[asset];
Expand Down Expand Up @@ -713,7 +713,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}

/**
* @dev Returns the fee on flash loans
* @dev Returns the fee on flash loans
*/
function FLASHLOAN_PREMIUM_TOTAL() public view returns (uint256) {
return _flashLoanPremiumTotal;
Expand Down
8 changes: 8 additions & 0 deletions contracts/protocol/tokenization/StableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
.add(rate.rayMul(vars.amountInRay))
.rayDiv(vars.nextSupply.wadToRay());

if (balanceIncrease > 0) {
emit Transfer(address(0), onBehalfOf, balanceIncrease);
}

_mint(onBehalfOf, amount.add(balanceIncrease), vars.previousSupply);

emit Transfer(address(0), onBehalfOf, amount);
Expand Down Expand Up @@ -234,6 +238,10 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
//solium-disable-next-line
_totalSupplyTimestamp = uint40(block.timestamp);

if (balanceIncrease > 0) {
emit Transfer(address(0), user, balanceIncrease);
}

if (balanceIncrease > amount) {
uint256 amountToMint = balanceIncrease.sub(amount);
_mint(user, amountToMint, previousSupply);
Expand Down