mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Removed ETH specific logic in tests
This commit is contained in:
parent
45cb9ab680
commit
b2d8a9e053
|
@ -7,15 +7,14 @@ import {
|
||||||
EXCESS_UTILIZATION_RATE,
|
EXCESS_UTILIZATION_RATE,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
} from '../../../helpers/constants';
|
} from '../../../helpers/constants';
|
||||||
import {IReserveParams, iAavePoolAssets, RateMode} from '../../../helpers/types';
|
import { IReserveParams, iAavePoolAssets, RateMode } from '../../../helpers/types';
|
||||||
import './math';
|
import './math';
|
||||||
import {ReserveData, UserReserveData} from './interfaces';
|
import { ReserveData, UserReserveData } from './interfaces';
|
||||||
|
|
||||||
export const strToBN = (amount: string): BigNumber => new BigNumber(amount);
|
export const strToBN = (amount: string): BigNumber => new BigNumber(amount);
|
||||||
|
|
||||||
interface Configuration {
|
interface Configuration {
|
||||||
reservesParams: iAavePoolAssets<IReserveParams>;
|
reservesParams: iAavePoolAssets<IReserveParams>;
|
||||||
ethereumAddress: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const configuration: Configuration = <Configuration>{};
|
export const configuration: Configuration = <Configuration>{};
|
||||||
|
@ -66,17 +65,7 @@ export const calcExpectedUserDataAfterDeposit = (
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
|
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
|
||||||
|
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(amountDeposited);
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
|
||||||
// console.log("** ETH CASE ****")
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance
|
|
||||||
.minus(txCost)
|
|
||||||
.minus(amountDeposited);
|
|
||||||
} else {
|
|
||||||
// console.log("** TOKEN CASE ****")
|
|
||||||
// console.log(userDataBeforeAction.walletBalance.toString())
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(amountDeposited);
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedUserData.principalATokenBalance = expectedUserData.currentATokenBalance = calcExpectedATokenBalance(
|
expectedUserData.principalATokenBalance = expectedUserData.currentATokenBalance = calcExpectedATokenBalance(
|
||||||
reserveDataBeforeAction,
|
reserveDataBeforeAction,
|
||||||
|
@ -171,14 +160,7 @@ export const calcExpectedUserDataAfterWithdraw = (
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
|
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
|
||||||
|
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountWithdrawn);
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance
|
|
||||||
.minus(txCost)
|
|
||||||
.plus(amountWithdrawn);
|
|
||||||
} else {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountWithdrawn);
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedUserData.redirectedBalance = userDataBeforeAction.redirectedBalance;
|
expectedUserData.redirectedBalance = userDataBeforeAction.redirectedBalance;
|
||||||
|
|
||||||
|
@ -600,13 +582,7 @@ export const calcExpectedUserDataAfterBorrow = (
|
||||||
userDataBeforeAction.redirectionAddressRedirectedBalance;
|
userDataBeforeAction.redirectionAddressRedirectedBalance;
|
||||||
expectedUserData.currentATokenUserIndex = userDataBeforeAction.currentATokenUserIndex;
|
expectedUserData.currentATokenUserIndex = userDataBeforeAction.currentATokenUserIndex;
|
||||||
|
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountBorrowed);
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance
|
|
||||||
.minus(txCost)
|
|
||||||
.plus(amountBorrowed);
|
|
||||||
} else {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountBorrowed);
|
|
||||||
}
|
|
||||||
|
|
||||||
return expectedUserData;
|
return expectedUserData;
|
||||||
};
|
};
|
||||||
|
@ -657,8 +633,7 @@ export const calcExpectedUserDataAfterRepay = (
|
||||||
expectedUserData.stableBorrowRate = expectedUserData.stableRateLastUpdated = new BigNumber(
|
expectedUserData.stableBorrowRate = expectedUserData.stableRateLastUpdated = new BigNumber(
|
||||||
'0'
|
'0'
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
expectedUserData.stableBorrowRate = userDataBeforeAction.stableBorrowRate;
|
expectedUserData.stableBorrowRate = userDataBeforeAction.stableBorrowRate;
|
||||||
expectedUserData.stableRateLastUpdated = txTimestamp;
|
expectedUserData.stableRateLastUpdated = txTimestamp;
|
||||||
}
|
}
|
||||||
|
@ -697,14 +672,7 @@ export const calcExpectedUserDataAfterRepay = (
|
||||||
expectedUserData.currentATokenUserIndex = userDataBeforeAction.currentATokenUserIndex;
|
expectedUserData.currentATokenUserIndex = userDataBeforeAction.currentATokenUserIndex;
|
||||||
|
|
||||||
if (user === onBehalfOf) {
|
if (user === onBehalfOf) {
|
||||||
//if user repaid for himself, update the wallet balances
|
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(totalRepaid);
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance
|
|
||||||
.minus(txCost)
|
|
||||||
.minus(totalRepaid);
|
|
||||||
} else {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(totalRepaid);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//wallet balance didn't change
|
//wallet balance didn't change
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance;
|
expectedUserData.walletBalance = userDataBeforeAction.walletBalance;
|
||||||
|
@ -719,14 +687,10 @@ export const calcExpectedUserDataAfterSetUseAsCollateral = (
|
||||||
userDataBeforeAction: UserReserveData,
|
userDataBeforeAction: UserReserveData,
|
||||||
txCost: BigNumber
|
txCost: BigNumber
|
||||||
): UserReserveData => {
|
): UserReserveData => {
|
||||||
const expectedUserData = {...userDataBeforeAction};
|
const expectedUserData = { ...userDataBeforeAction };
|
||||||
|
|
||||||
expectedUserData.usageAsCollateralEnabled = useAsCollateral;
|
expectedUserData.usageAsCollateralEnabled = useAsCollateral;
|
||||||
|
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(txCost);
|
|
||||||
}
|
|
||||||
|
|
||||||
return expectedUserData;
|
return expectedUserData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -829,7 +793,7 @@ export const calcExpectedUserDataAfterSwapRateMode = (
|
||||||
txCost: BigNumber,
|
txCost: BigNumber,
|
||||||
txTimestamp: BigNumber
|
txTimestamp: BigNumber
|
||||||
): UserReserveData => {
|
): UserReserveData => {
|
||||||
const expectedUserData = {...userDataBeforeAction};
|
const expectedUserData = { ...userDataBeforeAction };
|
||||||
|
|
||||||
const variableBorrowBalance = calcExpectedVariableDebtTokenBalance(
|
const variableBorrowBalance = calcExpectedVariableDebtTokenBalance(
|
||||||
reserveDataBeforeAction,
|
reserveDataBeforeAction,
|
||||||
|
@ -892,9 +856,6 @@ export const calcExpectedUserDataAfterSwapRateMode = (
|
||||||
|
|
||||||
expectedUserData.liquidityRate = expectedDataAfterAction.liquidityRate;
|
expectedUserData.liquidityRate = expectedDataAfterAction.liquidityRate;
|
||||||
|
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(txCost);
|
|
||||||
}
|
|
||||||
return expectedUserData;
|
return expectedUserData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -976,7 +937,7 @@ export const calcExpectedUserDataAfterStableRateRebalance = (
|
||||||
txCost: BigNumber,
|
txCost: BigNumber,
|
||||||
txTimestamp: BigNumber
|
txTimestamp: BigNumber
|
||||||
): UserReserveData => {
|
): UserReserveData => {
|
||||||
const expectedUserData = {...userDataBeforeAction};
|
const expectedUserData = { ...userDataBeforeAction };
|
||||||
|
|
||||||
expectedUserData.principalVariableDebt = calcExpectedVariableDebtTokenBalance(
|
expectedUserData.principalVariableDebt = calcExpectedVariableDebtTokenBalance(
|
||||||
reserveDataBeforeAction,
|
reserveDataBeforeAction,
|
||||||
|
@ -1000,12 +961,6 @@ export const calcExpectedUserDataAfterStableRateRebalance = (
|
||||||
|
|
||||||
expectedUserData.liquidityRate = expectedDataAfterAction.liquidityRate;
|
expectedUserData.liquidityRate = expectedDataAfterAction.liquidityRate;
|
||||||
|
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
|
||||||
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(txCost);
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedUserData.liquidityRate = expectedDataAfterAction.liquidityRate;
|
|
||||||
|
|
||||||
expectedUserData.currentATokenBalance = calcExpectedATokenBalance(
|
expectedUserData.currentATokenBalance = calcExpectedATokenBalance(
|
||||||
reserveDataBeforeAction,
|
reserveDataBeforeAction,
|
||||||
userDataBeforeAction,
|
userDataBeforeAction,
|
||||||
|
@ -1037,8 +992,8 @@ export const calcExpectedUsersDataAfterRedirectInterest = (
|
||||||
txCost: BigNumber,
|
txCost: BigNumber,
|
||||||
txTimestamp: BigNumber
|
txTimestamp: BigNumber
|
||||||
): UserReserveData[] => {
|
): UserReserveData[] => {
|
||||||
const expectedFromData = {...fromDataBeforeAction};
|
const expectedFromData = { ...fromDataBeforeAction };
|
||||||
const expectedToData = {...toDataBeforeAction};
|
const expectedToData = { ...toDataBeforeAction };
|
||||||
|
|
||||||
expectedFromData.currentStableDebt = calcExpectedStableDebtTokenBalance(
|
expectedFromData.currentStableDebt = calcExpectedStableDebtTokenBalance(
|
||||||
fromDataBeforeAction,
|
fromDataBeforeAction,
|
||||||
|
@ -1069,12 +1024,6 @@ export const calcExpectedUsersDataAfterRedirectInterest = (
|
||||||
txTimestamp
|
txTimestamp
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isFromExecutingTx) {
|
|
||||||
if (reserveDataBeforeAction.address === configuration.ethereumAddress) {
|
|
||||||
expectedFromData.walletBalance = fromDataBeforeAction.walletBalance.minus(txCost);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedToData.redirectedBalance = toDataBeforeAction.redirectedBalance.plus(
|
expectedToData.redirectedBalance = toDataBeforeAction.redirectedBalance.plus(
|
||||||
expectedFromData.currentATokenBalance
|
expectedFromData.currentATokenBalance
|
||||||
);
|
);
|
||||||
|
@ -1215,7 +1164,7 @@ export const calcExpectedVariableDebtTokenBalance = (
|
||||||
) => {
|
) => {
|
||||||
const debt = calcExpectedReserveNormalizedDebt(reserveDataBeforeAction, currentTimestamp);
|
const debt = calcExpectedReserveNormalizedDebt(reserveDataBeforeAction, currentTimestamp);
|
||||||
|
|
||||||
const {principalVariableDebt, variableBorrowIndex} = userDataBeforeAction;
|
const { principalVariableDebt, variableBorrowIndex } = userDataBeforeAction;
|
||||||
|
|
||||||
if (variableBorrowIndex.eq(0)) {
|
if (variableBorrowIndex.eq(0)) {
|
||||||
return principalVariableDebt;
|
return principalVariableDebt;
|
||||||
|
@ -1228,7 +1177,7 @@ export const calcExpectedStableDebtTokenBalance = (
|
||||||
userDataBeforeAction: UserReserveData,
|
userDataBeforeAction: UserReserveData,
|
||||||
currentTimestamp: BigNumber
|
currentTimestamp: BigNumber
|
||||||
) => {
|
) => {
|
||||||
const {principalStableDebt, stableBorrowRate, stableRateLastUpdated} = userDataBeforeAction;
|
const { principalStableDebt, stableBorrowRate, stableRateLastUpdated } = userDataBeforeAction;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
stableBorrowRate.eq(0) ||
|
stableBorrowRate.eq(0) ||
|
||||||
|
@ -1301,7 +1250,7 @@ const calcExpectedInterestRates = (
|
||||||
totalBorrowsVariable: BigNumber,
|
totalBorrowsVariable: BigNumber,
|
||||||
averageStableBorrowRate: BigNumber
|
averageStableBorrowRate: BigNumber
|
||||||
): BigNumber[] => {
|
): BigNumber[] => {
|
||||||
const {reservesParams} = configuration;
|
const { reservesParams } = configuration;
|
||||||
|
|
||||||
const reserveIndex = Object.keys(reservesParams).findIndex((value) => value === reserveSymbol);
|
const reserveIndex = Object.keys(reservesParams).findIndex((value) => value === reserveSymbol);
|
||||||
const [, reserveConfiguration] = (Object.entries(reservesParams) as [string, IReserveParams][])[
|
const [, reserveConfiguration] = (Object.entries(reservesParams) as [string, IReserveParams][])[
|
||||||
|
@ -1391,7 +1340,7 @@ const calcExpectedReserveNormalizedIncome = (
|
||||||
reserveData: ReserveData,
|
reserveData: ReserveData,
|
||||||
currentTimestamp: BigNumber
|
currentTimestamp: BigNumber
|
||||||
) => {
|
) => {
|
||||||
const {liquidityRate, liquidityIndex, lastUpdateTimestamp} = reserveData;
|
const { liquidityRate, liquidityIndex, lastUpdateTimestamp } = reserveData;
|
||||||
|
|
||||||
//if utilization rate is 0, nothing to compound
|
//if utilization rate is 0, nothing to compound
|
||||||
if (liquidityRate.eq('0')) {
|
if (liquidityRate.eq('0')) {
|
||||||
|
@ -1413,7 +1362,7 @@ const calcExpectedReserveNormalizedDebt = (
|
||||||
reserveData: ReserveData,
|
reserveData: ReserveData,
|
||||||
currentTimestamp: BigNumber
|
currentTimestamp: BigNumber
|
||||||
) => {
|
) => {
|
||||||
const {variableBorrowRate, variableBorrowIndex, lastUpdateTimestamp} = reserveData;
|
const { variableBorrowRate, variableBorrowIndex, lastUpdateTimestamp } = reserveData;
|
||||||
|
|
||||||
//if utilization rate is 0, nothing to compound
|
//if utilization rate is 0, nothing to compound
|
||||||
if (variableBorrowRate.eq('0')) {
|
if (variableBorrowRate.eq('0')) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user