{"key": "retune-b", "blocked": null, "gates": {"A": {"pass": true, "sequences": 50, "callbacks": 100050, "max_fee_diff_bps": 1.2216616607219066e-09, "first_divergence": null}, "B": {"pass": true, "markets": "31000000..31004095", "paired_Tport_minus_RS2port": 0.2420270811033297, "se": 0.01692058854320023, "mean_Tport": 525.8018173009173, "mean_RS2port": 525.559790219814}, "C": {"pass": true, "sequences": 20, "callbacks": 40020, "max_fee_diff_bps": 1.9060447664642766e-09, "first_divergence": null}}, "ch_check": {"seeds": "0..999", "mean_edge": 525.5258821780834, "matches_brief": true}, "sim_markets_per_s": 478.4, "search": {"method": "cma (pycma) CMAEvolutionStrategy, seed 12, popsize 16, sigma0 0.15, x0 = T in normalized coords", "dims": 79, "generations": 190, "markets_per_generation": 256, "block_seeds": "21000000+256*g .. (g=0..189), shared by all 16 candidates and the T-port baseline (CRN)", "objective": "mean paired edge gain over T-port on the generation block", "monitor": "every 10 generations the CMA distribution mean (integers rounded) scored on 30000000..30002047, paired vs T-port; best kept by that score", "coords": "logit for constants in (0,1) (decays, alphas, tail slopes, SILENCE_DECAY/ATTENUATION, ROUTE_OLD, FLOW_BLEND, FLOW_RETENTION, STALE_SLOW_WEIGHT, MISSING_CAP); log for all other positive scales; no signed constants exist; integers (ELAPSED_CAP, STEP_COUNT_CAP, DIR_IMPACT_MULT, SILENCE_G_CAP, POST_ELAPSED_CAP, FLOW_ELAPSED_CAP, DENSITY_SCALE, DENSITY_POWER, Q_CENTER, Q_NEAR, Q_MID, ANCHOR_N) rounded, min 1", "excluded": {"per_brief": ["WAD", "BPS", "MAX_FEE", "MIN_FEE", "L<line>_N<k> audit entries"], "structural": ["ZERO", "ONE", "TWO", "THREE", "FOUR", "ONE_WEI (arithmetic/index literals)", "FALLBACK_PRICE (init only, unreachable since initialX>0)", "FLOW_CORRECTION_MODE", "FLOW_CORRECTION_ACTIVE", "FLOW_SIZE_MODE (mode switches)", "REVERT_U (0 = feature off; slot 11 is never written, so it cannot be set >0 meaningfully and 0 has no log/logit coordinate)"], "tied": ["ROUTE_NEW = 1-ROUTE_OLD", "STALE_FAST_WEIGHT = 1-STALE_SLOW_WEIGHT"]}, "deviation_note": "A first run with all 81 named constants independent found every candidate far below T (gen-10 monitor -34.8): at sigma 0.15 the two convex-weight pairs (ROUTE_OLD/NEW, STALE_SLOW/FAST_WEIGHT) stop summing to 1, biasing pHat/staleHat (single-dim +-0.15 cost -70..-280 edge on 128 markets). Those two pairs were tied and the search restarted from scratch; only the restarted run is reported.", "log_last10": [[180, 0.5146891888762184, 0.1773253930566625], [181, 0.6152315232054661, -0.4710694727506848], [182, 0.5898052220959471, 0.09496614314730323], [183, 0.4806308595957489, -0.26525686761584666], [184, 0.6946905738060423, 0.13736874104387198], [185, 0.6297163393400069, 0.03309202223954344], [186, 0.6088694628158464, -0.14911819001781623], [187, 0.43463885022799786, -0.004785402913483949], [188, 0.5646059667394638, 0.004103539873085538], [189, 0.5283732592433807, 0.13393911074655307]]}, "curve": [[10, -0.19977973790207393, 0.02603203988872857], [20, -0.16653462202050495, 0.02674689315183728], [30, 0.02483710357828331, 0.025969899498670405], [40, -0.3053038976163933, 0.027736253977733393], [50, -0.0740901476822842, 0.025102033542604818], [60, 0.2663355559721686, 0.027503938384737664], [70, 0.3602056934408214, 0.022145189453766683], [80, 0.5558707648276106, 0.026267138949576923], [90, 0.616967445148366, 0.0288580443371288], [100, 0.6011092433715342, 0.027039358585306712], [110, 0.5895222767713925, 0.025761869102465286], [120, 0.511454067137906, 0.0250561296968734], [130, 0.5975595740784082, 0.024870917742458566], [140, 0.5724819606397986, 0.021876298483878825], [150, 0.6562917858981608, 0.02501197218306619], [160, 0.6094603077674305, 0.0228369434383294], [170, 0.5351990656493611, 0.02641770841339239], [180, 0.4789941814550639, 0.025926607708945264], [190, 0.6879077949542078, 0.02158988050635428]], "best_monitor": {"gen": 190, "gain": 0.6879077949542078, "se": 0.02158988050635428, "retail_delta": 2.4207059836380243, "arb_delta": -1.7327981886838169}, "params": {"ELAPSED_CAP": 8, "SIGNAL_THRESHOLD": 0.0017511487959276906, "DIR_DECAY": 0.6514645036518215, "ACT_DECAY": 0.589750927902603, "SIZE_DECAY": 0.5380379278368321, "TOX_DECAY": 0.9093904864860669, "SIGMA_DECAY": 0.5770771525287579, "LAMBDA_DECAY": 0.9903471217456302, "SIZE_BLEND_DECAY": 0.871969791418832, "TOX_BLEND_DECAY": 0.09351022876308726, "ACT_BLEND_DECAY": 0.9895322166941372, "PHAT_ALPHA": 0.24213517706880847, "PHAT_ALPHA_RETAIL": 0.032339991693568194, "PHAT_ALPHA_SAME": 0.1830841161665029, "DIR_IMPACT_MULT": 3, "GATE_SIGMA_MULT": 3.1971840898111834, "MIN_GATE": 0.028165293857944758, "TRADE_TOX_BOOST": 0.42978288384089536, "STALE_ATTRACT_FRAC": 0.981475953631497, "RET_CAP": 0.02945295203859404, "TOX_CAP": 0.2981236389498349, "TRADE_RATIO_CAP": 0.11029474236039444, "LAMBDA_CAP": 1.2075087961483788, "STEP_COUNT_CAP": 110, "BASE_FEE": 0.0008650075901767141, "SIGMA_COEF": 0.08067422929103589, "LAMBDA_COEF": 0.0012415387090822826, "FLOW_SIZE_COEF": 0.4079034165095706, "TOX_COEF": 0.0439491840446791, "TOX_QUAD_COEF": 1.4605932033918767, "ACT_COEF": 12.044143456537576, "DIR_COEF": 0.001756339474717297, "DIR_TOX_COEF": 0.011156145602773478, "STALE_DIR_COEF": 0.6490614552677916, "SIGMA_TOX_COEF": 0.055924606077370216, "TAIL_KNEE": 0.042506777933567906, "TAIL_SLOPE_PROTECT": 0.8682403846711462, "TAIL_SLOPE_ATTRACT": 0.8002415624646925, "INITIAL_SIGMA": 0.0013672028240596143, "INITIAL_LAMBDA": 0.588446616406699, "INITIAL_SIZE": 0.001990211658046025, "INITIAL_RATE": 0.6574687905822574, "PROCESS_VAR": 2.7325060234787347e-07, "VAR_CAP": 8.931192211764996e-05, "SILENCE_G_CAP": 1, "SILENCE_DECAY": 0.7286326840675555, "SILENCE_ATTENUATION": 0.3100473221952523, "ROUTE_FEE": 0.0026147618677795103, "ROUTE_OLD": 0.8843965935142136, "PUSH_CAP": 0.2545446486180162, "DIR_CAP": 2.1130015313833, "FLOW_BLEND": 0.3491734014867046, "FLOW_RATE_CAP": 4.296672442708149, "FLOW_RETENTION": 0.9987790424458196, "FLOW_ELAPSED_CAP": 44, "MISSING_COEF": 401.8194972602162, "MISSING_CAP": 0.23740368873627413, "RETAIL_RATE_COEF": 0.32179513703076185, "RETAIL_SIZE_COEF": 3.4817433863357037, "STALE_SLOW_WEIGHT": 0.650859212955623, "RETAIL_BOOST_CAP": 0.00100006573560505, "ATTRACT_CAP": 0.003258763465833874, "VAR_FLOOR": 9.656186458418126e-09, "POST_ELAPSED_CAP": 4, "RETAIL_NOISE": 1.7238170213645818e-05, "OBS_VAR": 1.5792193446726006e-08, "DENSITY_SCALE": 15, "DENSITY_POWER": 6, "ODDS_SCALE": 0.0036007201955488934, "LARGE_SIZE": 0.004074890945864967, "LARGE_ODDS_MULT": 0.2612531845069948, "SILENT_ODDS_MULT": 0.6096402110722261, "MASS_FLOOR": 0.013819783447978882, "Q_CENTER": 50, "Q_NEAR": 24, "Q_MID": 12, "ANCHOR_N": 846, "ANCHOR_K_LIN": 0.6631392212040489, "ANCHOR_K_QUAD": 1.6075516599545092, "ROUTE_NEW": 0.11560340648578638, "STALE_FAST_WEIGHT": 0.349140787044377}, "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 = 1751148795927690;\n    uint256 constant DIR_DECAY = 651464503651821568;\n    uint256 constant ACT_DECAY = 589750927902603008;\n    uint256 constant SIZE_DECAY = 538037927836832128;\n    uint256 constant TOX_DECAY = 909390486486066944;\n    uint256 constant SIGMA_DECAY = 577077152528757888;\n    uint256 constant LAMBDA_DECAY = 990347121745630208;\n    uint256 constant SIZE_BLEND_DECAY = 871969791418832000;\n    uint256 constant TOX_BLEND_DECAY = 93510228763087264;\n    uint256 constant ACT_BLEND_DECAY = 989532216694137216;\n    uint256 constant PHAT_ALPHA = 242135177068808480;\n    uint256 constant PHAT_ALPHA_RETAIL = 32339991693568196;\n    uint256 constant PHAT_ALPHA_SAME = 183084116166502912;\n    uint256 constant REVERT_U = 0;\n    uint256 constant DIR_IMPACT_MULT = 3;\n    uint256 constant GATE_SIGMA_MULT = 3197184089811183616;\n    uint256 constant MIN_GATE = 28165293857944756;\n    uint256 constant TRADE_TOX_BOOST = 429782883840895360;\n    uint256 constant STALE_ATTRACT_FRAC = 981475953631496960;\n    uint256 constant RET_CAP = 29452952038594040;\n    uint256 constant TOX_CAP = 298123638949834880;\n    uint256 constant TRADE_RATIO_CAP = 110294742360394432;\n    uint256 constant LAMBDA_CAP = 1207508796148378880;\n    uint256 constant STEP_COUNT_CAP = 110;\n    uint256 constant BASE_FEE = 865007590176714;\n    uint256 constant SIGMA_COEF = 80674229291035888;\n    uint256 constant LAMBDA_COEF = 1241538709082282;\n    uint256 constant FLOW_SIZE_COEF = 407903416509570624;\n    uint256 constant TOX_COEF = 43949184044679104;\n    uint256 constant TOX_QUAD_COEF = 1460593203391876608;\n    uint256 constant ACT_COEF = 12044143456537575424;\n    uint256 constant DIR_COEF = 1756339474717297;\n    uint256 constant DIR_TOX_COEF = 11156145602773478;\n    uint256 constant STALE_DIR_COEF = 649061455267791616;\n    uint256 constant SIGMA_TOX_COEF = 55924606077370216;\n    uint256 constant TAIL_KNEE = 42506777933567904;\n    uint256 constant TAIL_SLOPE_PROTECT = 868240384671146112;\n    uint256 constant F_ROUTE_FEE = 2614761867779510;\n    uint256 constant F_RETAIL_BOOST_CAP = 1000065735605050;\n    uint256 constant F_ATTRACT_CAP = 3258763465833874;\n    uint256 constant F_FLOW_BLEND = 349173401486704640;\n    uint256 constant F_FLOW_RETENTION = 998779042445819648;\n    uint256 constant F_INITIAL_SIZE = 1990211658046025;\n    uint256 constant F_INITIAL_RATE = 657468790582257408;\n    uint256 constant F_PROCESS_VAR = 273250602348;\n    uint256 constant F_VAR_CAP = 89311922117650;\n    uint256 constant F_VAR_FLOOR = 9656186458;\n    uint256 constant TAIL_SLOPE_ATTRACT = 800241562464692480;\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] = 1367202824059614; slots[7] = 588446616406699008; slots[8] = F_INITIAL_SIZE;\n        slots[15] = F_INITIAL_RATE | (F_INITIAL_SIZE << 160); slots[13] = F_PROCESS_VAR; 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 > F_VAR_CAP) uncertainty = F_VAR_CAP;\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(728632684067555584, 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(310047322195252288, 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 > F_ROUTE_FEE && gamma > 0) {\n            uint256 normalSpot = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - F_ROUTE_FEE)\n                : wdiv(wmul(spot, WAD - F_ROUTE_FEE), gamma);\n            pHat = wmul(pHat, 884396593514213632) + wmul(normalSpot, 115603406485786368);\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 > 254544648618016192) push = 254544648618016192;\n            if (trade.isBuy) {\n                dirState = dirState + push;\n                if (dirState > 2113001531383300096) dirState = 2113001531383300096;\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 < 846) 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, 663139221204048896);\n            toxQuadratic = _anchorBlend(runMean, toxEma, 1607551659954509312);\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 (F_FLOW_BLEND > 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 = F_INITIAL_RATE;\n            if (meanSize == 0) meanSize = F_INITIAL_SIZE;\n            if (isNewStep) {\n                uint256 inst = count / silent;\n                if (inst > 4296672442708149248) inst = 4296672442708149248;\n                uint256 retention = _powWad(F_FLOW_RETENTION, silent > 44 ? 44 : 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, 401819497260216221696);\n                if (missing > 237403688736274112) missing = 237403688736274112;\n                correctedWeight = wdiv(weight, WAD-missing);\n            }\n            count += correctedWeight;\n            uint256 learning = wmul(WAD-F_FLOW_RETENTION, weight);\n            meanSize = _blend(meanSize, tradeRatio, learning);\n            slots[15]=rate | (count << 80) | (meanSize << 160);\n            uint256 retailRate = wmul(rate, 321795137030761856);\n            uint256 retailSize = 2 == 0 ? sizeHat : wmul(meanSize,3481743386335703552);\n            lambdaHat = _blend(lambdaHat,retailRate,F_FLOW_BLEND);\n            sizeHat = _blend(sizeHat,retailSize,F_FLOW_BLEND);\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, 650859212955623040) + wmul(fastHat, 349140787044376960);\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 > F_RETAIL_BOOST_CAP) tradeBoost = F_RETAIL_BOOST_CAP;\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 > F_ROUTE_FEE) bidFee = F_ROUTE_FEE;\n            else if (bidFee > askFee && askFee > F_ROUTE_FEE) askFee = F_ROUTE_FEE;\n        }\n\n        if (bidFee > askFee && askFee > F_ATTRACT_CAP) askFee = F_ATTRACT_CAP;\n        else if (askFee > bidFee && bidFee > F_ATTRACT_CAP) bidFee = F_ATTRACT_CAP;\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 < F_VAR_FLOOR) x.v = F_VAR_FLOOR;\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>4?4:x.silent;\n                x.v += F_PROCESS_VAR*(elapsed-1);\n                (x.mu,x.v)=_band(x.mu,x.v,lo,hi);\n            }\n            x.v+=F_PROCESS_VAR;\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 > F_ROUTE_FEE) {\n                uint256 normal = x.buy ? wdiv(wmul(x.spot, WAD-fee), WAD-F_ROUTE_FEE)\n                    : wdiv(wmul(x.spot, WAD-F_ROUTE_FEE), WAD-fee);\n                uint256 residual = wdiv(absDiff(normal, x.mu),x.mu);\n                uint256 noise = 17238170213646 + 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 + 15792193447;\n        uint256 z = wdiv(wmul(e,e),totalV);\n        uint256 density = _powWad(wdiv(WAD,WAD+z/15),6);\n        uint256 odds = wmul(density,wdiv(3600720195548894,_isqrt(totalV*WAD)));\n        if (x.size > 4074890945864968) odds = wmul(odds,261253184506994816);\n        if (x.silent > 1) odds = wmul(odds,609640211072226048);\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 < 13819783447978882) mass = 13819783447978882;\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 > F_VAR_CAP) variance = F_VAR_CAP;\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?50:(j==2||j==4?24:(j==1||j==5?12: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):F_VAR_FLOOR);\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": "b9a6cfc6dea448a249d9ac9091814af535ee7c8d308d15173846815ffc39adc5", "real": {"seeds": "6010000..6010511", "chunks": "8 x 64, in order, each chunk candidate then T, each strategy alone vs VanillaStrategy via amm_sim_rs.run_batch(...,8)", "n": 512, "mean_diff": 0.6660656750211413, "se": 0.048660133223841766, "mean_candidate": 530.9755646475767, "mean_T": 530.3094989725555, "worst5": [{"seed": 6010056, "d": -4.390787161499475}, {"seed": 6010167, "d": -1.8935969270149826}, {"seed": 6010267, "d": -1.8428326025604065}, {"seed": 6010098, "d": -1.7774117659661215}, {"seed": 6010380, "d": -1.693067820146382}], "retail_delta": {"mean": 2.404473966366323, "se": 0.05411544810139543}, "arb_delta": {"mean": -1.73840829134518, "se": 0.029532728043446553}, "share_positive": 0.78515625}, "gas": {"max_ok": 226188, "init_max_ok": 243115, "oog": 0, "revert": 0, "other_errors": 0, "afterSwap_limit_ok": true, "T_same_seeds": {"max_ok": 223348, "init_max_ok": 243115, "oog": 0, "revert": 0, "other_errors": 0}}, "minutes": {"search": 30.3, "real": 9.3}, "interpretation": "The replica-proposed CMA-ES retune of all named constants of T beats T on the real engine by +0.666 (se 0.049, n=512), consistent with the replica monitor (+0.688 se 0.022). This is a real but modest gain, far short of the ~+4.3 over T the top 10 needs; the search was still improving slowly (sigma ~0.073) when stopped after 190 generations / 30.3 min.", "notes": ["Candidate seeds were not used to choose anything; the frozen candidate was fixed before the real run, which ran once.", "gas.max_ok is the afterSwap max_ok_gas over all 512 seeds for the candidate; T_same_seeds gives T on the same seeds.", "Pre-existing T, RS2, replica and port sources were sha256-checked against the brief before use."]}