{"item": "e04-band-transport/a retail displacement control", "blocked": null, "seeds_kind": "tuning", "board_claim": 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    int256 constant RD_T1 = 0;\n    int256 constant RD_T2 = 0;\n    int256 constant RD_W = -26176559775005564;\n    int256 constant RD_WR = 0;\n    int256 constant RD_WC = 4536284430155866;\n    int256 constant RD_RHO = 0;\n    int256 constant RD_CAP = 10000000000000000;\n    uint256 constant SIGNAL_THRESHOLD = WAD / 650;\n    uint256 constant DIR_DECAY = 750000000000000000;\n    uint256 constant ACT_DECAY = 530000000000000000;\n    uint256 constant SIZE_DECAY = 530000000000000000;\n    uint256 constant TOX_DECAY = 910000000000000000;\n    uint256 constant SIGMA_DECAY = 690000000000000000;\n    uint256 constant LAMBDA_DECAY = 990000000000000000;\n    uint256 constant SIZE_BLEND_DECAY = 828000000000000000;\n    uint256 constant TOX_BLEND_DECAY = 51000000000000000;\n    uint256 constant ACT_BLEND_DECAY = 985000000000000000;\n    uint256 constant PHAT_ALPHA = 270000000000000000;\n    uint256 constant PHAT_ALPHA_RETAIL = 60000000000000000;\n    uint256 constant PHAT_ALPHA_SAME = 120000000000000000;\n    uint256 constant REVERT_U = 0;\n    uint256 constant DIR_IMPACT_MULT = 4;\n    uint256 constant GATE_SIGMA_MULT = 7200000000000000000;\n    uint256 constant MIN_GATE = 30000000000000000;\n    uint256 constant TRADE_TOX_BOOST = 3500 * BPS;\n    uint256 constant STALE_ATTRACT_FRAC = 1050000000000000000;\n    uint256 constant RET_CAP = WAD / 35;\n    uint256 constant TOX_CAP = WAD / 5;\n    uint256 constant TRADE_RATIO_CAP = WAD / 5;\n    uint256 constant LAMBDA_CAP = 1820000000000000000;\n    uint256 constant STEP_COUNT_CAP = 64;\n    uint256 constant BASE_FEE = 4 * BPS;\n    uint256 constant SIGMA_COEF = 200000000000000000;\n    uint256 constant LAMBDA_COEF = 12 * BPS;\n    uint256 constant FLOW_SIZE_COEF = 4842 * BPS;\n    uint256 constant TOX_COEF = 300 * BPS;\n    uint256 constant TOX_QUAD_COEF = 15000 * BPS;\n    uint256 constant ACT_COEF = 91843 * BPS;\n    uint256 constant DIR_COEF = 20 * BPS;\n    uint256 constant DIR_TOX_COEF = 100 * BPS;\n    uint256 constant STALE_DIR_COEF = 6850 * BPS;\n    uint256 constant SIGMA_TOX_COEF = 500 * BPS;\n    uint256 constant TAIL_KNEE = 600 * BPS;\n    uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000;\n    uint256 constant TAIL_SLOPE_ATTRACT = 850000000000000000;\n\n    function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) {\n        slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[3] = WAD; \n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n        slots[13] = 902500000000; slots[14] = slots[5]; \n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 prevBidFee = slots[0]; uint256 prevAskFee = slots[1]; uint256 lastTs = uint64(slots[2]);\n        uint256 dirState = slots[3]; uint256 actEma = slots[4]; uint256 pHat = slots[5];\n        uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8];\n        uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10];\n\n        uint256 sigmaForFast = sigmaHat;\n        uint256 fastHat = slots[14];\n        uint256 uncertainty = slots[13];\n        uint256 silent = trade.timestamp > lastTs ? trade.timestamp - lastTs : 0;\n        bool isNewStep = trade.timestamp > lastTs;\n        if (isNewStep) {\n            uint256 elapsedRaw = trade.timestamp - lastTs;\n            uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw;\n            dirState = _decayCentered(dirState, DIR_DECAY, elapsed);\n            actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed));\n            sizeHat = wmul(sizeHat, _powWad(SIZE_DECAY, elapsed));\n            toxEma = wmul(toxEma, _powWad(TOX_DECAY, elapsed));\n            if (stepTradeCount > 0 && elapsedRaw > 0) {\n                uint256 lambdaInst = (stepTradeCount * WAD) / elapsedRaw;\n                if (lambdaInst > LAMBDA_CAP) lambdaInst = LAMBDA_CAP;\n                lambdaHat = wmul(lambdaHat, LAMBDA_DECAY) + wmul(lambdaInst, WAD - LAMBDA_DECAY);\n            }\n            // Process variance is propagated inside the censored update.\n            if (uncertainty > 100000000000000) uncertainty = 100000000000000;\n            stepTradeCount = 0;\n        }\n\n        bool firstInStep = stepTradeCount == 0;\n        uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat;\n        if (pHat == 0) pHat = spot;\n\n        uint256 feeUsed = trade.isBuy ? prevBidFee : prevAskFee;\n        uint256 gamma = feeUsed < WAD ? WAD - feeUsed : 0;\n        uint256 pImplied;\n        if (gamma == 0) { pImplied = spot; }\n        else { pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma); }\n\n        // S: infer a no-trade interval center from the last post-trade spot.\n        uint256 silenceScale = WAD;\n        if (firstInStep && silent > 1) {\n            uint256 g = silent - 1;\n            if (g > 1) g = 1;\n            uint256 w = WAD - _powWad(800000000000000000, g);\n            uint256 s = slots[2] >> 64;\n            if (s == 0) s = pHat;\n            uint256 c = (wmul(s, WAD - prevBidFee) + wdiv(s, WAD - prevAskFee)) / 2;\n            if (c >= pHat) pHat += wmul(w, c - pHat);\n            else pHat -= wmul(w, pHat - c);\n            silenceScale = WAD - wmul(300000000000000000, w);\n        }\n\n        {\n            uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0;\n            uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL;\n            uint256 prePhat = pHat;\n            bool secondPrint = !firstInStep && stepTradeCount == 1;\n            bool sameDir = false; bool oppDir = false;\n            if (secondPrint) {\n                bool up2 = pImplied >= pHat;\n                uint256 d1 = slots[12];\n                if (d1 != 0) { sameDir = (d1 == 1) == up2; oppDir = !sameDir; }\n                if (sameDir) alpha = PHAT_ALPHA_SAME;\n            }\n            if (firstInStep) { slots[12] = pImplied >= pHat ? 1 : 2; }\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            alpha = wmul(alpha, silenceScale);\n            adaptiveGate = wmul(adaptiveGate, silenceScale);\n            if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); }\n            if (oppDir && REVERT_U > 0) {\n                uint256 pre = slots[11];\n                if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U);\n                else pHat = pHat - wmul(pHat - pre, REVERT_U);\n            }\n            if (firstInStep) {\n                if (ret > RET_CAP) ret = RET_CAP;\n                sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY);\n            }\n        }\n\n        // Interior retail routing equalizes fee-adjusted marginal prices.\n        // Subsequent trades in a step cannot be the initial arbitrage trade.\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalSpot = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            pHat = wmul(pHat, 90 * WAD / 100) + wmul(normalSpot, 10 * WAD / 100);\n        }\n\n        // Censored assumed-density posterior. No external or future inputs.\n        (fastHat, uncertainty) = _posterior(PosteriorInput(\n            fastHat, uncertainty, pImplied, spot, slots[2] >> 64,\n            prevBidFee, prevAskFee, firstInStep, silent, trade.isBuy,\n            trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0\n        ));\n        slots[13] = uncertainty;\n        slots[14] = fastHat;\n        uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n        if (tradeRatio > TRADE_RATIO_CAP) tradeRatio = TRADE_RATIO_CAP;\n\n        if (tradeRatio > SIGNAL_THRESHOLD) {\n            uint256 push = tradeRatio * DIR_IMPACT_MULT;\n            if (push > WAD / 4) push = WAD / 4;\n            if (trade.isBuy) {\n                dirState = dirState + push;\n                if (dirState > 2 * WAD) dirState = 2 * WAD;\n            } else {\n                dirState = dirState > push ? dirState - push : 0;\n            }\n            actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY);\n            sizeHat = wmul(sizeHat, SIZE_BLEND_DECAY) + wmul(tradeRatio, WAD - SIZE_BLEND_DECAY);\n            if (sizeHat > WAD) sizeHat = WAD;\n        }\n\n        uint256 tox = pHat > 0 ? wdiv(absDiff(spot, pHat), pHat) : 0;\n        if (tox > TOX_CAP) tox = TOX_CAP;\n        toxEma = wmul(toxEma, TOX_BLEND_DECAY) + wmul(tox, WAD - TOX_BLEND_DECAY);\n        uint256 toxSignal = toxEma;\n\n        stepTradeCount = stepTradeCount + 1;\n        if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP;\n\n        uint256 flowSize = wmul(lambdaHat, sizeHat);\n        uint256 fBase = BASE_FEE + wmul(SIGMA_COEF, sigmaHat) + wmul(LAMBDA_COEF, lambdaHat) + wmul(FLOW_SIZE_COEF, flowSize);\n        uint256 fMid = fBase + wmul(TOX_COEF, toxSignal) + wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal)) + wmul(ACT_COEF, actEma);\n        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal));\n\n        uint256 dirDev; bool sellPressure;\n        if (dirState >= WAD) { dirDev = dirState - WAD; sellPressure = true; }\n        else { dirDev = WAD - dirState; sellPressure = false; }\n\n        uint256 skew = wmul(DIR_COEF, dirDev) + wmul(DIR_TOX_COEF, wmul(dirDev, toxSignal));\n        uint256 bidFee; uint256 askFee;\n        if (sellPressure) {\n            bidFee = fMid + skew;\n            askFee = fMid > skew ? fMid - skew : 0;\n        } else {\n            askFee = fMid + skew;\n            bidFee = fMid > skew ? fMid - skew : 0;\n        }\n\n        {\n            uint256 staleHat = wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000);\n            uint256 staleTox = wdiv(absDiff(spot, staleHat), staleHat);\n            if (staleTox > TOX_CAP) staleTox = TOX_CAP;\n            uint256 staleShift = wmul(STALE_DIR_COEF, staleTox);\n            uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC);\n            if (spot >= staleHat) {\n                bidFee = bidFee + staleShift;\n                askFee = askFee > attractShift ? askFee - attractShift : 0;\n            } else {\n                askFee = askFee + staleShift;\n                bidFee = bidFee > attractShift ? bidFee - attractShift : 0;\n            }\n        }\n\n        {\n            bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat);\n            if (tradeAligned) {\n                uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\n                if (!firstInStep && tradeBoost > 16 * BPS) tradeBoost = 16 * BPS;\n                if (trade.isBuy) { bidFee = bidFee + tradeBoost; }\n                else { askFee = askFee + tradeBoost; }\n            }\n        }\n\n        if (sellPressure) {\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_PROTECT));\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_ATTRACT));\n        } else {\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_PROTECT));\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_ATTRACT));\n        }\n\n        if (firstInStep) {\n            if (askFee > bidFee && bidFee > 30 * BPS) bidFee = 30 * BPS;\n            else if (bidFee > askFee && askFee > 30 * BPS) askFee = 30 * BPS;\n        }\n\n        if (bidFee > askFee && askFee > 36 * BPS) askFee = 36 * BPS;\n        else if (askFee > bidFee && bidFee > 36 * BPS) bidFee = 36 * BPS;\n\n        (bidFee, askFee) = _steer(bidFee, askFee, spot, firstInStep);\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 returns (uint256, uint256) {\n        if (x.mu == 0) x.mu = x.spot;\n        if (x.v < 10000000000) x.v = 10000000000;\n        uint256 lo = wmul(x.preSpot, WAD-x.bid);\n        uint256 hi = wdiv(x.preSpot, WAD-x.ask);\n        if (x.first) {\n            if (x.silent>1 && x.preSpot>0) {\n                uint256 elapsed=x.silent>8?8:x.silent;\n                x.v += 902500000000*(elapsed-1);\n                (x.mu,x.v)=_band(x.mu,x.v,lo,hi);\n            }\n            x.v+=902500000000;\n        }\n        uint256 mRetail = x.mu;\n        uint256 vRetail = x.v;\n        // A missing own-pool trade is a censored price observation.\n        if (x.first && x.preSpot > 0) {\n            (mRetail, vRetail) = _band(x.mu, x.v, lo, hi);\n        }\n        if (!x.first) {\n            // A later print is retail. Only an interior route is an observation\n            // of the other pool, with explicit observation uncertainty.\n            uint256 fee = x.buy ? x.bid : x.ask;\n            if (fee > 30 * BPS) {\n                uint256 normal = x.buy ? wdiv(wmul(x.spot, WAD-fee), WAD-30*BPS)\n                    : wdiv(wmul(x.spot, WAD-30*BPS), WAD-fee);\n                uint256 residual = wdiv(absDiff(normal, x.mu),x.mu);\n                uint256 noise = 9000000000000 + wmul(residual,residual);\n                uint256 k = wdiv(x.v,x.v+noise);\n                return (_blend(x.mu,normal,k),wmul(x.v,WAD-k));\n            }\n            return (x.mu,x.v);\n        }\n        uint256 e = wdiv(absDiff(x.obs,x.mu),x.mu);\n        uint256 totalV = x.v + 22500000000;\n        uint256 z = wdiv(wmul(e,e),totalV);\n        uint256 density = _powWad(wdiv(WAD,WAD+z/8),4);\n        uint256 odds = wmul(density,wdiv(4000000000000000,_isqrt(totalV*WAD)));\n        if (x.size > 3000000000000000) odds = wmul(odds,4*WAD/10);\n        if (x.silent > 1) odds = wmul(odds,8*WAD/10);\n        uint256 sd = _isqrt(x.v*WAD);\n        uint256 width = wdiv(hi-lo,x.mu);\n        uint256 distance = x.mu<lo?lo-x.mu:(x.mu>hi?x.mu-hi:0);\n        uint256 zBand = wdiv(wdiv(distance,x.mu),sd);\n        uint256 mass = wmul(wdiv(width,width+2*sd),wdiv(WAD,WAD+wmul(zBand,zBand)));\n        if (mass < WAD/100) mass = WAD/100;\n        odds = wdiv(odds,mass);\n        uint256 prob = wdiv(odds,WAD+odds);\n        slots[16] = prob;\n        uint256 kArb = wdiv(x.v,totalV);\n        uint256 mArb = _blend(x.mu,x.obs,kArb);\n        uint256 mean = _blend(mRetail,mArb,prob);\n        uint256 between = wdiv(absDiff(mArb,mRetail),x.mu);\n        uint256 variance = wmul(prob,wmul(x.v,WAD-kArb)) + wmul(WAD-prob,vRetail)\n            + wmul(wmul(prob,WAD-prob),wmul(between,between));\n        if (variance > 100000000000000) variance = 100000000000000;\n        return (mean,variance);\n    }\n    // Retail displacement band steering. d = signed spot move since step opening that is\n    // attributed to retail: later prints certain, first print weighted by (1 - posterior arb prob).\n    function _steer(uint256 bid, uint256 ask, uint256 spot, bool first) internal returns (uint256, uint256) {\n        uint256 s0; int256 a; int256 carry;\n        if (first) {\n            s0 = slots[2] >> 64;\n            a = s0 > 0 ? (int256(slots[16]) * (int256(spot) - int256(s0))) / int256(s0) : int256(0);\n            slots[16] = (s0 << 128) | uint256(uint128(int128(a)));\n            if (RD_RHO != 0) carry = (RD_RHO * int256(int128(uint128(slots[17] >> 128)))) / int256(WAD);\n        } else {\n            uint256 st = slots[16]; s0 = st >> 128; a = int256(int128(uint128(st)));\n            if (RD_RHO != 0) carry = int256(int128(uint128(slots[17])));\n        }\n        if (s0 == 0) return (bid, ask);\n        int256 d = ((int256(spot) - int256(s0)) * int256(WAD)) / int256(s0) - a + carry;\n        if (RD_RHO != 0) slots[17] = (uint256(uint128(int128(d))) << 128) | uint256(uint128(int128(carry)));\n        int256 ad = d >= 0 ? d : -d;\n        int256 tr = (RD_T1 * d + RD_T2 * ((d * ad) / 1e16)) / int256(WAD);\n        int256 wd = (RD_W * ad) / int256(WAD);\n        int256 sL = tr - wd; int256 sU = tr + wd;\n        int256 r = (RD_WR * ad) / int256(WAD); int256 c = (RD_WC * ad) / int256(WAD);\n        if (d > 0) { sL += r; sU += c; } else { sU -= r; sL -= c; }\n        if (sL > RD_CAP) sL = RD_CAP; if (sL < -RD_CAP) sL = -RD_CAP;\n        if (sU > RD_CAP) sU = RD_CAP; if (sU < -RD_CAP) sU = -RD_CAP;\n        if (sL == 0 && sU == 0) return (bid, ask);\n        // Invert L' = spot(1-bid)(1+sL), U' = spot/(1-ask)*(1+sU) back to fees.\n        int256 nb = int256(bid) - (sL * (int256(WAD) - int256(bid))) / int256(WAD);\n        int256 na = int256(WAD) - ((int256(WAD) - int256(ask)) * int256(WAD)) / (int256(WAD) + sU);\n        return (clampFee(nb > 0 ? uint256(nb) : 0), clampFee(na > 0 ? uint256(na) : 0));\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 \"rd_steer\"; }\n}\n", "sha256": "51b8a9260dcda83a26014c6c028919cccc7ce9dcad9a15079882d0f0dbb3817e", "base": {"name": "V10", "sha256": "cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245", "source": "https://api.imdnotdead.fun/artifacts/33f54e81f3372088e9eced52c0174f310ac348af98ef5727b73785c088679194 (code sha256 verified)"}, "params": {"W": -0.026176559775005565, "WC": 0.004536284430155866, "T1": 0, "T2": 0, "WR": 0, "RHO": 0, "CAP": 0.01, "meaning": "sL=T1*d+T2*100*d|d|-W|d| (+WR|d| if d>0 else -WC|d|), sU=T1*d+T2*100*d|d|+W|d| (+WC|d| if d>0 else -WR|d|); both clamped to +-CAP; L'=spot(1-bid)(1+sL), U'=spot/(1-ask)(1+sU); bid'=bid-sL(1-bid), ask'=1-(1-ask)/(1+sU), clampFee. Frozen arm: W<0 narrows both endpoints toward spot by 2.6% of |d|, WC>0 pushes continuation side out by 0.45% of |d|."}, "mechanism": "d = signed spot change since step opening (s0 = last post-trade spot of prior step) attributed to retail: first print weighted by (1 - posterior arb probability that V10 _posterior already computes, now stored in slot 16), later prints counted fully; optional carry RHO*d_prev across steps (slot 17). Applied after all V10 fee logic; stored fees are the steered ones so V10 implied-price/posterior updates see the actual fees. Zero intervention returns V10 fees exactly (checked: max |edge diff| 0.0 on seeds 680000..680019). Causal: only trade, reserves, timestamp and own state.", "structures_compared": {"S1_translation": ["T1", "T2"], "S2_width": ["W", "WC"], "S3_coupled_feedback": ["T1", "WR", "WC", "RHO"]}, "harness_source": "import json,time,sys,hashlib\nfrom pathlib import Path\nimport numpy as np\nimport amm_sim_rs as sim\nfrom amm_competition.evm.compiler import SolidityCompiler\nC=SolidityCompiler()\nVAN=C.compile(Path('contracts/src/VanillaStrategy.sol').read_text(),'VanillaStrategy');assert VAN.success\ndef configs(start,n):\n    out=[]\n    for seed in range(start,start+n):\n        rng=np.random.default_rng(seed)\n        size=rng.uniform(19.,21.);rate=rng.uniform(.6,1.);sigma=rng.uniform(.000882,.001008)\n        out.append(sim.SimulationConfig(n_steps=10000,initial_price=100.,initial_x=100.,initial_y=10000.,gbm_mu=0.,gbm_sigma=sigma,gbm_dt=1.,retail_arrival_rate=rate,retail_mean_size=size,retail_size_sigma=1.2,retail_buy_prob=.5,seed=seed))\n    return out\ndef decomposition(r,initial_fee=.0004):\n    steps=r.steps\n    fair=np.array([s.fair_price for s in steps])\n    spots=np.array([r.initial_fair_price]+[s.spot_prices['submission'] for s in steps[:-1]])\n    bids=np.array([initial_fee]+[s.fees['submission'][0] for s in steps[:-1]])\n    asks=np.array([initial_fee]+[s.fees['submission'][1] for s in steps[:-1]])\n    x0,y0=r.initial_reserves['submission'];k=x0*y0\n    x=np.sqrt(k/spots);y=np.sqrt(k*spots)\n    ga=1-asks;gb=1-bids\n    out=np.minimum(np.maximum(x-np.sqrt(k/(ga*fair)),0),.99*x)\n    paid=(k/(x-out)-y)/ga\n    buyprofit=np.where(out>0,np.maximum(out*fair-paid,0),0)\n    gross=np.maximum((np.sqrt(k*gb/fair)-x)/gb,0)\n    received=y-k/(x+gb*gross)\n    sellprofit=np.where(gross>0,np.maximum(received-gross*fair,0),0)\n    arb=-float(np.sum(np.where(spots<fair,buyprofit,sellprofit)))\n    return arb,r.edges['submission']-arb\nERR=['oog','revert','other_halt','tx_error','bad_return']\ndef run(source,seeds,decomp=False):\n    comp=C.compile(source);assert comp.success,comp.errors\n    rows={};chunks=[]\n    seeds=list(seeds)\n    for i in range(0,len(seeds),20):\n        ss=seeds[i:i+20]\n        cf=[c for s in ss for c in configs(s,1)]\n        sim.gas_stats_reset()\n        b=sim.run_batch(list(comp.bytecode),list(VAN.bytecode),cf,8)\n        for r in b.results:\n            e=r.edges['submission']\n            if decomp: a,rt=decomposition(r); rows[r.seed]=(e,a,rt)\n            else: rows[r.seed]=(e,)\n        chunks.append(sim.gas_stats()); del b\n    assert sorted(rows)==sorted(seeds)\n    sw=[x for ch in chunks for x in ch if x['role']!='Baseline' and x['callback']=='afterSwap']\n    gas={'afterSwap_max_ok':max(x['max_ok_gas'] for x in sw),\n         'init_max_ok':max(x['max_ok_gas'] for ch in chunks for x in ch if x['role']!='Baseline' and x['callback']=='afterInitialize'),\n         'halts':{e:sum(x.get(e,0) for ch in chunks for x in ch) for e in ERR}}\n    return {'sha256':hashlib.sha256(source.encode()).hexdigest(),'rows':rows,'gas':gas,'chunks':chunks}\n", "generator_source": "\"\"\"Generate a retail-displacement band-steering variant of V10 (sha cd9bdb45...).\nParams (WAD-scaled ints in source): T1,T2 translation; W width; WR,WC sign-aware side gains; RHO carry; CAP shift cap.\"\"\"\nfrom pathlib import Path\nimport hashlib\nV10=Path(__file__).with_name('V10.sol').read_text()\nassert hashlib.sha256(V10.encode()).hexdigest()=='cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245'\nNAMES=['T1','T2','W','WR','WC','RHO','CAP']\nDEFAULT_CAP=0.01\nSTEER='''\n    // Retail displacement band steering. d = signed spot move since step opening that is\n    // attributed to retail: later prints certain, first print weighted by (1 - posterior arb prob).\n    function _steer(uint256 bid, uint256 ask, uint256 spot, bool first) internal returns (uint256, uint256) {\n        uint256 s0; int256 a; int256 carry;\n        if (first) {\n            s0 = slots[2] >> 64;\n            a = s0 > 0 ? (int256(slots[16]) * (int256(spot) - int256(s0))) / int256(s0) : int256(0);\n            slots[16] = (s0 << 128) | uint256(uint128(int128(a)));\n            if (RD_RHO != 0) carry = (RD_RHO * int256(int128(uint128(slots[17] >> 128)))) / int256(WAD);\n        } else {\n            uint256 st = slots[16]; s0 = st >> 128; a = int256(int128(uint128(st)));\n            if (RD_RHO != 0) carry = int256(int128(uint128(slots[17])));\n        }\n        if (s0 == 0) return (bid, ask);\n        int256 d = ((int256(spot) - int256(s0)) * int256(WAD)) / int256(s0) - a + carry;\n        if (RD_RHO != 0) slots[17] = (uint256(uint128(int128(d))) << 128) | uint256(uint128(int128(carry)));\n        int256 ad = d >= 0 ? d : -d;\n        int256 tr = (RD_T1 * d + RD_T2 * ((d * ad) / 1e16)) / int256(WAD);\n        int256 wd = (RD_W * ad) / int256(WAD);\n        int256 sL = tr - wd; int256 sU = tr + wd;\n        int256 r = (RD_WR * ad) / int256(WAD); int256 c = (RD_WC * ad) / int256(WAD);\n        if (d > 0) { sL += r; sU += c; } else { sU -= r; sL -= c; }\n        if (sL > RD_CAP) sL = RD_CAP; if (sL < -RD_CAP) sL = -RD_CAP;\n        if (sU > RD_CAP) sU = RD_CAP; if (sU < -RD_CAP) sU = -RD_CAP;\n        if (sL == 0 && sU == 0) return (bid, ask);\n        // Invert L' = spot(1-bid)(1+sL), U' = spot/(1-ask)*(1+sU) back to fees.\n        int256 nb = int256(bid) - (sL * (int256(WAD) - int256(bid))) / int256(WAD);\n        int256 na = int256(WAD) - ((int256(WAD) - int256(ask)) * int256(WAD)) / (int256(WAD) + sU);\n        return (clampFee(nb > 0 ? uint256(nb) : 0), clampFee(na > 0 ? uint256(na) : 0));\n    }\n'''\ndef gen(p):\n    s=V10\n    consts=''.join(f'    int256 constant RD_{n} = {int(round(p.get(n,DEFAULT_CAP if n==\"CAP\" else 0.0)*1e18))};\\n' for n in NAMES)\n    s=s.replace('    uint256 constant ELAPSED_CAP = 8;\\n','    uint256 constant ELAPSED_CAP = 8;\\n'+consts,1)\n    a='        slots[0] = bidFee; slots[1] = askFee; slots[2] = (spot << 64) | trade.timestamp;'\n    assert a in s\n    s=s.replace(a,'        (bidFee, askFee) = _steer(bidFee, askFee, spot, firstInStep);\\n'+a,1)\n    a='    function _posterior(PosteriorInput memory x) internal pure returns'\n    assert a in s; s=s.replace(a,'    function _posterior(PosteriorInput memory x) internal returns',1)\n    a='        uint256 prob = wdiv(odds,WAD+odds);\\n'\n    assert a in s; s=s.replace(a,a+'        slots[16] = prob;\\n',1)\n    a='    function _blend('\n    s=s.replace(a,STEER.lstrip('\\n')+a,1)\n    s=s.replace('return \"censored_10\";','return \"rd_steer\";')\n    return s\nif __name__=='__main__':\n    import sys,json\n    print(gen(json.loads(sys.argv[1]) if len(sys.argv)>1 else {}))\n", "search_source": "import sys,json,time,pickle,os\nsys.path.insert(0,'scratch');import h,gen\nimport numpy as np,cma\nfrom pathlib import Path\nST={'S1_translation':['T1','T2'],'S2_width':['W','WC'],'S3_coupled_feedback':['T1','WR','WC','RHO']}\nSCALE=0.03\nSP='scratch/cma_state.pkl';LOG='scratch/search_log.jsonl'\nV10=Path('scratch/V10.sol').read_text()\ndef block(g):  # rotating 32-seed CRN blocks inside 680000..683999\n    return list(range(680000+32*(g+1),680000+32*(g+1)+32))\nif os.path.exists(SP): st=pickle.load(open(SP,'rb'))\nelse:\n    st={'g':0,'es':{k:cma.CMAEvolutionStrategy([0.0]*len(v),1.0,{'seed':405,'popsize':6,'verbose':-9}) for k,v in ST.items()}}\ng=st['g'];seeds=block(g);t=time.time()\nbase=h.run(V10,seeds)\ndef log(o):\n    open(LOG,'a').write(json.dumps(o)+'\\n')\nlog({'gen':g,'arm':'V10','sha256':base['sha256'],'seeds':[seeds[0],seeds[-1]],'gas':base['gas']})\nfor k,names in ST.items():\n    es=st['es'][k];X=es.ask();F=[]\n    for x in X:\n        p={n:float(v)*SCALE for n,v in zip(names,x)}\n        src=gen.gen(p);r=h.run(src,seeds)\n        d=np.array([r['rows'][s][0]-base['rows'][s][0] for s in seeds])\n        bad=sum(r['gas']['halts'].values())>0\n        f=-(d.mean()) if not bad else 1e6\n        F.append(f)\n        log({'gen':g,'structure':k,'params':p,'sha256':r['sha256'],'seeds':[seeds[0],seeds[-1]],'mean_diff':float(d.mean()),'se':float(d.std(ddof=1)/np.sqrt(len(d))),'gas':r['gas']})\n        print(g,k,{a:round(b,4) for a,b in p.items()},round(d.mean(),4),r['gas']['afterSwap_max_ok'],flush=True)\n    es.tell(X,F)\nst['g']=g+1;pickle.dump(st,open(SP,'wb'))\nprint('gen',g,'secs',time.time()-t)\n", "eval_source": "import sys,json,time\nsys.path.insert(0,'scratch');import h,gen\nimport numpy as np\nfrom pathlib import Path\nstart,n,tag=int(sys.argv[1]),int(sys.argv[2]),sys.argv[3]\narms=json.loads(sys.argv[4])  # {name: params or \"V10\"}\nseeds=list(range(start,start+n));res={}\nfor name,p in arms.items():\n    src=Path('scratch/V10.sol').read_text() if p=='V10' else gen.gen(p)\n    t=time.time();r=h.run(src,seeds,decomp=True)\n    res[name]={'params':p,'sha256':r['sha256'],'gas':r['gas'],'rows':{str(k):v for k,v in r['rows'].items()},'secs':time.time()-t,'src':src}\n    print(name,r['sha256'],r['gas'],round(time.time()-t),flush=True)\njson.dump(res,open(f'scratch/eval_{tag}.json','w'))\nb=res['V10']['rows']\nfor name in res:\n    if name=='V10':continue\n    a=res[name]['rows'];d=np.array([a[s][0]-b[s][0] for s in b]);ar=np.array([a[s][1]-b[s][1] for s in b]);rt=np.array([a[s][2]-b[s][2] for s in b])\n    se=lambda x:float(x.std(ddof=1)/np.sqrt(len(x)))\n    print(name,'mean',d.mean(),'se',se(d),'arb',ar.mean(),se(ar),'retail',rt.mean(),se(rt),'recon',np.abs(d-ar-rt).max())\n", "harness_note": "configs and decomposition copied from V10 artifact harness_source; CH calibration (525.5258821780834 on seeds 0..999) not re-run here because the brief states it was already verified; zero-intervention identity checked instead.", "search_log": {"method": "cma (pycma 4.5.0) seed 405, popsize 6, sigma0 1.0 in scaled units, structures interleaved on a shared rotating 32-seed CRN block per generation; objective = mean paired edge diff vs V10 on that block; any halt -> rejected. First generation used scale 0.25 (block 680000..680031): every arm lost 1.8-63, roughly quadratic in step size, so CMA was restarted at scale 0.03 for 2 generations (blocks 680032..680063, 680064..680095). Stopped after ~15 min of search because gen-2 (second 0.03 gen) had no positive arm and the gen-1 positives (max +0.22, se 0.09) were within noise.", "evaluations": [{"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S1_translation", "params": {"T1": -0.26471, "T2": 0.24067}, "mean_diff": -15.3984, "se": 0.7938, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S1_translation", "params": {"T1": -0.14903, "T2": -0.20538}, "mean_diff": -23.7111, "se": 0.9636, "afterSwap_max": 200434, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S1_translation", "params": {"T1": -0.19751, "T2": 0.17067}, "mean_diff": -11.6425, "se": 0.6993, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S1_translation", "params": {"T1": 0.27577, "T2": 0.36444}, "mean_diff": -63.3142, "se": 2.0758, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S1_translation", "params": {"T1": -0.10877, "T2": 0.02411}, "mean_diff": -3.3379, "se": 0.5687, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S1_translation", "params": {"T1": -0.38189, "T2": -0.17099}, "mean_diff": -33.722, "se": 1.2711, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S2_width", "params": {"W": -0.224, "WC": -0.12571}, "mean_diff": -13.645, "se": 0.6287, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S2_width", "params": {"W": 0.20223, "WC": 0.05827}, "mean_diff": -19.1614, "se": 0.8153, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S2_width", "params": {"W": 0.22636, "WC": -0.20263}, "mean_diff": -12.6952, "se": 0.7353, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S2_width", "params": {"W": -0.21814, "WC": 0.0378}, "mean_diff": -11.5797, "se": 0.5671, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S2_width", "params": {"W": -0.09909, "WC": 0.17516}, "mean_diff": -3.783, "se": 0.6389, "afterSwap_max": 200257, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S2_width", "params": {"W": -0.07263, "WC": 0.09732}, "mean_diff": -1.8287, "se": 0.6297, "afterSwap_max": 195368, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S3_coupled_feedback", "params": {"T1": 0.39693, "WR": 0.09022, "WC": -0.09023, "RHO": -0.19647}, "mean_diff": -49.0313, "se": 1.5367, "afterSwap_max": 206919, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S3_coupled_feedback", "params": {"T1": -0.42484, "WR": -0.09428, "WC": 0.12203, "RHO": -0.27136}, "mean_diff": -33.7207, "se": 1.2492, "afterSwap_max": 203617, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S3_coupled_feedback", "params": {"T1": -0.12864, "WR": -0.22653, "WC": -0.07796, "RHO": 0.19718}, "mean_diff": -20.0633, "se": 0.9081, "afterSwap_max": 205647, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S3_coupled_feedback", "params": {"T1": 0.0257, "WR": -0.25262, "WC": 0.06312, "RHO": -0.17065}, "mean_diff": -14.6011, "se": 0.6966, "afterSwap_max": 206919, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S3_coupled_feedback", "params": {"T1": 0.16544, "WR": 0.08832, "WC": 0.04171, "RHO": 0.33636}, "mean_diff": -16.839, "se": 0.8165, "afterSwap_max": 206845, "oog": 0, "halts": 0}, {"phase": "cma_scale0.25", "gen": 0, "seeds": [680000, 680031], "structure": "S3_coupled_feedback", "params": {"T1": -0.28444, "WR": 0.39564, "WC": -0.02048, "RHO": 0.10487}, "mean_diff": -5.4232, "se": 0.6074, "afterSwap_max": 197545, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S1_translation", "params": {"T1": -0.03176, "T2": 0.02888}, "mean_diff": -1.3536, "se": 0.2872, "afterSwap_max": 184586, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S1_translation", "params": {"T1": -0.01788, "T2": -0.02465}, "mean_diff": -3.493, "se": 0.4015, "afterSwap_max": 184614, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S1_translation", "params": {"T1": -0.0237, "T2": 0.02048}, "mean_diff": -0.9008, "se": 0.248, "afterSwap_max": 184586, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S1_translation", "params": {"T1": 0.03309, "T2": 0.04373}, "mean_diff": -5.7603, "se": 0.4395, "afterSwap_max": 199061, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S1_translation", "params": {"T1": -0.01305, "T2": 0.00289}, "mean_diff": -0.2075, "se": 0.0691, "afterSwap_max": 184586, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S1_translation", "params": {"T1": -0.04583, "T2": -0.02052}, "mean_diff": -4.4122, "se": 0.3823, "afterSwap_max": 184614, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S2_width", "params": {"W": -0.02688, "WC": -0.01508}, "mean_diff": 0.1001, "se": 0.0872, "afterSwap_max": 199080, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S2_width", "params": {"W": 0.02427, "WC": 0.00699}, "mean_diff": -1.2856, "se": 0.1446, "afterSwap_max": 184552, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S2_width", "params": {"W": 0.02716, "WC": -0.02432}, "mean_diff": -0.7424, "se": 0.1158, "afterSwap_max": 184589, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S2_width", "params": {"W": -0.02618, "WC": 0.00454}, "mean_diff": 0.2215, "se": 0.0906, "afterSwap_max": 199085, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S2_width", "params": {"W": -0.01189, "WC": 0.02102}, "mean_diff": 0.0351, "se": 0.0649, "afterSwap_max": 199097, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S2_width", "params": {"W": -0.00872, "WC": 0.01168}, "mean_diff": 0.0458, "se": 0.0425, "afterSwap_max": 199097, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S3_coupled_feedback", "params": {"T1": 0.04763, "WR": 0.01083, "WC": -0.01083, "RHO": -0.02358}, "mean_diff": -0.6256, "se": 0.2223, "afterSwap_max": 204332, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S3_coupled_feedback", "params": {"T1": -0.05098, "WR": -0.01131, "WC": 0.01464, "RHO": -0.03256}, "mean_diff": -2.3973, "se": 0.2256, "afterSwap_max": 206955, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S3_coupled_feedback", "params": {"T1": -0.01544, "WR": -0.02718, "WC": -0.00936, "RHO": 0.02366}, "mean_diff": -1.4082, "se": 0.1397, "afterSwap_max": 206921, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S3_coupled_feedback", "params": {"T1": 0.00308, "WR": -0.03031, "WC": 0.00757, "RHO": -0.02048}, "mean_diff": -0.9023, "se": 0.1231, "afterSwap_max": 206936, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S3_coupled_feedback", "params": {"T1": 0.01985, "WR": 0.0106, "WC": 0.005, "RHO": 0.04036}, "mean_diff": -0.1954, "se": 0.1068, "afterSwap_max": 204270, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 0, "seeds": [680032, 680063], "structure": "S3_coupled_feedback", "params": {"T1": -0.03413, "WR": 0.04748, "WC": -0.00246, "RHO": 0.01258}, "mean_diff": 0.0509, "se": 0.0673, "afterSwap_max": 204315, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S1_translation", "params": {"T1": -0.00496, "T2": 0.00968}, "mean_diff": -2.0299, "se": 0.5382, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S1_translation", "params": {"T1": -0.04062, "T2": -0.0006}, "mean_diff": -1.4787, "se": 0.1355, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S1_translation", "params": {"T1": 0.00321, "T2": 0.0416}, "mean_diff": -5.7364, "se": 0.5864, "afterSwap_max": 199691, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S1_translation", "params": {"T1": -0.02073, "T2": 0.03833}, "mean_diff": -4.2825, "se": 0.5439, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S1_translation", "params": {"T1": -0.03984, "T2": -0.00155}, "mean_diff": -1.5605, "se": 0.1344, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S1_translation", "params": {"T1": 0.01178, "T2": -0.02713}, "mean_diff": -2.646, "se": 0.3075, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S2_width", "params": {"W": -0.01548, "WC": -0.0307}, "mean_diff": -0.3711, "se": 0.1192, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S2_width", "params": {"W": -0.05597, "WC": 0.00694}, "mean_diff": -1.5361, "se": 0.3988, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S2_width", "params": {"W": -0.03397, "WC": -0.03104}, "mean_diff": -0.8843, "se": 0.2386, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S2_width", "params": {"W": -0.03933, "WC": -0.00633}, "mean_diff": -1.0031, "se": 0.3156, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S2_width", "params": {"W": -0.02291, "WC": 0.0372}, "mean_diff": -0.6511, "se": 0.2483, "afterSwap_max": 199695, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S2_width", "params": {"W": -0.02728, "WC": -0.03742}, "mean_diff": -0.7499, "se": 0.2102, "afterSwap_max": 193212, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S3_coupled_feedback", "params": {"T1": -0.03632, "WR": 0.02385, "WC": -0.02619, "RHO": -0.0119}, "mean_diff": -0.6994, "se": 0.0895, "afterSwap_max": 207233, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S3_coupled_feedback", "params": {"T1": -0.02389, "WR": 0.08361, "WC": -0.01752, "RHO": 0.0058}, "mean_diff": -1.5965, "se": 0.4036, "afterSwap_max": 207123, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S3_coupled_feedback", "params": {"T1": -0.03042, "WR": 0.09127, "WC": 0.00156, "RHO": 0.02175}, "mean_diff": -1.5568, "se": 0.4101, "afterSwap_max": 207107, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S3_coupled_feedback", "params": {"T1": -0.00581, "WR": 0.00479, "WC": 0.00201, "RHO": 0.03756}, "mean_diff": -0.0516, "se": 0.0302, "afterSwap_max": 207180, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S3_coupled_feedback", "params": {"T1": -0.0304, "WR": 0.04218, "WC": 0.01311, "RHO": 0.02138}, "mean_diff": -0.1535, "se": 0.0879, "afterSwap_max": 207107, "oog": 0, "halts": 0}, {"phase": "cma_scale0.03", "gen": 1, "seeds": [680064, 680095], "structure": "S3_coupled_feedback", "params": {"T1": -0.00079, "WR": 0.02066, "WC": -0.01249, "RHO": -0.00764}, "mean_diff": -0.3408, "se": 0.2062, "afterSwap_max": 207160, "oog": 0, "halts": 0}], "v10_baseline_gas_per_block": [{"gen_block": [680000, 680031], "afterSwap_max": 192739, "halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}, {"gen_block": [680032, 680063], "afterSwap_max": 190748, "halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}, {"gen_block": [680064, 680095], "afterSwap_max": 190536, "halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}]}, "recheck_684000_684255": {"top2_selection": "two highest tuning means: A (S2 W=-0.02618,WC=0.00454, +0.222 se 0.091) and B (S2 W=-0.02688,WC=-0.01508, +0.100 se 0.087), both from block 680032..680063", "A": {"paired": {"n": 256, "mean_diff": -0.17394318108283713, "se": 0.10138086159483337, "worst": [{"seed": 684235, "d": -21.414888269316293}, {"seed": 684042, "d": -6.28412497891145}, {"seed": 684151, "d": -4.2679631217826}]}, "retail_edge_delta": {"mean": 1.0980306099044077, "se": 0.03944604279088878}, "arb_edge_delta": {"mean": -1.2719737909872468, "se": 0.08562058976774001}, "reconciliation_max_abs": 1.1368683772161603e-13, "arm_means": {"A": {"edge": 530.6229671403723, "arb": -28.05138953638557, "retail": 558.674356676758}, "V10": {"edge": 530.7969103214552, "arb": -26.779415745398325, "retail": 557.5763260668537}}, "sha256": "51b8a9260dcda83a26014c6c028919cccc7ce9dcad9a15079882d0f0dbb3817e", "gas": {"afterSwap_max_ok": 199404, "init_max_ok_separate": 220969, "oog": 0, "all_halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}}, "B": {"paired": {"n": 256, "mean_diff": -0.3037698470076533, "se": 0.1042685471537634, "worst": [{"seed": 684235, "d": -21.389612726233622}, {"seed": 684042, "d": -8.242683135983953}, {"seed": 684052, "d": -4.461973537597942}]}, "retail_edge_delta": {"mean": 1.0702124797810257, "se": 0.041079827402250316}, "arb_edge_delta": {"mean": -1.3739823267886804, "se": 0.08744991891016135}, "reconciliation_max_abs": 1.1368683772161603e-13, "arm_means": {"B": {"edge": 530.4931404744475, "arb": -28.153398072187006, "retail": 558.6465385466347}, "V10": {"edge": 530.7969103214552, "arb": -26.779415745398325, "retail": 557.5763260668537}}, "sha256": "cf92387df038a394c32eb09a487e2efdb9e1570daa0ec832920ca1542e24a01b", "gas": {"afterSwap_max_ok": 199387, "init_max_ok_separate": 220969, "oog": 0, "all_halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}}, "V10_gas": {"afterSwap_max_ok": 192814, "init_max_ok_separate": 220981, "oog": 0, "all_halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}}, "freeze": {"hash": "51b8a9260dcda83a26014c6c028919cccc7ce9dcad9a15079882d0f0dbb3817e", "arm": "A", "timestamp_utc": "2026-11-08T21:13:49Z", "rule": "better recheck mean of top 2 (both negative); frozen before held-out was run"}, "heldout_685000_685511": {"paired": {"n": 512, "mean_diff": -0.1871561636153335, "se": 0.0508208173423439, "worst": [{"seed": 685335, "d": -10.847965783915242}, {"seed": 685148, "d": -8.916306378916033}, {"seed": 685249, "d": -6.630615687616569}, {"seed": 685483, "d": -5.438683339327326}, {"seed": 685268, "d": -4.922504107761256}]}, "retail_edge_delta": {"mean": 1.096507729447647, "se": 0.026419444404411865}, "arb_edge_delta": {"mean": -1.2836638930629798, "se": 0.04505836736042446}, "reconciliation_max_abs": 1.0658141036401503e-13, "arm_means": {"A": {"edge": 520.454034260176, "arb": -26.78881057431062, "retail": 547.2428448344865}, "V10": {"edge": 520.6411904237912, "arb": -25.50514668124764, "retail": 546.1463371050388}}, "gas": {"candidate": {"afterSwap_max_ok": 202854, "init_max_ok_separate": 220969, "oog": 0, "all_halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}, "V10": {"afterSwap_max_ok": 194561, "init_max_ok_separate": 220981, "oog": 0, "all_halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}}}, "paired": {"n": 512, "mean_diff": -0.1871561636153335, "se": 0.0508208173423439, "worst": [{"seed": 685335, "d": -10.847965783915242}, {"seed": 685148, "d": -8.916306378916033}, {"seed": 685249, "d": -6.630615687616569}, {"seed": 685483, "d": -5.438683339327326}, {"seed": 685268, "d": -4.922504107761256}]}, "retail_edge_delta": {"mean": 1.096507729447647, "se": 0.026419444404411865}, "arb_edge_delta": {"mean": -1.2836638930629798, "se": 0.04505836736042446}, "reconciliation": "per-seed edge diff = arb diff + retail diff, max residual 1.07e-13; retail gains +1.10 but arb losses -1.28 (narrower band near displaced spot lets arbs trade more).", "gas": {"candidate": {"afterSwap_max_ok": 202854, "init_max_ok_separate": 220969, "oog": 0, "all_halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}, "V10": {"afterSwap_max_ok": 194561, "init_max_ok_separate": 220981, "oog": 0, "all_halts": {"oog": 0, "revert": 0, "other_halt": 0, "tx_error": 0, "bad_return": 0}}, "note": "afterSwap max over held-out; init (afterInitialize incl. as reported by gas_stats) separate. Tuning arms afterSwap max 184.6k-207.2k, all 0 halts; recheck A 199,404, B 199,387. All < 235k."}, "halt_counts": "0 oog/revert/other_halt/tx_error/bad_return in every run (tuning, recheck, held-out, V10 baselines); gas_stats reset/read around every <=20-seed chunk; no seeds dropped.", "seed_ledger": {"identity_check": "680000..680019 (V10 vs zero-params, plus one smoke arm)", "tuning": "680000..680031 (scale 0.25 gen), 680032..680063, 680064..680095 (scale 0.03 gens)", "recheck": "684000..684255 (256)", "heldout_once": "685000..685511 (512)", "seeds_ge_5000000": "none used"}, "validation": {"amm-match validate": "Strategy rd_steer validated successfully (frozen source)", "zero_intervention_exact": true, "compiler": "solc 0.8.24 via repo SolidityCompiler"}, "interpretation": "No structure beat V10. Retail displacement steering of both band endpoints trades retail edge against arb edge: on held-out the frozen width arm gains +1.10 retail but loses 1.28 to arb, net -0.187 (se 0.051, about 3.7 se below 0). Translation (S1) lost the most; coupled feedback with carry (S3) never cleared noise. V10 looks locally optimal along these displacement directions, with high curvature (losses grow roughly with the square of the gain).", "limitations": ["Search was short (3 generations, 54 CMA evaluations, 32 seeds each) and stopped early to stay inside the 55-minute window; this is incomplete, not exhaustive.", "Scale 0.25 was too coarse; at scale 0.03 the search covered only 2 generations.", "First-print retail weight uses V10 posterior probability, an approximation.", "d is measured against the last post-trade spot, so it includes any arb drift misclassified as retail.", "Edge decomposition is a reconstruction (V10 method), not simulator counters.", "Tuning seeds only; no board claim; no STACK comparison was run."]}