Skip to main content

Integration Architecture

System architecture and data flow

The complete technical architecture of PercoSec - from on-chain programs to frontend interfaces, with data flow specifications.

System Architecture Diagram

The architecture separates concerns across four layers: interface, application, data, and on-chain execution. On-chain programs are the canonical source of truth.

Diagram format: Mermaid graph TD. Render at mermaid.live or integrate with documentation tooling.

Insolvency Claim Data Flow

Component Specifications

Frontend

Interface
Next.js, TypeScript

Web application providing market dashboards, pool management UI, risk score displays, and real-time position monitoring. Connects to the API layer for data aggregation.

depends on:API Gateway

API Gateway

Application
Node.js, REST + WebSocket

Aggregates data from the on-chain indexer, exposes RESTful endpoints for pool state queries, and broadcasts real-time updates via WebSocket connections. Stateless - all canonical state lives on-chain.

depends on:IndexerRPC Node

Indexer

Data
Rust, PostgreSQL

Subscribes to Solana program event logs and parses all PercoSec-emitted instructions. Maintains a queryable off-chain replica of pool states, position histories, risk scores, and claim events.

depends on:Solana RPCRisk Engine Program

Keeper Network

Execution
Rust, Solana SDK

Distributed network of bots responsible for triggering on-chain liquidations, epoch settlements, and premium calculations when conditions are met. Permissionless - any party can run a keeper and earn fees.

depends on:Insurance Pool ProgramRisk Engine Program

Risk Engine Program

On-chain
Anchor (Rust), Solana

Core Solana program that computes and stores risk scores for each market. Reads oracle prices, open interest, leverage data, and funding history to produce composite risk scores on a per-epoch basis.

depends on:Pyth OraclePremium Manager

Premium Manager

On-chain
Anchor (Rust), Solana

Manages premium rate calculations based on current risk scores. Routes premium inflows from market accounts to the corresponding insurance pool. Updates rates on each epoch cycle.

depends on:Risk Engine ProgramInsurance Pool Program

Insurance Pool Program

On-chain
Anchor (Rust), Solana

Manages capital provider deposits and withdrawals, maintains per-market pool balances, tracks provider shares, and enforces epoch-based lock periods. The primary fund custody program.

depends on:Insolvency HandlerPremium Manager

Insolvency Handler

On-chain
Anchor (Rust), Solana

Evaluates insolvency claims, verifies deficit thresholds against on-chain market state, and executes the waterfall payout logic. Emits claim events consumed by the indexer for historical tracking.

depends on:Insurance Pool Program

Data Flow Specifications

Data flow specifications for key system events
EventData PathFrequencyLatency
Market Price UpdatePyth Oracle → Risk Engine Program → Risk Score Account → Indexer → API → FrontendEvery 400ms (Solana slot)<1s end-to-end
Position LiquidationKeeper detects breach → Liquidation IX → Insurance Pool deficit check → Insolvency Handler (if deficit) → Indexer logs claimEvent-driven<1 block (~400ms)
Premium AccrualMarket fee account → Premium Manager → Pool balance update → Indexer → APIPer epoch (15 min)1 epoch
Capital DepositUser wallet → Insurance Pool Program → Share issuance → Indexer → API balance updateOn-demand~400ms (1 block)
Risk Score RecalculationRisk Engine Program reads oracle + OI data → Computes weighted score → Writes to risk account → Triggers premium recalculationEvery epoch1 epoch

On-chain Account Model

All PercoSec state is stored in Program Derived Accounts (PDAs) seeded by market IDs, provider pubkeys, and epoch numbers. The account structure is designed for composability.