{"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[15] = 400000000000000000 | (uint256(2000000000000000) << 160); 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        uint256 arbProbability;\n        (fastHat, uncertainty, arbProbability) = _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        uint256 toxLinear;\n        uint256 toxQuadratic;\n        {\n            uint256 packedAnchor = slots[16];\n            uint256 runMean = uint64(packedAnchor);\n            uint256 sampleCount = packedAnchor >> 64;\n            if (sampleCount < 674) sampleCount++;\n            if (toxEma >= runMean) runMean += (toxEma-runMean)/sampleCount;\n            else runMean -= (runMean-toxEma)/sampleCount;\n            slots[16] = runMean | (sampleCount << 64);\n            toxLinear = _anchorBlend(runMean, toxEma, 712696014807650816);\n            toxQuadratic = _anchorBlend(runMean, toxEma, 1295240753826310656);\n        }\n\n\n        stepTradeCount = stepTradeCount + 1;\n        if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP;\n\n        uint256 originalLambda = lambdaHat; uint256 originalSize = sizeHat;\n\n        if (342406799193418304 > 0) {\n            uint256 packedFlow = slots[15];\n            uint256 rate = uint80(packedFlow);\n            uint256 count = uint80(packedFlow >> 80);\n            uint256 meanSize = uint80(packedFlow >> 160);\n            if (rate == 0) rate = 400000000000000000;\n            if (meanSize == 0) meanSize = 2000000000000000;\n            if (isNewStep) {\n                uint256 inst = count / silent;\n                if (inst > 3 * WAD) inst = 3 * WAD;\n                uint256 retention = _powWad(999000000000000000, silent > 64 ? 64 : silent);\n                rate = wmul(rate, retention) + wmul(inst, WAD-retention);\n                count = 0;\n            }\n            uint256 weight = firstInStep ? WAD-arbProbability : WAD;\n            uint256 correctedWeight = weight;\n            if (2 == 2) {\n                uint256 missing = wmul(feeUsed, 196030880396139429888);\n                if (missing > 333333333333333376) missing = 333333333333333376;\n                correctedWeight = wdiv(weight, WAD-missing);\n            }\n            count += correctedWeight;\n            uint256 learning = wmul(WAD-999000000000000000, weight);\n            meanSize = _blend(meanSize, tradeRatio, learning);\n            slots[15]=rate | (count << 80) | (meanSize << 160);\n            uint256 retailRate = wmul(rate, 366383424913407168);\n            uint256 retailSize = 2 == 0 ? sizeHat : wmul(meanSize,1883296158119298304);\n            lambdaHat = _blend(lambdaHat,retailRate,342406799193418304);\n            sizeHat = _blend(sizeHat,retailSize,342406799193418304);\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, toxLinear) + wmul(TOX_QUAD_COEF, wmul(toxQuadratic, toxQuadratic)) + wmul(ACT_COEF, actEma);\n        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxLinear));\n\n        lambdaHat = originalLambda; sizeHat = originalSize;\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        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    function _anchorBlend(uint256 mean, uint256 value, uint256 k) internal pure returns (uint256) {\n        if (k == WAD) return value;\n        if (value >= mean) return mean + wmul(value-mean,k);\n        uint256 delta = wmul(mean-value,k);\n        return delta < mean ? mean-delta : 0;\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, 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),0);\n            }\n            return (x.mu,x.v,0);\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,prob);\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":"ebd9de9bf6af6e55d5e308fd15dbb88edec11fd684891d02a30aec185acd19b3","params":{"target":"toxEma","TOX_DECAY":"910000000000000000","k_linear":0.7126960148076509,"k_quadratic":1.2952407538263107,"N":674,"cma_seed":45},"log":[{"params":[0.7606817830040726,0.8554320462623013,612],"n":64,"mean_diff":-0.36271454600530095,"se":0.054248159843225174,"fitness":-0.36271454600530095,"valid":true,"seed_start":950008,"generation":0,"elapsed_seconds":71.53270973498002},{"params":[0.6672581334595039,0.23498019124669287,159],"n":64,"mean_diff":-1.533257283835196,"se":0.1261815489251437,"fitness":-1.533257283835196,"valid":true,"seed_start":950008,"generation":0,"elapsed_seconds":71.38634985219687},{"params":[0.8673207692994713,0.39630572440057854,1632],"n":64,"mean_diff":-1.2137081510339156,"se":0.10590291665028065,"fitness":-1.2137081510339156,"valid":true,"seed_start":950008,"generation":0,"elapsed_seconds":72.21752508264035},{"params":[1.1287177452733888,0.743647587567167,1381],"n":64,"mean_diff":-0.46311590098456534,"se":0.051766759910397114,"fitness":-0.46311590098456534,"valid":true,"seed_start":950008,"generation":0,"elapsed_seconds":72.1808393439278},{"params":[0.15330773235845196,1.0747856844605148,115],"n":64,"mean_diff":-0.08883896466590713,"se":0.04573795666210567,"fitness":-0.08883896466590713,"valid":true,"seed_start":950008,"generation":0,"elapsed_seconds":57.57078371895477},{"params":[0.5495039677731235,0.3415098641119416,1032],"n":64,"mean_diff":-1.511805433784736,"se":0.12567828915515838,"fitness":-1.511805433784736,"valid":true,"seed_start":950008,"generation":0,"elapsed_seconds":40.42582811508328},{"params":[0.10308152352133597,0.7020084413925601,1385],"n":64,"mean_diff":-1.1017057137248614,"se":0.130489862106933,"fitness":-1.1017057137248614,"valid":true,"seed_start":950072,"generation":1,"elapsed_seconds":41.83088768878952},{"params":[0.03199608394237456,0.5388105824633905,129],"n":64,"mean_diff":-1.4609282186516923,"se":0.15713329382092314,"fitness":-1.4609282186516923,"valid":true,"seed_start":950072,"generation":1,"elapsed_seconds":40.465636684093624},{"params":[1.0341809511313658,0.47884214432100425,127],"n":64,"mean_diff":-0.9702483170997249,"se":0.10342612630402331,"fitness":-0.9702483170997249,"valid":true,"seed_start":950072,"generation":1,"elapsed_seconds":39.16147166537121},{"params":[1.43689796742366,1.0252150659359613,331],"n":64,"mean_diff":0.11358821542177999,"se":0.048677319249159405,"fitness":0.11358821542177999,"valid":true,"seed_start":950072,"generation":1,"elapsed_seconds":40.384448514319956},{"params":[0.5954187866171814,0.6040566242206987,631],"n":64,"mean_diff":-0.9757720293744718,"se":0.11749183494916832,"fitness":-0.9757720293744718,"valid":true,"seed_start":950072,"generation":1,"elapsed_seconds":41.019724023062736},{"params":[0.00543136140455106,1.4922892351317762,110],"n":64,"mean_diff":0.08687681854866192,"se":0.1844531498977163,"fitness":0.08687681854866192,"valid":true,"seed_start":950072,"generation":1,"elapsed_seconds":39.81224045017734},{"params":[1.417716646410589,0.9963295353406977,118],"n":64,"mean_diff":0.07874103222130113,"se":0.04486415912643504,"fitness":0.07874103222130113,"valid":true,"seed_start":950136,"generation":2,"elapsed_seconds":39.608905455097556},{"params":[0.912313731523712,1.1397744130342484,101],"n":64,"mean_diff":0.16916364494418445,"se":0.08077100788680712,"fitness":0.16916364494418445,"valid":true,"seed_start":950136,"generation":2,"elapsed_seconds":39.75460508093238},{"params":[1.3497067937703575,0.5712247646629681,514],"n":64,"mean_diff":-0.6492872783454757,"se":0.06830302895285335,"fitness":-0.6492872783454757,"valid":true,"seed_start":950136,"generation":2,"elapsed_seconds":39.472560219001025},{"params":[1.0917141102666517,0.7186139707801608,1359],"n":64,"mean_diff":-0.4903066387410071,"se":0.055447042942599056,"fitness":-0.4903066387410071,"valid":true,"seed_start":950136,"generation":2,"elapsed_seconds":39.89649603003636},{"params":[1.1044031555428824,1.1706773560174795,2715],"n":64,"mean_diff":0.20652252852173092,"se":0.11641820803799673,"fitness":0.20652252852173092,"valid":true,"seed_start":950136,"generation":2,"elapsed_seconds":40.35118042584509},{"params":[1.4938305359934525,1.473502153668738,2185],"n":64,"mean_diff":-0.9796266912357279,"se":0.3505823300775027,"fitness":-0.9796266912357279,"valid":true,"seed_start":950136,"generation":2,"elapsed_seconds":39.69646607898176},{"params":[0.7126960148076509,1.2952407538263107,674],"n":64,"mean_diff":0.2983131921566189,"se":0.12767848624339656,"fitness":0.2983131921566189,"valid":true,"seed_start":950200,"generation":3,"elapsed_seconds":40.704792756121606},{"params":[1.0086324125761255,0.6748744517565866,398],"n":64,"mean_diff":-0.5343932302462964,"se":0.08027946305443172,"fitness":-0.5343932302462964,"valid":true,"seed_start":950200,"generation":3,"elapsed_seconds":39.618723694235086},{"params":[0.9280260035278367,1.0254378507041875,1772],"n":64,"mean_diff":0.05121977520492926,"se":0.014127664072675952,"fitness":0.05121977520492926,"valid":true,"seed_start":950200,"generation":3,"elapsed_seconds":39.234000300988555},{"params":[1.0297973005419596,1.4968322886640395,1059],"n":64,"mean_diff":-0.5603542080470394,"se":0.341390216797673,"fitness":-0.5603542080470394,"valid":true,"seed_start":950200,"generation":3,"elapsed_seconds":39.490935823414475},{"params":[1.3490720224364616,1.1781129419149794,1507],"n":64,"mean_diff":0.2555396553392013,"se":0.10525084924596646,"fitness":0.2555396553392013,"valid":true,"seed_start":950200,"generation":3,"elapsed_seconds":38.99777186103165},{"params":[0.9200759493009093,1.4908785007838288,114],"n":64,"mean_diff":-0.24748062893556622,"se":0.2514838772067754,"fitness":-0.24748062893556622,"valid":true,"seed_start":950200,"generation":3,"elapsed_seconds":40.46710763219744},{"params":[0.6233188147908063,1.3706168274093389,203],"n":64,"mean_diff":0.10835022028486829,"se":0.14724395342871135,"fitness":0.10835022028486829,"valid":true,"seed_start":950264,"generation":4,"elapsed_seconds":40.14736494375393}],"recheck":[{"params":[0.7126960148076509,1.2952407538263107,674],"valid":true,"paired":{"n":256,"mean_diff":0.270224707720107,"se":0.05149140371036169,"worst":[{"seed":953171,"d":-6.859049688671121},{"seed":953052,"d":-2.450295546809116},{"seed":953221,"d":-2.0956910339230603},{"seed":953122,"d":-2.080844859329659},{"seed":953186,"d":-2.0238654648853185}]},"retail_edge_delta":{"mean":-0.6971071423067843,"se":0.05577585716852322},"arb_edge_delta":{"mean":0.9673318500268914,"se":0.030820841264947267},"reconciliation_max_abs":1.0302869668521453e-13,"gas":{"max_ok":223347,"init_max_ok":243115,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},{"params":[1.3490720224364616,1.1781129419149794,1507],"valid":true,"paired":{"n":256,"mean_diff":0.15912170121785385,"se":0.04351964221428467,"worst":[{"seed":953168,"d":-3.1603019143921074},{"seed":953052,"d":-2.5745816688826153},{"seed":953122,"d":-2.5347385778661646},{"seed":953004,"d":-1.9767030587241834},{"seed":953186,"d":-1.9555166862706415}]},"retail_edge_delta":{"mean":-1.2647305692426005,"se":0.045564534723959986},"arb_edge_delta":{"mean":1.423852270460455,"se":0.030652094164565467},"reconciliation_max_abs":9.947598300641403e-14,"gas":{"max_ok":223347,"init_max_ok":243115,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},{"params":[1.1044031555428824,1.1706773560174795,2715],"valid":true,"paired":{"n":256,"mean_diff":0.19160517369881847,"se":0.033901278835413,"worst":[{"seed":953122,"d":-2.0224386185218464},{"seed":953186,"d":-1.6563488575518477},{"seed":953221,"d":-1.58750708385611},{"seed":953129,"d":-1.3833383359436766},{"seed":953250,"d":-1.2829544130552222}]},"retail_edge_delta":{"mean":-0.7935284227673534,"se":0.03474024823725491},"arb_edge_delta":{"mean":0.9851335964661704,"se":0.0236477285419919},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":223347,"init_max_ok":243115,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}],"held_out":{"vs_rs2":{"n":512,"mean_diff":0.23348546171278806,"se":0.03730861769844101,"worst":[{"seed":954369,"d":-8.724713458962242},{"seed":954398,"d":-4.054803634916311},{"seed":954083,"d":-3.167669864237496},{"seed":954158,"d":-2.7647642151475793},{"seed":954237,"d":-2.374953150606757}]},"retail_edge_delta":{"mean":-0.7774245705147632,"se":0.04220457015290185},"arb_edge_delta":{"mean":1.0109100322275493,"se":0.022803666884412516},"reconciliation_max_abs":2.2737367544323206e-13,"seeds":[954000,954511]},"gas":{"max_ok":225483,"init_max_ok":243115,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"scope":"Frozen candidate on held-out 512 seeds; gas_stats for each arm reset and collected separately.","all_search_recheck_held_parity":{"max_ok":225483,"init_max_ok":243115,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}},"held_out_rs2":{"max_ok":202414,"init_max_ok":243099,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"parity":{"off":{"n":32,"start":954600,"end":954631,"all_edge_rows_equal":true,"paired":{"n":32,"mean_diff":0.0,"se":0.0,"worst":[{"seed":954600,"d":0.0},{"seed":954601,"d":0.0},{"seed":954602,"d":0.0},{"seed":954603,"d":0.0},{"seed":954604,"d":0.0}]},"gas":{"max_ok":197288,"init_max_ok":243099,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}},"source_equals_rs2":true},"unit":{"n":32,"start":954600,"end":954631,"all_edge_rows_equal":true,"paired":{"n":32,"mean_diff":0.0,"se":0.0,"worst":[{"seed":954600,"d":0.0},{"seed":954601,"d":0.0},{"seed":954602,"d":0.0},{"seed":954603,"d":0.0},{"seed":954604,"d":0.0}]},"gas":{"max_ok":219704,"init_max_ok":243099,"oog":0,"other_halts":{"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},"generator_source":"RS2_SOURCE = '// 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[15] = 400000000000000000 | (uint256(2000000000000000) << 160); 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        uint256 arbProbability;\\n        (fastHat, uncertainty, arbProbability) = _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 originalLambda = lambdaHat; uint256 originalSize = sizeHat;\\n\\n        if (342406799193418304 > 0) {\\n            uint256 packedFlow = slots[15];\\n            uint256 rate = uint80(packedFlow);\\n            uint256 count = uint80(packedFlow >> 80);\\n            uint256 meanSize = uint80(packedFlow >> 160);\\n            if (rate == 0) rate = 400000000000000000;\\n            if (meanSize == 0) meanSize = 2000000000000000;\\n            if (isNewStep) {\\n                uint256 inst = count / silent;\\n                if (inst > 3 * WAD) inst = 3 * WAD;\\n                uint256 retention = _powWad(999000000000000000, silent > 64 ? 64 : silent);\\n                rate = wmul(rate, retention) + wmul(inst, WAD-retention);\\n                count = 0;\\n            }\\n            uint256 weight = firstInStep ? WAD-arbProbability : WAD;\\n            uint256 correctedWeight = weight;\\n            if (2 == 2) {\\n                uint256 missing = wmul(feeUsed, 196030880396139429888);\\n                if (missing > 333333333333333376) missing = 333333333333333376;\\n                correctedWeight = wdiv(weight, WAD-missing);\\n            }\\n            count += correctedWeight;\\n            uint256 learning = wmul(WAD-999000000000000000, weight);\\n            meanSize = _blend(meanSize, tradeRatio, learning);\\n            slots[15]=rate | (count << 80) | (meanSize << 160);\\n            uint256 retailRate = wmul(rate, 366383424913407168);\\n            uint256 retailSize = 2 == 0 ? sizeHat : wmul(meanSize,1883296158119298304);\\n            lambdaHat = _blend(lambdaHat,retailRate,342406799193418304);\\n            sizeHat = _blend(sizeHat,retailSize,342406799193418304);\\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        lambdaHat = originalLambda; sizeHat = originalSize;\\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        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, 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),0);\\n            }\\n            return (x.mu,x.v,0);\\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,prob);\\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'\n\ndef generate(base,params,enabled=True):\n    kl,kq,N=params\n    if not enabled: return base\n    kl=int(round(kl*10**18)); kq=int(round(kq*10**18)); N=int(round(N))\n    anchor=f'''\n        uint256 toxLinear;\n        uint256 toxQuadratic;\n        {{\n            uint256 packedAnchor = slots[16];\n            uint256 runMean = uint64(packedAnchor);\n            uint256 sampleCount = packedAnchor >> 64;\n            if (sampleCount < {N}) sampleCount++;\n            if (toxEma >= runMean) runMean += (toxEma-runMean)/sampleCount;\n            else runMean -= (runMean-toxEma)/sampleCount;\n            slots[16] = runMean | (sampleCount << 64);\n            toxLinear = _anchorBlend(runMean, toxEma, {kl});\n            toxQuadratic = _anchorBlend(runMean, toxEma, {kq});\n        }}\n'''\n    old='        uint256 toxSignal = toxEma;'\n    assert base.count(old)==1\n    s=base.replace(old,old+anchor)\n    s=s.replace('wmul(TOX_COEF, toxSignal)', 'wmul(TOX_COEF, toxLinear)')\n    s=s.replace('wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal))', 'wmul(TOX_QUAD_COEF, wmul(toxQuadratic, toxQuadratic))')\n    s=s.replace('wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal))', 'wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxLinear))')\n    helper='''\n    function _anchorBlend(uint256 mean, uint256 value, uint256 k) internal pure returns (uint256) {\n        if (k == WAD) return value;\n        if (value >= mean) return mean + wmul(value-mean,k);\n        uint256 delta = wmul(mean-value,k);\n        return delta < mean ? mean-delta : 0;\n    }\n'''\n    return s.replace('    struct PosteriorInput {',helper+'\\n    struct PosteriorInput {')\n\n\nPARAMS = [0.7126960148076509, 1.2952407538263107, 674]\n# Reproduce final code exactly:\ncode = generate(RS2_SOURCE, PARAMS)\n","calibration":{"n":1000,"mean_edge":525.5258821780834,"expected":525.5258821780834,"abs_error":0.0,"elapsed":424.15693831443787},"notes":["Each arm runs alone against VanillaStrategy using amm_sim_rs.run_batch(..., 8). Simulator and checkout pinned as requested; initial RS2 source SHA-256 verified.","This subtask uses RS2 rather than STACK as its paired reference and only the prescribed seed ranges; no seeds >=5000000 were used.","Running mean is sampled after each swap updates toxEma. n increases to N then stays capped; subsequent updates have weight 1/N. Integer division truncates toward zero. Mean and count are packed into slots[16], initially zero without an initialization write.","Linear blend feeds TOX_COEF and SIGMA_TOX_COEF; separate quadratic blend feeds TOX_QUAD_COEF. DIR_TOX_COEF keeps the original toxSignal. Extrapolation below zero for k>1 is floored at zero. Price, stale-shift and posterior code are unchanged.","CMA searches normalized coordinates: k_linear=1.5*x0, k_quadratic=1.5*x1, N=round(100*100**x2), bounds 0..1, initial [0.5,0.5,0.5], sigma 0.27, population 6, random seed 45. Each generation shares one fresh 64-seed block across separately simulated arms; fresh blocks between generations. Probe seeds 950000..950007 excluded from search.","Any halt or gas-limit violation gives fitness -1000. Search elapsed seconds: 1371.4161212360486. Top three valid observed paired gains rechecked on 953000..953255; highest valid recheck mean frozen before held-out.","Parity separately re-executes RS2, overlay-off (exact RS2 source), and enabled k_linear=k_quadratic=1 on seeds 954600..954631; compares edge, arbitrage, and retail rows exactly for every seed.","Worst contains the five lowest paired seed deltas. SE is sample standard deviation of paired differences divided by sqrt(n). Retail/arb decomposition follows supplied harness, including initial fee 0.0004.","No board submission or board gain is claimed. Measured results are local simulator outputs, not externally certified."]}