Borrowing

This page covers Borrow Lifecycle Using Order Books and Repay/Collateral Management using Strategy.

Core Contracts & Integration

(Borrowing + Repayment + Collateral Management + Examples)

Developers primarily interact with:

  • Orderbook → for borrowing

  • Strategies → for repayment, collateral, and ERC-4626 actions

This page merges conceptual flows, function, and real Solidity examples.


1. Borrowing Lifecycle

Borrowing in Avon:

  • Uses global liquidity, aggregated from all strategies

  • Opens isolated debt positions inside each strategy that participates

  • Returns a single aggregated loan amount to the borrower

Borrow Steps

  1. Borrower provides collateral

  2. Calls matchMarketBorrowOrder on the orderbook

  3. Orderbook selects best strategy quotes

  4. Collateral gets routed into strategies

  5. Strategies open debt positions

  6. Borrower receives loan tokens

Only the orderbook initiates borrowing. Only strategies hold positions.


2. Borrow Flow Diagram


3. Borrow (Orderbook)

Function

Parameter Definitions

Parameter
Description

borrowAmount

Requested loan amount

minExpected

Minimum acceptable output (slippage check)

collateralBuffer

Required margin above strategy LTV

maxRate

Optional rate ceiling (0 disables)

maxLtv

Optional LTV ceiling (0 disables)

Execution Rules

  • Matches up to 30 best strategy quotes

  • Routes collateral into participating strategies

  • Reverts if constraints violated

  • Returns aggregated loan tokens


4. Repayment Lifecycle

Because strategies are isolated, repayment must happen per-strategy.

Repay Steps

  1. Borrower approves strategy

  2. Calls repay()

  3. Strategy reduces debt

  4. Strategy unlocks proportional collateral

  5. If strategy debt becomes zero → all collateral withdrawable


5. Repayment (Strategy)

Rules:

  • Partial or full repayment

  • If amount == type(uint256).max, strategy repays full debt

  • Improves borrower health

  • Unlocks collateral proportionally


6. Collateral Management (Strategy)

Deposit Collateral

Withdraw Collateral

Rules:

  • Must maintain health ≥ LLTV

  • Cannot withdraw collateral securing active debt

  • Required collateral is computed per-strategy


7. Reading Position Data (Strategies)

Borrowers must query each strategy independently.


8. Borrow + Repay (Solidity Example)

Borrow Function


Repay Function


9. Example: Leverage Loop

Borrow → swap → redeposit → borrow again:

Avon does not restrict leverage logic — strategies remain isolated and composable.


10. Example: Frontend Borrow Quote

Frontends may:

  1. Read all strategies under an orderbook

  2. Retrieve their tick quotes

  3. Sort them

  4. Estimate borrow results client-side

  5. Call matchMarketBorrowOrder as final action

The onchain result will always follow the same deterministic logic.


This completes the strategy model. Next page covers data access, security, and full reference.

Last updated