mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Updating withdrawal tests
This commit is contained in:
parent
e3c422468d
commit
2e8f6ee02c
|
@ -11,6 +11,8 @@ import {
|
|||
import {IAToken} from './interfaces/IAToken.sol';
|
||||
import {IERC20} from '../interfaces/IERC20.sol';
|
||||
import {SafeERC20} from "../misc/SafeERC20.sol";
|
||||
import "@nomiclabs/buidler/console.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Aave ERC20 AToken
|
||||
|
@ -118,7 +120,9 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
|
|||
|
||||
uint256 currentBalance = balanceOf(user);
|
||||
|
||||
require(currentBalance <= amount, Errors.INVALID_ATOKEN_BALANCE);
|
||||
console.log("Amount is %s, balance is %s", amount, currentBalance);
|
||||
|
||||
require(amount <= currentBalance, Errors.INVALID_ATOKEN_BALANCE);
|
||||
|
||||
uint256 index = _pool.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS);
|
||||
|
||||
|
@ -240,6 +244,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
|
|||
return _interestRedirectionIndexes[user];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dev calculates the total supply of the specific aToken
|
||||
* since the balance of every single user increases over time, the total supply
|
||||
|
|
|
@ -65,8 +65,6 @@ export const calcExpectedUserDataAfterDeposit = (
|
|||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(amountDeposited);
|
||||
|
||||
expectedUserData.scaledATokenBalance = calcExpectedScaledATokenBalance(reserveDataAfterAction, userDataBeforeAction, new BigNumber(amountDeposited), new BigNumber(0));
|
||||
|
||||
|
||||
expectedUserData.currentATokenBalance = calcExpectedATokenBalance(
|
||||
reserveDataBeforeAction,
|
||||
userDataBeforeAction,
|
||||
|
@ -121,23 +119,26 @@ export const calcExpectedUserDataAfterWithdraw = (
|
|||
amountWithdrawn = aTokenBalance.toFixed(0);
|
||||
}
|
||||
|
||||
expectedUserData.principalATokenBalance = expectedUserData.currentATokenBalance = aTokenBalance.minus(
|
||||
expectedUserData.scaledATokenBalance = calcExpectedScaledATokenBalance(reserveDataAfterAction, userDataBeforeAction, new BigNumber(0), new BigNumber(amountWithdrawn));
|
||||
|
||||
expectedUserData.currentATokenBalance = aTokenBalance.minus(
|
||||
amountWithdrawn
|
||||
);
|
||||
|
||||
expectedUserData.currentStableDebt = expectedUserData.principalStableDebt = calcExpectedStableDebtTokenBalance(
|
||||
expectedUserData.principalStableDebt = userDataBeforeAction.principalStableDebt;
|
||||
expectedUserData.principalVariableDebt = userDataBeforeAction.principalVariableDebt;
|
||||
|
||||
expectedUserData.currentStableDebt = calcExpectedStableDebtTokenBalance(
|
||||
userDataBeforeAction,
|
||||
txTimestamp
|
||||
);
|
||||
|
||||
expectedUserData.currentVariableDebt = expectedUserData.principalStableDebt = calcExpectedVariableDebtTokenBalance(
|
||||
expectedUserData.currentVariableDebt = calcExpectedVariableDebtTokenBalance(
|
||||
reserveDataBeforeAction,
|
||||
userDataBeforeAction,
|
||||
txTimestamp
|
||||
);
|
||||
|
||||
expectedUserData.principalStableDebt = userDataBeforeAction.principalStableDebt;
|
||||
expectedUserData.principalVariableDebt = userDataBeforeAction.principalVariableDebt;
|
||||
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
|
||||
expectedUserData.stableBorrowRate = userDataBeforeAction.stableBorrowRate;
|
||||
expectedUserData.stableRateLastUpdated = userDataBeforeAction.stableRateLastUpdated;
|
||||
|
@ -155,9 +156,7 @@ export const calcExpectedUserDataAfterWithdraw = (
|
|||
}
|
||||
}
|
||||
|
||||
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
|
||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountWithdrawn);
|
||||
|
||||
expectedUserData.redirectedBalance = userDataBeforeAction.redirectedBalance;
|
||||
|
||||
if (expectedUserData.currentATokenBalance.eq(0) && expectedUserData.redirectedBalance.eq(0)) {
|
||||
|
@ -1038,7 +1037,7 @@ const calcExpectedScaledATokenBalance = (
|
|||
amountTaken: BigNumber
|
||||
|
||||
) => {
|
||||
return userDataBeforeAction.scaledATokenBalance.plus(amountAdded.rayDiv(reserveDataAfterAction.liquidityIndex));
|
||||
return userDataBeforeAction.scaledATokenBalance.plus(amountAdded.rayDiv(reserveDataAfterAction.liquidityIndex)).minus(amountTaken.rayDiv(reserveDataAfterAction.liquidityIndex));
|
||||
}
|
||||
|
||||
const calcExpectedATokenBalance = (
|
||||
|
|
Loading…
Reference in New Issue
Block a user