|
| 1 | +import { TestEnv, makeSuite } from './helpers/make-suite'; |
| 2 | +import { |
| 3 | + APPROVAL_AMOUNT_LENDING_POOL, |
| 4 | + MAX_UINT_AMOUNT, |
| 5 | + RAY, |
| 6 | + ZERO_ADDRESS, |
| 7 | +} from '../../helpers/constants'; |
| 8 | +import { |
| 9 | + convertToCurrencyDecimals, |
| 10 | + getContractAddressWithJsonFallback, |
| 11 | +} from '../../helpers/contracts-helpers'; |
| 12 | +import { eContractid, ProtocolErrors, RateMode } from '../../helpers/types'; |
| 13 | +import { strategyWETH } from '../../markets/aave/reservesConfigs'; |
| 14 | +import { |
| 15 | + deployATokenImplementations, |
| 16 | + deployMintableERC20, |
| 17 | + deployValidationLogic, |
| 18 | +} from '../../helpers/contracts-deployments'; |
| 19 | +import { getATokenExtraParams } from '../../helpers/init-helpers'; |
| 20 | +import { ConfigNames } from '../../helpers/configuration'; |
| 21 | +import { zeroAddress } from 'hardhat/node_modules/ethereumjs-util'; |
| 22 | +import AaveConfig from '../../markets/aave'; |
| 23 | +import { getATokensAndRatesHelper } from '../../helpers/contracts-getters'; |
| 24 | +import { config } from 'process'; |
| 25 | +import { parseEther } from '@ethersproject/units'; |
| 26 | +import exp from 'constants'; |
| 27 | + |
| 28 | +const { expect } = require('chai'); |
| 29 | + |
| 30 | +makeSuite('Adding > 128 asset to many-asset configured pool', (testEnv: TestEnv) => { |
| 31 | + const tokens = {}; |
| 32 | + |
| 33 | + before('setup', async () => { |
| 34 | + const { pool, dai, configurator, deployer, oracle } = testEnv; |
| 35 | + const atokenAndRatesDeployer = await getATokensAndRatesHelper(); |
| 36 | + |
| 37 | + const reservesCount = await pool.getReservesList(); |
| 38 | + |
| 39 | + const daiData = await pool.getReserveData(dai.address); |
| 40 | + const poolName = ConfigNames.Aave; |
| 41 | + |
| 42 | + const { |
| 43 | + ATokenNamePrefix, |
| 44 | + StableDebtTokenNamePrefix, |
| 45 | + VariableDebtTokenNamePrefix, |
| 46 | + SymbolPrefix, |
| 47 | + } = AaveConfig; |
| 48 | + |
| 49 | + // Create tokens |
| 50 | + let tokenInitParams = []; |
| 51 | + let reserveInitParams = []; |
| 52 | + |
| 53 | + const aTokenImplAddress = await getContractAddressWithJsonFallback( |
| 54 | + eContractid.AToken, |
| 55 | + poolName |
| 56 | + ); |
| 57 | + const stableDebtImplAddress = await getContractAddressWithJsonFallback( |
| 58 | + eContractid.StableDebtToken, |
| 59 | + poolName |
| 60 | + ); |
| 61 | + const variableDebtImplAddress = await getContractAddressWithJsonFallback( |
| 62 | + eContractid.VariableDebtToken, |
| 63 | + poolName |
| 64 | + ); |
| 65 | + |
| 66 | + const daiPrice = await oracle.getAssetPrice(dai.address); |
| 67 | + |
| 68 | + // All assets will be initialized with the same price as Dai. |
| 69 | + for (let i = reservesCount.length; i < 140; i++) { |
| 70 | + const tokenName = `RealT-${i}`; |
| 71 | + const token = await deployMintableERC20([tokenName, tokenName, '18']); |
| 72 | + tokens[tokenName] = token; |
| 73 | + |
| 74 | + tokenInitParams.push({ |
| 75 | + aTokenImpl: aTokenImplAddress, |
| 76 | + stableDebtTokenImpl: stableDebtImplAddress, |
| 77 | + variableDebtTokenImpl: variableDebtImplAddress, |
| 78 | + underlyingAssetDecimals: 18, |
| 79 | + interestRateStrategyAddress: daiData.interestRateStrategyAddress, |
| 80 | + underlyingAsset: token.address, |
| 81 | + treasury: ZERO_ADDRESS, |
| 82 | + incentivesController: ZERO_ADDRESS, |
| 83 | + underlyingAssetName: tokenName, |
| 84 | + aTokenName: `${ATokenNamePrefix} ${tokenName}`, |
| 85 | + aTokenSymbol: `a${SymbolPrefix}${tokenName}`, |
| 86 | + variableDebtTokenName: `${VariableDebtTokenNamePrefix} ${SymbolPrefix}${tokenName}`, |
| 87 | + variableDebtTokenSymbol: `variableDebt${SymbolPrefix}${tokenName}`, |
| 88 | + stableDebtTokenName: `${StableDebtTokenNamePrefix} ${tokenName}`, |
| 89 | + stableDebtTokenSymbol: `stableDebt${SymbolPrefix}${tokenName}`, |
| 90 | + params: '0x10', |
| 91 | + }); |
| 92 | + |
| 93 | + reserveInitParams.push({ |
| 94 | + asset: token.address, |
| 95 | + baseLTV: 5000, |
| 96 | + liquidationThreshold: 8000, |
| 97 | + liquidationBonus: 10500, |
| 98 | + reserveFactor: 1000, |
| 99 | + stableBorrowingEnabled: false, |
| 100 | + borrowingEnabled: true, |
| 101 | + }); |
| 102 | + |
| 103 | + if (tokenInitParams.length == 2 || i == 139) { |
| 104 | + await configurator.batchInitReserve(tokenInitParams); |
| 105 | + |
| 106 | + for (let j = 0; j < reserveInitParams.length; j++) { |
| 107 | + let params = reserveInitParams[j]; |
| 108 | + await configurator |
| 109 | + .connect(deployer.signer) |
| 110 | + .configureReserveAsCollateral( |
| 111 | + params.asset, |
| 112 | + params.baseLTV, |
| 113 | + params.liquidationThreshold, |
| 114 | + params.liquidationBonus |
| 115 | + ); |
| 116 | + await configurator.enableBorrowingOnReserve(params.asset, false); |
| 117 | + await oracle.setAssetPrice(params.asset, daiPrice); |
| 118 | + } |
| 119 | + tokenInitParams = []; |
| 120 | + reserveInitParams = []; |
| 121 | + } |
| 122 | + } |
| 123 | + }); |
| 124 | + |
| 125 | + it('Check that pool contains >128 assets', async () => { |
| 126 | + const { pool } = testEnv; |
| 127 | + const reservesCount = await pool.getReservesList(); |
| 128 | + expect(reservesCount.length).to.be.gt(128); |
| 129 | + }); |
| 130 | + |
| 131 | + it('Add collateral and borrow asset 130', async () => { |
| 132 | + const { |
| 133 | + users: [, user, funder], |
| 134 | + weth, |
| 135 | + pool, |
| 136 | + } = testEnv; |
| 137 | + |
| 138 | + const realT130 = tokens[`RealT-${130}`]; |
| 139 | + |
| 140 | + const assetdata = await pool.getReserveData(realT130.address); |
| 141 | + expect(assetdata.id).to.be.gt(128); |
| 142 | + |
| 143 | + await realT130.connect(funder.signer).mint(parseEther('100')); |
| 144 | + await realT130.connect(funder.signer).approve(pool.address, MAX_UINT_AMOUNT); |
| 145 | + await pool |
| 146 | + .connect(funder.signer) |
| 147 | + .deposit(realT130.address, parseEther('100'), funder.address, 0); |
| 148 | + |
| 149 | + await weth.connect(user.signer).mint(parseEther('1')); |
| 150 | + await weth.connect(user.signer).approve(pool.address, MAX_UINT_AMOUNT); |
| 151 | + await pool.connect(user.signer).deposit(weth.address, parseEther('1'), user.address, 0); |
| 152 | + |
| 153 | + const userDataBefore = await pool.getUserAccountData(user.address); |
| 154 | + await pool |
| 155 | + .connect(user.signer) |
| 156 | + .borrow(realT130.address, parseEther('1'), RateMode.Variable, 0, user.address); |
| 157 | + const userDataAfter = await pool.getUserAccountData(user.address); |
| 158 | + |
| 159 | + expect(userDataAfter.totalCollateralETH).to.be.eq(userDataBefore.totalCollateralETH); |
| 160 | + expect(userDataBefore.totalDebtETH).to.be.eq(0); |
| 161 | + expect(userDataAfter.totalDebtETH).to.be.gt(userDataBefore.totalDebtETH); |
| 162 | + expect(userDataAfter.healthFactor).to.be.lt(userDataBefore.healthFactor); |
| 163 | + }); |
| 164 | +}); |
0 commit comments