UniswapV2DirectToLiquidity
Inherits: BaseDirectToLiquidity
This Callback contract deposits the proceeds from a batch auction into a Uniswap V2 pool
in order to create liquidity immediately.
The LP tokens are transferred to DTLConfiguration.recipient
, or can optionally vest to the auction seller.
An important risk to consider: if the auction's base token is available and liquid, a third-party
could front-run the auction by creating the pool before the auction ends. This would allow them to
manipulate the price of the pool and potentially profit from the eventual deposit of the auction proceeds.
As a general rule, this callback contract does not retain balances of tokens between calls.
Transfers are performed within the same function that requires the balance.
State Variables
uniV2Factory
The Uniswap V2 factory
This contract is used to create Uniswap V2 pools
IUniswapV2Factory public uniV2Factory;
uniV2Router
The Uniswap V2 router
This contract is used to add liquidity to Uniswap V2 pools
IUniswapV2Router02 public uniV2Router;
Functions
constructor
constructor(
address auctionHouse_,
address uniswapV2Factory_,
address uniswapV2Router_
) BaseDirectToLiquidity(auctionHouse_);
__onCreate
Uniswap-specific implementation of the onCreate callback
This function implements the following:
- Validates the parameters
This function reverts if:
- The callback data is of the incorrect length
UniswapV2OnCreateParams.maxSlippage
is out of bounds
Note that this function does not check if the pool already exists. The reason for this is that it could be used as a DoS vector.
function __onCreate(
uint96 lotId_,
address,
address,
address,
uint256,
bool,
bytes calldata
) internal virtual override;
Parameters
Name | Type | Description |
---|---|---|
lotId_ | uint96 | The lot ID |
<none> | address | |
<none> | address | |
<none> | address | |
<none> | uint256 | |
<none> | bool | |
<none> | bytes |
_mintAndDeposit
Mint and deposit into the pool
This function implements the following:
- Creates the pool if necessary
- Detects and handles (if necessary) manipulation of pool reserves
- Deposits the tokens into the pool
function _mintAndDeposit(
uint96 lotId_,
address quoteToken_,
uint256 quoteTokenAmount_,
address baseToken_,
uint256 baseTokenAmount_,
bytes memory
) internal virtual override returns (ERC20 poolToken);
Parameters
Name | Type | Description |
---|---|---|
lotId_ | uint96 | The lot ID |
quoteToken_ | address | The quote token address |
quoteTokenAmount_ | uint256 | The amount of quote tokens to deposit |
baseToken_ | address | The base token address |
baseTokenAmount_ | uint256 | The amount of base tokens to deposit |
<none> | bytes |
Returns
Name | Type | Description |
---|---|---|
poolToken | ERC20 | The ERC20 pool token |
_decodeOnCreateParameters
Decodes the configuration parameters from the DTLConfiguration
The configuration parameters are stored in DTLConfiguration.implParams
function _decodeOnCreateParameters(
uint96 lotId_
) internal view returns (UniswapV2OnCreateParams memory);
_mitigateDonation
This function mitigates the risk of a third-party having donated quote tokens to the pool causing the auction settlement to fail.
It performs the following:
- Checks if the pool has had quote tokens donated, or exits
- Swaps the quote tokens for base tokens to adjust the reserves to the correct price
function _mitigateDonation(
address pairAddress_,
uint256 auctionPrice_,
address quoteToken_,
address baseToken_
) internal returns (uint256 quoteTokensUsed, uint256 baseTokensUsed);
Parameters
Name | Type | Description |
---|---|---|
pairAddress_ | address | The address of the Uniswap V2 pair |
auctionPrice_ | uint256 | The price of the auction |
quoteToken_ | address | The quote token of the pair |
baseToken_ | address | The base token of the pair |
Returns
Name | Type | Description |
---|---|---|
quoteTokensUsed | uint256 | The amount of quote tokens used in the swap |
baseTokensUsed | uint256 | The amount of base tokens used in the swap |
Structs
UniswapV2OnCreateParams
Parameters for the onCreate callback
This will be encoded in the callbackData_
parameter
struct UniswapV2OnCreateParams {
uint24 maxSlippage;
}
Properties
Name | Type | Description |
---|---|---|
maxSlippage | uint24 | The maximum slippage allowed when adding liquidity (in terms of basis points, where 1% = 1e2) |