Skip to main content

CommonTrigger

Git Source

Inherits: Governance

Title: Common Trigger

Author: Yearn.finance

This is a central contract that keepers can use to decide if Yearn V3 strategies should report profits, when V3 Vaults should record a strategies profits, and when strategies that implement auctions should kick off an auction. It allows for a simple default flow that most strategies and vaults can use for easy integration with a keeper network. However, it is also customizable by the strategy and vaults management to allow complete customization if desired.

State Variables​

name​

string public name = "Yearn Common Trigger"

LEGACY_REPORT_TRIGGER​

address public constant LEGACY_REPORT_TRIGGER = 0xA045D4dAeA28BA7Bfe234c96eAa03daFae85A147

baseFeeProvider​

address public baseFeeProvider

acceptableBaseFee​

uint256 public acceptableBaseFee

customStrategyTrigger​

mapping(address => address) public customStrategyTrigger

customStrategyBaseFee​

mapping(address => uint256) public customStrategyBaseFee

customVaultTrigger​

mapping(address => mapping(address => address)) public customVaultTrigger

customVaultBaseFee​

mapping(address => mapping(address => uint256)) public customVaultBaseFee

customAuctionTrigger​

mapping(address => address) public customAuctionTrigger

minimumAmountToKick​

mapping(address => mapping(address => uint256)) public minimumAmountToKick

Functions​

constructor​

constructor(address _governance) Governance(_governance);

setCustomStrategyTrigger​

Set a custom report trigger contract for a strategy.

This gives the management of a specific strategy the option to enforce a custom report trigger for their strategy easily while still using this standard contract for keepers to read the trigger status from. The custom trigger contract only needs to implement the reportTrigger function to return true or false.

function setCustomStrategyTrigger(address _strategy, address _trigger) external virtual;

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to set the trigger for.
_triggeraddressThe address of the custom trigger contract.

setCustomStrategyBaseFee​

Set a custom base fee for a specific strategy.

This can be set by a strategies management to increase or decrease the acceptable network base fee for a specific strategies trigger to return true. This can be used instead of a custom trigger contract. This will have no effect if a custom trigger is set for the strategy.

function setCustomStrategyBaseFee(address _strategy, uint256 _baseFee) external virtual;

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to customize.
_baseFeeuint256The max acceptable network base fee.

setCustomVaultTrigger​

Set a custom report trigger contract for a vaults strategy.

This gives the management of a vault the option to enforce a custom report trigger for a specific strategy attached to the vault while still using this standard contract for keepers to read the trigger status from. The address calling must have the REPORTING_MANAGER role on the vault. The custom trigger contract only needs to implement the reportTrigger function to return true or false.

function setCustomVaultTrigger(address _vault, address _strategy, address _trigger) external virtual;

Parameters

NameTypeDescription
_vaultaddressThe address of the vault
_strategyaddressThe address of the strategy to set the trigger for.
_triggeraddressThe address of the custom trigger contract.

setCustomVaultBaseFee​

Set a custom base fee for a vaults strategy.

This can be set by the vaults management to increase or decrease the acceptable network base fee for a specific strategies trigger to return true. This can be used instead of a custom trigger contract. This will have no effect if a custom trigger is set for the strategy. The address calling must have the REPORTING_MANAGER role on the vault.

function setCustomVaultBaseFee(address _vault, address _strategy, uint256 _baseFee) external virtual;

Parameters

NameTypeDescription
_vaultaddressThe address of the vault.
_strategyaddressThe address of the strategy to customize.
_baseFeeuint256The max acceptable network base fee.

setCustomAuctionTrigger​

Set a custom auction trigger contract for a strategy.

This gives the management of a specific strategy the option to enforce a custom auction trigger for their strategy easily while still using this standard contract for keepers to read the trigger status from. The custom trigger contract only needs to implement the auctionTrigger function to return true or false with bytes reason.

function setCustomAuctionTrigger(address _strategy, address _trigger) external virtual;

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to set the trigger for.
_triggeraddressThe address of the custom trigger contract.

setMinimumAmountToKick​

