Skip to main content

BaseDirectToLiquidity

Git Source

Inherits: BaseCallback

Base contract for DirectToLiquidity callbacks

This contract is intended to be inherited by a callback contract that supports a particular liquidity platform, such as Uniswap V2 or V3. It provides integration points that enable the implementing contract to support different liquidity platforms. NOTE: The parameters to the functions in this contract refer to linear vesting, which is currently only supported for ERC20 pool tokens. A future version could improve upon this by shifting the (ERC20) linear vesting functionality into a variant that inherits from this contract.

State Variables

ONE_HUNDRED_PERCENT

uint24 public constant ONE_HUNDRED_PERCENT = 100e2;

LINEAR_VESTING_KEYCODE

bytes5 public constant LINEAR_VESTING_KEYCODE = 0x4c49560000;

lotConfiguration

Maps the lot id to the DTL configuration

mapping(uint96 lotId => DTLConfiguration) public lotConfiguration;

Functions

constructor

constructor(
address auctionHouse_
)
BaseCallback(
auctionHouse_,
Callbacks.Permissions({
onCreate: true,
onCancel: true,
onCurate: true,
onPurchase: false,
onBid: false,
onSettle: true,
receiveQuoteTokens: true,
sendBaseTokens: false
})
);

_onCreate

Callback for when a lot is created

This function performs the following:

  • Validates the input data
  • Calls the Uniswap-specific implementation
  • Stores the configuration for the lot

This function reverts if:

  • OnCreateParams.poolPercent is out of bounds
  • OnCreateParams.vestingStart or OnCreateParams.vestingExpiry do not pass validation
  • Vesting is enabled and the linear vesting module is not found
  • The OnCreateParams.recipient address is the zero address
function _onCreate(
uint96 lotId_,
address seller_,
address baseToken_,
address quoteToken_,
uint256 capacity_,
bool prefund_,
bytes calldata callbackData_
) internal virtual override;

Parameters

NameTypeDescription
lotId_uint96The lot ID
seller_address
baseToken_addressThe base token address
quoteToken_addressThe quote token address
capacity_uint256The capacity of the lot
prefund_bool
callbackData_bytesEncoded OnCreateParams struct

__onCreate

Uniswap-specific implementation of the onCreate callback

The implementation will be called by the _onCreate function after the callbackData_ has been validated and after the lot configuration is stored.

The implementation should perform the following:

  • Additional validation
function __onCreate(
uint96 lotId_,
address seller_,
address baseToken_,
address quoteToken_,
uint256 capacity_,
bool prefund_,
bytes calldata callbackData_
) internal virtual;

Parameters

NameTypeDescription
lotId_uint96The lot ID
seller_addressThe seller address
baseToken_addressThe base token address
quoteToken_addressThe quote token address
capacity_uint256The capacity of the lot
prefund_boolWhether the lot is prefunded
callbackData_bytesEncoded OnCreateParams struct

_onCancel

Callback for when a lot is cancelled

This function performs the following:

  • Marks the lot as inactive

This function reverts if:

  • The lot is not registered
  • The lot has already been completed
function _onCancel(uint96 lotId_, uint256, bool, bytes calldata) internal override;

Parameters

NameTypeDescription
lotId_uint96The lot ID
<none>uint256
<none>bool
<none>bytes

_onCurate

Callback for when a lot is curated

This function performs the following:

  • Records the curator payout

This function reverts if:

  • The lot is not registered
  • The lot has already been completed
function _onCurate(uint96 lotId_, uint256 curatorPayout_, bool, bytes calldata) internal override;

Parameters

NameTypeDescription
lotId_uint96The lot ID
curatorPayout_uint256The maximum curator payout
<none>bool
<none>bytes

_onPurchase

Callback for a purchase

Not implemented

function _onPurchase(
uint96,
address,
uint256,
uint256,
bool,
bytes calldata
) internal pure override;

_onBid

Callback for a bid

Not implemented

function _onBid(uint96, uint64, address, uint256, bytes calldata) internal pure override;

_onSettle

Callback for claiming the proceeds

This function performs the following:

  • Calculates the base and quote tokens to deposit into the pool
  • Calls the Uniswap-specific implementation to mint and deposit into the pool
  • If vesting is enabled, mints the vesting tokens, or transfers the LP tokens to the recipient
  • Sends any remaining quote and base tokens to the seller

