Initial fix

This commit is contained in:
The3D 2020-09-30 17:40:47 +02:00
parent f435b2fa0a
commit b907b6b0b3
3 changed files with 19 additions and 6 deletions

View File

@ -45,10 +45,12 @@ library Errors {
string public constant INVALID_EQUAL_ASSETS_TO_SWAP = '56'; string public constant INVALID_EQUAL_ASSETS_TO_SWAP = '56';
string public constant NO_MORE_RESERVES_ALLOWED = '59'; string public constant NO_MORE_RESERVES_ALLOWED = '59';
// require error messages - aToken // require error messages - aToken - DebtTokens
string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool' string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool'
string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself' string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero' string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
string public constant INVALID_MINT_AMOUNT = '53'; //invalid amount to mint
string public constant INVALID_BURN_AMOUNT = '53'; //invalid amount to burn
// require error messages - ReserveLogic // require error messages - ReserveLogic
string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized' string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized'

View File

@ -101,7 +101,9 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
uint256 amount, uint256 amount,
uint256 index uint256 index
) external override onlyLendingPool { ) external override onlyLendingPool {
_burn(user, amount.rayDiv(index)); uint256 amountScaled = amount.rayDiv(index);
require(amountScaled != 0, Errors.INVALID_BURN_AMOUNT);
_burn(user, amountScaled);
//transfers the underlying to the target //transfers the underlying to the target
IERC20(UNDERLYING_ASSET_ADDRESS).safeTransfer(receiverOfUnderlying, amount); IERC20(UNDERLYING_ASSET_ADDRESS).safeTransfer(receiverOfUnderlying, amount);
@ -122,8 +124,9 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
uint256 amount, uint256 amount,
uint256 index uint256 index
) external override onlyLendingPool { ) external override onlyLendingPool {
//mint an equivalent amount of tokens to cover the new deposit uint256 amountScaled = amount.rayDiv(index);
_mint(user, amount.rayDiv(index)); require(amountScaled != 0, Errors.INVALID_MINT_AMOUNT);
_mint(user, amountScaled);
//transfer event to track balances //transfer event to track balances
emit Transfer(address(0), user, amount); emit Transfer(address(0), user, amount);

View File

@ -7,6 +7,7 @@ import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol';
import {DebtTokenBase} from './base/DebtTokenBase.sol'; import {DebtTokenBase} from './base/DebtTokenBase.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {IVariableDebtToken} from './interfaces/IVariableDebtToken.sol'; import {IVariableDebtToken} from './interfaces/IVariableDebtToken.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
/** /**
* @title contract VariableDebtToken * @title contract VariableDebtToken
@ -60,7 +61,10 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
uint256 index uint256 index
) external override onlyLendingPool { ) external override onlyLendingPool {
_mint(user, amount.rayDiv(index)); uint256 amountScaled = amount.rayDiv(index);
require(amountScaled != 0, Errors.INVALID_MINT_AMOUNT);
_mint(user, amountScaled);
emit Transfer(address(0), user, amount); emit Transfer(address(0), user, amount);
emit Mint(user, amount, index); emit Mint(user, amount, index);
@ -76,7 +80,11 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
uint256 amount, uint256 amount,
uint256 index uint256 index
) external override onlyLendingPool { ) external override onlyLendingPool {
_burn(user, amount.rayDiv(index));
uint256 amountScaled = amount.rayDiv(index);
require(amountScaled != 0, Errors.INVALID_BURN_AMOUNT);
_burn(user, amountScaled);
emit Transfer(user, address(0), amount); emit Transfer(user, address(0), amount);
emit Burn(user, amount, index); emit Burn(user, amount, index);