Set a minimum amount of tokens required to kick an auction.

This gives the management of a specific strategy the option to set a minimum balance threshold that must be met before an auction can be kicked for a specific token.

function setMinimumAmountToKick(address _strategy, address _token, uint256 _amount) external virtual;

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to set the minimum for.
_tokenaddressThe address of the token, or address(0) for global minimum.
_amountuint256The minimum amount of tokens required to kick an auction.

strategyReportTrigger​

Returns wether or not a strategy is ready for a keeper to call report.

Will first check if a custom trigger is set. If not it will use the default trigger flow.

function strategyReportTrigger(address _strategy) external view virtual returns (bool, bytes memory);

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to check the trigger for.

Returns

NameTypeDescription
<none>bool. Bool representing if the strategy is ready to report.
<none>bytes. Bytes with either the calldata or reason why False.

defaultStrategyReportTrigger​

The default trigger logic for a strategy.

This is kept in a separate function so it can still be used by custom triggers even if extra checks are needed first or after. This will also check if a custom acceptable base fee has been set by the strategies management. In order for the default flow to return true the strategy must:

  1. Not be shutdown.
  2. Have funds.
  3. The current network base fee be below the acceptableBaseFee.
  4. The time since the last report be > the strategies profitMaxUnlockTime.
function defaultStrategyReportTrigger(address _strategy) public view virtual returns (bool, bytes memory);

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to check the trigger for.

Returns

NameTypeDescription
<none>bool. Bool representing if the strategy is ready to report.
<none>bytes. Bytes with either the calldata or reason why False.

vaultReportTrigger​

Return wether or not a report should be called on a vault for a specific strategy.

Will first check if a custom trigger is set. If not it will use the default trigger flow.

function vaultReportTrigger(address _vault, address _strategy) external view virtual returns (bool, bytes memory);

Parameters

NameTypeDescription
_vaultaddressThe address of the vault.
_strategyaddressThe address of the strategy to report.

Returns

NameTypeDescription
<none>bool. Bool if the strategy should report to the vault.
<none>bytes. Bytes with either the calldata or reason why False.

defaultVaultReportTrigger​

The default trigger logic for a vault.

This is kept in a separate function so it can still be used by custom triggers even if extra checks are needed before or after. This will also check if a custom acceptable base fee has been set by the vault management for the _strategy. In order for the default flow to return true:

  1. The vault must not be shutdown.
  2. The strategy must be active and have debt allocated.
  3. The current network base fee be below the acceptableBaseFee.
  4. The time since the strategies last report be > the vaults profitMaxUnlockTime.
function defaultVaultReportTrigger(address _vault, address _strategy)
public
view
virtual
returns (bool, bytes memory);

Parameters

NameTypeDescription
_vaultaddressThe address of the vault.
_strategyaddressThe address of the strategy to report.

Returns

NameTypeDescription
<none>bool. Bool if the strategy should report to the vault.
<none>bytes. Bytes with either the calldata or reason why False.

strategyTendTrigger​

Return whether or not a strategy should be tended by a keeper.

This can be used as an easy keeper integration for any strategy that implements a tendTrigger. It is expected that a strategy implement all needed checks such as isShutdown, totalAssets > 0 and base fee checks within the trigger.

function strategyTendTrigger(address _strategy) external view virtual returns (bool, bytes memory);

Parameters

NameTypeDescription
_strategyaddressAddress of the strategy to check.

Returns

NameTypeDescription
<none>bool. Bool if the strategy should be tended.
<none>bytes. Bytes with the calldata.

getCurrentBaseFee​

Returns the current base fee from the provider.

Will return 0 if a base fee provider is not set.

function getCurrentBaseFee() public view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256. The current base fee for the chain.

isCurrentBaseFeeAcceptable​

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

Can be used in custom triggers to easily still use this contracts fee provider and acceptableBaseFee. And makes it backwards compatible to V2. Will always return true if no baseFeeProvider is set.

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

Returns

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

auctionTrigger​

Returns whether or not an auction should be kicked for a strategy.

