Renamed totalBorrowsStable, totalBorrowsVariable

This commit is contained in:
The3D 2020-09-14 15:13:30 +02:00
parent a6d3cfd03b
commit b2ec4dd2fa
10 changed files with 109 additions and 109 deletions

View File

@ -295,8 +295,8 @@ interface ILendingPool {
view view
returns ( returns (
uint256 availableLiquidity, uint256 availableLiquidity,
uint256 totalBorrowsStable, uint256 totalStableDebt,
uint256 totalBorrowsVariable, uint256 totalVariableDebt,
uint256 liquidityRate, uint256 liquidityRate,
uint256 variableBorrowRate, uint256 variableBorrowRate,
uint256 stableBorrowRate, uint256 stableBorrowRate,

View File

@ -21,8 +21,8 @@ interface IReserveInterestRateStrategy {
function calculateInterestRates( function calculateInterestRates(
address reserve, address reserve,
uint256 utilizationRate, uint256 utilizationRate,
uint256 totalBorrowsStable, uint256 totalStableDebt,
uint256 totalBorrowsVariable, uint256 totalVariableDebt,
uint256 averageStableBorrowRate, uint256 averageStableBorrowRate,
uint256 reserveFactor uint256 reserveFactor
) )

View File

@ -104,8 +104,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
* @dev calculates the interest rates depending on the available liquidity and the total borrowed. * @dev calculates the interest rates depending on the available liquidity and the total borrowed.
* @param reserve the address of the reserve * @param reserve the address of the reserve
* @param availableLiquidity the liquidity available in the reserve * @param availableLiquidity the liquidity available in the reserve
* @param totalBorrowsStable the total borrowed from the reserve a stable rate * @param totalStableDebt the total borrowed from the reserve a stable rate
* @param totalBorrowsVariable the total borrowed from the reserve at a variable rate * @param totalVariableDebt the total borrowed from the reserve at a variable rate
* @param averageStableBorrowRate the weighted average of all the stable rate borrows * @param averageStableBorrowRate the weighted average of all the stable rate borrows
* @param reserveFactor the reserve portion of the interest to redirect to the reserve treasury * @param reserveFactor the reserve portion of the interest to redirect to the reserve treasury
* @return currentLiquidityRate the liquidity rate * @return currentLiquidityRate the liquidity rate
@ -115,8 +115,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
function calculateInterestRates( function calculateInterestRates(
address reserve, address reserve,
uint256 availableLiquidity, uint256 availableLiquidity,
uint256 totalBorrowsStable, uint256 totalStableDebt,
uint256 totalBorrowsVariable, uint256 totalVariableDebt,
uint256 averageStableBorrowRate, uint256 averageStableBorrowRate,
uint256 reserveFactor uint256 reserveFactor
) )
@ -132,7 +132,7 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
CalcInterestRatesLocalVars memory vars; CalcInterestRatesLocalVars memory vars;
vars.totalBorrows = totalBorrowsStable.add(totalBorrowsVariable); vars.totalBorrows = totalStableDebt.add(totalVariableDebt);
vars.currentVariableBorrowRate = 0; vars.currentVariableBorrowRate = 0;
vars.currentStableBorrowRate = 0; vars.currentStableBorrowRate = 0;
vars.currentLiquidityRate = 0; vars.currentLiquidityRate = 0;
@ -166,8 +166,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
} }
vars.currentLiquidityRate = _getOverallBorrowRate( vars.currentLiquidityRate = _getOverallBorrowRate(
totalBorrowsStable, totalStableDebt,
totalBorrowsVariable, totalVariableDebt,
vars.currentVariableBorrowRate, vars.currentVariableBorrowRate,
averageStableBorrowRate averageStableBorrowRate
) )
@ -179,27 +179,27 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
/** /**
* @dev calculates the overall borrow rate as the weighted average between the total variable borrows and total stable borrows. * @dev calculates the overall borrow rate as the weighted average between the total variable borrows and total stable borrows.
* @param totalBorrowsStable the total borrowed from the reserve a stable rate * @param totalStableDebt the total borrowed from the reserve a stable rate
* @param totalBorrowsVariable the total borrowed from the reserve at a variable rate * @param totalVariableDebt the total borrowed from the reserve at a variable rate
* @param currentVariableBorrowRate the current variable borrow rate * @param currentVariableBorrowRate the current variable borrow rate
* @param currentAverageStableBorrowRate the weighted average of all the stable rate borrows * @param currentAverageStableBorrowRate the weighted average of all the stable rate borrows
* @return the weighted averaged borrow rate * @return the weighted averaged borrow rate
**/ **/
function _getOverallBorrowRate( function _getOverallBorrowRate(
uint256 totalBorrowsStable, uint256 totalStableDebt,
uint256 totalBorrowsVariable, uint256 totalVariableDebt,
uint256 currentVariableBorrowRate, uint256 currentVariableBorrowRate,
uint256 currentAverageStableBorrowRate uint256 currentAverageStableBorrowRate
) internal pure returns (uint256) { ) internal pure returns (uint256) {
uint256 totalBorrows = totalBorrowsStable.add(totalBorrowsVariable); uint256 totalBorrows = totalStableDebt.add(totalVariableDebt);
if (totalBorrows == 0) return 0; if (totalBorrows == 0) return 0;
uint256 weightedVariableRate = totalBorrowsVariable.wadToRay().rayMul( uint256 weightedVariableRate = totalVariableDebt.wadToRay().rayMul(
currentVariableBorrowRate currentVariableBorrowRate
); );
uint256 weightedStableRate = totalBorrowsStable.wadToRay().rayMul( uint256 weightedStableRate = totalStableDebt.wadToRay().rayMul(
currentAverageStableBorrowRate currentAverageStableBorrowRate
); );

View File

@ -587,8 +587,8 @@ contract LendingPool is VersionedInitializable, ILendingPool {
view view
returns ( returns (
uint256 availableLiquidity, uint256 availableLiquidity,
uint256 totalBorrowsStable, uint256 totalStableDebt,
uint256 totalBorrowsVariable, uint256 totalVariableDebt,
uint256 liquidityRate, uint256 liquidityRate,
uint256 variableBorrowRate, uint256 variableBorrowRate,
uint256 stableBorrowRate, uint256 stableBorrowRate,

View File

@ -421,8 +421,8 @@ contract LendingPoolConfigurator is VersionedInitializable {
function deactivateReserve(address asset) external onlyLendingPoolManager { function deactivateReserve(address asset) external onlyLendingPoolManager {
( (
uint256 availableLiquidity, uint256 availableLiquidity,
uint256 totalBorrowsStable, uint256 totalStableDebt,
uint256 totalBorrowsVariable, uint256 totalVariableDebt,
, ,
, ,
, ,
@ -432,7 +432,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
) = pool.getReserveData(asset); ) = pool.getReserveData(asset);
require( require(
availableLiquidity == 0 && totalBorrowsStable == 0 && totalBorrowsVariable == 0, availableLiquidity == 0 && totalStableDebt == 0 && totalVariableDebt == 0,
Errors.RESERVE_LIQUIDITY_NOT_0 Errors.RESERVE_LIQUIDITY_NOT_0
); );

View File

@ -233,7 +233,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
userData: usdcUserDataBefore, userData: usdcUserDataBefore,
} = await getContractsData(usdc.address, user.address, testEnv); } = await getContractsData(usdc.address, user.address, testEnv);
const amountToRepay = usdcReserveDataBefore.totalBorrowsVariable.dividedBy(2).toFixed(0); const amountToRepay = usdcReserveDataBefore.totalVariableDebt.dividedBy(2).toFixed(0);
await mockSwapAdapter.setAmountToReturn(amountToRepay); await mockSwapAdapter.setAmountToReturn(amountToRepay);
await waitForTx( await waitForTx(
@ -368,7 +368,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
userData: usdcUserDataBefore, userData: usdcUserDataBefore,
} = await getContractsData(usdc.address, user.address, testEnv); } = await getContractsData(usdc.address, user.address, testEnv);
const amountToRepay = usdcReserveDataBefore.totalBorrowsVariable.toFixed(0); const amountToRepay = usdcReserveDataBefore.totalVariableDebt.toFixed(0);
await mockSwapAdapter.setAmountToReturn(amountToRepay); await mockSwapAdapter.setAmountToReturn(amountToRepay);
await waitForTx( await waitForTx(
@ -486,7 +486,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
testEnv testEnv
); );
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.toString(); const amountToRepay = daiReserveDataBefore.totalVariableDebt.toString();
await waitForTx(await mockSwapAdapter.setTryReentrancy(true)); await waitForTx(await mockSwapAdapter.setTryReentrancy(true));
@ -522,7 +522,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
); );
// First half // First half
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.dividedBy(2).toString(); const amountToRepay = daiReserveDataBefore.totalVariableDebt.dividedBy(2).toString();
await mockSwapAdapter.setAmountToReturn(amountToRepay); await mockSwapAdapter.setAmountToReturn(amountToRepay);
await expect( await expect(
@ -568,7 +568,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
); );
// First half // First half
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.multipliedBy(0.6).toString(); const amountToRepay = daiReserveDataBefore.totalVariableDebt.multipliedBy(0.6).toString();
await mockSwapAdapter.setAmountToReturn(amountToRepay); await mockSwapAdapter.setAmountToReturn(amountToRepay);
await waitForTx( await waitForTx(
@ -654,7 +654,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
await increaseTime(1000); await increaseTime(1000);
// Repay the remaining DAI // Repay the remaining DAI
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.toString(); const amountToRepay = daiReserveDataBefore.totalVariableDebt.toString();
await mockSwapAdapter.setAmountToReturn(amountToRepay); await mockSwapAdapter.setAmountToReturn(amountToRepay);
const receipt = await waitForTx( const receipt = await waitForTx(

View File

@ -60,8 +60,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const currentLiquidityIndex = reserveData.liquidityIndex; const currentLiquidityIndex = reserveData.liquidityIndex;
const totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString()) const totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString())
.plus(reserveData.totalBorrowsStable.toString()) .plus(reserveData.totalStableDebt.toString())
.plus(reserveData.totalBorrowsVariable.toString()); .plus(reserveData.totalVariableDebt.toString());
expect(totalLiquidity.toString()).to.be.equal('1000720000000000000'); expect(totalLiquidity.toString()).to.be.equal('1000720000000000000');
expect(currentLiquidityRate.toString()).to.be.equal('0'); expect(currentLiquidityRate.toString()).to.be.equal('0');
@ -87,8 +87,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const currentLiquidityIndex = reserveData.liquidityIndex; const currentLiquidityIndex = reserveData.liquidityIndex;
const totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString()) const totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString())
.plus(reserveData.totalBorrowsStable.toString()) .plus(reserveData.totalStableDebt.toString())
.plus(reserveData.totalBorrowsVariable.toString()); .plus(reserveData.totalVariableDebt.toString());
expect(totalLiquidity.toString()).to.be.equal('1001620648000000000'); expect(totalLiquidity.toString()).to.be.equal('1001620648000000000');
expect(currentLiqudityRate.toString()).to.be.equal('0'); expect(currentLiqudityRate.toString()).to.be.equal('0');
@ -242,8 +242,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const userData = await pool.getUserReserveData(usdc.address, depositor.address); const userData = await pool.getUserReserveData(usdc.address, depositor.address);
const totalLiquidity = reserveData.availableLiquidity const totalLiquidity = reserveData.availableLiquidity
.add(reserveData.totalBorrowsStable) .add(reserveData.totalStableDebt)
.add(reserveData.totalBorrowsVariable) .add(reserveData.totalVariableDebt)
.toString(); .toString();
const currentLiqudityRate = reserveData.liquidityRate.toString(); const currentLiqudityRate = reserveData.liquidityRate.toString();
const currentLiquidityIndex = reserveData.liquidityIndex.toString(); const currentLiquidityIndex = reserveData.liquidityIndex.toString();

View File

@ -166,21 +166,21 @@ export const calcExpectedReserveDataAfterDeposit = (
reserveDataBeforeAction.availableLiquidity reserveDataBeforeAction.availableLiquidity
).plus(amountDeposited); ).plus(amountDeposited);
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable; expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable; expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate; expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
expectedReserveData.utilizationRate = calcExpectedUtilizationRate( expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.totalLiquidity expectedReserveData.totalLiquidity
); );
const rates = calcExpectedInterestRates( const rates = calcExpectedInterestRates(
reserveDataBeforeAction.symbol, reserveDataBeforeAction.symbol,
reserveDataBeforeAction.marketStableRate, reserveDataBeforeAction.marketStableRate,
expectedReserveData.utilizationRate, expectedReserveData.utilizationRate,
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.averageStableBorrowRate expectedReserveData.averageStableBorrowRate
); );
expectedReserveData.liquidityRate = rates[0]; expectedReserveData.liquidityRate = rates[0];
@ -225,21 +225,21 @@ export const calcExpectedReserveDataAfterWithdraw = (
reserveDataBeforeAction.availableLiquidity reserveDataBeforeAction.availableLiquidity
).minus(amountWithdrawn); ).minus(amountWithdrawn);
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable; expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable; expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate; expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
expectedReserveData.utilizationRate = calcExpectedUtilizationRate( expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.totalLiquidity expectedReserveData.totalLiquidity
); );
const rates = calcExpectedInterestRates( const rates = calcExpectedInterestRates(
reserveDataBeforeAction.symbol, reserveDataBeforeAction.symbol,
reserveDataBeforeAction.marketStableRate, reserveDataBeforeAction.marketStableRate,
expectedReserveData.utilizationRate, expectedReserveData.utilizationRate,
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.averageStableBorrowRate expectedReserveData.averageStableBorrowRate
); );
expectedReserveData.liquidityRate = rates[0]; expectedReserveData.liquidityRate = rates[0];
@ -286,17 +286,17 @@ export const calcExpectedReserveDataAfterBorrow = (
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued); expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt
.plus(amountBorrowedBN) .plus(amountBorrowedBN)
.plus(debtAccrued); .plus(debtAccrued);
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate( expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
reserveDataBeforeAction.averageStableBorrowRate, reserveDataBeforeAction.averageStableBorrowRate,
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued), reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
amountBorrowedBN, amountBorrowedBN,
reserveDataBeforeAction.stableBorrowRate reserveDataBeforeAction.stableBorrowRate
); );
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable; expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
} else { } else {
const variableDebtBefore = userDataBeforeAction.scaledVariableDebt.rayMul( const variableDebtBefore = userDataBeforeAction.scaledVariableDebt.rayMul(
reserveDataBeforeAction.variableBorrowIndex reserveDataBeforeAction.variableBorrowIndex
@ -304,10 +304,10 @@ export const calcExpectedReserveDataAfterBorrow = (
const debtAccrued = userVariableDebt.minus(variableDebtBefore); const debtAccrued = userVariableDebt.minus(variableDebtBefore);
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued); expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt
.plus(amountBorrowedBN) .plus(amountBorrowedBN)
.plus(debtAccrued); .plus(debtAccrued);
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable; expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate; expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
} }
@ -316,8 +316,8 @@ export const calcExpectedReserveDataAfterBorrow = (
); );
expectedReserveData.utilizationRate = calcExpectedUtilizationRate( expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.totalLiquidity expectedReserveData.totalLiquidity
); );
@ -325,8 +325,8 @@ export const calcExpectedReserveDataAfterBorrow = (
reserveDataBeforeAction.symbol, reserveDataBeforeAction.symbol,
reserveDataBeforeAction.marketStableRate, reserveDataBeforeAction.marketStableRate,
expectedReserveData.utilizationRate, expectedReserveData.utilizationRate,
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.averageStableBorrowRate expectedReserveData.averageStableBorrowRate
); );
expectedReserveData.liquidityRate = rates[0]; expectedReserveData.liquidityRate = rates[0];
@ -385,17 +385,17 @@ export const calcExpectedReserveDataAfterRepay = (
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued); expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt
.minus(amountRepaidBN) .minus(amountRepaidBN)
.plus(debtAccrued); .plus(debtAccrued);
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate( expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
reserveDataBeforeAction.averageStableBorrowRate, reserveDataBeforeAction.averageStableBorrowRate,
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued), reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
amountRepaidBN.negated(), amountRepaidBN.negated(),
userDataBeforeAction.stableBorrowRate userDataBeforeAction.stableBorrowRate
); );
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable; expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
} else { } else {
const variableDebtBefore = userDataBeforeAction.scaledVariableDebt.rayMul( const variableDebtBefore = userDataBeforeAction.scaledVariableDebt.rayMul(
reserveDataBeforeAction.variableBorrowIndex reserveDataBeforeAction.variableBorrowIndex
@ -405,11 +405,11 @@ export const calcExpectedReserveDataAfterRepay = (
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued); expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt
.plus(debtAccrued) .plus(debtAccrued)
.minus(amountRepaidBN); .minus(amountRepaidBN);
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable; expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate; expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
} }
@ -422,8 +422,8 @@ export const calcExpectedReserveDataAfterRepay = (
); );
expectedReserveData.utilizationRate = calcExpectedUtilizationRate( expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.totalLiquidity expectedReserveData.totalLiquidity
); );
@ -431,8 +431,8 @@ export const calcExpectedReserveDataAfterRepay = (
reserveDataBeforeAction.symbol, reserveDataBeforeAction.symbol,
reserveDataBeforeAction.marketStableRate, reserveDataBeforeAction.marketStableRate,
expectedReserveData.utilizationRate, expectedReserveData.utilizationRate,
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.averageStableBorrowRate expectedReserveData.averageStableBorrowRate
); );
expectedReserveData.liquidityRate = rates[0]; expectedReserveData.liquidityRate = rates[0];
@ -677,16 +677,16 @@ export const calcExpectedReserveDataAfterSwapRateMode = (
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate( expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
reserveDataBeforeAction.averageStableBorrowRate, reserveDataBeforeAction.averageStableBorrowRate,
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued), reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
stableDebt.negated(), stableDebt.negated(),
userDataBeforeAction.stableBorrowRate userDataBeforeAction.stableBorrowRate
); );
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable.plus( expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt.plus(
stableDebt stableDebt
); );
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable.minus( expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt.minus(
userDataBeforeAction.principalStableDebt userDataBeforeAction.principalStableDebt
); );
} else { } else {
@ -695,23 +695,23 @@ export const calcExpectedReserveDataAfterSwapRateMode = (
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued); expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable; expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable.plus( expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt.plus(
variableDebt variableDebt
); );
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate( expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
reserveDataBeforeAction.averageStableBorrowRate, reserveDataBeforeAction.averageStableBorrowRate,
reserveDataBeforeAction.totalBorrowsStable, reserveDataBeforeAction.totalStableDebt,
variableDebt, variableDebt,
reserveDataBeforeAction.stableBorrowRate reserveDataBeforeAction.stableBorrowRate
); );
} }
expectedReserveData.utilizationRate = calcExpectedUtilizationRate( expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.totalLiquidity expectedReserveData.totalLiquidity
); );
@ -719,8 +719,8 @@ export const calcExpectedReserveDataAfterSwapRateMode = (
reserveDataBeforeAction.symbol, reserveDataBeforeAction.symbol,
reserveDataBeforeAction.marketStableRate, reserveDataBeforeAction.marketStableRate,
expectedReserveData.utilizationRate, expectedReserveData.utilizationRate,
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.averageStableBorrowRate expectedReserveData.averageStableBorrowRate
); );
expectedReserveData.liquidityRate = rates[0]; expectedReserveData.liquidityRate = rates[0];
@ -824,7 +824,7 @@ export const calcExpectedReserveDataAfterStableRateRebalance = (
const avgRateBefore = calcExpectedAverageStableBorrowRate( const avgRateBefore = calcExpectedAverageStableBorrowRate(
reserveDataBeforeAction.averageStableBorrowRate, reserveDataBeforeAction.averageStableBorrowRate,
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued), reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
stableBorrowBalance.negated(), stableBorrowBalance.negated(),
userDataBeforeAction.stableBorrowRate userDataBeforeAction.stableBorrowRate
); );
@ -832,19 +832,19 @@ export const calcExpectedReserveDataAfterStableRateRebalance = (
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate( expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
avgRateBefore, avgRateBefore,
reserveDataBeforeAction.totalBorrowsStable.minus(userDataBeforeAction.principalStableDebt), reserveDataBeforeAction.totalStableDebt.minus(userDataBeforeAction.principalStableDebt),
stableBorrowBalance, stableBorrowBalance,
reserveDataBeforeAction.stableBorrowRate reserveDataBeforeAction.stableBorrowRate
); );
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable; expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable.plus( expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt.plus(
debtAccrued debtAccrued
); );
expectedReserveData.utilizationRate = calcExpectedUtilizationRate( expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.totalLiquidity expectedReserveData.totalLiquidity
); );
@ -852,8 +852,8 @@ export const calcExpectedReserveDataAfterStableRateRebalance = (
reserveDataBeforeAction.symbol, reserveDataBeforeAction.symbol,
reserveDataBeforeAction.marketStableRate, reserveDataBeforeAction.marketStableRate,
expectedReserveData.utilizationRate, expectedReserveData.utilizationRate,
expectedReserveData.totalBorrowsStable, expectedReserveData.totalStableDebt,
expectedReserveData.totalBorrowsVariable, expectedReserveData.totalVariableDebt,
expectedReserveData.averageStableBorrowRate expectedReserveData.averageStableBorrowRate
); );
@ -936,13 +936,13 @@ const calcExpectedATokenBalance = (
const calcExpectedAverageStableBorrowRate = ( const calcExpectedAverageStableBorrowRate = (
avgStableRateBefore: BigNumber, avgStableRateBefore: BigNumber,
totalBorrowsStableBefore: BigNumber, totalStableDebtBefore: BigNumber,
amountChanged: string | BigNumber, amountChanged: string | BigNumber,
rate: BigNumber rate: BigNumber
) => { ) => {
const weightedTotalBorrows = avgStableRateBefore.multipliedBy(totalBorrowsStableBefore); const weightedTotalBorrows = avgStableRateBefore.multipliedBy(totalStableDebtBefore);
const weightedAmountBorrowed = rate.multipliedBy(amountChanged); const weightedAmountBorrowed = rate.multipliedBy(amountChanged);
const totalBorrowedStable = totalBorrowsStableBefore.plus(new BigNumber(amountChanged)); const totalBorrowedStable = totalStableDebtBefore.plus(new BigNumber(amountChanged));
if (totalBorrowedStable.eq(0)) return new BigNumber('0'); if (totalBorrowedStable.eq(0)) return new BigNumber('0');
@ -1048,8 +1048,8 @@ const calcExpectedInterestRates = (
reserveSymbol: string, reserveSymbol: string,
marketStableRate: BigNumber, marketStableRate: BigNumber,
utilizationRate: BigNumber, utilizationRate: BigNumber,
totalBorrowsStable: BigNumber, totalStableDebt: BigNumber,
totalBorrowsVariable: BigNumber, totalVariableDebt: BigNumber,
averageStableBorrowRate: BigNumber averageStableBorrowRate: BigNumber
): BigNumber[] => { ): BigNumber[] => {
const {reservesParams} = configuration; const {reservesParams} = configuration;
@ -1093,8 +1093,8 @@ const calcExpectedInterestRates = (
} }
const expectedOverallRate = calcExpectedOverallBorrowRate( const expectedOverallRate = calcExpectedOverallBorrowRate(
totalBorrowsStable, totalStableDebt,
totalBorrowsVariable, totalVariableDebt,
variableBorrowRate, variableBorrowRate,
averageStableBorrowRate averageStableBorrowRate
); );
@ -1104,18 +1104,18 @@ const calcExpectedInterestRates = (
}; };
const calcExpectedOverallBorrowRate = ( const calcExpectedOverallBorrowRate = (
totalBorrowsStable: BigNumber, totalStableDebt: BigNumber,
totalBorrowsVariable: BigNumber, totalVariableDebt: BigNumber,
currentVariableBorrowRate: BigNumber, currentVariableBorrowRate: BigNumber,
currentAverageStableBorrowRate: BigNumber currentAverageStableBorrowRate: BigNumber
): BigNumber => { ): BigNumber => {
const totalBorrows = totalBorrowsStable.plus(totalBorrowsVariable); const totalBorrows = totalStableDebt.plus(totalVariableDebt);
if (totalBorrows.eq(0)) return strToBN('0'); if (totalBorrows.eq(0)) return strToBN('0');
const weightedVariableRate = totalBorrowsVariable.wadToRay().rayMul(currentVariableBorrowRate); const weightedVariableRate = totalVariableDebt.wadToRay().rayMul(currentVariableBorrowRate);
const weightedStableRate = totalBorrowsStable.wadToRay().rayMul(currentAverageStableBorrowRate); const weightedStableRate = totalStableDebt.wadToRay().rayMul(currentAverageStableBorrowRate);
const overallBorrowRate = weightedVariableRate const overallBorrowRate = weightedVariableRate
.plus(weightedStableRate) .plus(weightedStableRate)
@ -1125,15 +1125,15 @@ const calcExpectedOverallBorrowRate = (
}; };
const calcExpectedUtilizationRate = ( const calcExpectedUtilizationRate = (
totalBorrowsStable: BigNumber, totalStableDebt: BigNumber,
totalBorrowsVariable: BigNumber, totalVariableDebt: BigNumber,
totalLiquidity: BigNumber totalLiquidity: BigNumber
): BigNumber => { ): BigNumber => {
if (totalBorrowsStable.eq('0') && totalBorrowsVariable.eq('0')) { if (totalStableDebt.eq('0') && totalVariableDebt.eq('0')) {
return strToBN('0'); return strToBN('0');
} }
const utilization = totalBorrowsStable.plus(totalBorrowsVariable).rayDiv(totalLiquidity); const utilization = totalStableDebt.plus(totalVariableDebt).rayDiv(totalLiquidity);
return utilization; return utilization;
}; };
@ -1210,8 +1210,8 @@ const calcExpectedLiquidityIndex = (reserveData: ReserveData, timestamp: BigNumb
}; };
const calcExpectedVariableBorrowIndex = (reserveData: ReserveData, timestamp: BigNumber) => { const calcExpectedVariableBorrowIndex = (reserveData: ReserveData, timestamp: BigNumber) => {
//if totalBorrowsVariable is 0, nothing to compound //if totalVariableDebt is 0, nothing to compound
if (reserveData.totalBorrowsVariable.eq('0')) { if (reserveData.totalVariableDebt.eq('0')) {
return reserveData.variableBorrowIndex; return reserveData.variableBorrowIndex;
} }

View File

@ -26,14 +26,14 @@ export const getReserveData = async (
const decimals = new BigNumber(await token.decimals()); const decimals = new BigNumber(await token.decimals());
const totalLiquidity = new BigNumber(data.availableLiquidity.toString()) const totalLiquidity = new BigNumber(data.availableLiquidity.toString())
.plus(data.totalBorrowsStable.toString()) .plus(data.totalStableDebt.toString())
.plus(data.totalBorrowsVariable.toString()); .plus(data.totalVariableDebt.toString());
const utilizationRate = new BigNumber( const utilizationRate = new BigNumber(
totalLiquidity.eq(0) totalLiquidity.eq(0)
? 0 ? 0
: new BigNumber(data.totalBorrowsStable.toString()) : new BigNumber(data.totalStableDebt.toString())
.plus(data.totalBorrowsVariable.toString()) .plus(data.totalVariableDebt.toString())
.rayDiv(totalLiquidity) .rayDiv(totalLiquidity)
); );
@ -41,8 +41,8 @@ export const getReserveData = async (
totalLiquidity, totalLiquidity,
utilizationRate, utilizationRate,
availableLiquidity: new BigNumber(data.availableLiquidity.toString()), availableLiquidity: new BigNumber(data.availableLiquidity.toString()),
totalBorrowsStable: new BigNumber(data.totalBorrowsStable.toString()), totalStableDebt: new BigNumber(data.totalStableDebt.toString()),
totalBorrowsVariable: new BigNumber(data.totalBorrowsVariable.toString()), totalVariableDebt: new BigNumber(data.totalVariableDebt.toString()),
liquidityRate: new BigNumber(data.liquidityRate.toString()), liquidityRate: new BigNumber(data.liquidityRate.toString()),
variableBorrowRate: new BigNumber(data.variableBorrowRate.toString()), variableBorrowRate: new BigNumber(data.variableBorrowRate.toString()),
stableBorrowRate: new BigNumber(data.stableBorrowRate.toString()), stableBorrowRate: new BigNumber(data.stableBorrowRate.toString()),

View File

@ -21,8 +21,8 @@ export interface ReserveData {
decimals: BigNumber; decimals: BigNumber;
totalLiquidity: BigNumber; totalLiquidity: BigNumber;
availableLiquidity: BigNumber; availableLiquidity: BigNumber;
totalBorrowsStable: BigNumber; totalStableDebt: BigNumber;
totalBorrowsVariable: BigNumber; totalVariableDebt: BigNumber;
averageStableBorrowRate: BigNumber; averageStableBorrowRate: BigNumber;
variableBorrowRate: BigNumber; variableBorrowRate: BigNumber;
stableBorrowRate: BigNumber; stableBorrowRate: BigNumber;