S03 · The Black Hat · L-12

Constant-Product AMM

Difficulty
hard
Type
implementation
Session
Standard
Stack
TypeScript node20-ts5
Domain
DeFi logic
Est. solve
~30 min

01 · The task

Implement swap and a mulDiv helper for a constant-product (x·y=k) AMM against a narrow, fixed API: compute the output amount with fees, preserve the invariant, and stay overflow-safe with integer fixed-point math. Hidden tests cover rounding, fee edges, and large reserves.

02 · Constraints

  • Narrow API

    Touch only the small, specified surface — nothing wider.

  • Overflow-safe

    Integer math must not overflow across the supported range.

03 · Skills exercised

defiDecentralized-finance logic: exact, overflow-safe on-chain arithmetic.fixed-point-mathInteger-based fractional arithmetic with explicit rounding and overflow control.ammAutomated market maker — a constant-product (x·y=k) pricing curve for on-chain swaps.

How to playDaemon

The whole level runs through the local promptly daemon — it pulls the workspace, captures your token usage, tests locally, and submits the ranked run.

  1. Pair this machine

    One-time — approve the code under your devices.

    promptly pair
  2. Pull the workspace

    Downloads the starter kit into the current folder and starts the solve clock.

    promptly init stage-3-12-constant-product-amm
  3. Start the captured session

    Then drive your AI tool — the daemon meters every prompt and token live.

    promptly start stage-3-12-constant-product-amm
  4. Submit for ranked grading

    Runs the full hidden suite and ends the attempt.

    promptly submit

Or combine steps 02–03 into one commandShortcut

promptly play pulls the workspace, launches the daemon, and starts the captured session in a single step — the same as running init then start.

promptly play stage-3-12-constant-product-amm