Will first check if a custom trigger is set. If not it will attempt to call auctionTrigger on the strategy itself. If that fails, it will return false with the error message. This function uses try-catch to ensure it never reverts at the top level.

function auctionTrigger(address _strategy, address _from) external view virtual returns (bool, bytes memory);

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to check the trigger for.
_fromaddressThe address of the token to be auctioned.

Returns

NameTypeDescription
<none>bool. Bool representing if the auction should be kicked.
<none>bytes. Bytes with either the calldata or reason why False.

defaultAuctionTrigger​

The default trigger logic for a strategy auction.

This attempts to call auctionTrigger(address) on the strategy itself. If the strategy implements this function, it will use that logic. If not, or if it reverts, it will return false. This will also check if a custom acceptable base fee has been set by the strategies management.

function defaultAuctionTrigger(address _strategy, address _from) public view virtual returns (bool, bytes memory);

Parameters

NameTypeDescription
_strategyaddressThe address of the strategy to check the trigger for.
_fromaddressThe address of the token to be auctioned.

Returns

NameTypeDescription
<none>bool. Bool representing if the auction should be kicked.
<none>bytes. Bytes with either the calldata or reason why False.

_getCustomStrategyTrigger​

Internal function to get custom strategy trigger with legacy fallback.

function _getCustomStrategyTrigger(address _strategy) internal view returns (address);

_getCustomStrategyBaseFee​

Internal function to get custom strategy base fee with legacy fallback.

function _getCustomStrategyBaseFee(address _strategy) internal view returns (uint256);

_getCustomVaultTrigger​

Internal function to get custom vault trigger with legacy fallback.

function _getCustomVaultTrigger(address _vault, address _strategy) internal view returns (address);

_getCustomVaultBaseFee​

Internal function to get custom vault base fee with legacy fallback.

function _getCustomVaultBaseFee(address _vault, address _strategy) internal view returns (uint256);

_getFromLegacy​

function _getFromLegacy(bytes memory _data) internal view returns (bytes memory);

_getCustomAuctionTrigger​

Internal function to get custom auction trigger - no legacy fallback since this is new.

function _getCustomAuctionTrigger(address _strategy) internal view returns (address);

_getMinimumAmountToKick​

Internal function to get minimum amount to kick for a strategy-token pair. First checks for specific token minimum, then falls back to global minimum.

function _getMinimumAmountToKick(address _strategy, address _token) internal view returns (uint256);

setBaseFeeProvider​

Sets the address used to pull the current network base fee.

Throws if the caller is not current governance.

function setBaseFeeProvider(address _baseFeeProvider) external virtual onlyGovernance;

Parameters

NameTypeDescription
_baseFeeProvideraddressThe network's baseFeeProvider address.

setAcceptableBaseFee​

Sets the default acceptable current network base fee.

Throws if the caller is not current governance.

function setAcceptableBaseFee(uint256 _newAcceptableBaseFee) external virtual onlyGovernance;

Parameters

NameTypeDescription
_newAcceptableBaseFeeuint256The acceptable network base fee.

Events​

NewBaseFeeProvider​

event NewBaseFeeProvider(address indexed provider);

UpdatedAcceptableBaseFee​

event UpdatedAcceptableBaseFee(uint256 acceptableBaseFee);

UpdatedCustomStrategyTrigger​

event UpdatedCustomStrategyTrigger(address indexed strategy, address indexed trigger);

UpdatedCustomStrategyBaseFee​

event UpdatedCustomStrategyBaseFee(address indexed strategy, uint256 acceptableBaseFee);

UpdatedCustomVaultTrigger​

event UpdatedCustomVaultTrigger(address indexed vault, address indexed strategy, address indexed trigger);

UpdatedCustomVaultBaseFee​

event UpdatedCustomVaultBaseFee(address indexed vault, address indexed strategy, uint256 acceptableBaseFee);

UpdatedCustomAuctionTrigger​

event UpdatedCustomAuctionTrigger(address indexed strategy, address indexed trigger);

UpdatedMinimumAmountToKick​

event UpdatedMinimumAmountToKick(address indexed strategy, address indexed token, uint256 amount);