mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Renamed totalBorrowsStable, totalBorrowsVariable
This commit is contained in:
parent
a6d3cfd03b
commit
b2ec4dd2fa
|
@ -295,8 +295,8 @@ interface ILendingPool {
|
|||
view
|
||||
returns (
|
||||
uint256 availableLiquidity,
|
||||
uint256 totalBorrowsStable,
|
||||
uint256 totalBorrowsVariable,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
uint256 liquidityRate,
|
||||
uint256 variableBorrowRate,
|
||||
uint256 stableBorrowRate,
|
||||
|
|
|
@ -21,8 +21,8 @@ interface IReserveInterestRateStrategy {
|
|||
function calculateInterestRates(
|
||||
address reserve,
|
||||
uint256 utilizationRate,
|
||||
uint256 totalBorrowsStable,
|
||||
uint256 totalBorrowsVariable,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
uint256 averageStableBorrowRate,
|
||||
uint256 reserveFactor
|
||||
)
|
||||
|
|
|
@ -104,8 +104,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
* @dev calculates the interest rates depending on the available liquidity and the total borrowed.
|
||||
* @param reserve the address of the reserve
|
||||
* @param availableLiquidity the liquidity available in the reserve
|
||||
* @param totalBorrowsStable the total borrowed from the reserve a stable rate
|
||||
* @param totalBorrowsVariable the total borrowed from the reserve at a variable rate
|
||||
* @param totalStableDebt the total borrowed from the reserve a stable 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 reserveFactor the reserve portion of the interest to redirect to the reserve treasury
|
||||
* @return currentLiquidityRate the liquidity rate
|
||||
|
@ -115,8 +115,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
function calculateInterestRates(
|
||||
address reserve,
|
||||
uint256 availableLiquidity,
|
||||
uint256 totalBorrowsStable,
|
||||
uint256 totalBorrowsVariable,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
uint256 averageStableBorrowRate,
|
||||
uint256 reserveFactor
|
||||
)
|
||||
|
@ -132,7 +132,7 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
|
||||
CalcInterestRatesLocalVars memory vars;
|
||||
|
||||
vars.totalBorrows = totalBorrowsStable.add(totalBorrowsVariable);
|
||||
vars.totalBorrows = totalStableDebt.add(totalVariableDebt);
|
||||
vars.currentVariableBorrowRate = 0;
|
||||
vars.currentStableBorrowRate = 0;
|
||||
vars.currentLiquidityRate = 0;
|
||||
|
@ -166,8 +166,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
}
|
||||
|
||||
vars.currentLiquidityRate = _getOverallBorrowRate(
|
||||
totalBorrowsStable,
|
||||
totalBorrowsVariable,
|
||||
totalStableDebt,
|
||||
totalVariableDebt,
|
||||
vars.currentVariableBorrowRate,
|
||||
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.
|
||||
* @param totalBorrowsStable the total borrowed from the reserve a stable rate
|
||||
* @param totalBorrowsVariable the total borrowed from the reserve at a variable rate
|
||||
* @param totalStableDebt the total borrowed from the reserve a stable rate
|
||||
* @param totalVariableDebt the total borrowed from the reserve at a variable rate
|
||||
* @param currentVariableBorrowRate the current variable borrow rate
|
||||
* @param currentAverageStableBorrowRate the weighted average of all the stable rate borrows
|
||||
* @return the weighted averaged borrow rate
|
||||
**/
|
||||
function _getOverallBorrowRate(
|
||||
uint256 totalBorrowsStable,
|
||||
uint256 totalBorrowsVariable,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
uint256 currentVariableBorrowRate,
|
||||
uint256 currentAverageStableBorrowRate
|
||||
) internal pure returns (uint256) {
|
||||
uint256 totalBorrows = totalBorrowsStable.add(totalBorrowsVariable);
|
||||
uint256 totalBorrows = totalStableDebt.add(totalVariableDebt);
|
||||
|
||||
if (totalBorrows == 0) return 0;
|
||||
|
||||
uint256 weightedVariableRate = totalBorrowsVariable.wadToRay().rayMul(
|
||||
uint256 weightedVariableRate = totalVariableDebt.wadToRay().rayMul(
|
||||
currentVariableBorrowRate
|
||||
);
|
||||
|
||||
uint256 weightedStableRate = totalBorrowsStable.wadToRay().rayMul(
|
||||
uint256 weightedStableRate = totalStableDebt.wadToRay().rayMul(
|
||||
currentAverageStableBorrowRate
|
||||
);
|
||||
|
||||
|
|
|
@ -587,8 +587,8 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
|||
view
|
||||
returns (
|
||||
uint256 availableLiquidity,
|
||||
uint256 totalBorrowsStable,
|
||||
uint256 totalBorrowsVariable,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
uint256 liquidityRate,
|
||||
uint256 variableBorrowRate,
|
||||
uint256 stableBorrowRate,
|
||||
|
|
|
@ -421,8 +421,8 @@ contract LendingPoolConfigurator is VersionedInitializable {
|
|||
function deactivateReserve(address asset) external onlyLendingPoolManager {
|
||||
(
|
||||
uint256 availableLiquidity,
|
||||
uint256 totalBorrowsStable,
|
||||
uint256 totalBorrowsVariable,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
,
|
||||
,
|
||||
,
|
||||
|
@ -432,7 +432,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
|
|||
|
||||
) = pool.getReserveData(asset);
|
||||
require(
|
||||
availableLiquidity == 0 && totalBorrowsStable == 0 && totalBorrowsVariable == 0,
|
||||
availableLiquidity == 0 && totalStableDebt == 0 && totalVariableDebt == 0,
|
||||
Errors.RESERVE_LIQUIDITY_NOT_0
|
||||
);
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
|
|||
userData: usdcUserDataBefore,
|
||||
} = 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 waitForTx(
|
||||
|
@ -368,7 +368,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
|
|||
userData: usdcUserDataBefore,
|
||||
} = await getContractsData(usdc.address, user.address, testEnv);
|
||||
|
||||
const amountToRepay = usdcReserveDataBefore.totalBorrowsVariable.toFixed(0);
|
||||
const amountToRepay = usdcReserveDataBefore.totalVariableDebt.toFixed(0);
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
await waitForTx(
|
||||
|
@ -486,7 +486,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
|
|||
testEnv
|
||||
);
|
||||
|
||||
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.toString();
|
||||
const amountToRepay = daiReserveDataBefore.totalVariableDebt.toString();
|
||||
|
||||
await waitForTx(await mockSwapAdapter.setTryReentrancy(true));
|
||||
|
||||
|
@ -522,7 +522,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
|
|||
);
|
||||
|
||||
// First half
|
||||
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.dividedBy(2).toString();
|
||||
const amountToRepay = daiReserveDataBefore.totalVariableDebt.dividedBy(2).toString();
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
await expect(
|
||||
|
@ -568,7 +568,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
|
|||
);
|
||||
|
||||
// First half
|
||||
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.multipliedBy(0.6).toString();
|
||||
const amountToRepay = daiReserveDataBefore.totalVariableDebt.multipliedBy(0.6).toString();
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
await waitForTx(
|
||||
|
@ -654,7 +654,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
|
|||
|
||||
await increaseTime(1000);
|
||||
// Repay the remaining DAI
|
||||
const amountToRepay = daiReserveDataBefore.totalBorrowsVariable.toString();
|
||||
const amountToRepay = daiReserveDataBefore.totalVariableDebt.toString();
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
const receipt = await waitForTx(
|
||||
|
|
|
@ -60,8 +60,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
|||
const currentLiquidityIndex = reserveData.liquidityIndex;
|
||||
|
||||
const totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString())
|
||||
.plus(reserveData.totalBorrowsStable.toString())
|
||||
.plus(reserveData.totalBorrowsVariable.toString());
|
||||
.plus(reserveData.totalStableDebt.toString())
|
||||
.plus(reserveData.totalVariableDebt.toString());
|
||||
|
||||
expect(totalLiquidity.toString()).to.be.equal('1000720000000000000');
|
||||
expect(currentLiquidityRate.toString()).to.be.equal('0');
|
||||
|
@ -87,8 +87,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
|||
const currentLiquidityIndex = reserveData.liquidityIndex;
|
||||
|
||||
const totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString())
|
||||
.plus(reserveData.totalBorrowsStable.toString())
|
||||
.plus(reserveData.totalBorrowsVariable.toString());
|
||||
.plus(reserveData.totalStableDebt.toString())
|
||||
.plus(reserveData.totalVariableDebt.toString());
|
||||
|
||||
expect(totalLiquidity.toString()).to.be.equal('1001620648000000000');
|
||||
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 totalLiquidity = reserveData.availableLiquidity
|
||||
.add(reserveData.totalBorrowsStable)
|
||||
.add(reserveData.totalBorrowsVariable)
|
||||
.add(reserveData.totalStableDebt)
|
||||
.add(reserveData.totalVariableDebt)
|
||||
.toString();
|
||||
const currentLiqudityRate = reserveData.liquidityRate.toString();
|
||||
const currentLiquidityIndex = reserveData.liquidityIndex.toString();
|
||||
|
|
|
@ -166,21 +166,21 @@ export const calcExpectedReserveDataAfterDeposit = (
|
|||
reserveDataBeforeAction.availableLiquidity
|
||||
).plus(amountDeposited);
|
||||
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable;
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable;
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
|
||||
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
|
||||
|
||||
expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.totalLiquidity
|
||||
);
|
||||
const rates = calcExpectedInterestRates(
|
||||
reserveDataBeforeAction.symbol,
|
||||
reserveDataBeforeAction.marketStableRate,
|
||||
expectedReserveData.utilizationRate,
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.averageStableBorrowRate
|
||||
);
|
||||
expectedReserveData.liquidityRate = rates[0];
|
||||
|
@ -225,21 +225,21 @@ export const calcExpectedReserveDataAfterWithdraw = (
|
|||
reserveDataBeforeAction.availableLiquidity
|
||||
).minus(amountWithdrawn);
|
||||
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable;
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable;
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
|
||||
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
|
||||
|
||||
expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.totalLiquidity
|
||||
);
|
||||
const rates = calcExpectedInterestRates(
|
||||
reserveDataBeforeAction.symbol,
|
||||
reserveDataBeforeAction.marketStableRate,
|
||||
expectedReserveData.utilizationRate,
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.averageStableBorrowRate
|
||||
);
|
||||
expectedReserveData.liquidityRate = rates[0];
|
||||
|
@ -286,17 +286,17 @@ export const calcExpectedReserveDataAfterBorrow = (
|
|||
|
||||
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
|
||||
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt
|
||||
.plus(amountBorrowedBN)
|
||||
.plus(debtAccrued);
|
||||
|
||||
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
|
||||
reserveDataBeforeAction.averageStableBorrowRate,
|
||||
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued),
|
||||
reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
|
||||
amountBorrowedBN,
|
||||
reserveDataBeforeAction.stableBorrowRate
|
||||
);
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable;
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
|
||||
} else {
|
||||
const variableDebtBefore = userDataBeforeAction.scaledVariableDebt.rayMul(
|
||||
reserveDataBeforeAction.variableBorrowIndex
|
||||
|
@ -304,10 +304,10 @@ export const calcExpectedReserveDataAfterBorrow = (
|
|||
|
||||
const debtAccrued = userVariableDebt.minus(variableDebtBefore);
|
||||
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt
|
||||
.plus(amountBorrowedBN)
|
||||
.plus(debtAccrued);
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable;
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
|
||||
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
|
||||
}
|
||||
|
||||
|
@ -316,8 +316,8 @@ export const calcExpectedReserveDataAfterBorrow = (
|
|||
);
|
||||
|
||||
expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.totalLiquidity
|
||||
);
|
||||
|
||||
|
@ -325,8 +325,8 @@ export const calcExpectedReserveDataAfterBorrow = (
|
|||
reserveDataBeforeAction.symbol,
|
||||
reserveDataBeforeAction.marketStableRate,
|
||||
expectedReserveData.utilizationRate,
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.averageStableBorrowRate
|
||||
);
|
||||
expectedReserveData.liquidityRate = rates[0];
|
||||
|
@ -385,17 +385,17 @@ export const calcExpectedReserveDataAfterRepay = (
|
|||
|
||||
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
|
||||
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt
|
||||
.minus(amountRepaidBN)
|
||||
.plus(debtAccrued);
|
||||
|
||||
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
|
||||
reserveDataBeforeAction.averageStableBorrowRate,
|
||||
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued),
|
||||
reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
|
||||
amountRepaidBN.negated(),
|
||||
userDataBeforeAction.stableBorrowRate
|
||||
);
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable;
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
|
||||
} else {
|
||||
const variableDebtBefore = userDataBeforeAction.scaledVariableDebt.rayMul(
|
||||
reserveDataBeforeAction.variableBorrowIndex
|
||||
|
@ -405,11 +405,11 @@ export const calcExpectedReserveDataAfterRepay = (
|
|||
|
||||
expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued);
|
||||
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt
|
||||
.plus(debtAccrued)
|
||||
.minus(amountRepaidBN);
|
||||
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable;
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt;
|
||||
expectedReserveData.averageStableBorrowRate = reserveDataBeforeAction.averageStableBorrowRate;
|
||||
}
|
||||
|
||||
|
@ -422,8 +422,8 @@ export const calcExpectedReserveDataAfterRepay = (
|
|||
);
|
||||
|
||||
expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.totalLiquidity
|
||||
);
|
||||
|
||||
|
@ -431,8 +431,8 @@ export const calcExpectedReserveDataAfterRepay = (
|
|||
reserveDataBeforeAction.symbol,
|
||||
reserveDataBeforeAction.marketStableRate,
|
||||
expectedReserveData.utilizationRate,
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.averageStableBorrowRate
|
||||
);
|
||||
expectedReserveData.liquidityRate = rates[0];
|
||||
|
@ -677,16 +677,16 @@ export const calcExpectedReserveDataAfterSwapRateMode = (
|
|||
|
||||
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
|
||||
reserveDataBeforeAction.averageStableBorrowRate,
|
||||
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued),
|
||||
reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
|
||||
stableDebt.negated(),
|
||||
userDataBeforeAction.stableBorrowRate
|
||||
);
|
||||
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable.plus(
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt.plus(
|
||||
stableDebt
|
||||
);
|
||||
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable.minus(
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt.minus(
|
||||
userDataBeforeAction.principalStableDebt
|
||||
);
|
||||
} else {
|
||||
|
@ -695,23 +695,23 @@ export const calcExpectedReserveDataAfterSwapRateMode = (
|
|||
|
||||
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
|
||||
);
|
||||
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
|
||||
reserveDataBeforeAction.averageStableBorrowRate,
|
||||
reserveDataBeforeAction.totalBorrowsStable,
|
||||
reserveDataBeforeAction.totalStableDebt,
|
||||
variableDebt,
|
||||
reserveDataBeforeAction.stableBorrowRate
|
||||
);
|
||||
}
|
||||
|
||||
expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.totalLiquidity
|
||||
);
|
||||
|
||||
|
@ -719,8 +719,8 @@ export const calcExpectedReserveDataAfterSwapRateMode = (
|
|||
reserveDataBeforeAction.symbol,
|
||||
reserveDataBeforeAction.marketStableRate,
|
||||
expectedReserveData.utilizationRate,
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.averageStableBorrowRate
|
||||
);
|
||||
expectedReserveData.liquidityRate = rates[0];
|
||||
|
@ -824,7 +824,7 @@ export const calcExpectedReserveDataAfterStableRateRebalance = (
|
|||
|
||||
const avgRateBefore = calcExpectedAverageStableBorrowRate(
|
||||
reserveDataBeforeAction.averageStableBorrowRate,
|
||||
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued),
|
||||
reserveDataBeforeAction.totalStableDebt.plus(debtAccrued),
|
||||
stableBorrowBalance.negated(),
|
||||
userDataBeforeAction.stableBorrowRate
|
||||
);
|
||||
|
@ -832,19 +832,19 @@ export const calcExpectedReserveDataAfterStableRateRebalance = (
|
|||
|
||||
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
|
||||
avgRateBefore,
|
||||
reserveDataBeforeAction.totalBorrowsStable.minus(userDataBeforeAction.principalStableDebt),
|
||||
reserveDataBeforeAction.totalStableDebt.minus(userDataBeforeAction.principalStableDebt),
|
||||
stableBorrowBalance,
|
||||
reserveDataBeforeAction.stableBorrowRate
|
||||
);
|
||||
|
||||
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable;
|
||||
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable.plus(
|
||||
expectedReserveData.totalVariableDebt = reserveDataBeforeAction.totalVariableDebt;
|
||||
expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt.plus(
|
||||
debtAccrued
|
||||
);
|
||||
|
||||
expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.totalLiquidity
|
||||
);
|
||||
|
||||
|
@ -852,8 +852,8 @@ export const calcExpectedReserveDataAfterStableRateRebalance = (
|
|||
reserveDataBeforeAction.symbol,
|
||||
reserveDataBeforeAction.marketStableRate,
|
||||
expectedReserveData.utilizationRate,
|
||||
expectedReserveData.totalBorrowsStable,
|
||||
expectedReserveData.totalBorrowsVariable,
|
||||
expectedReserveData.totalStableDebt,
|
||||
expectedReserveData.totalVariableDebt,
|
||||
expectedReserveData.averageStableBorrowRate
|
||||
);
|
||||
|
||||
|
@ -936,13 +936,13 @@ const calcExpectedATokenBalance = (
|
|||
|
||||
const calcExpectedAverageStableBorrowRate = (
|
||||
avgStableRateBefore: BigNumber,
|
||||
totalBorrowsStableBefore: BigNumber,
|
||||
totalStableDebtBefore: BigNumber,
|
||||
amountChanged: string | BigNumber,
|
||||
rate: BigNumber
|
||||
) => {
|
||||
const weightedTotalBorrows = avgStableRateBefore.multipliedBy(totalBorrowsStableBefore);
|
||||
const weightedTotalBorrows = avgStableRateBefore.multipliedBy(totalStableDebtBefore);
|
||||
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');
|
||||
|
||||
|
@ -1048,8 +1048,8 @@ const calcExpectedInterestRates = (
|
|||
reserveSymbol: string,
|
||||
marketStableRate: BigNumber,
|
||||
utilizationRate: BigNumber,
|
||||
totalBorrowsStable: BigNumber,
|
||||
totalBorrowsVariable: BigNumber,
|
||||
totalStableDebt: BigNumber,
|
||||
totalVariableDebt: BigNumber,
|
||||
averageStableBorrowRate: BigNumber
|
||||
): BigNumber[] => {
|
||||
const {reservesParams} = configuration;
|
||||
|
@ -1093,8 +1093,8 @@ const calcExpectedInterestRates = (
|
|||
}
|
||||
|
||||
const expectedOverallRate = calcExpectedOverallBorrowRate(
|
||||
totalBorrowsStable,
|
||||
totalBorrowsVariable,
|
||||
totalStableDebt,
|
||||
totalVariableDebt,
|
||||
variableBorrowRate,
|
||||
averageStableBorrowRate
|
||||
);
|
||||
|
@ -1104,18 +1104,18 @@ const calcExpectedInterestRates = (
|
|||
};
|
||||
|
||||
const calcExpectedOverallBorrowRate = (
|
||||
totalBorrowsStable: BigNumber,
|
||||
totalBorrowsVariable: BigNumber,
|
||||
totalStableDebt: BigNumber,
|
||||
totalVariableDebt: BigNumber,
|
||||
currentVariableBorrowRate: BigNumber,
|
||||
currentAverageStableBorrowRate: BigNumber
|
||||
): BigNumber => {
|
||||
const totalBorrows = totalBorrowsStable.plus(totalBorrowsVariable);
|
||||
const totalBorrows = totalStableDebt.plus(totalVariableDebt);
|
||||
|
||||
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
|
||||
.plus(weightedStableRate)
|
||||
|
@ -1125,15 +1125,15 @@ const calcExpectedOverallBorrowRate = (
|
|||
};
|
||||
|
||||
const calcExpectedUtilizationRate = (
|
||||
totalBorrowsStable: BigNumber,
|
||||
totalBorrowsVariable: BigNumber,
|
||||
totalStableDebt: BigNumber,
|
||||
totalVariableDebt: BigNumber,
|
||||
totalLiquidity: BigNumber
|
||||
): BigNumber => {
|
||||
if (totalBorrowsStable.eq('0') && totalBorrowsVariable.eq('0')) {
|
||||
if (totalStableDebt.eq('0') && totalVariableDebt.eq('0')) {
|
||||
return strToBN('0');
|
||||
}
|
||||
|
||||
const utilization = totalBorrowsStable.plus(totalBorrowsVariable).rayDiv(totalLiquidity);
|
||||
const utilization = totalStableDebt.plus(totalVariableDebt).rayDiv(totalLiquidity);
|
||||
|
||||
return utilization;
|
||||
};
|
||||
|
@ -1210,8 +1210,8 @@ const calcExpectedLiquidityIndex = (reserveData: ReserveData, timestamp: BigNumb
|
|||
};
|
||||
|
||||
const calcExpectedVariableBorrowIndex = (reserveData: ReserveData, timestamp: BigNumber) => {
|
||||
//if totalBorrowsVariable is 0, nothing to compound
|
||||
if (reserveData.totalBorrowsVariable.eq('0')) {
|
||||
//if totalVariableDebt is 0, nothing to compound
|
||||
if (reserveData.totalVariableDebt.eq('0')) {
|
||||
return reserveData.variableBorrowIndex;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ export const getReserveData = async (
|
|||
const decimals = new BigNumber(await token.decimals());
|
||||
|
||||
const totalLiquidity = new BigNumber(data.availableLiquidity.toString())
|
||||
.plus(data.totalBorrowsStable.toString())
|
||||
.plus(data.totalBorrowsVariable.toString());
|
||||
.plus(data.totalStableDebt.toString())
|
||||
.plus(data.totalVariableDebt.toString());
|
||||
|
||||
const utilizationRate = new BigNumber(
|
||||
totalLiquidity.eq(0)
|
||||
? 0
|
||||
: new BigNumber(data.totalBorrowsStable.toString())
|
||||
.plus(data.totalBorrowsVariable.toString())
|
||||
: new BigNumber(data.totalStableDebt.toString())
|
||||
.plus(data.totalVariableDebt.toString())
|
||||
.rayDiv(totalLiquidity)
|
||||
);
|
||||
|
||||
|
@ -41,8 +41,8 @@ export const getReserveData = async (
|
|||
totalLiquidity,
|
||||
utilizationRate,
|
||||
availableLiquidity: new BigNumber(data.availableLiquidity.toString()),
|
||||
totalBorrowsStable: new BigNumber(data.totalBorrowsStable.toString()),
|
||||
totalBorrowsVariable: new BigNumber(data.totalBorrowsVariable.toString()),
|
||||
totalStableDebt: new BigNumber(data.totalStableDebt.toString()),
|
||||
totalVariableDebt: new BigNumber(data.totalVariableDebt.toString()),
|
||||
liquidityRate: new BigNumber(data.liquidityRate.toString()),
|
||||
variableBorrowRate: new BigNumber(data.variableBorrowRate.toString()),
|
||||
stableBorrowRate: new BigNumber(data.stableBorrowRate.toString()),
|
||||
|
|
|
@ -21,8 +21,8 @@ export interface ReserveData {
|
|||
decimals: BigNumber;
|
||||
totalLiquidity: BigNumber;
|
||||
availableLiquidity: BigNumber;
|
||||
totalBorrowsStable: BigNumber;
|
||||
totalBorrowsVariable: BigNumber;
|
||||
totalStableDebt: BigNumber;
|
||||
totalVariableDebt: BigNumber;
|
||||
averageStableBorrowRate: BigNumber;
|
||||
variableBorrowRate: BigNumber;
|
||||
stableBorrowRate: BigNumber;
|
||||
|
|
Loading…
Reference in New Issue
Block a user