{
 "approach": "Pure ablation of YQ with no retuning: each of the nine named components was removed alone and measured paired against YQ on tuning seeds 10000..10999 (n=1000). Rule: remove when mean_diff > -1 se. Three passed: cubic tox, directional skew, sigma-tox term. Six are load-bearing and stay: stale shift, lambda term, activity term, flow-size term, trade-aligned boost, tail compression. dirState stays because it still picks the tail slope; only the skew derived from it was removed. The file was frozen, then measured once on the fresh block: mean_diff 0.0193, se 0.007 (z=2.75, n=2000), which clears twice its se. On scoring seeds 0..999 the paired gain is 0.001 (se 0.0081), so there it is neutral and the rounded score equals YQ's 524.63. This is a simplification with a very small gain, not a material score advance: 32 fewer lines, 4 fewer constants, runtime bytecode 3825 bytes vs 4199. Toolchain: pinned commit built with maturin, amm-match validate passes on the reference, YQ and this file; YQ reproduced 524.63 through both the CLI and the seeded harness. Gas: the repo's reported gas_used is a fixed estimate, so real gas was read from pyrevm's execution result over 3000 synthetic trades: afterInitialize 185532; afterSwap maximum 112605 (first swap, YQ 113636), mean 32803 (YQ 33819). pyrevm appears to keep state warm between calls while the Rust engine runs separate transactions; by my estimate cold-slot surcharges add at most about 23000, still under the 250000 limit. Those 3000 trades are synthetic, not a replay of the simulator's trades. seconds_per_simulation is wall time with 8 workers on the fresh block; one worker measured 0.188 s.",
 "tried": [
  {
   "variant": "YQ minus cubic tox",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": 0.008,
   "se": 0.0151,
   "decision": "removed (mean_diff > -1 se)"
  },
  {
   "variant": "YQ minus trade-aligned boost",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": -0.4173,
   "se": 0.0215,
   "decision": "kept (mean_diff <= -1 se)"
  },
  {
   "variant": "YQ minus tail compression",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": -0.1348,
   "se": 0.0451,
   "decision": "kept (mean_diff <= -1 se)"
  },
  {
   "variant": "YQ minus directional skew",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": 0.0143,
   "se": 0.0056,
   "decision": "removed (mean_diff > -1 se)"
  },
  {
   "variant": "YQ minus stale shift",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": -115.5505,
   "se": 0.6945,
   "decision": "kept (mean_diff <= -1 se)"
  },
  {
   "variant": "YQ minus activity term",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": -1.8554,
   "se": 0.041,
   "decision": "kept (mean_diff <= -1 se)"
  },
  {
   "variant": "YQ minus sigma-tox term",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": 0.0002,
   "se": 0.0024,
   "decision": "removed (mean_diff > -1 se)"
  },
  {
   "variant": "YQ minus lambda term",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": -39.8382,
   "se": 0.0894,
   "decision": "kept (mean_diff <= -1 se)"
  },
  {
   "variant": "YQ minus flow-size term",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": -1.0427,
   "se": 0.0341,
   "decision": "kept (mean_diff <= -1 se)"
  },
  {
   "variant": "YQ minus cubic tox, directional skew, sigma-tox (this file); dead code stripped, per-seed edges bit-identical to the unstripped combination",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": 0.0292,
   "se": 0.0153,
   "decision": "delivered; this block chose the removals, so it is selection-biased"
  },
  {
   "variant": "this file, replicate on a second tuning block",
   "seed_start": 11000,
   "n": 1000,
   "mean_diff": 0.0082,
   "se": 0.0085,
   "decision": "consistent, not significant alone"
  },
  {
   "variant": "YQ minus tail compression, replicate because it was the closest rejection and its first-block loss came largely from two outlier seeds (-35.42, -24.05)",
   "seed_start": 11000,
   "n": 1000,
   "mean_diff": -0.0672,
   "se": 0.0197,
   "decision": "still fails the rule; kept"
  },
  {
   "variant": "this file with one tail slope 0.9425 instead of 0.93/0.955, measured against this file, not against YQ",
   "seed_start": 10000,
   "n": 1000,
   "mean_diff": 0.0061,
   "se": 0.0029,
   "decision": "follow-up only, not delivered: outside the nine named components and not confirmed on fresh seeds"
  }
 ],
 "next": [
  "Try a single tail slope on this file: +0.0061 (se 0.0029) on tuning seeds 10000..10999. It would make dirState dead, freeing slot 3, DIR_DECAY, DIR_IMPACT_MULT and _decayCentered; it needs its own fresh block.",
  "Study high-fee episodes: without tail compression, 1000-step mean fee reached 290 and 201 bps on seed 10879 (YQ 47, 50) and 81 and 209 bps on seed 10166 (YQ 51, 37); YQ itself peaks at 1000 bps on both. Cause not established; the pHat gate (MIN_GATE 3%) is an untested suspect.",
  "Removals were not compensated, so the lambda (-39.84) and flow-size (-1.04) losses may partly be a lower fee level rather than lost signal; untested: replace them with a raised BASE_FEE and drop lambdaHat and sizeHat if neutral."
 ],
 "code": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {AMMStrategyBase} from \"./AMMStrategyBase.sol\";\nimport {TradeInfo} from \"./IAMMStrategy.sol\";\n\ncontract Strategy is AMMStrategyBase {\n    // --- decay / update constants ---\n    uint256 constant ELAPSED_CAP = 8;\n    uint256 constant SIGNAL_THRESHOLD = WAD / 500; // ~20 bps of reserve\n    uint256 constant DIR_DECAY = 800000000000000000; // 0.80\n    uint256 constant ACT_DECAY = 700000000000000000; // 0.70\n    uint256 constant SIZE_DECAY = 700000000000000000; // 0.70\n    uint256 constant TOX_DECAY = 910000000000000000; // 0.91\n    uint256 constant SIGMA_DECAY = 824000000000000000; // 0.824\n    uint256 constant LAMBDA_DECAY = 990000000000000000; // 0.99\n    uint256 constant SIZE_BLEND_DECAY = 818000000000000000; // 0.818\n    uint256 constant TOX_BLEND_DECAY = 51000000000000000; // 0.051\n    uint256 constant ACT_BLEND_DECAY = 985000000000000000; // 0.985\n    uint256 constant PHAT_ALPHA = 260000000000000000; // 0.26\n    uint256 constant PHAT_ALPHA_RETAIL = 50000000000000000; // 0.05\n    uint256 constant DIR_IMPACT_MULT = 2;\n\n    // --- Adaptive Shock Gate ---\n    uint256 constant GATE_SIGMA_MULT = 10 * WAD;\n    uint256 constant MIN_GATE = 30000000000000000; // 0.03 WAD\n\n    // --- Trade-Tox Boost ---\n    uint256 constant TRADE_TOX_BOOST = 2500 * BPS;\n\n    // --- Asymmetric Stale Dir ---\n    uint256 constant STALE_ATTRACT_FRAC = 1124000000000000000; // 1.124\n\n    // --- state caps ---\n    uint256 constant RET_CAP = WAD / 10; // 10%\n    uint256 constant TOX_CAP = WAD / 5; // 20%\n    uint256 constant TRADE_RATIO_CAP = WAD / 5; // 20%\n    uint256 constant LAMBDA_CAP = 5 * WAD; // max 5 trades/step estimate\n    uint256 constant STEP_COUNT_CAP = 64; // guardrail\n\n    // --- fee model constants ---\n    uint256 constant BASE_FEE = 3 * BPS;\n    uint256 constant SIGMA_COEF = 200000000000000000; // 0.20\n    uint256 constant LAMBDA_COEF = 12 * BPS;\n    uint256 constant FLOW_SIZE_COEF = 4842 * BPS;\n    uint256 constant TOX_COEF = 250 * BPS;\n    uint256 constant TOX_QUAD_COEF = 11700 * BPS;\n    uint256 constant ACT_COEF = 91843 * BPS;\n    uint256 constant STALE_DIR_COEF = 6850 * BPS;\n    uint256 constant TAIL_KNEE = 500 * BPS;\n    uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000; // 0.93\n    uint256 constant TAIL_SLOPE_ATTRACT = 955000000000000000; // 0.955\n\n    // slots[0] = bid fee\n    // slots[1] = ask fee\n    // slots[2] = last timestamp\n    // slots[3] = dirState (centered at WAD, [0, 2*WAD])\n    // slots[4] = actEma\n    // slots[5] = pHat\n    // slots[6] = sigmaHat\n    // slots[7] = lambdaHat\n    // slots[8] = sizeHat\n    // slots[9] = toxEma\n    // slots[10] = stepTradeCount (raw integer)\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[2] = 0;\n        slots[3] = WAD; // neutral direction\n        slots[4] = 0;\n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; // 0.095% initial sigma guess\n        slots[7] = 800000000000000000; // 0.8 initial arrival-rate guess\n        slots[8] = 2000000000000000; // 0.2% reserve-size ratio guess\n        slots[9] = 0;\n        slots[10] = 0;\n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 prevBidFee = slots[0];\n        uint256 prevAskFee = slots[1];\n        uint256 lastTs = slots[2];\n        uint256 dirState = slots[3];\n        uint256 actEma = slots[4];\n        uint256 pHat = slots[5];\n        uint256 sigmaHat = slots[6];\n        uint256 lambdaHat = slots[7];\n        uint256 sizeHat = slots[8];\n        uint256 toxEma = slots[9];\n        uint256 stepTradeCount = slots[10];\n\n        bool isNewStep = trade.timestamp > lastTs;\n        if (isNewStep) {\n            uint256 elapsedRaw = trade.timestamp - lastTs;\n            uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw;\n\n            dirState = _decayCentered(dirState, DIR_DECAY, elapsed);\n            actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed));\n            sizeHat = wmul(sizeHat, _powWad(SIZE_DECAY, elapsed));\n            toxEma = wmul(toxEma, _powWad(TOX_DECAY, elapsed));\n\n            if (stepTradeCount > 0 && elapsedRaw > 0) {\n                uint256 lambdaInst = (stepTradeCount * WAD) / elapsedRaw;\n                if (lambdaInst > LAMBDA_CAP) lambdaInst = LAMBDA_CAP;\n                lambdaHat = wmul(lambdaHat, LAMBDA_DECAY) + wmul(lambdaInst, WAD - LAMBDA_DECAY);\n            }\n\n            stepTradeCount = 0;\n        }\n\n        bool firstInStep = stepTradeCount == 0;\n\n        uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat;\n        if (pHat == 0) pHat = spot;\n\n        uint256 feeUsed = trade.isBuy ? prevBidFee : prevAskFee;\n        uint256 gamma = feeUsed < WAD ? WAD - feeUsed : 0;\n        uint256 pImplied;\n        if (gamma == 0) {\n            pImplied = spot;\n        } else {\n            pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma);\n        }\n\n        {\n            uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0;\n            uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL;\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            if (ret <= adaptiveGate) {\n                pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha);\n            }\n            if (firstInStep) {\n                if (ret > RET_CAP) ret = RET_CAP;\n                sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY);\n            }\n        }\n\n        uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n        if (tradeRatio > TRADE_RATIO_CAP) tradeRatio = TRADE_RATIO_CAP;\n\n        if (tradeRatio > SIGNAL_THRESHOLD) {\n            uint256 push = tradeRatio * DIR_IMPACT_MULT;\n            if (push > WAD / 4) push = WAD / 4;\n\n            if (trade.isBuy) {\n                dirState = dirState + push;\n                if (dirState > 2 * WAD) dirState = 2 * WAD;\n            } else {\n                dirState = dirState > push ? dirState - push : 0;\n            }\n\n            actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY);\n\n            sizeHat = wmul(sizeHat, SIZE_BLEND_DECAY) + wmul(tradeRatio, WAD - SIZE_BLEND_DECAY);\n            if (sizeHat > WAD) sizeHat = WAD;\n        }\n\n        uint256 tox = pHat > 0 ? wdiv(absDiff(spot, pHat), pHat) : 0;\n        if (tox > TOX_CAP) tox = TOX_CAP;\n        toxEma = wmul(toxEma, TOX_BLEND_DECAY) + wmul(tox, WAD - TOX_BLEND_DECAY);\n        uint256 toxSignal = toxEma;\n\n        stepTradeCount = stepTradeCount + 1;\n        if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP;\n\n        uint256 flowSize = wmul(lambdaHat, sizeHat);\n        uint256 fBase = BASE_FEE + wmul(SIGMA_COEF, sigmaHat) + wmul(LAMBDA_COEF, lambdaHat) + wmul(FLOW_SIZE_COEF, flowSize);\n        uint256 fMid = fBase + wmul(TOX_COEF, toxSignal) + wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal)) + wmul(ACT_COEF, actEma);\n\n        bool sellPressure = dirState >= WAD;\n        uint256 bidFee = fMid;\n        uint256 askFee = fMid;\n\n        // Directional protection using stale-price sign\n        {\n            uint256 staleShift = wmul(STALE_DIR_COEF, toxSignal);\n            uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC);\n            if (spot >= pHat) {\n                bidFee = bidFee + staleShift;\n                askFee = askFee > attractShift ? askFee - attractShift : 0;\n            } else {\n                askFee = askFee + staleShift;\n                bidFee = bidFee > attractShift ? bidFee - attractShift : 0;\n            }\n        }\n\n        // Trade-aligned toxicity boost\n        {\n            bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat);\n            if (tradeAligned) {\n                uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\n                if (trade.isBuy) {\n                    bidFee = bidFee + tradeBoost;\n                } else {\n                    askFee = askFee + tradeBoost;\n                }\n            }\n        }\n\n        // Asymmetric tail compression\n        if (sellPressure) {\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_PROTECT));\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_ATTRACT));\n        } else {\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_PROTECT));\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_ATTRACT));\n        }\n\n        slots[0] = bidFee;\n        slots[1] = askFee;\n        slots[2] = trade.timestamp;\n        slots[3] = dirState;\n        slots[4] = actEma;\n        slots[5] = pHat;\n        slots[6] = sigmaHat;\n        slots[7] = lambdaHat;\n        slots[8] = sizeHat;\n        slots[9] = toxEma;\n        slots[10] = stepTradeCount;\n\n        return (bidFee, askFee);\n    }\n\n    function _compressTailWithSlope(uint256 fee, uint256 slope) internal pure returns (uint256) {\n        if (fee <= TAIL_KNEE) return fee;\n        return TAIL_KNEE + wmul(fee - TAIL_KNEE, slope);\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 _decayCentered(uint256 centered, uint256 decayFactor, uint256 elapsed) internal pure returns (uint256) {\n        uint256 mul = _powWad(decayFactor, elapsed);\n        if (centered >= WAD) {\n            return WAD + wmul(centered - WAD, mul);\n        }\n        uint256 below = wmul(WAD - centered, mul);\n        return below < WAD ? WAD - below : 0;\n    }\n\n    function getName() external pure override returns (string memory) {\n        return \"yq-ablate\";\n    }\n}\n",
 "code_sha256": "a8a761d4fc15fc03953055c688b9bdd016a846642f9d4bbead7079b4d5926fbb",
 "delta": "@@ -28,3 +27,0 @@\n-    // --- Cubic Toxicity ---\n-    uint256 constant TOX_CUBIC_COEF = 15000 * BPS;\n-\n@@ -52,2 +48,0 @@\n-    uint256 constant DIR_COEF = 20 * BPS;\n-    uint256 constant DIR_TOX_COEF = 100 * BPS;\n@@ -55 +49,0 @@\n-    uint256 constant SIGMA_TOX_COEF = 500 * BPS;\n@@ -179,17 +173,3 @@\n-        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal));\n-\n-        // Cubic toxicity\n-        {\n-            uint256 toxCubed = wmul(toxSignal, wmul(toxSignal, toxSignal));\n-            fMid = fMid + wmul(TOX_CUBIC_COEF, toxCubed);\n-        }\n-\n-        uint256 dirDev;\n-        bool sellPressure;\n-        if (dirState >= WAD) {\n-            dirDev = dirState - WAD;\n-            sellPressure = true;\n-        } else {\n-            dirDev = WAD - dirState;\n-            sellPressure = false;\n-        }\n+        bool sellPressure = dirState >= WAD;\n+        uint256 bidFee = fMid;\n+        uint256 askFee = fMid;\n@@ -197,12 +176,0 @@\n-        uint256 skew = wmul(DIR_COEF, dirDev) + wmul(DIR_TOX_COEF, wmul(dirDev, toxSignal));\n-\n-        uint256 bidFee;\n-        uint256 askFee;\n-        if (sellPressure) {\n-            bidFee = fMid + skew;\n-            askFee = fMid > skew ? fMid - skew : 0;\n-        } else {\n-            askFee = fMid + skew;\n-            bidFee = fMid > skew ? fMid - skew : 0;\n-        }\n-\n@@ -283 +251 @@\n-        return \"yq\";\n+        return \"yq-ablate\";\n",
 "score": {
  "n": 1000,
  "mean_edge": 524.6281,
  "se": 2.7849,
  "seed_start": 0
 },
 "paired": {
  "reference": "YQ 00fae418",
  "seed_start": 400000,
  "n": 2000,
  "mean_diff": 0.0193,
  "se": 0.007,
  "worst": [
   {
    "seed": 400587,
    "diff": -1.3011
   },
   {
    "seed": 401805,
    "diff": -0.7081
   },
   {
    "seed": 400992,
    "diff": -0.6751
   },
   {
    "seed": 401058,
    "diff": -0.6245
   },
   {
    "seed": 401090,
    "diff": -0.6122
   }
  ]
 },
 "seconds_per_simulation": 0.0438,
 "validate_ok": true,
 "blocked": null,
 "citations": [
  "https://raw.githubusercontent.com/jiayaoqijia/amm-challenge-yq/3e9dc7d5a6192c88b562a0f8d9c172ca566ec94d/contracts/src/Strategy.sol",
  "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/match.py",
  "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/config.py",
  "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/evm/strategy.rs",
  "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/evm/executor.py"
 ]
}
