Fixed rebalance tests

This commit is contained in:
The3D 2020-07-07 13:57:08 +02:00
parent dd1982010c
commit d68261c1bc
3 changed files with 17 additions and 7 deletions

View File

@ -351,9 +351,6 @@ export const borrow = async (
txCost
);
console.log(userDataAfter.stableBorrowRate.toFixed(), expectedUserData.stableBorrowRate.toFixed());
console.log(userDataAfter.principalStableBorrowBalance.toFixed(), expectedUserData.principalStableBorrowBalance.toFixed());
expectEqual(reserveDataAfter, expectedReserveData);
expectEqual(userDataAfter, expectedUserData);

View File

@ -953,14 +953,25 @@ export const calcExpectedReserveDataAfterStableRateRebalance = (
expectedReserveData.availableLiquidity = reserveDataBeforeAction.availableLiquidity;
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
//removing the stable liquidity at the old rate
const avgRateBefore = calcExpectedAverageStableBorrowRate(
reserveDataBeforeAction.averageStableBorrowRate,
reserveDataBeforeAction.totalBorrowsStable,
debtAccrued,
reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued),
stableBorrowBalance.negated(),
userDataBeforeAction.stableBorrowRate
);
// adding it again at the new rate
expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate(
avgRateBefore,
reserveDataBeforeAction.totalBorrowsStable.minus(userDataBeforeAction.principalStableBorrowBalance),
stableBorrowBalance,
reserveDataBeforeAction.stableBorrowRate
);
expectedReserveData.totalBorrowsVariable = reserveDataBeforeAction.totalBorrowsVariable;
expectedReserveData.totalBorrowsStable = reserveDataBeforeAction.totalBorrowsStable.plus(debtAccrued);
expectedReserveData.utilizationRate = calcExpectedUtilizationRate(
expectedReserveData.totalBorrowsStable,
@ -1013,6 +1024,8 @@ export const calcExpectedUserDataAfterStableRateRebalance = (
txTimestamp
);
expectedUserData.stableRateLastUpdated = txTimestamp;
expectedUserData.principalVariableBorrowBalance =
userDataBeforeAction.principalVariableBorrowBalance;

View File

@ -12,7 +12,7 @@ BigNumber.config({DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN});
const scenarioFolder = './test/helpers/scenarios/';
const selectedScenarios: string[] = ['swap-rate-mode.json'];
const selectedScenarios: string[] = ['rebalance-stable-rate.json'];
fs.readdirSync(scenarioFolder).forEach((file) => {
if (selectedScenarios.length > 0 && !selectedScenarios.includes(file)) return;