Fixed credit delegation tests

This commit is contained in:
The3D 2020-09-21 15:35:22 +02:00
parent a1a45d392a
commit 6f9ff11e49
3 changed files with 37 additions and 23 deletions

View File

@ -47,7 +47,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 public constant UINT_MAX_VALUE = uint256(-1); uint256 public constant UINT_MAX_VALUE = uint256(-1);
uint256 public constant LENDINGPOOL_REVISION = 0x2; uint256 public constant LENDINGPOOL_REVISION = 0x2;
/** /**
* @dev only lending pools configurator can use functions affected by this modifier * @dev only lending pools configurator can use functions affected by this modifier
**/ **/
@ -68,7 +67,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
function whenNotPaused() internal view { function whenNotPaused() internal view {
require(!_paused, Errors.IS_PAUSED); require(!_paused, Errors.IS_PAUSED);
} }
function getRevision() internal override pure returns (uint256) { function getRevision() internal override pure returns (uint256) {
return LENDINGPOOL_REVISION; return LENDINGPOOL_REVISION;
} }
@ -248,9 +247,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 rateMode, uint256 rateMode,
address onBehalfOf address onBehalfOf
) external override { ) external override {
whenNotPaused(); whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset]; ReserveLogic.ReserveData storage reserve = _reserves[asset];
(uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(onBehalfOf, reserve); (uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(onBehalfOf, reserve);
@ -281,7 +279,11 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (interestRateMode == ReserveLogic.InterestRateMode.STABLE) { if (interestRateMode == ReserveLogic.InterestRateMode.STABLE) {
IStableDebtToken(reserve.stableDebtTokenAddress).burn(onBehalfOf, paybackAmount); IStableDebtToken(reserve.stableDebtTokenAddress).burn(onBehalfOf, paybackAmount);
} else { } else {
IVariableDebtToken(reserve.variableDebtTokenAddress).burn(onBehalfOf, paybackAmount, reserve.variableBorrowIndex); IVariableDebtToken(reserve.variableDebtTokenAddress).burn(
onBehalfOf,
paybackAmount,
reserve.variableBorrowIndex
);
} }
address aToken = reserve.aTokenAddress; address aToken = reserve.aTokenAddress;
@ -322,10 +324,18 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (interestRateMode == ReserveLogic.InterestRateMode.STABLE) { if (interestRateMode == ReserveLogic.InterestRateMode.STABLE) {
//burn stable rate tokens, mint variable rate tokens //burn stable rate tokens, mint variable rate tokens
IStableDebtToken(reserve.stableDebtTokenAddress).burn(msg.sender, stableDebt); IStableDebtToken(reserve.stableDebtTokenAddress).burn(msg.sender, stableDebt);
IVariableDebtToken(reserve.variableDebtTokenAddress).mint(msg.sender, stableDebt, reserve.variableBorrowIndex); IVariableDebtToken(reserve.variableDebtTokenAddress).mint(
msg.sender,
stableDebt,
reserve.variableBorrowIndex
);
} else { } else {
//do the opposite //do the opposite
IVariableDebtToken(reserve.variableDebtTokenAddress).burn(msg.sender, variableDebt, reserve.variableBorrowIndex); IVariableDebtToken(reserve.variableDebtTokenAddress).burn(
msg.sender,
variableDebt,
reserve.variableBorrowIndex
);
IStableDebtToken(reserve.stableDebtTokenAddress).mint( IStableDebtToken(reserve.stableDebtTokenAddress).mint(
msg.sender, msg.sender,
variableDebt, variableDebt,
@ -372,7 +382,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
Errors.INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET Errors.INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET
); );
reserve.updateState(); reserve.updateState();
//burn old debt tokens, mint new ones //burn old debt tokens, mint new ones
@ -502,7 +511,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_flashLiquidationLocked = false; _flashLiquidationLocked = false;
} }
struct FlashLoanLocalVars { struct FlashLoanLocalVars {
uint256 premium; uint256 premium;
uint256 amountPlusPremium; uint256 amountPlusPremium;
IFlashLoanReceiver receiver; IFlashLoanReceiver receiver;
@ -883,9 +892,17 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
) { ) {
currentStableRate = reserve.currentStableBorrowRate; currentStableRate = reserve.currentStableBorrowRate;
IStableDebtToken(reserve.stableDebtTokenAddress).mint(vars.user, vars.amount, currentStableRate); IStableDebtToken(reserve.stableDebtTokenAddress).mint(
vars.onBehalfOf,
vars.amount,
currentStableRate
);
} else { } else {
IVariableDebtToken(reserve.variableDebtTokenAddress).mint(vars.user, vars.amount, reserve.variableBorrowIndex); IVariableDebtToken(reserve.variableDebtTokenAddress).mint(
vars.onBehalfOf,
vars.amount,
reserve.variableBorrowIndex
);
} }
reserve.updateInterestRates( reserve.updateInterestRates(

View File

@ -369,9 +369,7 @@ export const borrow = async (
expectedReserveData, expectedReserveData,
userDataBefore, userDataBefore,
txTimestamp, txTimestamp,
timestamp, timestamp
onBehalfOf,
user.address
); );
console.log("total debt stable exp ", expectedReserveData.totalStableDebt.toFixed()); console.log("total debt stable exp ", expectedReserveData.totalStableDebt.toFixed());
@ -381,10 +379,13 @@ export const borrow = async (
console.log("total debt variable act ", reserveDataAfter.totalVariableDebt.toFixed()); console.log("total debt variable act ", reserveDataAfter.totalVariableDebt.toFixed());
console.log("avl liquidity exp ", expectedReserveData.availableLiquidity.toFixed()); console.log("avl liquidity exp ", expectedReserveData.availableLiquidity.toFixed());
console.log("avl liquidity exp ", reserveDataAfter.availableLiquidity.toFixed()); console.log("avl liquidity act ", reserveDataAfter.availableLiquidity.toFixed());
console.log("avg borrow rate exp ", expectedReserveData.averageStableBorrowRate.toFixed()); console.log("avg borrow rate exp ", expectedReserveData.averageStableBorrowRate.toFixed());
console.log("avl borrow rate exp ", reserveDataAfter.averageStableBorrowRate.toFixed()); console.log("avl borrow rate act ", reserveDataAfter.averageStableBorrowRate.toFixed());
console.log("liquidity rate exp ", expectedReserveData.averageStableBorrowRate.toFixed());
console.log("avl borrow rate act ", reserveDataAfter.averageStableBorrowRate.toFixed());
expectEqual(reserveDataAfter, expectedReserveData); expectEqual(reserveDataAfter, expectedReserveData);
@ -487,8 +488,7 @@ export const repay = async (
user.address, user.address,
onBehalfOf.address, onBehalfOf.address,
txTimestamp, txTimestamp,
timestamp, timestamp
txCost
); );
expectEqual(reserveDataAfter, expectedReserveData); expectEqual(reserveDataAfter, expectedReserveData);

View File

@ -597,9 +597,7 @@ export const calcExpectedUserDataAfterBorrow = (
expectedDataAfterAction: ReserveData, expectedDataAfterAction: ReserveData,
userDataBeforeAction: UserReserveData, userDataBeforeAction: UserReserveData,
txTimestamp: BigNumber, txTimestamp: BigNumber,
currentTimestamp: BigNumber, currentTimestamp: BigNumber
user: tEthereumAddress,
onBehalfOf: tEthereumAddress
): UserReserveData => { ): UserReserveData => {
const expectedUserData = <UserReserveData>{}; const expectedUserData = <UserReserveData>{};
@ -682,8 +680,7 @@ export const calcExpectedUserDataAfterRepay = (
user: string, user: string,
onBehalfOf: string, onBehalfOf: string,
txTimestamp: BigNumber, txTimestamp: BigNumber,
currentTimestamp: BigNumber, currentTimestamp: BigNumber
txCost: BigNumber
): UserReserveData => { ): UserReserveData => {
const expectedUserData = <UserReserveData>{}; const expectedUserData = <UserReserveData>{};