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 | Address |
---|---|
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
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 |
rewards | uint256[][] | Amount of reward tokens collected for each vault. The first dimension is vault from the |
purchaseTokens | address[][] | The token to purchase for each of the rewards. The first dimension is vault from the |
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
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 |
claimAssets
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 |
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
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
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
Parameters
Name | Type | Description |
---|---|---|
batch | uint256 | Liquidation batch index from the previously executed |
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
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
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
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
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
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
Sets a new implementation of the DEX syncSwapper.
Parameters
Name | Type | Description |
---|---|---|
_syncSwapper | address | Address of the DEX syncSwapper. |
setAsyncSwapper
Sets a new implementation of the DEX asyncSwapper.
Parameters
Name | Type | Description |
---|---|---|
_asyncSwapper | address | Address of the DEX asyncSwapper. |
rescueToken
Governor rescues tokens from the liquidator in case a vault's donateToken is failing.
Last updated