UniswapV3Swapper
Title: UniswapV3Swapper
Author: Golem Foundation
Uniswap V3 swap utilities for exact input and exact output swaps
Address variables default to ETH mainnet. Inheriting contract must set uniFees for token pairs.
Notes:
-
security-contact: [email protected]
-
origin: https://github.com/yearn/tokenized-strategy-periphery/blob/master/src/swappers/UniswapV3Swapper.sol
State Variables
minAmountToSell
uint256 public minAmountToSell
base
address public base = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
router
address public router = 0xE592427A0AEce92De3Edee1F18E0157C05861564
uniFees
mapping(address => mapping(address => uint24)) public uniFees
Functions
_setUniFees
Set fees bidirectionally for token pair
function _setUniFees(address _token0, address _token1, uint24 _fee) internal virtual;
Parameters
| Name | Type | Description |
|---|---|---|
_token0 | address | First token address |
_token1 | address | Second token address |
_fee | uint24 | Pool fee in basis points |
_swapFrom
Exact input swap with automatic routing (direct or via base token)
function _swapFrom(address _from, address _to, uint256 _amountIn, uint256 _minAmountOut)
internal
virtual
returns (uint256 _amountOut);
Parameters
| Name | Type | Description |
|---|---|---|
_from | address | Token address to swap from |
_to | address | Token address to swap to |
_amountIn | uint256 | Amount of _from to swap |
_minAmountOut | uint256 | Minimum amount of _to to receive |
Returns
| Name | Type | Description |
|---|---|---|
_amountOut | uint256 | Actual amount of _to received |
_swapTo
Exact output swap with automatic routing (direct or via base token)
function _swapTo(address _from, address _to, uint256 _amountTo, uint256 _maxAmountFrom)
internal
virtual
returns (uint256 _amountIn);
Parameters
| Name | Type | Description |
|---|---|---|
_from | address | Token address to swap from |
_to | address | Token address to swap to |
_amountTo | uint256 | Amount of _to needed out |
_maxAmountFrom | uint256 | Maximum amount of _from to swap |
Returns
| Name | Type | Description |
|---|---|---|
_amountIn | uint256 | Actual amount of _from swapped |
_checkAllowance
Ensure sufficient allowance for contract to spend token
function _checkAllowance(address _contract, address _token, uint256 _amount) internal virtual;
Parameters
| Name | Type | Description |
|---|---|---|
_contract | address | Address of contract that will move the token |
_token | address | Token address to approve |
_amount | uint256 | Amount to approve |