mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: parse 32 bytes symbol to string
This commit is contained in:
parent
0b775af7a4
commit
8a57656668
|
@ -15,9 +15,7 @@ import {ReserveConfiguration} from '../protocol/libraries/configuration/ReserveC
|
||||||
import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol';
|
import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol';
|
||||||
import {DataTypes} from '../protocol/libraries/types/DataTypes.sol';
|
import {DataTypes} from '../protocol/libraries/types/DataTypes.sol';
|
||||||
import {IChainlinkAggregator} from '../interfaces/IChainlinkAggregator.sol';
|
import {IChainlinkAggregator} from '../interfaces/IChainlinkAggregator.sol';
|
||||||
import {
|
import {DefaultReserveInterestRateStrategy} from '../protocol/lendingpool/DefaultReserveInterestRateStrategy.sol';
|
||||||
DefaultReserveInterestRateStrategy
|
|
||||||
} from '../protocol/lendingpool/DefaultReserveInterestRateStrategy.sol';
|
|
||||||
import {IERC20DetailedBytes} from './interfaces/IERC20DetailedBytes.sol';
|
import {IERC20DetailedBytes} from './interfaces/IERC20DetailedBytes.sol';
|
||||||
|
|
||||||
contract UiPoolDataProvider is IUiPoolDataProvider {
|
contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
|
@ -30,7 +28,6 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
uint256 public constant ETH_CURRENCY_UNIT = 1 ether;
|
uint256 public constant ETH_CURRENCY_UNIT = 1 ether;
|
||||||
address public constant MKRAddress = 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2;
|
address public constant MKRAddress = 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2;
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
IChainlinkAggregator _networkBaseTokenPriceInUsdProxyAggregator,
|
IChainlinkAggregator _networkBaseTokenPriceInUsdProxyAggregator,
|
||||||
IChainlinkAggregator _marketReferenceCurrencyPriceInUsdProxyAggregator
|
IChainlinkAggregator _marketReferenceCurrencyPriceInUsdProxyAggregator
|
||||||
|
@ -71,10 +68,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
public
|
public
|
||||||
view
|
view
|
||||||
override
|
override
|
||||||
returns (
|
returns (AggregatedReserveData[] memory, BaseCurrencyInfo memory)
|
||||||
AggregatedReserveData[] memory,
|
|
||||||
BaseCurrencyInfo memory
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
IAaveOracle oracle = IAaveOracle(provider.getPriceOracle());
|
IAaveOracle oracle = IAaveOracle(provider.getPriceOracle());
|
||||||
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
||||||
|
@ -86,8 +80,9 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
reserveData.underlyingAsset = reserves[i];
|
reserveData.underlyingAsset = reserves[i];
|
||||||
|
|
||||||
// reserve current state
|
// reserve current state
|
||||||
DataTypes.ReserveData memory baseData =
|
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(
|
||||||
lendingPool.getReserveData(reserveData.underlyingAsset);
|
reserveData.underlyingAsset
|
||||||
|
);
|
||||||
reserveData.liquidityIndex = baseData.liquidityIndex;
|
reserveData.liquidityIndex = baseData.liquidityIndex;
|
||||||
reserveData.variableBorrowIndex = baseData.variableBorrowIndex;
|
reserveData.variableBorrowIndex = baseData.variableBorrowIndex;
|
||||||
reserveData.liquidityRate = baseData.currentLiquidityRate;
|
reserveData.liquidityRate = baseData.currentLiquidityRate;
|
||||||
|
@ -98,7 +93,9 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress;
|
reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress;
|
||||||
reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress;
|
reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress;
|
||||||
reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress;
|
reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress;
|
||||||
reserveData.priceInMarketReferenceCurrency = oracle.getAssetPrice(reserveData.underlyingAsset);
|
reserveData.priceInMarketReferenceCurrency = oracle.getAssetPrice(
|
||||||
|
reserveData.underlyingAsset
|
||||||
|
);
|
||||||
|
|
||||||
reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
|
reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
|
||||||
reserveData.aTokenAddress
|
reserveData.aTokenAddress
|
||||||
|
@ -115,12 +112,11 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
|
// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
|
||||||
if (address(reserveData.underlyingAsset) == address(MKRAddress)) {
|
if (address(reserveData.underlyingAsset) == address(MKRAddress)) {
|
||||||
bytes32 symbol = IERC20DetailedBytes(reserveData.underlyingAsset).symbol();
|
bytes32 symbol = IERC20DetailedBytes(reserveData.underlyingAsset).symbol();
|
||||||
reserveData.symbol = string(abi.encodePacked(symbol));
|
reserveData.symbol = bytes32ToString(symbol);
|
||||||
} else {
|
} else {
|
||||||
reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol();
|
reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// (bool success, bytes memory result) = reserveData.underlyingAsset.staticcall(abi.encodeWithSignature("symbol()"));
|
// (bool success, bytes memory result) = reserveData.underlyingAsset.staticcall(abi.encodeWithSignature("symbol()"));
|
||||||
// reserveData.symbol = string(abi.encodePacked(result));
|
// reserveData.symbol = string(abi.encodePacked(result));
|
||||||
|
|
||||||
|
@ -158,15 +154,21 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseCurrencyInfo memory baseCurrencyInfo;
|
BaseCurrencyInfo memory baseCurrencyInfo;
|
||||||
baseCurrencyInfo.networkBaseTokenPriceInUsd = networkBaseTokenPriceInUsdProxyAggregator.latestAnswer();
|
baseCurrencyInfo.networkBaseTokenPriceInUsd = networkBaseTokenPriceInUsdProxyAggregator
|
||||||
baseCurrencyInfo.networkBaseTokenPriceDecimals = networkBaseTokenPriceInUsdProxyAggregator.decimals();
|
.latestAnswer();
|
||||||
|
baseCurrencyInfo.networkBaseTokenPriceDecimals = networkBaseTokenPriceInUsdProxyAggregator
|
||||||
|
.decimals();
|
||||||
|
|
||||||
try oracle.BASE_CURRENCY_UNIT() returns (uint256 baseCurrencyUnit) {
|
try oracle.BASE_CURRENCY_UNIT() returns (uint256 baseCurrencyUnit) {
|
||||||
baseCurrencyInfo.marketReferenceCurrencyUnit = baseCurrencyUnit;
|
baseCurrencyInfo.marketReferenceCurrencyUnit = baseCurrencyUnit;
|
||||||
baseCurrencyInfo.marketReferenceCurrencyPriceInUsd = int256(baseCurrencyUnit);
|
baseCurrencyInfo.marketReferenceCurrencyPriceInUsd = int256(baseCurrencyUnit);
|
||||||
} catch (bytes memory /*lowLevelData*/) {
|
} catch (
|
||||||
|
bytes memory /*lowLevelData*/
|
||||||
|
) {
|
||||||
baseCurrencyInfo.marketReferenceCurrencyUnit = ETH_CURRENCY_UNIT;
|
baseCurrencyInfo.marketReferenceCurrencyUnit = ETH_CURRENCY_UNIT;
|
||||||
baseCurrencyInfo.marketReferenceCurrencyPriceInUsd = marketReferenceCurrencyPriceInUsdProxyAggregator.latestAnswer();
|
baseCurrencyInfo
|
||||||
|
.marketReferenceCurrencyPriceInUsd = marketReferenceCurrencyPriceInUsdProxyAggregator
|
||||||
|
.latestAnswer();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (reservesData, baseCurrencyInfo);
|
return (reservesData, baseCurrencyInfo);
|
||||||
|
@ -182,8 +184,9 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
address[] memory reserves = lendingPool.getReservesList();
|
address[] memory reserves = lendingPool.getReservesList();
|
||||||
DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
|
DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
|
||||||
|
|
||||||
UserReserveData[] memory userReservesData =
|
UserReserveData[] memory userReservesData = new UserReserveData[](
|
||||||
new UserReserveData[](user != address(0) ? reserves.length : 0);
|
user != address(0) ? reserves.length : 0
|
||||||
|
);
|
||||||
|
|
||||||
for (uint256 i = 0; i < reserves.length; i++) {
|
for (uint256 i = 0; i < reserves.length; i++) {
|
||||||
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
|
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
|
||||||
|
@ -197,24 +200,32 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
|
|
||||||
if (userConfig.isBorrowing(i)) {
|
if (userConfig.isBorrowing(i)) {
|
||||||
userReservesData[i].scaledVariableDebt = IVariableDebtToken(
|
userReservesData[i].scaledVariableDebt = IVariableDebtToken(
|
||||||
baseData
|
baseData.variableDebtTokenAddress
|
||||||
.variableDebtTokenAddress
|
).scaledBalanceOf(user);
|
||||||
)
|
|
||||||
.scaledBalanceOf(user);
|
|
||||||
userReservesData[i].principalStableDebt = IStableDebtToken(baseData.stableDebtTokenAddress)
|
userReservesData[i].principalStableDebt = IStableDebtToken(baseData.stableDebtTokenAddress)
|
||||||
.principalBalanceOf(user);
|
.principalBalanceOf(user);
|
||||||
if (userReservesData[i].principalStableDebt != 0) {
|
if (userReservesData[i].principalStableDebt != 0) {
|
||||||
userReservesData[i].stableBorrowRate = IStableDebtToken(baseData.stableDebtTokenAddress)
|
userReservesData[i].stableBorrowRate = IStableDebtToken(baseData.stableDebtTokenAddress)
|
||||||
.getUserStableRate(user);
|
.getUserStableRate(user);
|
||||||
userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken(
|
userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken(
|
||||||
baseData
|
baseData.stableDebtTokenAddress
|
||||||
.stableDebtTokenAddress
|
).getUserLastUpdated(user);
|
||||||
)
|
|
||||||
.getUserLastUpdated(user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (userReservesData);
|
return (userReservesData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bytes32ToString(bytes32 _bytes32) public pure returns (string memory) {
|
||||||
|
uint8 i = 0;
|
||||||
|
while (i < 32 && _bytes32[i] != 0) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
bytes memory bytesArray = new bytes(i);
|
||||||
|
for (i = 0; i < 32 && _bytes32[i] != 0; i++) {
|
||||||
|
bytesArray[i] = _bytes32[i];
|
||||||
|
}
|
||||||
|
return string(bytesArray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user