Fixed tests code

This commit is contained in:
The3D 2020-10-12 20:07:17 +02:00
parent fb9f981efa
commit aea61d57ab
17 changed files with 293 additions and 216 deletions

View File

@ -82,7 +82,7 @@ contract AaveProtocolTestHelpers {
(isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled) = configuration (isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled) = configuration
.getFlagsMemory(); .getFlagsMemory();
usageAsCollateralEnabled = liquidationThreshold == 0; usageAsCollateralEnabled = liquidationThreshold > 0;
} }
function getReserveData(address asset) function getReserveData(address asset)
@ -151,4 +151,23 @@ contract AaveProtocolTestHelpers {
); );
usageAsCollateralEnabled = userConfig.isUsingAsCollateral(reserve.id); usageAsCollateralEnabled = userConfig.isUsingAsCollateral(reserve.id);
} }
function getReserveTokensAddresses(address asset)
external
view
returns (
address aTokenAddress,
address stableDebtTokenAddress,
address variableDebtTokenAddress
)
{
ReserveLogic.ReserveData memory reserve = ILendingPool(ADDRESSES_PROVIDER.getLendingPool())
.getReserveData(asset);
return (
reserve.aTokenAddress,
reserve.stableDebtTokenAddress,
reserve.variableDebtTokenAddress
);
}
} }

View File

