{"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\n    uint256 constant MODE = 0;\n    uint256 constant P0 = 76476331918756448;\n    uint256 constant Q0 = 961220695206442240;\n    uint256 constant SLOPE = 10012070769040363520;\n    int256 constant CP1 = -int256(915972593462506624);\n    int256 constant CP2 = -int256(354422987587045056);\n    int256 constant CP3 = -int256(2171530105962272512);\n    int256 constant CA1 = int256(350908467528843);\n    int256 constant CA2 = int256(1781503013725281280);\n    int256 constant CAPP = int256(417146799905802);\n    int256 constant CAPA = int256(7097284476554);\n    uint256 constant GF = 217349470695506656;\n    uint256 constant GG = 974635429675602944;\n    uint256 constant PRIOR_N = 8;\n    uint256 constant COUNT_CAP = 3000;\n    uint256 constant GAP_HI = 20 * BPS;\n    uint256 constant SIZE_HI = 3000000000000000;\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        uint256 cnt = slots[16];\n        {\n            uint256 pc = slots[15];\n            if (pc != 0) cnt = _bump(cnt, pc - 1, !isNewStep);\n        }\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 > 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        {\n            uint256 staleHat2 = wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000);\n            uint256 gap2 = wdiv(absDiff(spot, staleHat2), staleHat2);\n            if (gap2 > TOX_CAP) gap2 = TOX_CAP;\n            uint256 ctx = (stepTradeCount > 1 ? 1 : 0) + (gap2 > GAP_HI ? 2 : 0) + (tradeRatio > SIZE_HI ? 4 : 0);\n            uint256 pNext = _pSame(cnt, ctx);\n            PolIn memory pi = PolIn(pNext, gap2, _isqrt(uncertainty * WAD), tradeRatio, stepTradeCount > 1, gap2 > GAP_HI, spot >= staleHat2);\n            (bidFee, askFee) = _policy(bidFee, askFee, pi);\n            slots[15] = ctx + 1; slots[16] = cnt;\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\n    struct PolIn { uint256 p; uint256 gap; uint256 sd; uint256 tr; bool later; bool gapHi; bool spotHigh; }\n    function _bump(uint256 cnt, uint256 c, bool same) internal pure returns (uint256) {\n        uint256 sh = c * 32;\n        uint256 w = (cnt >> sh) & 0xffffffff;\n        uint256 sm = w >> 16; uint256 tot = w & 0xffff;\n        tot += 1; if (same) sm += 1;\n        if (tot >= COUNT_CAP) { tot >>= 1; sm >>= 1; }\n        cnt = (cnt & ~(uint256(0xffffffff) << sh)) | (((sm << 16) | tot) << sh);\n        return cnt;\n    }\n    function _pSame(uint256 cnt, uint256 c) internal pure returns (uint256) {\n        uint256 w = (cnt >> (c * 32)) & 0xffffffff;\n        uint256 sm = w >> 16; uint256 tot = w & 0xffff;\n        return ((sm * WAD) + PRIOR_N * P0) / (tot + PRIOR_N);\n    }\n    function _policy(uint256 bid, uint256 ask, PolIn memory x) internal pure returns (uint256, uint256) {\n        if (CP1 == 0 && CP2 == 0 && CP3 == 0 && CA1 == 0 && CA2 == 0) return (bid, ask);\n        uint256 q = WAD - x.p; // probability next print opens a new step (arb exposure)\n        uint256 w;\n        if (MODE == 1) {\n            w = q > Q0 ? WAD : 0;\n        } else {\n            uint256 t = q > Q0 ? wmul(q - Q0, SLOPE) : 0;\n            w = t > WAD ? WAD : t;\n            if (MODE == 2) {\n                if (x.later) w = wmul(w, GF);\n                if (x.gapHi) w = wmul(w, GG);\n                if (w > WAD) w = WAD;\n            }\n        }\n        int256 rp = (int256(w) * (CP1 * int256(x.gap) / int256(WAD) + CP2 * int256(x.sd) / int256(WAD) + CP3 * int256(x.tr) / int256(WAD))) / int256(WAD);\n        if (rp > CAPP) rp = CAPP; else if (rp < -CAPP) rp = -CAPP;\n        int256 ra = (int256(WAD - w) * (CA1 + CA2 * int256(x.sd) / int256(WAD))) / int256(WAD);\n        if (ra > CAPA) ra = CAPA; else if (ra < -CAPA) ra = -CAPA;\n        // protect side: the side V10's stale rule already raises; attract side: the other.\n        int256 b; int256 a;\n        if (x.spotHigh) { b = int256(bid) + rp; a = int256(ask) + ra; }\n        else { a = int256(ask) + rp; b = int256(bid) + ra; }\n        return (clampFee(b > 0 ? uint256(b) : 0), clampFee(a > 0 ? uint256(a) : 0));\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 \"trans_policy\"; }\n}\n", "sha256": "c4bdfae56273046c33e286add9808bfd38cf7ca3b2d81353a4bd44c1e5a6b67e", "harness_source": {"h.py": "import time,sys,json\nfrom pathlib import Path\nimport numpy as np\nimport amm_sim_rs as sim\nfrom amm_competition.evm.compiler import SolidityCompiler\nfrom amm_competition.competition.config import build_config\nCOMP=SolidityCompiler()\nVAN=COMP.compile(Path('contracts/src/VanillaStrategy.sol').read_text(),'VanillaStrategy')\ndef configs(seeds):\n    out=[]\n    for s in seeds:\n        r=np.random.default_rng(s)\n        size=r.uniform(19,21);rate=r.uniform(.6,1);sigma=r.uniform(.000882,.001008)\n        out.append(build_config(seed=s,gbm_sigma=sigma,retail_arrival_rate=rate,retail_mean_size=size))\n    return out\ndef compile_src(src):\n    a=COMP.compile(src); assert a.success,a.errors; return a\ndef run(art,seeds,chunk=16):\n    \"\"\"returns edges array, gas dict (afterSwap max, oog, any halts)\"\"\"\n    edges=[];g={'max_ok':0,'init_max':0,'oog':0,'revert':0,'other_halt':0,'tx_error':0,'bad_return':0,'calls':0}\n    seeds=list(seeds)\n    for i in range(0,len(seeds),chunk):\n        sim.gas_stats_reset()\n        res=sim.run_batch(list(art.bytecode),list(VAN.bytecode),configs(seeds[i:i+chunk]),8)\n        edges.extend(r.edges['submission'] for r in res.results)\n        for c in sim.gas_stats():\n            if isinstance(c,dict) and c.get('role')=='Submission':\n                if c['callback']=='afterSwap': g['max_ok']=max(g['max_ok'],c['max_ok_gas']);g['calls']+=c['calls']\n                if c['callback']=='afterInitialize': g['init_max']=max(g['init_max'],c['max_ok_gas'])\n                for k in ('oog','revert','other_halt','tx_error','bad_return'): g[k]+=c[k]\n        del res\n    return np.array(edges),g\nif __name__=='__main__':\n    t=time.time();a=compile_src(Path(sys.argv[1]).read_text());print('compile',time.time()-t)\n    t=time.time();e,g=run(a,range(660000,660032));print('run32',time.time()-t,e.mean(),g)\n    print(type(sim.gas_stats()), str(sim.gas_stats())[:300])\n", "gen.py (generator)": "\"\"\"Generator: builds candidate Solidity from V10 + transition-probability policy.\"\"\"\nfrom pathlib import Path\nV10=Path('scratch/v10.sol').read_text()\nWAD=10**18\nNAMES=['p0','q0','s','cp1','cp2','cp3','ca1','ca2','capp','capa','gf','gg']\n# physical ranges [lo,hi] mapped from unit box [0,1]\nRANGES={'p0':(.05,.95),'q0':(0.,1.),'s':(.5,20.),'cp1':(-1,1),'cp2':(-2,2),'cp3':(-20,20),\n        'ca1':(-10e-4,10e-4),'ca2':(-2,2),'capp':(0,30e-4),'capa':(0,15e-4),'gf':(0,3),'gg':(0,3)}\ndef phys(u):\n    return {k:RANGES[k][0]+(RANGES[k][1]-RANGES[k][0])*min(1,max(0,x)) for k,x in zip(NAMES,u)}\ndef sw(v): return str(int(round(v*WAD)))\ndef make(mode,P):\n    \"\"\"mode 0 smooth, 1 threshold, 2 context-conditioned. P dict of physical params (zero-intervention: all gains 0).\"\"\"\n    def sc(k): # signed WAD int literal\n        v=int(round(P[k]*WAD)); return f\"int256({v})\" if v>=0 else f\"-int256({-v})\"\n    consts=f\"\"\"\n    uint256 constant MODE = {mode};\n    uint256 constant P0 = {sw(P['p0'])};\n    uint256 constant Q0 = {sw(P['q0'])};\n    uint256 constant SLOPE = {sw(P['s'])};\n    int256 constant CP1 = {sc('cp1')};\n    int256 constant CP2 = {sc('cp2')};\n    int256 constant CP3 = {sc('cp3')};\n    int256 constant CA1 = {sc('ca1')};\n    int256 constant CA2 = {sc('ca2')};\n    int256 constant CAPP = {sc('capp')};\n    int256 constant CAPA = {sc('capa')};\n    uint256 constant GF = {sw(P['gf'])};\n    uint256 constant GG = {sw(P['gg'])};\n    uint256 constant PRIOR_N = 8;\n    uint256 constant COUNT_CAP = 3000;\n    uint256 constant GAP_HI = 20 * BPS;\n    uint256 constant SIZE_HI = 3000000000000000;\n\"\"\"\n    s=V10.replace(\"    uint256 constant ELAPSED_CAP = 8;\",consts+\"    uint256 constant ELAPSED_CAP = 8;\",1)\n    # 1. learn: update counts for previous quote context when this callback arrives\n    s=s.replace(\"        bool isNewStep = trade.timestamp > lastTs;\\n\",\n\"\"\"        bool isNewStep = trade.timestamp > lastTs;\n        uint256 cnt = slots[16];\n        {\n            uint256 pc = slots[15];\n            if (pc != 0) cnt = _bump(cnt, pc - 1, !isNewStep);\n        }\n\"\"\",1)\n    # 2. policy before final storage\n    s=s.replace(\"        slots[0] = bidFee; slots[1] = askFee; slots[2] = (spot << 64) | trade.timestamp;\",\n\"\"\"        {\n            uint256 staleHat2 = wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000);\n            uint256 gap2 = wdiv(absDiff(spot, staleHat2), staleHat2);\n            if (gap2 > TOX_CAP) gap2 = TOX_CAP;\n            uint256 ctx = (stepTradeCount > 1 ? 1 : 0) + (gap2 > GAP_HI ? 2 : 0) + (tradeRatio > SIZE_HI ? 4 : 0);\n            uint256 pNext = _pSame(cnt, ctx);\n            PolIn memory pi = PolIn(pNext, gap2, _isqrt(uncertainty * WAD), tradeRatio, stepTradeCount > 1, gap2 > GAP_HI, spot >= staleHat2);\n            (bidFee, askFee) = _policy(bidFee, askFee, pi);\n            slots[15] = ctx + 1; slots[16] = cnt;\n        }\n        slots[0] = bidFee; slots[1] = askFee; slots[2] = (spot << 64) | trade.timestamp;\"\"\",1)\n    helpers=\"\"\"\n    struct PolIn { uint256 p; uint256 gap; uint256 sd; uint256 tr; bool later; bool gapHi; bool spotHigh; }\n    function _bump(uint256 cnt, uint256 c, bool same) internal pure returns (uint256) {\n        uint256 sh = c * 32;\n        uint256 w = (cnt >> sh) & 0xffffffff;\n        uint256 sm = w >> 16; uint256 tot = w & 0xffff;\n        tot += 1; if (same) sm += 1;\n        if (tot >= COUNT_CAP) { tot >>= 1; sm >>= 1; }\n        cnt = (cnt & ~(uint256(0xffffffff) << sh)) | (((sm << 16) | tot) << sh);\n        return cnt;\n    }\n    function _pSame(uint256 cnt, uint256 c) internal pure returns (uint256) {\n        uint256 w = (cnt >> (c * 32)) & 0xffffffff;\n        uint256 sm = w >> 16; uint256 tot = w & 0xffff;\n        return ((sm * WAD) + PRIOR_N * P0) / (tot + PRIOR_N);\n    }\n    function _policy(uint256 bid, uint256 ask, PolIn memory x) internal pure returns (uint256, uint256) {\n        if (CP1 == 0 && CP2 == 0 && CP3 == 0 && CA1 == 0 && CA2 == 0) return (bid, ask);\n        uint256 q = WAD - x.p; // probability next print opens a new step (arb exposure)\n        uint256 w;\n        if (MODE == 1) {\n            w = q > Q0 ? WAD : 0;\n        } else {\n            uint256 t = q > Q0 ? wmul(q - Q0, SLOPE) : 0;\n            w = t > WAD ? WAD : t;\n            if (MODE == 2) {\n                if (x.later) w = wmul(w, GF);\n                if (x.gapHi) w = wmul(w, GG);\n                if (w > WAD) w = WAD;\n            }\n        }\n        int256 rp = (int256(w) * (CP1 * int256(x.gap) / int256(WAD) + CP2 * int256(x.sd) / int256(WAD) + CP3 * int256(x.tr) / int256(WAD))) / int256(WAD);\n        if (rp > CAPP) rp = CAPP; else if (rp < -CAPP) rp = -CAPP;\n        int256 ra = (int256(WAD - w) * (CA1 + CA2 * int256(x.sd) / int256(WAD))) / int256(WAD);\n        if (ra > CAPA) ra = CAPA; else if (ra < -CAPA) ra = -CAPA;\n        // protect side: the side V10's stale rule already raises; attract side: the other.\n        int256 b; int256 a;\n        if (x.spotHigh) { b = int256(bid) + rp; a = int256(ask) + ra; }\n        else { a = int256(ask) + rp; b = int256(bid) + ra; }\n        return (clampFee(b > 0 ? uint256(b) : 0), clampFee(a > 0 ? uint256(a) : 0));\n    }\n\"\"\"\n    s=s.replace(\"    struct PosteriorInput {\",helpers+\"    struct PosteriorInput {\",1)\n    s=s.replace('return \"censored_10\"','return \"trans_policy\"')\n    return s\nZERO=dict(p0=.4,q0=.5,s=4,cp1=0,cp2=0,cp3=0,ca1=0,ca2=0,capp=10e-4,capa=5e-4,gf=1,gg=1)\nif __name__=='__main__':\n    Path('scratch/zero.sol').write_text(make(0,ZERO))\n", "search.py": "import sys,time,json,hashlib\nsys.path.insert(0,'scratch')\nfrom concurrent.futures import ProcessPoolExecutor\nimport cma\nfrom h import *\nfrom gen import *\nmode=int(sys.argv[1]); budget=float(sys.argv[2])\ndef comp(u):\n    P=phys(u); return list(compile_src(make(mode,P)).bytecode)\nclass A: pass\nV10=compile_src(Path('scratch/v10.sol').read_text())\nbase={}\ndef v10edges(S):\n    miss=[s for s in S if s not in base]\n    if miss:\n        e,_=run(V10,miss)\n        for s,x in zip(miss,e): base[s]=x\n    return np.array([base[s] for s in S])\n# unit-box start; cp/ca centered at 0 => mid 0.5\nx0=[.4,.5,.3,.5,.5,.5,.5,.5,.3,.3,.33,.33]\nes=cma.CMAEvolutionStrategy(x0,.25,{'seed':403,'popsize':8,'bounds':[0,1],'verbose':-9})\nt0=time.time();log=[];g=0;best=None;ledger=[]\npool=ProcessPoolExecutor(8)\nwhile time.time()-t0<budget:\n    n=32 if g%2==0 else 64\n    off=660000+(g*96)%(4000-64)\n    S=list(range(off,off+n)); ledger.append([off,off+n-1])\n    xs=es.ask()\n    class Art: pass\n    arts=[]\n    for bc in pool.map(comp,xs):\n        a=Art();a.bytecode=bc;arts.append(a)\n    b=v10edges(S)\n    f=[];gas=[]\n    for a in arts:\n        e,gs=run(a,S)\n        bad=gs['oog']+gs['revert']+gs['other_halt']+gs['tx_error']+gs['bad_return']\n        d=float((e-b).mean())\n        f.append(-d+(1e3 if bad else 0)); gas.append(gs['max_ok'])\n    es.tell(xs,f)\n    i=int(np.argmin(f)); \n    rec={'gen':g,'seeds':[off,off+n-1],'n':n,'best_gain':-f[i],'mean_gain':-float(np.mean(f)),'best_x':[round(float(v),4) for v in xs[i]],'max_gas':max(gas),'t':round(time.time()-t0)}\n    log.append(rec);print(json.dumps(rec),flush=True)\n    g+=1\nfav=[float(v) for v in es.result.xfavorite]\nout={'mode':mode,'log':log,'ledger':ledger,'xfavorite':fav,'phys':phys(fav),'gens':g,'cma':'cma 4.5.0 seed 403 popsize 8 sigma0 .25'}\nPath(f'scratch/search_{mode}.json').write_text(json.dumps(out))\n", "final.py": "import sys,json,hashlib,time\nsys.path.insert(0,'scratch')\nfrom h import *\nfrom gen import *\nfrom decomp import decomposition\ndef run2(art,seeds,chunk=16):\n    E=[];A=[];g={'max_ok':0,'init_max':0,'oog':0,'revert':0,'other_halt':0,'tx_error':0,'bad_return':0,'calls':0,'chunks':0}\n    seeds=list(seeds)\n    for i in range(0,len(seeds),chunk):\n        sim.gas_stats_reset()\n        res=sim.run_batch(list(art.bytecode),list(VAN.bytecode),configs(seeds[i:i+chunk]),8)\n        for r in res.results:\n            arb,ret=decomposition(r);E.append(r.edges['submission']);A.append(arb)\n        for c in sim.gas_stats():\n            if c['role']=='Submission':\n                if c['callback']=='afterSwap': g['max_ok']=max(g['max_ok'],c['max_ok_gas']);g['calls']+=c['calls']\n                if c['callback']=='afterInitialize': g['init_max']=max(g['init_max'],c['max_ok_gas'])\n                for k in ('oog','revert','other_halt','tx_error','bad_return'): g[k]+=c[k]\n        g['chunks']+=1;del res\n    E=np.array(E);A=np.array(A);return E,A,E-A,g\ndef paired(d,seeds):\n    d=np.array(d);w=np.argsort(d)[:5]\n    return {'n':len(d),'mean_diff':float(d.mean()),'se':float(d.std(ddof=1)/np.sqrt(len(d))),'worst':[{'seed':list(seeds)[i],'d':float(d[i])} for i in w]}\nV10=compile_src(Path('scratch/v10.sol').read_text())\ncands={}\nfor m in (0,1,2):\n    o=json.load(open(f'scratch/search_{m}.json'));P=phys(o['xfavorite']);cands[m]=(P,make(m,P))\nS=list(range(664000,664256))\neb,ab,rb,gb=run2(V10,S)\nrech={}\nfor m,(P,src) in cands.items():\n    a=compile_src(src);e,ar,rt,g=run2(a,S)\n    rech[m]={'params':P,'sha256':hashlib.sha256(src.encode()).hexdigest(),'paired':paired(e-eb,S),'retail_delta':float((rt-rb).mean()),'arb_delta':float((ar-ab).mean()),'gas':g}\n    print(m,rech[m]['paired']['mean_diff'],rech[m]['paired']['se'],g['max_ok'],g['oog'],flush=True)\norder=sorted(rech,key=lambda m:-rech[m]['paired']['mean_diff'])\nfrozen=order[0]\nsrc=cands[frozen][1];h=hashlib.sha256(src.encode()).hexdigest()\nPath('scratch/frozen.sol').write_text(src)\nprint('FROZEN mode',frozen,h,flush=True)\nH=list(range(665000,665512))\na=compile_src(src)\neb2,ab2,rb2,gb2=run2(V10,H);e,ar,rt,g=run2(a,H)\nout={'recheck':{str(k):v for k,v in rech.items()},'recheck_v10_gas':gb,'order':order,'frozen_mode':frozen,'sha256':h,'params':cands[frozen][0],\n 'heldout':{'paired':paired(e-eb2,H),'retail_delta':float((rt-rb2).mean()),'arb_delta':float((ar-ab2).mean()),\n 'retail_delta_se':float((rt-rb2).std(ddof=1)/np.sqrt(len(H))),'arb_delta_se':float((ar-ab2).std(ddof=1)/np.sqrt(len(H))),\n 'recon_max_abs':float(np.abs((e-eb2)-((rt-rb2)+(ar-ab2))).max()),'gas_candidate':g,'gas_v10':gb2,'candidate_mean':float(e.mean()),'v10_mean':float(eb2.mean())}}\nPath('scratch/final.json').write_text(json.dumps(out));print(json.dumps(out['heldout']))\n"}, "base": {"v10_sha256_verified": "cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245", "note": "V10 code from the supplied artifact; sha256 of the code field recomputed and matched. CH calibration not re-run (brief: already verified). Decomposition code taken verbatim from V10 artifact tuning_harness_source."}, "policy": "V10 unchanged plus: at each quote the context (later-print flag, gap>20bps vs 0.7pHat+0.3fastHat, last size ratio>0.003; 8 contexts) is stored; when the next callback arrives its context counter (same timestamp vs new) is updated (packed 16-bit counts in slot 16, halve at 3000, prior strength 8 at p0). p=P(next callback same timestamp). Gate w from q=1-p. Protect-side residual rp=w*(cp1*gap+cp2*sd+cp3*size) capped +-capp; attract-side residual ra=(1-w)*(ca1+ca2*sd) capped +-capa; added after V10 final fees then clampFee. Zero gains => returns V10 fees unchanged (checked: max |edge diff| 0.0 over 16 seeds 660000..660015).", "structures": {"0_smooth": "w=clip((q-q0)*s,0,1)", "1_threshold": "w=1[q>q0]", "2_context": "smooth w times gf if later print, times gg if gap high"}, "params": {"p0": 0.07647633191875644, "q0": 0.9612206952064423, "s": 10.012070769040363, "cp1": -0.9159725934625066, "cp2": -0.35442298758704505, "cp3": -2.1715301059622725, "ca1": 0.00035090846752884315, "ca2": 1.7815030137252812, "capp": 0.00041714679990580215, "capa": 7.097284476553557e-06, "gf": 0.21734947069550664, "gg": 0.9746354296756029}, "param_count": 12, "search_log": {"0": {"cma": "cma 4.5.0 seed 403 popsize 8 sigma0 .25", "generations": 6, "log": [{"gen": 0, "seeds": [660000, 660031], "n": 32, "best_gain": -0.014439985378237097, "mean_gain": -6.517303825561993, "best_x": [0.7256, 0.7844, 0.0059, 0.7766, 0.5359, 0.4284, 0.723, 0.6108, 0.3369, 0.0053, 0.3702, 0.2136], "max_gas": 219276, "t": 56}, {"gen": 1, "seeds": [660096, 660159], "n": 64, "best_gain": -0.014084291032529173, "mean_gain": -4.4294146595397965, "best_x": [0.667, 0.8298, 0.0545, 0.5675, 0.5193, 0.4611, 0.5192, 0.4776, 0.2086, 0.0106, 0.3227, 0.2697], "max_gas": 219298, "t": 167}, {"gen": 2, "seeds": [660192, 660223], "n": 32, "best_gain": -0.22857308672033128, "mean_gain": -1.2490122230814005, "best_x": [0.3082, 0.9703, 0.2087, 0.4545, 0.2384, 0.4549, 0.5799, 0.9417, 0.0736, 0.0468, 0.0008, 0.2492], "max_gas": 219282, "t": 222}, {"gen": 3, "seeds": [660288, 660351], "n": 64, "best_gain": -0.042842687086060316, "mean_gain": -1.0286453411839385, "best_x": [0.2049, 0.9095, 0.4419, 0.0001, 0.516, 0.6552, 0.1895, 0.652, 0.2821, 0.0124, 0.0031, 0.1089], "max_gas": 221356, "t": 331}, {"gen": 4, "seeds": [660384, 660415], "n": 32, "best_gain": -0.06488960488684548, "mean_gain": -0.7833705821146302, "best_x": [0.0819, 0.8621, 0.481, 0.1989, 0.4052, 0.2544, 0.7949, 0.948, 0.0964, 0.013, 0.2693, 0.2119], "max_gas": 223470, "t": 387}, {"gen": 5, "seeds": [660480, 660543], "n": 64, "best_gain": -0.15514634210604772, "mean_gain": -0.977111496248913, "best_x": [0.0033, 0.8511, 0.6153, 0.0033, 0.1711, 0.547, 0.5902, 0.9061, 0.2907, 0.0033, 0.2871, 0.1043], "max_gas": 219328, "t": 496}], "xfavorite_unit_box": [0.02941814657639604, 0.9612206952064423, 0.4877985009764289, 0.042013703268746705, 0.41139425310323874, 0.4457117473509432, 0.6754542337644216, 0.9453757534313203, 0.13904893330193405, 0.004731522984369038, 0.07244982356516888, 0.3248784765585343], "xfavorite_physical": {"p0": 0.07647633191875644, "q0": 0.9612206952064423, "s": 10.012070769040363, "cp1": -0.9159725934625066, "cp2": -0.35442298758704505, "cp3": -2.1715301059622725, "ca1": 0.00035090846752884315, "ca2": 1.7815030137252812, "capp": 0.00041714679990580215, "capa": 7.097284476553557e-06, "gf": 0.21734947069550664, "gg": 0.9746354296756029}}, "1": {"cma": "cma 4.5.0 seed 403 popsize 8 sigma0 .25", "generations": 5, "log": [{"gen": 0, "seeds": [660000, 660031], "n": 32, "best_gain": -0.4858688887422975, "mean_gain": -9.276477171963451, "best_x": [0.7256, 0.7844, 0.0059, 0.7766, 0.5359, 0.4284, 0.723, 0.6108, 0.3369, 0.0053, 0.3702, 0.2136], "max_gas": 219144, "t": 58}, {"gen": 1, "seeds": [660096, 660159], "n": 64, "best_gain": -0.11127229258906368, "mean_gain": -3.3282054073515335, "best_x": [0.5716, 0.9824, 0.0784, 0.9335, 0.8064, 0.7862, 0.2423, 0.4996, 0.2996, 0.0677, 0.0718, 0.7012], "max_gas": 219183, "t": 168}, {"gen": 2, "seeds": [660192, 660223], "n": 32, "best_gain": -0.1054773221601426, "mean_gain": -1.5476047943239997, "best_x": [0.2276, 0.9477, 0.3563, 0.9355, 0.7267, 0.1925, 0.3294, 0.3354, 0.0335, 0.0658, 0.3879, 0.071], "max_gas": 219166, "t": 223}, {"gen": 3, "seeds": [660288, 660351], "n": 64, "best_gain": -0.04804505920707314, "mean_gain": -2.309217673354475, "best_x": [0.4239, 0.9957, 0.1008, 0.9994, 0.3153, 0.0846, 0.4496, 0.5132, 0.2384, 0.0527, 0.0695, 0.0218], "max_gas": 221246, "t": 334}, {"gen": 4, "seeds": [660384, 660415], "n": 32, "best_gain": -0.08759643715731968, "mean_gain": -1.423951924683382, "best_x": [0.2847, 0.8916, 0.0384, 0.8173, 0.3414, 0.5496, 0.1952, 0.9956, 0.026, 0.0139, 0.6245, 0.3349], "max_gas": 223287, "t": 390}], "xfavorite_unit_box": [0.33084188714167206, 0.9555602127728867, 0.027879807063715664, 0.8464557947945693, 0.35513899590140696, 0.4328527747712392, 0.3539726423783307, 0.6847527521330417, 0.22938613840575353, 0.008865696163614472, 0.4182571322667903, 0.33259652067179934], "xfavorite_physical": {"p0": 0.3477576984275048, "q0": 0.9555602127728867, "s": 1.0436562377424554, "cp1": 0.6929115895891387, "cp2": -0.5794440163943722, "cp3": -2.685889009150433, "ca1": -0.00029205471524333855, "ca2": 0.7390110085321666, "capp": 0.0006881584152172607, "capa": 1.3298544245421708e-05, "gf": 1.2547713968003709, "gg": 0.997789562015398}}, "2": {"cma": "cma 4.5.0 seed 403 popsize 8 sigma0 .25", "generations": 5, "log": [{"gen": 0, "seeds": [660000, 660031], "n": 32, "best_gain": -0.025220826690324216, "mean_gain": -5.444003401286748, "best_x": [0.7256, 0.7844, 0.0059, 0.7766, 0.5359, 0.4284, 0.723, 0.6108, 0.3369, 0.0053, 0.3702, 0.2136], "max_gas": 219283, "t": 58}, {"gen": 1, "seeds": [660096, 660159], "n": 64, "best_gain": -0.01362509105447085, "mean_gain": -2.774790440700405, "best_x": [0.667, 0.8298, 0.0545, 0.5675, 0.5193, 0.4611, 0.5192, 0.4776, 0.2086, 0.0106, 0.3227, 0.2697], "max_gas": 219326, "t": 169}, {"gen": 2, "seeds": [660192, 660223], "n": 32, "best_gain": -0.055272838893316134, "mean_gain": -1.5535440892606955, "best_x": [0.6027, 0.9987, 0.1768, 0.7587, 0.6833, 0.364, 0.489, 0.8643, 0.227, 0.0137, 0.0001, 0.0001], "max_gas": 219287, "t": 226}, {"gen": 3, "seeds": [660288, 660351], "n": 64, "best_gain": -7.960613663282601e-05, "mean_gain": -1.2116092668910303, "best_x": [0.269, 0.778, 0.0159, 0.9097, 0.4225, 0.4432, 0.1893, 0.9838, 0.3751, 0.0019, 0.2604, 0.0432], "max_gas": 221287, "t": 336}, {"gen": 4, "seeds": [660384, 660415], "n": 32, "best_gain": -0.23807824040135195, "mean_gain": -1.157444141411187, "best_x": [0.2945, 0.8265, 0.2454, 0.8483, 0.6299, 0.7677, 0.4251, 0.992, 0.2779, 0.0181, 0.0257, 0.2283], "max_gas": 223229, "t": 392}], "xfavorite_unit_box": [0.3708117904899716, 0.9467653367308768, 0.13658778307000313, 0.9691696080759319, 0.7423056219484132, 0.6468008112503013, 0.3273593771677188, 0.9994828112895154, 0.3660365794862765, 0.0052014792199437014, 0.042980130979179014, 0.19174454708702315], "xfavorite_physical": {"p0": 0.38373061144097437, "q0": 0.9467653367308768, "s": 3.163461769865061, "cp1": 0.9383392161518638, "cp2": 0.9692224877936528, "cp3": 5.872032450012053, "ca1": -0.0003452812456645624, "ca2": 1.9979312451580618, "capp": 0.0010981097384588296, "capa": 7.802218829915552e-06, "gf": 0.12894039293753704, "gg": 0.5752336412610695}}}, "search_note": "Each structure ran about 390 s wall (about 6 generations, popsize 8, rotating 32/64-seed CRN; generation gain = mean paired diff vs V10 on the same seeds). Total search about 20 min. In every generation the best candidate was at or below zero gain; CMA drifted toward zero intervention. No structure found a positive local gain; search was short (<=6 generations x 8), so it is not an exhaustive negative.", "seed_ledger": {"search": "660000..663999 inclusive window; per-generation blocks start 660000+(gen*96)%3936, listed in each search_log ledger via seeds fields", "recheck": "664000..664255 (256)", "heldout": "665000..665511 (512) once", "no_seed_ge_5000000": true, "smoke_seeds": "660000..660015 (zero-check and one nonzero smoke, before search)"}, "recheck_664000_664255": {"0": {"params": {"p0": 0.07647633191875644, "q0": 0.9612206952064423, "s": 10.012070769040363, "cp1": -0.9159725934625066, "cp2": -0.35442298758704505, "cp3": -2.1715301059622725, "ca1": 0.00035090846752884315, "ca2": 1.7815030137252812, "capp": 0.00041714679990580215, "capa": 7.097284476553557e-06, "gf": 0.21734947069550664, "gg": 0.9746354296756029}, "sha256": "c4bdfae56273046c33e286add9808bfd38cf7ca3b2d81353a4bd44c1e5a6b67e", "paired": {"n": 256, "mean_diff": -0.014117881700977941, "se": 0.014441838143299102, "worst": [{"seed": 664001, "d": -1.2996526981179386}, {"seed": 664038, "d": -1.099910908729612}, {"seed": 664103, "d": -0.5840968260158661}, {"seed": 664188, "d": -0.511095162368008}, {"seed": 664215, "d": -0.2975726437235835}]}, "retail_delta": -0.01693670578297346, "arb_delta": 0.0028188240819925214, "gas": {"max_ok": 219263, "init_max": 221015, "oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0, "calls": 2595704, "chunks": 16}}, "1": {"params": {"p0": 0.3477576984275048, "q0": 0.9555602127728867, "s": 1.0436562377424554, "cp1": 0.6929115895891387, "cp2": -0.5794440163943722, "cp3": -2.685889009150433, "ca1": -0.00029205471524333855, "ca2": 0.7390110085321666, "capp": 0.0006881584152172607, "capa": 1.3298544245421708e-05, "gf": 1.2547713968003709, "gg": 0.997789562015398}, "sha256": "ae3a2be40b3cde721ad7b7d1177a426e8133be6fc62d80977b684be82e350f8f", "paired": {"n": 256, "mean_diff": -0.036056821467866484, "se": 0.014525356383471189, "worst": [{"seed": 664001, "d": -1.3417705735059826}, {"seed": 664038, "d": -1.1826199996027071}, {"seed": 664188, "d": -0.5349967560954951}, {"seed": 664077, "d": -0.5139867335064991}, {"seed": 664215, "d": -0.37665627980152294}]}, "retail_delta": -0.048449059646129555, "arb_delta": 0.012392238178260115, "gas": {"max_ok": 219192, "init_max": 221015, "oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0, "calls": 2594668, "chunks": 16}}, "2": {"params": {"p0": 0.38373061144097437, "q0": 0.9467653367308768, "s": 3.163461769865061, "cp1": 0.9383392161518638, "cp2": 0.9692224877936528, "cp3": 5.872032450012053, "ca1": -0.0003452812456645624, "ca2": 1.9979312451580618, "capp": 0.0010981097384588296, "capa": 7.802218829915552e-06, "gf": 0.12894039293753704, "gg": 0.5752336412610695}, "sha256": "21c94076d5386ed5d60a921fa0c0cf260c9edf5a024fec91eacd18e00f5f1ec4", "paired": {"n": 256, "mean_diff": -0.01907807085610802, "se": 0.01450514688674866, "worst": [{"seed": 664001, "d": -1.3014251962514436}, {"seed": 664038, "d": -1.098616473113907}, {"seed": 664103, "d": -0.5861782521421901}, {"seed": 664188, "d": -0.5133847217157381}, {"seed": 664215, "d": -0.33526939651085286}]}, "retail_delta": -0.02376672999378715, "arb_delta": 0.00468865913767863, "gas": {"max_ok": 219198, "init_max": 220987, "oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0, "calls": 2595493, "chunks": 16}}, "note": "All three structures rechecked (superset of top 2); order by mean_diff: [0, 2, 1]", "v10_gas": {"max_ok": 190754, "init_max": 220981, "oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0, "calls": 2596654, "chunks": 16}}, "frozen_mode": 0, "paired": {"n": 512, "mean_diff": -0.02593418172619999, "se": 0.005323855493810268, "worst": [{"seed": 665407, "d": -0.7446324240270314}, {"seed": 665378, "d": -0.5334452511896188}, {"seed": 665039, "d": -0.405581454442995}, {"seed": 665476, "d": -0.39442539709204993}, {"seed": 665372, "d": -0.33660074016472663}]}, "paired_basis": "512 held-out seeds 665000..665511 vs V10, sample SE (ddof=1)", "retail_edge_delta": {"mean": -0.027521553848475988, "se": 0.005526355379147049}, "arb_edge_delta": {"mean": 0.0015873721222756723, "se": 0.001870614937477682}, "reconciliation": {"max_abs_per_seed_total_minus_retail_plus_arb": 1.1013412404281553e-13, "method": "retail = total edge - reconstructed arb (V10 harness decomposition), so reconciliation is by construction to rounding"}, "means": {"candidate": 526.5037266164305, "v10": 526.5296607981568}, "gas": {"candidate": {"max_ok": 221343, "oog": 0, "init_max_separate": 221015}, "v10": {"max_ok": 192838, "oog": 0, "init_max_separate": 220981}, "chunk_size": 16, "gas_stats reset per chunk": true, "aim_afterSwap_below_235k_met": true}, "halt_counts": {"candidate": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}, "v10": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}, "validation": {"amm-match validate scratch frozen.sol": "passed (strategy trans_policy)", "zero_intervention_equals_v10": "max abs edge diff 0.0 on 16 seeds", "early_bug": "first nonzero smoke returned 9 bad_return (unclamped fee); fixed by clampFee before any search or measured result"}, "verdict": "Negative: frozen hash loses about 0.026 per seed vs V10 (SE 0.005) on held-out; no improvement. Not useful toward the +5.0 goal.", "limitations": ["Short search: about 6 CMA generations of 8 per structure within the 20 min budget; structure ranking is noise-dominated.", "Residual families are bounded linear-in-gap/uncertainty/size forms; richer forms untested.", "Local-to-board transfer not assessed; V10 itself is +0.14 over STACK.", "Gas max includes search-chosen param effects; afterSwap max about 221k."], "seeds_kind": "tuning", "board_claim": null}