Merge branch 'fix/8' into 'master'

Resolve "Move redeem() to LendingPool"

Closes #8

See merge request aave-tech/protocol-v2!15
This commit is contained in:
The-3D 2020-08-19 11:33:46 +00:00
commit e01b39814d
14 changed files with 267 additions and 310 deletions

View File

@ -73,13 +73,13 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
); );
/** /**
* @dev emitted during a redeem action. * @dev emitted during a withdraw action.
* @param _reserve the address of the reserve * @param _reserve the address of the reserve
* @param _user the address of the user * @param _user the address of the user
* @param _amount the amount to be deposited * @param _amount the amount to be withdrawn
* @param _timestamp the timestamp of the action * @param _timestamp the timestamp of the action
**/ **/
event RedeemUnderlying( event Withdraw(
address indexed _reserve, address indexed _reserve,
address indexed _user, address indexed _user,
uint256 _amount, uint256 _amount,
@ -277,7 +277,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
} }
//minting AToken to user 1:1 with the specific exchange rate //minting AToken to user 1:1 with the specific exchange rate
aToken.mintOnDeposit(msg.sender, _amount); aToken.mint(msg.sender, _amount);
//transfer to the aToken contract //transfer to the aToken contract
IERC20(_reserve).safeTransferFrom(msg.sender, address(aToken), _amount); IERC20(_reserve).safeTransferFrom(msg.sender, address(aToken), _amount);
@ -287,36 +287,47 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
} }
/** /**
* @dev Redeems the underlying amount of assets requested by _user. * @dev withdraws the assets of _user.
* This function is executed by the overlying aToken contract in response to a redeem action.
* @param _reserve the address of the reserve * @param _reserve the address of the reserve
* @param _user the address of the user performing the action
* @param _amount the underlying amount to be redeemed * @param _amount the underlying amount to be redeemed
**/ **/
function redeemUnderlying( function withdraw(address _reserve, uint256 _amount) external nonReentrant {
address _reserve,
address payable _user,
uint256 _amount,
uint256 _aTokenBalanceAfterRedeem
) external nonReentrant {
ReserveLogic.ReserveData storage reserve = reserves[_reserve]; ReserveLogic.ReserveData storage reserve = reserves[_reserve];
AToken aToken = AToken(payable(reserve.aTokenAddress)); AToken aToken = AToken(payable(reserve.aTokenAddress));
ValidationLogic.validateRedeem(reserve, _reserve, _amount); uint256 userBalance = aToken.balanceOf(msg.sender);
uint256 amountToWithdraw = _amount;
//if amount is equal to uint(-1), the user wants to redeem everything
if (_amount == UINT_MAX_VALUE) {
amountToWithdraw = userBalance;
}
ValidationLogic.validateWithdraw(
_reserve,
address(aToken),
amountToWithdraw,
userBalance,
reserves,
usersConfig[msg.sender],
reservesList,
addressesProvider.getPriceOracle()
);
reserve.updateCumulativeIndexesAndTimestamp(); reserve.updateCumulativeIndexesAndTimestamp();
reserve.updateInterestRates(_reserve, 0, _amount); reserve.updateInterestRates(_reserve, 0, amountToWithdraw);
if (_aTokenBalanceAfterRedeem == 0) { if (amountToWithdraw == userBalance) {
usersConfig[_user].setUsingAsCollateral(reserve.index, false); usersConfig[msg.sender].setUsingAsCollateral(reserve.index, false);
} }
AToken(reserve.aTokenAddress).transferUnderlyingTo(_user, _amount); aToken.burn(msg.sender, msg.sender, amountToWithdraw);
//solium-disable-next-line //solium-disable-next-line
emit RedeemUnderlying(_reserve, _user, _amount, block.timestamp); emit Withdraw(_reserve, msg.sender, _amount, block.timestamp);
} }
/** /**
@ -457,11 +468,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
usersConfig[_onBehalfOf].setBorrowing(reserve.index, false); usersConfig[_onBehalfOf].setBorrowing(reserve.index, false);
} }
IERC20(_reserve).safeTransferFrom( IERC20(_reserve).safeTransferFrom(msg.sender, reserve.aTokenAddress, vars.paybackAmount);
msg.sender,
reserve.aTokenAddress,
vars.paybackAmount
);
emit Repay( emit Repay(
_reserve, _reserve,
@ -485,7 +492,13 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
ReserveLogic.InterestRateMode rateMode = ReserveLogic.InterestRateMode(_rateMode); ReserveLogic.InterestRateMode rateMode = ReserveLogic.InterestRateMode(_rateMode);
ValidationLogic.validateSwapRateMode(reserve, usersConfig[msg.sender], stableDebt, variableDebt, rateMode); ValidationLogic.validateSwapRateMode(
reserve,
usersConfig[msg.sender],
stableDebt,
variableDebt,
rateMode
);
reserve.updateCumulativeIndexesAndTimestamp(); reserve.updateCumulativeIndexesAndTimestamp();

View File

@ -146,7 +146,6 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
vars.userCollateralBalance = IERC20(collateralReserve.aTokenAddress).balanceOf(_user); vars.userCollateralBalance = IERC20(collateralReserve.aTokenAddress).balanceOf(_user);
vars.isCollateralEnabled = vars.isCollateralEnabled =
collateralReserve.configuration.getLiquidationThreshold() > 0 && collateralReserve.configuration.getLiquidationThreshold() > 0 &&
userConfig.isUsingAsCollateral(collateralReserve.index); userConfig.isUsingAsCollateral(collateralReserve.index);
@ -247,8 +246,7 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
collateralReserve.updateInterestRates(_collateral, 0, vars.maxCollateralToLiquidate); collateralReserve.updateInterestRates(_collateral, 0, vars.maxCollateralToLiquidate);
//burn the equivalent amount of atoken //burn the equivalent amount of atoken
vars.collateralAtoken.burnOnLiquidation(_user, vars.maxCollateralToLiquidate); vars.collateralAtoken.burn(_user, msg.sender, vars.maxCollateralToLiquidate);
vars.collateralAtoken.transferUnderlyingTo(msg.sender, vars.maxCollateralToLiquidate);
} }
//transfers the principal currency to the aToken //transfers the principal currency to the aToken

View File

@ -41,29 +41,46 @@ library ValidationLogic {
{ {
(bool isActive, bool isFreezed, , ) = _reserve.configuration.getFlags(); (bool isActive, bool isFreezed, , ) = _reserve.configuration.getFlags();
internalValidateReserveStateAndAmount(_reserve, _amount); require(_amount > 0, 'Amount must be greater than 0');
} }
/** /**
* @dev validates a redeem. * @dev validates a withdraw action.
* @param _reserve the reserve state from which the user is redeeming
* @param _reserveAddress the address of the reserve * @param _reserveAddress the address of the reserve
* @param _amount the amount to be redeemed * @param _aTokenAddress the address of the aToken for the reserve
* @param _amount the amount to be withdrawn
* @param _userBalance the balance of the user
*/ */
function validateRedeem( function validateWithdraw(
ReserveLogic.ReserveData storage _reserve,
address _reserveAddress, address _reserveAddress,
uint256 _amount address _aTokenAddress,
uint256 _amount,
uint256 _userBalance,
mapping(address => ReserveLogic.ReserveData) storage _reservesData,
UserConfiguration.Map storage _userConfig,
address[] calldata _reserves,
address _oracle
) external view { ) external view {
internalValidateReserveStateAndAmount(_reserve, _amount); require(_amount > 0, 'Amount must be greater than 0');
require(msg.sender == _reserve.aTokenAddress, '31'); uint256 currentAvailableLiquidity = IERC20(_reserveAddress).balanceOf(address(_aTokenAddress));
uint256 currentAvailableLiquidity = IERC20(_reserveAddress).balanceOf(
address(_reserve.aTokenAddress)
);
require(currentAvailableLiquidity >= _amount, '4'); require(currentAvailableLiquidity >= _amount, '4');
require(_amount <= _userBalance, 'User cannot withdraw more than the available balance');
require(
GenericLogic.balanceDecreaseAllowed(
_reserveAddress,
msg.sender,
_userBalance,
_reservesData,
_userConfig,
_reserves,
_oracle
),
'Transfer cannot be allowed.'
);
} }
struct ValidateBorrowLocalVars { struct ValidateBorrowLocalVars {
@ -135,9 +152,7 @@ library ValidationLogic {
); );
//check that the amount is available in the reserve //check that the amount is available in the reserve
vars.availableLiquidity = IERC20(_reserveAddress).balanceOf( vars.availableLiquidity = IERC20(_reserveAddress).balanceOf(address(_reserve.aTokenAddress));
address(_reserve.aTokenAddress)
);
require(vars.availableLiquidity >= _amount, '7'); require(vars.availableLiquidity >= _amount, '7');
@ -325,16 +340,4 @@ library ValidationLogic {
'User deposit is already being used as collateral' 'User deposit is already being used as collateral'
); );
} }
/**
* @dev validates that the reserve is active and the amount is greater than 0
* @param _reserve the state of the reserve being validated
* @param _amount the amount being validated
*/
function internalValidateReserveStateAndAmount(
ReserveLogic.ReserveData storage _reserve,
uint256 _amount
) internal view {
require(_amount > 0, 'Amount must be greater than 0');
}
} }

