{
 "approach": "Simplify: standalone re-implementation of YQ's behaviour in 6 storage slots and 7 named constants. Kept: pHat from band inversion on each step's first trade (pImplied = spot*(1-bid) if we bought X, spot/(1-ask) if sold; EMA alpha 0.26, no shock gate), sigmaHat EMA of first-trade |pImplied-pHat|/pHat, one flow EMA (sum of trade size / reserveY per step, decayed 0.7 per elapsed step) replacing YQ's lambdaHat*sizeHat, lambda and actEma terms, base fee 25 bps, and toxicity tox=|spot-pHat|/pHat entering once as the stale directional shift: the side that a stale price exposes gets +0.685*tox, the other side -0.685*tox. Dropped: dir skew, trade-aligned boost, tail compression, linear/quad/cubic tox level terms, sigma*tox, retail-trade pHat updates, shock gate, step counter/lambda. The linear tox level term was tuned to 0 (it did not help) and removed, so the toxicity term is the stale shift; the 8th constant slot is unused.",
 "result_summary": "Negative: the lite file loses -17.52 +/- 0.083 edge per sim paired vs YQ on held-out seeds 500000..501999 (n 2000); it scores 507.07 on seeds 0..999 vs YQ 524.63 on the same seeds. Not a promotion candidate.",
 "dropped_part_cost_ranking": "Single-part ablations of YQ on seeds 10000..10499 (n 500, paired vs YQ): stale directional shift costs most (-114.72 +/- 0.98) but the lite keeps it; among parts the lite actually drops or replaces, the lambda/flow-size level terms cost most (-50.71 +/- 0.22 when zeroed with YQ's 3 bps base; the lite's flat 25 bps base plus one flow EMA recovers most but not all of that), then the sigma term (-4.97 +/- 0.08; the lite keeps a sigma term but SIGMA_COEF > 0.2 blew up in tuning), actEma (-1.82 +/- 0.06), shock gate (-1.51 +/- 0.06), retail pHat updates (-0.82 +/- 0.04), trade-aligned boost (-0.39 +/- 0.03), tox linear+cubic (-0.14 +/- 0.04), tail compression (-0.12 +/- 0.05); dir skew is free to drop (+0.02 +/- 0.01). These YQ ablations sum to about -10 excluding the flow block, so most of the lite's -17.5 gap is the coarser activity/flow fee level.",
 "tried": [
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {}
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -218.1234,
   "se": 3.3059
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 14
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -361.423,
   "se": 4.6072
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "BASE": 15
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -225.1012,
   "se": 3.1937
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 0
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -61.8821,
   "se": 0.5932
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 3
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -29.5063,
   "se": 0.4484
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 3,
     "BASE": 20
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -43.7318,
   "se": 0.5424
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 0,
     "BASE": 30
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -22.2248,
   "se": 0.3395
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 0,
     "BASE": 40
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -33.5505,
   "se": 0.3629
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -18.8526,
   "se": 0.2675
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 0,
     "BASE": 30,
     "ST": 0.9
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -39.9596,
   "se": 0.6976
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 0,
     "BASE": 30,
     "TC": 0.25
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -45.5087,
   "se": 0.7073
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25,
     "ST": 0.5
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -23.6588,
   "se": 0.2671
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25,
     "TC": 0
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -17.2984,
   "se": 0.2442
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25,
     "FD": 0.9
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -20.5965,
   "se": 0.2664
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25,
     "PA": 0.4
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -27.2547,
   "se": 0.3194
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 20,
     "SC": 5
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -436.5619,
   "se": 5.4575
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25,
     "TC": 0,
     "PA": 0.15
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -17.6865,
   "se": 0.2463
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25,
     "TC": 0,
     "ST": 0.75
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -19.6573,
   "se": 0.2815
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 2,
     "BASE": 22,
     "TC": 0
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -20.9428,
   "se": 0.304
  },
  {
   "params": {
    "kind": "lite tuning vs YQ",
    "defaults": "BASE=5bps PHAT_ALPHA=0.26 SIGMA_DECAY=0.824 SIGMA_COEF=0.2 FLOW_DECAY=0.7 FLOW_COEF=8 TOX_COEF=0.025 STALE_COEF=0.685 FLOW0=0.004",
    "override": {
     "FC": 1.5,
     "BASE": 25,
     "TC": 0,
     "SC": 1
    }
   },
   "seeds": "0..199",
   "n": 200,
   "mean_diff": -404.5438,
   "se": 5.3578
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_sigma (SIGMA_COEF,SIGMA_TOX_COEF=0)"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -4.9669,
   "se": 0.078
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_lambda_flow (LAMBDA_COEF,FLOW_SIZE_COEF=0; base left at 3bps)"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -50.7095,
   "se": 0.2158
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_act (ACT_COEF=0)"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -1.8189,
   "se": 0.0588
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_dir_skew (DIR_COEF,DIR_TOX_COEF=0)"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": 0.0193,
   "se": 0.0081
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_trade_boost"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -0.3857,
   "se": 0.0339
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_tail_compression"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -0.1182,
   "se": 0.0519
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "tox_quad_only (linear+cubic tox=0)"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -0.1403,
   "se": 0.0393
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_stale_shift (STALE_DIR_COEF=0)"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -114.7188,
   "se": 0.9786
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_retail_pHat_update (PHAT_ALPHA_RETAIL=0)"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -0.8151,
   "se": 0.0396
  },
  {
   "params": {
    "kind": "YQ single-part ablation vs YQ",
    "dropped": "no_shock_gate"
   },
   "seeds": "10000..10499",
   "n": 500,
   "mean_diff": -1.5062,
   "se": 0.0581
  }
 ],
 "next": "Since the lite gap is concentrated in the activity-driven fee level, a fair simplification should keep YQ's lambdaHat*sizeHat + actEma block (3 slots) and drop dir skew, tail compression, tox cubic/linear and the trade boost (each costs <0.4 alone); measure that ~9-slot variant paired vs YQ. Dir skew alone costs nothing and can be removed from YQ outright (+0.02 +/- 0.01, n 500, not held-out tested).",
 "code": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {AMMStrategyBase} from \"./AMMStrategyBase.sol\";\nimport {TradeInfo} from \"./IAMMStrategy.sol\";\n\n/// yq-lite: YQ's fee behaviour reduced to 6 slots and 7 constants.\ncontract Strategy is AMMStrategyBase {\n    uint256 constant BASE_FEE = 25 * BPS;\n    uint256 constant PHAT_ALPHA = 260000000000000000; // pHat blend on a step's first trade\n    uint256 constant SIGMA_DECAY = 824000000000000000;\n    uint256 constant SIGMA_COEF = 200000000000000000;\n    uint256 constant FLOW_DECAY = 700000000000000000; // per-step decay of traded-size flow\n    uint256 constant FLOW_COEF = 1500000000000000000;\n    // Toxicity: |spot - pHat| / pHat; its single fee term is the directional stale shift.\n    uint256 constant STALE_COEF = 685000000000000000; // directional shift per unit toxicity\n\n    // slots[0] = bid fee, slots[1] = ask fee, slots[2] = last timestamp,\n    // slots[3] = pHat, slots[4] = sigmaHat, slots[5] = flow (traded size per step)\n\n    function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) {\n        slots[0] = BASE_FEE;\n        slots[1] = BASE_FEE;\n        slots[3] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[4] = 950000000000000; // 0.095%\n        slots[5] = 4000000000000000;\n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 pHat = slots[3];\n        uint256 sigmaHat = slots[4];\n        uint256 flow = slots[5];\n\n        bool firstInStep = trade.timestamp > slots[2];\n        if (firstInStep) {\n            uint256 elapsed = trade.timestamp - slots[2];\n            flow = wmul(flow, _powWad(FLOW_DECAY, elapsed > 8 ? 8 : elapsed));\n        }\n\n        uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat;\n\n        // Invert the fee band: the price that makes this trade marginal.\n        if (firstInStep) {\n            uint256 gamma = WAD - (trade.isBuy ? slots[0] : slots[1]);\n            uint256 pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma);\n            uint256 ret = wdiv(absDiff(pImplied, pHat), pHat);\n            if (ret > WAD / 10) ret = WAD / 10;\n            pHat = wmul(pHat, WAD - PHAT_ALPHA) + wmul(pImplied, PHAT_ALPHA);\n            sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY);\n        }\n\n        uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n        if (tradeRatio > WAD / 5) tradeRatio = WAD / 5;\n        flow = flow + wmul(tradeRatio, WAD - FLOW_DECAY);\n\n        uint256 tox = wdiv(absDiff(spot, pHat), pHat);\n        if (tox > WAD / 5) tox = WAD / 5;\n\n        uint256 fMid = BASE_FEE + wmul(SIGMA_COEF, sigmaHat) + wmul(FLOW_COEF, flow);\n        uint256 shift = wmul(STALE_COEF, tox);\n        uint256 protect = clampFee(fMid + shift);\n        uint256 attract = fMid > shift ? fMid - shift : 0;\n        // Spot above pHat: our X is cheap, so guard the bid side and attract asks.\n        (uint256 bidFee, uint256 askFee) = spot >= pHat ? (protect, attract) : (attract, protect);\n\n        slots[0] = bidFee;\n        slots[1] = askFee;\n        slots[2] = trade.timestamp;\n        slots[3] = pHat;\n        slots[4] = sigmaHat;\n        slots[5] = flow;\n        return (bidFee, askFee);\n    }\n\n    function _powWad(uint256 factor, uint256 exp) internal pure returns (uint256 result) {\n        result = WAD;\n        while (exp > 0) {\n            if (exp & 1 == 1) result = wmul(result, factor);\n            factor = wmul(factor, factor);\n            exp >>= 1;\n        }\n    }\n\n    function getName() external pure override returns (string memory) {\n        return \"yq-lite\";\n    }\n}\n",
 "code_sha256": "598090994d2ade4e8910b628b880fbcda5e5b92d264df65cdf8d595baf5f5820",
 "delta": "standalone",
 "score": {
  "seed_start": 0,
  "n": 1000,
  "mean_edge": 507.0733,
  "se": 2.7631,
  "reference_YQ_same_seeds": 524.6271,
  "cli_check": "amm-match run --simulations 1000 printed 'yq-lite Edge: 507.07'"
 },
 "paired": {
  "reference": "YQ 00fae418",
  "seed_start": 500000,
  "n": 2000,
  "mean_diff": -17.5179,
  "se": 0.0826,
  "worst": [
   {
    "seed": 501176,
    "diff": -35.7148
   },
   {
    "seed": 501380,
    "diff": -32.9215
   },
   {
    "seed": 501128,
    "diff": -29.7717
   },
   {
    "seed": 500048,
    "diff": -29.3776
   },
   {
    "seed": 500938,
    "diff": -29.2206
   }
  ],
  "lite_mean": 505.0236,
  "yq_mean": 522.5415
 },
 "seconds_per_simulation": 0.0874,
 "seconds_per_simulation_note": "wall seconds per simulation, run_batch with 12 workers, n 2000",
 "validate_ok": true,
 "blocked": null,
 "method": "Rust engine from benedictbrady/amm-challenge @6b6921f built with maturin; seeds built like MatchRunner._build_configs (numpy default_rng(seed)), run via amm_sim_rs.run_batch against the 30 bps vanilla normalizer. Harness reproduced the CLI exactly (YQ 537.87 on seeds 0..99 both ways). Tuning used only seeds 0..199 and 10000..10499; the final file was measured once on 500000..501999.",
 "citations": [
  "https://github.com/benedictbrady/amm-challenge (commit 6b6921f8d463314aa7c96234e1be25a25245f704)",
  "https://raw.githubusercontent.com/jiayaoqijia/amm-challenge-yq/3e9dc7d5a6192c88b562a0f8d9c172ca566ec94d/contracts/src/Strategy.sol"
 ]
}