{
 "item": "first",
 "batch": "e08-boost-cap",
 "blocked": null,
 "confirmation": null,
 "experiment": "G with the aligned-trade tradeBoost capped: when firstInStep (evaluated before the stepTradeCount increment), tradeBoost = min(wmul(TRADE_TOX_BOOST, tradeRatio), K*BPS). tradeAligned test, side assignment, tail compression, flow terms, stale shifts, estimators, direction skew unchanged; outside the gate fees are G's.",
 "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    uint256 constant ELAPSED_CAP = 8;\n    uint256 constant SIGNAL_THRESHOLD = WAD / 650;\n    uint256 constant DIR_DECAY = 750000000000000000;\n    uint256 constant ACT_DECAY = 530000000000000000;\n    uint256 constant SIZE_DECAY = 530000000000000000;\n    uint256 constant TOX_DECAY = 910000000000000000;\n    uint256 constant SIGMA_DECAY = 690000000000000000;\n    uint256 constant LAMBDA_DECAY = 990000000000000000;\n    uint256 constant SIZE_BLEND_DECAY = 828000000000000000;\n    uint256 constant TOX_BLEND_DECAY = 51000000000000000;\n    uint256 constant ACT_BLEND_DECAY = 985000000000000000;\n    uint256 constant PHAT_ALPHA = 270000000000000000;\n    uint256 constant PHAT_ALPHA_RETAIL = 60000000000000000;\n    uint256 constant PHAT_ALPHA_SAME = 120000000000000000;\n    uint256 constant REVERT_U = 0;\n    uint256 constant DIR_IMPACT_MULT = 4;\n    uint256 constant GATE_SIGMA_MULT = 7200000000000000000;\n    uint256 constant MIN_GATE = 30000000000000000;\n    uint256 constant TRADE_TOX_BOOST = 3500 * BPS;\n    uint256 constant STALE_ATTRACT_FRAC = 1050000000000000000;\n    uint256 constant RET_CAP = WAD / 35;\n    uint256 constant TOX_CAP = WAD / 5;\n    uint256 constant TRADE_RATIO_CAP = WAD / 5;\n    uint256 constant LAMBDA_CAP = 1820000000000000000;\n    uint256 constant STEP_COUNT_CAP = 64;\n    uint256 constant BASE_FEE = 4 * BPS;\n    uint256 constant SIGMA_COEF = 200000000000000000;\n    uint256 constant LAMBDA_COEF = 12 * BPS;\n    uint256 constant FLOW_SIZE_COEF = 4842 * BPS;\n    uint256 constant TOX_COEF = 300 * BPS;\n    uint256 constant TOX_QUAD_COEF = 15000 * BPS;\n    uint256 constant ACT_COEF = 91843 * BPS;\n    uint256 constant DIR_COEF = 20 * BPS;\n    uint256 constant DIR_TOX_COEF = 100 * BPS;\n    uint256 constant STALE_DIR_COEF = 6850 * BPS;\n    uint256 constant SIGMA_TOX_COEF = 500 * BPS;\n    uint256 constant TAIL_KNEE = 600 * BPS;\n    uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000;\n    uint256 constant TAIL_SLOPE_ATTRACT = 850000000000000000;\n\n    function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) {\n        slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[3] = WAD; \n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n        slots[13] = 902500000000; slots[14] = slots[5]; \n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 prevBidFee = slots[0]; uint256 prevAskFee = slots[1]; uint256 lastTs = uint64(slots[2]);\n        uint256 dirState = slots[3]; uint256 actEma = slots[4]; uint256 pHat = slots[5];\n        uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8];\n        uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10];\n\n        uint256 sigmaForFast = sigmaHat;\n        uint256 fastHat = slots[14];\n        uint256 uncertainty = slots[13];\n        uint256 silent = trade.timestamp > lastTs ? trade.timestamp - lastTs : 0;\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            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            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            uncertainty += wmul(sigmaForFast, sigmaForFast) * elapsedRaw;\n            if (uncertainty > 100000000000000) uncertainty = 100000000000000;\n            stepTradeCount = 0;\n        }\n\n        bool firstInStep = stepTradeCount == 0;\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) { pImplied = spot; }\n        else { pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma); }\n\n        // S: infer a no-trade interval center from the last post-trade spot.\n        uint256 silenceScale = WAD;\n        if (firstInStep && silent > 1) {\n            uint256 g = silent - 1;\n            if (g > 1) g = 1;\n            uint256 w = WAD - _powWad(800000000000000000, g);\n            uint256 s = slots[2] >> 64;\n            if (s == 0) s = pHat;\n            uint256 c = (wmul(s, WAD - prevBidFee) + wdiv(s, WAD - prevAskFee)) / 2;\n            if (c >= pHat) pHat += wmul(w, c - pHat);\n            else pHat -= wmul(w, pHat - c);\n            silenceScale = WAD - wmul(300000000000000000, w);\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 prePhat = pHat;\n            bool secondPrint = !firstInStep && stepTradeCount == 1;\n            bool sameDir = false; bool oppDir = false;\n            if (secondPrint) {\n                bool up2 = pImplied >= pHat;\n                uint256 d1 = slots[12];\n                if (d1 != 0) { sameDir = (d1 == 1) == up2; oppDir = !sameDir; }\n                if (sameDir) alpha = PHAT_ALPHA_SAME;\n            }\n            if (firstInStep) { slots[12] = pImplied >= pHat ? 1 : 2; }\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            alpha = wmul(alpha, silenceScale);\n            adaptiveGate = wmul(adaptiveGate, silenceScale);\n            if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); }\n            if (oppDir && REVERT_U > 0) {\n                uint256 pre = slots[11];\n                if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U);\n                else pHat = pHat - wmul(pHat - pre, REVERT_U);\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        // Interior retail routing equalizes fee-adjusted marginal prices.\n        // Subsequent trades in a step cannot be the initial arbitrage trade.\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalSpot = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            pHat = wmul(pHat, 90 * WAD / 100) + wmul(normalSpot, 10 * WAD / 100);\n        }\n\n        {\n            uint256 ret = fastHat > 0 ? wdiv(absDiff(pImplied, fastHat), fastHat) : 0;\n            uint256 alpha;\n            if (firstInStep) {\n                uint256 processSigma = sigmaForFast;\n                uint256 obsVar = uncertainty + wmul(processSigma, processSigma);\n                uint256 probArb;\n                uint256 z2 = wdiv(wmul(ret, ret), obsVar);\n                uint256 density = _powWad(wdiv(WAD, WAD + z2 / 16), 8);\n                uint256 sigmaObs = _isqrt(obsVar * WAD);\n                uint256 odds = wmul(density, wdiv(6700000000000000, sigmaObs));\n                bool arbFlag = ret <= wmul(sigmaForFast, 1220000000000000000);\n                uint256 prior = arbFlag ? 650000000000000000 : 400000000000000000;\n                uint256 tr = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n                if (tr > 3000000000000000) prior = wmul(prior, 6 * WAD / 10);\n                if (silent > 1) prior = wmul(prior, 8 * WAD / 10);\n                odds = wmul(odds, wdiv(prior, WAD - prior));\n                probArb = wdiv(odds, WAD + odds);\n                alpha = wmul(probArb, 600000000000000000) + wmul(WAD - probArb, 80000000000000000);\n                slots[15] = pImplied >= fastHat ? 1 : 2;\n                uncertainty = wmul(uncertainty, WAD - alpha);\n            } else {\n                if ((slots[15] == 1) == (pImplied >= fastHat)) alpha = PHAT_ALPHA_RETAIL;\n            }\n            uint256 gate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (gate < MIN_GATE) gate = MIN_GATE;\n            if (ret <= gate) fastHat = wmul(fastHat, WAD - alpha) + wmul(pImplied, alpha);\n            slots[13] = uncertainty;\n        }\n\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalObs = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            if ((slots[15] == 1) == (normalObs >= fastHat)) {\n                fastHat = wmul(fastHat, 9 * WAD / 10) + wmul(normalObs, WAD / 10);\n            }\n        }\n        slots[14] = fastHat;\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            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            actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY);\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        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal));\n\n        uint256 dirDev; bool sellPressure;\n        if (dirState >= WAD) { dirDev = dirState - WAD; sellPressure = true; }\n        else { dirDev = WAD - dirState; sellPressure = false; }\n\n        uint256 skew = wmul(DIR_COEF, dirDev) + wmul(DIR_TOX_COEF, wmul(dirDev, toxSignal));\n        uint256 bidFee; 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        {\n            uint256 staleHat = wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000);\n            uint256 staleTox = wdiv(absDiff(spot, staleHat), staleHat);\n            if (staleTox > TOX_CAP) staleTox = TOX_CAP;\n            uint256 staleShift = wmul(STALE_DIR_COEF, staleTox);\n            uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC);\n            if (spot >= staleHat) {\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        {\n            bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat);\n            if (tradeAligned) {\n                uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\n                if (firstInStep && tradeBoost > 16 * BPS) tradeBoost = 16 * BPS;\n                if (trade.isBuy) { bidFee = bidFee + tradeBoost; }\n                else { askFee = askFee + tradeBoost; }\n            }\n        }\n\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; slots[1] = askFee; slots[2] = (spot << 64) | trade.timestamp;\n        slots[3] = dirState; slots[4] = actEma; slots[5] = pHat;\n        slots[6] = sigmaHat; slots[7] = lambdaHat; slots[8] = sizeHat;\n        slots[9] = toxEma; 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) { return WAD + wmul(centered - WAD, mul); }\n        uint256 below = wmul(WAD - centered, mul);\n        return below < WAD ? WAD - below : 0;\n    }\n\n    // Floor square root: bit-length seed and seven Newton steps (all uint256).\n    function _isqrt(uint256 x) internal pure returns (uint256 r) {\n        if (x == 0) return 0;\n        unchecked {\n            uint256 y = x;\n            r = 1;\n            if (y >> 128 != 0) { y >>= 128; r <<= 64; }\n            if (y >> 64 != 0) { y >>= 64; r <<= 32; }\n            if (y >> 32 != 0) { y >>= 32; r <<= 16; }\n            if (y >> 16 != 0) { y >>= 16; r <<= 8; }\n            if (y >> 8 != 0) { y >>= 8; r <<= 4; }\n            if (y >> 4 != 0) { y >>= 4; r <<= 2; }\n            if (y >> 2 != 0) { r <<= 1; }\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            uint256 t = x / r;\n            return r < t ? r : t;\n        }\n    }\n\n    function getName() external pure override returns (string memory) { return \"no_cubic\"; }\n}\n",
 "sha256": "ab4a2640963d22cb94502234e5e05684faff9ad7ddade860a0ebdb4168388bea",
 "base_sha256": "610c1905e7dd5559b84e40a3b2d6f8e0b53a7b0ac7574ae33b6c1770a28367cb",
 "v2_sha256": "28417e116f57f1029fdd1803832e852574902c1ae7253c05657f317db76da4ab",
 "selected_variant": {
  "K": 16,
  "cap_bps": 16,
  "sha256": "ab4a2640963d22cb94502234e5e05684faff9ad7ddade860a0ebdb4168388bea"
 },
 "variant_patch_K16": "--- a/G.sol\n+++ b/GCap16.sol\n@@ -245,6 +245,7 @@\n             bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat);\n             if (tradeAligned) {\n                 uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\n+                if (firstInStep && tradeBoost > 16 * BPS) tradeBoost = 16 * BPS;\n                 if (trade.isBuy) { bidFee = bidFee + tradeBoost; }\n                 else { askFee = askFee + tradeBoost; }\n             }\n",
 "variant_generator_py": "\"\"\"Generate boost-cap variants from G: inside the tradeAligned block, when firstInStep,\ntradeBoost = min(wmul(TRADE_TOX_BOOST, tradeRatio), K*BPS). Everything else unchanged.\"\"\"\nimport hashlib, sys\nOLD = \"                uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\\n\"\ndef make(g_src, k):\n    assert g_src.count(OLD) == 1\n    new = OLD + f\"                if (firstInStep && tradeBoost > {k} * BPS) tradeBoost = {k} * BPS;\\n\"\n    return g_src.replace(OLD, new)\nif __name__ == \"__main__\":\n    g = open(sys.argv[1]).read()\n    assert hashlib.sha256(g.encode()).hexdigest() == \"610c1905e7dd5559b84e40a3b2d6f8e0b53a7b0ac7574ae33b6c1770a28367cb\"\n    for k in map(int, sys.argv[3:]):\n        s = make(g, k); p = f\"{sys.argv[2]}/GCap{k}.sol\"; open(p, \"w\").write(s)\n        print(k, p, hashlib.sha256(s.encode()).hexdigest())\n",
 "variant_generator_usage": "python gen.py contracts/src/G.sol OUTDIR 4 8 16 32  (asserts G sha256; inserts one line after the tradeBoost assignment)",
 "paired": {
  "n": 512,
  "mean_diff": 0.013459151610404785,
  "se": 0.005702257954794114,
  "sd": 0.12902736857311525,
  "n_nonzero": 495,
  "worst": {
   "seed": 12143,
   "diff": -0.16893907899577698,
   "edge_a": 406.2539967000602,
   "edge_b": 406.422935779056
  },
  "stage": "tuning",
  "seeds": [
   12000,
   12511
  ]
 },
 "stages": {
  "screen": {
   "seeds": [
    10000,
    10255
   ],
   "n": 256,
   "reference": "V2 run once, its rows reused for every candidate",
   "G_control": {
    "sha256": "610c1905e7dd5559b84e40a3b2d6f8e0b53a7b0ac7574ae33b6c1770a28367cb",
    "valid": true,
    "invalid_reasons": [],
    "paired": {
     "n": 256,
     "mean_diff": 0.002904894772038702,
     "se": 0.002857312170046356,
     "sd": 0.0457169947207417,
     "n_nonzero": 5,
     "worst": {
      "seed": 10044,
      "diff": -0.023879557265217954,
      "edge_a": 581.4479025749735,
      "edge_b": 581.4717821322387
     }
    },
    "edge_component_deltas_vs_V2": {
     "retail": {
      "mean_diff": -0.00032599031636637577,
      "se": 0.0002866995092404792
     },
     "arb": {
      "mean_diff": 0.0032308850883991103,
      "se": 0.0031205864312076224
     }
    },
    "retail_volume_y_delta": {
     "mean": -0.11089077048507079,
     "se": 0.0819791498696051
    },
    "v2_volume_terciles": {
     "low": {
      "n": 85,
      "mean_diff": -2.4036177770165736e-05,
      "se": 2.403617777016574e-05,
      "v2_retail_volume_y_range": [
       57146.525064967944,
       70352.36088653858
      ]
     },
     "mid": {
      "n": 85,
      "mean_diff": 0.00892753401864518,
      "se": 0.008596601552777522,
      "v2_retail_volume_y_range": [
       70606.56468501159,
       81644.02672968531
      ]
     },
     "high": {
      "n": 86,
      "mean_diff": -0.00015284017247056401,
      "se": 0.0003057745660954134,
      "v2_retail_volume_y_range": [
       82121.65976706463,
       98205.47208725398
      ]
     }
    },
    "gas": {
     "max_ok_afterSwap": 211186,
     "init_max": 220944,
     "max_ok_any": 220944,
     "oog": 0,
     "oog_seeds": [],
     "other_errors": 0,
     "afterSwap_calls": 2644186,
     "vanilla_oog": 0,
     "vanilla_other_errors": 0,
     "complete": true,
     "counters_per_seed_match_global": true,
     "max_abs_reconciliation_error": 7.673861546209082e-12
    }
   },
   "variants": {
    "K4": {
     "K": 4,
     "cap_wad": 400000000000000,
     "sha256": "83cd2c9c4973608148a90dbae657f7e21f1b9d5119ff9a16036d54c377cc03c3",
     "screen": {
      "sha256": "83cd2c9c4973608148a90dbae657f7e21f1b9d5119ff9a16036d54c377cc03c3",
      "valid": true,
      "invalid_reasons": [],
      "paired": {
       "n": 256,
       "mean_diff": -0.1920413549451021,
       "se": 0.017830687103436323,
       "sd": 0.2852909936549812,
       "n_nonzero": 256,
       "worst": {
        "seed": 10121,
        "diff": -1.2136531296989688,
        "edge_a": 693.9814014695366,
        "edge_b": 695.1950545992356
       }
      },
      "edge_component_deltas_vs_V2": {
       "retail": {
        "mean_diff": 0.2067545577062404,
        "se": 0.017740384757087904
       },
       "arb": {
        "mean_diff": -0.3987959126515662,
        "se": 0.010017970917580095
       }
      },
      "retail_volume_y_delta": {
       "mean": 145.90831426324712,
       "se": 4.17587655039864
      },
      "v2_volume_terciles": {
       "low": {
        "n": 85,
        "mean_diff": -0.141370571927879,
        "se": 0.02853773752954078,
        "v2_retail_volume_y_range": [
         57146.525064967944,
         70352.36088653858
        ]
       },
       "mid": {
        "n": 85,
        "mean_diff": -0.20803047132045013,
        "se": 0.029450489813172623,
        "v2_retail_volume_y_range": [
         70606.56468501159,
         81644.02672968531
        ]
       },
       "high": {
        "n": 86,
        "mean_diff": -0.226319746393467,
        "se": 0.033910827146139834,
        "v2_retail_volume_y_range": [
         82121.65976706463,
         98205.47208725398
        ]
       }
      },
      "gas": {
       "max_ok_afterSwap": 211349,
       "init_max": 220962,
       "max_ok_any": 220962,
       "oog": 0,
       "oog_seeds": [],
       "other_errors": 0,
       "afterSwap_calls": 2647744,
       "vanilla_oog": 0,
       "vanilla_other_errors": 0,
       "complete": true,
       "counters_per_seed_match_global": true,
       "max_abs_reconciliation_error": 8.29913915367797e-12
      }
     }
    },
    "K8": {
     "K": 8,
     "cap_wad": 800000000000000,
     "sha256": "d7809f87123fbccc38080fc7f85cb20140b36bde9ef925fe125819f5227ad837",
     "screen": {
      "sha256": "d7809f87123fbccc38080fc7f85cb20140b36bde9ef925fe125819f5227ad837",
      "valid": true,
      "invalid_reasons": [],
      "paired": {
       "n": 256,
       "mean_diff": -0.0399470252283507,
       "se": 0.009683303108091235,
       "sd": 0.15493284972945975,
       "n_nonzero": 256,
       "worst": {
        "seed": 10142,
        "diff": -0.4903629964965148,
        "edge_a": 571.7759802427119,
        "edge_b": 572.2663432392084
       }
      },
      "edge_component_deltas_vs_V2": {
       "retail": {
        "mean_diff": 0.049854942491564413,
        "se": 0.010432009653921867
       },
       "arb": {
        "mean_diff": -0.08980196772002555,
        "se": 0.006208329028115429
       }
      },
      "retail_volume_y_delta": {
       "mean": 29.41087773142553,
       "se": 2.9564583119442447
      },
      "v2_volume_terciles": {
       "low": {
        "n": 85,
        "mean_diff": 0.0005794287337968907,
        "se": 0.01880300238271269,
        "v2_retail_volume_y_range": [
         57146.525064967944,
         70352.36088653858
        ]
       },
       "mid": {
        "n": 85,
        "mean_diff": -0.06502920125025184,
        "se": 0.016277939377270102,
        "v2_retail_volume_y_range": [
         70606.56468501159,
         81644.02672968531
        ]
       },
       "high": {
        "n": 86,
        "mean_diff": -0.055211718541384965,
        "se": 0.01428500149819179,
        "v2_retail_volume_y_range": [
         82121.65976706463,
         98205.47208725398
        ]
       }
      },
      "gas": {
       "max_ok_afterSwap": 211347,
       "init_max": 220962,
       "max_ok_any": 220962,
       "oog": 0,
       "oog_seeds": [],
       "other_errors": 0,
       "afterSwap_calls": 2645058,
       "vanilla_oog": 0,
       "vanilla_other_errors": 0,
       "complete": true,
       "counters_per_seed_match_global": true,
       "max_abs_reconciliation_error": 5.002220859751105e-12
      }
     }
    },
    "K16": {
     "K": 16,
     "cap_wad": 1600000000000000,
     "sha256": "ab4a2640963d22cb94502234e5e05684faff9ad7ddade860a0ebdb4168388bea",
     "screen": {
      "sha256": "ab4a2640963d22cb94502234e5e05684faff9ad7ddade860a0ebdb4168388bea",
      "valid": true,
      "invalid_reasons": [],
      "paired": {
       "n": 256,
       "mean_diff": 0.006006198955234909,
       "se": 0.006638662214627736,
       "sd": 0.10621859543404377,
       "n_nonzero": 247,
       "worst": {
        "seed": 10075,
        "diff": -0.33097435792944907,
        "edge_a": 617.3323292057667,
        "edge_b": 617.6633035636961
       }
      },
      "edge_component_deltas_vs_V2": {
       "retail": {
        "mean_diff": 0.006901474774756444,
        "se": 0.007724556158564582
       },
       "arb": {
        "mean_diff": -0.0008952758195720223,
        "se": 0.004789462846076989
       }
      },
      "retail_volume_y_delta": {
       "mean": 4.502498070509887,
       "se": 2.647759216627023
      },
      "v2_volume_terciles": {
       "low": {
        "n": 85,
        "mean_diff": 0.029262820854468345,
        "se": 0.016353995828484486,
        "v2_retail_volume_y_range": [
         57146.525064967944,
         70352.36088653858
        ]
       },
       "mid": {
        "n": 85,
        "mean_diff": -8.190453630063263e-05,
        "se": 0.009406881168274988,
        "v2_retail_volume_y_range": [
         70606.56468501159,
         81644.02672968531
        ]
       },
       "high": {
        "n": 86,
        "mean_diff": -0.010962685517489754,
        "se": 0.005983238384804541,
        "v2_retail_volume_y_range": [
         82121.65976706463,
         98205.47208725398
        ]
       }
      },
      "gas": {
       "max_ok_afterSwap": 211347,
       "init_max": 220962,
       "max_ok_any": 220962,
       "oog": 0,
       "oog_seeds": [],
       "other_errors": 0,
       "afterSwap_calls": 2644415,
       "vanilla_oog": 0,
       "vanilla_other_errors": 0,
       "complete": true,
       "counters_per_seed_match_global": true,
       "max_abs_reconciliation_error": 7.503331289626658e-12
      }
     }
    },
    "K32": {
     "K": 32,
     "cap_wad": 3200000000000000,
     "sha256": "9b9a2efc610e51ada65ead4da6ed26e6aa1899f1683603b065c66e5fc8958ade",
     "screen": {
      "sha256": "9b9a2efc610e51ada65ead4da6ed26e6aa1899f1683603b065c66e5fc8958ade",
      "valid": true,
      "invalid_reasons": [],
      "paired": {
       "n": 256,
       "mean_diff": 0.005037802624973775,
       "se": 0.00552862376218004,
       "sd": 0.08845798019488064,
       "n_nonzero": 33,
       "worst": {
        "seed": 10214,
        "diff": -0.1791814415397539,
        "edge_a": 517.938832753861,
        "edge_b": 518.1180141954007
       }
      },
      "edge_component_deltas_vs_V2": {
       "retail": {
        "mean_diff": 0.0028048040140213892,
        "se": 0.0072308779352742445
       },
       "arb": {
        "mean_diff": 0.0022329986109413252,
        "se": 0.004040691338104533
       }
      },
      "retail_volume_y_delta": {
       "mean": 2.8022894316570444,
       "se": 2.617481845466125
      },
      "v2_volume_terciles": {
       "low": {
        "n": 85,
        "mean_diff": 0.013526667297615216,
        "se": 0.01392825581895958,
        "v2_retail_volume_y_range": [
         57146.525064967944,
         70352.36088653858
        ]
       },
       "mid": {
        "n": 85,
        "mean_diff": 0.005569328962153176,
        "se": 0.008944513326936786,
        "v2_retail_volume_y_range": [
         70606.56468501159,
         81644.02672968531
        ]
       },
       "high": {
        "n": 86,
        "mean_diff": -0.003877700117291011,
        "se": 0.0018851478741109004,
        "v2_retail_volume_y_range": [
         82121.65976706463,
         98205.47208725398
        ]
       }
      },
      "gas": {
       "max_ok_afterSwap": 211347,
       "init_max": 220962,
       "max_ok_any": 220962,
       "oog": 0,
       "oog_seeds": [],
       "other_errors": 0,
       "afterSwap_calls": 2644352,
       "vanilla_oog": 0,
       "vanilla_other_errors": 0,
       "complete": true,
       "counters_per_seed_match_global": true,
       "max_abs_reconciliation_error": 7.673861546209082e-12
      }
     }
    }
   },
   "v2_gas": {
    "max_ok_afterSwap": 243554,
    "init_max": 236377,
    "max_ok_any": 243554,
    "oog": 7,
    "oog_seeds": [
     [
      10043,
      2
     ],
     [
      10044,
      1
     ],
     [
      10057,
      1
     ],
     [
      10150,
      2
     ],
     [
      10231,
      1
     ]
    ],
    "other_errors": 0,
    "afterSwap_calls": 2644187,
    "vanilla_oog": 0,
    "vanilla_other_errors": 0,
    "complete": true,
    "counters_per_seed_match_global": true,
    "max_abs_reconciliation_error": 7.673861546209082e-12
   }
  },
  "tuning": {
   "seeds": [
    12000,
    12511
   ],
   "n": 512,
   "variant": "K16",
   "result": {
    "sha256": "ab4a2640963d22cb94502234e5e05684faff9ad7ddade860a0ebdb4168388bea",
    "valid": true,
    "invalid_reasons": [],
    "paired": {
     "n": 512,
     "mean_diff": 0.013459151610404785,
     "se": 0.005702257954794114,
     "sd": 0.12902736857311525,
     "n_nonzero": 495,
     "worst": {
      "seed": 12143,
      "diff": -0.16893907899577698,
      "edge_a": 406.2539967000602,
      "edge_b": 406.422935779056
     }
    },
    "edge_component_deltas_vs_V2": {
     "retail": {
      "mean_diff": 0.013973005089824686,
      "se": 0.004654767059247085
     },
     "arb": {
      "mean_diff": -0.0005138534794958058,
      "se": 0.002443984872211496
     }
    },
    "retail_volume_y_delta": {
     "mean": 3.1525638119887702,
     "se": 0.6353476268765387
    },
    "v2_volume_terciles": {
     "low": {
      "n": 170,
      "mean_diff": 0.013355125325244565,
      "se": 0.008573701375409852,
      "v2_retail_volume_y_range": [
       56609.85690614511,
       69222.66461157559
      ]
     },
     "mid": {
      "n": 170,
      "mean_diff": 0.007563580222285496,
      "se": 0.006473916909437844,
      "v2_retail_volume_y_range": [
       69299.74772823698,
       79829.17813642243
      ]
     },
     "high": {
      "n": 172,
      "mean_diff": 0.01938898652004151,
      "se": 0.013269924699892908,
      "v2_retail_volume_y_range": [
       79891.65741965121,
       97575.07091417206
      ]
     }
    },
    "gas": {
     "max_ok_afterSwap": 213308,
     "init_max": 220962,
     "max_ok_any": 220962,
     "oog": 0,
     "oog_seeds": [],
     "other_errors": 0,
     "afterSwap_calls": 5254672,
     "vanilla_oog": 0,
     "vanilla_other_errors": 0,
     "complete": true,
     "counters_per_seed_match_global": true,
     "max_abs_reconciliation_error": 8.412825991399586e-12
    }
   },
   "v2_gas": {
    "max_ok_afterSwap": 243733,
    "init_max": 236377,
    "max_ok_any": 243733,
    "oog": 10,
    "oog_seeds": [
     [
      12120,
      1
     ],
     [
      12129,
      1
     ],
     [
      12138,
      1
     ],
     [
      12221,
      2
     ],
     [
      12286,
      3
     ],
     [
      12288,
      1
     ],
     [
      12505,
      1
     ]
    ],
    "other_errors": 0,
    "afterSwap_calls": 5254411,
    "vanilla_oog": 0,
    "vanilla_other_errors": 0,
    "complete": true,
    "counters_per_seed_match_global": true,
    "max_abs_reconciliation_error": 6.821210263296962e-12
   }
  }
 },
 "selection": {
  "rule": "highest screen paired mean_diff vs V2 among valid variants (all four valid: 0 OOG, 0 other errors)",
  "screen_mean_diff": {
   "K4": -0.1920413549451021,
   "K8": -0.0399470252283507,
   "K16": 0.006006198955234909,
   "K32": 0.005037802624973775
  },
  "G_control_screen_mean_diff": 0.002904894772038702,
  "selected": "K16",
  "note": "K16 vs K32 vs G differences on the screen are well inside 1 se; selection is noise-limited. K4 and K8 are clearly harmful (retail edge up, arb edge down more)."
 },
 "freeze": {
  "frozen_after": "tuning stage 12000..12511",
  "sha256": "ab4a2640963d22cb94502234e5e05684faff9ad7ddade860a0ebdb4168388bea"
 },
 "gas": {
  "max_ok": 213308,
  "init_max": 220962,
  "oog": 0,
  "other_errors": 0,
  "stage": "tuning",
  "screen_max_ok": 211347,
  "screen_oog": 0
 },
 "v2_gas": {
  "max_ok": 243733,
  "init_max": 236377,
  "oog": 10,
  "other_errors": 0,
  "oog_seeds": [
   [
    12120,
    1
   ],
   [
    12129,
    1
   ],
   [
    12138,
    1
   ],
   [
    12221,
    2
   ],
   [
    12286,
    3
   ],
   [
    12288,
    1
   ],
   [
    12505,
    1
   ]
  ],
  "stage": "tuning",
  "screen_max_ok": 243554,
  "screen_oog": 7,
  "screen_oog_seeds": [
   [
    10043,
    2
   ],
   [
    10044,
    1
   ],
   [
    10057,
    1
   ],
   [
    10150,
    2
   ],
   [
    10231,
    1
   ]
  ]
 },
 "oog_attribution": {
  "note": "G is bit-identical to V2 except on seeds where V2 hits OOG (prior e06 result); the K16-minus-V2 diff on non-V2-OOG seeds approximates K16-minus-G.",
  "screen_K16_excluding_v2_oog_seeds": {
   "n": 251,
   "mean_diff": 0.002923034293338646,
   "se": 0.006114208605817142
  },
  "screen_G_excluding_v2_oog_seeds": {
   "n": 251,
   "mean_diff": 0.0,
   "se": 0.0
  },
  "tuning_K16_excluding_v2_oog_seeds": {
   "n": 505,
   "mean_diff": 0.012523450627809504,
   "se": 0.00568114743205414
  },
  "tuning_contribution_of_v2_oog_seeds_to_mean": 0.0011069200341473628
 },
 "edge_component_deltas_vs_V2": {
  "screen_K16": {
   "retail": {
    "mean_diff": 0.006901474774756444,
    "se": 0.007724556158564582
   },
   "arb": {
    "mean_diff": -0.0008952758195720223,
    "se": 0.004789462846076989
   }
  },
  "tuning_K16": {
   "retail": {
    "mean_diff": 0.013973005089824686,
    "se": 0.004654767059247085
   },
   "arb": {
    "mean_diff": -0.0005138534794958058,
    "se": 0.002443984872211496
   }
  }
 },
 "v2_volume_terciles": {
  "screen_K16": {
   "low": {
    "n": 85,
    "mean_diff": 0.029262820854468345,
    "se": 0.016353995828484486,
    "v2_retail_volume_y_range": [
     57146.525064967944,
     70352.36088653858
    ]
   },
   "mid": {
    "n": 85,
    "mean_diff": -8.190453630063263e-05,
    "se": 0.009406881168274988,
    "v2_retail_volume_y_range": [
     70606.56468501159,
     81644.02672968531
    ]
   },
   "high": {
    "n": 86,
    "mean_diff": -0.010962685517489754,
    "se": 0.005983238384804541,
    "v2_retail_volume_y_range": [
     82121.65976706463,
     98205.47208725398
    ]
   }
  },
  "tuning_K16": {
   "low": {
    "n": 170,
    "mean_diff": 0.013355125325244565,
    "se": 0.008573701375409852,
    "v2_retail_volume_y_range": [
     56609.85690614511,
     69222.66461157559
    ]
   },
   "mid": {
    "n": 170,
    "mean_diff": 0.007563580222285496,
    "se": 0.006473916909437844,
    "v2_retail_volume_y_range": [
     69299.74772823698,
     79829.17813642243
    ]
   },
   "high": {
    "n": 172,
    "mean_diff": 0.01938898652004151,
    "se": 0.013269924699892908,
    "v2_retail_volume_y_range": [
     79891.65741965121,
     97575.07091417206
    ]
   }
  }
 },
 "method": {
  "simulator": "github.com/benedictbrady/amm-challenge @ 6b6921f8d463314aa7c96234e1be25a25245f704, Linux x86_64, release build with instrumentation.patch from G artifact bundle",
  "runs": "each strategy separately: amm_sim_rs.run_batch(X, VanillaStrategy, configs, 8), chunks of 32 seeds, all seeds kept",
  "configs": "MatchRunner._build_configs per seed: default_rng(seed) uniform size, rate, sigma; price seed, retail seed+1; 10000 steps; afterSwap/init gas 250000",
  "validity": "bundle harness.validity: complete seeds, finite edges, no revert/tx_error/other_halt/bad_return, Vanilla no failures, per-seed vs global counters equal, |total-retail-arb| < 1e-8, candidate OOG <= V2 OOG"
 },
 "checks": {
  "G_sha256_verified": true,
  "V2_sha256_verified": true,
  "V2_rebuilt_from_base_artifact_matches": true,
  "setup_sh_ok": true,
  "instrumentation_patch_applied_and_rebuilt": true,
  "harness_tests_all_pass": true,
  "amm_match_validate": {
   "G": true,
   "V2": true,
   "K4": true,
   "K8": true,
   "K16": true,
   "K32": true
  },
  "all_runs_complete_counters_match_reconciled": true,
  "max_seed_used": 12511,
  "no_seeds_ge_4000000": true
 },
 "interpretation": "Capping the first-in-step aligned boost at 16 bps is neutral-to-slightly-positive (screen +0.006+/-0.007 vs V2, of which ~+0.003 is G's OOG removal; tuning +0.0135+/-0.0057, +0.0125 on non-OOG seeds). Tighter caps (4, 8 bps) lose more arb edge than they gain retail edge. This is orders of magnitude below the +5.0 (top 10) / +8.7 (1st) targets: saturating large-trade protection is not the missing fee rule.",
 "not_measured": [
  "No confirmation on seeds >= 4000000 (separate episode); the tuning stage is not a confirmation.",
  "K16 vs G was not run directly on 12000..12511 (brief: only best variant); approximated via non-V2-OOG seeds.",
  "No board submission or rank claim."
 ]
}