DeFi Saver
Search…
Actions
An Action is a contract that will perform a specific operation. In the context of DeFi, that includes actions such as supplying an asset, making a token swap, making a deposit, etc.
Actions are registered in the DFSRegistry and can be combined into recipes. Actions are always called through a DSProxy and cannot hold any state. There are currently only two types of actions: Standard action and FlashLoan action. We need to differentiate between these, as they will have different execution paths in the RecipeExecutor.
When calling a FlashLoan action, it only makes sense to call them as part of a Recipe. You also need to add an extra empty input in the callData if it's a FlashLoan action.
Each action should inherit the ActionBase contract, which implements a standard interface to call the actions and some helper functions or contracts to make development easier. Actions can be called directly through a DSProxy with executeActionDirect() which takes an array of bytes representing the inputs of that action. Each action can have different inputs and in order to keep a universal interface, all the inputs are converted into a bytes array before calling. Action always returns one bytes32 value, which can later be used as input for other actions.
While a single Action can be executed as a Recipe through the RecipeExecutor, it is more gas efficient to call a single Action directly when needed.
Each action should also produce a log message in the standard DFSLogger.
Actions can be bundled into Recipes, which can then be executed manually or as part of a Strategy. Because of this, some of the inputs of an Action can be hardcoded in Subscription data or it can be an output of a different Action. That's why when an Action is executed inside of a recipe a different function is used executeAction(). Here subData is passed along as well as paramMapping data and returnValues from previous functions.

Return values and subscription data mapping

paramMapping is an array of uint8 values representing if any inputs of the actions need to be switched out, either with subData or by returnValues.
If the value is 0, this means the inputs are used and not modified. Values in the range of [1-127] are used for returnValues mapping, meaning that 1 means the return value of the first action, 2 represents the second action return values, etc... going up to 127.
If values are in the [127-255] range that means that the Subscriptions subData is used to replace inputs, following the same logic as return values in how they are mapped.
The last values in the subData range, 254 and 255 are 'reserved'. That means that the ActionBase contract and the related parseParam methods will inject for 254 the address of the DSProxy of the caller and on 255 will inject the address of the owner of the proxy.
1
// Mapping example
2
// In an action that has 3 inputs, the first two are not changed
3
// and the third one will be changed with the return value of the second action
4
[0, 0, 2]
Copied!
Below is the interface of the ActionBase:
1
contract ActionBase {
2
3
enum ActionType { FL_ACTION, STANDARD_ACTION, FEE_ACTION, CHECK_ACTION, CUSTOM_ACTION }
4
5
/// @notice Parses inputs and runs the implemented action through a proxy
6
/// @dev Is called by the RecipeExecutor chaining actions together
7
/// @param _callData Array of input values each value encoded as bytes
8
/// @param _subData Array of subscribed vales, replaces input values if specified
9
/// @param _paramMapping Array that specifies how return and subscribed values are mapped in input
10
/// @param _returnValues Returns values from actions before, which can be injected in inputs
11
/// @return Returns a bytes32 value through DSProxy, each actions implements what that value is
12
function executeAction(
13
bytes memory _callData,
14
bytes32[] memory _subData,
15
uint8[] memory _paramMapping,
16
bytes32[] memory _returnValues
17
) public payable virtual returns (bytes32);
18
19
/// @notice Parses inputs and runs the single implemented action through a proxy
20
/// @dev Used to save gas when executing a single action directly
21
function executeActionDirect(bytes memory _callData) public virtual payable;
22
23
/// @notice Returns the type of action we are implementing
24
function actionType() public pure virtual returns (uint8);
25
}
Copied!
Last modified 1d ago