Mendifinance

Mendifinance used cToken exchange rates to value legacy lending balances.

Updated

Mendifinance used cToken exchange rates to convert supplied lending balances into underlying asset amounts. A stored rate used existing market accounting and omitted interest not yet accrued. The protocol underwent a sunset with a limited withdrawal-interface window and smart-contract access continuing afterward. Converting a legacy balance therefore required the correct rate, token units, and interest state.

Table of contents

Legacy Mendi Finance markets on Linea kept separate conversions for their respective underlying assets. A rate connected supply accounting with the controller's collateral calculations. Token staking followed a separate balance system, so lending-token conversion required the lending market's own data.

Reading a legacy supplied balance

A legacy supply balance translated into an underlying asset quantity through the exchange rate for that particular market. The account's cToken balance counted lending tokens representing its supplied position. Those tokens and the underlying asset had different units, so their displayed quantities did not necessarily match. Multiplication by the correctly scaled exchange rate established the underlying quantity represented by the holding. The market applied the same exchange-rate calculation to its holders; each account's token balance determined its share.

The converted amount described gross supplied assets. Outstanding borrowing remained a separate obligation, with its own balance and interest accounting. Subtracting a loan required compatible asset valuations; the supply conversion alone did not describe a net account position.

The market accounting behind the exchange rate

With nonzero cToken supply, the contract divided cash plus recorded borrowing minus reserves by total cToken supply. In raw contract units, the scaled relationship was R = floor((C + L - V) × 10^18 / S) . Here, C represented market cash, L total recorded borrowing, V reserves, and S total cToken supply.

Market cash counted the underlying assets the contract held. Recorded borrowing counted assets borrowers owed the market, including interest already added to accounting. Together, these amounts described the asset backing before the reserve deduction.

Reserves formed a separate accounting allocation. The exchange-rate calculation deducted them before assigning underlying value to cToken supply. Including all cash and borrowing without that deduction would overstate the conversion numerator. Reserve accounting therefore affected supplied-asset valuation even when the account's cToken quantity remained unchanged.

The reserve factor directed a fraction of newly accrued borrowing interest into reserves. That reserve increase reduced the interest contribution to the exchange-rate numerator. The factor belonged to market configuration, so a conversion estimate could not substitute a universal reserve percentage.

A zero-supply market followed a different branch: the contract returned its configured initial exchange rate. That initial parameter applied to the zero-supply branch; it did not establish a common conversion value across every legacy market.

Raw units and token decimal precision

Raw cToken and underlying balances used integers, and each token's decimal precision determined its readable quantity. The conversion needed those units before any display formatting.

Contract-unit calculation

The underlying conversion used the raw cToken balance B and the scaled exchange-rate integer R. Its relationship was U = floor(B × R / 10^18) , where U represented raw underlying units. The fixed-point divisor removed the rate's arithmetic scale. Applying that expression directly to a balance already formatted as readable cTokens would mix units. The contract's calculation operated on integers before a display added decimal places.

Readable token quantities

The underlying asset's decimal precision converted U into a readable asset amount. The cToken's precision separately controlled how its own integer balance appeared. These precisions need not match. A rate between readable token quantities therefore needed the decimal relationship as well as the fixed-point scale. A large raw rate integer alone conveyed neither a large investment return nor a large asset balance.

When did a stored exchange rate omit interest?

A stored rate omitted borrowing interest the market had not yet added to its recorded balances. Elapsed time and completed accrual updates therefore described different accounting states.

Stored reads

The legacy exchangeRateStored method calculated the conversion without accruing interest first. It used recorded borrowing and reserves alongside the contract's cash calculation. A stored read did not freeze the rate at an earlier displayed number. Cash formed an input to the calculation, while pending interest remained outside the recorded borrowing and reserve amounts.

Accrual before calculation

The exchangeRateCurrent method called accrueInterest before returning the calculated rate. Accrual updated total borrowing, reserves, and the borrow index. The balanceOfUnderlying method used that current-rate path to calculate an account's underlying balance. Stored and current calculations could agree when no additional interest accrued; the different method names did not guarantee different values.

Diagram: Mendifinance - Accrual before calculation

View full-size image

Elapsed time in the legacy interest model

The legacy base implementation measured elapsed time through timestamps, despite several identifiers containing the word block. Its getBlockNumber function returned block.timestamp . Interest accrual used the difference between that value and the previous accrual checkpoint. Reading borrowRatePerBlock as a rate per produced blockchain block would therefore misinterpret this base implementation. Annualizing a rate required the actual time basis and the applicable interest model. A method name alone did not supply those assumptions or a permanent annual return.

Two redemption inputs and one conversion relationship

The legacy ERC-20 market implementation exposed redemption by cToken quantity and redemption by underlying quantity. These entry points used the exchange rate in opposite calculation directions. Their parameter units determined what the caller specified, while the market's redemption checks governed whether either operation could proceed.

A cToken quantity

The redeem entry point accepted the number of cTokens to exchange. The calculation multiplied that quantity by the exchange rate to determine underlying output. An amount expressed in readable underlying tokens did not belong in this cToken-unit parameter. The internal redemption path accrued interest before calculating the conversion and checking the requested redemption.

An underlying quantity

The redeemUnderlying entry point accepted the requested underlying amount. Division by the exchange rate determined the corresponding cToken quantity. This path also accrued interest before conversion. An earlier stored-rate estimate could therefore differ from the arithmetic at execution. Both entry points retained collateral and market-cash constraints; changing the input unit did not remove those conditions.

Account snapshots and collateral valuation

