High-level Overview
This page describes the current testnet app. On-chain lending logic lives in program/src/main.leo (deploy name varies; e.g. xyra_lending_v6.aleo). The UI can show multiple reserve rows (ALEO, USDCx, USAD) when your env points at a unified multi-asset deployment—there are no separate USD-denominated Leo program folders in this repo; optional NEXT_PUBLIC_* IDs exist so the wallet and Markets can list extra program names when you split deployments. Risk and health use the rate model and oracles implemented in the program, not a separate "USD program" tree.
The app is an Aave-style experience on Aleo testnet: supply/borrow flows, utilization-based APY, and (when enabled) a single health constraint across reserves defined in the deployed program.
- Views: Dashboard, Markets, and Docs as tabs on /dashboard.
- Wallet: Shield wallet (Provable adapter) — connect from the header.
- Reserves in one program: when unified, deposits and borrows for multiple assets share one pool contract; asset ids are defined in Leo (e.g. 0field, 1field, 2field).
- Cross-asset risk: borrow/withdraw paths use oracle prices, per-asset LTV, and program rules so total debt stays within allowed collateral.
- Private data UX: shield icons and tooltips on sensitive columns and actions.
- Transaction history: Supabase transaction_history by wallet address; optional vault tx links after the pool tx finalizes.
Current features
- Leo: deposit, borrow, repay, withdraw, accrue interest, utilization-based rates in program/src/main.leo; offline lending-math tests under program/lending_math_tests.
- Dashboard: portfolio summary, per-reserve rows with Supply/Borrow APY, expandable Manage flows, validation and processing overlay, loading skeletons.
- Markets: on-chain aggregates, live RPC block height / network status.
- History: Supabase-backed transaction history with explorer (and optional vault) links.
- Backend: vault queue, credit payouts after finalized pool txs, CORS for split deploys.
Roadmap
- Architecture: multi-asset, cross-collateral, Aave-style money market—one program with separate reserves (ALEO, USDCx, USAD), per-reserve utilization and indices, and a linear base+slope borrow curve with reserve factor (see finalize_accrue).
- Explore: flash loan support (design and safety work TBD).
- Later: liquidations, governance, richer oracles, and additional assets as the stack matures.
Wallet Behavior & Permissions
- Integration via @provablehq/aleo-wallet-adaptor-react and WalletMultiButton.
- Programs permission list comes from getWalletConnectProgramIds() in src/types/index.ts. The list is deduplicated.
- decryptPermission is set for automatic record decryption where the adapter supports it.
- Connected address is used for RPC reads, executeTransaction, and history filters.
- WalletPersistence uses sessionStorage so navigating between Dashboard/Markets/Docs does not drop the connection.
Dashboard & Markets
- Dashboard shows a unified summary (total collateral, borrowable estimate, total debt, health factor) and per-reserve rows for each configured market.
- Cross-asset checks: before borrow/withdraw, the UI can consult on-chain caps and /vault-balances to prevent transaction failures.
- Markets shows public on-chain aggregates (totals, utilization, APYs) and a reserve overview table.
Lending Program
Source: program/src/main.leo (deploy name xyra_lending_v6.aleo).
Single program, multiple logical reserves: mappings are keyed by asset_id. Each reserve has its own supply/borrow indices, utilization, fees, LTV, liquidation parameters, and oracle price for risk normalization.
Cross-asset borrow health: finalize_borrow loads positions, converts supplies to weighted collateral and borrows to debt using asset_price and LTV per the program's model.
- Primary: xyra_lending_v6.aleo
- USDCx slot: xyra_lending_v6.aleo
- USAD slot: xyra_lending_v6.aleo
All three env vars resolve to the same program ID (unified deployment).
APY model: utilization-based rates per asset computed from on-chain totals and parameters.
Privacy Model in UI
- Columns such as wallet balance, available, position balance, and debt are labeled as private where appropriate.
- PrivateDataColumnHeader adds a shield icon and tooltip.
- PrivateActionButton styles supply/borrow/withdraw/repay with a consistent private-transaction affordance.
Transaction Lifecycle
- User starts an action from the modal (Supply / Borrow / Repay / Withdraw) for the selected asset.
- components/aleo/rpc.ts builds the transition and calls the wallet executeTransaction; a temporary tx id is returned.
- The UI polls transactionStatus until finalized, then uses the final on-chain id for explorer links and Supabase.
- For borrow and withdraw, the app records the row in Supabase and the backend watcher completes vault transfers.
- Accrue-interest actions call accrue_interest with the correct literal per asset.
Supabase TX History
Schema (Summary)
Table transaction_history key columns:
- wallet_address — Aleo address.
- tx_id — main pool transaction hash.
- type — deposit | withdraw | borrow | repay.
- asset — aleo, usdcx, or usad.
- vault_tx_id — when vault payout completes.
Environment
- NEXT_PUBLIC_SUPABASE_URL
- NEXT_PUBLIC_SUPABASE_PUB_KEY
Vault Backend
The Node server in backend/ holds the vault wallet and sends user payouts from on-chain programs after the pool records the borrow/withdraw intent.
- Vault transfers for supported asset types (e.g. Aleo credits / configured tokens) via Provable SDK.
- GET /vault-balances — public vault balances per token program.
- Vault watcher — polls Supabase for rows needing a vault tx.
- Optional oracle — backend can poll spot prices and broadcast set_asset_price.
Configure NEXT_PUBLIC_BACKEND_URL on the frontend and CORS_ORIGIN / vault env vars in backend/.env.
Development & Env
- Pool program: NEXT_PUBLIC_LENDING_POOL_PROGRAM_ID.
- NEXT_PUBLIC_APP_ENV toggles minor UX (e.g. status message timing).
- Next.js Pages router, Tailwind, layout in layouts/_layout.tsx.
- All integrations target Aleo testnet unless changed.
Implementation entry points: src/pages/dashboard.tsx, src/components/aleo/rpc.ts, backend/src/server.js, supabase/schema.sql.