Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: uni v2 extended #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/swappers/UniswapV2Extended.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.18;

import {UniswapV2Swapper, IUniswapV2Router02} from "./UniswapV2Swapper.sol";

/**
* @title UniswapV2Extended
* @author Yearn.finance
* @dev This is a simple contract that can be inherited by any tokenized
* strategy that would like to use more Uniswap V2 functions than just
* an exact swap from of erc-20 tokens.
*
* This contract will give access to all other Uni V2 functionality
* with the ease of one internal function call.
*/
contract UniswapV2Extended is UniswapV2Swapper {
/**
* @dev Used to swap a specific amount of `_to` from `_from` unless
* it takes more than `_maxAmountFrom`.
*
* This will check and handle all allownaces as well as not swapping
* unless `_maxAmountFrom` is greater than the set `minAmountToSell`
*
* If one of the tokens matches with the `base` token it will do only
* one jump, otherwise will do two jumps.
*
* @param _from The token we are swapping from.
* @param _to The token we are swapping to.
* @param _amountTo The amount of `_to` we need out.
* @param _maxAmountFrom The max of `_from` we will swap.
*/
function _swapTo(
address _from,
address _to,
uint256 _amountTo,
uint256 _maxAmountFrom
) internal {
if (_maxAmountFrom > minAmountToSell) {
_checkAllowance(router, _from, _maxAmountFrom);

IUniswapV2Router02(router).swapTokensForExactTokens(
_amountTo,
_maxAmountFrom,
_getTokenOutPath(_from, _to),
address(this),
block.timestamp
);
}
}
}