Skip to main content

Account Settlement

Overview

The Settlement functions handle the maturation of positions in Tenor markets. It supports two primary settlement flows:

  1. Standard Tenor Position settlement
  2. Settlement of borrowers with matured debts to Morpho, if applicable

Standard Tenor Position Settlement

Function

function settle(
MarketContext memory marketContext,
address account,
AccountState storage accountState
) internal

Settlement Process

  1. Maturity Processing Order
  • Maturities are sorted in ascending order
  • Processes: zeroes → matured positions → future positions
  • Ensures fixed assets are processed before debts
  1. Asset Settlement Flow

    • Processes limit orders first
    if (accountMaturityState.limitOrderBalance > 0) {
    AccountLib.withdrawLimitOrder(...);
    (uint256 fixedOut, uint256 loanOut) = _withdrawLimitOrder(...);
    }
    • Converts withdrawn assets to appropriate tokens
    • Updates account balances
  2. Debt Settlement Flow

    if (accountMaturityState.fixedBalance < 0 && loanBalance != 0) {
    (loanOut, fixedIn,) = marketContext.loanToken.settleDebt(...);
    }
    • Settles negative fixed balances using available loan tokens
    • Updates account state accordingly
  3. Fixed Token Settlement

    if (accountMaturityState.fixedBalance > 0) {
    fixedOut = uint256(uint112(accountMaturityState.fixedBalance));
    loanIn = marketContext.loanToken.settleFixed(fixedToken, fixedOut);
    }
    • Converts positive fixed balances to loan tokens
    • Updates final balances

Morpho Settlement

Function

function settleToMorpho(
IMorpho morpho,
IProxyMorphoAccountFactory proxyMorphoAccountFactory,
MarketContext memory marketContext,
Seconds maturity,
address account
) internal returns (
uint256 loanRepaid,
uint256 debtSettled,
uint256 collateralSettled
)

Settlement to Morpho Process

  1. Eligibility Checks
  • The borrower has matured debts after the normal settlement process
  • The Loan Token has negative sharesBackingExcess ≥ to the amount to be settled to Morpho.
  1. Collateral Calculation
  • Calculates the amount of collateral to be transfered to Morpho to repay the net matured debt
  • Maintains same LTV ratio across the Morpho account and Tenor
  1. Proxy Account Management
  • Creates or retrieves user's proxy account
  • Handles Morpho authorizations
  1. Position Migration
  • Transfers collateral to Morpho
  • Creates equivalent borrowing position
  • Sends the borrowed funds on Morpho as Loan Tokens in the borrower's account