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 {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
||||||
import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol';
|
import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol';
|
||||||
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
|
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
|
||||||
|
import 'hardhat/console.sol';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title DefaultReserveInterestRateStrategy contract
|
* @title DefaultReserveInterestRateStrategy contract
|
||||||
|
@ -145,15 +146,15 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
||||||
vars.availableLiquidity = IERC20(reserve).balanceOf(aToken);
|
vars.availableLiquidity = IERC20(reserve).balanceOf(aToken);
|
||||||
vars.availableLiquidity = vars.availableLiquidity.add(liquidityAdded).sub(liquidityTaken);
|
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.totalDebt == 0 ? 0 : vars.totalDebt.rayDiv(vars.availableLiquidity.add(vars.totalDebt));
|
||||||
|
|
||||||
vars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle())
|
vars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle())
|
||||||
.getMarketBorrowRate(reserve);
|
.getMarketBorrowRate(reserve);
|
||||||
|
|
||||||
if (utilizationRate > OPTIMAL_UTILIZATION_RATE) {
|
if (vars.utilizationRate > OPTIMAL_UTILIZATION_RATE) {
|
||||||
uint256 excessUtilizationRateRatio =
|
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(
|
vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(_stableRateSlope1).add(
|
||||||
_stableRateSlope2.rayMul(excessUtilizationRateRatio)
|
_stableRateSlope2.rayMul(excessUtilizationRateRatio)
|
||||||
|
@ -164,10 +165,10 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(
|
vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(
|
||||||
_stableRateSlope1.rayMul(utilizationRate.rayDiv(OPTIMAL_UTILIZATION_RATE))
|
_stableRateSlope1.rayMul(vars.utilizationRate.rayDiv(OPTIMAL_UTILIZATION_RATE))
|
||||||
);
|
);
|
||||||
vars.currentVariableBorrowRate = _baseVariableBorrowRate.add(
|
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,
|
.currentVariableBorrowRate,
|
||||||
averageStableBorrowRate
|
averageStableBorrowRate
|
||||||
)
|
)
|
||||||
.rayMul(utilizationRate)
|
.rayMul(vars.utilizationRate)
|
||||||
.percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(reserveFactor));
|
.percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(reserveFactor));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -310,7 +310,7 @@ export const deployStableDebtToken = async (
|
||||||
verify
|
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;
|
return instance;
|
||||||
};
|
};
|
||||||
|
@ -326,7 +326,7 @@ export const deployVariableDebtToken = async (
|
||||||
verify
|
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;
|
return instance;
|
||||||
};
|
};
|
||||||
|
@ -372,7 +372,8 @@ export const deployGenericAToken = async (
|
||||||
incentivesController,
|
incentivesController,
|
||||||
'18',
|
'18',
|
||||||
name,
|
name,
|
||||||
symbol
|
symbol,
|
||||||
|
'0x10'
|
||||||
);
|
);
|
||||||
|
|
||||||
return instance;
|
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 {
|
import { TestEnv, makeSuite } from './helpers/make-suite';
|
||||||
// IReserveParams,
|
import { deployDefaultReserveInterestRateStrategy } from '../../helpers/contracts-deployments';
|
||||||
// iAavePoolAssets,
|
|
||||||
// iAssetsWithoutETH,
|
|
||||||
// ITestEnvWithoutInstances,
|
|
||||||
// } from "../utils/types"
|
|
||||||
// import {
|
|
||||||
|
|
||||||
// LendingPoolAddressesProviderInstance,
|
import { APPROVAL_AMOUNT_LENDING_POOL, PERCENTAGE_FACTOR, RAY } from '../../helpers/constants';
|
||||||
|
|
||||||
// DefaultReserveInterestRateStrategyInstance,
|
import { rateStrategyStableOne } from '../../markets/aave/rateStrategies';
|
||||||
// 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")
|
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]) => {
|
const { expect } = require('chai');
|
||||||
// let _testEnvProvider: ITestEnvWithoutInstances
|
|
||||||
// let _strategyInstance: DefaultReserveInterestRateStrategyInstance
|
|
||||||
// let _tokenInstances: iAssetsWithoutETH<MintableERC20Instance>
|
|
||||||
// let _addressesProviderInstance: LendingPoolAddressesProviderInstance
|
|
||||||
// let _reservesParams: iAavePoolAssets<IReserveParams>
|
|
||||||
|
|
||||||
// before("Initializing test variables", async () => {
|
makeSuite('Interest rate strategy tests', (testEnv: TestEnv) => {
|
||||||
// console.time('setup-test');
|
let strategyInstance: DefaultReserveInterestRateStrategy;
|
||||||
// _testEnvProvider = await testEnvProviderWithoutInstances(
|
let dai: MintableERC20;
|
||||||
// artifacts,
|
let aDai: AToken;
|
||||||
// [deployer, ...users],
|
|
||||||
// )
|
|
||||||
|
|
||||||
// const {
|
before(async () => {
|
||||||
// getAllAssetsInstances,
|
dai = testEnv.dai;
|
||||||
// getLendingPoolAddressesProviderInstance,
|
aDai = testEnv.aDai;
|
||||||
// getAavePoolReservesParams,
|
|
||||||
// } = _testEnvProvider
|
|
||||||
|
|
||||||
// const instances = await Promise.all([
|
const { addressesProvider } = testEnv;
|
||||||
// getAllAssetsInstances(),
|
|
||||||
// getLendingPoolAddressesProviderInstance()
|
|
||||||
// ])
|
|
||||||
|
|
||||||
// _tokenInstances = instances[0]
|
strategyInstance = await deployDefaultReserveInterestRateStrategy(
|
||||||
// _addressesProviderInstance = instances[1]
|
[
|
||||||
// _reservesParams = await getAavePoolReservesParams()
|
addressesProvider.address,
|
||||||
// console.timeEnd('setup-test');
|
rateStrategyStableOne.optimalUtilizationRate,
|
||||||
// })
|
rateStrategyStableOne.baseVariableBorrowRate,
|
||||||
|
rateStrategyStableOne.variableRateSlope1,
|
||||||
|
rateStrategyStableOne.variableRateSlope2,
|
||||||
|
rateStrategyStableOne.stableRateSlope1,
|
||||||
|
rateStrategyStableOne.stableRateSlope2,
|
||||||
|
],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// it("Deploys a new instance of a DefaultReserveInterestRateStrategy contract", async () => {
|
it('Checks rates at 0% utilization rate, empty reserve', async () => {
|
||||||
// const {DAI: daiInstance} = _tokenInstances
|
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")
|
it('Checks rates at 80% utilization rate', async () => {
|
||||||
// const mathLibrary = await artifacts.require("WadRayMath")
|
const {
|
||||||
// const mathLibraryInstance = await mathLibrary.new()
|
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(
|
expect(currentLiquidityRate.toString()).to.be.equal(
|
||||||
// daiInstance.address,
|
expectedVariableRate
|
||||||
// _addressesProviderInstance.address,
|
.times(0.8)
|
||||||
// daiConfiguration.baseVariableBorrowRate,
|
.percentMul(new BigNumber(PERCENTAGE_FACTOR).minus(strategyDAI.reserveFactor))
|
||||||
// daiConfiguration.variableRateSlope1,
|
.toFixed(0),
|
||||||
// daiConfiguration.variableRateSlope2,
|
'Invalid liquidity rate'
|
||||||
// daiConfiguration.stableRateSlope1,
|
);
|
||||||
// daiConfiguration.stableRateSlope2,
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it("Checks rates at 0% utilization rate", async () => {
|
expect(currentVariableBorrowRate.toString()).to.be.equal(
|
||||||
// const {DAI: daiInstance} = _tokenInstances
|
expectedVariableRate.toFixed(0),
|
||||||
// const {DAI: daiConfiguration} = _reservesParams
|
'Invalid variable rate'
|
||||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
);
|
||||||
// daiInstance.address,
|
|
||||||
// "1000000000000000000",
|
|
||||||
// "0",
|
|
||||||
// "0",
|
|
||||||
// "0",
|
|
||||||
// )
|
|
||||||
|
|
||||||
// expect(data.currentLiquidityRate.toString()).to.be.equal("0", "Invalid liquidity rate")
|
expect(currentStableBorrowRate.toString()).to.be.equal(
|
||||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
new BigNumber(0.039).times(RAY).plus(rateStrategyStableOne.stableRateSlope1).toFixed(0),
|
||||||
// new BigNumber(0.039).times(RAY).toFixed(0),
|
'Invalid stable rate'
|
||||||
// "Invalid stable rate",
|
);
|
||||||
// )
|
});
|
||||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
|
||||||
// daiConfiguration.baseVariableBorrowRate,
|
|
||||||
// "Invalid variable rate",
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it("Checks rates at 80% utilization rate", async () => {
|
it('Checks rates at 100% utilization rate', async () => {
|
||||||
// const {DAI: daiInstance} = _tokenInstances
|
const {
|
||||||
// const {DAI: daiConfiguration} = _reservesParams
|
0: currentLiquidityRate,
|
||||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
1: currentStableBorrowRate,
|
||||||
// daiInstance.address,
|
2: currentVariableBorrowRate,
|
||||||
// "200000000000000000",
|
} = await strategyInstance.calculateInterestRates(
|
||||||
// "0",
|
dai.address,
|
||||||
// "800000000000000000",
|
aDai.address,
|
||||||
// "0",
|
'0',
|
||||||
// )
|
'0',
|
||||||
|
'0',
|
||||||
|
'800000000000000000',
|
||||||
|
'0',
|
||||||
|
strategyDAI.reserveFactor
|
||||||
|
);
|
||||||
|
|
||||||
// const expectedVariableRate = new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
const expectedVariableRate = new BigNumber(rateStrategyStableOne.baseVariableBorrowRate)
|
||||||
// .plus(daiConfiguration.variableRateSlope1)
|
.plus(rateStrategyStableOne.variableRateSlope1)
|
||||||
|
.plus(rateStrategyStableOne.variableRateSlope2);
|
||||||
|
|
||||||
// expect(data.currentLiquidityRate.toString()).to.be.equal(
|
expect(currentLiquidityRate.toString()).to.be.equal(
|
||||||
// expectedVariableRate.times(0.8).toFixed(0),
|
expectedVariableRate
|
||||||
// "Invalid liquidity rate",
|
.percentMul(new BigNumber(PERCENTAGE_FACTOR).minus(strategyDAI.reserveFactor))
|
||||||
// )
|
.toFixed(0),
|
||||||
|
'Invalid liquidity rate'
|
||||||
|
);
|
||||||
|
|
||||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
expect(currentVariableBorrowRate.toString()).to.be.equal(
|
||||||
// new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
expectedVariableRate.toFixed(0),
|
||||||
// .plus(daiConfiguration.variableRateSlope1)
|
'Invalid variable rate'
|
||||||
// .toFixed(0),
|
);
|
||||||
// "Invalid variable rate",
|
|
||||||
// )
|
|
||||||
|
|
||||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
expect(currentStableBorrowRate.toString()).to.be.equal(
|
||||||
// new BigNumber(0.039)
|
new BigNumber(0.039)
|
||||||
// .times(RAY)
|
.times(RAY)
|
||||||
// .plus(daiConfiguration.stableRateSlope1)
|
.plus(rateStrategyStableOne.stableRateSlope1)
|
||||||
// .toFixed(0),
|
.plus(rateStrategyStableOne.stableRateSlope2)
|
||||||
// "Invalid stable rate",
|
.toFixed(0),
|
||||||
// )
|
'Invalid stable rate'
|
||||||
// })
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// it("Checks rates at 100% utilization rate", async () => {
|
it('Checks rates at 100% utilization rate, 50% stable debt and 50% variable debt, with a 10% avg stable rate', async () => {
|
||||||
// const {DAI: daiInstance} = _tokenInstances
|
const {
|
||||||
// const {DAI: daiConfiguration} = _reservesParams
|
0: currentLiquidityRate,
|
||||||
// const data: any = await _strategyInstance.calculateInterestRates(
|
1: currentStableBorrowRate,
|
||||||
// daiInstance.address,
|
2: currentVariableBorrowRate,
|
||||||
// "0",
|
} = await strategyInstance.calculateInterestRates(
|
||||||
// "0",
|
dai.address,
|
||||||
// "1000000000000000000",
|
aDai.address,
|
||||||
// "0",
|
'0',
|
||||||
// )
|
'0',
|
||||||
|
'400000000000000000',
|
||||||
|
'400000000000000000',
|
||||||
|
'100000000000000000000000000',
|
||||||
|
strategyDAI.reserveFactor
|
||||||
|
);
|
||||||
|
|
||||||
// const expectedVariableRate = new BigNumber(daiConfiguration.baseVariableBorrowRate)
|
const expectedVariableRate = new BigNumber(rateStrategyStableOne.baseVariableBorrowRate)
|
||||||
// .plus(daiConfiguration.variableRateSlope1)
|
.plus(rateStrategyStableOne.variableRateSlope1)
|
||||||
// .plus(daiConfiguration.variableRateSlope2)
|
.plus(rateStrategyStableOne.variableRateSlope2);
|
||||||
// .toFixed(0)
|
|
||||||
|
|
||||||
// expect(data.currentLiquidityRate.toString()).to.be.equal(
|
const expectedLiquidityRate = new BigNumber(
|
||||||
// expectedVariableRate,
|
currentVariableBorrowRate.add('100000000000000000000000000').div(2).toString()
|
||||||
// "Invalid liquidity rate",
|
)
|
||||||
// )
|
.percentMul(new BigNumber(PERCENTAGE_FACTOR).minus(strategyDAI.reserveFactor))
|
||||||
|
.toFixed(0);
|
||||||
|
|
||||||
// expect(data.currentVariableBorrowRate.toString()).to.be.equal(
|
expect(currentLiquidityRate.toString()).to.be.equal(
|
||||||
// expectedVariableRate,
|
expectedLiquidityRate,
|
||||||
// "Invalid variable rate",
|
'Invalid liquidity rate'
|
||||||
// )
|
);
|
||||||
|
|
||||||
// expect(data.currentStableBorrowRate.toString()).to.be.equal(
|
expect(currentVariableBorrowRate.toString()).to.be.equal(
|
||||||
// new BigNumber(0.039)
|
expectedVariableRate.toFixed(0),
|
||||||
// .times(RAY)
|
'Invalid variable rate'
|
||||||
// .plus(daiConfiguration.stableRateSlope1)
|
);
|
||||||
// .plus(daiConfiguration.stableRateSlope2)
|
|
||||||
// .toFixed(0),
|
expect(currentStableBorrowRate.toString()).to.be.equal(
|
||||||
// "Invalid stable rate",
|
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