From 4daba04266e6a91739f9e081fcba40373d48f955 Mon Sep 17 00:00:00 2001 From: pradyuman-verma Date: Sat, 18 Jun 2022 19:00:36 +0530 Subject: [PATCH] fixed aave swapMode bug --- .../avalanche/connectors/aave/v2/main.sol | 39 ++++++++++--------- contracts/mainnet/connectors/aave/v2/main.sol | 13 ++++--- contracts/polygon/connectors/aave/v2/main.sol | 38 +++++++++--------- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/contracts/avalanche/connectors/aave/v2/main.sol b/contracts/avalanche/connectors/aave/v2/main.sol index 52fa67cc..98d48a48 100644 --- a/contracts/avalanche/connectors/aave/v2/main.sol +++ b/contracts/avalanche/connectors/aave/v2/main.sol @@ -276,28 +276,29 @@ abstract contract AaveResolver is Events, Helpers { _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 AVAX: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param rateMode Desired borrow rate mode. (Stable = 1, Variable = 2) - */ - function swapBorrowRateMode(address token, uint256 rateMode) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - AaveInterface aave = AaveInterface(aaveProvider.getLendingPool()); - uint256 currentRateMode = rateMode == 1 ? 2 : 1; + /** + * @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 AVAX: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param currentRateMode Current Rate mode. (Stable = 1, Variable = 2) + */ + function swapBorrowRateMode( + address token, + uint currentRateMode + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + AaveInterface aave = AaveInterface(aaveProvider.getLendingPool()); - if (getPaybackBalance(token, currentRateMode) > 0) { - aave.swapBorrowRateMode(token, rateMode); - } + bool isAVAX = token == avaxAddr; + address _token = isAVAX ? wavaxAddr : token; - _eventName = "LogSwapRateMode(address,uint256)"; - _eventParam = abi.encode(token, rateMode); - } + if (getPaybackBalance(_token, currentRateMode) > 0) { + aave.swapBorrowRateMode(_token, currentRateMode); + } + + _eventName = "LogSwapRateMode(address,uint256)"; + _eventParam = abi.encode(token, currentRateMode); + } } contract ConnectV2AaveV2Avalanche is AaveResolver { diff --git a/contracts/mainnet/connectors/aave/v2/main.sol b/contracts/mainnet/connectors/aave/v2/main.sol index ec7b557b..4a4cf1bf 100644 --- a/contracts/mainnet/connectors/aave/v2/main.sol +++ b/contracts/mainnet/connectors/aave/v2/main.sol @@ -245,22 +245,23 @@ abstract contract AaveResolver is Events, Helpers { * @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) + * @param currentRateMode Current Rate mode. (Stable = 1, Variable = 2) */ function swapBorrowRateMode( address token, - uint rateMode + uint currentRateMode ) external payable returns (string memory _eventName, bytes memory _eventParam) { AaveInterface aave = AaveInterface(aaveProvider.getLendingPool()); - uint currentRateMode = rateMode == 1 ? 2 : 1; + bool isEth = token == ethAddr; + address _token = isEth ? wethAddr : token; - if (getPaybackBalance(token, currentRateMode) > 0) { - aave.swapBorrowRateMode(token, rateMode); + if (getPaybackBalance(_token, currentRateMode) > 0) { + aave.swapBorrowRateMode(_token, currentRateMode); } _eventName = "LogSwapRateMode(address,uint256)"; - _eventParam = abi.encode(token, rateMode); + _eventParam = abi.encode(token, currentRateMode); } } diff --git a/contracts/polygon/connectors/aave/v2/main.sol b/contracts/polygon/connectors/aave/v2/main.sol index 59911d9b..b8c11d96 100644 --- a/contracts/polygon/connectors/aave/v2/main.sol +++ b/contracts/polygon/connectors/aave/v2/main.sol @@ -276,28 +276,28 @@ abstract contract AaveResolver is Events, Helpers { _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 MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param rateMode Desired borrow rate mode. (Stable = 1, Variable = 2) - */ - function swapBorrowRateMode(address token, uint256 rateMode) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - AaveInterface aave = AaveInterface(aaveProvider.getLendingPool()); + /** + * @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 MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param currentRateMode Current Rate mode. (Stable = 1, Variable = 2) + */ + function swapBorrowRateMode( + address token, + uint currentRateMode + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + AaveInterface aave = AaveInterface(aaveProvider.getLendingPool()); - uint256 currentRateMode = rateMode == 1 ? 2 : 1; + bool isMatic = token == maticAddr; + address _token = isMatic ? wmaticAddr : token; - if (getPaybackBalance(token, currentRateMode) > 0) { - aave.swapBorrowRateMode(token, rateMode); - } + if (getPaybackBalance(_token, currentRateMode) > 0) { + aave.swapBorrowRateMode(_token, currentRateMode); + } - _eventName = "LogSwapRateMode(address,uint256)"; - _eventParam = abi.encode(token, rateMode); - } + _eventName = "LogSwapRateMode(address,uint256)"; + _eventParam = abi.encode(token, currentRateMode); + } } contract ConnectV2AaveV2Polygon is AaveResolver {