mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Refactored interest rate strategies tests
This commit is contained in:
parent
03dc5370ee
commit
eb9077f25e
|
@ -8,6 +8,7 @@ import {PercentageMath} from '../libraries/math/PercentageMath.sol';
|
|||
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
||||
import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol';
|
||||
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
|
||||
import 'hardhat/console.sol';
|
||||
|
||||
/**
|
||||
* @title DefaultReserveInterestRateStrategy contract
|
||||
|
@ -145,15 +146,15 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
vars.availableLiquidity = IERC20(reserve).balanceOf(aToken);
|
||||
vars.availableLiquidity = vars.availableLiquidity.add(liquidityAdded).sub(liquidityTaken);
|
||||
|
||||
uint256 utilizationRate =
|
||||
vars.utilizationRate =
|
||||
vars.totalDebt == 0 ? 0 : vars.totalDebt.rayDiv(vars.availableLiquidity.add(vars.totalDebt));
|
||||
|
||||
vars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle())
|
||||
.getMarketBorrowRate(reserve);
|
||||
|
||||
if (utilizationRate > OPTIMAL_UTILIZATION_RATE) {
|
||||
if (vars.utilizationRate > OPTIMAL_UTILIZATION_RATE) {
|
||||
uint256 excessUtilizationRateRatio =
|
||||
utilizationRate.sub(OPTIMAL_UTILIZATION_RATE).rayDiv(EXCESS_UTILIZATION_RATE);
|
||||
vars.utilizationRate.sub(OPTIMAL_UTILIZATION_RATE).rayDiv(EXCESS_UTILIZATION_RATE);
|
||||
|
||||
vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(_stableRateSlope1).add(
|
||||
_stableRateSlope2.rayMul(excessUtilizationRateRatio)
|
||||
|
@ -164,10 +165,10 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
);
|
||||
} else {
|
||||
vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(
|
||||
_stableRateSlope1.rayMul(utilizationRate.rayDiv(OPTIMAL_UTILIZATION_RATE))
|
||||
_stableRateSlope1.rayMul(vars.utilizationRate.rayDiv(OPTIMAL_UTILIZATION_RATE))
|
||||
);
|
||||
vars.currentVariableBorrowRate = _baseVariableBorrowRate.add(
|
||||
utilizationRate.rayMul(_variableRateSlope1).rayDiv(OPTIMAL_UTILIZATION_RATE)
|
||||
vars.utilizationRate.rayMul(_variableRateSlope1).rayDiv(OPTIMAL_UTILIZATION_RATE)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -178,7 +179,7 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
.currentVariableBorrowRate,
|
||||
averageStableBorrowRate
|
||||
)
|
||||
.rayMul(utilizationRate)
|
||||
.rayMul(vars.utilizationRate)
|
||||
.percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(reserveFactor));
|
||||
|
||||
return (
|
||||
|
|
|
@ -310,7 +310,7 @@ export const deployStableDebtToken = async (
|
|||
verify
|
||||
);
|
||||
|
||||
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]);
|
||||
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4], '0x10');
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
@ -326,7 +326,7 @@ export const deployVariableDebtToken = async (
|
|||
verify
|
||||
);
|
||||
|
||||
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]);
|
||||
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4], '0x10');
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
@ -372,7 +372,8 @@ export const deployGenericAToken = async (
|
|||
incentivesController,
|
||||
'18',
|
||||
name,
|
||||
symbol
|
||||
symbol,
|
||||
'0x10'
|
||||
);
|
||||
|
||||
return instance;
|
||||
|
|
|
@ -1,241 +0,0 @@
|
|||
// import {iATokenBase, iAssetsWithoutETH, ITestEnvWithoutInstances, RateMode} from '../utils/types';
|
||||
// import {
|
||||
// LendingPoolConfiguratorInstance,
|
||||
// LendingPoolInstance,
|
||||
// ATokenInstance,
|
||||
// LendingPoolCoreInstance,
|
||||
// MintableERC20Instance,
|
||||
// } from '../utils/typechain-types/truffle-contracts';
|
||||
// import {testEnvProviderWithoutInstances} from '../utils/truffle/dlp-tests-env';
|
||||
// import {oneEther, ETHEREUM_ADDRESS} from '../utils/constants';
|
||||
// import {convertToCurrencyDecimals} from '../utils/misc-utils';
|
||||
|
||||
// const expectRevert = require('@openzeppelin/test-helpers').expectRevert;
|
||||
|
||||
// contract('LendingPool: Modifiers', async ([deployer, ...users]) => {
|
||||
// let _testEnvProvider: ITestEnvWithoutInstances;
|
||||
// let _lendingPoolConfiguratorInstance: LendingPoolConfiguratorInstance;
|
||||
// let _lendingPoolInstance: LendingPoolInstance;
|
||||
// let _lendingPoolCoreInstance: LendingPoolCoreInstance;
|
||||
// let _aTokenInstances: iATokenBase<ATokenInstance>;
|
||||
// let _tokenInstances: iAssetsWithoutETH<MintableERC20Instance>;
|
||||
|
||||
// before('Initializing LendingPool test variables', async () => {
|
||||
// console.time('setup-test');
|
||||
// _testEnvProvider = await testEnvProviderWithoutInstances(artifacts, [deployer, ...users]);
|
||||
|
||||
// const {
|
||||
// getAllAssetsInstances,
|
||||
// getLendingPoolInstance,
|
||||
// getLendingPoolCoreInstance,
|
||||
// getLendingPoolConfiguratorInstance,
|
||||
// getATokenInstances,
|
||||
// } = _testEnvProvider;
|
||||
// const instances = await Promise.all([
|
||||
// getLendingPoolInstance(),
|
||||
// getLendingPoolCoreInstance(),
|
||||
// getLendingPoolConfiguratorInstance(),
|
||||
// getATokenInstances(),
|
||||
// getAllAssetsInstances(),
|
||||
// ]);
|
||||
|
||||
// _lendingPoolInstance = instances[0];
|
||||
// _lendingPoolCoreInstance = instances[1];
|
||||
// _lendingPoolConfiguratorInstance = instances[2];
|
||||
|
||||
// _aTokenInstances = instances[3];
|
||||
// _tokenInstances = instances[4];
|
||||
// console.timeEnd('setup-test');
|
||||
// });
|
||||
|
||||
// it('Tries to deposit in an inactive reserve', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.deposit(deployer, '1', '0'),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to invoke redeemUnderlying on an reserve, from a non-aToken address', async () => {
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.redeemUnderlying(ETHEREUM_ADDRESS, deployer, '1', '0'),
|
||||
// 'The caller of this function can only be the aToken contract of this reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to borrow from an inactive reserve', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.borrow(deployer, '1', '0', RateMode.Stable),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to repay in an inactive reserve', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.repay(deployer, '1', deployer),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to swapBorrowRateMode on an inactive reserve', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.swapBorrowRateMode(deployer),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to rebalanceStableBorrowRate on an inactive reserve', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.rebalanceStableBorrowRate(deployer, deployer),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to setUserUseReserveAsCollateral on an inactive reserve', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.setUserUseReserveAsCollateral(deployer, true),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to invoke liquidationCall on an inactive reserve', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.liquidationCall(ETHEREUM_ADDRESS, deployer, deployer, '1', false),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Tries to invoke liquidationCall on an inactive collateral', async () => {
|
||||
// //using the deployer address as a fake reserve address
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.liquidationCall(deployer, ETHEREUM_ADDRESS, deployer, '1', false),
|
||||
// 'Action requires an active reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Freezes the ETH reserve', async () => {
|
||||
// await _lendingPoolConfiguratorInstance.freezeReserve(ETHEREUM_ADDRESS);
|
||||
// });
|
||||
|
||||
// it('tries to deposit in a freezed reserve', async () => {
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.deposit(ETHEREUM_ADDRESS, '1', '0'),
|
||||
// 'Action requires an unfreezed reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('tries to borrow from a freezed reserve', async () => {
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.borrow(ETHEREUM_ADDRESS, '1', '0', '0'),
|
||||
// 'Action requires an unfreezed reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('tries to swap interest rate mode in a freezed reserve', async () => {
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.swapBorrowRateMode(ETHEREUM_ADDRESS),
|
||||
// 'Action requires an unfreezed reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('tries to disable as collateral a freezed reserve', async () => {
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.setUserUseReserveAsCollateral(ETHEREUM_ADDRESS, false),
|
||||
// 'Action requires an unfreezed reserve'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('unfreezes the reserve, user deposits 1 ETH, freezes the reserve, check that the user can redeem', async () => {
|
||||
// const {aWETH} = _aTokenInstances;
|
||||
|
||||
// //unfreezes the reserve
|
||||
// await _lendingPoolConfiguratorInstance.unfreezeReserve(ETHEREUM_ADDRESS);
|
||||
|
||||
// //deposit 1 ETH
|
||||
// await _lendingPoolInstance.deposit(ETHEREUM_ADDRESS, oneEther, '0', {
|
||||
// value: oneEther.toString(),
|
||||
// });
|
||||
|
||||
// //freezes the reserve
|
||||
// await _lendingPoolConfiguratorInstance.freezeReserve(ETHEREUM_ADDRESS);
|
||||
|
||||
// const balance = await aWETH.balanceOf(deployer);
|
||||
|
||||
// await aWETH.redeem(balance);
|
||||
// });
|
||||
|
||||
// it('unfreezes the reserve, user 0 deposits 100 DAI, user 1 deposits 1 ETH and borrows 50 DAI, freezes the reserve, checks that the user 1 can repay', async () => {
|
||||
// const {aWETH, aDAI} = _aTokenInstances;
|
||||
// const {DAI} = _tokenInstances;
|
||||
|
||||
// //unfreezes the reserve
|
||||
// await _lendingPoolConfiguratorInstance.unfreezeReserve(ETHEREUM_ADDRESS);
|
||||
|
||||
// const amountDAI = await convertToCurrencyDecimals(DAI.address, '100');
|
||||
|
||||
// //user 0 deposits 100 DAI
|
||||
// await DAI.mint(amountDAI, {from: users[0]});
|
||||
|
||||
// await DAI.approve(_lendingPoolCoreInstance.address, amountDAI, {from: users[0]});
|
||||
|
||||
// await _lendingPoolInstance.deposit(DAI.address, amountDAI, '0', {from: users[0]});
|
||||
|
||||
// //user 1 deposits 1 ETH
|
||||
// await _lendingPoolInstance.deposit(ETHEREUM_ADDRESS, oneEther, '0', {
|
||||
// from: users[1],
|
||||
// value: oneEther.toString(),
|
||||
// });
|
||||
|
||||
// const amountDAIToBorrow = await convertToCurrencyDecimals(DAI.address, '10');
|
||||
|
||||
// //user 1 borrows 10 DAI
|
||||
// await _lendingPoolInstance.borrow(DAI.address, amountDAIToBorrow, RateMode.Stable, '0', {
|
||||
// from: users[1],
|
||||
// });
|
||||
|
||||
// //freezes the reserve
|
||||
// await _lendingPoolConfiguratorInstance.freezeReserve(ETHEREUM_ADDRESS);
|
||||
|
||||
// //user 1 repays 1 DAI
|
||||
// await DAI.approve(_lendingPoolCoreInstance.address, amountDAIToBorrow, {from: users[1]});
|
||||
|
||||
// await _lendingPoolInstance.repay(DAI.address, oneEther, users[1], {from: users[1]});
|
||||
// });
|
||||
|
||||
// it('Check that liquidationCall can be executed on a freezed reserve', async () => {
|
||||
// const {aWETH, aDAI} = _aTokenInstances;
|
||||
// const {DAI} = _tokenInstances;
|
||||
|
||||
// //user 2 tries to liquidate
|
||||
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.liquidationCall(
|
||||
// ETHEREUM_ADDRESS,
|
||||
// DAI.address,
|
||||
// users[1],
|
||||
// oneEther,
|
||||
// true,
|
||||
// {from: users[2]}
|
||||
// ),
|
||||
// 'Health factor is not below the threshold'
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('Check that rebalanceStableBorrowRate can be executed on a freezed reserve', async () => {
|
||||
// const {aWETH, aDAI} = _aTokenInstances;
|
||||
// const {DAI} = _tokenInstances;
|
||||
|
||||
// //user 2 tries to liquidate
|
||||
|
||||
// await expectRevert(
|
||||
// _lendingPoolInstance.rebalanceStableBorrowRate(DAI.address, users[1]),
|
||||
// 'Interest rate rebalance conditions were not met'
|
||||
// );
|
||||
// });
|
||||
// });
|
|
@ -1,165 +1,193 @@
|
|||
// import {
|
||||
// IReserveParams,
|
||||
// iAavePoolAssets,
|
||||
// iAssetsWithoutETH,
|
||||
// ITestEnvWithoutInstances,
|
||||
// } from "../utils/types"
|
||||
// import {
|
||||
import { TestEnv, makeSuite } from './helpers/make-suite';
|
||||
import { deployDefaultReserveInterestRateStrategy } from '../../helpers/contracts-deployments';
|
||||
|
||||
// LendingPoolAddressesProviderInstance,
|
||||
import { APPROVAL_AMOUNT_LENDING_POOL, PERCENTAGE_FACTOR, RAY } from '../../helpers/constants';
|
||||
|
||||
// DefaultReserveInterestRateStrategyInstance,
|
||||
// MintableERC20Instance,
|
||||
// } from "../utils/typechain-types/truffle-contracts"
|
||||
// import { testEnvProviderWithoutInstances} from "../utils/truffle/dlp-tests-env"
|
||||
// import {RAY} from "../utils/constants"
|
||||
// import BigNumber from "bignumber.js"
|
||||
import { rateStrategyStableOne } from '../../markets/aave/rateStrategies';
|
||||
|
||||
// const {expect} = require("chai")
|
||||
import { strategyDAI } from '../../markets/aave/reservesConfigs';
|
||||
import { AToken, DefaultReserveInterestRateStrategy, MintableERC20 } from '../../types';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import './helpers/utils/math';
|
||||
|
||||
// contract("Interest rate strategy", async ([deployer, ...users]) => {
|
||||
// let _testEnvProvider: ITestEnvWithoutInstances
|
||||
// let _strategyInstance: DefaultReserveInterestRateStrategyInstance
|
||||
// let _tokenInstances: iAssetsWithoutETH<MintableERC20Instance>
|
||||
// let _addressesProviderInstance: LendingPoolAddressesProviderInstance
|
||||
// let _reservesParams: iAavePoolAssets<IReserveParams>
|
||||
const { expect } = require('chai');
|
||||
|
||||
// before("Initializing test variables", async () => {
|
||||
// console.time('setup-test');
|
||||
// _testEnvProvider = await testEnvProviderWithoutInstances(
|
||||
// artifacts,
|
||||
// [deployer, ...users],
|
||||
// )
|
||||
makeSuite('Interest rate strategy tests', (testEnv: TestEnv) => {
|
||||
let strategyInstance: DefaultReserveInterestRateStrategy;
|
||||
let dai: MintableERC20;
|
||||
let aDai: AToken;
|
||||
|
||||
// const {
|
||||
// getAllAssetsInstances,
|
||||
// getLendingPoolAddressesProviderInstance,
|
||||
// getAavePoolReservesParams,
|
||||
// } = _testEnvProvider
|
||||
before(async () => {
|
||||
dai = testEnv.dai;
|
||||
aDai = testEnv.aDai;
|
||||
|
||||
// const instances = await Promise.all([
|
||||
// getAllAssetsInstances(),
|
||||
// getLendingPoolAddressesProviderInstance()
|
||||
// ])
|
||||
const { addressesProvider } = testEnv;
|
||||
|
||||
// _tokenInstances = instances[0]
|
||||
// _addressesProviderInstance = instances[1]
|
||||
// _reservesParams = await getAavePoolReservesParams()
|
||||
// console.timeEnd('setup-test');
|
||||
// })
|
||||
strategyInstance = await deployDefaultReserveInterestRateStrategy(
|
||||
[
|
||||
addressesProvider.address,
|
||||
rateStrategyStableOne.optimalUtilizationRate,
|
||||
rateStrategyStableOne.baseVariableBorrowRate,
|
||||
rateStrategyStableOne.variableRateSlope1,
|
||||
rateStrategyStableOne.variableRateSlope2,
|
||||
rateStrategyStableOne.stableRateSlope1,
|
||||
rateStrategyStableOne.stableRateSlope2,
|
||||
],
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
// it("Deploys a new instance of a DefaultReserveInterestRateStrategy contract", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
it('Checks rates at 0% utilization rate, empty reserve', async () => {
|
||||
const {
|
||||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
dai.address,
|
||||
aDai.address,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
strategyDAI.reserveFactor
|
||||
);
|
||||
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
expect(currentLiquidityRate.toString()).to.be.equal('0', 'Invalid liquidity rate');
|
||||
expect(currentStableBorrowRate.toString()).to.be.equal(
|
||||
new BigNumber(0.039).times(RAY).toFixed(0),
|
||||
'Invalid stable rate'
|
||||
);
|
||||
expect(currentVariableBorrowRate.toString()).to.be.equal(
|
||||
rateStrategyStableOne.baseVariableBorrowRate,
|
||||
'Invalid variable rate'
|
||||
);
|
||||
});
|
||||
|
||||
// const contract: any = await artifacts.require("DefaultReserveInterestRateStrategy")
|
||||
// const mathLibrary = await artifacts.require("WadRayMath")
|
||||
// const mathLibraryInstance = await mathLibrary.new()
|
||||
it('Checks rates at 80% utilization rate', async () => {
|
||||
const {
|
||||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
dai.address,
|
||||
aDai.address,
|
||||
'200000000000000000',
|
||||
'0',
|
||||
'0',
|
||||
'800000000000000000',
|
||||
'0',
|
||||
strategyDAI.reserveFactor
|
||||
);
|
||||
|
||||
// await contract.link("WadRayMath", mathLibraryInstance.address)
|
||||
const expectedVariableRate = new BigNumber(rateStrategyStableOne.baseVariableBorrowRate).plus(
|
||||
rateStrategyStableOne.variableRateSlope1
|
||||
);
|
||||
|
||||
// _strategyInstance = await contract.new(
|
||||
// daiInstance.address,
|
||||
// _addressesProviderInstance.address,
|
||||
// daiConfiguration.baseVariableBorrowRate,
|
||||
// daiConfiguration.variableRateSlope1,
|
||||
// daiConfiguration.variableRateSlope2,
|
||||
// daiConfiguration.stableRateSlope1,
|
||||
// daiConfiguration.stableRateSlope2,
|
||||
// )
|
||||
// })
|
||||
expect(currentLiquidityRate.toString()).to.be.equal(
|
||||
expectedVariableRate
|
||||
.times(0.8)
|
||||
.percentMul(new BigNumber(PERCENTAGE_FACTOR).minus(strategyDAI.reserveFactor))
|
||||
.toFixed(0),
|
||||
'Invalid liquidity rate'
|
||||
);
|
||||
|
||||
// it("Checks rates at 0% utilization rate", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
||||
// daiInstance.address,
|
||||
// "1000000000000000000",
|
||||
// "0",
|
||||
// "0",
|
||||
// "0",
|
||||
// )
|
||||
expect(currentVariableBorrowRate.toString()).to.be.equal(
|
||||
expectedVariableRate.toFixed(0),
|
||||
'Invalid variable rate'
|
||||
);
|
||||
|
||||
// expect(data.currentLiquidityRate.toString()).to.be.equal("0", "Invalid liquidity rate")
|
||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(0.039).times(RAY).toFixed(0),
|
||||
// "Invalid stable rate",
|
||||
// )
|
||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
||||
// daiConfiguration.baseVariableBorrowRate,
|
||||
// "Invalid variable rate",
|
||||
// )
|
||||
// })
|
||||
expect(currentStableBorrowRate.toString()).to.be.equal(
|
||||
new BigNumber(0.039).times(RAY).plus(rateStrategyStableOne.stableRateSlope1).toFixed(0),
|
||||
'Invalid stable rate'
|
||||
);
|
||||
});
|
||||
|
||||
// it("Checks rates at 80% utilization rate", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
||||
// daiInstance.address,
|
||||
// "200000000000000000",
|
||||
// "0",
|
||||
// "800000000000000000",
|
||||
// "0",
|
||||
// )
|
||||
it('Checks rates at 100% utilization rate', async () => {
|
||||
const {
|
||||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
dai.address,
|
||||
aDai.address,
|
||||
'0',
|
||||
'0',
|
||||
'0',
|
||||
'800000000000000000',
|
||||
'0',
|
||||
strategyDAI.reserveFactor
|
||||
);
|
||||
|
||||
// const expectedVariableRate = new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
||||
// .plus(daiConfiguration.variableRateSlope1)
|
||||
const expectedVariableRate = new BigNumber(rateStrategyStableOne.baseVariableBorrowRate)
|
||||
.plus(rateStrategyStableOne.variableRateSlope1)
|
||||
.plus(rateStrategyStableOne.variableRateSlope2);
|
||||
|
||||
// expect(data.currentLiquidityRate.toString()).to.be.equal(
|
||||
// expectedVariableRate.times(0.8).toFixed(0),
|
||||
// "Invalid liquidity rate",
|
||||
// )
|
||||
expect(currentLiquidityRate.toString()).to.be.equal(
|
||||
expectedVariableRate
|
||||
.percentMul(new BigNumber(PERCENTAGE_FACTOR).minus(strategyDAI.reserveFactor))
|
||||
.toFixed(0),
|
||||
'Invalid liquidity rate'
|
||||
);
|
||||
|
||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
||||
// .plus(daiConfiguration.variableRateSlope1)
|
||||
// .toFixed(0),
|
||||
// "Invalid variable rate",
|
||||
// )
|
||||
expect(currentVariableBorrowRate.toString()).to.be.equal(
|
||||
expectedVariableRate.toFixed(0),
|
||||
'Invalid variable rate'
|
||||
);
|
||||
|
||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(0.039)
|
||||
// .times(RAY)
|
||||
// .plus(daiConfiguration.stableRateSlope1)
|
||||
// .toFixed(0),
|
||||
// "Invalid stable rate",
|
||||
// )
|
||||
// })
|
||||
expect(currentStableBorrowRate.toString()).to.be.equal(
|
||||
new BigNumber(0.039)
|
||||
.times(RAY)
|
||||
.plus(rateStrategyStableOne.stableRateSlope1)
|
||||
.plus(rateStrategyStableOne.stableRateSlope2)
|
||||
.toFixed(0),
|
||||
'Invalid stable rate'
|
||||
);
|
||||
});
|
||||
|
||||
// it("Checks rates at 100% utilization rate", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
||||
// daiInstance.address,
|
||||
// "0",
|
||||
// "0",
|
||||
// "1000000000000000000",
|
||||
// "0",
|
||||
// )
|
||||
it('Checks rates at 100% utilization rate, 50% stable debt and 50% variable debt, with a 10% avg stable rate', async () => {
|
||||
const {
|
||||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
dai.address,
|
||||
aDai.address,
|
||||
'0',
|
||||
'0',
|
||||
'400000000000000000',
|
||||
'400000000000000000',
|
||||
'100000000000000000000000000',
|
||||
strategyDAI.reserveFactor
|
||||
);
|
||||
|
||||
// const expectedVariableRate = new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
||||
// .plus(daiConfiguration.variableRateSlope1)
|
||||
// .plus(daiConfiguration.variableRateSlope2)
|
||||
// .toFixed(0)
|
||||
const expectedVariableRate = new BigNumber(rateStrategyStableOne.baseVariableBorrowRate)
|
||||
.plus(rateStrategyStableOne.variableRateSlope1)
|
||||
.plus(rateStrategyStableOne.variableRateSlope2);
|
||||
|
||||
// expect(data.currentLiquidityRate.toString()).to.be.equal(
|
||||
// expectedVariableRate,
|
||||
// "Invalid liquidity rate",
|
||||
// )
|
||||
const expectedLiquidityRate = new BigNumber(
|
||||
currentVariableBorrowRate.add('100000000000000000000000000').div(2).toString()
|
||||
)
|
||||
.percentMul(new BigNumber(PERCENTAGE_FACTOR).minus(strategyDAI.reserveFactor))
|
||||
.toFixed(0);
|
||||
|
||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
||||
// expectedVariableRate,
|
||||
// "Invalid variable rate",
|
||||
// )
|
||||
expect(currentLiquidityRate.toString()).to.be.equal(
|
||||
expectedLiquidityRate,
|
||||
'Invalid liquidity rate'
|
||||
);
|
||||
|
||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(0.039)
|
||||
// .times(RAY)
|
||||
// .plus(daiConfiguration.stableRateSlope1)
|
||||
// .plus(daiConfiguration.stableRateSlope2)
|
||||
// .toFixed(0),
|
||||
// "Invalid stable rate",
|
||||
// )
|
||||
// })
|
||||
// })
|
||||
expect(currentVariableBorrowRate.toString()).to.be.equal(
|
||||
expectedVariableRate.toFixed(0),
|
||||
'Invalid variable rate'
|
||||
);
|
||||
|
||||
expect(currentStableBorrowRate.toString()).to.be.equal(
|
||||
new BigNumber(0.039)
|
||||
.times(RAY)
|
||||
.plus(rateStrategyStableOne.stableRateSlope1)
|
||||
.plus(rateStrategyStableOne.stableRateSlope2)
|
||||
.toFixed(0),
|
||||
'Invalid stable rate'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,165 +0,0 @@
|
|||
// import {
|
||||
// IReserveParams,
|
||||
// iAavePoolAssets,
|
||||
// iAssetsWithoutETH,
|
||||
// ITestEnvWithoutInstances,
|
||||
// } from "../utils/types"
|
||||
// import {
|
||||
|
||||
// LendingPoolAddressesProviderInstance,
|
||||
|
||||
// DefaultReserveInterestRateStrategyInstance,
|
||||
// MintableERC20Instance,
|
||||
// } from "../utils/typechain-types/truffle-contracts"
|
||||
// import { testEnvProviderWithoutInstances} from "../utils/truffle/dlp-tests-env"
|
||||
// import {RAY} from "../utils/constants"
|
||||
// import BigNumber from "bignumber.js"
|
||||
|
||||
// const {expect} = require("chai")
|
||||
|
||||
// contract("Interest rate strategy", async ([deployer, ...users]) => {
|
||||
// let _testEnvProvider: ITestEnvWithoutInstances
|
||||
// let _strategyInstance: DefaultReserveInterestRateStrategyInstance
|
||||
// let _tokenInstances: iAssetsWithoutETH<MintableERC20Instance>
|
||||
// let _addressesProviderInstance: LendingPoolAddressesProviderInstance
|
||||
// let _reservesParams: iAavePoolAssets<IReserveParams>
|
||||
|
||||
// before("Initializing test variables", async () => {
|
||||
// console.time('setup-test');
|
||||
// _testEnvProvider = await testEnvProviderWithoutInstances(
|
||||
// artifacts,
|
||||
// [deployer, ...users],
|
||||
// )
|
||||
|
||||
// const {
|
||||
// getAllAssetsInstances,
|
||||
// getLendingPoolAddressesProviderInstance,
|
||||
// getAavePoolReservesParams,
|
||||
// } = _testEnvProvider
|
||||
|
||||
// const instances = await Promise.all([
|
||||
// getAllAssetsInstances(),
|
||||
// getLendingPoolAddressesProviderInstance()
|
||||
// ])
|
||||
|
||||
// _tokenInstances = instances[0]
|
||||
// _addressesProviderInstance = instances[1]
|
||||
// _reservesParams = await getAavePoolReservesParams()
|
||||
// console.timeEnd('setup-test');
|
||||
// })
|
||||
|
||||
// it("Deploys a new instance of a DefaultReserveInterestRateStrategy contract", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
|
||||
// const contract: any = await artifacts.require("DefaultReserveInterestRateStrategy")
|
||||
// const mathLibrary = await artifacts.require("WadRayMath")
|
||||
// const mathLibraryInstance = await mathLibrary.new()
|
||||
|
||||
// await contract.link("WadRayMath", mathLibraryInstance.address)
|
||||
|
||||
// _strategyInstance = await contract.new(
|
||||
// daiInstance.address,
|
||||
// _addressesProviderInstance.address,
|
||||
// daiConfiguration.baseVariableBorrowRate,
|
||||
// daiConfiguration.variableRateSlope1,
|
||||
// daiConfiguration.variableRateSlope2,
|
||||
// daiConfiguration.stableRateSlope1,
|
||||
// daiConfiguration.stableRateSlope2,
|
||||
// )
|
||||
// })
|
||||
|
||||
// it("Checks rates at 0% utilization rate", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
||||
// daiInstance.address,
|
||||
// "1000000000000000000",
|
||||
// "0",
|
||||
// "0",
|
||||
// "0",
|
||||
// )
|
||||
|
||||
// expect(data.currentLiquidityRate.toString()).to.be.equal("0", "Invalid liquidity rate")
|
||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(0.039).times(RAY).toFixed(0),
|
||||
// "Invalid stable rate",
|
||||
// )
|
||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
||||
// daiConfiguration.baseVariableBorrowRate,
|
||||
// "Invalid variable rate",
|
||||
// )
|
||||
// })
|
||||
|
||||
// it("Checks rates at 80% utilization rate", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
||||
// daiInstance.address,
|
||||
// "200000000000000000",
|
||||
// "0",
|
||||
// "800000000000000000",
|
||||
// "0",
|
||||
// )
|
||||
|
||||
// const expectedVariableRate = new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
||||
// .plus(daiConfiguration.variableRateSlope1)
|
||||
|
||||
// expect(data.currentLiquidityRate.toString()).to.be.equal(
|
||||
// expectedVariableRate.times(0.8).toFixed(0),
|
||||
// "Invalid liquidity rate",
|
||||
// )
|
||||
|
||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
||||
// .plus(daiConfiguration.variableRateSlope1)
|
||||
// .toFixed(0),
|
||||
// "Invalid variable rate",
|
||||
// )
|
||||
|
||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(0.039)
|
||||
// .times(RAY)
|
||||
// .plus(daiConfiguration.stableRateSlope1)
|
||||
// .toFixed(0),
|
||||
// "Invalid stable rate",
|
||||
// )
|
||||
// })
|
||||
|
||||
// it("Checks rates at 100% utilization rate", async () => {
|
||||
// const {DAI: daiInstance} = _tokenInstances
|
||||
// const {DAI: daiConfiguration} = _reservesParams
|
||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
||||
// daiInstance.address,
|
||||
// "0",
|
||||
// "0",
|
||||
// "1000000000000000000",
|
||||
// "0",
|
||||
// )
|
||||
|
||||
// const expectedVariableRate = new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
||||
// .plus(daiConfiguration.variableRateSlope1)
|
||||
// .plus(daiConfiguration.variableRateSlope2)
|
||||
// .toFixed(0)
|
||||
|
||||
// expect(data.currentLiquidityRate.toString()).to.be.equal(
|
||||
// expectedVariableRate,
|
||||
// "Invalid liquidity rate",
|
||||
// )
|
||||
|
||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
||||
// expectedVariableRate,
|
||||
// "Invalid variable rate",
|
||||
// )
|
||||
|
||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
||||
// new BigNumber(0.039)
|
||||
// .times(RAY)
|
||||
// .plus(daiConfiguration.stableRateSlope1)
|
||||
// .plus(daiConfiguration.stableRateSlope2)
|
||||
// .toFixed(0),
|
||||
// "Invalid stable rate",
|
||||
// )
|
||||
// })
|
||||
// })
|
Loading…
Reference in New Issue
Block a user