Borrow

Whitelisted Operators in Cap can borrow and repay the underlying Vault assets, provided they have secured sufficient collateral from a Delegator.

Mechanics

Borrow

The borrow process flow is as follows:

  1. Operator calls the borrow function on the Lender contract

  2. Restaker interest is realized first to prevent charging for compounded interest

  3. If eligible to borrow*, assets are lent out from the Vault to the Opeartor

  4. Debt tokens are minted to track the loan

Key Validations*:

  • Operator must have sufficient collateral and health factor

  • Operator must be whitelisted and not paused

  • Asset being borrowed should not be paused

  • Borrow amount must meet minimum requirements, and may not exceed maximum borrows

    • Minimum: set by Admin via the setMinBorrow function

    • Maximum: The smaller value of the Operator's remaining borrowable capacity, and the remaining available amount to be borrowed from the Vault

Repay

The repay process flow is as follows:

  1. Operator calls the repay function on the Lender contract

  2. Restaker interest is realized first to ensure all interest is accounted for

  3. The repayment is processed in the following order:

    1. Unrealized restaker interest (if any)

    2. Vault principal debt

    3. Vault interest

  4. Debt tokens corresponding to the total amount repaid are burned

If the repayment is not in full, the system will maintain a minimum borrow amount for the Operator.

Interest Distribution

The repaid assets are distributed back to the shareholders:

  1. Vault Principal: Sent to Vault contract's reserves

  2. Vault Interest: Sent to interestReceiver (set to FeeAuction). Any excess interest will go to the interest receiver

  3. Restaker Interest: Sent to Delegation contract for distribution to Delegators

  4. Unrealized Interest: Added to agent's debt balance for future repayment

Realizing Interest

Interest in Cap is accrued continuously but realized discretely:

  • Accrued Interest: Calculated in real-time based on elapsed time and rates

  • Realized Interest: Actually borrowed from vault and distributed to recipients

  • Unrealized Interest: Accrued but not yet realized due to vault liquidity constraints

As can be seen, interest can be realized prior to repayment in Cap. Both stcUSD holders and Delegators may permissionlessly realize interest by borrowing from the vault and distributing to interest receivers.

There are two functions to realize interest: realizeInterest and realizeRestakerInterest

RealizeInterest:

  • Realizes vault interest (interest paid to the stcUSD holders)

  • Interest is borrowed from the Vault and paid to the interest receiver

RealizeRestakerInterest:

  • Realizes restaker interest (interest paid to Delegators)

  • Interest is borrowed from the Vault and paid to the Delegation Contract

For both functions, the process flow is as follows:

  1. Determine available interest to realize

  2. Increase reserve debt

  3. Borrow interest amount from Vault

  4. Transfer assets to recipient

Architecture

Borrow Logic

The BorrowLogic library is the core component responsible for managing borrowing and repayment operations in the CAP lending system.

Key Dependencies:

  • IDebtToken: Manages debt token minting/burning

  • IDelegation: Handles restaker interest distribution

  • IVault: Manages asset storage and transfers

  • ValidationLogic: Validates borrowing operations

  • ViewLogic: Calculates borrowing capacity and health metrics

  • AgentConfiguration: Tracks agent borrowing status per reserve

Debt Token

Debt tokens are core to accounting an Operator's loan. Debt tokens are non-transferrable ERC20 tokens minted when an Operator borrows, and burned when the debt is repayed.

Vault

Assets are transferred from/to the Vault once validation checks and interest calculations are done in the Lender.

Key Functions

borrow: Borrow an asset

where the borrow params are:

Process Flow:

  1. Interest Realization:

  2. Amount Calculation:

  3. Validation:

  4. State Updates:

  5. Asset Transfer:

repay: Repay an asset

where the repay params are:

Process Flow:

  1. Interest Realization:

  2. Amount Calculation: prevents repaying more than owned

  3. Minimum Debt Protection:

  4. Repayment Allocation:

  5. Asset Distribution:

  6. Debt Token Burning:

realizeInterest: Realize interest for an asset

realizeRestakerInterest: Realize interest for restaker debt of an agent for an asset

Unrealized interest support: Can track interest that couldn't be realized due to liquidity constraintss

Admin Functions

setInterestReceiver: Set Interest Receiver for an asset

setMinBorrow: Set minimum borrow amount for an asset

View Functions

accruedRestakerInterest: Accrued Restaker Interest

unrealizedInterest: Unrealized Restaker Interest

maxRealization: Calculates the maximum vault interest that can be realized for an asset

maxRestakerRealization: Calculates the maximum restaker interest that can be realized for an agent

  • newRealizedInterest: Maximum realizable interest

  • newUnrealizedInterest: Interest that will become unrealized

Last updated