mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Add enable collareral method
This commit is contained in:
parent
e9edaf0ca4
commit
ef4dd82523
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user