Account Settlement
Overview
The Settlement functions handle the maturation of positions in Tenor markets. It supports two primary settlement flows:
- Standard Tenor Position settlement
- 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
- Maturity Processing Order
- Maturities are sorted in ascending order
- Processes: zeroes → matured positions → future positions
- Ensures fixed assets are processed before debts
-
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
-
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
-
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
- 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.
- 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
- Proxy Account Management
- Creates or retrieves user's proxy account
- Handles Morpho authorizations
- Position Migration
- Transfers collateral to Morpho
- Creates equivalent borrowing position
- Sends the borrowed funds on Morpho as Loan Tokens in the borrower's account