Action Smart Contracts

Action smart contracts are the fundamental building blocks of the Brava system. They represent individual, atomic operations that can be performed within various DeFi protocols. The Action contract concept is designed to provide modularity, flexibility, and composability to the system.

Action Characteristics

Action contracts in the Brava system have the following key characteristics:

  • Modularity: Each contract encapsulates a specific operation for a particular protocol, allowing for easier maintenance, upgrades, and addition of new functionalities.

  • Unified Interface: All contracts implement a common interface with the executeAction function, enabling uniform interaction with the SequenceExecutor.

  • Protocol-specific: Organized by protocol for clear separation and management of different DeFi integrations.

  • Stateless: Perform operations based on input parameters and current blockchain state, without maintaining persistent state.

  • Delegate Call Execution: Executed via delegate calls from the SequenceExecutor, operating in the context of the user's Safe wallet.

  • Parametrized: Define their own set of parameters for execution, providing flexibility in handling different types of operations.

  • Centralized Logging: Use a centralized Logger contract to emit events, ensuring consistent and organized event handling across the system.

Implementation Pattern

Action contracts typically follow this pattern:

  1. Inherit from ActionBase, which provides common functionality and interface.

  2. Define a Params struct to encapsulate the action-specific parameters.

  3. Implement the executeAction function, which:

    • Parses the input data

    • Performs necessary checks and validations

    • Executes the core logic of the action

    • Logs relevant events through the Logger contract

  4. Implement the actionType function to return the specific type of action.

Interaction with SequenceExecutor

The SequenceExecutor interacts with Action contracts in the following way:

  1. The SequenceExecutor receives a sequence of actions to execute.

  2. For each action in the sequence:

    • The SequenceExecutor retrieves the action address from the AdminVault using the action ID.

    • It then performs a delegate call to the action contract's executeAction function, passing the necessary parameters.

    • The action is executed in the context of the user's Safe wallet.

    • Any state changes or external calls are made as if they were initiated by the Safe wallet itself.

This interaction pattern ensures that actions are executed securely and maintain the user's custody of funds throughout the process.

Action Types

The actionType function in each Action contract plays a critical role in the security and functionality of the Brava system. It returns a specific type identifier for each action, which serves several important purposes:

Security and Access Control

  1. Fee-taking Bot Restrictions:

    • A fee-taking bot, operating through a Safe module, is restricted to calling only actions with the "Deposit" type.

    • This restriction ensures that even if the bot were to pass non-zero parameters to an action, it could only result in giving funds to the user, not taking them away.

    • This mechanism provides a robust safeguard against unauthorized fund extraction.

  2. Send Tokens Action:

    • The "SendTokens" action type is unique and highly sensitive, as it's the only action that allows funds to be transferred away from the user's Safe without expecting a return from a protocol.

    • This action type should only be triggered directly by the user to withdraw funds from the system.

    • Fee-taking bots and other automated processes are explicitly prohibited from using this action type.

Error Reporting and Logging

  1. Context-Aware Errors:

    • Due to the delegate call execution model, the logic being executed isn't inherently aware of its context within the user's Safe.

    • The actionType, along with protocol names in each action, allows for more informative error reporting and logging.

    • Errors can include specific information about which action and protocol were involved, greatly aiding in debugging and user support.

  2. Enhanced Traceability:

    • The action type provides an additional layer of traceability in logs and events.

    • This improves system transparency and aids in auditing and monitoring system behavior.

Implementation

Action contracts implement the actionType function to return a specific identifier. For example:

function actionType() public pure virtual override returns (ActionType) {
    return ActionType.Deposit;
}

Possible action types include, but are not limited to:

  • Deposit

  • Withdraw

  • Swap

  • SendTokens

  • PurchaseCover

Importance in System Design

The action type system is a crucial part of Brava's security architecture. It provides:

  1. A mechanism for fine-grained access control.

  2. Enhanced error reporting and system transparency.

  3. A clear delineation of action capabilities, especially for sensitive operations like fund transfers.

Developers and integrators should pay close attention to action types when designing new actions or interacting with the system, as they play a key role in maintaining the security and integrity of user funds.

Security Considerations

  • The AdminVault controls which actions are available, providing an additional layer of security.

  • Delegate calls ensure that actions operate within the user's wallet context, maintaining fund custody.

  • While actions can be called directly, they are designed to be most effective when used through the SequenceExecutor as part of the Brava system.

  • The action type system provides fine-grained control over what operations can be performed by different parts of the system, enhancing overall security.

Extensibility

The modular nature of Action contracts allows for easy addition of new DeFi protocols and operations:

  1. Develop a new Action contract for the desired protocol or operation.

  2. Deploy the new Action contract.

  3. Register the new action with the AdminVault.

  4. The new action is now available for use in sequences.

This process enables the Brava system to quickly adapt to new DeFi opportunities and protocols.

Conclusion

Action smart contracts form the core of Brava's modular and extensible architecture, enabling complex DeFi operations to be composed from simple, reusable building blocks. This design promotes flexibility, upgradability, and gas efficiency in executing multi-step DeFi strategies.

Last updated