Add swap borrow rate method

This commit is contained in:
Mubaris NK 2021-03-29 17:04:05 +05:30
parent 6911d7060c
commit f9566ae6a7
No known key found for this signature in database
GPG Key ID: 9AC09AD0F8D68561
3 changed files with 25 additions and 1 deletions

View File

@ -6,4 +6,5 @@ contract Events {
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);
event LogSwapRateMode(address indexed token, uint256 rateMode);
}

View File

@ -12,6 +12,7 @@ interface AaveInterface {
) external;
function repay(address _asset, uint256 _amount, uint256 _rateMode, address _onBehalfOf) external;
function setUserUseReserveAsCollateral(address _asset, bool _useAsCollateral) external;
function swapBorrowRateMode(address _asset, uint256 _rateMode) external;
}
interface AaveLendingPoolProviderInterface {

View File

@ -173,9 +173,31 @@ abstract contract AaveResolver is Events, Helpers {
}
}
_eventName = "LogEnableCollateral(address[]);";
_eventName = "LogEnableCollateral(address[])";
_eventParam = abi.encode(tokens);
}
/**
* @dev Swap borrow rate mode
* @notice Swaps user borrow rate mode between variable and stable
* @param token The address of the token to swap borrow rate.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param rateMode Desired borrow rate mode. (Stable = 1, Variable = 2)
*/
function swapBorrowRateMode(
address token,
uint rateMode
) external payable returns (string memory _eventName, bytes memory _eventParam) {
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
uint currentRateMode = rateMode == 1 ? 2 : 1;
if (getPaybackBalance(token, currentRateMode) > 0) {
aave.swapBorrowRateMode(token, rateMode);
}
_eventName = "LogSwapRateMode(address,uint256)";
_eventParam = abi.encode(token, rateMode);
}
}
contract ConnectV2AaveV2AMM is AaveResolver {