{
 "item": "a",
 "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 SH_KAP = 47651212838280808;\n    uint256 constant SH_KM = 902272563060334976;\n    uint256 constant SH_SM = 870344047140699520;\n    uint256 constant SH_WA = 420025633952219712;\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 (SH_KAP > 0) {\n            (bidFee, askFee) = _shadow(bidFee, askFee, spot, pHat, wmul(SH_SM, wmul(sigmaHat, sigmaHat) + uncertainty), wmul(lambdaHat, sizeHat), sizeHat);\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 > 30 * BPS) bidFee = 30 * BPS;\n            else if (bidFee > askFee && askFee > 30 * BPS) askFee = 30 * 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    int256 constant IW = 1e18;\n    function _expNeg(int256 u) internal pure returns (int256) {\n        unchecked {\n        if (u <= 0) return IW;\n        int256 n = u / IW;\n        if (n >= 40) return 0;\n        int256 r = u - n * IW;\n        int256 t = IW - r / 7;\n        t = IW - r * t / IW / 6;\n        t = IW - r * t / IW / 5;\n        t = IW - r * t / IW / 4;\n        t = IW - r * t / IW / 3;\n        t = IW - r * t / IW / 2;\n        t = IW - r * t / IW;\n        return int256(_powWad(367879441171442322, uint256(n))) * t / IW;\n        }\n    }\n    // returns (Phi(d), phi(d)) in WAD\n    function _ncdf(int256 d) internal pure returns (int256 P, int256 q) {\n        unchecked {\n        int256 ad = d >= 0 ? d : -d;\n        if (ad > 8 * IW) { return (d >= 0 ? IW : int256(0), 0); }\n        q = _expNeg(ad * ad / IW / 2) * 398942280401432678 / IW;\n        int256 t = IW * IW / (IW + 231641900000000000 * ad / IW);\n        int256 p = 1330274429000000000;\n        p = -1821255978000000000 + t * p / IW;\n        p = 1781477937000000000 + t * p / IW;\n        p = -356563782000000000 + t * p / IW;\n        p = 319381530000000000 + t * p / IW;\n        p = t * p / IW;\n        int256 Q = q * p / IW;\n        P = d >= 0 ? IW - Q : Q;\n        }\n    }\n    // E(g-a)+ and E(g-a)+^2 for g~N(mu, s^2)\n    function _tail(int256 mu, int256 s, int256 s2, int256 a) internal pure returns (int256 t1, int256 t2) {\n        unchecked {\n        int256 x = mu - a;\n        (int256 P, int256 q) = _ncdf(x * IW / s);\n        t1 = x * P / IW + s * q / IW;\n        t2 = ((x * x / IW + s2) * P / IW) + (x * s / IW) * q / IW;\n        if (t1 < 0) t1 = 0;\n        if (t2 < 0) t2 = 0;\n        }\n    }\n    function _shadowJ2(int256 Va, int256 Vb, int256 lamSize, int256 kk) internal pure returns (int256) {\n        unchecked {\n        int256 sa = IW / 2 + kk * (30e14 - Va) / IW; if (sa < 0) sa = 0; if (sa > IW) sa = IW;\n        int256 sb = IW / 2 + kk * (30e14 - Vb) / IW; if (sb < 0) sb = 0; if (sb > IW) sb = IW;\n        return lamSize / 2 * ((sa * Va + sb * Vb) / IW) / IW;\n        }\n    }\n    function _shadow(uint256 b0, uint256 a0, uint256 spot, uint256 pHat, uint256 s2u, uint256 lamSizeU, uint256 sizeHat) internal pure returns (uint256, uint256) {\n        if (sizeHat == 0 || s2u == 0 || spot == 0) return (b0, a0);\n        int256 s2 = int256(s2u);\n        int256 s = int256(_isqrt(s2u * WAD));\n        if (s == 0) return (b0, a0);\n        int256 m = (int256(pHat) - int256(spot)) * IW / int256(spot);\n        int256 kk = int256(SH_KM) * IW / int256(4 * sizeHat);\n        int256 D = 3e14;\n        int256 lamSize = int256(lamSizeU);\n        int256 A0 = int256(a0); int256 B0 = int256(b0);\n        bool askSide = m >= 0;\n        // three pairs: base and the two one-side neighbours on the exposed side\n        int256[3] memory X; // candidate fee on the moving side\n        X[0] = askSide ? A0 : B0; X[1] = X[0] + D; X[2] = X[0] - D; if (X[2] < 0) X[2] = 0;\n        int256 fixedF = askSide ? B0 : A0;\n        int256 mo = askSide ? m : -m;\n        (int256 F1, int256 F2) = _tail(-mo, s, s2, fixedF);\n        int256 best; uint256 bi;\n        for (uint256 j = 0; j < 3; j++) {\n            (int256 M1, int256 M2) = _tail(mo, s, s2, X[j]);\n            int256 tau = mo - M1 + F1; // tau in moving-side orientation\n            int256 J = _shadowJ2(X[j] - tau, fixedF + tau, lamSize, kk) - int256(SH_WA) * ((M2 + F2) / 4) / IW;\n            if (j == 0 || J > best) { best = J; bi = j; }\n        }\n        int256 bj = askSide ? B0 : X[bi]; int256 aj = askSide ? X[bi] : A0;\n        int256 bn = int256(b0) + int256(SH_KAP) * (bj - int256(b0)) / IW;\n        int256 an = int256(a0) + int256(SH_KAP) * (aj - int256(a0)) / IW;\n        if (bn < 0) bn = 0; if (an < 0) an = 0;\n        return (uint256(bn), uint256(an));\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_shadow\"; }\n}\n",
 "sha256": "263a8b85ce918e2e97ca650e12141e599ab0537bcdc5c4c91de6d54749ca92f1",
 "params": {
  "kap": 0.047651212838280804,
  "km": 0.902272563060335,
  "sm": 0.8703440471406996,
  "wa": 0.4200256339522197
 },
 "evaluations": 20,
 "log": [
  {
   "gen": 0,
   "kap": 1.0074,
   "km": 1.6372,
   "sm": 1.2193,
   "wa": 0.4575,
   "crn_mean_diff": -0.8314,
   "max_ok": 220297,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 1.3432,
   "km": 1.3071,
   "sm": 0.7246,
   "wa": 1.4172,
   "crn_mean_diff": -1.3538,
   "max_ok": 220283,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 1.0187,
   "km": 1.193,
   "sm": 1.0172,
   "wa": 1.3882,
   "crn_mean_diff": -0.8037,
   "max_ok": 220301,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 0.3581,
   "km": 0.9069,
   "sm": 0.7488,
   "wa": 1.4323,
   "crn_mean_diff": -0.2331,
   "max_ok": 220283,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 0.8238,
   "km": 0.8391,
   "sm": 0.6255,
   "wa": 0.857,
   "crn_mean_diff": -0.656,
   "max_ok": 220767,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 0.8049,
   "km": 0.8476,
   "sm": 2.1737,
   "wa": 1.8295,
   "crn_mean_diff": -0.5931,
   "max_ok": 219999,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 0.0,
   "km": 0.3219,
   "sm": 0.9004,
   "wa": 0.7762,
   "crn_mean_diff": 0.0,
   "max_ok": 209193,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 0.9282,
   "km": 1.1393,
   "sm": 3.5634,
   "wa": 0.5131,
   "crn_mean_diff": -0.7264,
   "max_ok": 219999,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 0.5734,
   "km": 3.4064,
   "sm": 1.4741,
   "wa": 1.4886,
   "crn_mean_diff": -0.4314,
   "max_ok": 219995,
   "oog": 0
  },
  {
   "gen": 0,
   "kap": 0.4916,
   "km": 0.372,
   "sm": 1.1057,
   "wa": 1.0676,
   "crn_mean_diff": -0.3375,
   "max_ok": 220301,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.516,
   "km": 1.0724,
   "sm": 0.4819,
   "wa": 0.6472,
   "crn_mean_diff": -0.3575,
   "max_ok": 221065,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.247,
   "km": 0.7172,
   "sm": 0.906,
   "wa": 1.1176,
   "crn_mean_diff": -0.1952,
   "max_ok": 220301,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.4796,
   "km": 0.7947,
   "sm": 1.3474,
   "wa": 2.0133,
   "crn_mean_diff": -0.3371,
   "max_ok": 219999,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.2884,
   "km": 1.5647,
   "sm": 1.6741,
   "wa": 1.0359,
   "crn_mean_diff": -0.1653,
   "max_ok": 219999,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.5353,
   "km": 0.3351,
   "sm": 1.6782,
   "wa": 0.8073,
   "crn_mean_diff": -0.3586,
   "max_ok": 219999,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 1.0763,
   "km": 0.575,
   "sm": 0.9989,
   "wa": 0.986,
   "crn_mean_diff": -0.9006,
   "max_ok": 220297,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.0,
   "km": 0.4455,
   "sm": 1.0707,
   "wa": 0.8373,
   "crn_mean_diff": 0.0,
   "max_ok": 209193,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.0,
   "km": 1.2129,
   "sm": 0.3392,
   "wa": 1.4846,
   "crn_mean_diff": 0.0,
   "max_ok": 209193,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.0,
   "km": 0.347,
   "sm": 0.5116,
   "wa": 1.607,
   "crn_mean_diff": 0.0,
   "max_ok": 209193,
   "oog": 0
  },
  {
   "gen": 1,
   "kap": 0.0477,
   "km": 0.9023,
   "sm": 0.8703,
   "wa": 0.42,
   "crn_mean_diff": -0.0153,
   "max_ok": 220301,
   "oog": 0
  }
 ],
 "recheck": {
  "seeds": "601000..601255",
  "stack_mean_edge": 533.8785719493533,
  "stack_max_ok": 211576,
  "rows": [
   {
    "params": {
     "kap": 0.047651212838280804,
     "km": 0.902272563060335,
     "sm": 0.8703440471406996,
     "wa": 0.4200256339522197
    },
    "crn_fitness": -0.015293001446056387,
    "n": 256,
    "mean_diff": -0.006733069466885899,
    "se": 0.009654513646389078,
    "worst": -0.576243469356541,
    "max_ok": 222697,
    "oog": 0
   },
   {
    "params": {
     "kap": 0.2883556494668014,
     "km": 1.564693132744602,
     "sm": 1.6741449214829087,
     "wa": 1.0359464588434297
    },
    "crn_fitness": -0.1652791472032309,
    "n": 256,
    "mean_diff": -0.12198674346911198,
    "se": 0.022532414332253222,
    "worst": -1.3691112682394078,
    "max_ok": 222413,
    "oog": 0
   },
   {
    "params": {
     "kap": 0.24698680254266037,
     "km": 0.7171839120509159,
     "sm": 0.9059578057931038,
     "wa": 1.1175967891548313
    },
    "crn_fitness": -0.19522372622168582,
    "n": 256,
    "mean_diff": -0.09076547536041923,
    "se": 0.02009748977157455,
    "worst": -0.9787196119649479,
    "max_ok": 222693,
    "oog": 0
   }
  ]
 },
 "held_out": {
  "seeds": "610000..610511",
  "paired": {
   "n": 512,
   "mean_diff": -0.023709651182443503,
   "se": 0.009924094726245032,
   "worst": -3.354000700861093
  }
 },
 "retail_edge_delta": {
  "mean": -0.155556575029005,
  "se": 0.010505435165188015
 },
 "arb_edge_delta": {
  "mean": 0.1318469238465615,
  "se": 0.00290077335893022
 },
 "gas": {
  "max_ok": 222723,
  "oog": 0
 },
 "confirm": null,
 "notes": "Result: negative. The shadow-value overlay never beat STACK. Frozen best (kap~0.048) held-out paired diff -0.0237 +/- 0.0099 (n=512), below the confirm gate (> 2 se and >= +0.05), so seeds 5032000..5034000 were left untouched and confirm=null. On the CRN block (600000..600063) every kap>0 candidate lost, getting worse as kap rose (kap 0.25-0.36: -0.17 to -0.23; first probes at kap=1: -0.48, kap=3: -4.17 on seeds 0..31). Four of the 20 CMA samples clipped to kap=0 and scored exactly 0.0, because kap=0 is the same as STACK: verified bit-identical on seeds 0..31, max |diff| 0.0. The search was heading to kap=0, so the recheck used the top 3 kap>0 candidates. Mechanism: on held-out the overlay gains +0.132 arb edge but loses -0.156 retail edge. The J argmax mostly widens the exposed side, so it trades retail share for arb protection at a net loss. Deviations from the brief: (1) CMA ran 2 generations (20 evals, about 10 min of wall time), not 30 min, because each 64-seed eval took about 30 s on this 4-core machine with a fixed time budget. Constant re-tuning was out of scope; the trend in kap was monotone. (2) 3 pairs were used instead of 5: with 5 pairs max_ok was 239,293 on 32 seeds, and STACK itself peaks about 26k higher on larger seed sets (188k here vs 214k reported), so 5 pairs would risk OOG. Following the brief's >240k rule, the 3 pairs are the base plus the +/-3bp neighbours on the exposed side (ask if ghat>=0, else bid). (3) y in the arb term is taken as normalised by reserveY: the retail term lambdaHat*sizeHat is already a fraction of reserveY, so J/reserveY = lambdaHat*sizeHat/2*sum(share*V) - wa/4*(E(g-fa)+^2+E(-g-fb)+^2). The argmax is scale invariant, so this choice is consistent. Implementation: STACK verbatim plus an _shadow() call after tradeBoost and before STACK's tail compression, clampFee and 30/36bp caps. s2 = sm*(sigmaHat^2 + uncertainty), where uncertainty is the slots[13] value after this call's update. Gaussian moments use the Abramowitz-Stegun 26.2.17 normal CDF and exp(-u) by integer power times a degree-7 Taylor series, in int256 WAD with unchecked blocks. kap is clipped to [0,3]; km, sm and wa are searched in log space. CMA-ES: pop 10, mu 5, rng seed 1, start mean kap 0.8 with logs 0, sigma 0.6. Arb edge is rebuilt per step from the prior step's end spot and fees, the step's fair price and the constant k=1e6 (fees are kept out of reserves), using the closed-form optimal arb. retail = total - arb. STACK held-out: total 520.651, arb -26.272, retail 546.923, max_ok 211,588, 0 OOG. Frozen: max_ok 222,723, 0 OOG/halts in every run (gas_stats per arm). amm-match validate passed. Setup: amm-challenge at 6b6921f8; STACK sha256 2eaafc79...25719 verified. CH check on seeds 0..999: mean edge 525.5258821780834 vs expected 525.5258821780834 (match)"
}