Skip to main content

UniswapV3DirectToLiquidity

Git Source

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 enabled
  • UniswapV3OnCreateParams.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

NameTypeDescription
lotId_uint96The 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 (as receiveQuoteTokens 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

NameTypeDescription
lotId_uint96The lot ID
quoteToken_addressThe quote token address
quoteTokenAmount_uint256The amount of quote tokens to deposit
baseToken_addressThe base token address
baseTokenAmount_uint256The amount of base tokens to deposit
<none>bytes

Returns

NameTypeDescription
poolTokenERC20The 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

NameTypeDescription
token_addressThe token to approve
spender_addressThe spender
amount_uint256The amount available
amountActual_uint256The actual amount required
maxSlippage_uint24The 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

NameTypeDescription
poolFeeuint24The fee of the Uniswap V3 pool
maxSlippageuint24The maximum slippage allowed when adding liquidity (in terms of ONE_HUNDRED_PERCENT)