Skip to content

DeFi mechanics: automated market makers and lending pools

Expert4 min readLesson 4 of 8

170 XP

In short

An automated market maker (AMM) holds two tokens in a pool and prices trades so that the product of the two balances stays constant. In this example, a Larkspur pool of 100 VRX and 4,000,000 MDT prices VRX at $40,000; buying 1 VRX costs $40,404.04 (1.01% above that price) and buying 10 costs $44,444.44 each (11.11%), before any pool fee. Liquidity providers who supply the pool trail simply holding the two tokens when prices move, before fees: a doubling of the VRX price leaves them 5.72% behind. A lending pool lends against collateral. A $6,000 MDT loan against $10,000 of VRX with an 80% liquidation threshold is liquidated if VRX falls 25%, to $30,000. Lenders earn less than borrowers pay: at a 5% borrowing rate, 80% utilization and a 10% reserve factor, suppliers receive 3.60%.

Scope. This article explains the two most common DeFi building blocks: automated market makers, which price trades with a formula, and lending pools, which lend against collateral and liquidate automatically. It builds on DeFi: Financial Machinery Without the Institutions. It is educational and informational only. It contains no price forecast, level, target or signal, names no protocol, exchange or platform, and does not evaluate any token. Worked figures use the fictional Larkspur protocol, Verex (VRX) and Meridian Dollar Token (MDT). Tax rules vary by country and are not covered here.

Automated market makers

A conventional exchange matches buyers with sellers. An AMM has no order book; it holds a pool of two tokens and lets anyone trade against it at a price set by a formula. The most widely used design keeps the product of the two balances constant, so x × y = k.

Larkspur's pool holds 100 VRX and 4,000,000 MDT, so k = 400,000,000 and the pool price is $40,000. To buy VRX, a trader adds MDT and removes VRX until the product is back to k:

VRX boughtMDT paidAverage priceAbove pool price
140,404.04$40,404.041.01%
10444,444.44$44,444.4411.11%

The larger the trade relative to the pool, the worse the price. Pools also charge a fee on each trade, which goes to the liquidity providers; the table leaves the fee out.

The liquidity provider's position

Liquidity providers deposit both tokens and earn fees. When the price of one token moves, the formula leaves the pool holding more of the token that fell and less of the one that rose. If the VRX price doubles, the pool position is worth 2√2 ÷ 3 = 0.9428 of what simply holding the two tokens would be worth, a 5.72% shortfall before fees (see DeFi: Financial Machinery Without the Institutions). Fees may or may not make up the difference.

Lending pools

RuleLarkspur settingFailure mode
CollateralDeposit tokens worth more than the loanCollateral value can fall faster than liquidations can run
Liquidation threshold80% of collateral valueOracle errors can trigger liquidations wrongly
LiquidationAnyone can repay the loan and take collateral at a discountThe borrower loses the discount on top of the fall
Interest rateRises with utilization (borrowed ÷ supplied)At full utilization, suppliers cannot withdraw

A borrower deposits $10,000 of VRX and borrows $6,000 of MDT. The health factor is 10,000 × 0.80 ÷ 6,000 = 1.33; liquidation starts when it falls to 1, when collateral is worth $7,500. That is a 25% fall, with VRX at $30,000. On the lending side, if borrowers pay 5% and 80% of the pool is lent out, suppliers receive 5% × 80% × (1 − 10% reserve factor) = 3.60%.

Teaching value, not a forecast: Larkspur figures and parameters are fictional.

Risks the formulas do not show

Smart-contract bugs, price oracles that report wrong prices, governance changes to parameters (see Governance Tokens), and the stablecoin used as the other side of the pool (see Stablecoin Plumbing at Depth) all sit outside the arithmetic. DeFi: Financial Machinery Without the Institutions described the general property: code without discretion also has no one to correct its errors. The exception is a contract deployed with upgrade or admin powers: whoever holds those keys can change it, which is a separate risk, covered in Reading a Token's Documentation.

Try it with your numbers

What does a trade cost in a constant-product pool?

Try it · AMM constant product.

Inputs

No lesson works an example for this tool, so it opens on round starting values. The tool suggests no number: enter your own.

0 by default, as in the lessons.

The size you enter; it is never solved for.