@ -145,7 +145,7 @@
}, },
"DefaultReserveInterestRateStrategy": { "DefaultReserveInterestRateStrategy": {
"buidlerevm": { "buidlerevm": {
"address": "0x626FdE749F9d499d3777320CAf29484B624ab84a", "address": "0xB660Fdd109a95718cB9d20E3A89EE6cE342aDcB6",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
@ -204,7 +204,7 @@
}, },
"MockFlashLoanReceiver": { "MockFlashLoanReceiver": {
"buidlerevm": { "buidlerevm": {
"address": "0x2B681757d757fbB80cc51c6094cEF5eE75bF55aA" "address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2"
}, },
"localhost": { "localhost": {
"address": "0x2B681757d757fbB80cc51c6094cEF5eE75bF55aA" "address": "0x2B681757d757fbB80cc51c6094cEF5eE75bF55aA"
@ -215,7 +215,7 @@
}, },
"WalletBalanceProvider": { "WalletBalanceProvider": {
"buidlerevm": { "buidlerevm": {
"address": "0xDf73fC454FA018051D4a1509e63D11530A59DE10", "address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
@ -551,7 +551,7 @@
}, },
"AaveProtocolTestHelpers": { "AaveProtocolTestHelpers": {
"buidlerevm": { "buidlerevm": {
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4" "address": "0xe7536f450378748E1BD4645D3c77ec38e0F3ba28"
}, },
"localhost": { "localhost": {
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4" "address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
@ -562,7 +562,7 @@
}, },
"StableDebtToken": { "StableDebtToken": {
"buidlerevm": { "buidlerevm": {
"address": "0xB660Fdd109a95718cB9d20E3A89EE6cE342aDcB6", "address": "0x830bceA96E56DBC1F8578f75fBaC0AF16B32A07d",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
@ -576,7 +576,7 @@
}, },
"VariableDebtToken": { "VariableDebtToken": {
"buidlerevm": { "buidlerevm": {
"address": "0x830bceA96E56DBC1F8578f75fBaC0AF16B32A07d", "address": "0xA0AB1cB92A4AF81f84dCd258155B5c25D247b54E",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"localhost": { "localhost": {
@ -594,7 +594,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"buidlerevm": { "buidlerevm": {
"address": "0xA0AB1cB92A4AF81f84dCd258155B5c25D247b54E", "address": "0x5f7134cd38C826a7649f9Cc47dda24d834DD2967",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}, },
"coverage": { "coverage": {
@ -660,7 +660,7 @@
}, },
"MockSwapAdapter": { "MockSwapAdapter": {
"buidlerevm": { "buidlerevm": {
"address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2" "address": "0xDf73fC454FA018051D4a1509e63D11530A59DE10"
}, },
"coverage": { "coverage": {
"address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2" "address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2"

View File

@ -57,6 +57,7 @@ import {LendingPoolConfigurator} from '../types/LendingPoolConfigurator';
import {initializeMakeSuite} from './helpers/make-suite'; import {initializeMakeSuite} from './helpers/make-suite';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import {AaveProtocolTestHelpers} from '../types/AaveProtocolTestHelpers';
['misc'].forEach((folder) => { ['misc'].forEach((folder) => {
const tasksPath = path.join(__dirname, '../', 'tasks', folder); const tasksPath = path.join(__dirname, '../', 'tasks', folder);
@ -175,6 +176,7 @@ const initReserves = async (
lendingPoolAddressesProvider: LendingPoolAddressesProvider, lendingPoolAddressesProvider: LendingPoolAddressesProvider,
lendingPool: LendingPool, lendingPool: LendingPool,
lendingPoolConfigurator: LendingPoolConfigurator, lendingPoolConfigurator: LendingPoolConfigurator,
helpersContract: AaveProtocolTestHelpers,
aavePool: AavePools, aavePool: AavePools,
incentivesController: tEthereumAddress incentivesController: tEthereumAddress
) => { ) => {
@ -194,7 +196,7 @@ const initReserves = async (
assetAddressIndex assetAddressIndex
]; ];
const {isActive: reserveInitialized} = await lendingPool.getReserveConfigurationData( const {isActive: reserveInitialized} = await helpersContract.getReserveConfigurationData(
tokenAddress tokenAddress
); );
@ -276,7 +278,7 @@ const initReserves = async (
const enableReservesToBorrow = async ( const enableReservesToBorrow = async (
reservesParams: iMultiPoolsAssets<IReserveParams>, reservesParams: iMultiPoolsAssets<IReserveParams>,
tokenAddresses: {[symbol: string]: tEthereumAddress}, tokenAddresses: {[symbol: string]: tEthereumAddress},
lendingPool: LendingPool, helpersContract: AaveProtocolTestHelpers,
lendingPoolConfigurator: LendingPoolConfigurator lendingPoolConfigurator: LendingPoolConfigurator
) => { ) => {
for (const [assetSymbol, {borrowingEnabled, stableBorrowRateEnabled}] of Object.entries( for (const [assetSymbol, {borrowingEnabled, stableBorrowRateEnabled}] of Object.entries(
@ -292,7 +294,7 @@ const enableReservesToBorrow = async (
]; ];
const { const {
borrowingEnabled: borrowingAlreadyEnabled, borrowingEnabled: borrowingAlreadyEnabled,
} = await lendingPool.getReserveConfigurationData(tokenAddress); } = await helpersContract.getReserveConfigurationData(tokenAddress);
if (borrowingAlreadyEnabled) { if (borrowingAlreadyEnabled) {
console.log(`Reserve ${assetSymbol} is already enabled for borrowing, skipping`); console.log(`Reserve ${assetSymbol} is already enabled for borrowing, skipping`);
@ -311,7 +313,7 @@ const enableReservesToBorrow = async (
const enableReservesAsCollateral = async ( const enableReservesAsCollateral = async (
reservesParams: iMultiPoolsAssets<IReserveParams>, reservesParams: iMultiPoolsAssets<IReserveParams>,
tokenAddresses: {[symbol: string]: tEthereumAddress}, tokenAddresses: {[symbol: string]: tEthereumAddress},
lendingPool: LendingPool, helpersContract: AaveProtocolTestHelpers,
lendingPoolConfigurator: LendingPoolConfigurator lendingPoolConfigurator: LendingPoolConfigurator
) => { ) => {
for (const [ for (const [
@ -328,7 +330,7 @@ const enableReservesAsCollateral = async (
]; ];
const { const {
usageAsCollateralEnabled: alreadyEnabled, usageAsCollateralEnabled: alreadyEnabled,
} = await lendingPool.getReserveConfigurationData(tokenAddress); } = await helpersContract.getReserveConfigurationData(tokenAddress);
if (alreadyEnabled) { if (alreadyEnabled) {
console.log(`Reserve ${assetSymbol} is already enabled as collateral, skipping`); console.log(`Reserve ${assetSymbol} is already enabled as collateral, skipping`);
@ -479,6 +481,10 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const reservesParams = getReservesConfigByPool(AavePools.proto); const reservesParams = getReservesConfigByPool(AavePools.proto);
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address);
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
console.log('Initialize configuration'); console.log('Initialize configuration');
await initReserves( await initReserves(
reservesParams, reservesParams,
@ -486,19 +492,20 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
addressesProvider, addressesProvider,
lendingPoolProxy, lendingPoolProxy,
lendingPoolConfiguratorProxy, lendingPoolConfiguratorProxy,
testHelpers,
AavePools.proto, AavePools.proto,
ZERO_ADDRESS ZERO_ADDRESS
); );
await enableReservesToBorrow( await enableReservesToBorrow(
reservesParams, reservesParams,
protoPoolReservesAddresses, protoPoolReservesAddresses,
lendingPoolProxy, testHelpers,
lendingPoolConfiguratorProxy lendingPoolConfiguratorProxy
); );
await enableReservesAsCollateral( await enableReservesAsCollateral(
reservesParams, reservesParams,
protoPoolReservesAddresses, protoPoolReservesAddresses,
lendingPoolProxy, testHelpers,
lendingPoolConfiguratorProxy lendingPoolConfiguratorProxy
); );
@ -515,10 +522,6 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
await deployWalletBalancerProvider(addressesProvider.address); await deployWalletBalancerProvider(addressesProvider.address);
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address);
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
console.timeEnd('setup'); console.timeEnd('setup');
}; };

View File

@ -115,7 +115,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
}); });
it('User tries to swap correct amount', async () => { it('User tries to swap correct amount', async () => {
const {pool, weth, dai, aEth, aDai} = testEnv; const {pool, weth, dai, aEth, aDai, helpersContract} = testEnv;
const userAddress = await pool.signer.getAddress(); const userAddress = await pool.signer.getAddress();
const amountToSwap = ethers.utils.parseEther('0.25'); const amountToSwap = ethers.utils.parseEther('0.25');
@ -174,7 +174,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
'was received incorrect amount if reserve funds' 'was received incorrect amount if reserve funds'
); );
expect( expect(
(await pool.getUserReserveData(dai.address, userAddress)).usageAsCollateralEnabled (await helpersContract.getUserReserveData(dai.address, userAddress)).usageAsCollateralEnabled
).to.be.equal(true, 'usage as collateral was not enabled on destination reserve for the user'); ).to.be.equal(true, 'usage as collateral was not enabled on destination reserve for the user');
}); });

View File

@ -9,17 +9,17 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {CALLER_NOT_AAVE_ADMIN, RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors; const {CALLER_NOT_AAVE_ADMIN, RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors;
it('Deactivates the ETH reserve', async () => { it('Deactivates the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, weth, helpersContract} = testEnv;
await configurator.deactivateReserve(weth.address); await configurator.deactivateReserve(weth.address);
const {isActive} = await pool.getReserveConfigurationData(weth.address); const {isActive} = await helpersContract.getReserveConfigurationData(weth.address);
expect(isActive).to.be.equal(false); expect(isActive).to.be.equal(false);
}); });
it('Rectivates the ETH reserve', async () => { it('Rectivates the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, weth, helpersContract} = testEnv;
await configurator.activateReserve(weth.address); await configurator.activateReserve(weth.address);
const {isActive} = await pool.getReserveConfigurationData(weth.address); const {isActive} = await helpersContract.getReserveConfigurationData(weth.address);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
}); });
@ -40,7 +40,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Freezes the ETH reserve', async () => { it('Freezes the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, pool, weth, helpersContract} = testEnv;
await configurator.freezeReserve(weth.address); await configurator.freezeReserve(weth.address);
const { const {
decimals, decimals,
@ -51,12 +51,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(true); expect(isFrozen).to.be.equal(true);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(7500); expect(ltv).to.be.equal(7500);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -66,7 +66,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Unfreezes the ETH reserve', async () => { it('Unfreezes the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.unfreezeReserve(weth.address); await configurator.unfreezeReserve(weth.address);
const { const {
@ -78,12 +78,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(7500); expect(ltv).to.be.equal(7500);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -109,7 +109,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Deactivates the ETH reserve for borrowing', async () => { it('Deactivates the ETH reserve for borrowing', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.disableBorrowingOnReserve(weth.address); await configurator.disableBorrowingOnReserve(weth.address);
const { const {
decimals, decimals,
@ -120,12 +120,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(false); expect(borrowingEnabled).to.be.equal(false);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(7500); expect(ltv).to.be.equal(7500);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -135,9 +135,9 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Activates the ETH reserve for borrowing', async () => { it('Activates the ETH reserve for borrowing', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, weth, helpersContract} = testEnv;
await configurator.enableBorrowingOnReserve(weth.address, true); await configurator.enableBorrowingOnReserve(weth.address, true);
const {variableBorrowIndex} = await pool.getReserveData(weth.address); const {variableBorrowIndex} = await helpersContract.getReserveData(weth.address);
const { const {
decimals, decimals,
@ -148,12 +148,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(7500); expect(ltv).to.be.equal(7500);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -181,7 +181,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Deactivates the ETH reserve as collateral', async () => { it('Deactivates the ETH reserve as collateral', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.disableReserveAsCollateral(weth.address); await configurator.disableReserveAsCollateral(weth.address);
const { const {
decimals, decimals,
@ -192,12 +192,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(0); expect(ltv).to.be.equal(0);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -207,7 +207,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Activates the ETH reserve as collateral', async () => { it('Activates the ETH reserve as collateral', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.enableReserveAsCollateral(weth.address, '7500', '8000', '10500'); await configurator.enableReserveAsCollateral(weth.address, '7500', '8000', '10500');
const { const {
@ -219,12 +219,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(7500); expect(ltv).to.be.equal(7500);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -252,7 +252,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Disable stable borrow rate on the ETH reserve', async () => { it('Disable stable borrow rate on the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.disableReserveStableRate(weth.address); await configurator.disableReserveStableRate(weth.address);
const { const {
decimals, decimals,
@ -263,12 +263,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(7500); expect(ltv).to.be.equal(7500);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -278,7 +278,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Enables stable borrow rate on the ETH reserve', async () => { it('Enables stable borrow rate on the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.enableReserveStableRate(weth.address); await configurator.enableReserveStableRate(weth.address);
const { const {
decimals, decimals,
@ -289,12 +289,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(7500); expect(ltv).to.be.equal(7500);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -320,7 +320,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Changes LTV of the reserve', async () => { it('Changes LTV of the reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.setLtv(weth.address, '6000'); await configurator.setLtv(weth.address, '6000');
const { const {
decimals, decimals,
@ -331,12 +331,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(6000); expect(ltv).to.be.equal(6000);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -354,7 +354,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Changes the reserve factor of the reserve', async () => { it('Changes the reserve factor of the reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.setReserveFactor(weth.address, '1000'); await configurator.setReserveFactor(weth.address, '1000');
const { const {
decimals, decimals,
@ -365,12 +365,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(6000); expect(ltv).to.be.equal(6000);
expect(liquidationThreshold).to.be.equal(8000); expect(liquidationThreshold).to.be.equal(8000);
@ -388,7 +388,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Changes liquidation threshold of the reserve', async () => { it('Changes liquidation threshold of the reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.setLiquidationThreshold(weth.address, '7500'); await configurator.setLiquidationThreshold(weth.address, '7500');
const { const {
decimals, decimals,
@ -399,12 +399,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(6000); expect(ltv).to.be.equal(6000);
expect(liquidationThreshold).to.be.equal(7500); expect(liquidationThreshold).to.be.equal(7500);
@ -422,7 +422,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
}); });
it('Changes liquidation bonus of the reserve', async () => { it('Changes liquidation bonus of the reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, helpersContract, weth} = testEnv;
await configurator.setLiquidationBonus(weth.address, '11000'); await configurator.setLiquidationBonus(weth.address, '11000');
const { const {
decimals, decimals,
@ -433,12 +433,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
isActive, isActive,
isFreezed, isFrozen,
} = await pool.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true); expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true); expect(isActive).to.be.equal(true);
expect(isFreezed).to.be.equal(false); expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(18); expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(6000); expect(ltv).to.be.equal(6000);
expect(liquidationThreshold).to.be.equal(7500); expect(liquidationThreshold).to.be.equal(7500);

View File

@ -34,7 +34,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
}); });
it('User 5 liquidate User 3 collateral, all his variable debt and part of the stable', async () => { it('User 5 liquidate User 3 collateral, all his variable debt and part of the stable', async () => {
const {pool, weth, usdc, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, usdc, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[2]; const user = users[2];
const liquidator = users[4]; const liquidator = users[4];
const amountToDeposit = parseEther('20'); const amountToDeposit = parseEther('20');
@ -103,10 +103,10 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -209,7 +209,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
}); });
it('User 5 liquidates half the USDC loan of User 3 by swapping his WETH collateral', async () => { it('User 5 liquidates half the USDC loan of User 3 by swapping his WETH collateral', async () => {
const {pool, weth, usdc, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, usdc, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[2]; const user = users[2];
const liquidator = users[4]; const liquidator = users[4];
// Sets USDC Price higher to decrease health factor below 1 // Sets USDC Price higher to decrease health factor below 1
@ -268,10 +268,10 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -344,7 +344,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
}); });
it('User 5 liquidates all the USDC loan of User 3 by swapping his WETH collateral', async () => { it('User 5 liquidates all the USDC loan of User 3 by swapping his WETH collateral', async () => {
const {pool, weth, usdc, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, usdc, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[2]; const user = users[2];
const liquidator = users[4]; const liquidator = users[4];
// Sets USDC Price higher to decrease health factor below 1 // Sets USDC Price higher to decrease health factor below 1
@ -403,10 +403,10 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -541,7 +541,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
).to.be.revertedWith('38'); ).to.be.revertedWith('38');
}); });
it('User 5 liquidates User 2 DAI Variable loan using his WETH collateral, half the amount', async () => { it('User 5 liquidates User 2 DAI Variable loan using his WETH collateral, half the amount', async () => {
const {pool, weth, dai, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, dai, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[1]; const user = users[1];
const liquidator = users[4]; const liquidator = users[4];
@ -570,7 +570,10 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
); );
// First half // First half
const amountToRepay = daiReserveDataBefore.totalVariableDebt.multipliedBy(0.6).toFixed(0).toString(); const amountToRepay = daiReserveDataBefore.totalVariableDebt
.multipliedBy(0.6)
.toFixed(0)
.toString();
await mockSwapAdapter.setAmountToReturn(amountToRepay); await mockSwapAdapter.setAmountToReturn(amountToRepay);
await waitForTx( await waitForTx(
@ -599,10 +602,10 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
const principalPrice = await oracle.getAssetPrice(dai.address); const principalPrice = await oracle.getAssetPrice(dai.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(dai.address) await helpersContract.getReserveConfigurationData(dai.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -639,7 +642,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
}); });
it('User 2 tries to repay remaining DAI Variable loan using his WETH collateral', async () => { it('User 2 tries to repay remaining DAI Variable loan using his WETH collateral', async () => {
const {pool, weth, dai, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, dai, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[1]; const user = users[1];
const {userData: wethUserDataBefore} = await getContractsData( const {userData: wethUserDataBefore} = await getContractsData(
@ -686,10 +689,10 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
const principalPrice = await oracle.getAssetPrice(dai.address); const principalPrice = await oracle.getAssetPrice(dai.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(dai.address) await helpersContract.getReserveConfigurationData(dai.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -722,7 +725,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
}); });
it('Liquidator tries to repay 4 user a bigger amount that what can be swapped of a particular collateral, repaying only the maximum allowed by that collateral', async () => { it('Liquidator tries to repay 4 user a bigger amount that what can be swapped of a particular collateral, repaying only the maximum allowed by that collateral', async () => {
const {pool, weth, dai, usdc, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, dai, usdc, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[3]; const user = users[3];
const liquidator = users[5]; const liquidator = users[5];
@ -795,11 +798,11 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
const collateralPrice = await oracle.getAssetPrice(weth.address); const collateralPrice = await oracle.getAssetPrice(weth.address);
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralConfig = await pool.getReserveConfigurationData(weth.address); const collateralConfig = await helpersContract.getReserveConfigurationData(weth.address);
const collateralDecimals = collateralConfig.decimals.toString(); const collateralDecimals = collateralConfig.decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const collateralLiquidationBonus = collateralConfig.liquidationBonus.toString(); const collateralLiquidationBonus = collateralConfig.liquidationBonus.toString();
@ -879,9 +882,9 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
const daiPrice = await oracle.getAssetPrice(dai.address); const daiPrice = await oracle.getAssetPrice(dai.address);
await oracle.setAssetPrice( await oracle.setAssetPrice(
dai.address, dai.address,
new BigNumber(daiPrice.toString()).multipliedBy(0.9).toFixed(0) new BigNumber(daiPrice.toString()).multipliedBy(0.9).toFixed(0)
); );
// Liquidator should NOT be able to liquidate himself with WETH, even if is disabled // Liquidator should NOT be able to liquidate himself with WETH, even if is disabled
await mockSwapAdapter.setAmountToReturn(amountToRepay); await mockSwapAdapter.setAmountToReturn(amountToRepay);

View File

@ -43,7 +43,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
}); });
it('Takes WETH flashloan with mode = 0, returns the funds correctly', async () => { it('Takes WETH flashloan with mode = 0, returns the funds correctly', async () => {
const {pool, deployer, weth} = testEnv; const {pool, helpersContract, weth} = testEnv;
await pool.flashLoan( await pool.flashLoan(
_mockFlashLoanReceiver.address, _mockFlashLoanReceiver.address,
@ -56,7 +56,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
ethers.utils.parseUnits('10000'); ethers.utils.parseUnits('10000');
const reserveData = await pool.getReserveData(weth.address); const reserveData = await helpersContract.getReserveData(weth.address);
const currentLiquidityRate = reserveData.liquidityRate; const currentLiquidityRate = reserveData.liquidityRate;
const currentLiquidityIndex = reserveData.liquidityIndex; const currentLiquidityIndex = reserveData.liquidityIndex;
@ -71,9 +71,9 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
}); });
it('Takes an ETH flashloan with mode = 0 as big as the available liquidity', async () => { it('Takes an ETH flashloan with mode = 0 as big as the available liquidity', async () => {
const {pool, weth} = testEnv; const {pool, helpersContract, weth} = testEnv;
const reserveDataBefore = await pool.getReserveData(weth.address); const reserveDataBefore = await helpersContract.getReserveData(weth.address);
const txResult = await pool.flashLoan( const txResult = await pool.flashLoan(
_mockFlashLoanReceiver.address, _mockFlashLoanReceiver.address,
weth.address, weth.address,
@ -83,7 +83,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0' '0'
); );
const reserveData = await pool.getReserveData(weth.address); const reserveData = await helpersContract.getReserveData(weth.address);
const currentLiqudityRate = reserveData.liquidityRate; const currentLiqudityRate = reserveData.liquidityRate;
const currentLiquidityIndex = reserveData.liquidityIndex; const currentLiquidityIndex = reserveData.liquidityIndex;
@ -136,7 +136,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
}); });
it('Caller deposits 1000 DAI as collateral, Takes WETH flashloan with mode = 2, does not return the funds. A variable loan for caller is created', async () => { it('Caller deposits 1000 DAI as collateral, Takes WETH flashloan with mode = 2, does not return the funds. A variable loan for caller is created', async () => {
const {dai, pool, weth, users} = testEnv; const {dai, pool, weth, users, helpersContract} = testEnv;
const caller = users[1]; const caller = users[1];
@ -160,7 +160,9 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0x10', '0x10',
'0' '0'
); );
const {variableDebtTokenAddress} = await pool.getReserveTokensAddresses(weth.address); const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
weth.address
);
const wethDebtToken = await getContract<VariableDebtToken>( const wethDebtToken = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken, eContractid.VariableDebtToken,
@ -225,7 +227,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
}); });
it('Takes out a 500 USDC flashloan, returns the funds correctly', async () => { it('Takes out a 500 USDC flashloan, returns the funds correctly', async () => {
const {usdc, pool, deployer: depositor} = testEnv; const {usdc, pool, helpersContract, deployer: depositor} = testEnv;
await _mockFlashLoanReceiver.setFailExecutionTransfer(false); await _mockFlashLoanReceiver.setFailExecutionTransfer(false);
@ -240,8 +242,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0' '0'
); );
const reserveData = await pool.getReserveData(usdc.address); const reserveData = await helpersContract.getReserveData(usdc.address);
const userData = await pool.getUserReserveData(usdc.address, depositor.address); const userData = await helpersContract.getUserReserveData(usdc.address, depositor.address);
const totalLiquidity = reserveData.availableLiquidity const totalLiquidity = reserveData.availableLiquidity
.add(reserveData.totalStableDebt) .add(reserveData.totalStableDebt)
@ -278,7 +280,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
}); });
it('Caller deposits 5 WETH as collateral, Takes a USDC flashloan with mode = 2, does not return the funds. A loan for caller is created', async () => { it('Caller deposits 5 WETH as collateral, Takes a USDC flashloan with mode = 2, does not return the funds. A loan for caller is created', async () => {
const {usdc, pool, weth, users} = testEnv; const {usdc, pool, weth, users, helpersContract} = testEnv;
const caller = users[2]; const caller = users[2];
@ -297,7 +299,9 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
await pool await pool
.connect(caller.signer) .connect(caller.signer)
.flashLoan(_mockFlashLoanReceiver.address, usdc.address, flashloanAmount, 2, '0x10', '0'); .flashLoan(_mockFlashLoanReceiver.address, usdc.address, flashloanAmount, 2, '0x10', '0');
const {variableDebtTokenAddress} = await pool.getReserveTokensAddresses(usdc.address); const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
usdc.address
);
const usdcDebtToken = await getContract<VariableDebtToken>( const usdcDebtToken = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken, eContractid.VariableDebtToken,
@ -334,7 +338,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
}); });
it('Caller takes a WETH flashloan with mode = 1', async () => { it('Caller takes a WETH flashloan with mode = 1', async () => {
const {dai, pool, weth, users} = testEnv; const {dai, pool, weth, users, helpersContract} = testEnv;
const caller = users[3]; const caller = users[3];
@ -346,7 +350,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
.connect(caller.signer) .connect(caller.signer)
.flashLoan(_mockFlashLoanReceiver.address, weth.address, flashAmount, 1, '0x10', '0'); .flashLoan(_mockFlashLoanReceiver.address, weth.address, flashAmount, 1, '0x10', '0');
const {stableDebtTokenAddress} = await pool.getReserveTokensAddresses(weth.address); const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
const wethDebtToken = await getContract<StableDebtToken>( const wethDebtToken = await getContract<StableDebtToken>(
eContractid.VariableDebtToken, eContractid.VariableDebtToken,

View File

@ -32,7 +32,7 @@ import {waitForTx} from '../__setup.spec';
import {ContractReceipt} from 'ethers'; import {ContractReceipt} from 'ethers';
import {AToken} from '../../types/AToken'; import {AToken} from '../../types/AToken';
import {RateMode, tEthereumAddress} from '../../helpers/types'; import {RateMode, tEthereumAddress} from '../../helpers/types';
import { time } from 'console'; import {time} from 'console';
const {expect} = chai; const {expect} = chai;
@ -736,11 +736,11 @@ export const getContractsData = async (
testEnv: TestEnv, testEnv: TestEnv,
sender?: string sender?: string
) => { ) => {
const {pool} = testEnv; const {pool, helpersContract} = testEnv;
const [userData, reserveData, timestamp] = await Promise.all([ const [userData, reserveData, timestamp] = await Promise.all([
getUserData(pool, reserve, user, sender || user), getUserData(pool, helpersContract, reserve, user, sender || user),
getReserveData(pool, reserve), getReserveData(helpersContract, reserve),
timeLatest(), timeLatest(),
]); ]);

View File

@ -9,7 +9,8 @@ import {
getMintableErc20, getMintableErc20,
getLendingPoolConfiguratorProxy, getLendingPoolConfiguratorProxy,
getPriceOracle, getPriceOracle,
getMockSwapAdapter, getLendingPoolAddressesProviderRegistry getMockSwapAdapter,
getLendingPoolAddressesProviderRegistry,
} from '../../helpers/contracts-helpers'; } from '../../helpers/contracts-helpers';
import {tEthereumAddress} from '../../helpers/types'; import {tEthereumAddress} from '../../helpers/types';
import {LendingPool} from '../../types/LendingPool'; import {LendingPool} from '../../types/LendingPool';
@ -24,8 +25,8 @@ import bignumberChai from 'chai-bignumber';
import {almostEqual} from './almost-equal'; import {almostEqual} from './almost-equal';
import {PriceOracle} from '../../types/PriceOracle'; import {PriceOracle} from '../../types/PriceOracle';
import {LendingPoolAddressesProvider} from '../../types/LendingPoolAddressesProvider'; import {LendingPoolAddressesProvider} from '../../types/LendingPoolAddressesProvider';
import { MockSwapAdapter } from '../../types/MockSwapAdapter'; import {MockSwapAdapter} from '../../types/MockSwapAdapter';
import { LendingPoolAddressesProviderRegistry } from '../../types/LendingPoolAddressesProviderRegistry'; import {LendingPoolAddressesProviderRegistry} from '../../types/LendingPoolAddressesProviderRegistry';
chai.use(bignumberChai()); chai.use(bignumberChai());
chai.use(almostEqual()); chai.use(almostEqual());
@ -73,7 +74,7 @@ const testEnv: TestEnv = {
lend: {} as MintableErc20, lend: {} as MintableErc20,
addressesProvider: {} as LendingPoolAddressesProvider, addressesProvider: {} as LendingPoolAddressesProvider,
mockSwapAdapter: {} as MockSwapAdapter, mockSwapAdapter: {} as MockSwapAdapter,
registry: {} as LendingPoolAddressesProviderRegistry registry: {} as LendingPoolAddressesProviderRegistry,
} as TestEnv; } as TestEnv;
export async function initializeMakeSuite() { export async function initializeMakeSuite() {
@ -134,7 +135,7 @@ export async function initializeMakeSuite() {
testEnv.lend = await getMintableErc20(lendAddress); testEnv.lend = await getMintableErc20(lendAddress);
testEnv.weth = await getMintableErc20(wethAddress); testEnv.weth = await getMintableErc20(wethAddress);
testEnv.mockSwapAdapter = await getMockSwapAdapter() testEnv.mockSwapAdapter = await getMockSwapAdapter();
} }
export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) { export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) {

View File

@ -4,19 +4,22 @@ import {
getLendingRateOracle, getLendingRateOracle,
getIErc20Detailed, getIErc20Detailed,
getMintableErc20, getMintableErc20,
getAToken, getStableDebtToken, getVariableDebtToken getAToken,
getStableDebtToken,
getVariableDebtToken,
} from '../../../helpers/contracts-helpers'; } from '../../../helpers/contracts-helpers';
import {tEthereumAddress} from '../../../helpers/types'; import {tEthereumAddress} from '../../../helpers/types';
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import {getDb, BRE} from '../../../helpers/misc-utils'; import {getDb, BRE} from '../../../helpers/misc-utils';
import {AaveProtocolTestHelpers} from '../../../types/AaveProtocolTestHelpers';
export const getReserveData = async ( export const getReserveData = async (
pool: LendingPool, helper: AaveProtocolTestHelpers,
reserve: tEthereumAddress reserve: tEthereumAddress
): Promise<ReserveData> => { ): Promise<ReserveData> => {
const [reserveData, tokenAddresses, rateOracle, token] = await Promise.all([ const [reserveData, tokenAddresses, rateOracle, token] = await Promise.all([
pool.getReserveData(reserve), helper.getReserveData(reserve),
pool.getReserveTokensAddresses(reserve), helper.getReserveTokensAddresses(reserve),
getLendingRateOracle(), getLendingRateOracle(),
getIErc20Detailed(reserve), getIErc20Detailed(reserve),
]); ]);
@ -27,7 +30,6 @@ export const getReserveData = async (
const [principalStableDebt] = await stableDebtToken.getSupplyData(); const [principalStableDebt] = await stableDebtToken.getSupplyData();
const totalStableDebtLastUpdated = await stableDebtToken.getTotalSupplyLastUpdated(); const totalStableDebtLastUpdated = await stableDebtToken.getTotalSupplyLastUpdated();
const scaledVariableDebt = await variableDebtToken.scaledTotalSupply(); const scaledVariableDebt = await variableDebtToken.scaledTotalSupply();
const rate = (await rateOracle.getMarketBorrowRate(reserve)).toString(); const rate = (await rateOracle.getMarketBorrowRate(reserve)).toString();
@ -72,13 +74,14 @@ export const getReserveData = async (
export const getUserData = async ( export const getUserData = async (
pool: LendingPool, pool: LendingPool,
helper: AaveProtocolTestHelpers,
reserve: string, reserve: string,
user: tEthereumAddress, user: tEthereumAddress,
sender?: tEthereumAddress sender?: tEthereumAddress
): Promise<UserReserveData> => { ): Promise<UserReserveData> => {
const [userData, scaledATokenBalance] = await Promise.all([ const [userData, scaledATokenBalance] = await Promise.all([
pool.getUserReserveData(reserve, user), helper.getUserReserveData(reserve, user),
getATokenUserData(reserve, user, pool), getATokenUserData(reserve, user, helper),
]); ]);
const token = await getMintableErc20(reserve); const token = await getMintableErc20(reserve);
@ -110,8 +113,13 @@ export const getReserveAddressFromSymbol = async (symbol: string) => {
return token.address; return token.address;
}; };
const getATokenUserData = async (reserve: string, user: string, pool: LendingPool) => { const getATokenUserData = async (
const aTokenAddress: string = (await pool.getReserveTokensAddresses(reserve)).aTokenAddress; reserve: string,
user: string,
helpersContract: AaveProtocolTestHelpers
) => {
const aTokenAddress: string = (await helpersContract.getReserveTokensAddresses(reserve))
.aTokenAddress;
const aToken = await getAToken(aTokenAddress); const aToken = await getAToken(aTokenAddress);

View File

@ -114,7 +114,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
}); });
it('LIQUIDATION - Liquidates the borrow', async () => { it('LIQUIDATION - Liquidates the borrow', async () => {
const {pool, dai, weth, users, oracle} = testEnv; const {pool, dai, weth, users, oracle, helpersContract} = testEnv;
const borrower = users[1]; const borrower = users[1];
//mints dai to the caller //mints dai to the caller
@ -124,10 +124,15 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
//approve protocol to access depositor wallet //approve protocol to access depositor wallet
await dai.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await dai.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
const daiReserveDataBefore = await getReserveData(pool, dai.address); const daiReserveDataBefore = await getReserveData(helpersContract, dai.address);
const ethReserveDataBefore = await pool.getReserveData(weth.address); const ethReserveDataBefore = await helpersContract.getReserveData(weth.address);
const userReserveDataBefore = await getUserData(pool, dai.address, borrower.address); const userReserveDataBefore = await getUserData(
pool,
helpersContract,
dai.address,
borrower.address
);
const amountToLiquidate = new BigNumber(userReserveDataBefore.currentVariableDebt.toString()) const amountToLiquidate = new BigNumber(userReserveDataBefore.currentVariableDebt.toString())
.div(2) .div(2)
@ -141,21 +146,24 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
true true
); );
const userReserveDataAfter = await pool.getUserReserveData(dai.address, borrower.address); const userReserveDataAfter = await helpersContract.getUserReserveData(
dai.address,
borrower.address
);
const userGlobalDataAfter = await pool.getUserAccountData(borrower.address); const userGlobalDataAfter = await pool.getUserAccountData(borrower.address);
const daiReserveDataAfter = await pool.getReserveData(dai.address); const daiReserveDataAfter = await helpersContract.getReserveData(dai.address);
const ethReserveDataAfter = await pool.getReserveData(weth.address); const ethReserveDataAfter = await helpersContract.getReserveData(weth.address);
const collateralPrice = (await oracle.getAssetPrice(weth.address)).toString(); const collateralPrice = (await oracle.getAssetPrice(weth.address)).toString();
const principalPrice = (await oracle.getAssetPrice(dai.address)).toString(); const principalPrice = (await oracle.getAssetPrice(dai.address)).toString();
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(dai.address) await helpersContract.getReserveConfigurationData(dai.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice) const expectedCollateralLiquidated = new BigNumber(principalPrice)
@ -215,7 +223,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
}); });
it('User 3 deposits 1000 USDC, user 4 1 WETH, user 4 borrows - drops HF, liquidates the borrow', async () => { it('User 3 deposits 1000 USDC, user 4 1 WETH, user 4 borrows - drops HF, liquidates the borrow', async () => {
const {users, pool, usdc, oracle, weth} = testEnv; const {users, pool, usdc, oracle, weth, helpersContract} = testEnv;
const depositor = users[3]; const depositor = users[3];
const borrower = users[4]; const borrower = users[4];
@ -278,10 +286,13 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
//approve protocol to access depositor wallet //approve protocol to access depositor wallet
await usdc.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await usdc.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
const userReserveDataBefore = await pool.getUserReserveData(usdc.address, borrower.address); const userReserveDataBefore = await helpersContract.getUserReserveData(
usdc.address,
borrower.address
);
const usdcReserveDataBefore = await pool.getReserveData(usdc.address); const usdcReserveDataBefore = await helpersContract.getReserveData(usdc.address);
const ethReserveDataBefore = await pool.getReserveData(weth.address); const ethReserveDataBefore = await helpersContract.getReserveData(weth.address);
const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString()) const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString())
.multipliedBy(0.5) .multipliedBy(0.5)
@ -295,21 +306,24 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
true true
); );
const userReserveDataAfter = await pool.getUserReserveData(usdc.address, borrower.address); const userReserveDataAfter = await helpersContract.getUserReserveData(
usdc.address,
borrower.address
);
const userGlobalDataAfter = await pool.getUserAccountData(borrower.address); const userGlobalDataAfter = await pool.getUserAccountData(borrower.address);
const usdcReserveDataAfter = await pool.getReserveData(usdc.address); const usdcReserveDataAfter = await helpersContract.getReserveData(usdc.address);
const ethReserveDataAfter = await pool.getReserveData(weth.address); const ethReserveDataAfter = await helpersContract.getReserveData(weth.address);
const collateralPrice = (await oracle.getAssetPrice(weth.address)).toString(); const collateralPrice = (await oracle.getAssetPrice(weth.address)).toString();
const principalPrice = (await oracle.getAssetPrice(usdc.address)).toString(); const principalPrice = (await oracle.getAssetPrice(usdc.address)).toString();
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice) const expectedCollateralLiquidated = new BigNumber(principalPrice)

View File

@ -119,7 +119,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
}); });
it('LIQUIDATION - Liquidates the borrow', async () => { it('LIQUIDATION - Liquidates the borrow', async () => {
const {dai, weth, users, pool, oracle} = testEnv; const {dai, weth, users, pool, oracle, helpersContract} = testEnv;
const liquidator = users[3]; const liquidator = users[3];
const borrower = users[1]; const borrower = users[1];
@ -129,10 +129,15 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
//approve protocol to access the liquidator wallet //approve protocol to access the liquidator wallet
await dai.connect(liquidator.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await dai.connect(liquidator.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
const daiReserveDataBefore = await pool.getReserveData(dai.address); const daiReserveDataBefore = await helpersContract.getReserveData(dai.address);
const ethReserveDataBefore = await pool.getReserveData(weth.address); const ethReserveDataBefore = await helpersContract.getReserveData(weth.address);
const userReserveDataBefore = await getUserData(pool, dai.address, borrower.address); const userReserveDataBefore = await getUserData(
pool,
helpersContract,
dai.address,
borrower.address
);
const amountToLiquidate = userReserveDataBefore.currentStableDebt.div(2).toFixed(0); const amountToLiquidate = userReserveDataBefore.currentStableDebt.div(2).toFixed(0);
@ -142,19 +147,24 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
.connect(liquidator.signer) .connect(liquidator.signer)
.liquidationCall(weth.address, dai.address, borrower.address, amountToLiquidate, false); .liquidationCall(weth.address, dai.address, borrower.address, amountToLiquidate, false);
const userReserveDataAfter = await getUserData(pool, dai.address, borrower.address); const userReserveDataAfter = await getUserData(
pool,
helpersContract,
dai.address,
borrower.address
);
const daiReserveDataAfter = await pool.getReserveData(dai.address); const daiReserveDataAfter = await helpersContract.getReserveData(dai.address);
const ethReserveDataAfter = await pool.getReserveData(weth.address); const ethReserveDataAfter = await helpersContract.getReserveData(weth.address);
const collateralPrice = await oracle.getAssetPrice(weth.address); const collateralPrice = await oracle.getAssetPrice(weth.address);
const principalPrice = await oracle.getAssetPrice(dai.address); const principalPrice = await oracle.getAssetPrice(dai.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(dai.address) await helpersContract.getReserveConfigurationData(dai.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -214,7 +224,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
}); });
it('User 3 deposits 1000 USDC, user 4 1 WETH, user 4 borrows - drops HF, liquidates the borrow', async () => { it('User 3 deposits 1000 USDC, user 4 1 WETH, user 4 borrows - drops HF, liquidates the borrow', async () => {
const {usdc, users, pool, oracle, weth} = testEnv; const {usdc, users, pool, oracle, weth, helpersContract} = testEnv;
const depositor = users[3]; const depositor = users[3];
const borrower = users[4]; const borrower = users[4];
@ -280,10 +290,13 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
//approve protocol to access depositor wallet //approve protocol to access depositor wallet
await usdc.connect(liquidator.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await usdc.connect(liquidator.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
const userReserveDataBefore = await pool.getUserReserveData(usdc.address, borrower.address); const userReserveDataBefore = await helpersContract.getUserReserveData(
usdc.address,
borrower.address
);
const usdcReserveDataBefore = await pool.getReserveData(usdc.address); const usdcReserveDataBefore = await helpersContract.getReserveData(usdc.address);
const ethReserveDataBefore = await pool.getReserveData(weth.address); const ethReserveDataBefore = await helpersContract.getReserveData(weth.address);
const amountToLiquidate = BRE.ethers.BigNumber.from( const amountToLiquidate = BRE.ethers.BigNumber.from(
userReserveDataBefore.currentStableDebt.toString() userReserveDataBefore.currentStableDebt.toString()
@ -295,21 +308,24 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
.connect(liquidator.signer) .connect(liquidator.signer)
.liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, false); .liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, false);
const userReserveDataAfter = await pool.getUserReserveData(usdc.address, borrower.address); const userReserveDataAfter = await helpersContract.getUserReserveData(
usdc.address,
borrower.address
);
const userGlobalDataAfter = await pool.getUserAccountData(borrower.address); const userGlobalDataAfter = await pool.getUserAccountData(borrower.address);
const usdcReserveDataAfter = await pool.getReserveData(usdc.address); const usdcReserveDataAfter = await helpersContract.getReserveData(usdc.address);
const ethReserveDataAfter = await pool.getReserveData(weth.address); const ethReserveDataAfter = await helpersContract.getReserveData(weth.address);
const collateralPrice = await oracle.getAssetPrice(weth.address); const collateralPrice = await oracle.getAssetPrice(weth.address);
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -361,7 +377,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
}); });
it('User 4 deposits 1000 LEND - drops HF, liquidates the LEND, which results on a lower amount being liquidated', async () => { it('User 4 deposits 1000 LEND - drops HF, liquidates the LEND, which results on a lower amount being liquidated', async () => {
const {lend, usdc, users, pool, oracle} = testEnv; const {lend, usdc, users, pool, oracle, helpersContract} = testEnv;
const depositor = users[3]; const depositor = users[3];
const borrower = users[4]; const borrower = users[4];
@ -395,10 +411,13 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
//approve protocol to access depositor wallet //approve protocol to access depositor wallet
await usdc.connect(liquidator.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await usdc.connect(liquidator.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
const userReserveDataBefore = await pool.getUserReserveData(usdc.address, borrower.address); const userReserveDataBefore = await helpersContract.getUserReserveData(
usdc.address,
borrower.address
);
const usdcReserveDataBefore = await pool.getReserveData(usdc.address); const usdcReserveDataBefore = await helpersContract.getReserveData(usdc.address);
const lendReserveDataBefore = await pool.getReserveData(lend.address); const lendReserveDataBefore = await helpersContract.getReserveData(lend.address);
const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString()) const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString())
.div(2) .div(2)
@ -412,26 +431,26 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
.connect(liquidator.signer) .connect(liquidator.signer)
.liquidationCall(lend.address, usdc.address, borrower.address, amountToLiquidate, false); .liquidationCall(lend.address, usdc.address, borrower.address, amountToLiquidate, false);
const userReserveDataAfter = await pool.getUserReserveData(usdc.address, borrower.address); const userReserveDataAfter = await helpersContract.getUserReserveData(
usdc.address,
borrower.address
);
const userGlobalDataAfter = await pool.getUserAccountData(borrower.address); const userGlobalDataAfter = await pool.getUserAccountData(borrower.address);
const usdcReserveDataAfter = await pool.getReserveData(usdc.address); const usdcReserveDataAfter = await helpersContract.getReserveData(usdc.address);
const lendReserveDataAfter = await pool.getReserveData(lend.address); const lendReserveDataAfter = await helpersContract.getReserveData(lend.address);
const lendConfiguration = await helpersContract.getReserveConfigurationData(lend.address);
const collateralDecimals = lendConfiguration.decimals.toString();
const liquidationBonus = lendConfiguration.liquidationBonus.toString();
const collateralDecimals = (
await pool.getReserveConfigurationData(lend.address)
).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = oneEther.multipliedBy('1000'); const expectedCollateralLiquidated = oneEther.multipliedBy('1000');
const liquidationBonus = (
await pool.getReserveConfigurationData(lend.address)
).liquidationBonus.toString();
const expectedPrincipal = new BigNumber(collateralPrice.toString()) const expectedPrincipal = new BigNumber(collateralPrice.toString())
.times(expectedCollateralLiquidated) .times(expectedCollateralLiquidated)
.times(new BigNumber(10).pow(principalDecimals)) .times(new BigNumber(10).pow(principalDecimals))

View File

@ -236,7 +236,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
}); });
it('Liquidation call', async () => { it('Liquidation call', async () => {
const {users, pool, usdc, oracle, weth, configurator} = testEnv; const {users, pool, usdc, oracle, weth, configurator, helpersContract} = testEnv;
const depositor = users[3]; const depositor = users[3];
const borrower = users[4]; const borrower = users[4];
@ -295,7 +295,10 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
await usdc.mint(await convertToCurrencyDecimals(usdc.address, '1000')); await usdc.mint(await convertToCurrencyDecimals(usdc.address, '1000'));
await usdc.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await usdc.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
const userReserveDataBefore = await pool.getUserReserveData(usdc.address, borrower.address); const userReserveDataBefore = await helpersContract.getUserReserveData(
usdc.address,
borrower.address
);
const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString()) const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString())
.multipliedBy(0.5) .multipliedBy(0.5)

View File

@ -131,7 +131,7 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
}); });
it('User 2 tries to repay his DAI Variable loan using his WETH collateral. First half the amount, after that, the rest', async () => { it('User 2 tries to repay his DAI Variable loan using his WETH collateral. First half the amount, after that, the rest', async () => {
const {pool, weth, dai, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, dai, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[1]; const user = users[1];
const amountToRepay = parseEther('10'); const amountToRepay = parseEther('10');
@ -177,10 +177,10 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
const principalPrice = await oracle.getAssetPrice(dai.address); const principalPrice = await oracle.getAssetPrice(dai.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(dai.address) await helpersContract.getReserveConfigurationData(dai.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -230,7 +230,7 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
}); });
it('User 3 repays completely his USDC loan by swapping his WETH collateral', async () => { it('User 3 repays completely his USDC loan by swapping his WETH collateral', async () => {
const {pool, weth, usdc, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, usdc, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[2]; const user = users[2];
const amountToRepay = parseUnits('10', 6); const amountToRepay = parseUnits('10', 6);
@ -277,10 +277,10 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -337,7 +337,7 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
}); });
it('User 3 tries to repay with his collateral all his variable debt and part of the stable', async () => { it('User 3 tries to repay with his collateral all his variable debt and part of the stable', async () => {
const {pool, weth, usdc, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, usdc, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[2]; const user = users[2];
const amountToDeposit = parseEther('20'); const amountToDeposit = parseEther('20');
@ -398,10 +398,10 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())
@ -478,7 +478,7 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
}); });
it('User 4 tries to repay a bigger amount that what can be swapped of a particular collateral, repaying only the maximum allowed by that collateral', async () => { it('User 4 tries to repay a bigger amount that what can be swapped of a particular collateral, repaying only the maximum allowed by that collateral', async () => {
const {pool, weth, dai, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, dai, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[3]; const user = users[3];
const amountToDepositWeth = parseEther('0.1'); const amountToDepositWeth = parseEther('0.1');
@ -535,14 +535,15 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
const collateralPrice = await oracle.getAssetPrice(weth.address); const collateralPrice = await oracle.getAssetPrice(weth.address);
const principalPrice = await oracle.getAssetPrice(dai.address); const principalPrice = await oracle.getAssetPrice(dai.address);
const collateralConfig = await pool.getReserveConfigurationData(weth.address); const collateralConfig = await helpersContract.getReserveConfigurationData(weth.address);
const collateralDecimals = collateralConfig.decimals.toString(); const collateralDecimals = collateralConfig.decimals.toString();
const principalDecimals = (
await pool.getReserveConfigurationData(dai.address)
).decimals.toString();
const collateralLiquidationBonus = collateralConfig.liquidationBonus.toString(); const collateralLiquidationBonus = collateralConfig.liquidationBonus.toString();
const principalDecimals = (
await helpersContract.getReserveConfigurationData(dai.address)
).decimals.toString();
const expectedDebtCovered = new BigNumber(collateralPrice.toString()) const expectedDebtCovered = new BigNumber(collateralPrice.toString())
.times(new BigNumber(wethUserDataBefore.currentATokenBalance.toString())) .times(new BigNumber(wethUserDataBefore.currentATokenBalance.toString()))
.times(new BigNumber(10).pow(principalDecimals)) .times(new BigNumber(10).pow(principalDecimals))
@ -589,7 +590,7 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
}); });
it('User 5 tries to repay his USDC loan by swapping his WETH collateral, should not revert even with WETH collateral disabled', async () => { it('User 5 tries to repay his USDC loan by swapping his WETH collateral, should not revert even with WETH collateral disabled', async () => {
const {pool, weth, usdc, users, mockSwapAdapter, oracle} = testEnv; const {pool, weth, usdc, users, mockSwapAdapter, oracle, helpersContract} = testEnv;
const user = users[4]; const user = users[4];
const amountToRepay = parseUnits('65', 6); const amountToRepay = parseUnits('65', 6);
@ -642,10 +643,10 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
const principalPrice = await oracle.getAssetPrice(usdc.address); const principalPrice = await oracle.getAssetPrice(usdc.address);
const collateralDecimals = ( const collateralDecimals = (
await pool.getReserveConfigurationData(weth.address) await helpersContract.getReserveConfigurationData(weth.address)
).decimals.toString(); ).decimals.toString();
const principalDecimals = ( const principalDecimals = (
await pool.getReserveConfigurationData(usdc.address) await helpersContract.getReserveConfigurationData(usdc.address)
).decimals.toString(); ).decimals.toString();
const expectedCollateralLiquidated = new BigNumber(principalPrice.toString()) const expectedCollateralLiquidated = new BigNumber(principalPrice.toString())

View File

@ -8,9 +8,9 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors; const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
it('Tries to invoke mint not being the LendingPool', async () => { it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, pool, dai} = testEnv; const {deployer, pool, dai, helpersContract} = testEnv;
const daiStableDebtTokenAddress = (await pool.getReserveTokensAddresses(dai.address)) const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
.stableDebtTokenAddress; .stableDebtTokenAddress;
const stableDebtContract = await getContract<StableDebtToken>( const stableDebtContract = await getContract<StableDebtToken>(
@ -24,9 +24,9 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
}); });
it('Tries to invoke burn not being the LendingPool', async () => { it('Tries to invoke burn not being the LendingPool', async () => {
const {deployer, pool, dai} = testEnv; const {deployer, dai, helpersContract} = testEnv;
const daiStableDebtTokenAddress = (await pool.getReserveTokensAddresses(dai.address)) const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
.stableDebtTokenAddress; .stableDebtTokenAddress;
const stableDebtContract = await getContract<StableDebtToken>( const stableDebtContract = await getContract<StableDebtToken>(

View File

@ -26,7 +26,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
ZERO_ADDRESS, ZERO_ADDRESS,
'Aave Interest bearing DAI updated', 'Aave Interest bearing DAI updated',
'aDAI', 'aDAI',
ZERO_ADDRESS ZERO_ADDRESS,
]); ]);
const stableDebtTokenInstance = await deployContract<MockStableDebtToken>( const stableDebtTokenInstance = await deployContract<MockStableDebtToken>(
@ -87,13 +87,13 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
}); });
it('Upgrades the DAI stable debt token implementation ', async () => { it('Upgrades the DAI stable debt token implementation ', async () => {
const {dai, configurator, pool} = testEnv; const {dai, configurator, pool, helpersContract} = testEnv;
const name = await (await getAToken(newATokenAddress)).name(); const name = await (await getAToken(newATokenAddress)).name();
await configurator.updateStableDebtToken(dai.address, newStableTokenAddress); await configurator.updateStableDebtToken(dai.address, newStableTokenAddress);
const {stableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address); const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>( const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken, eContractid.MockStableDebtToken,
@ -116,13 +116,13 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
}); });
it('Upgrades the DAI variable debt token implementation ', async () => { it('Upgrades the DAI variable debt token implementation ', async () => {
const {dai, configurator, pool} = testEnv; const {dai, configurator, pool, helpersContract} = testEnv;
const name = await (await getAToken(newATokenAddress)).name(); const name = await (await getAToken(newATokenAddress)).name();
await configurator.updateVariableDebtToken(dai.address, newVariableTokenAddress); await configurator.updateVariableDebtToken(dai.address, newVariableTokenAddress);
const {variableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address); const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>( const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken, eContractid.MockStableDebtToken,

View File

@ -8,10 +8,11 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors; const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
it('Tries to invoke mint not being the LendingPool', async () => { it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, pool, dai} = testEnv; const {deployer, pool, dai, helpersContract} = testEnv;
const daiVariableDebtTokenAddress = (await pool.getReserveTokensAddresses(dai.address)) const daiVariableDebtTokenAddress = (
.variableDebtTokenAddress; await helpersContract.getReserveTokensAddresses(dai.address)
).variableDebtTokenAddress;
const variableDebtContract = await getContract<VariableDebtToken>( const variableDebtContract = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken, eContractid.VariableDebtToken,
@ -24,10 +25,11 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
}); });
it('Tries to invoke burn not being the LendingPool', async () => { it('Tries to invoke burn not being the LendingPool', async () => {
const {deployer, pool, dai} = testEnv; const {deployer, pool, dai, helpersContract} = testEnv;
const daiVariableDebtTokenAddress = (await pool.getReserveTokensAddresses(dai.address)) const daiVariableDebtTokenAddress = (
.variableDebtTokenAddress; await helpersContract.getReserveTokensAddresses(dai.address)
).variableDebtTokenAddress;
const variableDebtContract = await getContract<VariableDebtToken>( const variableDebtContract = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken, eContractid.VariableDebtToken,