Section 2 of 15

Build
+15 Lynx

LiquityBase: Constants, Math, and Helpers

Key takeaway: Every Liquity contract that does math inherits from LiquityBase and uses helpers from the LiquityMath library. LiquityBase carries 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. LiquityMath carries 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:

  1. Decimal math conventions. Every value in Liquity is scaled by 1e18 (called DECIMAL_PRECISION throughout). 100% is 1e18. 110% is 1.1e18. A 0.5% fee is 5e15. This is the same convention OpenZeppelin uses for ERC-4626 share-asset rates, and the same as wad in MakerDAO.
  2. 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.
  3. The math primitives. _min, _max, decMul, _decPow, _computeCR, _computeNominalCR. Plus system-level helpers that read across the pools: _getTCR, _checkRecoveryMode.

Your Code

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

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 continue

Already have an account? Log in