Vulnerability Details
If collateralToken
is depricated on Aave its Token will be unavailable IF collateral was deposited.
In AaveDIVAWrapperCore::_registerCollateralToken() there's a check to see if the collateral token has a corresponding aToken on the Aave pool. But if this collateral token was deprecated before a supplier called AaveDIVAWrapper::addLiquidity() / AaveDIVAWrapperCore::_addLiquidity() then they risk losing their collateral to the protocol or the protocol having to provide the supplier with position tokens but losing out on getting yield from the supplied collateral since they can't supply it to Aave as the function doesn't check if the collateral token has a corresponding aToken on the Aave pool.
# AaveDIVAWrapperCore::_registerCollateralToken()
#https:
function _registerCollateralToken(address _collateralToken) internal returns (address) {
if (_collateralTokenToWToken[_collateralToken] != address(0)) {
revert CollateralTokenAlreadyRegistered();
}
address _aToken = _getAToken(_collateralToken);
if (_aToken == address(0)) {
revert UnsupportedCollateralToken(); @audit2
}
IERC20Metadata _collateralTokenContract = IERC20Metadata(_collateralToken);
WToken _wTokenContract = new WToken(
string(abi.encodePacked("w", _collateralTokenContract.symbol())),
_collateralTokenContract.decimals(),
address(this)
);
address _wToken = address(_wTokenContract);
_collateralTokenToWToken[_collateralToken] = _wToken;
_wTokenToCollateralToken[_wToken] = _collateralToken;
_wTokenContract.approve(_diva, type(uint256).max);
_collateralTokenContract.approve(_aaveV3Pool, type(uint256).max);
emit CollateralTokenRegistered(_collateralToken, _wToken);
return _wToken;
}
#AaveDIVAWrapper::addLiquidity()
#https:
function addLiquidity(
bytes32 _poolId,
uint256 _collateralAmount,
address _longRecipient,
address _shortRecipient
) external override nonReentrant {
_addLiquidity(_poolId, _collateralAmount, _longRecipient, _shortRecipient);
}
#AaveDIVAWrapperCore::_addLiquidity()
#https:
function _addLiquidity(
bytes32 _poolId,
uint256 _collateralAmount,
address _longRecipient,
address _shortRecipient
) internal {
IDIVA.Pool memory _pool = IDIVA(_diva).getPoolParameters(_poolId);
address _collateralToken = _wTokenToCollateralToken[_pool.collateralToken];
if (_collateralToken == address(0)) {
revert CollateralTokenNotRegistered();
}
_handleTokenOperations(_collateralToken, _collateralAmount, _pool.collateralToken);
IDIVA(_diva).addLiquidity(_poolId, _collateralAmount, _longRecipient, _shortRecipient);
}
#AaveDIVAWrapperCore::_handleTokenOperations()
function _handleTokenOperations(address _collateralToken, uint256 _collateralAmount, address _wToken) private {
IERC20Metadata(_collateralToken).safeTransferFrom(msg.sender, address(this), _collateralAmount);
IAave(_aaveV3Pool).supply(
_collateralToken,
_collateralAmount,
address(this),
0
);
IWToken(_wToken).mint(address(this), _collateralAmount);
}
Impact
Suppliers
risk losing their collateral to the protocol or the protocol having to provide the supplier
with position tokens but losing out on getting yield from the supplied collateral on aave.
Tools Used
Manual review.
Recommendations
It is best to include a method to unregister depricated collateralToken
collateral token has a corresponding aToken on the Aave pool.