{
  "item": "b",
  "blocked": null,
  "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            // Process variance is propagated inside the censored update.\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        // Censored assumed-density posterior. No external or future inputs.\n        (fastHat, uncertainty) = _posterior(PosteriorInput(\n            fastHat, uncertainty, pImplied, spot, slots[2] >> 64,\n            prevBidFee, prevAskFee, firstInStep, silent, trade.isBuy,\n            trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0\n        ));\n        slots[13] = uncertainty;\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        if (firstInStep) {\n            if (askFee > bidFee && bidFee > 28 * BPS) bidFee = 28 * BPS;\n            else if (bidFee > askFee && askFee > 28 * BPS) askFee = 28 * BPS;\n        }\n\n        if (bidFee > askFee && askFee > 36 * BPS) askFee = 36 * BPS;\n        else if (askFee > bidFee && bidFee > 36 * BPS) bidFee = 36 * BPS;\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\n    struct PosteriorInput {\n        uint256 mu; uint256 v; uint256 obs; uint256 spot; uint256 preSpot;\n        uint256 bid; uint256 ask; bool first; uint256 silent; bool buy; uint256 size;\n    }\n    function _posterior(PosteriorInput memory x) internal pure returns (uint256, uint256) {\n        if (x.mu == 0) x.mu = x.spot;\n        if (x.v < 10000000000) x.v = 10000000000;\n        uint256 lo = wmul(x.preSpot, WAD-x.bid);\n        uint256 hi = wdiv(x.preSpot, WAD-x.ask);\n        if (x.first) {\n            if (x.silent>1 && x.preSpot>0) {\n                uint256 elapsed=x.silent>8?8:x.silent;\n                x.v += 902500000000*(elapsed-1);\n                (x.mu,x.v)=_band(x.mu,x.v,lo,hi);\n            }\n            x.v+=902500000000;\n        }\n        uint256 mRetail = x.mu;\n        uint256 vRetail = x.v;\n        // A missing own-pool trade is a censored price observation.\n        if (x.first && x.preSpot > 0) {\n            (mRetail, vRetail) = _band(x.mu, x.v, lo, hi);\n        }\n        if (!x.first) {\n            // A later print is retail. Only an interior route is an observation\n            // of the other pool, with explicit observation uncertainty.\n            uint256 fee = x.buy ? x.bid : x.ask;\n            if (fee > 30 * BPS) {\n                uint256 normal = x.buy ? wdiv(wmul(x.spot, WAD-fee), WAD-30*BPS)\n                    : wdiv(wmul(x.spot, WAD-30*BPS), WAD-fee);\n                uint256 residual = wdiv(absDiff(normal, x.mu),x.mu);\n                uint256 noise = 9000000000000 + wmul(residual,residual);\n                uint256 k = wdiv(x.v,x.v+noise);\n                return (_blend(x.mu,normal,k),wmul(x.v,WAD-k));\n            }\n            return (x.mu,x.v);\n        }\n        uint256 e = wdiv(absDiff(x.obs,x.mu),x.mu);\n        uint256 totalV = x.v + 22500000000;\n        uint256 z = wdiv(wmul(e,e),totalV);\n        uint256 density = _powWad(wdiv(WAD,WAD+z/8),4);\n        uint256 odds = wmul(density,wdiv(4000000000000000,_isqrt(totalV*WAD)));\n        if (x.size > 3000000000000000) odds = wmul(odds,4*WAD/10);\n        if (x.silent > 1) odds = wmul(odds,8*WAD/10);\n        uint256 sd = _isqrt(x.v*WAD);\n        uint256 width = wdiv(hi-lo,x.mu);\n        uint256 distance = x.mu<lo?lo-x.mu:(x.mu>hi?x.mu-hi:0);\n        uint256 zBand = wdiv(wdiv(distance,x.mu),sd);\n        uint256 mass = wmul(wdiv(width,width+2*sd),wdiv(WAD,WAD+wmul(zBand,zBand)));\n        if (mass < WAD/100) mass = WAD/100;\n        odds = wdiv(odds,mass);\n        uint256 prob = wdiv(odds,WAD+odds);\n        uint256 kArb = wdiv(x.v,totalV);\n        uint256 mArb = _blend(x.mu,x.obs,kArb);\n        uint256 mean = _blend(mRetail,mArb,prob);\n        uint256 between = wdiv(absDiff(mArb,mRetail),x.mu);\n        uint256 variance = wmul(prob,wmul(x.v,WAD-kArb)) + wmul(WAD-prob,vRetail)\n            + wmul(wmul(prob,WAD-prob),wmul(between,between));\n        if (variance > 100000000000000) variance = 100000000000000;\n        return (mean,variance);\n    }\n    function _blend(uint256 a,uint256 b,uint256 w) internal pure returns(uint256) {\n        return b>=a ? a+wmul(b-a,w) : a-wmul(a-b,w);\n    }\n    function _band(uint256 mu,uint256 v,uint256 lo,uint256 hi) internal pure returns(uint256,uint256) {\n        // Soft interval likelihood avoids discontinuities at quadrature nodes.\n        uint256 sd=wmul(mu,_isqrt(v*WAD));\n        uint256[3] memory acc;\n        for(uint256 j=0;j<7;j++) {\n            uint256 p=j<3 ? (mu>(3-j)*sd?mu-(3-j)*sd:1) : mu+(j-3)*sd;\n            uint256 w=j==3?72:(j==2||j==4?45:(j==1||j==5?10:1));\n            uint256 distance=p<lo?lo-p:(p>hi?p-hi:0);\n            uint256 z=sd>0?wdiv(distance,sd):0;\n            uint256 likelihood=wdiv(WAD,WAD+4*wmul(z,z));\n            w=wmul(w*WAD,likelihood);\n            acc[0]+=w;acc[1]+=wmul(w,p);\n            uint256 d=wdiv(absDiff(p,mu),mu);\n            acc[2]+=wmul(w,wmul(d,d));\n        }\n        uint256 m=wdiv(acc[1],acc[0]);\n        uint256 d=wdiv(absDiff(m,mu),mu);\n        uint256 second=wdiv(acc[2],acc[0]);\n        return(m,second>wmul(d,d)?second-wmul(d,d):10000000000);\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 \"censored_10\"; }\n}\n",
  "sha256": "6694d28afa215f0851a46e87b645bbf05fd298df564278b0af3666b589b53cb6",
  "settings": {
    "frozen_name": "C28",
    "STALE_ATTRACT_FRAC": 1.05,
    "post_stale_lower_fee_multiplier": 1.0,
    "first_in_step_lower_fee_cap_bps": 28,
    "base_v10_sha256": "cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245",
    "stack_sha256": "2eaafc7960e520b8a7fd322ec8afaff8fa677c730228a961efb509cc30b25719",
    "tuning_seeds": {
      "screen": [
        500000,
        500128
      ],
      "shortlist": [
        500128,
        500512
      ],
      "intervals": "start inclusive, stop exclusive"
    },
    "freeze": {
      "sha256": "6694d28afa215f0851a46e87b645bbf05fd298df564278b0af3666b589b53cb6",
      "settings": {
        "winner": "C28",
        "shortlist": [
          {
            "name": "combo",
            "n": 384,
            "mean_diff": 0.0,
            "se": 0.0,
            "worst": 0.0
          },
          {
            "name": "C28",
            "n": 384,
            "mean_diff": 0.003219679518680074,
            "se": 0.004668441032463799,
            "worst": -0.3282180908857981
          },
          {
            "name": "C26",
            "n": 384,
            "mean_diff": -0.003061487874739773,
            "se": 0.00703579660260766,
            "worst": -0.4712395460336438
          }
        ],
        "axis_winners": []
      },
      "validation": "Validating strategy...\nCompiling strategy...\nStrategy 'censored_10' validated successfully!\n",
      "confirmation_seeds": {
        "start": 5022000,
        "stop_exclusive": 5024000
      },
      "time_unix": 1794168034.2657008
    }
  },
  "screen": [
    {
      "axis": "A",
      "value": "1.3",
      "name": "A1.3",
      "n": 128,
      "mean_diff": -0.6061829850725653,
      "se": 0.04841784334925674,
      "worst": -3.8512583617805376,
      "gas": {
        "max_ok": 192715,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1328862,
        "all_roles_valid": true
      }
    },
    {
      "axis": "A",
      "value": "1.6",
      "name": "A1.6",
      "n": 128,
      "mean_diff": -1.542184564464073,
      "se": 0.06025194323147257,
      "worst": -4.8653376393285725,
      "gas": {
        "max_ok": 192715,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1337354,
        "all_roles_valid": true
      }
    },
    {
      "axis": "A",
      "value": "2.0",
      "name": "A2.0",
      "n": 128,
      "mean_diff": -2.6650107536086103,
      "se": 0.07528654704690625,
      "worst": -6.662012250228713,
      "gas": {
        "max_ok": 194408,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1345409,
        "all_roles_valid": true
      }
    },
    {
      "axis": "B",
      "value": "0.85",
      "name": "B0.85",
      "n": 128,
      "mean_diff": -0.46940068771808807,
      "se": 0.047484485730991156,
      "worst": -4.321894184243774,
      "gas": {
        "max_ok": 192755,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1327606,
        "all_roles_valid": true
      }
    },
    {
      "axis": "B",
      "value": "0.9",
      "name": "B0.9",
      "n": 128,
      "mean_diff": -0.2847706953731093,
      "se": 0.04158938713346733,
      "worst": -3.708028919911044,
      "gas": {
        "max_ok": 192755,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1324342,
        "all_roles_valid": true
      }
    },
    {
      "axis": "B",
      "value": "0.95",
      "name": "B0.95",
      "n": 128,
      "mean_diff": -0.1418608505234178,
      "se": 0.040311578054494604,
      "worst": -3.5261244411090047,
      "gas": {
        "max_ok": 192755,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1321095,
        "all_roles_valid": true
      }
    },
    {
      "axis": "C",
      "value": "26",
      "name": "C26",
      "n": 128,
      "mean_diff": -0.021152374940780927,
      "se": 0.013337181175086057,
      "worst": -0.7074286828420782,
      "gas": {
        "max_ok": 192715,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1318425,
        "all_roles_valid": true
      }
    },
    {
      "axis": "C",
      "value": "28",
      "name": "C28",
      "n": 128,
      "mean_diff": -0.00634308022272112,
      "se": 0.007572621096743413,
      "worst": -0.39679692670074473,
      "gas": {
        "max_ok": 192715,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 1317912,
        "all_roles_valid": true
      }
    }
  ],
  "shortlist": {
    "axis_winners": [],
    "rows": [
      {
        "name": "combo",
        "n": 384,
        "mean_diff": 0.0,
        "se": 0.0,
        "worst": 0.0,
        "gas": {
          "max_ok": 192814,
          "oog": 0,
          "revert": 0,
          "other_halt": 0,
          "tx_error": 0,
          "bad_return": 0,
          "afterSwap_calls": 3902708,
          "all_roles_valid": true
        }
      },
      {
        "name": "C28",
        "n": 384,
        "mean_diff": 0.003219679518680074,
        "se": 0.004668441032463799,
        "worst": -0.3282180908857981,
        "gas": {
          "max_ok": 192814,
          "oog": 0,
          "revert": 0,
          "other_halt": 0,
          "tx_error": 0,
          "bad_return": 0,
          "afterSwap_calls": 3903690,
          "all_roles_valid": true
        }
      },
      {
        "name": "C26",
        "n": 384,
        "mean_diff": -0.003061487874739773,
        "se": 0.00703579660260766,
        "worst": -0.4712395460336438,
        "gas": {
          "max_ok": 192814,
          "oog": 0,
          "revert": 0,
          "other_halt": 0,
          "tx_error": 0,
          "bad_return": 0,
          "afterSwap_calls": 3905062,
          "all_roles_valid": true
        }
      }
    ]
  },
  "confirm": {
    "seeds": {
      "start": 5022000,
      "stop_exclusive": 5024000
    },
    "vs_stack": {
      "n": 2000,
      "mean_diff": 0.1533725409948071,
      "se": 0.014114041643220169,
      "worst": [
        {
          "seed": 5022131,
          "diff": -2.451734575486512,
          "candidate_edge": 704.1173568130467,
          "baseline_edge": 706.5690913885333
        },
        {
          "seed": 5022118,
          "diff": -2.215943386298818,
          "candidate_edge": 763.979581868786,
          "baseline_edge": 766.1955252550848
        },
        {
          "seed": 5023477,
          "diff": -2.1218475296800534,
          "candidate_edge": 700.246410103433,
          "baseline_edge": 702.3682576331131
        },
        {
          "seed": 5023811,
          "diff": -1.9670381279635194,
          "candidate_edge": 663.1095449845938,
          "baseline_edge": 665.0765831125573
        },
        {
          "seed": 5022404,
          "diff": -1.8788059066906726,
          "candidate_edge": 607.7254098142397,
          "baseline_edge": 609.6042157209304
        }
      ]
    },
    "vs_v10": {
      "n": 2000,
      "mean_diff": 0.0018787537178642708,
      "se": 0.002555729916292394,
      "worst": [
        {
          "seed": 5022990,
          "diff": -1.9318602942065581,
          "candidate_edge": 669.951330501462,
          "baseline_edge": 671.8831907956686
        },
        {
          "seed": 5023687,
          "diff": -0.9076099766446646,
          "candidate_edge": 380.97450088663385,
          "baseline_edge": 381.8821108632785
        },
        {
          "seed": 5022721,
          "diff": -0.7519313357822739,
          "candidate_edge": 638.3389604475109,
          "baseline_edge": 639.0908917832932
        },
        {
          "seed": 5022205,
          "diff": -0.5014602720435732,
          "candidate_edge": 579.250381152992,
          "baseline_edge": 579.7518414250355
        },
        {
          "seed": 5022483,
          "diff": -0.48043521210405515,
          "candidate_edge": 508.004541027648,
          "baseline_edge": 508.48497623975203
        }
      ]
    },
    "retail_edge_delta": {
      "mean_diff": -1.1112437414958636,
      "se": 0.014442400417784723
    },
    "arb_edge_delta": {
      "mean_diff": 1.2646162824906715,
      "se": 0.0075057654723846
    },
    "retail_edge_delta_vs_v10": {
      "mean_diff": 0.0067699861335822785,
      "se": 0.0023090360838334727
    },
    "arb_edge_delta_vs_v10": {
      "mean_diff": -0.004891232415715501,
      "se": 0.001227762128175223
    },
    "gas": {
      "max_ok": 194759,
      "oog": 0,
      "revert": 0,
      "other_halt": 0,
      "tx_error": 0,
      "bad_return": 0,
      "afterSwap_calls": 20404709,
      "all_roles_valid": true
    },
    "gas_per_arm": {
      "frozen": {
        "max_ok": 194759,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 20404709,
        "all_roles_valid": true
      },
      "stack": {
        "max_ok": 213500,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 20644146,
        "all_roles_valid": true
      },
      "v10": {
        "max_ok": 194759,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 20399843,
        "all_roles_valid": true
      }
    },
    "arm_means": {
      "frozen": {
        "edge": 524.1696204169014,
        "retail": 550.4699525444342,
        "arb": -26.300332127532872
      },
      "stack": {
        "edge": 524.0162478759065,
        "retail": 551.5811962859301,
        "arb": -27.564948410023543
      },
      "v10": {
        "edge": 524.1677416631835,
        "retail": 550.4631825583007,
        "arb": -26.29544089511715
      }
    },
    "max_arb_volume_reconstruction_error": 0.00017910497626871802,
    "valid": false,
    "strict_protocol_compliant": false,
    "simulator_valid": true
  },
  "notes": {
    "protocol": "Each strategy runs alone against VanillaStrategy in amm_sim_rs.run_batch(X, Vanilla, configs, 8). Default 10000-step configs use default_rng(seed) to draw size U[19,21], rate U[0.6,1.0], sigma U[0.000882,0.001008], price seed=seed, retail seed=seed+1. No seed dropped. Paired SE uses sample SD (ddof=1)/sqrt(n). All differences are candidate minus indicated baseline.",
    "confirmation_batching": "Each confirmation arm visits each of 2000 seeds once, in disjoint batches of 64 (last 16), resetting gas counters per batch and summing counts / taking max gas. Frozen source and validation recorded before opening confirmation results. V10 confirmation aliases the frozen results only when sources are exactly identical.",
    "selection": "Choose best positive screen result per axis for combo; shortlist combo and two highest-scoring singles on next 384. Keep V10 when no shortlisted candidate beats it. No confirmation-driven change.",
    "B_implementation": "Multiply the strictly lower of bidFee and askFee immediately after stale adjustment, before trade boost and tail compression; tied fees remain unchanged.",
    "decomposition": "Numerically reconstruct negative optimal arb profit from current fair price, preceding final spot and fees, initial reserves and constant k. Initial fees are obtained from afterInitialize. Retail=simulator total edge minus reconstructed arb. Reconstructed arb Y volume is checked against simulator arb_volume_y on every confirmation path (tolerance 1e-3 + 1e-8*reported Y volume).",
    "decomposition_diagnostic": {
      "seeds": [
        11000,
        11032
      ],
      "n_steps": 100,
      "zero_retail_paths": 10,
      "max_abs_total_minus_arb": 6.170923494419611e-11
    },
    "calibration": {
      "url": "https://raw.githubusercontent.com/ChengHua926/amm-challenge/d34a5199c59a4c44d5336a25f1436b4ae1f21104/contracts/src/Strategy.sol",
      "n": 1000,
      "seeds": [
        0,
        1000
      ],
      "mean_edge": 525.5258821780834,
      "expected": 525.5258821780834,
      "gas": {
        "max_ok": 151647,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 10445223,
        "all_roles_valid": true
      }
    },
    "wheel_sha256": "aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a",
    "simulator_commit": "6b6921f8d463314aa7c96234e1be25a25245f704",
    "gas_scope": "max_ok reports submission afterSwap only, limit 250000; error counters cover every submission callback. all_roles_valid checks both roles and all callback error types.",
    "evidence": "Strategy code and pinned simulator behavior use the URLs in sources.json. All reported measurements were produced locally; they are not claims copied from remote artifacts. No leaderboard submission or top-10 result is claimed.",
    "protocol_deviation": {
      "strict_single_pass": false,
      "repeated_arm": "frozen",
      "repeated_seeds": {
        "start": 5022000,
        "stop_exclusive": 5022064
      },
      "reason": "The first simulator batch completed with zero callback errors, but reconstruction asserted on an 8.922609049477614e-05 Y volume discrepancy before per-seed edges were saved. The same frozen bytecode was rerun on these 64 seeds after adding a checkpoint and adjusting only the numerical volume-check tolerance. No selection or fee-rule change used confirmation data. All other confirmation seeds were run once per arm. Treat this as a deviation from the requested strict single-pass protocol."
    },
    "recovery_repeat_check": {
      "n": 64,
      "original_mean_edge": 539.4746559204559,
      "recovered_mean_edge": 539.4746559204559,
      "exact_mean_match": true,
      "exact_callback_counter_match": true,
      "original_gas": {
        "max_ok": 190636,
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0,
        "afterSwap_calls": 658559,
        "all_roles_valid": true
      }
    },
    "numerical_audit": {
      "frozen": {
        "n": 2000,
        "max_abs_arb_edge_difference_stable_formula": 1.942126459653082e-09,
        "max_abs_arb_volume_difference": 0.00012192028589197434
      },
      "stack": {
        "n": 2000,
        "max_abs_arb_edge_difference_stable_formula": 1.8349055608268827e-09,
        "max_abs_arb_volume_difference": 0.00013519581625587307
      },
      "v10": {
        "n": 2000,
        "max_abs_arb_edge_difference_stable_formula": 1.887698886093858e-09,
        "max_abs_arb_volume_difference": 0.00017910497626871802
      }
    },
    "numerical_audit_method": "Cross-check the trade-value reconstruction against algebraically equivalent squared-root profit identities at optimal size, using saved spot/fair/fee paths. No extra simulator calls.",
    "outcome": "No tested cheaper-side variant improved the 128-seed screen. The retained cap variant was selected on the 384-seed shortlist; its holdout comparison is reported separately.",
    "holdout_interpretation": "The 28 bps cap adds only 0.0018787537178642708 edge versus V10 (SE 0.002555729916292394), so this experiment does not establish an improvement from making the attracting side cheaper. The +0.1533725409948071 gain over STACK is far below the approximately +5 local gain sought. The single-pass protocol caveat limits confirmation status."
  }
}
