Liquidator

The Liquidator module is responsible for collecting reward tokens from vaults, swapping them and donating back the purchased tokens to the vaults. Typically, this is swapping reward tokens to vault assets which are donated back to the vaults to increase their assets per share. For example, swapping $CRV earned in a Curve pool back to a vault asset like $DAI. There can be multiple reward tokens collected from a vault and different target tokens can be specified for each reward token.

The Liquidator's main task is to batch the swapping of rewards collected from multiple vaults. This socializes the gas costs in swapping rewards across multiple vaults.

The Liquidator uses a Swapper module to do on-chain token swaps. A swapper typically uses a swap aggregator like 1Inch or CowSwap but can use decentralized exchanges like Uniswap or Balancer.

Liquidator Contracts

Contract Interface

See the metavaults github repository for contract diagrams and process diagrams.

Variables

syncSwapper

contract IDexSwap syncSwapper

Contract that implements on-chain swaps

asyncSwapper

contract IDexAsyncSwap asyncSwapper

Contract that implements on-chain async swaps

Functions

collectRewards

function collectRewards(address[] vaults) external returns (address[][] rewardTokens, uint256[][] rewards, address[][] purchaseTokens)

The keeper or governor can collect different rewards from a list of vaults. The Liquidator calls each vault to collect their rewards. The vaults transfer the rewards to themselves first and then the Liquidator transfers each reward from each vault to the Liquidator. Vault rewards can be collect multiple times before they are swapped for the vault asset. It's the responsibility of the Liquidator to account for how many rewards were collected from each vault.

Parameters

Name
Type
Description

vaults

address[]

List of vault addresses to collect rewards from.

Return Values

Name
Type
Description

rewardTokens

address[][]

Reward token addresses for each vault. The first dimension is vault from the vaults param. The second dimension is the index of the reward token within the vault.

rewards

uint256[][]

Amount of reward tokens collected for each vault. The first dimension is vault from the vaults param. The second dimension is the index of the reward token within the vault.

purchaseTokens

address[][]

The token to purchase for each of the rewards. The first dimension is vault from the vaults param. The second dimension is the index of the reward token within the vault.

donateTokens

function donateTokens(address[] rewardTokens, address[] purchaseTokens, address[] vaults) external returns (uint256[] assets)

The protocol Governor or Keeper can send the purchased assets in a batch back to the vaults. The order of the input elements is important to aggreate multiple deposits of the same asset to the vault.

