From 7e0d572778b51fbd246174bd16cbf5d1788306f8 Mon Sep 17 00:00:00 2001 From: defcon022 Date: Wed, 1 Mar 2023 12:34:32 +0530 Subject: [PATCH] Fix: PR comments. --- contracts/Swap/SwapRouter.sol | 28 ++++++++++------------------ contracts/Swap/interfaces/IVBNB.sol | 5 +++++ 2 files changed, 15 insertions(+), 18 deletions(-) create mode 100644 contracts/Swap/interfaces/IVBNB.sol diff --git a/contracts/Swap/SwapRouter.sol b/contracts/Swap/SwapRouter.sol index 65fca4ce8..5936bfcf0 100644 --- a/contracts/Swap/SwapRouter.sol +++ b/contracts/Swap/SwapRouter.sol @@ -5,6 +5,7 @@ import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable. import "./interfaces/IPancakeSwapV2Router.sol"; import "./interfaces/IVtoken.sol"; import "./RouterHelper.sol"; +import "./interfaces/IVBNB.sol"; /** * @title Venus's Pancake Swap Integration Contract @@ -317,7 +318,7 @@ contract SwapRouter is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable, Rout /** * @notice Swap Exact tokens for BNB and repay to a Venus market - * @param vTokenAddress The address of the vToken contract for supplying assets. + * @param vBNBAddress The address of the vToken contract for supplying assets. * @param amountIn The amount of tokens to swap. * @param amountOutMin Minimum amount of tokens to receive. * @param path Array with addresses of the underlying assets to be swapped @@ -325,7 +326,7 @@ contract SwapRouter is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable, Rout * @dev In case of swapping native BNB the first asset in path array should be the wBNB address */ function swapExactTokensForETHAndRepay( - address vTokenAddress, + address vBNBAddress, uint256 amountIn, uint256 amountOutMin, address[] calldata path, @@ -335,15 +336,12 @@ contract SwapRouter is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable, Rout _swapExactTokensForETH(amountIn, amountOutMin, path, address(this), TypesOfTokens.NON_SUPPORTING_FEE); uint256 balanceAfter = address(this).balance; uint256 swapAmount = balanceAfter - balanceBefore; - uint256 response = IVToken(vTokenAddress).repayBorrowBehalf(msg.sender, swapAmount); - if (response != 0) { - revert RepayError(msg.sender, vTokenAddress, response); - } + IVBNB(vBNBAddress).repayBorrowBehalf{ value: swapAmount }(msg.sender); } /** * @notice Swap Exact tokens for BNB and repay to a Venus market - * @param vTokenAddress The address of the vToken contract for supplying assets. + * @param vBNBAddress The address of the vToken contract for supplying assets. * @param amountIn The amount of tokens to swap. * @param amountOutMin Minimum amount of tokens to receive. * @param path Array with addresses of the underlying assets to be swapped @@ -351,7 +349,7 @@ contract SwapRouter is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable, Rout * @dev In case of swapping native BNB the first asset in path array should be the wBNB address */ function swapExactTokensForETHAndRepayAtSupportingFee( - address vTokenAddress, + address vBNBAddress, uint256 amountIn, uint256 amountOutMin, address[] calldata path, @@ -361,15 +359,12 @@ contract SwapRouter is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable, Rout _swapExactTokensForETH(amountIn, amountOutMin, path, address(this), TypesOfTokens.SUPPORTING_FEE); uint256 balanceAfter = address(this).balance; uint256 swapAmount = balanceAfter - balanceBefore; - uint256 response = IVToken(vTokenAddress).repayBorrowBehalf(msg.sender, swapAmount); - if (response != 0) { - revert RepayError(msg.sender, vTokenAddress, response); - } + IVBNB(vBNBAddress).repayBorrowBehalf{ value: swapAmount }(msg.sender); } /** * @notice Swap tokens for Exact BNB and repay to a Venus market - * @param vTokenAddress The address of the vToken contract for supplying assets. + * @param vBNBAddress The address of the vToken contract for supplying assets. * @param amountOut The amount of the tokens needs to be as output token. * @param amountInMax The maximum amount of input tokens that can be taken for the transaction not to revert. * @param path Array with addresses of the underlying assets to be swapped @@ -377,7 +372,7 @@ contract SwapRouter is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable, Rout * @dev In case of swapping native BNB the first asset in path array should be the wBNB address */ function swapTokensForExactETHAndRepay( - address vTokenAddress, + address vBNBAddress, uint256 amountOut, uint256 amountInMax, address[] calldata path, @@ -387,10 +382,7 @@ contract SwapRouter is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable, Rout _swapTokensForExactETH(amountOut, amountInMax, path, address(this)); uint256 balanceAfter = address(this).balance; uint256 swapAmount = balanceAfter - balanceBefore; - uint256 response = IVToken(vTokenAddress).repayBorrowBehalf(msg.sender, swapAmount); - if (response != 0) { - revert RepayError(msg.sender, vTokenAddress, response); - } + IVBNB(vBNBAddress).repayBorrowBehalf{ value: swapAmount }(msg.sender); } /** diff --git a/contracts/Swap/interfaces/IVBNB.sol b/contracts/Swap/interfaces/IVBNB.sol new file mode 100644 index 000000000..f74434647 --- /dev/null +++ b/contracts/Swap/interfaces/IVBNB.sol @@ -0,0 +1,5 @@ +pragma solidity 0.8.13; + +interface IVBNB { + function repayBorrowBehalf(address borrower) external payable; +}