The assumptions are:

  • the callback has proceeds_ quantity of quote tokens (as receiveQuoteTokens flag is set)
  • the seller has the required balance of base tokens
  • the seller has approved the callback to spend the base tokens

This function reverts if:

  • The lot is not registered
  • The lot is already complete
function _onSettle(
uint96 lotId_,
uint256 proceeds_,
uint256 refund_,
bytes calldata callbackData_
) internal virtual override;

Parameters

NameTypeDescription
lotId_uint96The lot ID
proceeds_uint256The proceeds from the auction
refund_uint256The refund from the auction
callbackData_bytesImplementation-specific data

_mintAndDeposit

Mint and deposit into the pool

This function should be implemented by the Uniswap-specific callback

It is expected to:

  • Create and initialize the pool
  • Deposit the quote and base tokens into the pool
  • The pool tokens should be received by this contract
  • Return the ERC20 pool token
function _mintAndDeposit(
uint96 lotId_,
address quoteToken_,
uint256 quoteTokenAmount_,
address baseToken_,
uint256 baseTokenAmount_,
bytes memory callbackData_
) internal virtual 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
callbackData_bytesImplementation-specific data

Returns

NameTypeDescription
poolTokenERC20The ERC20 pool token

_getAmountWithSlippage

function _getAmountWithSlippage(
uint256 amount_,
uint24 slippage_
) internal pure returns (uint256);

_tokensRequiredForPool

function _tokensRequiredForPool(
uint256 amount_,
uint24 poolPercent_
) internal pure returns (uint256);

_getLatestLinearVestingModule

function _getLatestLinearVestingModule() internal view returns (address);

_getEncodedVestingParams

function _getEncodedVestingParams(
uint48 start_,
uint48 expiry_
) internal pure returns (bytes memory);

Errors

Callback_InsufficientBalance

error Callback_InsufficientBalance(
address token_, address account_, uint256 balance_, uint256 required_
);

Callback_Params_InvalidAddress

error Callback_Params_InvalidAddress();

Callback_Params_PercentOutOfBounds

error Callback_Params_PercentOutOfBounds(uint24 actual_, uint24 min_, uint24 max_);

Callback_Params_PoolExists

error Callback_Params_PoolExists();

Callback_Params_InvalidVestingParams

error Callback_Params_InvalidVestingParams();

Callback_LinearVestingModuleNotFound

error Callback_LinearVestingModuleNotFound();

Callback_AlreadyComplete

The auction lot has already been completed

error Callback_AlreadyComplete();

Structs

DTLConfiguration

Configuration for the DTL callback

struct DTLConfiguration {
address recipient;
uint256 lotCapacity;
uint256 lotCuratorPayout;
uint24 poolPercent;
uint48 vestingStart;
uint48 vestingExpiry;
LinearVesting linearVestingModule;
bool active;
bytes implParams;
}

Properties

NameTypeDescription
recipientaddressRecipient of the LP tokens
lotCapacityuint256Capacity of the lot
lotCuratorPayoutuint256Maximum curator payout of the lot
poolPercentuint24Percentage of the proceeds to allocate to the pool, in basis points (1% = 100). The remainder will be sent to the recipient.
vestingStartuint48Start of the vesting period for the LP tokens (0 if disabled)
vestingExpiryuint48End of the vesting period for the LP tokens (0 if disabled)
linearVestingModuleLinearVestingLinearVesting module for the LP tokens (only set if linear vesting is enabled)
activeboolWhether the lot is active
implParamsbytesImplementation-specific parameters

OnCreateParams

Parameters used in the onCreate callback

struct OnCreateParams {
uint24 poolPercent;
uint48 vestingStart;
uint48 vestingExpiry;
address recipient;
bytes implParams;
}

Properties

NameTypeDescription
poolPercentuint24Percentage of the proceeds to allocate to the pool, in basis points (1% = 100). The remainder will be sent to the recipient.
vestingStartuint48Start of the vesting period for the LP tokens (0 if disabled)
vestingExpiryuint48End of the vesting period for the LP tokens (0 if disabled)
recipientaddressRecipient of the LP tokens
implParamsbytesImplementation-specific parameters