2022-03-22 15:24:40 +00:00
|
|
|
//SPDX-License-Identifier: MIT
|
2022-02-14 06:27:50 +00:00
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
|
|
|
|
import { DSMath } from "../../../common/math.sol";
|
|
|
|
import { Basic } from "../../../common/basic.sol";
|
2022-02-19 13:47:39 +00:00
|
|
|
import { AavePoolProviderInterface, AaveDataProviderInterface } from "./interface.sol";
|
2022-02-14 06:27:50 +00:00
|
|
|
|
|
|
|
abstract contract Helpers is DSMath, Basic {
|
2022-02-19 13:47:39 +00:00
|
|
|
/**
|
|
|
|
* @dev Aave Pool Provider
|
|
|
|
*/
|
|
|
|
AavePoolProviderInterface internal constant aaveProvider =
|
2023-01-26 01:25:32 +00:00
|
|
|
AavePoolProviderInterface(0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e);
|
2022-02-19 13:47:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Aave Pool Data Provider
|
|
|
|
*/
|
|
|
|
AaveDataProviderInterface internal constant aaveData =
|
2023-01-26 01:25:32 +00:00
|
|
|
AaveDataProviderInterface(0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3);
|
2022-02-19 13:47:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Aave Referral Code
|
|
|
|
*/
|
|
|
|
uint16 internal constant referralCode = 3228;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Checks if collateral is enabled for an asset
|
|
|
|
* @param token token address of the asset.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getIsColl(address token) internal view returns (bool isCol) {
|
|
|
|
(, , , , , , , , isCol) = aaveData.getUserReserveData(
|
|
|
|
token,
|
|
|
|
address(this)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Get total debt balance & fee for an asset
|
|
|
|
* @param token token address of the debt.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
|
|
|
* @param rateMode Borrow rate mode (Stable = 1, Variable = 2)
|
|
|
|
*/
|
|
|
|
function getPaybackBalance(address token, uint256 rateMode)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
|
|
|
(, uint256 stableDebt, uint256 variableDebt, , , , , , ) = aaveData
|
|
|
|
.getUserReserveData(token, address(this));
|
|
|
|
return rateMode == 1 ? stableDebt : variableDebt;
|
|
|
|
}
|
|
|
|
|
2022-04-28 21:35:31 +00:00
|
|
|
/**
|
|
|
|
* @dev Get OnBehalfOf user's total debt balance & fee for an asset
|
|
|
|
* @param token token address of the debt.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
|
|
|
* @param rateMode Borrow rate mode (Stable = 1, Variable = 2)
|
|
|
|
*/
|
|
|
|
function getOnBehalfOfPaybackBalance(address token, uint256 rateMode, address onBehalfOf)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
|
|
|
(, uint256 stableDebt, uint256 variableDebt, , , , , , ) = aaveData
|
|
|
|
.getUserReserveData(token, onBehalfOf);
|
|
|
|
return rateMode == 1 ? stableDebt : variableDebt;
|
|
|
|
}
|
|
|
|
|
2022-02-19 13:47:39 +00:00
|
|
|
/**
|
|
|
|
* @dev Get total collateral balance for an asset
|
|
|
|
* @param token token address of the collateral.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
|
|
|
*/
|
|
|
|
function getCollateralBalance(address token)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (uint256 bal)
|
|
|
|
{
|
|
|
|
(bal, , , , , , , , ) = aaveData.getUserReserveData(
|
|
|
|
token,
|
|
|
|
address(this)
|
|
|
|
);
|
|
|
|
}
|
2022-04-26 23:02:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Get debt token address for an asset
|
|
|
|
* @param token token address of the asset
|
|
|
|
* @param rateMode Debt type: stable-1, variable-2
|
|
|
|
*/
|
2022-04-27 14:15:32 +00:00
|
|
|
function getDTokenAddr(address token, uint256 rateMode)
|
2022-04-26 23:02:47 +00:00
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns(address dToken)
|
|
|
|
{
|
|
|
|
if (rateMode == 1) {
|
|
|
|
(, dToken, ) = aaveData.getReserveTokensAddresses(token);
|
|
|
|
} else {
|
|
|
|
(, , dToken) = aaveData.getReserveTokensAddresses(token);
|
|
|
|
}
|
|
|
|
}
|
2022-02-14 06:27:50 +00:00
|
|
|
}
|