Chō Markets

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

View on Explorer (Devnet)

Account Sizes

AccountSize (bytes)Rent (SOL)Zero-Copy
Market584~0.0047Yes
Position161~0.0019No
ProtocolConfig480~0.0040No
IrmRegistry2,136~0.0158No
IrmConfig272~0.0027No
MarketOracleConfig100(embedded)Yes

PDA Seeds

AccountSeeds
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)

InstructionArgs
supplyassets: u64
withdrawshares: u128
deposit_collateralamount: u64
withdraw_collateralamount: u64
borrowassets: u64
repayparams: RepayParams
repay_assetsassets: u64
liquidateparams: LiquidateParams
accrue_interest(none)
create_marketparams: CreateMarketParams

Governance (20)

InstructionArgs
initialize_protocol_configparams
submit_enable_lltvlltv: u64
accept_enable_lltv(none)
revoke_enable_lltv(none)
submit_enable_irmirm_type: u8
accept_enable_irm(none)
revoke_enable_irm(none)
initialize_irm_registryparams
create_irm_configindex, params
submit_enable_irm_idirm_id: Pubkey
accept_enable_irm_id(none)
revoke_enable_irm_id(none)
update_market_feenew_fee: u64
set_default_market_feenew_fee_bps: u64
claim_fees(none)
set_fee_recipientnew: Pubkey
set_fee_authoritynew: Pubkey
submit_transfer_authoritynew: Pubkey
accept_transfer_authority(none)
revoke_transfer_authority(none)

Error Codes (51)

Math Errors

  • MathOverflow
  • Underflow
  • DivisionByZero
  • ConversionError

Validation Errors

  • InvalidLltv - LLTV > 98%
  • InvalidFee - Fee > 25%
  • InvalidIrmType
  • InvalidCollateral
  • InvalidCloseFactor
  • ZeroAmount
  • InvalidInstructionData

Account Errors

  • MarketExists
  • MarketNotFound
  • PositionNotFound
  • InsufficientBalance
  • Unauthorized

Position Errors

  • HealthCheckFailed
  • PositionNotLiquidatable
  • MaxRepayExceeded
  • NoBorrowToRepay
  • NoCollateralToWithdraw
  • LiquidationCapExceeded
  • PositionHasCollateral

Oracle Errors (10)

  • InvalidOracle
  • StalePriceData
  • OraclePriceInvalid
  • OracleConfidenceTooWide
  • InvalidOracleAdapter
  • NoOracleReturnData
  • OracleParseError
  • OraclePriceTooLow
  • OraclePriceTooHigh
  • MissingOracleAccounts

Governance Errors (8)

  • MaxAllowlistReached
  • AlreadyEnabled
  • LltvNotEnabled
  • IrmNotEnabled
  • TimelockNotExpired
  • NoPendingValue
  • ProtocolConfigNotInitialized
  • NoFeesToClaim

Events (15)

EventKey Fields
MarketCreatedmarket, loan_token, collateral_token, irm_type, lltv, fee
SupplyEventmarket, user, assets, shares, totals
WithdrawEventmarket, user, assets, shares, totals
DepositCollateralEventmarket, user, amount, total_collateral
WithdrawCollateralEventmarket, user, amount, total_collateral
BorrowEventmarket, user, assets, shares, totals
RepayEventmarket, user, assets, shares, totals
LiquidateEventmarket, borrower, liquidator, repaid, seized, hf_before
AccrueInterestEventmarket, interest, fee_shares, borrow_rate, new_rate_at_target
BadDebtSocializedmarket, borrower, bad_debt_amount, total_bad_debt
FeesClaimedmarket, fee_recipient, shares_claimed
FeeRecipientUpdatedold_recipient, new_recipient
AuthorityTransferSubmittedcurrent_authority, pending_authority, valid_at
AuthorityTransferredold_authority, new_authority
AuthorityTransferRevokedpending_authority

Note: FeeRecipientUpdated and authority events missing from table above but total is 16 including MarketFeeUpdated and OracleRiskParamsUpdated.

Math Precision

ConstantValueUsage
WAD10^18Fixed-point math (1.0 = 1e18)
VIRTUAL_SHARES10^6Prevents first-depositor attack
VIRTUAL_ASSETS1Shares math offset
BPS10,000Basis points (100 bps = 1%)

Protocol Limits

LimitValueNotes
Max LLTV9,800 bps (98%)Leaves 2% safety margin
Max Fee2,500 bps (25%)Protocol fee on interest
Max Liquidation Incentive1.15 (15%)LLTV-dependent, capped
Max Enabled LLTVs32Protocol config allowlist
Max Enabled IRMs8Protocol config allowlist
Default Timelock3 days259,200 seconds
Min Rate (AdaptiveCurve)0.1% APRRate floor
Max Rate (AdaptiveCurve)200% APRRate 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 types

Dependencies

CrateVersionPurpose
anchor-lang0.31+Framework
anchor-spl0.31+Token program integration
bytemuck1.xZero-copy Pod/Zeroable

External Programs

ProgramUsage
System ProgramAccount creation, rent
Token ProgramSPL token transfers
Associated Token ProgramATA 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.