Learning Objectives
By the end of this course, you will be able to:
- Explain why Automated Market Makers (AMMs) replaced traditional order books as the dominant DEX model
- Apply the constant product formula (x × y = k) to calculate swap prices, slippage, and pool ratios
- Describe how liquidity pools work, including adding/removing liquidity and LP token mechanics
- Understand UTLSwap — Kenostod's native AMM contract on BNB Smart Chain — and how to interact with it
- Calculate impermanent loss and evaluate when providing liquidity is profitable vs risky
- Explain UTLFarm — how LP tokens are staked for KENO yield rewards and why it incentivizes liquidity
- Map the full DeFi stack: how UTLSwap and UTLFarm work together as a complete decentralized financial system
- Identify and defend against MEV sandwich attacks when trading on AMMs
This is not a theory course. UTLSwap and UTLFarm are live, deployed smart contracts on BNB Smart Chain — part of the UTL Protocol ecosystem you have learned throughout this curriculum. In the On-Chain Lab section, you will interact directly with these contracts using real KENO tokens. This is Education-Fi in action: you learn it, you use it.
The Death of the Order Book
To understand why Automated Market Makers matter, you first need to understand what came before them and why it failed on-chain.
The Traditional Order Book Model
Traditional exchanges — from the New York Stock Exchange to Coinbase Pro — use an order book: a live list of every buy and sell order placed by users. When a buyer's price matches a seller's price, a matching engine executes the trade. The buyer gets the asset; the seller gets the cash.
Order books work beautifully in centralized systems where a server processes thousands of orders per second. But when developers tried to put an order book on a blockchain, they ran into three fundamental problems:
| Problem | Why It Breaks On-Chain |
|---|---|
| Every order update costs gas | Placing, canceling, and modifying orders are all on-chain transactions. A busy order book would burn thousands of dollars per minute in gas fees. |
| Speed mismatch | Blockchains produce blocks every 3–15 seconds. High-frequency traders exploit this delay — by the time your order is confirmed, the price has moved. |
| Front-running by validators | Block producers can see your order before it confirms and insert their own order first. The public mempool is a front-runner's paradise. |
The Breakthrough: Replace the Order Book with Math
In 2018, Uniswap's founder Hayden Adams published a radically simple idea: instead of matching buyers with sellers, use a mathematical formula to set the price automatically. No order book. No matching engine. No market makers needed. Just a smart contract holding two tokens and a single equation governing every trade.
This became the Automated Market Maker (AMM) — the architecture that powers Uniswap, PancakeSwap, Curve, SushiSwap, and now UTLSwap.
Order books require counterparties — someone must be willing to sell exactly when you want to buy. AMMs replace counterparties with liquidity pools — smart contracts that are always ready to trade, 24/7, at any size, with no registration or counterparty needed. This is what makes DeFi truly permissionless.
How AMMs Work — The x × y = k Formula
Every AMM built on the constant product model (Uniswap V2, PancakeSwap, UTLSwap) operates from a single mathematical invariant:
The pool holds two tokens. The product of their quantities must always equal the same constant k. Every trade changes the ratio of tokens, moving along a curve — but k stays fixed (excluding fees).
A Real Example: KENO/BNB Pool
Imagine UTLSwap's KENO/BNB pool has:
- x = 100,000 KENO
- y = 100 BNB
- k = 100,000 × 100 = 10,000,000
- Implied price: 1,000 KENO per BNB
Now a trader wants to buy 10 BNB worth of KENO. They send 10 BNB into the pool. After the trade, the pool has 110 BNB. Since k must stay at 10,000,000:
This is price impact — large trades relative to pool size move the price significantly. The formula naturally enforces this: the bigger your trade relative to the pool, the worse your price.
The Price Curve
The constant product formula creates a hyperbolic price curve. This means:
- Small trades have minimal price impact — the curve is nearly flat near the current price
- Large trades have severe price impact — moving along the curve costs progressively more
- The pool can never be drained — buying all of one token would require an infinite amount of the other
In practice, the 0.3% swap fee (standard in most AMMs) is added to the pool on every trade. So k actually grows slightly with each swap — this is how liquidity providers earn fees. The invariant is maintained before fee addition, then k increases, benefiting all LPs proportionally.
Key Terms
Liquidity Pools Deep Dive
Liquidity pools are the fuel of every AMM. Without people depositing tokens, there is nothing for traders to trade against. Understanding how to add and remove liquidity — and what you get in return — is essential DeFi knowledge.
Adding Liquidity
To add liquidity to a pool, you must deposit both tokens in the pool's current ratio. If the KENO/BNB pool has a ratio of 1000 KENO per BNB and you want to add liquidity, you must deposit both KENO and BNB at that same 1000:1 ratio.
-
Approve the AMM contract
Before depositing, you sign an ERC-20 approval transaction allowing the pool contract to move your tokens. This is a one-time permission per token per contract.
-
Deposit tokens at current ratio
You send both tokens to the pool contract simultaneously. The contract verifies you've deposited at the correct ratio (within a small tolerance for block timing).
-
Receive LP tokens
The contract mints and sends you LP tokens (Liquidity Provider tokens) — ERC-20 tokens that represent your proportional share of the pool. If you deposited 10% of all pool liquidity, you receive tokens representing 10% ownership.
-
Earn swap fees automatically
Every swap in the pool generates a 0.3% fee. This fee is distributed proportionally to all LPs by being added to the pool reserves. Your LP tokens grow in value as fees accumulate — no claiming needed.
LP Tokens — Your Proof of Position
LP tokens are the most important concept in liquidity provision. They are:
- Transferable — you can send them to another wallet
- Stakeable — you can deposit them into a farm (like UTLFarm) to earn additional yield
- Redeemable — burning your LP tokens returns your proportional share of the pool, including accumulated fees
- Priced — they have a dollar value equal to your share of pool assets
Removing Liquidity
To exit a pool, you return your LP tokens to the contract. The contract burns them and sends you back your proportional share of current pool reserves. Note: you get back the pool's current ratio of tokens, not the ratio you deposited at. If the ratio changed (because the price moved), you get a different split than you put in. This price-ratio divergence is the root cause of impermanent loss, covered in Section 6.
You cannot deposit only one token into a standard AMM pool. If you try to add 10,000 KENO without also adding the corresponding BNB amount, the transaction will revert. Some advanced AMMs (like Curve's stablecoin pools or Uniswap V3) allow single-sided deposits through internal swapping, but this adds complexity and fees.
UTLSwap — Kenostod's Native AMM
UTLSwap is the Kenostod ecosystem's Automated Market Maker — a live, open-source smart contract on BNB Smart Chain that enables permissionless token swaps between KENO and BNB, and serves as the liquidity infrastructure for the entire UTL Protocol.
UTLSwap Architecture
UTLSwap is built on the battle-tested constant product formula (x × y = k), with additional Kenostod-specific features designed for the Education-Fi ecosystem:
-
KENO/BNB Liquidity Pool
The primary pool holds KENO tokens and BNB. Any holder can swap KENO for BNB or BNB for KENO at any time. The swap fee is 0.3%, of which 100% goes to liquidity providers — Kenostod takes no protocol fee.
-
Whitelisted Token Access
Since KENO has transfer restrictions (the whitelist you learned about in the UTL Protocol courses), UTLSwap is whitelisted by the KENO contract owner. This allows the AMM contract to move KENO tokens on behalf of traders without being blocked by the whitelist check.
-
LP Token Minting (UTL-LP)
When you add liquidity, UTLSwap mints UTL-LP tokens — BEP-20 tokens on BNB Smart Chain. These are the tokens you stake in UTLFarm to earn KENO yield. They are transferable and represent a real, redeemable claim on pool assets.
-
Slippage Protection
Every swap includes a minimum output parameter. If the price moves beyond your tolerance between when you sign and when your transaction confirms, the contract automatically reverts — protecting you from sandwich attacks and price manipulation.
-
Deadline Parameter
Every swap includes a deadline timestamp. If your transaction sits in the mempool too long (e.g., during network congestion), the contract rejects it after the deadline — preventing stale trades from executing at much worse prices.
UTLSwap Live Contract
How to Swap on UTLSwap
Before UTLSwap, KENO could only be transferred directly between whitelisted addresses. UTLSwap creates a permissionless market — any wallet can swap BNB for KENO without needing to be whitelisted themselves, because UTLSwap (not the trader) is the one moving the KENO. This is a fundamental unlock for the ecosystem.
Impermanent Loss — The LP's Risk
Impermanent loss (IL) is the reduction in dollar value of your pooled assets compared to simply holding those same assets outside the pool. It occurs whenever the price ratio between the two tokens in your pool changes after you deposit.
The word "impermanent" is critical: if the price ratio returns to exactly where it was when you deposited, the loss disappears. But if you withdraw while prices differ from your entry, the loss becomes realized and permanent.
Why IL Happens — The Math
When you deposit into an AMM pool, you give up price exposure for fee income. Here's why:
Imagine you deposit into the KENO/BNB pool when 1 BNB = 1000 KENO. You deposit 1,000 KENO and 1 BNB (total: ~$600 at $600/BNB). The pool ratio is 1000:1.
Now BNB price doubles to $1,200. Arbitrageurs notice they can buy "cheap" BNB from your pool (still priced at the old ratio) and sell it on Binance for profit. They trade KENO into your pool for BNB until the pool reflects the new market price. Your pool now holds more KENO and less BNB than you started with.
| BNB Price Change | If You Held | In the Pool | IL % |
|---|---|---|---|
| No change | $600 | $600 | 0% |
| +50% ($900) | $750 | $733 | 2.0% |
| +100% ($1,200) | $900 | $849 | 5.7% |
| +200% ($1,800) | $1,200 | $1,039 | 13.4% |
| +400% ($3,000) | $1,800 | $1,342 | 25.5% |
| −50% ($300) | $450 | $424 | 5.7% |
When Is Providing Liquidity Worth It?
Impermanent loss doesn't mean LPs always lose. You earn fees on every swap through your pool. The question is whether accumulated fees exceed your IL over the period you're in the pool.
- High volume, stable ratio → fees accumulate fast with minimal IL → great for LPs
- Low volume, volatile ratio → IL exceeds fees → bad for LPs
- UTLFarm rewards → KENO yield earned by staking LP tokens can offset IL even during volatile periods
This is why UTLFarm exists alongside UTLSwap. By earning KENO rewards on top of swap fees, liquidity providers have a third income stream that helps overcome impermanent loss even in volatile market conditions. The combination of swap fees + KENO farming rewards is what makes the Kenostod liquidity ecosystem sustainable.
UTLFarm — Yield Farming with LP Tokens
UTLFarm is Kenostod's yield farming contract — a live BEP-20 smart contract that rewards liquidity providers with KENO tokens for staking their UTL-LP tokens. It is the incentive layer that sits on top of UTLSwap, completing the two-layer DeFi architecture.
What Is Yield Farming?
Yield farming (also called liquidity mining) is the practice of staking or locking crypto assets in a protocol in exchange for token rewards. In the Kenostod ecosystem:
- You add liquidity to UTLSwap's KENO/BNB pool
- You receive UTL-LP tokens representing your pool share
- You deposit (stake) those LP tokens into UTLFarm
- UTLFarm pays you KENO rewards every block
- You can claim KENO at any time, or unstake and exit completely
UTLFarm Mechanics
-
KENO Per Block Reward
The farm distributes a fixed amount of KENO per BNB Smart Chain block. This reward is split proportionally among all stakers — the more LP tokens you stake relative to the total staked, the larger your share of each block's rewards.
-
Reward Accumulation
Rewards accumulate continuously with every block (~3 seconds on BSC). There is no minimum staking period. You can claim rewards or unstake at any moment — the contract calculates exactly how many blocks you have staked and distributes proportionally.
-
No Lock-Up Period
UTLFarm has no forced lock-up. You maintain full control of your LP tokens and can withdraw instantly. This respects the DeFi principle of self-custody — your assets, your decisions.
-
Compounding Strategy
Advanced farmers claim their KENO rewards, then use those KENO tokens to add more liquidity to UTLSwap (getting more LP tokens), then stake those additional LP tokens in UTLFarm. This compounds their position over time — earning rewards on rewards.
UTLFarm Live Contract
How to Farm: Step-by-Step
APR (Annual Percentage Rate) is the raw yield rate without compounding — what the farm advertises. APY (Annual Percentage Yield) accounts for compounding — what you actually earn if you regularly claim and restake rewards. For UTLFarm, frequent compounding can significantly boost returns above the displayed APR.
The Full DeFi Stack — UTLSwap + UTLFarm Together
Understanding each piece individually is good. Understanding how they work together as a system is what makes you a true DeFi practitioner. Here is the complete Kenostod DeFi stack, layer by layer:
Layer 1: The Token — KENO
The foundation. KENO is a BEP-20 token with a whitelist system that controls which contracts can move it. Every layer above must interact with the KENO token contract. UTLSwap and UTLFarm are both whitelisted on KENO, allowing them to facilitate trades and reward distributions without triggering transfer restrictions.
Layer 2: The Exchange — UTLSwap
UTLSwap creates the price discovery mechanism for KENO. It holds the KENO/BNB liquidity pool, executes trades using x × y = k, generates 0.3% fees for LPs, and mints UTL-LP tokens as proof of liquidity provision. Without UTLSwap, KENO has no on-chain market price and no permissionless way to trade.
Layer 3: The Incentive — UTLFarm
UTLFarm solves the cold start problem: why would anyone provide liquidity before there are traders, and why would traders come before there's liquidity? By rewarding early LPs with KENO, UTLFarm bootstraps liquidity into UTLSwap. More liquidity → less slippage → more traders → more fees → more LP income → more liquidity. This is the DeFi flywheel.
The Ecosystem Flywheel
Comparison: Kenostod vs PancakeSwap Architecture
| Feature | PancakeSwap | Kenostod (UTLSwap + UTLFarm) |
|---|---|---|
| AMM Formula | x × y = k (constant product) | x × y = k (constant product) |
| Swap Fee | 0.25% (0.17% to LPs, 0.08% to treasury) | 0.3% (100% to LPs) |
| Farm Reward Token | CAKE | KENO |
| Governance | CAKE holders vote | KENO holders + UTL Protocol |
| Education Layer | None | 21-course E-Fi curriculum |
| Access Model | Fully permissionless | Whitelist-gated (KENO contract) |
MEV & Sandwich Attacks on AMMs
Maximal Extractable Value (MEV) is the profit that block validators can capture by reordering, inserting, or censoring transactions within a block. On AMMs, the primary MEV attack is the sandwich attack.
How a Sandwich Attack Works
- You submit a large KENO swap on UTLSwap
- A MEV bot sees your pending transaction in the mempool
- The bot submits its own identical swap with a higher gas fee — so it gets included before yours
- The bot's trade moves the price (buying pushes price up)
- Your transaction executes at the now-worse price
- The bot immediately sells its tokens at the inflated price for a risk-free profit
Protecting Yourself on UTLSwap
- Set tight slippage tolerance — 0.5% max on stable pairs; 1-2% on volatile pairs. Your transaction reverts automatically if slippage exceeds this.
- Break large trades into smaller chunks — multiple smaller swaps are harder to profitably sandwich than one large swap
- Use low-traffic times — MEV competition is lower during off-peak hours on BSC
- Set aggressive deadlines — a 2-minute deadline prevents your transaction from sitting in the mempool long enough to attract bots
Because KENO requires whitelist approval for transfers, MEV bots that are not whitelisted cannot actually receive KENO — which means they cannot execute the "back-run" half of the sandwich. This is an unintentional but real MEV protection benefit of the KENO whitelist architecture.
Real-World Case Studies
Case Study 1: Uniswap V2 — The AMM That Changed Everything (2020)
What happened: Uniswap V2 launched in May 2020 and introduced the constant product AMM in its definitive form. Within 6 months, it was processing more daily volume than Coinbase Pro — a centralized exchange with hundreds of employees and years of infrastructure. It did this with a 700-line smart contract and zero employees.
The lesson: Mathematical simplicity beats operational complexity. The x × y = k formula, combined with permissionless liquidity provision, created more efficient markets than any order book system had achieved for long-tail tokens. UTLSwap is built on the same foundation.
Case Study 2: PancakeSwap — The BNB Chain AMM Empire (2020–Present)
What happened: PancakeSwap launched on BNB Smart Chain in September 2020, copying Uniswap's architecture but with lower gas fees (~$0.01 vs Ethereum's $20–$100). By combining an AMM (PancakeSwap Exchange) with yield farming (CAKE rewards for LP stakers), PancakeSwap grew to over $1B in daily trading volume and hundreds of millions in total value locked.
The lesson: The AMM + Farm combination is the proven playbook for DeFi liquidity bootstrapping. Lower gas fees dramatically expand the accessible user base. Kenostod's UTLSwap + UTLFarm directly follows this architecture on BSC — the same chain PancakeSwap dominates.
Case Study 3: The LUNA/UST Collapse — When Liquidity Pools Fail (May 2022)
What happened: TerraUSD (UST) was an algorithmic stablecoin backed by LUNA tokens. Curve Finance pools held billions in UST liquidity. When a coordinated attack drained the Curve UST pool, UST lost its $1.00 peg. As UST fell, the system minted massive amounts of LUNA to restore the peg — hyperinflating LUNA to near zero. $40B in market cap evaporated in 72 hours.
The lesson: Algorithmic stablecoin liquidity pools carry systemic risk. Liquidity pools are only as safe as the underlying tokens. KENO's $1.00 soft peg and fixed supply (no algorithmic minting) are designed to avoid the death spiral mechanism that destroyed LUNA. Understanding pool risk means understanding token risk first.
Case Study 4: Curve Wars — When Liquidity Becomes a Political Game (2021–2022)
What happened: Curve Finance controls the deepest stablecoin liquidity on Ethereum. Curve's governance token (veCRV) determines how CURVE rewards are distributed to different pools. DeFi protocols realized that whoever controlled the most veCRV could direct enormous liquidity to their own pools. A multi-billion dollar "war" broke out, with protocols like Convex Finance, Frax, and MIM competing to accumulate veCRV and control the liquidity firehose.
The lesson: Liquidity is a strategic resource in DeFi. Protocols that control deep liquidity can attract more users, better pricing, and more ecosystem integrations. UTLFarm's KENO rewards are Kenostod's mechanism for directing and retaining strategic liquidity in the KENO/BNB pool.
On-Chain Lab — Interact With UTLSwap & UTLFarm
This is the hands-on portion of Course 16. You will interact directly with live contracts on BNB Smart Chain using your MetaMask wallet and BscScan's Write Contract interface. No coding required — just a browser and your wallet.
You need: (1) MetaMask connected to BNB Smart Chain, (2) a small amount of BNB for gas (~0.01 BNB is sufficient), (3) some KENO tokens in a whitelisted wallet. All transactions are real — small amounts are sufficient for practice.
Lab Exercise 1 — Read the UTLSwap Pool State
-
Open UTLSwap on BscScan
Navigate to the UTLSwap contract address on bscscan.com → Contract → Read Contract. Find the
getReserves()function and call it. Record the current KENO and BNB reserves in the pool. -
Calculate the current implied price
Using the reserves you just read, apply the formula: KENO price = BNB reserve / KENO reserve × BNB price. Compare to the displayed price on the UTL dashboard.
Lab Exercise 2 — Check UTLFarm State
-
Open UTLFarm on BscScan
Go to bscscan.com/address/0x37D320A881CcF553F6cd757f0A33743ae01A2644#readContract. Find and call
kenoPerBlock()to see the current reward rate. -
Check total staked LP tokens
Call
totalStaked()— this shows how many LP tokens are currently staked across all farmers. Calculate what percentage of the pool you would own if you staked 100 LP tokens. -
View pending rewards for your wallet
Call
pendingKeno(yourAddress)using your wallet address as input. This shows how many KENO tokens you have earned and not yet claimed.
Written Exercises
Complete these exercises to reinforce your understanding. Take your time — thoughtful answers demonstrate true comprehension.
Exercise 1: AMM Price Calculation
The UTLSwap KENO/BNB pool has 500,000 KENO and 200 BNB. A trader wants to buy 50 BNB worth of KENO. Using the constant product formula, calculate: (a) how many KENO they will receive, (b) their effective price per BNB in KENO, and (c) the percentage slippage compared to the starting price.
Exercise 2: Impermanent Loss Scenario
You add liquidity to the KENO/BNB pool: 10,000 KENO at $1.00 each and 10 BNB at $1,000 each (total: $20,000). Three months later, BNB price has risen to $2,500 while KENO stays at $1.00. (a) What does your position now hold in the pool? (b) What would you have if you had just held both assets? (c) What is your impermanent loss in dollars and percentage?
Exercise 3: UTLFarm Strategy
UTLFarm is paying 10 KENO per block. There are currently 1,000,000 LP tokens staked in total. You are considering staking 50,000 LP tokens. (a) What percentage of total rewards would you earn? (b) If a BNB block is produced every 3 seconds, how many KENO per day would you earn? (c) At $1.00/KENO, what is your daily dollar yield? Should you account for impermanent loss in this calculation — why or why not?
Exercise 4: Sandwich Attack Defense
You want to swap 5,000 BNB worth of KENO on UTLSwap (a very large trade). The pool has 1,000,000 KENO and 1,000 BNB. Explain: (a) why this trade is at high risk of a sandwich attack, (b) what specific parameters you would set to protect yourself, and (c) an alternative strategy to execute this trade more safely.
Exercise 5: DeFi Stack Design
Kenostod is launching a new KENO/USDT pool alongside the existing KENO/BNB pool. As the protocol designer, explain: (a) what advantages a stablecoin pair (KENO/USDT) has over KENO/BNB for liquidity providers, (b) how impermanent loss differs between the two pairs, and (c) what reward rate (higher or lower than KENO/BNB) you would set in UTLFarm for the KENO/USDT pool and why.
Final Exam — 12 Questions
Score 9/12 (75%) or higher to complete Course 16 and earn your 250 KENO reward.