Cost of buying 1.00 tokens40,404.04 MDTConstant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees
  • k = x × y · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees400,000,000
  • Spot price, y ÷ x · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees40,000.00 MDT
  • Average price paid · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees40,404.04 MDT
  • Average over spot · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees1.01%
  • Cost of buying 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees444,444.44 MDT
  • Average price paid for 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees44,444.44 MDT
  • Average over spot for 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees11.11%
  • LP value ÷ hold value, 2√r ÷ (1 + r) · versus holding; excludes pool fees earned; model assumes no fees0.9428
  • Impermanent loss · versus holding; excludes pool fees earned; model assumes no fees−5.72%
  • LP position value · versus holding; excludes pool fees earned; model assumes no fees$14,142
  • Shortfall against holding · versus holding; excludes pool fees earned; model assumes no fees$858
  • Cost to the user, sandwiched · cost to the user only, at the entered front-run size, which is not solved for40,813.20 MDT
  • Extra cost to the user from the sandwich · cost to the user only, at the entered front-run size, which is not solved for; the same fee treatment on both costs409.16 MDT
  • User's average price over spot, sandwiched · cost to the user only, at the entered front-run size, which is not solved for2.03%

A pool of 100.00 tokens and 4,000,000.00 MDT has k = 400,000,000 and a spot price of 40,000.00 MDT. Buying 1.00 costs 40,404.04 MDT (1.01% over spot); buying 10.00 averages 44,444.44 MDT (11.11%), with a 0.00% pool fee: constant-product arithmetic on the entered reserves. At a price ratio of 2.00 the LP position is worth 0.9428 of holding: $14,142 against $15,000, a shortfall of $858 (−5.72%), versus holding; excludes pool fees earned; model assumes no fees. Cost to the user of a sandwiched trade: with 0.50 tokens bought ahead (the entered size, not solved for), the user pays 40,813.20 MDT against 40,404.04 MDT unsandwiched (the same fee treatment on both), an extra 409.16 MDT, 2.03% over spot, within the entered 3.00% tolerance. Framed only as cost to the user. Protocol risk and the total-loss row: a pool can lose its reserves to a contract failure, or a token can go to zero, and an LP position falls with it. No protocol is named or evaluated, and no fee-APR or yield figure is shown.

Educational and informational only — not investment advice, a recommendation, or an offer to buy or sell any security. Investing involves risk, including the possible loss of principal. Worked examples use fictional companies and figures.

Calculators earn no XP.

Open this calculator on its own page
Try it with your numbers

How far can collateral fall before a loan's health factor reaches 1?

Try it · Lending health factor.

Inputs

No lesson works an example for this tool, so it opens on round starting values and leaves your own figures empty. The tool suggests no number: enter your own.

Optional: the token price at which liquidation starts.

Your own figure, with no default: nothing here sizes a loan.

Enter your loan to see the arithmetic.

Educational and informational only — not investment advice, a recommendation, or an offer to buy or sell any security. Investing involves risk, including the possible loss of principal. Worked examples use fictional companies and figures.

Calculators earn no XP.

Open this calculator on its own page

Check understanding

1 of 5

In the Larkspur pool of 100 VRX and 4,000,000 MDT, a trader buys 5 VRX. What is the average price per VRX, before any pool fee?

Frequently askedCommon questions

4 questions

What does an AMM keep constant?

The product of the two token balances in the pool.

What does buying 1 VRX from the example pool cost?

$40,404.04, 1.01% above the pool price, before any pool fee.

When is the example loan liquidated?

When VRX falls 25%, to $30,000.

Why do suppliers earn less than borrowers pay?

Only part of the pool is lent out, and the protocol keeps a reserve share.

Finished reading?

Mark it complete once the answer holds without scrolling back up.

Ask MarketClue AI about this lesson

The question carries this lesson as its context. MarketClue AI needs an account.

MarketClue does not provide financial advice.

Next on your list

Topic 51 · Crypto market structureCross-venue fragmentation and arbitrageLesson 5 of 8
Next lesson

After that

Educational and informational only — not investment advice, a recommendation, or an offer to buy or sell any security. Investing involves risk, including the possible loss of principal. Worked examples use fictional companies and figures.