DAO/DEX Lab — AMM Mechanics and Price Impact¶
Goal¶
Implement a Uniswap V2-style AMM pool in Python and analyze price impact.
Learning objectives¶
- Implement the constant product invariant
x · y = k. - Compute swap output amounts with fees.
- Verify that
knever decreases after swaps. - Quantify price impact as a function of trade size and pool depth.
- Compare fee tiers.
Required formulas¶
x · y = k
amount_out = y · amount_in · (1 − f) / (x + amount_in · (1 − f))
price_impact = (p_spot − p_execution) / p_spot
spot_price = reserve_y / reserve_x
Deliverables¶
- Completed notebook
lab_dao_dex_[studentID].ipynb. - Working
UniswapV2Poolclass. - Two plots: swap size vs price impact, and pool TVL vs price impact.
- Written answers to the research questions.
The provided notebook is stored in the repository under notebooks/uniswap_v2_lab_task.ipynb.