Overview
The Spell class is created using thedsa.Spell() method and provides a fluent interface for building and executing transaction sequences across DeFi protocols. Spells denote a sequence of connector functions that achieve a specific use case.
Creating a Spell Instance
Create a spell instance to start building transaction sequences:Spell() method returns an extended Spells class instance with additional methods for casting and encoding transactions.
Available Methods
The Spell instance provides the following methods:add()
Add a connector function to the spell sequence. Returns the spell instance for method chaining. View detailed add() documentationcast()
Execute the spell sequence as a transaction on the blockchain. Returns the transaction hash. View detailed cast() documentationestimateCastGas()
Estimate the gas required to execute the spell sequence.Optional parameters for gas estimation
Estimated gas units required for the transaction
encodeCastABI()
Encode the spell sequence into transaction calldata without executing it.Optional parameters for ABI encoding
Hex-encoded transaction calldata
encodeSpells()
Encode the spell data into the internal format used by DSA contracts.Object containing targets and encoded spell data
convertToAvocadoActions()
Convert the spell sequence to Avocado-compatible actions format.Array of actions in Avocado format
Example Usage
Basic Spell Chain
Complex Multi-Protocol Transaction
Properties
Array of spell objects added to the instance
Notes
- The Spell instance uses method chaining for a fluent API
- All methods except
cast()return the spell instance for chaining - Spells are not executed until
cast()is called - The spell sequence is atomic - either all operations succeed or all fail
- Make sure your DSA has sufficient balance before casting spells