UniswapV3DirectToLiquidity
Inherits: BaseDirectToLiquidity
This Callback contract deposits the proceeds from a batch auction into a Uniswap V3 pool
in order to create liquidity immediately.
The Uniswap V3 position is tokenised as an ERC-20 using G-UNI.
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
uniV3Factory
The Uniswap V3 Factory contract
This contract is used to create Uniswap V3 pools
IUniswapV3Factory public uniV3Factory;
gUniFactory
The G-UNI Factory contract
This contract is used to create the ERC20 LP tokens
IGUniFactory public gUniFactory;
Functions
constructor
constructor(
address auctionHouse_,
address uniV3Factory_,
address gUniFactory_
) BaseDirectToLiquidity(auctionHouse_);
__onCreate
Uniswap-specific implementation of the onCreate callback
This function performs the following:
- Validates the input data
This function reverts if:
UniswapV3OnCreateParams.poolFee
is not enabledUniswapV3OnCreateParams.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 performs the following:
- Creates and initializes the pool, if necessary
- Deploys a pool token to wrap the Uniswap V3 position as an ERC-20 using GUni
- Uses the
GUniPool.getMintAmounts()
function to calculate the quantity of quote and base tokens required, given the current pool liquidity - Mint the LP tokens
The assumptions are:
- the callback has
quoteTokenAmount_
quantity of quote tokens (asreceiveQuoteTokens
flag is set) - the callback has
baseTokenAmount_
quantity of base tokens
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 |
_createAndInitializePoolIfNecessary
Modified from UniswapV3's PoolInitializer (which is GPL >= 2)
function _createAndInitializePoolIfNecessary(
address quoteToken,
address baseToken,
bool quoteTokenIsToken0,
uint256 maxBaseTokens,
uint24 fee,
uint160 sqrtPriceX96
) internal returns (address pool, uint256 quoteTokensReceived, uint256 baseTokensUsed);
_decodeOnCreateParameters
Decodes the configuration parameters from the DTLConfiguration
The configuration parameters are stored in DTLConfiguration.implParams
function _decodeOnCreateParameters(
uint96 lotId_
) internal view returns (UniswapV3OnCreateParams memory);
_approveMintAmount
Approves the spender to spend the token amount with a maximum slippage
This function reverts if the slippage is too high from the original amount
function _approveMintAmount(
address token_,
address spender_,
uint256 amount_,
uint256 amountActual_,
uint24 maxSlippage_
) internal;
Parameters
Name | Type | Description |
---|---|---|
token_ | address | The token to approve |
spender_ | address | The spender |
amount_ | uint256 | The amount available |
amountActual_ | uint256 | The actual amount required |
maxSlippage_ | uint24 | The maximum slippage allowed |
uniswapV3SwapCallback
function uniswapV3SwapCallback(
int256 amount0Delta_,
int256 amount1Delta_,
bytes calldata data_
) external;
Errors
Callback_Params_PoolFeeNotEnabled
error Callback_Params_PoolFeeNotEnabled();
Callback_Slippage
error Callback_Slippage(address token_, uint256 amountActual_, uint256 amountMin_);
Callback_Swap_InvalidData
error Callback_Swap_InvalidData();
Callback_Swap_InvalidCaller
error Callback_Swap_InvalidCaller();
Callback_Swap_InvalidCase
error Callback_Swap_InvalidCase();
Structs
UniswapV3OnCreateParams
Parameters for the onCreate callback
This will be encoded in the callbackData_
parameter
struct UniswapV3OnCreateParams {
uint24 poolFee;
uint24 maxSlippage;
}
Properties
Name | Type | Description |
---|---|---|
poolFee | uint24 | The fee of the Uniswap V3 pool |
maxSlippage | uint24 | The maximum slippage allowed when adding liquidity (in terms of ONE_HUNDRED_PERCENT ) |