dsa-connectors/contracts/avalanche/connectors/aave/v3/helpers.sol

67 lines
1.9 KiB
Solidity
Raw Normal View History

2022-03-06 13:21:50 +00:00
pragma solidity ^0.7.0;
import { DSMath } from "../../../common/math.sol";
import { Basic } from "../../../common/basic.sol";
import { AavePoolProviderInterface, AaveDataProviderInterface } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
/**
* @dev Aave Pool Provider
*/
AavePoolProviderInterface internal constant aaveProvider =
AavePoolProviderInterface(0xA55125A90d75a95EC00130E8E8C197dB5641Eb19); // rinkeby address
/**
* @dev Aave Pool Data Provider
*/
AaveDataProviderInterface internal constant aaveData =
AaveDataProviderInterface(0x256bBbeDbA70a1240a1EB64210abB1b063267408); // rinkeby address
/**
* @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;
}
/**
* @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)
);
}
}