Liquidium LogoLiquidium
TechnicalArchitecture

Lending Canister

The protocol orchestrator managing accounts, positions, and coordination

Responsibilities

  • Account Management: Multi-chain wallet authentication and profile linking
  • Position Tracking: User collateral and debt positions using share-based accounting
  • Interest Accrual: Calculating and applying interest via global indices
  • Health Enforcement: Validating health factors before operations
  • Pool Coordination: Orchestrating deposits, withdrawals, borrows, and repayments
  • Price Integration: Fetching and caching asset prices from oracles
  • Liquidation API: Exposing interfaces for external liquidator bots

Architecture

Account Management

Multi-Chain Authentication

Users authenticate using their existing blockchain wallets - no Internet Identity required:

Wallet Abstraction

A wallet is simply a (Chain, Address) tuple - for example (Bitcoin, "bc1q...") or (Ethereum, "0x..."). The account is derived by hashing the wallet, and the principal is derived from the first wallet's hash.

Benefits:

  • Use existing wallets (no new keys)
  • Strong cryptographic identity
  • Multi-wallet support per profile
  • Unified positions across wallets

Position Management

Each user's position in a pool is tracked using shares:

FieldDescription
user_profilePrincipal of the user
pool_idPool canister ID
assetAsset type (BTC, ETH, USDC, etc.)
deposit_scaledSupply shares
debt_scaledDebt shares
lending_index_snapshotIndex at last update
borrow_index_snapshotIndex at last update

Core Operations

All operations follow the same pattern:

  1. Sync pool indices to current time
  2. Validate preconditions (caps, liquidity)
  3. Update shares (mint or burn)
  4. Validate postconditions (health factor)
  5. Schedule async execution if needed
OperationShare ActionHealth Check
DepositMint supply sharesNo (improves health)
WithdrawBurn supply sharesYes (must stay healthy)
BorrowMint debt sharesYes (must stay healthy)
RepayBurn debt sharesNo (improves health)

Pool Registry

The lending canister maintains a registry of all pools with their configuration:

CategoryFields
IdentityPrincipal, asset, chain
CapsSupply cap, borrow cap
Share TotalsTotal supply, total debt, treasury shares
Interest RatesBase rate, slope before, slope after, optimal utilization
IndicesBorrow index, lending index
Risk ParametersReserve factor, liquidation threshold, liquidation bonus

Event Handling

The lending canister receives events from pool canisters via notify_pool_event(). Events include:

  • DepositConfirmed - triggers supply share minting
  • RepaymentConfirmed - triggers debt share burning

Each event includes a ledger transaction ID for idempotency - if the same transaction ID is processed twice, the duplicate is ignored.

Background Tasks

TaskIntervalPurpose
sync_pools600sUpdate pool indices
update_prices300sRefresh price cache
process_wal_ops15sExecute pending operations

Price Integration

Prices are fetched from the price oracle and cached with a 60-second expiry. The cache prevents price manipulation attacks and reduces request overhead.