dsa-connectors/contracts/mainnet/connectors/spark/helpers.sol
2023-05-11 19:50:04 -04:00

100 lines
2.8 KiB
Solidity

//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import { SparkPoolAddressesProviderInterface, AaveDataProviderInterface } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
/**
* @dev Spark Pool Provider
*/
SparkPoolAddressesProviderInterface internal constant sparkProvider =
SparkPoolAddressesProviderInterface(0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE);
/**
* @dev Spark Pool Data Provider
*/
AaveDataProviderInterface internal constant sparkData =
AaveDataProviderInterface(0xFc21d6d146E6086B8359705C8b28512a983db0cb);
/**
* @dev Spark Referral Code
*/
uint16 internal constant referralCode = 0;
/**
* @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) = sparkData.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, , , , , , ) = sparkData
.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 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, , , , , , ) = sparkData
.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, , , , , , , , ) = sparkData.getUserReserveData(
token,
address(this)
);
}
/**
* @dev Get debt token address for an asset
* @param token token address of the asset
* @param rateMode Debt type: stable-1, variable-2
*/
function getDTokenAddr(address token, uint256 rateMode)
internal
view
returns(address dToken)
{
if (rateMode == 1) {
(, dToken, ) = sparkData.getReserveTokensAddresses(token);
} else {
(, , dToken) = sparkData.getReserveTokensAddresses(token);
}
}
}