{"key": "head-b", "blocked": null, "gates": {"A": {"pass": true, "sequences": 50, "callbacks": 100050, "max_fee_diff_bps": 1.2216616607219066e-09, "note": "T-port vs EVM T"}, "B": {"pass": true, "mean": 0.2420270811033297, "se": 0.01692058854320023, "n": 4096, "markets": "31000000..31004095", "T_port_mean": 525.8018173009173, "RS2_port_mean": 525.559790219814, "target": "0.27 +/- 0.10"}, "C": {"pass": true, "sequences": 20, "max_fee_diff_bps": 3.4685795902156258e-09, "note": "frozen 6-unit Solidity vs frozen 6-unit port; the earlier 12-unit version gave 7.8e-10"}}, "sim_markets_per_s": {"T_and_RS2_port_no_head_4_procs": 455.1, "search_with_12_unit_head": "about 311 (17 candidates x 256 markets in ~14 s/generation, 4 procs)"}, "curve": [[10, 0.11412085092356, 0.015295940253782135], [20, 0.2595524375543032, 0.01751231626591569], [30, 0.4395635138519348, 0.01784551496828221], [40, 0.39593753285938527, 0.01628359796707059], [50, 0.6331853856631886, 0.01678328064335624], [60, 0.6578403238956898, 0.02022155709869715], [70, 0.7141607402123651, 0.018909506814361463], [80, 0.7384690220400385, 0.017725217260728288], [90, 0.822163435761742, 0.01834980143612967], [100, 0.7959553014257383, 0.019892781836703993], [110, 0.8117133515782559, 0.020074348531586794], [120, 0.7843345942877294, 0.0204430326473831], [130, 0.7694444452263454, 0.018364589729968326]], "best_monitor": {"gain": 0.822163435761742, "se": 0.01834980143612967, "generation": 90, "units": 12, "monitor_markets": "30000000..30002047", "frozen_6_unit_gain": 0.7537746360886799, "frozen_6_unit_se": 0.01785351124336751, "note": "frozen 6-unit gain is optimistic: the 6 units were chosen by |W2| rank and compared on the first 1024 monitor markets"}, "params": {"setup": "fee_side = clamp(T fee + h_side*1e-4, 0, MAX_FEE); h = W2 r(W1 xn + b1) + b2 (bps); r=clamp(z,0,4); xn=clamp((f-c)/s,-4,4); features f in order: sigmaHat, lambdaHat, sizeHat, toxEma, actEma, direction, (spot-staleHat)/staleHat, signed trade ratio, arb probability, first-in-step, uncertainty, min(silent,8)/8, anchor mean. Weights rounded to 1e-6 (W2,b2 in bps).", "search_units": 12, "frozen_units_kept": [2, 3, 4, 7, 9, 11], "cma": {"seed": 22, "popsize": 16, "sigma0": 0.3, "W1_init": "N(0,0.3) rng(22)", "b1_init": 0.3, "W2_b2_init": 0, "generations": 137, "markets_per_gen": 256, "first_block_start": 23000000}, "norm_c": [0.003916, 1.126, 0.0001942, 0.004868, 1.782e-05, 1.0, 9.789e-05, -7.387e-07, 0.3557, 0.6607, 2.893e-06, 0.1228, 0.004855], "norm_s": [0.001361, 0.06069, 0.0003725, 0.005705, 3.434e-05, 0.01013, 0.007865, 0.001843, 0.3402, 0.4735, 2.453e-06, 0.1374, 0.0007214], "anchor_k": [0.7126960148076508, 1.2952407538263107], "W1_kept": {"2": [-0.386523, -0.09941, -0.853684, -1.620674, -0.349424, -0.454413, -0.376124, 0.332322, -0.188488, -0.035463, 0.327758, 0.019517, -0.989312], "3": [-1.57747, -0.823874, -0.312926, -3.145866, -0.383957, -0.606785, 1.162326, -0.877009, 0.106636, 0.214042, -0.208828, -0.194515, 0.068831], "4": [-1.572822, 0.147811, -0.992475, -0.071296, -0.012764, -2.830585, 0.036117, -1.009639, 0.491355, -0.444284, -2.326566, -0.374493, 0.549372], "7": [3.20907, -0.60743, -0.867368, 0.146218, 0.051078, 0.929345, 0.615099, -0.41044, -0.272232, 0.988985, 0.2564, -0.442726, 0.079812], "9": [-0.46637, 0.706461, 1.921391, 0.266328, -0.722358, -0.364499, 0.987386, 0.277402, -0.721404, 0.274906, 0.147993, -0.501168, 0.58819], "11": [0.436452, 0.037127, 2.651873, 1.133981, 1.249792, -0.727471, -0.767065, -2.891992, -1.24288, 0.190545, 0.867464, 0.820024, 0.778091]}, "b1_kept": {"2": -0.062699, "3": 0.713774, "4": -0.362826, "7": 0.593384, "9": -0.856699, "11": -2.397991}, "W2_kept": {"0": {"2": 0.741578, "3": 0.116534, "4": -0.72362, "7": -0.44462, "9": 0.49036, "11": -0.349234}, "1": {"2": 0.483003, "3": 1.155507, "4": -0.631125, "7": -0.879137, "9": -1.013998, "11": 1.121967}}, "b2": [-0.753846, -1.978561], "full_12_unit_search_best_rounded": [-1.102218, 0.230507, -1.387355, -0.348368, 1.339866, 0.723961, -1.019453, -0.120017, -0.238683, 0.01473, 0.103516, 0.194635, 0.583779, -0.424552, 1.085939, -0.140284, -0.555245, -0.498225, 0.583986, 0.854594, 0.262349, 0.046192, 0.038473, -1.506578, 0.589539, 1.399976, -0.386523, -0.09941, -0.853684, -1.620674, -0.349424, -0.454413, -0.376124, 0.332322, -0.188488, -0.035463, 0.327758, 0.019517, -0.989312, -1.57747, -0.823874, -0.312926, -3.145866, -0.383957, -0.606785, 1.162326, -0.877009, 0.106636, 0.214042, -0.208828, -0.194515, 0.068831, -1.572822, 0.147811, -0.992475, -0.071296, -0.012764, -2.830585, 0.036117, -1.009639, 0.491355, -0.444284, -2.326566, -0.374493, 0.549372, -0.740497, 0.10487, 0.200247, 0.292028, -0.64695, -0.469845, -0.524377, 0.4226, -1.233203, 0.66752, -0.541487, 0.248278, 1.262175, 1.267791, 1.154635, 0.92361, -0.790293, 0.017091, -0.043057, -0.09928, -0.709397, 0.18662, 0.95313, -1.952693, -1.134062, -0.775267, 3.20907, -0.60743, -0.867368, 0.146218, 0.051078, 0.929345, 0.615099, -0.41044, -0.272232, 0.988985, 0.2564, -0.442726, 0.079812, -0.393583, -1.545968, -0.581727, -0.410902, -0.504696, -2.194254, -0.360455, 0.565416, 1.207165, 1.624056, -2.065257, -1.646325, 0.620913, -0.46637, 0.706461, 1.921391, 0.266328, -0.722358, -0.364499, 0.987386, 0.277402, -0.721404, 0.274906, 0.147993, -0.501168, 0.58819, -0.447835, 0.251256, 0.071729, -1.148746, -0.561568, -0.733153, 0.030192, -0.195828, 0.500484, -0.711628, 1.243515, 0.175501, -1.256605, 0.436452, 0.037127, 2.651873, 1.133981, 1.249792, -0.727471, -0.767065, -2.891992, -1.24288, 0.190545, 0.867464, 0.820024, 0.778091, -0.700256, 1.75552, -0.062699, 0.713774, -0.362826, -0.480265, 0.427991, 0.593384, -0.819759, -0.856699, -0.982381, -2.397991, -0.098963, 0.660529, 0.741578, 0.116534, -0.72362, 0.037989, -0.659128, -0.44462, -0.164274, 0.49036, 0.18256, -0.349234, 1.122705, -0.176817, 0.483003, 1.155507, -0.631125, -0.003319, 0.086963, -0.879137, -0.113547, -1.013998, 0.22842, 1.121967, -0.753846, -1.978561]}, "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; uint256 anchorMean;\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            anchorMean = runMean;\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        {\n            int256[13] memory f;\n            f[0] = int256(sigmaHat); f[1] = int256(lambdaHat); f[2] = int256(sizeHat); f[3] = int256(toxEma);\n            f[4] = int256(actEma); f[5] = int256(dirState);\n            { uint256 sh = wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000); f[6] = _sgn(spot, sh); }\n            f[7] = trade.isBuy ? int256(tradeRatio) : -int256(tradeRatio);\n            f[8] = int256(arbProbability); f[9] = firstInStep ? int256(WAD) : int256(0);\n            f[10] = int256(uncertainty); f[11] = int256((silent > 8 ? 8 : silent) * WAD / 8); f[12] = int256(anchorMean);\n            (int256 hb, int256 ha) = _head(f);\n            bidFee = _addFee(bidFee, hb); askFee = _addFee(askFee, ha);\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 _head(int256[13] memory f) internal pure returns (int256, int256) {\n        int256 x0 = ((f[0] - (3916000000000000)) * 1000000000000000000) / 1361000000000000;\n        if (x0 > 4000000000000000000) x0 = 4000000000000000000; else if (x0 < -4000000000000000000) x0 = -4000000000000000000;\n        int256 x1 = ((f[1] - (1125999999999999872)) * 1000000000000000000) / 60690000000000000;\n        if (x1 > 4000000000000000000) x1 = 4000000000000000000; else if (x1 < -4000000000000000000) x1 = -4000000000000000000;\n        int256 x2 = ((f[2] - (194200000000000)) * 1000000000000000000) / 372500000000000;\n        if (x2 > 4000000000000000000) x2 = 4000000000000000000; else if (x2 < -4000000000000000000) x2 = -4000000000000000000;\n        int256 x3 = ((f[3] - (4868000000000000)) * 1000000000000000000) / 5705000000000000;\n        if (x3 > 4000000000000000000) x3 = 4000000000000000000; else if (x3 < -4000000000000000000) x3 = -4000000000000000000;\n        int256 x4 = ((f[4] - (17820000000000)) * 1000000000000000000) / 34340000000000;\n        if (x4 > 4000000000000000000) x4 = 4000000000000000000; else if (x4 < -4000000000000000000) x4 = -4000000000000000000;\n        int256 x5 = ((f[5] - (1000000000000000000)) * 1000000000000000000) / 10130000000000000;\n        if (x5 > 4000000000000000000) x5 = 4000000000000000000; else if (x5 < -4000000000000000000) x5 = -4000000000000000000;\n        int256 x6 = ((f[6] - (97890000000000)) * 1000000000000000000) / 7865000000000000;\n        if (x6 > 4000000000000000000) x6 = 4000000000000000000; else if (x6 < -4000000000000000000) x6 = -4000000000000000000;\n        int256 x7 = ((f[7] - (-738700000000)) * 1000000000000000000) / 1843000000000000;\n        if (x7 > 4000000000000000000) x7 = 4000000000000000000; else if (x7 < -4000000000000000000) x7 = -4000000000000000000;\n        int256 x8 = ((f[8] - (355700000000000000)) * 1000000000000000000) / 340200000000000000;\n        if (x8 > 4000000000000000000) x8 = 4000000000000000000; else if (x8 < -4000000000000000000) x8 = -4000000000000000000;\n        int256 x9 = ((f[9] - (660700000000000000)) * 1000000000000000000) / 473500000000000000;\n        if (x9 > 4000000000000000000) x9 = 4000000000000000000; else if (x9 < -4000000000000000000) x9 = -4000000000000000000;\n        int256 x10 = ((f[10] - (2893000000000)) * 1000000000000000000) / 2453000000000;\n        if (x10 > 4000000000000000000) x10 = 4000000000000000000; else if (x10 < -4000000000000000000) x10 = -4000000000000000000;\n        int256 x11 = ((f[11] - (122800000000000000)) * 1000000000000000000) / 137400000000000000;\n        if (x11 > 4000000000000000000) x11 = 4000000000000000000; else if (x11 < -4000000000000000000) x11 = -4000000000000000000;\n        int256 x12 = ((f[12] - (4855000000000000)) * 1000000000000000000) / 721400000000000;\n        if (x12 > 4000000000000000000) x12 = 4000000000000000000; else if (x12 < -4000000000000000000) x12 = -4000000000000000000;\n        int256 o0; int256 o1; int256 z;\n        z = ((-386523)*x0 + (-99410)*x1 + (-853684)*x2 + (-1620674)*x3 + (-349424)*x4 + (-454413)*x5 + (-376124)*x6 + 332322*x7 + (-188488)*x8 + (-35463)*x9 + 327758*x10 + 19517*x11 + (-989312)*x12) / 1000000 + (-62699)*1000000000000;\n        if (z > 0) { if (z > 4000000000000000000) z = 4000000000000000000; o0 += 741578*z; o1 += 483003*z; }\n        z = ((-1577470)*x0 + (-823874)*x1 + (-312926)*x2 + (-3145866)*x3 + (-383957)*x4 + (-606785)*x5 + 1162326*x6 + (-877009)*x7 + 106636*x8 + 214042*x9 + (-208828)*x10 + (-194515)*x11 + 68831*x12) / 1000000 + 713774*1000000000000;\n        if (z > 0) { if (z > 4000000000000000000) z = 4000000000000000000; o0 += 116534*z; o1 += 1155507*z; }\n        z = ((-1572822)*x0 + 147811*x1 + (-992475)*x2 + (-71296)*x3 + (-12764)*x4 + (-2830585)*x5 + 36117*x6 + (-1009639)*x7 + 491355*x8 + (-444284)*x9 + (-2326566)*x10 + (-374493)*x11 + 549372*x12) / 1000000 + (-362826)*1000000000000;\n        if (z > 0) { if (z > 4000000000000000000) z = 4000000000000000000; o0 += (-723620)*z; o1 += (-631125)*z; }\n        z = (3209070*x0 + (-607430)*x1 + (-867368)*x2 + 146218*x3 + 51078*x4 + 929345*x5 + 615099*x6 + (-410440)*x7 + (-272232)*x8 + 988985*x9 + 256400*x10 + (-442726)*x11 + 79812*x12) / 1000000 + 593384*1000000000000;\n        if (z > 0) { if (z > 4000000000000000000) z = 4000000000000000000; o0 += (-444620)*z; o1 += (-879137)*z; }\n        z = ((-466370)*x0 + 706461*x1 + 1921391*x2 + 266328*x3 + (-722358)*x4 + (-364499)*x5 + 987386*x6 + 277402*x7 + (-721404)*x8 + 274906*x9 + 147993*x10 + (-501168)*x11 + 588190*x12) / 1000000 + (-856699)*1000000000000;\n        if (z > 0) { if (z > 4000000000000000000) z = 4000000000000000000; o0 += 490360*z; o1 += (-1013998)*z; }\n        z = (436452*x0 + 37127*x1 + 2651873*x2 + 1133981*x3 + 1249792*x4 + (-727471)*x5 + (-767065)*x6 + (-2891992)*x7 + (-1242880)*x8 + 190545*x9 + 867464*x10 + 820024*x11 + 778091*x12) / 1000000 + (-2397991)*1000000000000;\n        if (z > 0) { if (z > 4000000000000000000) z = 4000000000000000000; o0 += (-349234)*z; o1 += 1121967*z; }\n        o0 = (o0 / 1000000 + (-753846)*1000000000000) / 10000;\n        o1 = (o1 / 1000000 + (-1978561)*1000000000000) / 10000;\n        return (o0, o1);\n    }\n\n    function _addFee(uint256 fee, int256 d) internal pure returns (uint256) {\n        int256 v = int256(fee) + d;\n        if (v <= 0) return 0;\n        if (uint256(v) > MAX_FEE) return MAX_FEE;\n        return uint256(v);\n    }\n    function _sgn(uint256 a, uint256 b) internal pure returns (int256) {\n        return (int256(a) - int256(b)) * 1000000000000000000 / int256(b);\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_head\"; }\n}\n", "sha256": "fab2b1966e8cd76d92608948c77285a8546335731901fbb3e9ebd36dbd274b22", "real": {"n": 512, "mean_diff": 0.7134519268025974, "se": 0.03127961932081569, "worst5": [{"seed": 6030029, "d": -2.1307808054459656}, {"seed": 6030100, "d": -1.8708317542262307}, {"seed": 6030284, "d": -1.7089025592239295}, {"seed": 6030407, "d": -1.5585339284058364}, {"seed": 6030127, "d": -1.2573358314077723}], "retail_delta": {"mean": 3.1343093453696804, "se": 0.03693426349749485}, "arb_delta": {"mean": -2.4208574185670817, "se": 0.02132550132375069}, "cand_mean": 522.5473787368317, "T_mean": 521.8339268100292}, "gas": {"max_ok": 245690, "init_max_ok": 243121, "oog": 0, "afterSwap_limit_check": "FAILS: afterSwap peak 245690 > 245000 (limit 250000, 0 OOG). Candidate violates the brief gas rule and should NOT be submitted as is; fix needs about 700+ gas saved and a re-run.", "T_afterSwap_max_ok": 225592}, "minutes": {"search": 33.4, "real": 12.0}, "notes": ["Replica says +0.75..+0.82 over T-port; real engine says +0.713 +/- 0.031 (n=512, seeds 6030000..6030511) for the 6-unit frozen candidate, so the replica overstated it by about 0.04.", "First, 12-unit frozen candidate (Gate C passed at 7.8e-10 bps) was run on the real engine first: +0.793 +/- 0.033 but 62 afterSwap OOG calls, peak 240186 among ok calls; INVALID. Per the brief it was cut to the 6 units with the largest |W2|, no re-search or fine-tune (time). This is a disclosed second real run on the same 512 seeds; the numbers above are the 6-unit run.", "Search ran 137 generations (limit about 45 min; stopped at 33.4 min to leave time for freeze and real). Monitor-best was generation 90.", "CH check passed: seeds 0..999 mean edge 525.5258821780834.", "Real run was done in 64-seed chunks, order kept; two attempts were killed by a wrapper timeout mid-chunk and the partial chunk redone from scratch (state saved per completed chunk).", "Features have heavy tails and are clipped to +/-4; normalisation constants from 48 T-port markets (seeds 23999000..23999047)."]}