Skip to content

Commit

Permalink
Fix: PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Debugger022 committed Mar 1, 2023
1 parent b8a0319 commit 7e0d572
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
28 changes: 10 additions & 18 deletions contracts/Swap/SwapRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -317,15 +318,15 @@ 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
* @dev Addresses of underlying assets should be ordered that first asset is the token we are swapping and second asset is the token we receive
* @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,
Expand All @@ -335,23 +336,20 @@ 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
* @dev Addresses of underlying assets should be ordered that first asset is the token we are swapping and second asset is the token we receive
* @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,
Expand All @@ -361,23 +359,20 @@ 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
* @dev Addresses of underlying assets should be ordered that first asset is the token we are swapping and second asset is the token we receive
* @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,
Expand All @@ -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);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions contracts/Swap/interfaces/IVBNB.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity 0.8.13;

interface IVBNB {
function repayBorrowBehalf(address borrower) external payable;
}

0 comments on commit 7e0d572

Please sign in to comment.