DeFi Saver
Search…
Triggers
A Trigger is a contract that will perform a check if certain conditions are met. It is used as a part of a Strategy to check when to execute a defined Recipe. Before executing recipe from a strategy RecipeExecutor contracts checks if every trigger in strategy is triggered and if needed rewrites some of the trigger parameters (e.g. updating to a new timestamp in the TimestampTrigger)
There is only one function that needs to be implemented and that is isTriggered() which returns a bool of the state of the trigger. When used within a strategy, all triggers need to return true for the Task to be executed.
Functions that need to be implemented are:
  • isTriggered() which returns a bool of the state of the trigger. When used within a strategy, all triggers need to return true for the Task to be executed.
  • isChangeable() which returns a bool if the trigger can have it's sub data changed during a strategy execution.
  • changedSubData() which returns bytes that the RecipeExecutor contract can overwrite the existing triggerData with. (RecipeExecutor line 116) This needs to be implemented only if isChangeable() returns true.
Triggers can accept external data from the bot caller if needed, but will generally rely on the subscription data.
Below is the interface of the TriggerInterface:
1
abstract contract ITrigger {
2
function isTriggered(bytes memory, bytes memory) public virtual returns (bool);
3
function isChangeable() public virtual returns (bool);
4
function changedSubData(bytes memory) public virtual returns (bytes memory);
5
}
6
Copied!
Last modified 1d ago
Copy link