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,8 +5,14 @@ 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';
|
||||||
|
|
||||||
|
@ -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];
|
||||||
};
|
};
|
||||||
|
|
|
@ -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