From 18d7a44db5691b1f10ecf89955853284a629ecfe Mon Sep 17 00:00:00 2001 From: andyk Date: Fri, 30 Oct 2020 13:14:42 +0300 Subject: [PATCH] removal of ReserveLogic.ReserveData from UI helper return --- buidler.config.ts | 4 +- contracts/misc/IUiPoolDataProvider.sol | 19 ++++++++-- contracts/misc/UiPoolDataProvider.sol | 51 +++++++++++++++----------- helpers/types.ts | 2 + package-lock.json | 6 +++ package.json | 2 + 6 files changed, 57 insertions(+), 27 deletions(-) diff --git a/buidler.config.ts b/buidler.config.ts index 0b309e90..6640e875 100644 --- a/buidler.config.ts +++ b/buidler.config.ts @@ -6,6 +6,8 @@ import {accounts} from './test-wallets.js'; import {eEthereumNetwork} from './helpers/types'; import {BUIDLEREVM_CHAINID, COVERAGE_CHAINID} from './helpers/buidler-constants'; +require('dotenv').config(); + usePlugin('@nomiclabs/buidler-ethers'); usePlugin('buidler-typechain'); usePlugin('solidity-coverage'); @@ -28,7 +30,7 @@ const MNEMONICS: {[network: string]: string} = { // Prevent to load scripts before compilation and typechain if (!SKIP_LOAD) { - ['misc', 'migrations', 'dev', 'full'].forEach((folder) => { + ['misc', 'deployments', 'migrations', 'dev', 'full'].forEach((folder) => { const tasksPath = path.join(__dirname, 'tasks', folder); fs.readdirSync(tasksPath) .filter((pth) => pth.includes('.ts')) diff --git a/contracts/misc/IUiPoolDataProvider.sol b/contracts/misc/IUiPoolDataProvider.sol index a09f210a..eee6d4e8 100644 --- a/contracts/misc/IUiPoolDataProvider.sol +++ b/contracts/misc/IUiPoolDataProvider.sol @@ -11,16 +11,27 @@ interface IUiPoolDataProvider { string name; string symbol; uint256 decimals; - uint256 ltv; - uint256 liquidationThreshold; - uint256 liquidationBonus; + uint256 baseLTVasCollateral; + uint256 reserveLiquidationThreshold; + uint256 reserveLiquidationBonus; uint256 reserveFactor; bool usageAsCollateralEnabled; bool borrowingEnabled; bool stableBorrowRateEnabled; bool isActive; bool isFreezed; - ReserveLogic.ReserveData baseData; + // base data + uint128 liquidityIndex; + uint128 variableBorrowIndex; + uint128 liquidityRate; + uint128 variableBorrowRate; + uint128 stableBorrowRate; + uint40 lastUpdateTimestamp; + address aTokenAddress; + address stableDebtTokenAddress; + address variableDebtTokenAddress; + address interestRateStrategyAddress; + // uint256 availableLiquidity; uint256 totalBorrowsStable; uint256 totalBorrowsVariable; diff --git a/contracts/misc/UiPoolDataProvider.sol b/contracts/misc/UiPoolDataProvider.sol index 74a5bb34..7b94e33a 100644 --- a/contracts/misc/UiPoolDataProvider.sol +++ b/contracts/misc/UiPoolDataProvider.sol @@ -12,9 +12,12 @@ import {IVariableDebtToken} from '../tokenization/interfaces/IVariableDebtToken. import {IStableDebtToken} from '../tokenization/interfaces/IStableDebtToken.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; +import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../libraries/configuration/UserConfiguration.sol'; -import '../lendingpool/DefaultReserveInterestRateStrategy.sol'; +import { + DefaultReserveInterestRateStrategy +} from '../lendingpool/DefaultReserveInterestRateStrategy.sol'; contract UiPoolDataProvider is IUiPoolDataProvider { using WadRayMath for uint256; @@ -66,19 +69,27 @@ contract UiPoolDataProvider is IUiPoolDataProvider { reserveData.underlyingAsset = reserves[i]; // reserve current state - reserveData.baseData = lendingPool.getReserveData(reserveData.underlyingAsset); + ReserveLogic.ReserveData memory baseData = lendingPool.getReserveData( + reserveData.underlyingAsset + ); + reserveData.liquidityIndex = baseData.liquidityIndex; + reserveData.variableBorrowIndex = baseData.variableBorrowIndex; + reserveData.liquidityRate = baseData.currentLiquidityRate; + reserveData.variableBorrowRate = baseData.currentVariableBorrowRate; + reserveData.stableBorrowRate = baseData.currentStableBorrowRate; + reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp; + reserveData.aTokenAddress = baseData.aTokenAddress; + reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress; + reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress; + reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress; reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset); reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf( - reserveData.baseData.aTokenAddress + reserveData.aTokenAddress ); - reserveData.totalBorrowsStable = IERC20Detailed(reserveData.baseData.stableDebtTokenAddress) + reserveData.totalBorrowsStable = IERC20Detailed(reserveData.stableDebtTokenAddress) .totalSupply(); - reserveData.totalBorrowsVariable = IERC20Detailed( - reserveData - .baseData - .variableDebtTokenAddress - ) + reserveData.totalBorrowsVariable = IERC20Detailed(reserveData.variableDebtTokenAddress) .totalSupply(); uint256 totalBorrows = reserveData.totalBorrowsStable + reserveData.totalBorrowsVariable; reserveData.utilizationRate = totalBorrows == 0 @@ -88,62 +99,58 @@ contract UiPoolDataProvider is IUiPoolDataProvider { // reserve configuration // we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed - reserveData.symbol = IERC20Detailed(reserveData.baseData.aTokenAddress).symbol(); + reserveData.symbol = IERC20Detailed(reserveData.aTokenAddress).symbol(); reserveData.name = ''; ( - reserveData.ltv, - reserveData.liquidationThreshold, - reserveData.liquidationBonus, + reserveData.baseLTVasCollateral, + reserveData.reserveLiquidationThreshold, + reserveData.reserveLiquidationBonus, reserveData.decimals, reserveData.reserveFactor - ) = reserveData.baseData.configuration.getParamsMemory(); + ) = baseData.configuration.getParamsMemory(); ( reserveData.isActive, reserveData.isFreezed, reserveData.borrowingEnabled, reserveData.stableBorrowRateEnabled - ) = reserveData.baseData.configuration.getFlagsMemory(); - reserveData.usageAsCollateralEnabled = reserveData.ltv != 0; + ) = baseData.configuration.getFlagsMemory(); + reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0; ( reserveData.variableRateSlope1, reserveData.variableRateSlope2, reserveData.stableRateSlope1, reserveData.stableRateSlope2 ) = getInterestRateStrategySlopes( - DefaultReserveInterestRateStrategy(reserveData.baseData.interestRateStrategyAddress) + DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress) ); if (user != address(0)) { // user reserve data userReservesData[i].underlyingAsset = reserveData.underlyingAsset; - userReservesData[i].principalATokenBalance = IAToken(reserveData.baseData.aTokenAddress) + userReservesData[i].principalATokenBalance = IAToken(reserveData.aTokenAddress) .scaledBalanceOf(user); userReservesData[i].usageAsCollateralEnabledOnUser = userConfig.isUsingAsCollateral(i); if (userConfig.isBorrowing(i)) { userReservesData[i].principalVariableBorrows = IVariableDebtToken( reserveData - .baseData .variableDebtTokenAddress ) .scaledBalanceOf(user); userReservesData[i].principalStableBorrows = IStableDebtToken( reserveData - .baseData .stableDebtTokenAddress ) .principalBalanceOf(user); if (userReservesData[i].principalStableBorrows != 0) { userReservesData[i].stableBorrowRate = IStableDebtToken( reserveData - .baseData .stableDebtTokenAddress ) .getUserStableRate(user); userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken( reserveData - .baseData .stableDebtTokenAddress ) .getUserLastUpdated(user); diff --git a/helpers/types.ts b/helpers/types.ts index 305ec335..ebea869f 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -1,5 +1,6 @@ import BigNumber from 'bignumber.js'; import {MockTokenMap} from './contracts-helpers'; +import {UiPoolDataProviderFactory} from '../types'; export interface SymbolMap { [symbol: string]: T; @@ -55,6 +56,7 @@ export enum eContractid { VariableDebtToken = 'VariableDebtToken', FeeProvider = 'FeeProvider', TokenDistributor = 'TokenDistributor', + UiPoolDataProvider = 'UiPoolDataProvider', } export enum ProtocolErrors { diff --git a/package-lock.json b/package-lock.json index f8a49a83..078aaa10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3763,6 +3763,12 @@ "integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==", "dev": true }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==", + "dev": true + }, "download": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/download/-/download-7.1.0.tgz", diff --git a/package.json b/package.json index f17dd906..cb70f387 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "dev:coverage": "buidler coverage --network coverage", "dev:deployment": "buidler dev-deployment", "dev:deployExample": "buidler deploy-Example", + "dev:deployUIProvider": "npm run buidler:kovan deploy-UiPoolDataProvider", "dev:prettier": "prettier --write .", "ci:test": "npm run compile && npm run types-gen && npm run test", "ci:clean": "rm -rf ./artifacts ./cache ./types" @@ -68,6 +69,7 @@ "chai": "4.2.0", "chai-bignumber": "3.0.0", "chai-bn": "^0.2.1", + "dotenv": "^8.2.0", "eth-sig-util": "2.5.3", "ethereum-waffle": "3.0.2", "ethereumjs-util": "7.0.2",