Program Technical Reference
Quick Stats
7,220
Lines of Code
41
Source Files
30
Instructions
6
Account Types
51
Error Codes
15
Events
4
IRM Types
2
Oracle Adapters
LOC excludes empty lines and comments.
Program ID
5LYM6PdjBQ9Fr6Y3PV5aFBfxVCncup41ZGEQ2q73tm4F
Account Sizes
| Account | Size (bytes) | Rent (SOL) | Zero-Copy |
|---|---|---|---|
| Market | 584 | ~0.0047 | Yes |
| Position | 161 | ~0.0019 | No |
| ProtocolConfig | 480 | ~0.0040 | No |
| IrmRegistry | 2,136 | ~0.0158 | No |
| IrmConfig | 272 | ~0.0027 | No |
| MarketOracleConfig | 100 | (embedded) | Yes |
PDA Seeds
| Account | Seeds |
|---|---|
| Market | ["market", loan_token, collateral_token, collateral_adapter, loan_adapter, irm_id, lltv, nonce] |
| Position | ["position", market, user] |
| ProtocolConfig | ["protocol_config"] |
| IrmRegistry | ["irm_registry"] |
| IrmConfig | ["irm_config", index_le_bytes] |
| Builtin IRM ID | ["irm_builtin", irm_type] |
All Instructions (30)
User Operations (10)
| Instruction | Args |
|---|---|
| supply | assets: u64 |
| withdraw | shares: u128 |
| deposit_collateral | amount: u64 |
| withdraw_collateral | amount: u64 |
| borrow | assets: u64 |
| repay | params: RepayParams |
| repay_assets | assets: u64 |
| liquidate | params: LiquidateParams |
| accrue_interest | (none) |
| create_market | params: CreateMarketParams |
Governance (20)
| Instruction | Args |
|---|---|
| initialize_protocol_config | params |
| submit_enable_lltv | lltv: u64 |
| accept_enable_lltv | (none) |
| revoke_enable_lltv | (none) |
| submit_enable_irm | irm_type: u8 |
| accept_enable_irm | (none) |
| revoke_enable_irm | (none) |
| initialize_irm_registry | params |
| create_irm_config | index, params |
| submit_enable_irm_id | irm_id: Pubkey |
| accept_enable_irm_id | (none) |
| revoke_enable_irm_id | (none) |
| update_market_fee | new_fee: u64 |
| set_default_market_fee | new_fee_bps: u64 |
| claim_fees | (none) |
| set_fee_recipient | new: Pubkey |
| set_fee_authority | new: Pubkey |
| submit_transfer_authority | new: Pubkey |
| accept_transfer_authority | (none) |
| revoke_transfer_authority | (none) |
Error Codes (51)
Math Errors
MathOverflowUnderflowDivisionByZeroConversionError
Validation Errors
InvalidLltv- LLTV > 98%InvalidFee- Fee > 25%InvalidIrmTypeInvalidCollateralInvalidCloseFactorZeroAmountInvalidInstructionData
Account Errors
MarketExistsMarketNotFoundPositionNotFoundInsufficientBalanceUnauthorized
Position Errors
HealthCheckFailedPositionNotLiquidatableMaxRepayExceededNoBorrowToRepayNoCollateralToWithdrawLiquidationCapExceededPositionHasCollateral
Oracle Errors (10)
InvalidOracleStalePriceDataOraclePriceInvalidOracleConfidenceTooWideInvalidOracleAdapterNoOracleReturnDataOracleParseErrorOraclePriceTooLowOraclePriceTooHighMissingOracleAccounts
Governance Errors (8)
MaxAllowlistReachedAlreadyEnabledLltvNotEnabledIrmNotEnabledTimelockNotExpiredNoPendingValueProtocolConfigNotInitializedNoFeesToClaim
Events (15)
| Event | Key Fields |
|---|---|
| MarketCreated | market, loan_token, collateral_token, irm_type, lltv, fee |
| SupplyEvent | market, user, assets, shares, totals |
| WithdrawEvent | market, user, assets, shares, totals |
| DepositCollateralEvent | market, user, amount, total_collateral |
| WithdrawCollateralEvent | market, user, amount, total_collateral |
| BorrowEvent | market, user, assets, shares, totals |
| RepayEvent | market, user, assets, shares, totals |
| LiquidateEvent | market, borrower, liquidator, repaid, seized, hf_before |
| AccrueInterestEvent | market, interest, fee_shares, borrow_rate, new_rate_at_target |
| BadDebtSocialized | market, borrower, bad_debt_amount, total_bad_debt |
| FeesClaimed | market, fee_recipient, shares_claimed |
| FeeRecipientUpdated | old_recipient, new_recipient |
| AuthorityTransferSubmitted | current_authority, pending_authority, valid_at |
| AuthorityTransferred | old_authority, new_authority |
| AuthorityTransferRevoked | pending_authority |
Note: FeeRecipientUpdated and authority events missing from table above but total is 16 including MarketFeeUpdated and OracleRiskParamsUpdated.
Math Precision
| Constant | Value | Usage |
|---|---|---|
| WAD | 10^18 | Fixed-point math (1.0 = 1e18) |
| VIRTUAL_SHARES | 10^6 | Prevents first-depositor attack |
| VIRTUAL_ASSETS | 1 | Shares math offset |
| BPS | 10,000 | Basis points (100 bps = 1%) |
Protocol Limits
| Limit | Value | Notes |
|---|---|---|
| Max LLTV | 9,800 bps (98%) | Leaves 2% safety margin |
| Max Fee | 2,500 bps (25%) | Protocol fee on interest |
| Max Liquidation Incentive | 1.15 (15%) | LLTV-dependent, capped |
| Max Enabled LLTVs | 32 | Protocol config allowlist |
| Max Enabled IRMs | 8 | Protocol config allowlist |
| Default Timelock | 3 days | 259,200 seconds |
| Min Rate (AdaptiveCurve) | 0.1% APR | Rate floor |
| Max Rate (AdaptiveCurve) | 200% APR | Rate ceiling |
File Structure
programs/cho-markets/src/
├── lib.rs # Entrypoint, declare_id, #[program]
├── errors.rs # 51 error codes
├── events.rs # 15 event definitions
├── state/
│ ├── mod.rs
│ ├── market.rs # Market account (584 bytes)
│ ├── position.rs # Position account (161 bytes)
│ ├── protocol_config.rs # ProtocolConfig (480 bytes)
│ ├── irm_registry.rs # IrmRegistry (2,136 bytes)
│ ├── irm_config.rs # IrmConfig (272 bytes)
│ └── oracle_config.rs # MarketOracleConfig (100 bytes)
├── instructions/
│ ├── mod.rs
│ ├── create_market.rs
│ ├── supply.rs
│ ├── withdraw.rs
│ ├── deposit_collateral.rs
│ ├── withdraw_collateral.rs
│ ├── borrow.rs
│ ├── repay.rs
│ ├── liquidate.rs
│ ├── accrue_interest.rs
│ ├── initialize_protocol_config.rs
│ ├── enable_lltv.rs # submit/accept/revoke
│ ├── enable_irm.rs # submit/accept/revoke (legacy)
│ ├── initialize_irm_registry.rs # V2 IRM management
│ ├── create_irm_config.rs # V2 IRM management
│ ├── enable_irm_id.rs # submit/accept/revoke (V2)
│ ├── update_market_fee.rs
│ ├── set_default_market_fee.rs
│ ├── claim_fees.rs
│ ├── set_fee_recipient.rs
│ ├── set_fee_authority.rs
│ └── transfer_authority.rs # submit/accept/revoke
├── math/
│ ├── mod.rs
│ ├── wad.rs # WAD arithmetic
│ ├── shares.rs # Shares <-> assets conversion
│ ├── interest.rs # IRM calculations
│ ├── irm.rs # IrmConfig rate calculation
│ └── liquidation.rs # Liquidation math
└── oracle/
├── mod.rs
├── router.rs # Oracle adapter CPI
└── types.rs # Oracle return typesDependencies
| Crate | Version | Purpose |
|---|---|---|
| anchor-lang | 0.31+ | Framework |
| anchor-spl | 0.31+ | Token program integration |
| bytemuck | 1.x | Zero-copy Pod/Zeroable |
External Programs
| Program | Usage |
|---|---|
| System Program | Account creation, rent |
| Token Program | SPL token transfers |
| Associated Token Program | ATA creation |
| Oracle Adapters (CPI) | Price feeds via adapter pattern |
IDL
The Anchor IDL is generated during build and available at:
target/idl/cho_markets.json
Client code can be generated using anchor client or Codama.