Collateral Engine V1
TL;DR: The Collateral Engine is XCCY's central bank — it holds all user funds, manages positions, calculates margin requirements, handles settlements, and executes liquidations.
Overview
The Collateral Engine is the custodian and risk manager of the protocol:
┌─────────────────────────────────────────────────────────────┐
│ COLLATERAL ENGINE │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ CUSTODY │ │ POSITIONS │ │ RISK │ │
│ │ │ │ │ │ │ │
│ │ Holds all │ │ Tracks all │ │ Margin │ │
│ │ user funds │ │ open trades │ │ requirements│ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ SETTLEMENT │ │ LIQUIDATION │ │ ORACLES │ │
│ │ │ │ │ │ │ │
│ │ Process at │ │ Force close │ │ Price and │ │
│ │ maturity │ │ if needed │ │ rate feeds │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘Account Structure
Account ID
Users are identified by a composite key:
Sub-Accounts
Users can create multiple isolated sub-accounts:
Margin Management
Depositing Margin
Example:
Collateral Valuation
Not all collateral is valued equally:
Why Discount Factors?
Volatile assets may lose value quickly. Haircuts ensure there's buffer for liquidators.
Position Tracking
Position Structure
Position Updates
When traders swap or LPs mint/burn, the CollateralEngine updates positions:
Margin Requirements
Calculation
The protocol calculates how much margin each position needs:
Worst Case Variable Factor
The protocol uses conservative VY estimates:
Health Check
Settlement
At Maturity
When a pool's term ends, positions can be settled:
Settlement Flow
Settlement Example
Liquidation
When Liquidation Occurs
Accounts are liquidatable when:
Liquidation Process
Flow:
Liquidator Incentive
Liquidators receive:
All remaining margin from liquidated account
All positions (which may have value)
Opportunity to profit if positions are profitable
Oracle Integration
Price Oracle (OracleHub)
Used for:
Collateral valuation
Cross-asset margin calculations
Rate Oracle (AprOracle)
Used for:
Settlement calculations (final VY)
Margin requirement estimation
Key Functions
updateAccountMargin()
Deposit/withdraw collateral
updatePositionPostVAMMAction()
Update positions after trades
checkMarginRequirement()
Verify margin sufficiency
settlePosition()
Process maturity settlement
liquidateAccount()
Force close underwater accounts
setMarginTokenWhitelist()
Admin: configure collateral
setWorstCaseVariableFactor()
Admin: set VY bounds
Storage Layout
Security Considerations
Access Control
Safety Checks
Key Takeaways
Central custody — All funds held by CollateralEngine
Sub-accounts — Isolate risk between strategies
Discount factors — Volatile collateral has haircuts
Worst case VY — Conservative margin calculations
Automatic settlement — At maturity, positions settle
Next Steps
Margin System — Detailed margin mechanics
Liquidations — Liquidation deep dive
API Reference — Full function reference
Last updated

