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 its mulDiv helper for a constant-product (x·y=k) AMM against a fixed API. The straightforward version is a few lines; the real work is the arithmetic edge cases the tests lean on, where fees, rounding, and integer limits all collide.

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 amm/ and starts the solve clock — cd in before the next step.

    promptly init amm
  3. Start the captured session

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

    promptly start
  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. Then cd amm and drive your harness.

promptly play amm