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
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.
Pair this machine
One-time — approve the code under your devices.
promptly pairPull the workspace
Downloads the starter kit into the current folder and starts the solve clock.
promptly init stage-3-12-constant-product-ammStart the captured session
Then drive your AI tool — the daemon meters every prompt and token live.
promptly start stage-3-12-constant-product-ammSubmit 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