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 that implements on-chain swaps
asyncSwapper
Contract that implements on-chain async swaps
Functions
collectRewards
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
vaults
address[]
List of vault addresses to collect rewards from.
Return Values
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
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
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
assets
uint256[]
Amount of asset tokens purchased for each different vault in the vaults
parameter.
claimAssets
Vault claims the purchased assets in a batch back. Separate transactions are required if a vault has multiple reward tokens.
Parameters
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
assets
uint256
Amount of asset tokens purchased in the batch.
pendingRewards
Parameters
rewardToken
address
Address of the rewards being sold.
assetToken
address
Address of the assets being purchased.
Return Values
batch
uint256
Current liquidation batch index.
rewards
uint256
Amount of reward tokens that are waiting to be swapped.
pendingVaultRewards
Parameters
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
batch
uint256
Current liquidation batch index.
rewards
uint256
Amount of reward tokens that are waiting to be swapped.
purchasedAssets
Parameters
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
assets
uint256
Amount of asset tokens purchased and not yet claimed. It is zero if assets have already been claimed.
swap
Swap the collected rewards to desired asset.
Parameters
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
Swap the collected rewards to desired asset. Off-chain order must be created providing a "receiver" of the swap.
Parameters
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
Swaps the collected rewards to desired assets. Off-chain order must be created providing a "receiver" of the swap.
Parameters
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
settles the last batch swap of rewards for assets. initiateSwap
must be called and the swap executed before settleSwap
.
Parameters
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
Swaps the collected rewards to desired assets. initiateSwap must be called first before settleSwap
Parameters
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
Sets a new implementation of the DEX syncSwapper.
Parameters
_syncSwapper
address
Address of the DEX syncSwapper.
setAsyncSwapper
Sets a new implementation of the DEX asyncSwapper.
Parameters
_asyncSwapper
address
Address of the DEX asyncSwapper.
rescueToken
Governor rescues tokens from the liquidator in case a vault's donateToken is failing.
Last updated