Skip to main content

DebtAllocator

Git Source

Inherits: Governance

Author: yearn.finance

This Debt Allocator is meant to be used alongside Yearn V3 vaults to provide the needed triggers for a keeper to perform automated debt updates for the vaults strategies.

Each vault that should be managed by this allocator will need to be added by first setting a minimumChange for the vault, which will act as the minimum amount of funds to move that will trigger a debt update. Then adding each strategy by setting a targetRatio and optionally a maxRatio. The allocator aims to allocate debt between the strategies based on their set target ratios. Which are denominated in basis points and represent the percent of total assets that specific strategy should hold (i.e 1_000 == 10% of the vaults totalAssets). The trigger will attempt to allocate up to the maxRatio when the strategy has minimumChange amount less than the targetRatio. And will pull funds to the targetRatio when it has minimumChange more than its maxRatio.*

State Variables

MAX_BPS

uint256 internal constant MAX_BPS = 10_000;

minimumWait

Time to wait between debt updates in seconds.

uint256 public minimumWait;

baseFeeProvider

Provider to read current block's base fee.

address public baseFeeProvider;

maxDebtUpdateLoss

Max loss to accept on debt updates in basis points.

uint256 public maxDebtUpdateLoss;

maxAcceptableBaseFee

Max the chains base fee can be during debt update.

uint256 public maxAcceptableBaseFee;

keepers

Mapping of addresses that are allowed to update debt.

mapping(address => bool) public keepers;

managers

Mapping of addresses that are allowed to update debt ratios.

mapping(address => bool) public managers;

_vaultConfigs

mapping(address => VaultConfig) internal _vaultConfigs;

_strategyConfigs

Mapping of vault => strategy => its config.

mapping(address => mapping(address => StrategyConfig)) internal _strategyConfigs;

Functions

onlyManagers

Make sure the caller is governance or a manager.

modifier onlyManagers();

onlyKeepers

Make sure the caller is a keeper

modifier onlyKeepers();

_isManager

Check is either factories governance or local manager.

function _isManager() internal view virtual;

_isKeeper

Check is one of the allowed keepers.

function _isKeeper() internal view virtual;

constructor

constructor() Governance(msg.sender);

initialize

Initialize the contract after being cloned.

Sets default values for the global variables.

function initialize(address _governance) external;

update_debt

Debt update wrapper for the vault.

This contract must have the DEBT_MANAGER role assigned to them. This will also uses the maxUpdateDebtLoss during debt updates to assure decreases did not realize profits outside of the allowed range.

function update_debt(address _vault, address _strategy, uint256 _targetDebt) public virtual onlyKeepers;

shouldUpdateDebt

Check if a strategy's debt should be updated.

This should be called by a keeper to decide if a strategies debt should be updated and if so by how much.

function shouldUpdateDebt(address _vault, address _strategy) public view virtual returns (bool, bytes memory);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to update.
_strategyaddressAddress of the strategy to check.

Returns

NameTypeDescription
<none>bool. Bool representing if the debt should be updated.
<none>bytes. Calldata if true or reason if false.

increaseStrategyDebtRatio

Increase a strategies target debt ratio.

setStrategyDebtRatio functions will do all needed checks.

function increaseStrategyDebtRatio(address _vault, address _strategy, uint256 _increase) external virtual;

Parameters

NameTypeDescription
_vaultaddress
_strategyaddressThe address of the strategy to increase the debt ratio for.
_increaseuint256The amount in Basis Points to increase it.

decreaseStrategyDebtRatio

Decrease a strategies target debt ratio.

function decreaseStrategyDebtRatio(address _vault, address _strategy, uint256 _decrease) external virtual;

Parameters

NameTypeDescription
_vaultaddress
_strategyaddressThe address of the strategy to decrease the debt ratio for.
_decreaseuint256The amount in Basis Points to decrease it.

setStrategyDebtRatio

Sets a new target debt ratio for a strategy.

This will default to a 20% increase for max debt.

function setStrategyDebtRatio(address _vault, address _strategy, uint256 _targetRatio) public virtual;

Parameters

NameTypeDescription
_vaultaddress
_strategyaddressAddress of the strategy to set.
_targetRatiouint256Amount in Basis points to allocate.

setStrategyDebtRatio

Sets a new target debt ratio for a strategy.

A minimumChange for that strategy must be set first. This is to prevent debt from being updated too frequently.

function setStrategyDebtRatio(address _vault, address _strategy, uint256 _targetRatio, uint256 _maxRatio)
public
virtual
onlyManagers;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault
_strategyaddressAddress of the strategy to set.
_targetRatiouint256Amount in Basis points to allocate.
_maxRatiouint256Max ratio to give on debt increases.

removeStrategy

Remove a strategy from this debt allocator.

Will delete the full config for the strategy

function removeStrategy(address _vault, address _strategy) external virtual onlyManagers;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault
_strategyaddressAddress of the address ro remove.

setMinimumChange

Set the minimum change variable for a strategy.

This is the minimum amount of debt to be added or pulled for it to trigger an update.

function setMinimumChange(address _vault, uint256 _minimumChange) external virtual onlyGovernance;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault
_minimumChangeuint256The new minimum to set for the strategy.

setPaused

Allows governance to pause the triggers.

function setPaused(address _vault, bool _status) external virtual onlyGovernance;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault
_statusboolStatus to set the paused bool to.

setMinimumWait

Set the minimum time to wait before re-updating a strategies debt.

This is only enforced per strategy.

function setMinimumWait(uint256 _minimumWait) external virtual onlyGovernance;

Parameters

NameTypeDescription
_minimumWaituint256The minimum time in seconds to wait.

setManager

Set if a manager can update ratios.

function setManager(address _address, bool _allowed) external virtual onlyGovernance;

Parameters

