Code Walkthrough Tweak Price

Dive deep into tweak_price—Curve V2’s complex function for EMA updates, re-pegging, and recalculating D and virtual price.

1. Math EMA Regular Interval
Understand the math behind exponential moving averages and how Curve uses them to smooth prices with on-chain updates. Duration: 5min
2. Python EMA Regular Interval
Simulate exponential moving averages with Python using Jupyter—learn how Curve smooths price updates with this hands-on EMA example. Duration: 6min
3. Math EMA Irregular Internal
Learn to compute exponential moving averages for irregular intervals—core to Curve V2's on-chain price smoothing. Duration: 8min
4. Python EMA Irregular Interval
Simulate Curve V2’s EMA with irregular updates in Python—model time-decayed averages using randomized time intervals and visualize the difference. Duration: 6min
5. Difference Between Math And Code
Learn how Curve V2 calculates exponential moving averages for irregular updates—using dynamic decay based on elapsed time since the last update. Duration: 4min
6. Code Walkthrough Price Oracle
Walk through Curve V2’s price_oracle function to see how it calculates the exponential moving average on-chain. Duration: 3min
7. When Is Tweak Price Called
Learn when Curve V2’s tweak_price is triggered and how it impacts re-pegging, virtual price, and the D invariant. Duration: 2min
8. Code Outline Tweak Price
Explore the structure of tweak_price in Curve V2—how it re-pegs prices, updates EMA, recalculates D, and sets virtual_price. Duration: 6min
9. Code Walkthrough Tweak Price
Dive deep into tweak_price—Curve V2’s complex function for EMA updates, re-pegging, and recalculating D and virtual price. Duration: 8min
10. XCP Profit
Understand how xcp_profit tracks fee-based growth in Curve V2 by comparing virtual price changes across tweak_price calls. Duration: 5min
11. When Is Claim Admin Fees Called
Learn when claim_admin_fees is triggered and how it impacts LP supply, virtual price, D, and xcp-based growth tracking. Duration: 1min
12. Code Walkthrough Claim Admin Fees
Walk through how claim_admin_fees calculates, mints, and distributes admin fees by tracking xcp profit and LP growth. Duration: 5min

Course Overview

About the course

What you'll learn

AMM math for Curve Cryptoswap

How liquidity is concentrated

Price-repegging

How function calls interact with the AMM

Curve Cryptoswap state variables

How the function exchange works

How to swap tokens

How to add and remove liquidity

Math for Curve Cryptoswap’s internal price oracle

Implicit differentiation

Course Description

Who is this course for?

  • Software Engineers
  • Web3 Developers
  • Finance Developers
  • AI Developers
  • Smart Contract Security Researchers

Potential Careers

Smart Contract Auditor

$100,000 - $200,000 (avg. salary)

Blockchain Financial Analyst

$100,000 - $150,000 (avg. salary)

DeFi Developer

$75,000 - $200,000 (avg. salary)

Smart Contract Engineer

$100,000 - $150,000 (avg. salary)

Web3 developer

$60,000 - $150,000 (avg. salary)

Web3 Developer Relations

$85,000 - $125,000 (avg. salary)

Meet your instructors

Tasuku Nakamura

Tasuku Nakamura

Founder at smartcontract.engineer

Smart contract engineer and educator.

Last updated on August 11, 2025