Add enable collareral method

This commit is contained in:
Mubaris NK 2020-12-09 17:45:10 +05:30
parent e9edaf0ca4
commit ef4dd82523
No known key found for this signature in database
GPG Key ID: 1F132294E8700320
2 changed files with 48 additions and 2 deletions

View File

@ -82,6 +82,7 @@ contract BasicResolver is AaveHelpers {
event LogWithdraw(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
event LogBorrow(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
event LogPayback(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
event LogEnableCollateral(address[] tokens);
/**
* @dev Deposit ETH/ERC20_Token.
@ -193,8 +194,28 @@ contract BasicResolver is AaveHelpers {
bytes memory _eventParam = abi.encode(token, _amt, getId, setId);
emitEvent(_eventCode, _eventParam);
}
/**
* @dev Enable collateral
* @param tokens Array of tokens to enable collateral
*/
function enableCollateral(address[] calldata tokens) external {
uint _length = tokens.length;
require(_length > 0, "0-tokens-not-allowed");
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
for (uint i = 0; i < _length; i++) {
address token = tokens[i];
if (getWithdrawBalance(token) > 0 && !getIsColl(aave, token)) {
aave.setUserUseReserveAsCollateral(token, true);
}
}
emit LogEnableCollateral(tokens);
}
}
contract ConnectAave is BasicResolver {
string public name = "Aave-v1";
}
}

View File

@ -103,6 +103,10 @@ contract AaveHelpers is DSMath, Stores {
(, uint stableDebt, uint variableDebt, , , , , , ) = aaveData.getUserReserveData(token, address(this));
return rateMode == 1 ? stableDebt : variableDebt;
}
function getCollateralBalance(AaveDataProviderInterface aaveData, address token) internal view returns (uint bal) {
(bal, , , , , , , ,) = aaveData.getUserReserveData(token, address(this));
}
}
contract BasicResolver is AaveHelpers {
@ -110,6 +114,7 @@ contract BasicResolver is AaveHelpers {
event LogWithdraw(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
event LogBorrow(address indexed token, uint256 tokenAmt, uint256 indexed rateMode, uint256 getId, uint256 setId);
event LogPayback(address indexed token, uint256 tokenAmt, uint256 indexed rateMode, uint256 getId, uint256 setId);
event LogEnableCollateral(address[] tokens);
/**
* @dev Deposit ETH/ERC20_Token.
@ -233,9 +238,29 @@ contract BasicResolver is AaveHelpers {
emit LogPayback(token, _amt, rateMode, getId, setId);
}
/**
* @dev Enable collateral
* @param tokens Array of tokens to enable collateral
*/
function enableCollateral(address[] calldata tokens) external {
uint _length = tokens.length;
require(_length > 0, "0-tokens-not-allowed");
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
AaveDataProviderInterface aaveData = getAaveDataProvider();
for (uint i = 0; i < _length; i++) {
address token = tokens[i];
if (getCollateralBalance(aaveData, token) > 0 && !getIsColl(aaveData, token, address(this))) {
aave.setUserUseReserveAsCollateral(token, true);
}
}
emit LogEnableCollateral(tokens);
}
}
contract ConnectAaveV2 is BasicResolver {
string public name = "AaveV2-v1.0";
}