Section 2 of 15
LiquityBase: Constants, Math, and Helpers
Key takeaway: Every Liquity contract that does math inherits from
LiquityBaseand uses helpers from theLiquityMathlibrary.LiquityBasecarries the system-wide constants (MCR = 110%,CCR = 150%,MIN_NET_DEBT = 1800 LUSD,LUSD_GAS_COMPENSATION = 200 LUSD,BORROWING_FEE_FLOOR = 0.5%) and the cross-pool helpers that read total system collateral and total system debt.LiquityMathcarries the per-Trove and per-system collateral-ratio formulas plus_decPow— the exponentiation-by-squaring implementation that drives base-rate decay. Everything else in the module reads from these two files.
What You Are Building
You are building the foundation that ten other contracts inherit from or call into. There are no users, no events, no state changes here. Just constants and pure functions. But every safety check in the protocol — every Minimum Collateral Ratio check, every Total Collateral Ratio computation, every fee bound, every Recovery Mode trigger — passes through this code.
Three things live here:
- Decimal math conventions. Every value in Liquity is scaled by
1e18(calledDECIMAL_PRECISIONthroughout). 100% is1e18. 110% is1.1e18. A 0.5% fee is5e15. This is the same convention OpenZeppelin uses for ERC-4626 share-asset rates, and the same aswadin MakerDAO. - The constants that define the protocol. None of these are ever changed. There is no setter for any of them. The whole protocol's risk parameters are six numbers.
- The math primitives.
_min,_max,decMul,_decPow,_computeCR,_computeNominalCR. Plus system-level helpers that read across the pools:_getTCR,_checkRecoveryMode.
Your Code
Requirements
Sign up free — keep reading + earn 15 Lynx
Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.
Sign up free to continueAlready have an account? Log in