Actions and Triggers
Simplifies blockchain app development with tools for smart accounts, blockchain interaction, and workflow management.
⚡ Actions and Triggers
Actions
Actions are the building blocks of a workflow. They are the steps that are executed by triggers. Each action has a configuration that defines how it should be executed. Here are available actions:
Uniswap Swap Action
The UniSwap swap action is an action that swaps tokens on UniSwap. It can be combined with price-based triggers to build a limit order workflow.
Configuration for UniSwap swap action:
- fromToken: Token object that represents the token from which the swap is made.
- toToken: Token object that represents the token to which the swap is made.
- fromAmount: Amount of
fromToken
that should be swapped, represented in weis multiplied by 10^fromToken.decimals. - slippagePercent: Optional parameter that determines the slippage percent, default is 0.5%.
- ProviderStrategy: Configuration for the provider used to execute the swap. It can be one of the following:
-
NodeJS provider:
{ type: 'nodejs'; rpcUrl: string; chainId: number }
-
Browser provider:
{ type: 'browser'; provider: ethers.providers.ExternalProvider }
-
Example
In this example, 1 token of fromToken
is swapped to toToken
with 0.05% slippage using the NodeJS provider strategy.
MultiSender Action
The MultiSender Action allows you to send tokens to multiple recipients in a single transaction.
Configuration for MultiSender Action:
- items: Array of objects, each representing a recipient with the address, amount, and asset.
Example
Custom Contract Call Action
The CustomContractCall
action allows you to interact with any smart contract by specifying the contract address, ABI, function name, and arguments. This action is useful for executing custom logic or interacting with contracts not directly supported by the SDK.
Configuration for Custom Contract Call Action:
- address: The address of the target contract.
- functionName: The name of the function to be called on the contract.
- abi: The ABI of the target contract.
- args: An array of arguments to be passed to the function.
- value: (Optional) The native amount to send with the call, default is
0
.
Example usage
Here is an example of a workflow that uses the CustomContractCall
action to disperse Ether to multiple recipients:
Implementing Custom Actions
Creating a custom action allows you to extend the functionality of your workflow beyond predefined actions like MultiSenderAction. You can define custom actions to interact with smart contracts or execute specific logic required for your application.
Steps to Implement a Custom Action
- Define the Configuration: Specify the parameters required for your action.
- Implement the Action Class: Create a class that implements the
CallDataBuilder
interface. - Build Call Data: Encode the function calls to interact with the blockchain.
Example SendTokens Action
The following example demonstrates how to create a custom action that sends tokens to a recipient.
Implementing custom actions allows you to tailor workflows to your specific requirements, making it possible to automate a wide range of blockchain interactions. By following the steps to define the configuration, implement the action class, and build call data, you can extend the capabilities of your workflows beyond predefined actions.
Triggers
Triggers define the conditions under which actions are executed. Here are the available triggers:
Instant Trigger
The Instant Trigger executes an action immediately without any conditions.
Example
Price-Based Trigger
A price-based trigger executes an action when the price of a specified asset meets certain conditions.
Configuration for Price-Based Trigger:
- uniswapPoolFeeTier: The fee tier of the Uniswap pool.
- triggerAtPrice: The price target that triggers the action.
- priceMustBeHigherThan: Optional boolean to specify if the price must be higher than the target price.
- fromToken: Token object representing the asset whose price is being monitored.
- toToken: Token object representing the target asset.
- ProviderStrategy: Configuration for the provider used to monitor the price.
Example
In this example, the trigger is set to execute an action when the price of the specified token is greater than 2 tokens.
Time-Based Trigger
A time-based trigger executes an action at specified intervals.
Configuration for Time-Based Trigger:
- startAtTimestamp: Unix timestamp when the trigger should start.
- repeatTimes: Optional number of times the trigger should repeat.
- cycle: Object defining the frequency and scale (e.g., minutes, hours, days) of the trigger.
- ProviderStrategy: Configuration for the provider used to manage the time-based execution.
Example
In this example, the trigger is set to execute an action every hour, starting in one hour, and will repeat 10 times.
Try this with our npm packages and check out more on GitHub.