Skip to content

plurigrid/flowglad-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flowglad + Aptos Move WebVM Integration

Status: Architecture + skeleton code
Target: Native Rust + WebVM (cheerpx/sel4) compatible
Deployment: Aptos mainnet with sel4 kernel support

Architecture

┌──────────────────────────────────────────────────────────┐
│              Rust Service (native/webvm)                  │
│  ┌────────────────────────────────────────────────────┐  │
│  │  Axum HTTP Router + Tower Middleware              │  │
│  ├────────────────────────────────────────────────────┤  │
│  │  /health                → Health check            │  │
│  │  /contracts/:name       → Fetch Move contract     │  │
│  │  /subscribe             → Create Flowglad billing │  │
│  │  /snipe                 → Execute market snipe    │  │
│  │  /subscription/:user_id → Check quota/balance    │  │
│  └────────────────────────────────────────────────────┘  │
│              ↓              ↓              ↓               │
└──────┬──────────────────┬──────────────────┬──────────────┘
       ↓                  ↓                  ↓
   ┌────────────┐   ┌──────────────┐   ┌─────────────┐
   │ AptosClient│   │ FlowgladBill │   │ SnipeMarket │
   ├────────────┤   ├──────────────┤   ├─────────────┤
   │ get_contract   │ create_sub   │   │ determine   │
   │ call_contract  │ get_balance  │   │ winner      │
   │ get_resources  │ poll_payment │   │ get_history │
   └────────────┘   └──────────────┘   └─────────────┘
       ↓                  ↓                  ↓
   ┌────────────┐   ┌──────────────┐   ┌─────────────┐
   │ RPC: Aptos │   │ RPC: Flowglad│   │ On-chain    │
   │ mainnet    │   │ webhook poll │   │ DuckDB      │
   └────────────┘   └──────────────┘   └─────────────┘

Features

1. Flowglad Billing (Zero-Webhook Polling)

// Create 69 snipes/month subscription
POST /subscribe
{
  "user_id": "alice",
  "snipes_per_month": 69,
  "payment_method": "stripe"
}{ "checkout_url": "https://checkout.flowglad.io/..." }

// Polling for payment confirmation
async poll_payment_status(sub_id)"completed" | "pending"

2. Aptos Move Contract Service

GET /contracts/snipe_core
→ { 
  "name": "snipe_core",
  "address": "0x1::snipe_core",
  "functions": [
    {"name": "create", "params": ["creator", "target", "duration"]},
    {"name": "commit", "params": ["signer", "snipe_id", "hash"]},
    {"name": "reveal", "params": ["signer", "snipe_id", "amount"]},
    {"name": "resolve", "params": ["signer", "snipe_id", "actual"]}
  ]
}

// Call Move entry function
POST /call
{
  "module": "snipe_core",
  "function": "create",
  "args": ["my-target", "86400"]
}{ "tx_id": "0xabc123..." }

3. Color Bandwidth Market

// Determine winner at interaction time by bandwidth comparison
POST /snipe
{
  "user_id": "alice",
  "target_id": "bob",
  "color_bandwidth": {
    "red": 0.8,
    "green": 0.7,
    "blue": 0.6,
    "extra_spectral": 0.5  // Optional: UV/IR/polarization
  }
}{
  "winner": "alice",      // Higher total bandwidth
  "loser": "bob",
  "bandwidth_diff": 0.42,
  "snipe_used": true      // Decremented from quota
}

Building

Native (Linux/macOS)

cd flowglad-rs-aptos-webvm
cargo build --release
cargo run --release
# Listens on http://0.0.0.0:3000

WebVM (cheerpx/sel4)

# Compile to wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown --features webvm

# Package for cheerpx
cd cheerpx
./build-webvm.sh ../target/wasm32-unknown-unknown/release/flowglad_aptos_webvm.wasm

# Boot sel4 kernel + webvm runtime
./boot.sh

sel4 Kernel Integration

# Build with sel4 kernel support
cargo build --features sel4-kernel

# Link with sel4 runtime
ld -T sel4_linker.ld \
   flowglad_aptos_webvm.o \
   /path/to/sel4/libsel4.a \
   -o flowglad_aptos.elf

API Examples

Subscribe to Vibesniping (69 snipes/month)

curl -X POST http://localhost:3000/subscribe \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "alice",
    "snipes_per_month": 69,
    "payment_method": "stripe"
  }'

Execute Snipe

curl -X POST http://localhost:3000/snipe \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "alice",
    "target_id": "bob",
    "color_bandwidth": {
      "red": 0.9,
      "green": 0.8,
      "blue": 0.7,
      "extra_spectral": 0.6
    }
  }'

Check Subscription Status

curl http://localhost:3000/subscription/alice

Fetch Move Contract

curl http://localhost:3000/contracts/snipe_core

Testing

cargo test
cargo test -- --nocapture  # With println output
cargo test flowglad        # Filter tests

Integration Points

Component RPC Endpoint Feature
Aptos https://fullnode.mainnet.aptoslabs.com Move contract calls
Flowglad Custom polling URL Webhook-free billing
DuckDB Local/remote ledger Market history + payouts
sel4 Kernel syscalls VM isolation
cheerpx WebVM runtime Browser sandboxing

Related Skills

  • aptos-society - Multiverse finance (GayMove contracts)
  • aptos-agent - MCP Aptos interaction
  • aptos-trading - Alpha executor trading
  • flowglad-integration - Billing pattern reference
  • sel4-boxxy - sel4 kernel integration

Files

  • src/main.rs - HTTP router + server bootstrap
  • src/market.rs - SnipeMarket + ColorBandwidth
  • src/aptos_client.rs - Aptos RPC client
  • src/flowglad_billing.rs - Subscription + polling
  • Cargo.toml - Dependencies

Next steps:

  1. Implement real Aptos RPC calls (requires aptos-sdk setup)
  2. Integrate Flowglad polling endpoint (requires API key)
  3. Connect DuckDB ledger for market history
  4. Test sel4 kernel integration with cheerpx
  5. Deploy to Aptos mainnet via validator network

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages