What is Venus?

Venus is Rialo's embedded DSL for writing workflow programs � on-chain programs that can pause, wait for conditions, react to external data, and resume, all without off-chain infrastructure. It compiles to Solana program calls on Rialo's SVM layer via the rialo-venus-dsl crate.

The core idea: async operations that would normally require a keeper bot, oracle, or scheduler are expressed as language keywords. The protocol handles the scheduling, resource analysis, and account management automatically.

??
Design philosophy

Venus was designed so that a developer familiar with async JavaScript or Rust's async/await can read and understand an on-chain workflow program without knowing anything about blockchain internals. The DSL handles account allocation, serialization, and scheduling; you write business logic.

Program structure

Every Venus program is wrapped in a rialo! macro and has two required sections:

rust
rialo! {
    // 1. Persistent on-chain state
    state {
        field_name: Type,
        // ...
    }

    // 2. Program logic � functions and async workflows
    program {
        // regular functions, AFTER, EVERY, ON, SEND, START
    }
}

The state { } block defines a workflow state � a persistent data structure that survives across async operations and transaction boundaries. The Venus compiler automatically calculates the required Solana accounts based on your state and async operations.

AFTER � one-shot delay

AFTER <duration> => <function>() schedules a function to run once after a specified delay. This is a protocol-level timer � no cron job, no hosted bot.

rust
rialo! {
    state {
        owner: Pubkey,
        amount: u64,
        locked_until: i64,
    }

    program {
        // Lock funds for 30 days, then auto-release
        fn lock_funds(ctx: Context, amount: u64) {
            state.amount = amount;
            state.locked_until = Clock::get().unix_timestamp + 30 * 86400;
            AFTER 30d => release_funds();
        }

        fn release_funds() {
            transfer(state.owner, state.amount);
            state.amount = 0;
        }
    }
}

Supported duration units: s (seconds), m (minutes), h (hours), d (days).

EVERY � recurring timer

EVERY <duration> => <function>() schedules a function to run repeatedly on a fixed interval. The scheduler is managed by the protocol � once registered, it runs indefinitely until explicitly cancelled.

rust
rialo! {
    state {
        portfolio_value: u64,
        rebalance_threshold: u64,
    }

    program {
        // Check portfolio balance every hour
        EVERY 1h => check_and_rebalance();

        fn check_and_rebalance() {
            let current = price_feed::get("ETH/USD") * state.portfolio_value;
            if current < state.rebalance_threshold {
                SEND trigger_rebalance();
            }
        }

        fn trigger_rebalance() {
            // rebalance logic here
            emit!(PortfolioRebalanced { value: state.portfolio_value });
        }
    }
}

ON � event trigger

ON <event_source> => <function>() registers a reactive handler that fires when a specific event occurs. Events can come from other on-chain programs, native price feeds, or cross-chain signals.

rust
rialo! {
    state {
        liquidation_price: u64,
        position_size: u64,
    }

    program {
        // React when BTC price drops below liquidation threshold
        ON price_feed::below("BTC/USD", state.liquidation_price)
            => liquidate_position();

        // React to an event from another program
        ON other_program::SettlementComplete
            => process_settlement(event.amount);

        fn liquidate_position() {
            // close the position
            emit!(PositionLiquidated { size: state.position_size });
            state.position_size = 0;
        }

        fn process_settlement(amount: u64) {
            state.position_size += amount;
        }
    }
}

SEND � async message

SEND <function>() enqueues an async call to another function or program. Unlike a direct function call, SEND is non-blocking � execution continues immediately while the message is delivered asynchronously. This is how you coordinate between workflows without blocking the caller.

rust
rialo! {
    state { order_id: u64, status: OrderStatus }

    program {
        fn place_order(ctx: Context, amount: u64) {
            state.order_id = generate_id();
            state.status = OrderStatus::Pending;

            // Non-blocking � caller gets a response immediately
            SEND notify_user(ctx.signer, state.order_id);
            SEND execute_trade(amount);
        }

        fn notify_user(user: Pubkey, order_id: u64) {
            // Send encrypted notification to user's device
            messaging::send(user, format!("Order {} placed", order_id));
        }

        fn execute_trade(amount: u64) {
            // execute logic
            state.status = OrderStatus::Filled;
        }
    }
}

START � spawn workflow

