Architecture

Kredio separates capital logic from intelligence. EVM contracts handle deterministic settlement, token custody, and event emission. Wasm and PVM contracts handle computation: credit scoring, liquidation risk modelling, and yield allocation. A Node.js backend service layer coordinates off-chain activity without holding any protocol state.

Execution Layers

Layer 1

EVM - Solidity

Capital state, positions, token custody, bridge, and XCM settlement. Standard ethers.js / viem compatible.

Layer 2

ink! Wasm - KreditAgent

Deterministic credit scoring. Called atomically via SCALE cross-VM staticcall from EVM market contracts in the same transaction.

Layer 3

ink! PVM - AI Layer

NeuralScorer, RiskAssessor, YieldMind. Called by the backend AI Engine; each computation emits a permanent on-chain event.

Layer 1 - EVM Contracts

All capital-bearing state lives in Solidity contracts on Polkadot Asset Hub EVM (Chain ID 420420417). These contracts are optimised for gas-efficient financial primitives: token transfers, position accounting, collateral management, and event emission. They do not perform heavy computation.

Deployed contracts: KredioLending, KredioPASMarket, KredioSwap, KredioXCMSettler, KredioAccountRegistry, GovernanceCache, KredioBridgeMinter, EthBridgeInbox, PASOracle, mUSDC, YieldPool.

Layer 2 - ink! Wasm (KreditAgent)

KreditAgent is compiled to WebAssembly and deployed on Asset Hub EVM alongside the Solidity contracts. Market contracts invoke it with a low-level staticcall carrying a SCALE-encoded 4-byte message selector:

bytes4 constant SEL_COMPUTE_SCORE    = 0x3a518c00;
bytes4 constant SEL_COLLATERAL_RATIO = 0xa70eec89;
bytes4 constant SEL_INTEREST_RATE    = 0xb8dc60f2;
bytes4 constant SEL_TIER             = 0x2b2bb477;

The cross-VM call executes atomically - same transaction, same block. The score, collateral ratio, and interest rate come back ABI-decoded and are immediately locked into the new position. No off-chain call, no latency, no trust assumption. This EVM-to-Wasm atomic interaction is unique to Polkadot's hybrid Asset Hub runtime.

Because KreditAgent is a Wasm contract, the scoring algorithm can be upgraded in place - incorporating governance signals in Phase 4, cross-chain history in Phase 6 - without redeploying KredioLending or KredioPASMarket.

Layer 3 - ink! PVM (AI Assessment)

Three contracts compiled for PolkaVM run alongside the capital layer. They are called by the backend AI Engine - not by EVM contracts directly - and each emits a full on-chain event after every computation:

  • NeuralScorer - neural cross-validation of the deterministic score; emits ScoreInferred with a confidence delta per borrower
  • RiskAssessor - forward-looking liquidation risk; emits RiskAssessed with estimated blocks-to-liquidation and recommended collateral top-up
  • YieldMind - optimal allocation across yield buckets; emits AllocationComputed with a documented reasoning code

Backend Service Layer

A Node.js process on port 3002 coordinates all off-chain activity. It reads events from contracts and writes authorised transactions back, holding no protocol state of its own.

ServiceRole
Oracle ServiceFeeds PAS/USD prices to PASOracle on a configurable interval; self-aligns to 80% of the oracle staleness limit so data never expires
Bridge ServiceValidates source-chain ETH deposits; cross-references CoinGecko and Chainlink (2% divergence tolerance); calls KredioBridgeMinter.processDeposit()
Yield StrategyMonitors pool utilisation; invests idle capital below 40% utilisation; partially recalls above 65%; full emergency recall above 80%
AI EnginePolls KredioLending events; calls NeuralScorer, RiskAssessor, and YieldMind on each event; runs a 50-block (~5 min) sweep of all active borrowers
XCM AcknowledgerMonitors KredioXCMSettler for IntentSettled and IntentFailed events; closes the three-event acknowledgment loop for every cross-chain operation
Protocol PingKeeps GovernanceCache and KredioAccountRegistry active with periodic background transactions; logs KredioSwap live quotes every 50 blocks

Borrow Event Flow

The complete path from a user borrow to a full AI-layer assessment:

  1. User calls KredioPASMarket.borrow(amount)
  2. Market calls KreditAgent.compute_score() via SCALE-encoded staticcall; receives score, collateral ratio, and rate in the same transaction
  3. Position is stored on-chain with locked parameters; Borrowed event emitted
  4. AI Engine polls the event; triggers NeuralScorer.infer() - emits ScoreInferred
  5. AI Engine triggers RiskAssessor.assess_position() - emits RiskAssessed
  6. On the next 50-block sweep, YieldMind.compute_allocation() runs over full pool state - emits AllocationComputed

Steps 4–6 are permanent, queryable event records on Blockscout. The full credit and risk history of every borrower accumulates in the event log from their first interaction.

Identity & Governance

KredioAccountRegistry binds an EVM address to a Substrate (SR25519) public key. The user provides a valid SR25519 signature over a structured payload containing their EVM address and a nonce. The registry verifies it on-chain using the Asset Hub System precompile's sr25519Verify function and creates a bidirectional, nonce-protected mapping. Replay attacks are blocked by nonce increment on both link and unlink.

GovernanceCache stores each user's OpenGov vote count and conviction level on-chain. In Phase 4 this data feeds directly into the KreditAgent scoring model - active governance participants earn a persistent credit bonus. The Polkadot ConvictionVoting precompile makes this natively queryable from Asset Hub contracts without any off-chain indexer.