ie. Vault 1 has Reward A, Reward B, both rewards are swapped for the same donated Token T.

  • donateTokens([rewardA.address, rewardB.address], [tokenT.address, tokenT.address], [vault1.Address, vault1.Address] Only triggers one deposit of Token T to the underlying vault

Parameters

Name
Type
Description

rewardTokens

address[]

List of addresses of the reward token that was sold.

purchaseTokens

address[]

List of addresses of the token that was purchased.

vaults

address[]

List of addresses for the vaults with the reward to asset pair.

Return Values

Name
Type
Description

assets

uint256[]

Amount of asset tokens purchased for each different vault in the vaults parameter.

claimAssets

function claimAssets(uint256 batch, address rewardToken, address assetToken) external returns (uint256 assets)

Vault claims the purchased assets in a batch back. Separate transactions are required if a vault has multiple reward tokens.

Parameters

Name
Type
Description

batch

uint256

Liquidation batch index from the previously executed swap.

rewardToken

address

Address of the reward token that was sold.

assetToken

address

Address of the asset token that was purchased.

Return Values

Name
Type
Description

assets

uint256

Amount of asset tokens purchased in the batch.

pendingRewards

function pendingRewards(address rewardToken, address assetToken) external view returns (uint256 batch, uint256 rewards)

Parameters

Name
Type
Description

rewardToken

address

Address of the rewards being sold.

assetToken

address

Address of the assets being purchased.

Return Values

Name
Type
Description

batch

uint256

Current liquidation batch index.

rewards

uint256

Amount of reward tokens that are waiting to be swapped.

pendingVaultRewards

function pendingVaultRewards(address rewardToken, address assetToken, address vault) external view returns (uint256 batch, uint256 rewards)

Parameters

Name
Type
Description

rewardToken

address

Address of the rewards being sold.

assetToken

address

Address of the assets being purchased.

vault

address

Address of the vault with the reward to asset pair.

Return Values

Name
Type
Description

batch

uint256

Current liquidation batch index.

rewards

uint256

Amount of reward tokens that are waiting to be swapped.

purchasedAssets

function purchasedAssets(uint256 batch, address rewardToken, address assetToken, address vault) external view returns (uint256 assets)

Parameters

Name
Type
Description

batch

uint256

Liquidation batch index from the previously executed swap.

rewardToken

address

Address of the reward token that was sold.

assetToken

address

Address of the asset token that was purchased.

vault

address

Address of the vault with the reward to asset pair.

Return Values

Name
Type
Description

assets

uint256

Amount of asset tokens purchased and not yet claimed. It is zero if assets have already been claimed.

swap

function swap(address rewardToken, address assetToken, uint256 minAssets, bytes data) external returns (uint256 batch, uint256 rewards, uint256 assets)

Swap the collected rewards to desired asset.

Parameters

Name
Type
Description

rewardToken

address

Address of the rewards being sold.

assetToken

address

Address of the assets being purchased.

minAssets

uint256

Minimum amount of assets that can be returned from the swap.

data

bytes

Is specific for the swap implementation. eg 1Inch, Cowswap, Matcha...

initiateSwap

function initiateSwap(address rewardToken, address assetToken, bytes data) external returns (uint256 batch, uint256 rewards)

Swap the collected rewards to desired asset. Off-chain order must be created providing a "receiver" of the swap.

Parameters

Name
Type
Description

rewardToken

address

Address of the rewards being sold.

assetToken

address

Address of the assets being purchased.

data

bytes

Is specific for the swap implementation. eg Cowswap, Matcha...

initiateSwaps

function initiateSwaps(address[] rewardTokens, address[] assetTokens, bytes[] datas) external returns (uint256[] batchs, uint256[] rewards)

Swaps the collected rewards to desired assets. Off-chain order must be created providing a "receiver" of the swap.

Parameters

Name
Type
Description

rewardTokens

address[]

Address of the rewards being sold.

assetTokens

address[]

Address of the assets being purchased.

datas

bytes[]

Is specific for the swap implementation. eg Cowswap, Matcha...

settleSwap

function settleSwap(address rewardToken, address assetToken, uint256 assets, bytes data) external returns (uint256 batch, uint256 rewards)

settles the last batch swap of rewards for assets. initiateSwap must be called and the swap executed before settleSwap.

Parameters

Name
Type
Description

rewardToken

address

Address of the rewards being sold.

assetToken

address

Address of the assets being purchased.

assets

uint256

Amount of purchaed assets received from the swap.

data

bytes

settleSwaps

function settleSwaps(address[] rewardTokens, address[] assetTokens, uint256[] assets, bytes[] datas) external returns (uint256[] batchs, uint256[] rewards)

Swaps the collected rewards to desired assets. initiateSwap must be called first before settleSwap

Parameters

Name
Type
Description

rewardTokens

address[]

Address of the rewards being sold.

assetTokens

address[]

Address of the assets being purchased.

assets

uint256[]

Amount of assets to swapped.

datas

bytes[]

Custom data for the swap.

setSyncSwapper

function setSyncSwapper(address _syncSwapper) external

Sets a new implementation of the DEX syncSwapper.

Parameters

Name
Type
Description

_syncSwapper

address

Address of the DEX syncSwapper.

setAsyncSwapper

function setAsyncSwapper(address _asyncSwapper) external

Sets a new implementation of the DEX asyncSwapper.

Parameters

Name
Type
Description

_asyncSwapper

address

Address of the DEX asyncSwapper.

rescueToken

function rescueToken(address token, uint256 amount) external

Governor rescues tokens from the liquidator in case a vault's donateToken is failing.

Last updated