removal of ReserveLogic.ReserveData from UI helper return

This commit is contained in:
andyk 2020-10-30 13:14:42 +03:00
parent 3400d3b2a8
commit 18d7a44db5
6 changed files with 57 additions and 27 deletions

View File

@ -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'))

View File

@ -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;

View File

@ -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);

View File

@ -1,5 +1,6 @@
import BigNumber from 'bignumber.js';
import {MockTokenMap} from './contracts-helpers';
import {UiPoolDataProviderFactory} from '../types';
export interface SymbolMap<T> {
[symbol: string]: T;
@ -55,6 +56,7 @@ export enum eContractid {
VariableDebtToken = 'VariableDebtToken',
FeeProvider = 'FeeProvider',
TokenDistributor = 'TokenDistributor',
UiPoolDataProvider = 'UiPoolDataProvider',
}
export enum ProtocolErrors {

6
package-lock.json generated
View File

@ -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",

View File

@ -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",