From df8e415a0159a6a121cedaa5994610b1ed342557 Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Wed, 2 Aug 2023 16:58:28 -0600 Subject: [PATCH 1/2] build: uni v2 extended --- src/swappers/UniswapV2Extended.sol | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/swappers/UniswapV2Extended.sol diff --git a/src/swappers/UniswapV2Extended.sol b/src/swappers/UniswapV2Extended.sol new file mode 100644 index 0000000..d6e1a60 --- /dev/null +++ b/src/swappers/UniswapV2Extended.sol @@ -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 + ); + } + } +} \ No newline at end of file From 40d0ec778450953072e49b193c4f4e44f4d5acbe Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Wed, 2 Aug 2023 17:17:11 -0600 Subject: [PATCH 2/2] fix: lint --- src/swappers/UniswapV2Extended.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/swappers/UniswapV2Extended.sol b/src/swappers/UniswapV2Extended.sol index d6e1a60..b37b2e3 100644 --- a/src/swappers/UniswapV2Extended.sol +++ b/src/swappers/UniswapV2Extended.sol @@ -47,4 +47,4 @@ contract UniswapV2Extended is UniswapV2Swapper { ); } } -} \ No newline at end of file +}