START <workflow>(args) instantiates a new independent workflow instance. Each instance has its own isolated state. This is useful for per-user or per-order workflows that run in parallel without sharing state.

rust
rialo! {
    state { active_escrows: u32 }

    program {
        // Each call to open_escrow spawns a fresh, isolated escrow workflow
        fn open_escrow(
            ctx: Context,
            buyer: Pubkey,
            seller: Pubkey,
            amount: u64,
            deadline: i64,
        ) {
            state.active_escrows += 1;
            START EscrowWorkflow {
                buyer,
                seller,
                amount,
                deadline,
            };
        }
    }
}

// Separate workflow definition � each instance is independent
rialo! {
    state {
        buyer: Pubkey,
        seller: Pubkey,
        amount: u64,
        deadline: i64,
        released: bool,
    }

    program {
        fn release(ctx: Context) {
            require!(ctx.signer == state.buyer, ErrorCode::Unauthorized);
            transfer(state.seller, state.amount);
            state.released = true;
        }

        // Auto-refund buyer if deadline passes without release
        AFTER state.deadline => auto_refund();

        fn auto_refund() {
            if !state.released {
                transfer(state.buyer, state.amount);
            }
        }
    }
}

Function types

Venus distinguishes four categories of functions inside a program { } block:

TypeDescriptionCalled by
InitiatingEntry point � starts a workflow or handles a user callExternal transaction
HandlerResponds to an async trigger (AFTER, EVERY, ON, SEND)Protocol scheduler / event system
InternalHelper function, not callable externallyOther functions in the same program
TerminatingFinal function that closes the workflow and releases accountsAny, once terminal condition is met

Error handling

Venus programs use require! for guard conditions and define custom error codes with the #[error_code] attribute:

rust
#[error_code]
pub enum ErrorCode {
    #[msg("You are not authorized to perform this action")]
    Unauthorized,
    #[msg("Deadline has already passed")]
    DeadlinePassed,
    #[msg("Insufficient funds")]
    InsufficientFunds,
}

rialo! {
    state { owner: Pubkey, balance: u64 }

    program {
        fn withdraw(ctx: Context, amount: u64) {
            require!(ctx.signer == state.owner, ErrorCode::Unauthorized);
            require!(state.balance >= amount, ErrorCode::InsufficientFunds);
            state.balance -= amount;
            transfer(ctx.signer, amount);
        }
    }
}

Full example � subscription billing

A real-world example: an automated recurring subscription that charges a user monthly, sends a notification, and cancels gracefully if payment fails.

rust
use rialo_cdk::prelude::*;
use rialo_venus_dsl::rialo;

#[error_code]
pub enum SubscriptionError {
    #[msg("Payment failed � insufficient balance")]
    PaymentFailed,
    #[msg("Subscription already cancelled")]
    AlreadyCancelled,
}

rialo! {
    state {
        subscriber:  Pubkey,
        provider:    Pubkey,
        amount:      u64,
        active:      bool,
        paid_cycles: u32,
    }

    program {
        // Initiating function � user calls this to start a subscription
        fn subscribe(ctx: Context, provider: Pubkey, amount: u64) {
            state.subscriber  = ctx.signer;
            state.provider    = provider;
            state.amount      = amount;
            state.active      = true;
            state.paid_cycles = 0;
            EVERY 30d => charge_cycle();
        }

        // Handler � runs every 30 days
        fn charge_cycle() {
            if !state.active { return; }

            let balance = token::balance(state.subscriber);
            if balance < state.amount {
                state.active = false;
                SEND notify_cancellation();
                return;
            }

            token::transfer(state.subscriber, state.provider, state.amount);
            state.paid_cycles += 1;
            SEND send_receipt(state.paid_cycles);
        }

        fn send_receipt(cycle: u32) {
            messaging::send(
                state.subscriber,
                format!("Subscription payment #{} processed", cycle),
            );
        }

        fn notify_cancellation() {
            messaging::send(
                state.subscriber,
                "Your subscription was cancelled due to insufficient funds.".into(),
            );
        }

        // User can cancel any time
        fn cancel(ctx: Context) {
            require!(ctx.signer == state.subscriber, SubscriptionError::AlreadyCancelled);
            state.active = false;
            emit!(SubscriptionCancelled { subscriber: state.subscriber });
        }
    }
}

#[event]
pub struct SubscriptionCancelled { pub subscriber: Pubkey }