Technical

Smart Contracts

AutoPilot is built on a modular Soroban smart contract architecture written in Rust. The core protocol acts as an on-chain Registry, Vault Manager, and Rules Engine.

Deployed Contract

The AutopilotProtocol contract is deployed on the Stellar Testnet:
Contract ID: CAYEKPHSHVIS5X2WXI5ACBBLSGCFRORNCQKVUBXTH5SGQTVSBNPFA3QR

Core Functions

The contract exposes several key capabilities directly on-chain:

  • Vault Creation: Users create on-chain vaults to hold funds securely.
  • Rule Storage: AI-generated rules are stored immutably on-chain.
  • Keeper Execution: The backend acts as a keeper, invoking execute_rule on-chain where limits and authorizations are enforced.

Keeper Execution Flow (Phase 4)

Instead of the backend sending payments directly, AutoPilot uses the backend as a Keeper. When an off-chain event occurs (e.g. salary received), the keeper invokes the Soroban contract.

typescript
// backend/src/stellar/soroban.ts
const invokeOp = contract.call("execute_rule", ruleId, paymentAmount);

const tx = new TransactionBuilder(engineAccount, { fee: "1000", networkPassphrase: Networks.TESTNET })
  .addOperation(invokeOp)
  .build();

Technical Specs

Contract Name
autopilot-vault
Language
Rust
SDK Version
soroban-sdk v22.0.0
Target
wasm32-unknown-unknown
Network
Stellar Testnet
CI Status
✅ Passing (GitHub Actions)

Contract Source (lib.rs)

The contract exposes a simple deposit function that records vault deposits on-chain with an event log:

rust
#![no_std]
use soroban_sdk::{contract, contractimpl, log, symbol_short, Env, Symbol};

#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
    /// Record a vault deposit on-chain
    pub fn deposit(env: Env, amount: i128, vault_type: Symbol) -> i128 {
        log!(&env, "Vault deposit: {} to {:?}", amount, vault_type);
        
        // Emit an event for indexers and off-chain listeners
        env.events().publish(
            (symbol_short!("deposit"), vault_type.clone()),
            amount,
        );

        amount
    }
}

Cargo.toml Configuration

toml
[package]
name = "autopilot-vault"
version = "0.0.0"
edition = "2021"

[lib]
crate-type = ["lib", "cdylib"]
doctest = false

[dependencies]
soroban-sdk = "22.0.0"

[dev-dependencies]
soroban-sdk = { version = "22.0.0", features = ["testutils"] }

[profile.release]
opt-level = "z"
overflow-checks = true
panic = "abort"
lto = true

Building the Contract

bash
# Install Rust and the wasm32 target
rustup target add wasm32-unknown-unknown

# Build the contract
cargo build \
  --manifest-path contracts/Cargo.toml \
  --target wasm32-unknown-unknown \
  --release

# Output: target/wasm32-unknown-unknown/release/autopilot_vault.wasm

CI/CD Workflow

GitHub Actions automatically builds the Soroban contract on every push to contracts/**:

yaml
name: Soroban Smart Contract CI
on:
  push:
    paths:
      - 'contracts/**'
      - '.github/workflows/contract.yml'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - name: Build Contract
        run: cargo build \
          --manifest-path contracts/Cargo.toml \
          --target wasm32-unknown-unknown \
          --release

Learn about the security model protecting user funds.

Security Overview