dsa-connectors/contracts/polygon/connectors/aave/v2/helpers.sol
2022-05-10 18:49:10 +05:30

84 lines
2.4 KiB
Solidity

//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import { DSMath } from "../../../common/math.sol";
import { Basic } from "../../../common/basic.sol";
import { AaveLendingPoolProviderInterface, AaveDataProviderInterface } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
/**
* @dev Aave Lending Pool Provider
*/
AaveLendingPoolProviderInterface internal constant aaveProvider =
AaveLendingPoolProviderInterface(
0xd05e3E715d945B59290df0ae8eF85c1BdB684744
);
/**
* @dev Aave Protocol Data Provider
*/
AaveDataProviderInterface internal constant aaveData =
AaveDataProviderInterface(0x7551b5D2763519d4e37e8B81929D336De671d46d);
/**
* @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 OnBehalfOf user's total debt balance & fee for an asset
* @param token token address of the debt.(For MATIC: 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;
}
/**
* @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)
);
}
}