View File

@ -24,14 +24,15 @@ contract AToken is VersionedInitializable, ERC20 {
uint256 public constant UINT_MAX_VALUE = uint256(-1); uint256 public constant UINT_MAX_VALUE = uint256(-1);
/** /**
* @dev emitted after the redeem action * @dev emitted after aTokens are burned
* @param _from the address performing the redeem * @param _from the address performing the redeem
* @param _value the amount to be redeemed * @param _value the amount to be redeemed
* @param _fromBalanceIncrease the cumulated balance since the last update of the user * @param _fromBalanceIncrease the cumulated balance since the last update of the user
* @param _fromIndex the last index of the user * @param _fromIndex the last index of the user
**/ **/
event Redeem( event Burn(
address indexed _from, address indexed _from,
address indexed _target,
uint256 _value, uint256 _value,
uint256 _fromBalanceIncrease, uint256 _fromBalanceIncrease,
uint256 _fromIndex uint256 _fromIndex
@ -44,22 +45,7 @@ contract AToken is VersionedInitializable, ERC20 {
* @param _fromBalanceIncrease the cumulated balance since the last update of the user * @param _fromBalanceIncrease the cumulated balance since the last update of the user
* @param _fromIndex the last index of the user * @param _fromIndex the last index of the user
**/ **/
event MintOnDeposit( event Mint(
address indexed _from,
uint256 _value,
uint256 _fromBalanceIncrease,
uint256 _fromIndex
);
/**
* @dev emitted during the liquidation action, when the liquidator reclaims the underlying
* asset
* @param _from the address from which the tokens are being burned
* @param _value the amount to be burned
* @param _fromBalanceIncrease the cumulated balance since the last update of the user
* @param _fromIndex the last index of the user
**/
event BurnOnLiquidation(
address indexed _from, address indexed _from,
uint256 _value, uint256 _value,
uint256 _fromBalanceIncrease, uint256 _fromBalanceIncrease,
@ -216,74 +202,52 @@ contract AToken is VersionedInitializable, ERC20 {
} }
/** /**
* @dev redeems aToken for the underlying asset * @dev burns the aTokens and sends the equivalent amount of underlying to the target.
* @param _amount the amount being redeemed * only lending pools can call this function
* @param _amount the amount being burned
**/ **/
function redeem(uint256 _amount) external { function burn(
require(_amount > 0, 'Amount to redeem needs to be > 0'); address _user,
address _underlyingTarget,
uint256 _amount
) external onlyLendingPool {
//cumulates the balance of the user //cumulates the balance of the user
(, uint256 currentBalance, uint256 balanceIncrease) = calculateBalanceIncreaseInternal( (, uint256 currentBalance, uint256 balanceIncrease) = calculateBalanceIncreaseInternal(_user);
msg.sender
);
uint256 amountToRedeem = _amount;
//if amount is equal to uint(-1), the user wants to redeem everything
if (_amount == UINT_MAX_VALUE) {
amountToRedeem = currentBalance;
}
require(amountToRedeem <= currentBalance, 'User cannot redeem more than the available balance');
//check that the user is allowed to redeem the amount
require(isTransferAllowed(msg.sender, amountToRedeem), 'Transfer cannot be allowed.');
//if the user is redirecting his interest towards someone else, //if the user is redirecting his interest towards someone else,
//we update the redirected balance of the redirection address by adding the accrued interest, //we update the redirected balance of the redirection address by adding the accrued interest,
//and removing the amount to redeem //and removing the amount to redeem
updateRedirectedBalanceOfRedirectionAddressInternal( updateRedirectedBalanceOfRedirectionAddressInternal(_user, balanceIncrease, _amount);
msg.sender,
balanceIncrease,
amountToRedeem
);
if(balanceIncrease > amountToRedeem){ if (balanceIncrease > _amount) {
_mint(msg.sender, balanceIncrease.sub(amountToRedeem)); _mint(_user, balanceIncrease.sub(_amount));
} } else {
else{ _burn(_user, _amount.sub(balanceIncrease));
_burn(msg.sender, amountToRedeem.sub(balanceIncrease));
} }
uint256 userIndex = 0; uint256 userIndex = 0;
//reset the user data if the remaining balance is 0 //reset the user data if the remaining balance is 0
if (currentBalance.sub(amountToRedeem) == 0) { if (currentBalance.sub(_amount) == 0) {
resetDataOnZeroBalanceInternal(msg.sender); resetDataOnZeroBalanceInternal(_user);
} else { } else {
//updates the user index //updates the user index
userIndex = userIndexes[msg.sender] = pool.getReserveNormalizedIncome(underlyingAssetAddress); userIndex = userIndexes[_user] = pool.getReserveNormalizedIncome(underlyingAssetAddress);
} }
// executes redeem of the underlying asset //transfers the underlying to the target
pool.redeemUnderlying( ERC20(underlyingAssetAddress).safeTransfer(_underlyingTarget, _amount);
underlyingAssetAddress,
msg.sender,
amountToRedeem,
currentBalance.sub(amountToRedeem)
);
emit Redeem(msg.sender, amountToRedeem, balanceIncrease, userIndex); emit Burn(msg.sender, _underlyingTarget, _amount, balanceIncrease, userIndex);
} }
/** /**
* @dev mints token in the event of users depositing the underlying asset into the lending pool * @dev mints aTokens to _user
* only lending pools can call this function * only lending pools can call this function
* @param _user the address receiving the minted tokens * @param _user the address receiving the minted tokens
* @param _amount the amount of tokens to mint * @param _amount the amount of tokens to mint
*/ */
function mintOnDeposit(address _user, uint256 _amount) external onlyLendingPool { function mint(address _user, uint256 _amount) external onlyLendingPool {
//cumulates the balance of the user //cumulates the balance of the user
(, , uint256 balanceIncrease) = calculateBalanceIncreaseInternal(_user); (, , uint256 balanceIncrease) = calculateBalanceIncreaseInternal(_user);
@ -298,36 +262,7 @@ contract AToken is VersionedInitializable, ERC20 {
//mint an equivalent amount of tokens to cover the new deposit //mint an equivalent amount of tokens to cover the new deposit
_mint(_user, _amount.add(balanceIncrease)); _mint(_user, _amount.add(balanceIncrease));
emit MintOnDeposit(_user, _amount, balanceIncrease, index); emit Mint(_user, _amount, balanceIncrease, index);
}
/**
* @dev burns token in the event of a borrow being liquidated, in case the liquidators reclaims the underlying asset
* Transfer of the liquidated asset is executed by the lending pool contract.
* only lending pools can call this function
* @param _account the address from which burn the aTokens
* @param _value the amount to burn
**/
function burnOnLiquidation(address _account, uint256 _value) external onlyLendingPool {
//cumulates the balance of the user being liquidated
(, uint256 accountBalance, uint256 balanceIncrease, uint256 index) = cumulateBalanceInternal(
_account
);
//adds the accrued interest and substracts the burned amount to
//the redirected balance
updateRedirectedBalanceOfRedirectionAddressInternal(_account, balanceIncrease, _value);
//burns the requested amount of tokens
_burn(_account, _value);
bool userIndexReset = false;
//reset the user data if the remaining balance is 0
if (accountBalance.sub(_value) == 0) {
userIndexReset = resetDataOnZeroBalanceInternal(_account);
}
emit BurnOnLiquidation(_account, _value, balanceIncrease, userIndexReset ? 0 : index);
} }
/** /**
@ -450,7 +385,6 @@ contract AToken is VersionedInitializable, ERC20 {
return redirectedBalances[_user]; return redirectedBalances[_user];
} }
/** /**
* @dev calculates the increase in balance since the last user action * @dev calculates the increase in balance since the last user action
* @param _user the address of the user * @param _user the address of the user
@ -492,7 +426,11 @@ contract AToken is VersionedInitializable, ERC20 {
uint256 uint256
) )
{ {
(uint256 previousBalance, uint256 currentBalance, uint256 balanceIncrease) = calculateBalanceIncreaseInternal(_user); (
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease
) = calculateBalanceIncreaseInternal(_user);
_mint(_user, balanceIncrease); _mint(_user, balanceIncrease);
@ -500,7 +438,6 @@ contract AToken is VersionedInitializable, ERC20 {
uint256 index = userIndexes[_user] = pool.getReserveNormalizedIncome(underlyingAssetAddress); uint256 index = userIndexes[_user] = pool.getReserveNormalizedIncome(underlyingAssetAddress);
return (previousBalance, currentBalance, balanceIncrease, index); return (previousBalance, currentBalance, balanceIncrease, index);
} }
/** /**

View File

@ -5,7 +5,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x666D47050E77ADB0B04076fB35DDcb74e95D1d7C", "address": "0x58F132FBB86E21545A4Bace3C19f1C05d86d7A22",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -15,7 +15,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x1FB61ED838A993b8885Ceb08936524F742F525cf", "address": "0xa4bcDF64Cdd5451b6ac3743B414124A6299B65FF",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -25,7 +25,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xcBf7A8f676Bf5fa60339ba8dFab867D4a074c604", "address": "0x5A0773Ff307Bf7C71a832dBB5312237fD3437f9F",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -34,7 +34,7 @@
"address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e" "address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e"
}, },
"localhost": { "localhost": {
"address": "0x26aBe949b24C10cc9b1d33100Cd7fF3Aa5e4C698" "address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e"
} }
}, },
"LendingPoolParametersProvider": { "LendingPoolParametersProvider": {
@ -52,7 +52,7 @@
"address": "0x9EC0480CF106d6dc1c7849BA141a56F874170F97" "address": "0x9EC0480CF106d6dc1c7849BA141a56F874170F97"
}, },
"localhost": { "localhost": {
"address": "0xaD0FdA3C2D467DEE48DFc3b4C123240F6e90D3c2" "address": "0x9EC0480CF106d6dc1c7849BA141a56F874170F97"
} }
}, },
"LendingPoolDataProvider": { "LendingPoolDataProvider": {
@ -65,7 +65,7 @@
"address": "0x6642B57e4265BAD868C17Fc1d1F4F88DBBA04Aa8" "address": "0x6642B57e4265BAD868C17Fc1d1F4F88DBBA04Aa8"
}, },
"localhost": { "localhost": {
"address": "0x29c1e17Ac4aAf9fEE3091A8DdAAf5B7798bcC4b9" "address": "0x6642B57e4265BAD868C17Fc1d1F4F88DBBA04Aa8"
} }
}, },
"PriceOracle": { "PriceOracle": {
@ -74,7 +74,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xfdAF4f6e47e854c05bE158993d32872e784F0502", "address": "0x099d9fF8F818290C8b5B7Db5bFca84CEebd2714c",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -84,7 +84,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x8d0FF86F21174b33f86A2673E96e8D7a472659A3", "address": "0xAF6BA11790D1942625C0c2dA07da19AB63845cfF",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -94,7 +94,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xf6fFAbB561D5b265127459cB7e43c89f58b7cAbe", "address": "0xD83D2773a7873ae2b5f8Fb92097e20a8C64F691E",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -104,7 +104,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x5DAe571bb5B70f9851eeef12E3a43f548dCF923c", "address": "0xf91aC1098F3b154671Ce83290114aaE45ac0225f",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -114,7 +114,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x5a3343A0CF72dC6933362676Bb5831784CaA0014", "address": "0x830bceA96E56DBC1F8578f75fBaC0AF16B32A07d",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -149,7 +149,7 @@
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4" "address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
}, },
"localhost": { "localhost": {
"address": "0x61751f72Fa303F3bB256707dD3cD368c89E82f1b" "address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
} }
}, },
"InitializableAdminUpgradeabilityProxy": { "InitializableAdminUpgradeabilityProxy": {
@ -158,7 +158,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x61751f72Fa303F3bB256707dD3cD368c89E82f1b", "address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -167,7 +167,7 @@
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60" "address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
}, },
"localhost": { "localhost": {
"address": "0xdF19a9539Fdd701D8334299C6Dd04931e4022303" "address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
} }
}, },
"WalletBalanceProvider": { "WalletBalanceProvider": {
@ -176,7 +176,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xBe6d8642382C241c9B4B50c89574DbF3f4181E7D", "address": "0x392E5355a0e88Bd394F717227c752670fb3a8020",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -186,7 +186,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x8733AfE8174BA7c04c6CD694bD673294079b7E10", "address": "0x7c2C195CD6D34B8F845992d380aADB2730bB9C6F",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -196,7 +196,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xA8083d78B6ABC328b4d3B714F76F384eCC7147e1", "address": "0x8858eeB3DfffA017D4BCE9801D340D36Cf895CCf",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -206,7 +206,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xa497f1Ed4edeA8151fECe457aa26e1D6A4318B6A", "address": "0x0078371BDeDE8aAc7DeBfFf451B74c5EDB385Af7",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -216,7 +216,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xB7b9568073C9e745acD84eEb30F1c32F74Ba4946", "address": "0xf4e77E5Da47AC3125140c470c71cBca77B5c638c",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -226,7 +226,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x64999a4272342C910FB8f6a71C2Ca50b878a8658", "address": "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -236,7 +236,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xFB6800f1BB30e235587b574F8Ce6c7bba2242276", "address": "0x038B86d9d8FAFdd0a02ebd1A476432877b0107C8",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -246,7 +246,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x832D8fDeeE7Df842796582bC7F804802c2c666fd", "address": "0x1A1FEe7EeD918BD762173e4dc5EfDB8a78C924A8",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -256,7 +256,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x8628E920E86DA923A79A57Ab4282CC9f89E12CEf", "address": "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -266,7 +266,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x04C90bD686E03782737C3f4C6bDC88dc3C92bDec", "address": "0xc4905364b78a742ccce7B890A89514061E47068D",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -276,7 +276,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x002164e9C8425D2F0c7dcde98E63317D305302C5", "address": "0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -286,7 +286,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xAe407A0bD891d02E495D3E79cE577C17BB61f366", "address": "0x8B5B7a6055E54a36fF574bbE40cf2eA68d5554b3",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -296,7 +296,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x96cf3831338c19F309121D48C12C3aB489FE7D5A", "address": "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -306,7 +306,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xfd1346a9ee71839D6103C76Bb63d1592971C23aE", "address": "0x20Ce94F404343aD2752A2D01b43fa407db9E0D00",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -316,7 +316,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x9884cF2d612CdD7031cCaa12dd3Bc69D754fc701", "address": "0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -326,7 +326,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x48fc85A6fcD880e2421586f4F9116f14e854E109", "address": "0x2D8553F9ddA85A9B3259F6Bf26911364B85556F5",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -336,7 +336,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x1bfF9DBd010EF644863918f77aCF79BD35721c13", "address": "0x52d3b94181f8654db2530b0fEe1B19173f519C52",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -346,7 +346,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xB42D37cB0E78aaCC5980eC6B2EcB98CBeCeB9df7", "address": "0xd15468525c35BDBC1eD8F2e09A00F8a173437f2f",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -356,7 +356,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x8051CFC72E5c27fD752834a854eDD306c254D3b1", "address": "0x7e35Eaf7e8FBd7887ad538D4A38Df5BbD073814a",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -366,7 +366,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x2F16C47532625acE7C652FC5EE7E9a9080B352f5", "address": "0x5bcb88A0d20426e451332eE6C4324b0e663c50E0",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -376,7 +376,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x7483ADEC5d3dA2203CCB2Fc5F837c6F8a1A92099", "address": "0x3521eF8AaB0323004A6dD8b03CE890F4Ea3A13f5",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -386,7 +386,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xe6688b6Cc79268D2e39f799C08673034a5350F13", "address": "0x53369fd4680FfE3DfF39Fc6DDa9CfbfD43daeA2E",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -396,7 +396,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xFa58524E6B3E432fb10B41A9fea95BAD32A608eF", "address": "0xB00cC45B4a7d3e1FEE684cFc4417998A1c183e6d",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -406,7 +406,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x666D47050E77ADB0B04076fB35DDcb74e95D1d7C", "address": "0x58F132FBB86E21545A4Bace3C19f1C05d86d7A22",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -415,7 +415,7 @@
"address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460" "address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460"
}, },
"localhost": { "localhost": {
"address": "0x02BB514187B830d6A2111197cd7D8cb60650B970" "address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460"
} }
}, },
"StableDebtToken": { "StableDebtToken": {
@ -424,7 +424,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xbC15a5eEA769cfB4BA6d7574c9942f0b8C40Ae03", "address": "0xA0AB1cB92A4AF81f84dCd258155B5c25D247b54E",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -434,13 +434,13 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x3c3AB51fF33032159e82E1FDEe6503dEd082F1d9", "address": "0x5f7134cd38C826a7649f9Cc47dda24d834DD2967",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
"AToken": { "AToken": {
"localhost": { "localhost": {
"address": "0x2d17b3E44e413F1fDa30E569895863EeD139CE6B", "address": "0xE91bBe8ee03560E3dda2786f95335F5399813Ca0",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"buidlerevm": { "buidlerevm": {
@ -454,7 +454,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0xc2517909aE3cFacC0283EB8FB917EAe273a3aE9e", "address": "0x7f23223A2FAf869962B38f5eC4aAB7f37454A45e",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -464,7 +464,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
"address": "0x501A498e8FDA589038d6526C2153a9fdc9d8eDD2", "address": "0xf784709d2317D872237C4bC22f867d1BAe2913AB",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
@ -472,12 +472,20 @@
"buidlerevm": { "buidlerevm": {
"address": "0x6aaF7e94e099291a94ed8E245c90f4766CE9bB7C", "address": "0x6aaF7e94e099291a94ed8E245c90f4766CE9bB7C",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
"address": "0x1203D1b97BF6E546c00C45Cda035D3010ACe1180",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
}, },
"MockVariableDebtToken": { "MockVariableDebtToken": {
"buidlerevm": { "buidlerevm": {
"address": "0x40A939911b662656C0EE71c19B954DB1911Dc8e3", "address": "0x40A939911b662656C0EE71c19B954DB1911Dc8e3",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
"address": "0x8733AfE8174BA7c04c6CD694bD673294079b7E10",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
} }
} }
} }

View File

@ -5,16 +5,14 @@ import {ProtocolErrors} from '../helpers/types';
makeSuite('AToken: Modifiers', (testEnv: TestEnv) => { makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
const {INVALID_POOL_CALLER_MSG_1} = ProtocolErrors; const {INVALID_POOL_CALLER_MSG_1} = ProtocolErrors;
it('Tries to invoke mintOnDeposit not being the LendingPool', async () => { it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, aDai} = testEnv; const {deployer, aDai} = testEnv;
await expect(aDai.mintOnDeposit(deployer.address, '1')).to.be.revertedWith( await expect(aDai.mint(deployer.address, '1')).to.be.revertedWith(INVALID_POOL_CALLER_MSG_1);
INVALID_POOL_CALLER_MSG_1
);
}); });
it('Tries to invoke burnOnLiquidation not being the LendingPool', async () => { it('Tries to invoke burn not being the LendingPool', async () => {
const {deployer, aDai} = testEnv; const {deployer, aDai} = testEnv;
await expect(aDai.burnOnLiquidation(deployer.address, '1')).to.be.revertedWith( await expect(aDai.burn(deployer.address, deployer.address, '1')).to.be.revertedWith(
INVALID_POOL_CALLER_MSG_1 INVALID_POOL_CALLER_MSG_1
); );
}); });

View File

@ -2,9 +2,9 @@ import BigNumber from 'bignumber.js';
import { import {
calcExpectedReserveDataAfterDeposit, calcExpectedReserveDataAfterDeposit,
calcExpectedReserveDataAfterRedeem, calcExpectedReserveDataAfterWithdraw,
calcExpectedUserDataAfterDeposit, calcExpectedUserDataAfterDeposit,
calcExpectedUserDataAfterRedeem, calcExpectedUserDataAfterWithdraw,
calcExpectedReserveDataAfterBorrow, calcExpectedReserveDataAfterBorrow,
calcExpectedUserDataAfterBorrow, calcExpectedUserDataAfterBorrow,
calcExpectedReserveDataAfterRepay, calcExpectedReserveDataAfterRepay,
@ -206,7 +206,7 @@ export const deposit = async (
} }
}; };
export const redeem = async ( export const withdraw = async (
reserveSymbol: string, reserveSymbol: string,
amount: string, amount: string,
user: SignerWithAddress, user: SignerWithAddress,
@ -214,6 +214,8 @@ export const redeem = async (
testEnv: TestEnv, testEnv: TestEnv,
revertMessage?: string revertMessage?: string
) => { ) => {
const {pool} = testEnv;
const { const {
aTokenInstance, aTokenInstance,
reserve, reserve,
@ -221,17 +223,17 @@ export const redeem = async (
reserveData: reserveDataBefore, reserveData: reserveDataBefore,
} = await getDataBeforeAction(reserveSymbol, user.address, testEnv); } = await getDataBeforeAction(reserveSymbol, user.address, testEnv);
let amountToRedeem = '0'; let amountToWithdraw = '0';
if (amount !== '-1') { if (amount !== '-1') {
amountToRedeem = (await convertToCurrencyDecimals(reserve, amount)).toString(); amountToWithdraw = (await convertToCurrencyDecimals(reserve, amount)).toString();
} else { } else {
amountToRedeem = MAX_UINT_AMOUNT; amountToWithdraw = MAX_UINT_AMOUNT;
} }
if (expectedResult === 'success') { if (expectedResult === 'success') {
const txResult = await waitForTx( const txResult = await waitForTx(
await aTokenInstance.connect(user.signer).redeem(amountToRedeem) await pool.connect(user.signer).withdraw(reserve, amountToWithdraw)
); );
const { const {
@ -242,15 +244,15 @@ export const redeem = async (
const {txCost, txTimestamp} = await getTxCostAndTimestamp(txResult); const {txCost, txTimestamp} = await getTxCostAndTimestamp(txResult);
const expectedReserveData = calcExpectedReserveDataAfterRedeem( const expectedReserveData = calcExpectedReserveDataAfterWithdraw(
amountToRedeem, amountToWithdraw,
reserveDataBefore, reserveDataBefore,
userDataBefore, userDataBefore,
txTimestamp txTimestamp
); );
const expectedUserData = calcExpectedUserDataAfterRedeem( const expectedUserData = calcExpectedUserDataAfterWithdraw(
amountToRedeem, amountToWithdraw,
reserveDataBefore, reserveDataBefore,
expectedReserveData, expectedReserveData,
userDataBefore, userDataBefore,
@ -259,7 +261,7 @@ export const redeem = async (
txCost txCost
); );
const actualAmountRedeemed = userDataBefore.currentATokenBalance.minus( const actualAmountWithdrawn = userDataBefore.currentATokenBalance.minus(
expectedUserData.currentATokenBalance expectedUserData.currentATokenBalance
); );
@ -273,7 +275,7 @@ export const redeem = async (
// ); // );
// }); // });
} else if (expectedResult === 'revert') { } else if (expectedResult === 'revert') {
await expect(aTokenInstance.connect(user.signer).redeem(amountToRedeem), revertMessage).to.be await expect(pool.connect(user.signer).withdraw(reserve, amountToWithdraw), revertMessage).to.be
.reverted; .reverted;
} }
}; };

View File

@ -4,7 +4,7 @@ import {
approve, approve,
deposit, deposit,
borrow, borrow,
redeem, withdraw,
repay, repay,
setUseAsCollateral, setUseAsCollateral,
swapBorrowRateMode, swapBorrowRateMode,
@ -102,15 +102,15 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv
} }
break; break;
case 'redeem': case 'withdraw':
{ {
const {amount} = action.args; const {amount} = action.args;
if (!amount || amount === '') { if (!amount || amount === '') {
throw `Invalid amount to redeem from the ${reserve} reserve`; throw `Invalid amount to withdraw from the ${reserve} reserve`;
} }
await redeem(reserve, amount, user, expected, testEnv, revertMessage); await withdraw(reserve, amount, user, expected, testEnv, revertMessage);
} }
break; break;
case 'borrow': case 'borrow':

View File

@ -122,10 +122,10 @@
] ]
}, },
{ {
"description": "User 0 redeems the deposited DAI plus interest", "description": "User 0 withdraws the deposited DAI plus interest",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -178,7 +178,7 @@
] ]
}, },
{ {
"description": "User 0 deposits 1000 DAI, user 1,2,3,4 deposit 1 WETH each and borrow 100 DAI at stable rate. Everything is repaid, user 0 redeems", "description": "User 0 deposits 1000 DAI, user 1,2,3,4 deposit 1 WETH each and borrow 100 DAI at stable rate. Everything is repaid, user 0 withdraws",
"actions": [ "actions": [
{ {
"name": "mint", "name": "mint",
@ -475,7 +475,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -486,7 +486,7 @@
] ]
}, },
{ {
"description": "User 0 deposits 1000 DAI, user 1 deposits 2 WETH and borrow 100 DAI at stable rate first, then 100 DAI at variable rate, repays everything. User 0 redeems", "description": "User 0 deposits 1000 DAI, user 1 deposits 2 WETH and borrow 100 DAI at stable rate first, then 100 DAI at variable rate, repays everything. User 0 withdraws",
"actions": [ "actions": [
{ {
"name": "mint", "name": "mint",
@ -593,7 +593,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",

View File

@ -185,10 +185,10 @@
] ]
}, },
{ {
"description": "User 0 redeems the deposited DAI plus interest", "description": "User 0 withdraws the deposited DAI plus interest",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -199,10 +199,10 @@
] ]
}, },
{ {
"description": "User 1 redeems the collateral", "description": "User 1 withdraws the collateral",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
@ -420,10 +420,10 @@
] ]
}, },
{ {
"description": "User 0 redeems the deposited WETH plus interest", "description": "User 0 withdraws the deposited WETH plus interest",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
@ -435,10 +435,10 @@
] ]
}, },
{ {
"description": "User 1 redeems the collateral", "description": "User 1 withdraws the collateral",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "LINK", "reserve": "LINK",
"amount": "-1", "amount": "-1",
@ -600,10 +600,10 @@
] ]
}, },
{ {
"description": "User 0 redeems the deposited USDC plus interest", "description": "User 0 withdraws the deposited USDC plus interest",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "USDC", "reserve": "USDC",
"amount": "-1", "amount": "-1",
@ -614,10 +614,10 @@
] ]
}, },
{ {
"description": "User 1 redeems the collateral", "description": "User 1 withdraws the collateral",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
"amount": "-1", "amount": "-1",
@ -713,10 +713,10 @@
] ]
}, },
{ {
"description": "user 3 redeems the 0.1 ETH", "description": "user 3 withdraws the 0.1 ETH",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
@ -813,10 +813,10 @@
] ]
}, },
{ {
"description": "user 3 redeems the 0.1 ETH", "description": "user 3 withdraws the 0.1 ETH",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
@ -828,7 +828,7 @@
] ]
}, },
{ {
"description": "User 0 deposits 1000 DAI, user 6 deposits 2 WETH and borrow 100 DAI at variable rate first, then 100 DAI at stable rate, repays everything. User 0 redeems", "description": "User 0 deposits 1000 DAI, user 6 deposits 2 WETH and borrow 100 DAI at variable rate first, then 100 DAI at stable rate, repays everything. User 0 withdraws",
"actions": [ "actions": [
{ {
"name": "mint", "name": "mint",
@ -946,7 +946,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",

View File

@ -104,7 +104,7 @@
] ]
}, },
{ {
"description": "User 1 borrows another 100 DAI, repay the whole amount. Users 0 and User 2 redeem", "description": "User 1 borrows another 100 DAI, repay the whole amount. Users 0 and User 2 withdraw",
"actions": [ "actions": [
{ {
"name": "borrow", "name": "borrow",
@ -146,7 +146,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -155,7 +155,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -166,7 +166,7 @@
] ]
}, },
{ {
"description": "User 0 deposits 1000 DAI, redirects interest to user 2, user 1 borrows 100 DAI. After one year, user 0 redirects interest back to himself, user 1 borrows another 100 DAI and after another year repays the whole amount. Users 0 and User 2 redeem", "description": "User 0 deposits 1000 DAI, redirects interest to user 2, user 1 borrows 100 DAI. After one year, user 0 redirects interest back to himself, user 1 borrows another 100 DAI and after another year repays the whole amount. Users 0 and User 2 withdraw",
"actions": [ "actions": [
{ {
"name": "deposit", "name": "deposit",
@ -246,7 +246,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -255,7 +255,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -266,7 +266,7 @@
] ]
}, },
{ {
"description": "User 0 deposits 1000 DAI, redirects interest to user 2, user 1 borrows 100 DAI. After one year, user 2 redirects interest to user 3. user 1 borrows another 100 DAI, user 0 deposits another 100 DAI. User 1 repays the whole amount. Users 0, 2 first 1 DAI, then everything. User 3 redeems", "description": "User 0 deposits 1000 DAI, redirects interest to user 2, user 1 borrows 100 DAI. After one year, user 2 redirects interest to user 3. user 1 borrows another 100 DAI, user 0 deposits another 100 DAI. User 1 repays the whole amount. Users 0, 2 first 1 DAI, then everything. User 3 withdraws",
"actions": [ "actions": [
{ {
"name": "deposit", "name": "deposit",
@ -355,7 +355,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "1", "amount": "1",
@ -364,7 +364,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "1", "amount": "1",
@ -373,7 +373,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -382,7 +382,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -391,7 +391,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",

View File

@ -33,7 +33,7 @@
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "0", "amount": "0",
@ -48,7 +48,7 @@
"description": "Users 0 tries to redeem 1100 DAI from the 1000 DAI deposited (revert expected)", "description": "Users 0 tries to redeem 1100 DAI from the 1000 DAI deposited (revert expected)",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "1100", "amount": "1100",
@ -100,7 +100,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",

View File

@ -1,6 +1,6 @@
{ {
"title": "LendingPool: Redeem", "title": "LendingPool: withdraw",
"description": "Redeem function.", "description": "withdraw function.",
"stories": [ "stories": [
{ {
"description": "User 0 Deposits 1000 DAI in an empty reserve", "description": "User 0 Deposits 1000 DAI in an empty reserve",
@ -34,10 +34,10 @@
] ]
}, },
{ {
"description": "User 0 redeems half of the deposited DAI", "description": "User 0 withdraws half of the deposited DAI",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "500", "amount": "500",
@ -48,10 +48,10 @@
] ]
}, },
{ {
"description": "User 0 redeems remaining half of the deposited DAI", "description": "User 0 withdraws remaining half of the deposited DAI",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -93,10 +93,10 @@
] ]
}, },
{ {
"description": "User 0 redeems half of the deposited USDC", "description": "User 0 withdraws half of the deposited USDC",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "USDC", "reserve": "USDC",
"amount": "500", "amount": "500",
@ -107,10 +107,10 @@
] ]
}, },
{ {
"description": "User 0 redeems remaining half of the deposited USDC", "description": "User 0 withdraws remaining half of the deposited USDC",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "USDC", "reserve": "USDC",
"amount": "-1", "amount": "-1",
@ -153,10 +153,10 @@
] ]
}, },
{ {
"description": "User 0 redeems half of the deposited ETH", "description": "User 0 withdraws half of the deposited ETH",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
@ -168,10 +168,10 @@
] ]
}, },
{ {
"description": "User 0 redeems remaining half of the deposited ETH", "description": "User 0 withdraws remaining half of the deposited ETH",
"actions": [ "actions": [
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
@ -183,7 +183,7 @@
] ]
}, },
{ {
"description": "Users 0 and 1 Deposit 1000 DAI, both redeem", "description": "Users 0 and 1 Deposit 1000 DAI, both withdraw",
"actions": [ "actions": [
{ {
"name": "mint", "name": "mint",
@ -221,7 +221,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -230,7 +230,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
@ -241,7 +241,7 @@
] ]
}, },
{ {
"description": "Users 0 deposits 1000 DAI, user 1 Deposit 1000 USDC and 1 WETH, borrows 100 DAI. User 1 tries to redeem all the USDC", "description": "Users 0 deposits 1000 DAI, user 1 Deposit 1000 USDC and 1 WETH, borrows 100 DAI. User 1 tries to withdraw all the USDC",
"actions": [ "actions": [
{ {
"name": "mint", "name": "mint",
@ -333,7 +333,7 @@
"expected": "success" "expected": "success"
}, },
{ {
"name": "redeem", "name": "withdraw",
"args": { "args": {
"reserve": "USDC", "reserve": "USDC",
"amount": "-1", "amount": "-1",

View File

@ -57,7 +57,7 @@ export const calcExpectedUserDataAfterDeposit = (
if (userDataBeforeAction.currentATokenBalance.eq(0)) { if (userDataBeforeAction.currentATokenBalance.eq(0)) {
expectedUserData.usageAsCollateralEnabled = true; expectedUserData.usageAsCollateralEnabled = true;
} else { } else {
//if user is redeeming everything, usageAsCollateralEnabled must be false //if the user is withdrawing everything, usageAsCollateralEnabled must be false
if (expectedUserData.currentATokenBalance.eq(0)) { if (expectedUserData.currentATokenBalance.eq(0)) {
expectedUserData.usageAsCollateralEnabled = false; expectedUserData.usageAsCollateralEnabled = false;
} else { } else {
@ -115,8 +115,8 @@ export const calcExpectedUserDataAfterDeposit = (
return expectedUserData; return expectedUserData;
}; };
export const calcExpectedUserDataAfterRedeem = ( export const calcExpectedUserDataAfterWithdraw = (
amountRedeemed: string, amountWithdrawn: string,
reserveDataBeforeAction: ReserveData, reserveDataBeforeAction: ReserveData,
reserveDataAfterAction: ReserveData, reserveDataAfterAction: ReserveData,
userDataBeforeAction: UserReserveData, userDataBeforeAction: UserReserveData,
@ -132,12 +132,12 @@ export const calcExpectedUserDataAfterRedeem = (
txTimestamp txTimestamp
); );
if (amountRedeemed == MAX_UINT_AMOUNT) { if (amountWithdrawn == MAX_UINT_AMOUNT) {
amountRedeemed = aTokenBalance.toFixed(0); amountWithdrawn = aTokenBalance.toFixed(0);
} }
expectedUserData.principalATokenBalance = expectedUserData.currentATokenBalance = aTokenBalance.minus( expectedUserData.principalATokenBalance = expectedUserData.currentATokenBalance = aTokenBalance.minus(
amountRedeemed amountWithdrawn
); );
expectedUserData.currentStableDebt = expectedUserData.principalStableDebt = calcExpectedStableDebtTokenBalance( expectedUserData.currentStableDebt = expectedUserData.principalStableDebt = calcExpectedStableDebtTokenBalance(
@ -162,7 +162,7 @@ export const calcExpectedUserDataAfterRedeem = (
if (userDataBeforeAction.currentATokenBalance.eq(0)) { if (userDataBeforeAction.currentATokenBalance.eq(0)) {
expectedUserData.usageAsCollateralEnabled = true; expectedUserData.usageAsCollateralEnabled = true;
} else { } else {
//if user is redeeming everything, usageAsCollateralEnabled must be false //if the user is withdrawing everything, usageAsCollateralEnabled must be false
if (expectedUserData.currentATokenBalance.eq(0)) { if (expectedUserData.currentATokenBalance.eq(0)) {
expectedUserData.usageAsCollateralEnabled = false; expectedUserData.usageAsCollateralEnabled = false;
} else { } else {
@ -175,9 +175,9 @@ export const calcExpectedUserDataAfterRedeem = (
if (reserveDataBeforeAction.address === configuration.ethereumAddress) { if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
expectedUserData.walletBalance = userDataBeforeAction.walletBalance expectedUserData.walletBalance = userDataBeforeAction.walletBalance
.minus(txCost) .minus(txCost)
.plus(amountRedeemed); .plus(amountWithdrawn);
} else { } else {
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountRedeemed); expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountWithdrawn);
} }
expectedUserData.redirectedBalance = userDataBeforeAction.redirectedBalance; expectedUserData.redirectedBalance = userDataBeforeAction.redirectedBalance;
@ -199,7 +199,7 @@ export const calcExpectedUserDataAfterRedeem = (
expectedUserData, expectedUserData,
userDataBeforeAction.redirectionAddressRedirectedBalance, userDataBeforeAction.redirectionAddressRedirectedBalance,
new BigNumber(0), new BigNumber(0),
new BigNumber(amountRedeemed) new BigNumber(amountWithdrawn)
); );
return expectedUserData; return expectedUserData;
@ -255,8 +255,8 @@ export const calcExpectedReserveDataAfterDeposit = (
return expectedReserveData; return expectedReserveData;
}; };
export const calcExpectedReserveDataAfterRedeem = ( export const calcExpectedReserveDataAfterWithdraw = (
amountRedeemed: string, amountWithdrawn: string,
reserveDataBeforeAction: ReserveData, reserveDataBeforeAction: ReserveData,
userDataBeforeAction: UserReserveData, userDataBeforeAction: UserReserveData,
txTimestamp: BigNumber txTimestamp: BigNumber
@ -265,8 +265,8 @@ export const calcExpectedReserveDataAfterRedeem = (
expectedReserveData.address = reserveDataBeforeAction.address; expectedReserveData.address = reserveDataBeforeAction.address;
if (amountRedeemed == MAX_UINT_AMOUNT) { if (amountWithdrawn == MAX_UINT_AMOUNT) {
amountRedeemed = calcExpectedATokenBalance( amountWithdrawn = calcExpectedATokenBalance(
reserveDataBeforeAction, reserveDataBeforeAction,
userDataBeforeAction, userDataBeforeAction,
txTimestamp txTimestamp
@ -274,11 +274,11 @@ export const calcExpectedReserveDataAfterRedeem = (
} }
expectedReserveData.totalLiquidity = new BigNumber(reserveDataBeforeAction.totalLiquidity).minus( expectedReserveData.totalLiquidity = new BigNumber(reserveDataBeforeAction.totalLiquidity).minus(
amountRedeemed amountWithdrawn
); );
expectedReserveData.availableLiquidity = new BigNumber( expectedReserveData.availableLiquidity = new BigNumber(
reserveDataBeforeAction.availableLiquidity reserveDataBeforeAction.availableLiquidity
).minus(amountRedeemed); ).minus(amountWithdrawn);
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable; expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable;
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable; expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable;
@ -1262,7 +1262,6 @@ const calcCompoundedInterest = (
currentTimestamp: BigNumber, currentTimestamp: BigNumber,
lastUpdateTimestamp: BigNumber lastUpdateTimestamp: BigNumber
) => { ) => {
const timeDifference = currentTimestamp.minus(lastUpdateTimestamp); const timeDifference = currentTimestamp.minus(lastUpdateTimestamp);
if (timeDifference.eq(0)) { if (timeDifference.eq(0)) {
@ -1288,7 +1287,6 @@ const calcCompoundedInterest = (
.plus(ratePerSecond.times(timeDifference)) .plus(ratePerSecond.times(timeDifference))
.plus(secondTerm) .plus(secondTerm)
.plus(thirdTerm); .plus(thirdTerm);
}; };
const calcExpectedInterestRates = ( const calcExpectedInterestRates = (