An account snapshot combined a cToken balance, a stored borrowing balance, and a stored exchange rate. The controller used those values when assessing collateral requirements. Its calculation converted supplied cTokens into underlying exposure, then applied the market's collateral factor and oracle price. Borrowing contributed separately through the borrowed asset's price. This produced a collateral-adjusted account assessment, with a different meaning from an underlying supply balance. A price movement or collateral-factor change could alter that assessment without changing the wallet's cToken count.

The hypothetical account-liquidity calculation modeled a proposed redemption or additional borrowing using stored market snapshots. It did not itself accrue fresh interest across those markets. The calculation returned excess collateral capacity or a shortfall after the proposed effect. A zero oracle price produced a price error in this controller calculation. Accurate token conversion alone therefore did not establish the value the controller could use for collateral assessment.

Conversion value and available cash

A computed underlying entitlement could exceed the assets a market held as immediately transferable cash. Recorded loans contributed to the exchange-rate numerator, while redemption required enough underlying cash for the requested output. The redemption implementation rejected an output exceeding its available cash. The controller also checked the proposed effect on collateral for accounts entered into that market.

Integer rounding at the conversion boundary

Integer division discarded fractional raw units in the conversion arithmetic. Multiplying cTokens by the scaled rate produced an underlying integer, while dividing an underlying amount by the rate produced a cToken integer. Display software could then apply its own rounding to readable quantities. These operations occurred at different boundaries, so reversing a displayed conversion did not necessarily reproduce the original integer balance.

The relevant precision depended on the market's token units and the requested direction. The redemption verification hook also rejected a positive underlying amount paired with zero redeemed cTokens. A tiny requested amount therefore needed more than a visually nonzero display value; the contract arithmetic determined the corresponding token quantity.

Conditions for reconciling cToken and asset balances

A balance reconciliation compared like quantities only when market identity, token precision, and accrual state matched. A cToken holding and a readable underlying amount could describe the same supplied position despite different quantities. The exchange rate supplied their relationship, while its accounting state limited what the comparison established.

  • Match the cToken balance and exchange rate to the same legacy lending market.
  • Keep the conversion in raw units and apply the rate's fixed-point scale.
  • Translate the resulting underlying integer using that asset's own decimal precision.
  • Identify whether the amount used stored accounting or an accrual-updated calculation.
  • Keep price-based collateral value and immediately transferable market cash separate from supplied-asset quantity.

The matched conversion described supplied underlying assets in the selected accounting state. It did not include a separate staking position or establish how much cash the market could immediately transfer.

Historical balance comparisons after sunset

A historical balance comparison needed the cToken holding and market rate from the same accounting state. Combining an earlier balance with a later rate assigned later market accounting to an earlier holding. Changes in the account's token quantity could also affect its supplied-asset amount. The market rate alone therefore could not explain the account's entire balance change if its cToken quantity also changed. Meaningful comparisons preserved the relevant market, units, and time context.

The sunset notice specified a limited withdrawal-interface period without giving a calendar cutoff. Smart-contract access was the specified continuation after that window. Legacy balance valuation still concerned the underlying assets represented by a position. Its practical limit remained the distinction between that accounting quantity and assets available for an actual redemption.

Helpful answers about Mendifinance

Did Mendifinance's cToken exchange rate measure an annual return?

The cToken exchange rate measured an asset conversion, not an annual percentage return. Estimating growth required comparing compatible rates over a defined interval. Annualizing that change needed additional time and compounding assumptions. A single rate supplied neither the elapsed interval nor a fixed future return.

Can a cToken transfer change a wallet balance without changing the market rate?

A permitted cToken transfer changed the sending and receiving accounts' token balances without changing total cToken supply. The legacy transfer logic reassigned those balances, subject to controller approval and transfer restrictions. That changed each account's share of the market. Separate interest or market-accounting changes could affect the rate, altering the underlying amount each cToken represented.

Does exchangeRateCurrent require a new asset deposit?

The legacy exchangeRateCurrent calculation accrued interest without requiring a new asset deposit. Its function updated market accounting and returned the resulting rate. This distinguished a current-rate calculation from supplying assets through the mint entry point. Calling a state-changing method and merely reading stored data had different effects on accounting, even though both could return a rate.

Which units did repayBorrow use in the legacy lending contract?

The repayBorrow amount normally specified raw units of the borrowed underlying asset; type(uint256).max requested the full outstanding debt after interest accrual. It did not specify a quantity of supplied cTokens. Repayment accounting used the underlying amount actually transferred to reduce borrowing after interest accrual. A lending-token conversion could help interpret supplied assets, but its resulting supply balance was not itself a repayment parameter.

Would an unavailable oracle price prevent exchangeRateStored from calculating an asset amount?

The exchangeRateStored calculation did not use an oracle price to calculate underlying units per cToken. It relied on market cash, recorded borrowing, reserves, and cToken supply, with an initial-rate branch for zero supply. Oracle pricing belonged to the separate controller calculation for collateral value. An unavailable price could therefore obstruct collateral assessment without being an input to the exchange-rate formula.

What happened to the rate numerator when market cash became a loan?

Borrowing added principal to recorded total borrowing and transferred the requested underlying amount out of market cash. If the cash reduction matched that principal increase, their combined contribution to the exchange-rate numerator stayed unchanged. Interest accrual and reserve changes could still alter the rate. Available cash could consequently fall without an equal fall in the accounting backing of cTokens.

Is a cToken exchange rate the same as a trading quote?

A cToken exchange rate expressed underlying asset units represented by lending tokens. It did not specify a trading quote from an external market. A separate trading quote could involve its own denomination and execution conditions. The legacy lending conversion described the protocol's supply accounting, with redemption still subject to its own market and collateral constraints.