Function Templates
Ready-to-use templates for common Stratus function patterns
Overview
Check out the Function Syntax page for more information on how to create and validate Stratus functions and the Overview page before you start..
These templates are starting points. You should modify them based on your specific requirements and add appropriate error handling.
Here are some common function templates you can use as starting points for your Stratus functions. Simply copy the code and replace the placeholder values with your specific parameters.
Track Relay.Link Bridge Activity
This function rewards users for bridging assets through relay.link. Replace the constants in the first lines of the function with your actual values.
There are two core steps to this function both of which can exist as part of any function:
- It tracks all incoming transfers to the
DESTINATION_CHAIN_ID
. - It uses the Coingecko API for price tracking. It requires a minimum of 1$ worth of coins to be bridged over and the dollar amount is multiplied by the REWARD_MULTIPLIER variable.
Function Code
Transaction Entries On-Chain
Some projects prefer to host points onchain to generate transaction volume and decentralize points data. This function listens to transaction entries and mints/burns tokens based on account balance changes. It can be adjusted to any token contract.
- Click
Add New Function
- In the
Subscription
field, either select an existing Snag Subscription, or create a new one, as in the image below.
- Finally, replace the
LOYALTY_CURRENCY_ID
with your loyalty currency ID and theERC20_CONTRACT_ADDRESS
with your token contract address in the first lines. - Click
Save
and you’re good to go.
Function Code
DEX Trading Rewards
This function tracks and rewards users based on their trading volume, using Redis for persistence.
It is based on a subscription to a USDC based uniswap pool, tracking the Swap
event.
Replace the constants in the first lines of the function with your actual values.
Function Code
Usage Notes
- Replace placeholder values (marked with
YOUR_*
) with your specific parameters - Update Redis URLs with your instance details
- Adjust reward multipliers and thresholds as needed
- Test thoroughly in development before deploying to production
Remember to handle your API keys and sensitive data securely. Never commit them directly in your code.
Common Parameters to Replace
LOYALTY_RULE_ID
: Your specific loyalty rule identifierREDIS_URL
: Your Redis instance connection stringERC20_CONTRACT_ADDRESS
: The address of your token contractVOLUME_THRESHOLD
: Minimum volume required for rewardsMULTIPLIER
: Reward calculation multiplier
These templates are starting points. You should modify them based on your specific requirements and add appropriate error handling.