NameTypeDescription
_addressaddressThe address to set mapping for.
_allowedboolIf the address can call update_debt.

setMaxDebtUpdateLoss

Set the max loss in Basis points to allow on debt updates.

Withdrawing during debt updates use redeem which allows for 100% loss. This can be used to assure a loss is not realized on redeem outside the tolerance.

function setMaxDebtUpdateLoss(uint256 _maxDebtUpdateLoss) external virtual onlyGovernance;

Parameters

NameTypeDescription
_maxDebtUpdateLossuint256The max loss to accept on debt updates.

setBaseFeeProvider

Used to set our baseFeeProvider, which checks the network's current base fee price to determine whether it is an optimal time to harvest or tend. This may only be called by governance.

function setBaseFeeProvider(address _baseFeeProvider) external virtual onlyGovernance;

Parameters

NameTypeDescription
_baseFeeProvideraddressAddress of our baseFeeProvider

setMaxAcceptableBaseFee

Set the max acceptable base fee.

This defaults to max uint256 and will need to be set for it to be used. Is denominated in gwei. So 50gwei would be set as 50e9.

function setMaxAcceptableBaseFee(uint256 _maxAcceptableBaseFee) external virtual onlyGovernance;

Parameters

NameTypeDescription
_maxAcceptableBaseFeeuint256The new max base fee.

setKeeper

Set if a keeper can update debt.

function setKeeper(address _address, bool _allowed) external virtual onlyGovernance;

Parameters

NameTypeDescription
_addressaddressThe address to set mapping for.
_allowedboolIf the address can call update_debt.

getStrategyConfig

Get a strategies full config.

Used for customizations by inheriting the contract.

function getStrategyConfig(address _vault, address _strategy) public view virtual returns (StrategyConfig memory);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault
_strategyaddressAddress of the strategy.

Returns

NameTypeDescription
<none>StrategyConfigThe strategies current Config.

getVaultConfig

Get a vaults full config.

Used for customizations by inheriting the contract.

function getVaultConfig(address _vault) public view virtual returns (VaultConfig memory);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.

Returns

NameTypeDescription
<none>VaultConfigThe vaults current Config.

totalDebtRatio

Get a vaults current total debt.

function totalDebtRatio(address _vault) external view virtual returns (uint256);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault

minimumChange

Get a vaults minimum change required.

function minimumChange(address _vault) external view virtual returns (uint256);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault

isPaused

Get the paused status of a vault

function isPaused(address _vault) public view virtual returns (bool);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault

getStrategyTargetRatio

Get a strategies target debt ratio.

function getStrategyTargetRatio(address _vault, address _strategy) public view virtual returns (uint256);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault
_strategyaddressAddress of the strategy.

Returns

NameTypeDescription
<none>uint256The strategies current targetRatio.

getStrategyMaxRatio

Get a strategies max debt ratio.

function getStrategyMaxRatio(address _vault, address _strategy) public view virtual returns (uint256);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault
_strategyaddressAddress of the strategy.

Returns

NameTypeDescription
<none>uint256The strategies current maxRatio.

isCurrentBaseFeeAcceptable

Returns wether or not the current base fee is acceptable based on the maxAcceptableBaseFee.

function isCurrentBaseFeeAcceptable() public view virtual returns (bool);

Returns

NameTypeDescription
<none>bool. If the current base fee is acceptable.

Events

UpdatedBaseFeeProvider

An event emitted when the base fee provider is set.

event UpdatedBaseFeeProvider(address baseFeeProvider);

UpdateKeeper

An event emitted when a keeper is added or removed.

event UpdateKeeper(address indexed keeper, bool allowed);

UpdateMaxAcceptableBaseFee

An event emitted when the max base fee is updated.

event UpdateMaxAcceptableBaseFee(uint256 newMaxAcceptableBaseFee);

UpdateStrategyDebtRatio

An event emitted when a strategies debt ratios are Updated.

event UpdateStrategyDebtRatio(
address indexed vault,
address indexed strategy,
uint256 newTargetRatio,
uint256 newMaxRatio,
uint256 newTotalDebtRatio
);

StrategyChanged

An event emitted when a strategy is added or removed.

event StrategyChanged(address indexed vault, address indexed strategy, Status status);

UpdateMinimumChange

An event emitted when the minimum change is updated.

event UpdateMinimumChange(address indexed vault, uint256 newMinimumChange);

UpdatePaused

An even emitted when the paused status is updated.

event UpdatePaused(address indexed vault, bool indexed status);

UpdateMinimumWait

An event emitted when the minimum time to wait is updated.

event UpdateMinimumWait(uint256 newMinimumWait);

UpdateManager

An event emitted when a keeper is added or removed.

event UpdateManager(address indexed manager, bool allowed);

UpdateMaxDebtUpdateLoss

An event emitted when the max debt update loss is updated.

event UpdateMaxDebtUpdateLoss(uint256 newMaxDebtUpdateLoss);

Structs

StrategyConfig

Struct for each strategies info.

struct StrategyConfig {
bool added;
uint16 targetRatio;
uint16 maxRatio;
uint96 lastUpdate;
uint120 open;
}

VaultConfig

Struct to hold the vault's info.

struct VaultConfig {
bool paused;
uint128 minimumChange;
uint16 totalDebtRatio;
}

StrategyDebtInfo

Used during the shouldUpdateDebt to hold the data.

struct StrategyDebtInfo {
VaultConfig vaultConfig;
StrategyConfig strategyConfig;
uint256 vaultAssets;
uint256 targetDebt;
uint256 maxDebt;
uint256 currentIdle;
uint256 minIdle;
uint256 toChange;
}

Enums

Status

Status when a strategy is added or removed from the allocator.

enum Status {
NULL,
ADDED,
REMOVED
}