mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Handled reserveFactor in the scenario tests
This commit is contained in:
parent
7892587f1b
commit
c9875f0a8f
|
@ -4,6 +4,8 @@ import BigNumber from 'bignumber.js';
|
||||||
// MATH
|
// MATH
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
||||||
|
export const PERCENTAGE_FACTOR = '10000';
|
||||||
|
export const HALF_PERCENTAGE = '5000';
|
||||||
export const WAD = Math.pow(10, 18).toString();
|
export const WAD = Math.pow(10, 18).toString();
|
||||||
export const HALF_WAD = new BigNumber(WAD).multipliedBy(0.5).toString();
|
export const HALF_WAD = new BigNumber(WAD).multipliedBy(0.5).toString();
|
||||||
export const RAY = new BigNumber(10).exponentiatedBy(27).toFixed();
|
export const RAY = new BigNumber(10).exponentiatedBy(27).toFixed();
|
||||||
|
|
|
@ -80,7 +80,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(8000);
|
expect(liquidationThreshold).to.be.equal(8000);
|
||||||
expect(liquidationBonus).to.be.equal(10500);
|
expect(liquidationBonus).to.be.equal(10500);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(true);
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Unfreezes the ETH reserve', async () => {
|
it('Unfreezes the ETH reserve', async () => {
|
||||||
|
@ -107,7 +107,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(8000);
|
expect(liquidationThreshold).to.be.equal(8000);
|
||||||
expect(liquidationBonus).to.be.equal(10500);
|
expect(liquidationBonus).to.be.equal(10500);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(true);
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on freezeReserve ', async () => {
|
it('Check the onlyAaveAdmin on freezeReserve ', async () => {
|
||||||
|
@ -149,7 +149,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(8000);
|
expect(liquidationThreshold).to.be.equal(8000);
|
||||||
expect(liquidationBonus).to.be.equal(10500);
|
expect(liquidationBonus).to.be.equal(10500);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(true);
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Activates the ETH reserve for borrowing', async () => {
|
it('Activates the ETH reserve for borrowing', async () => {
|
||||||
|
@ -177,7 +177,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(8000);
|
expect(liquidationThreshold).to.be.equal(8000);
|
||||||
expect(liquidationBonus).to.be.equal(10500);
|
expect(liquidationBonus).to.be.equal(10500);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(true);
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
|
|
||||||
expect(variableBorrowIndex.toString()).to.be.equal(RAY);
|
expect(variableBorrowIndex.toString()).to.be.equal(RAY);
|
||||||
});
|
});
|
||||||
|
@ -222,7 +222,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(0);
|
expect(liquidationThreshold).to.be.equal(0);
|
||||||
expect(liquidationBonus).to.be.equal(0);
|
expect(liquidationBonus).to.be.equal(0);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(true);
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Activates the ETH reserve as collateral', async () => {
|
it('Activates the ETH reserve as collateral', async () => {
|
||||||
|
@ -249,7 +249,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(8000);
|
expect(liquidationThreshold).to.be.equal(8000);
|
||||||
expect(liquidationBonus).to.be.equal(10500);
|
expect(liquidationBonus).to.be.equal(10500);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(true);
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on configureReserveAsCollateral ', async () => {
|
it('Check the onlyAaveAdmin on configureReserveAsCollateral ', async () => {
|
||||||
|
@ -285,7 +285,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(8000);
|
expect(liquidationThreshold).to.be.equal(8000);
|
||||||
expect(liquidationBonus).to.be.equal(10500);
|
expect(liquidationBonus).to.be.equal(10500);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(false);
|
expect(stableBorrowRateEnabled).to.be.equal(false);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Enables stable borrow rate on the ETH reserve', async () => {
|
it('Enables stable borrow rate on the ETH reserve', async () => {
|
||||||
|
@ -311,7 +311,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
expect(liquidationThreshold).to.be.equal(8000);
|
expect(liquidationThreshold).to.be.equal(8000);
|
||||||
expect(liquidationBonus).to.be.equal(10500);
|
expect(liquidationBonus).to.be.equal(10500);
|
||||||
expect(stableBorrowRateEnabled).to.be.equal(true);
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
||||||
expect(reserveFactor).to.be.equal(0);
|
expect(reserveFactor).to.be.equal(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on disableReserveStableRate', async () => {
|
it('Check the onlyAaveAdmin on disableReserveStableRate', async () => {
|
||||||
|
|
|
@ -5,10 +5,16 @@ import {
|
||||||
MAX_UINT_AMOUNT,
|
MAX_UINT_AMOUNT,
|
||||||
OPTIMAL_UTILIZATION_RATE,
|
OPTIMAL_UTILIZATION_RATE,
|
||||||
EXCESS_UTILIZATION_RATE,
|
EXCESS_UTILIZATION_RATE,
|
||||||
|
PERCENTAGE_FACTOR,
|
||||||
} from '../../../helpers/constants';
|
} from '../../../helpers/constants';
|
||||||
import {IReserveParams, iAavePoolAssets, RateMode, tEthereumAddress} from '../../../helpers/types';
|
import {
|
||||||
|
IReserveParams,
|
||||||
|
iAavePoolAssets,
|
||||||
|
RateMode,
|
||||||
|
tEthereumAddress,
|
||||||
|
} 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);
|
||||||
|
|
||||||
|
@ -758,7 +764,7 @@ 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;
|
||||||
|
|
||||||
|
@ -885,7 +891,7 @@ export const calcExpectedUserDataAfterSwapRateMode = (
|
||||||
txCost: BigNumber,
|
txCost: BigNumber,
|
||||||
txTimestamp: BigNumber
|
txTimestamp: BigNumber
|
||||||
): UserReserveData => {
|
): UserReserveData => {
|
||||||
const expectedUserData = {...userDataBeforeAction};
|
const expectedUserData = { ...userDataBeforeAction };
|
||||||
|
|
||||||
const stableDebtBalance = calcExpectedStableDebtTokenBalance(
|
const stableDebtBalance = calcExpectedStableDebtTokenBalance(
|
||||||
userDataBeforeAction.principalStableDebt,
|
userDataBeforeAction.principalStableDebt,
|
||||||
|
@ -1035,7 +1041,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,
|
||||||
|
@ -1084,7 +1090,7 @@ export const calcExpectedATokenBalance = (
|
||||||
) => {
|
) => {
|
||||||
const index = calcExpectedReserveNormalizedIncome(reserveData, currentTimestamp);
|
const index = calcExpectedReserveNormalizedIncome(reserveData, currentTimestamp);
|
||||||
|
|
||||||
const {scaledATokenBalance: scaledBalanceBeforeAction} = userData;
|
const { scaledATokenBalance: scaledBalanceBeforeAction } = userData;
|
||||||
|
|
||||||
return scaledBalanceBeforeAction.rayMul(index);
|
return scaledBalanceBeforeAction.rayMul(index);
|
||||||
};
|
};
|
||||||
|
@ -1119,7 +1125,7 @@ export const calcExpectedVariableDebtTokenBalance = (
|
||||||
currentTimestamp
|
currentTimestamp
|
||||||
);
|
);
|
||||||
|
|
||||||
const {scaledVariableDebt} = userData;
|
const { scaledVariableDebt } = userData;
|
||||||
|
|
||||||
return scaledVariableDebt.rayMul(normalizedDebt);
|
return scaledVariableDebt.rayMul(normalizedDebt);
|
||||||
};
|
};
|
||||||
|
@ -1202,7 +1208,7 @@ export const calcExpectedInterestRates = (
|
||||||
totalVariableDebt: BigNumber,
|
totalVariableDebt: 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][])[
|
||||||
|
@ -1248,7 +1254,9 @@ export const calcExpectedInterestRates = (
|
||||||
variableBorrowRate,
|
variableBorrowRate,
|
||||||
averageStableBorrowRate
|
averageStableBorrowRate
|
||||||
);
|
);
|
||||||
const liquidityRate = expectedOverallRate.rayMul(utilizationRate);
|
const liquidityRate = expectedOverallRate
|
||||||
|
.rayMul(utilizationRate)
|
||||||
|
.percentMul(new BigNumber(PERCENTAGE_FACTOR).minus(reserveConfiguration.reserveFactor));
|
||||||
|
|
||||||
return [liquidityRate, stableBorrowRate, variableBorrowRate];
|
return [liquidityRate, stableBorrowRate, variableBorrowRate];
|
||||||
};
|
};
|
||||||
|
@ -1292,7 +1300,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')) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import {RAY, WAD, HALF_RAY, HALF_WAD, WAD_RAY_RATIO} from '../../../helpers/constants';
|
import {RAY, WAD, HALF_RAY, HALF_WAD, WAD_RAY_RATIO, HALF_PERCENTAGE, PERCENTAGE_FACTOR} from '../../../helpers/constants';
|
||||||
|
|
||||||
declare module 'bignumber.js' {
|
declare module 'bignumber.js' {
|
||||||
interface BigNumber {
|
interface BigNumber {
|
||||||
|
@ -7,10 +7,13 @@ declare module 'bignumber.js' {
|
||||||
wad: () => BigNumber;
|
wad: () => BigNumber;
|
||||||
halfRay: () => BigNumber;
|
halfRay: () => BigNumber;
|
||||||
halfWad: () => BigNumber;
|
halfWad: () => BigNumber;
|
||||||
|
halfPercentage: () => BigNumber;
|
||||||
wadMul: (a: BigNumber) => BigNumber;
|
wadMul: (a: BigNumber) => BigNumber;
|
||||||
wadDiv: (a: BigNumber) => BigNumber;
|
wadDiv: (a: BigNumber) => BigNumber;
|
||||||
rayMul: (a: BigNumber) => BigNumber;
|
rayMul: (a: BigNumber) => BigNumber;
|
||||||
rayDiv: (a: BigNumber) => BigNumber;
|
rayDiv: (a: BigNumber) => BigNumber;
|
||||||
|
percentMul: (a: BigNumber) => BigNumber;
|
||||||
|
percentDiv: (a: BigNumber) => BigNumber;
|
||||||
rayToWad: () => BigNumber;
|
rayToWad: () => BigNumber;
|
||||||
wadToRay: () => BigNumber;
|
wadToRay: () => BigNumber;
|
||||||
}
|
}
|
||||||
|
@ -64,3 +67,20 @@ BigNumber.prototype.rayToWad = function (): BigNumber {
|
||||||
BigNumber.prototype.wadToRay = function (): BigNumber {
|
BigNumber.prototype.wadToRay = function (): BigNumber {
|
||||||
return this.multipliedBy(WAD_RAY_RATIO).decimalPlaces(0, BigNumber.ROUND_DOWN);
|
return this.multipliedBy(WAD_RAY_RATIO).decimalPlaces(0, BigNumber.ROUND_DOWN);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BigNumber.prototype.halfPercentage = (): BigNumber => {
|
||||||
|
return new BigNumber(HALF_PERCENTAGE).decimalPlaces(0, BigNumber.ROUND_DOWN);
|
||||||
|
};
|
||||||
|
|
||||||
|
BigNumber.prototype.percentMul = function (b: BigNumber): BigNumber {
|
||||||
|
return this.halfPercentage().plus(this.multipliedBy(b)).div(PERCENTAGE_FACTOR).decimalPlaces(0, BigNumber.ROUND_DOWN);
|
||||||
|
};
|
||||||
|
|
||||||
|
BigNumber.prototype.percentDiv = function (a: BigNumber): BigNumber {
|
||||||
|
const halfA = a.div(2).decimalPlaces(0, BigNumber.ROUND_DOWN);
|
||||||
|
|
||||||
|
return halfA.plus(this.multipliedBy(PERCENTAGE_FACTOR)).div(a).decimalPlaces(0, BigNumber.ROUND_DOWN);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user