Merge branch 'feat/data-helpers' into feat/renameing

This commit is contained in:
andyk 2020-11-02 14:50:41 +03:00
commit 438ab0fca1
7 changed files with 82 additions and 21 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');
@ -24,7 +26,7 @@ const MNEMONIC = process.env.MNEMONIC || '';
// 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 isFrozen;
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 totalPrincipalStableDebt;
uint256 averageStableRate;

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,11 +69,23 @@ 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.totalPrincipalStableDebt,
@ -88,62 +103,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.isFrozen,
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].scaledATokenBalance = IAToken(reserveData.baseData.aTokenAddress)
userReservesData[i].principalATokenBalance = IAToken(reserveData.aTokenAddress)
.scaledBalanceOf(user);
userReservesData[i].usageAsCollateralEnabledOnUser = userConfig.isUsingAsCollateral(i);
if (userConfig.isBorrowing(i)) {
userReservesData[i].scaledVariableDebt = IVariableDebtToken(
reserveData
.baseData
.variableDebtTokenAddress
)
.scaledBalanceOf(user);
userReservesData[i].principalStableDebt = IStableDebtToken(
reserveData
.baseData
.stableDebtTokenAddress
)
.principalBalanceOf(user);
if (userReservesData[i].principalStableDebt != 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;
@ -57,6 +58,7 @@ export enum eContractid {
TokenDistributor = 'TokenDistributor',
StableAndVariableTokensHelper = 'StableAndVariableTokensHelper',
ATokensAndRatesHelper = 'ATokensAndRatesHelper',
UiPoolDataProvider = 'UiPoolDataProvider',
}
/*

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

@ -45,6 +45,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"
@ -70,6 +71,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",

View File

@ -0,0 +1,27 @@
import {task} from '@nomiclabs/buidler/config';
import {UiPoolDataProviderFactory} from '../../types';
import {verifyContract} from '../../helpers/etherscan-verification';
import {eContractid} from '../../helpers/types';
task(`deploy-${eContractid.UiPoolDataProvider}`, `Deploys the UiPoolDataProvider contract`)
.addFlag('verify', 'Verify UiPoolDataProvider contract via Etherscan API.')
.setAction(async ({verify}, localBRE) => {
await localBRE.run('set-bre');
if (!localBRE.network.config.chainId) {
throw new Error('INVALID_CHAIN_ID');
}
console.log(`\n- UiPoolDataProvider deployment`);
console.log(`\tDeploying UiPoolDataProvider implementation ...`);
const uiPoolDataProvider = await new UiPoolDataProviderFactory(
await localBRE.ethers.provider.getSigner()
).deploy();
await uiPoolDataProvider.deployTransaction.wait();
console.log('uiPoolDataProvider.address', uiPoolDataProvider.address);
await verifyContract(eContractid.UiPoolDataProvider, uiPoolDataProvider.address, []);
console.log(`\tFinished UiPoolDataProvider proxy and implementation deployment`);
});