Skip to content

Operations

How user operations flow through the protocol

On this page

Operation Lifecycle

All operations follow a similar lifecycle:

User Action

Validation

State Update

Async Execution

Confirmation

1. User Action

User initiates operation (deposit, withdraw, borrow, repay)

2. Validation

  • Signature verification
  • Balance checks
  • Health factor validation

3. State Update

  • Share minting/burning
  • Position updates
  • Index synchronization

4. Async Execution

  • Inter-canister calls
  • ckAsset operations
  • Blockchain transactions

5. Confirmation

  • Event notification
  • Record updates
  • User notification

Inflow vs Outflow Operations

Operation Direction Initiated By State Update
Deposit Inflow Pool (detected) Mint supply shares
Repay Inflow Pool (detected) Burn debt shares
Withdraw Outflow User (signed) Burn supply shares
Borrow Outflow User (signed) Mint debt shares

Inflow Operations

Deposits and repayments are detected by the pool:

  1. User sends native assets to their deposit address
  2. ckAsset minter mints tokens to user's subaccount
  3. Pool timer detects new balance
  4. Pool transfers to treasury and notifies lending canister

Outflow Operations

Withdrawals and borrows are initiated by the user:

  1. User signs request with their wallet
  2. Lending canister validates and updates state
  3. Pool executes withdrawal asynchronously
  4. User receives native assets

Subaccount System

The protocol uses subaccounts for user isolation and automatic attribution:

Inflow Subaccounts

plaintext
Deposit:    [0x1, 0x0, length, ...principal_bytes...]
Repayment:  [0x2, 0x0, length, ...principal_bytes...]

Each user has unique subaccounts derived from their principal.

Outflow Subaccounts

plaintext
BTC (mapped):  [0x3, ...zeros..., ...u128_index...]
ETH (direct):  [0x4, ...zeros..., ...20_byte_address...]
IC Principal:  [0x5, 0x0, length, ...principal_bytes...]

Benefits

  • Privacy: No shared addresses
  • Automatic attribution: Subaccount identifies user
  • Parallel processing: No account contention
  • Simplified reconciliation: Deterministic mapping
Esc