Program condition trigger is a highly flexible trigger that lets you execute automations when one or more arbitrary conditions are met. You can use Snowflake prebuilt checker actions or develop your own custom checkers.

Use Snowflake prebuilt checker actions

Snowflake ships with prebuilt checker actions to get you started and we will continue to expand this set over time. To illustrate how this works, consider the following example:

As a user, I would like to purchase SOL using Orca when SOL/USDC price is below 150.

We cannot use time trigger in this scenario, since we don't know when the above price condition will become true. Instead, we are going to setup a program condition trigger automation with Snowflake Price Checker action, like so.

As you can see, the first action in this flow is Price Check action which leverages Pyth Oracle to check for the price of SOL/USD and ensures that the automation will only execute when SOL/USD price is less than or equal to 150.

This becomes even more powerful since Snowflake allows you to chain multiple actions in one flow. For example, let's say the user wants to buy SOL automatically when the price is good but also want to keep a maximum cap on her exposure to SOL.

As a user, I would like to purchase SOL using Orca when SOL/USDC price is below 150 and my SOL balance is below 100.

The above can be achieved simply by adding an additional balance check action between action 1 and action 2. The flow becomes: price check => balance check => swap.

Develop your own custom checkers

Prebuilt checker action is great but what if I want to check for an arbitrary condition in a specific program that Snowflake doesn't even know about? Snowflake takes this a step further and let you define your own custom checkers. Let's explore how this works.

A custom checker is simply a custom action that might return an error.

To illustrate how this works, let's go through a simple use case:

As a user, I want to buy SOL when my holding of USDC is above 20,000.

Holding check is common enough that will soon be available as a prebuilt checker but let's assume the developer wants to code her own action in this particular case. Basically, the developer would code a program that returns an error if the token holding is below a minimum amount, like so.

#[program]
mod holding_check {
pub fn check(ctx: Context<HoldingCheck>, min_amount : u64)
-> ProgramResult {
let token_account = &ctx.accounts.token_account;
let amount = token::accessor::amount(token_account)?;
if amount < min_amount {
return Err(ProgramError::Custom(102));
}
Ok(())
}
}

#[derive(Accounts)]
pub struct HoldingCheck<'info> {
token_account : Account<'info, TokenAccount>
}

Once deployed, the above program can be hooked up to Snowflake as a custom action, like so.

Action 1 is a custom checker action that invokes the holding checker program written by the developer deployed at address ETwB...gAC. Instruction 74b...22a encapsulates the min amount and Account 1 represents the token account to be checked against.

Simply save the automation and let Snowflake network takes care of monitoring and executing this transaction for you when the right condition is met.


We'd love to make Snowflake even easier and more delightful for our users to build on and would love any feedback you might have. Please feel free to hit our team using the messenger below.

Did this answer your question?