{"item":"d","blocked":null,"code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {AMMStrategyBase} from \"./AMMStrategyBase.sol\";\nimport {TradeInfo} from \"./IAMMStrategy.sol\";\n\ncontract Strategy is AMMStrategyBase {\n    uint256 constant ELAPSED_CAP = 8;\n    uint256 constant SIGNAL_THRESHOLD = WAD / 650;\n    uint256 constant DIR_DECAY = 750000000000000000;\n    uint256 constant ACT_DECAY = 530000000000000000;\n    uint256 constant SIZE_DECAY = 530000000000000000;\n    uint256 constant TOX_DECAY = 910000000000000000;\n    uint256 constant SIGMA_DECAY = 690000000000000000;\n    uint256 constant LAMBDA_DECAY = 990000000000000000;\n    uint256 constant SIZE_BLEND_DECAY = 828000000000000000;\n    uint256 constant TOX_BLEND_DECAY = 51000000000000000;\n    uint256 constant ACT_BLEND_DECAY = 985000000000000000;\n    uint256 constant PHAT_ALPHA = 270000000000000000;\n    uint256 constant PHAT_ALPHA_RETAIL = 60000000000000000;\n    uint256 constant PHAT_ALPHA_SAME = 120000000000000000;\n    uint256 constant REVERT_U = 0;\n    uint256 constant DIR_IMPACT_MULT = 4;\n    uint256 constant GATE_SIGMA_MULT = 7200000000000000000;\n    uint256 constant MIN_GATE = 30000000000000000;\n    uint256 constant TRADE_TOX_BOOST = 3500 * BPS;\n    uint256 constant STALE_ATTRACT_FRAC = 1050000000000000000;\n    uint256 constant RET_CAP = WAD / 35;\n    uint256 constant TOX_CAP = WAD / 5;\n    uint256 constant TRADE_RATIO_CAP = WAD / 5;\n    uint256 constant LAMBDA_CAP = 1820000000000000000;\n    uint256 constant STEP_COUNT_CAP = 64;\n    uint256 constant BASE_FEE = 4 * BPS;\n    uint256 constant SIGMA_COEF = 200000000000000000;\n    uint256 constant LAMBDA_COEF = 12 * BPS;\n    uint256 constant FLOW_SIZE_COEF = 4842 * BPS;\n    uint256 constant TOX_COEF = 300 * BPS;\n    uint256 constant TOX_QUAD_COEF = 15000 * BPS;\n    uint256 constant ACT_COEF = 91843 * BPS;\n    uint256 constant DIR_COEF = 20 * BPS;\n    uint256 constant DIR_TOX_COEF = 100 * BPS;\n    uint256 constant STALE_DIR_COEF = 6850 * BPS;\n    uint256 constant SIGMA_TOX_COEF = 500 * BPS;\n    uint256 constant TAIL_KNEE = 600 * BPS;\n    uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000;\n    uint256 constant TAIL_SLOPE_ATTRACT = 850000000000000000;\n\n    function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) {\n        slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[3] = WAD; \n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n        slots[15] = 400000000000000000 | (uint256(2000000000000000) << 160); slots[13] = 902500000000; slots[14] = slots[5]; \n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 prevBidFee = slots[0]; uint256 prevAskFee = slots[1]; uint256 lastTs = uint64(slots[2]);\n        uint256 dirState = slots[3]; uint256 actEma = slots[4]; uint256 pHat = slots[5];\n        uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8];\n        uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10];\n\n        uint256 sigmaForFast = sigmaHat;\n        uint256 fastHat = slots[14];\n        uint256 uncertainty = slots[13];\n        uint256 silent = trade.timestamp > lastTs ? trade.timestamp - lastTs : 0;\n        bool isNewStep = trade.timestamp > lastTs;\n        if (isNewStep) {\n            uint256 elapsedRaw = trade.timestamp - lastTs;\n            uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw;\n            dirState = _decayCentered(dirState, DIR_DECAY, elapsed);\n            actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed));\n            sizeHat = wmul(sizeHat, _powWad(SIZE_DECAY, elapsed));\n            toxEma = wmul(toxEma, _powWad(TOX_DECAY, elapsed));\n            if (stepTradeCount > 0 && elapsedRaw > 0) {\n                uint256 lambdaInst = (stepTradeCount * WAD) / elapsedRaw;\n                if (lambdaInst > LAMBDA_CAP) lambdaInst = LAMBDA_CAP;\n                lambdaHat = wmul(lambdaHat, LAMBDA_DECAY) + wmul(lambdaInst, WAD - LAMBDA_DECAY);\n            }\n            // Process variance is propagated inside the censored update.\n            if (uncertainty > 100000000000000) uncertainty = 100000000000000;\n            stepTradeCount = 0;\n        }\n\n        bool firstInStep = stepTradeCount == 0;\n        uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat;\n        if (pHat == 0) pHat = spot;\n\n        uint256 feeUsed = trade.isBuy ? prevBidFee : prevAskFee;\n        uint256 gamma = feeUsed < WAD ? WAD - feeUsed : 0;\n        uint256 pImplied;\n        if (gamma == 0) { pImplied = spot; }\n        else { pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma); }\n\n        // S: infer a no-trade interval center from the last post-trade spot.\n        uint256 silenceScale = WAD;\n        if (firstInStep && silent > 1) {\n            uint256 g = silent - 1;\n            if (g > 1) g = 1;\n            uint256 w = WAD - _powWad(800000000000000000, g);\n            uint256 s = slots[2] >> 64;\n            if (s == 0) s = pHat;\n            uint256 c = (wmul(s, WAD - prevBidFee) + wdiv(s, WAD - prevAskFee)) / 2;\n            if (c >= pHat) pHat += wmul(w, c - pHat);\n            else pHat -= wmul(w, pHat - c);\n            silenceScale = WAD - wmul(300000000000000000, w);\n        }\n\n        {\n            uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0;\n            uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL;\n            uint256 prePhat = pHat;\n            bool secondPrint = !firstInStep && stepTradeCount == 1;\n            bool sameDir = false; bool oppDir = false;\n            if (secondPrint) {\n                bool up2 = pImplied >= pHat;\n                uint256 d1 = slots[12];\n                if (d1 != 0) { sameDir = (d1 == 1) == up2; oppDir = !sameDir; }\n                if (sameDir) alpha = PHAT_ALPHA_SAME;\n            }\n            if (firstInStep) { slots[12] = pImplied >= pHat ? 1 : 2; }\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            alpha = wmul(alpha, silenceScale);\n            adaptiveGate = wmul(adaptiveGate, silenceScale);\n            if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); }\n            if (oppDir && REVERT_U > 0) {\n                uint256 pre = slots[11];\n                if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U);\n                else pHat = pHat - wmul(pHat - pre, REVERT_U);\n            }\n            if (firstInStep) {\n                if (ret > RET_CAP) ret = RET_CAP;\n                sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY);\n            }\n        }\n\n        // Interior retail routing equalizes fee-adjusted marginal prices.\n        // Subsequent trades in a step cannot be the initial arbitrage trade.\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalSpot = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            pHat = wmul(pHat, 90 * WAD / 100) + wmul(normalSpot, 10 * WAD / 100);\n        }\n\n        // Censored assumed-density posterior. No external or future inputs.\n        uint256 arbProbability;\n        (fastHat, uncertainty, arbProbability) = _posterior(PosteriorInput(\n            fastHat, uncertainty, pImplied, spot, slots[2] >> 64,\n            prevBidFee, prevAskFee, firstInStep, silent, trade.isBuy,\n            trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0\n        ));\n        slots[13] = uncertainty;\n        slots[14] = fastHat;\n        uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n        if (tradeRatio > TRADE_RATIO_CAP) tradeRatio = TRADE_RATIO_CAP;\n\n        if (tradeRatio > SIGNAL_THRESHOLD) {\n            uint256 push = tradeRatio * DIR_IMPACT_MULT;\n            if (push > WAD / 4) push = WAD / 4;\n            if (trade.isBuy) {\n                dirState = dirState + push;\n                if (dirState > 2 * WAD) dirState = 2 * WAD;\n            } else {\n                dirState = dirState > push ? dirState - push : 0;\n            }\n            actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY);\n            sizeHat = wmul(sizeHat, SIZE_BLEND_DECAY) + wmul(tradeRatio, WAD - SIZE_BLEND_DECAY);\n            if (sizeHat > WAD) sizeHat = WAD;\n        }\n\n        uint256 tox = pHat > 0 ? wdiv(absDiff(spot, pHat), pHat) : 0;\n        if (tox > TOX_CAP) tox = TOX_CAP;\n        toxEma = wmul(toxEma, TOX_BLEND_DECAY) + wmul(tox, WAD - TOX_BLEND_DECAY);\n        uint256 toxSignal = toxEma;\n\n        stepTradeCount = stepTradeCount + 1;\n        if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP;\n\n        uint256 feeActivity = actEma; uint256 originalLambda = lambdaHat; uint256 originalSize = sizeHat;\n\n        if (165091798395004448 > 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(990989344813230592, 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, 80000000000000000000);\n                if (missing > 500000000000000000) missing = 500000000000000000;\n                correctedWeight = wdiv(weight, WAD-missing);\n            }\n            count += correctedWeight;\n            uint256 learning = wmul(WAD-990989344813230592, weight);\n            meanSize = _blend(meanSize, tradeRatio, learning);\n            slots[15]=rate | (count << 80) | (meanSize << 160);\n            uint256 retailRate = wmul(rate, 668495983854602240);\n            uint256 retailSize = 2 == 0 ? sizeHat : wmul(meanSize,1594662769237502464);\n            lambdaHat = _blend(lambdaHat,retailRate,165091798395004448);\n            sizeHat = _blend(sizeHat,retailSize,165091798395004448);\n            uint256 cleanActivity = wmul(wmul(retailRate, retailSize), 31914893617021276);\n            feeActivity = _blend(actEma, cleanActivity, 0);\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, feeActivity);\n        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal));\n\n        lambdaHat = originalLambda; sizeHat = originalSize;\n        uint256 dirDev; bool sellPressure;\n        if (dirState >= WAD) { dirDev = dirState - WAD; sellPressure = true; }\n        else { dirDev = WAD - dirState; sellPressure = false; }\n\n        uint256 skew = wmul(DIR_COEF, dirDev) + wmul(DIR_TOX_COEF, wmul(dirDev, toxSignal));\n        uint256 bidFee; uint256 askFee;\n        if (sellPressure) {\n            bidFee = fMid + skew;\n            askFee = fMid > skew ? fMid - skew : 0;\n        } else {\n            askFee = fMid + skew;\n            bidFee = fMid > skew ? fMid - skew : 0;\n        }\n\n        {\n            uint256 staleHat = wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000);\n            uint256 staleTox = wdiv(absDiff(spot, staleHat), staleHat);\n            if (staleTox > TOX_CAP) staleTox = TOX_CAP;\n            uint256 staleShift = wmul(STALE_DIR_COEF, staleTox);\n            uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC);\n            if (spot >= staleHat) {\n                bidFee = bidFee + staleShift;\n                askFee = askFee > attractShift ? askFee - attractShift : 0;\n            } else {\n                askFee = askFee + staleShift;\n                bidFee = bidFee > attractShift ? bidFee - attractShift : 0;\n            }\n        }\n\n        {\n            bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat);\n            if (tradeAligned) {\n                uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\n                if (!firstInStep && tradeBoost > 16 * BPS) tradeBoost = 16 * BPS;\n                if (trade.isBuy) { bidFee = bidFee + tradeBoost; }\n                else { askFee = askFee + tradeBoost; }\n            }\n        }\n\n        if (sellPressure) {\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_PROTECT));\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_ATTRACT));\n        } else {\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_PROTECT));\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_ATTRACT));\n        }\n\n        if (firstInStep) {\n            if (askFee > bidFee && bidFee > 30 * BPS) bidFee = 30 * BPS;\n            else if (bidFee > askFee && askFee > 30 * BPS) askFee = 30 * BPS;\n        }\n\n        if (bidFee > askFee && askFee > 36 * BPS) askFee = 36 * BPS;\n        else if (askFee > bidFee && bidFee > 36 * BPS) bidFee = 36 * BPS;\n\n        slots[0] = bidFee; slots[1] = askFee; slots[2] = (spot << 64) | trade.timestamp;\n        slots[3] = dirState; slots[4] = actEma; slots[5] = pHat;\n        slots[6] = sigmaHat; slots[7] = lambdaHat; slots[8] = sizeHat;\n        slots[9] = toxEma; slots[10] = stepTradeCount;\n\n        return (bidFee, askFee);\n    }\n\n\n    struct PosteriorInput {\n        uint256 mu; uint256 v; uint256 obs; uint256 spot; uint256 preSpot;\n        uint256 bid; uint256 ask; bool first; uint256 silent; bool buy; uint256 size;\n    }\n    function _posterior(PosteriorInput memory x) internal pure returns (uint256, uint256, uint256) {\n        if (x.mu == 0) x.mu = x.spot;\n        if (x.v < 10000000000) x.v = 10000000000;\n        uint256 lo = wmul(x.preSpot, WAD-x.bid);\n        uint256 hi = wdiv(x.preSpot, WAD-x.ask);\n        if (x.first) {\n            if (x.silent>1 && x.preSpot>0) {\n                uint256 elapsed=x.silent>8?8:x.silent;\n                x.v += 902500000000*(elapsed-1);\n                (x.mu,x.v)=_band(x.mu,x.v,lo,hi);\n            }\n            x.v+=902500000000;\n        }\n        uint256 mRetail = x.mu;\n        uint256 vRetail = x.v;\n        // A missing own-pool trade is a censored price observation.\n        if (x.first && x.preSpot > 0) {\n            (mRetail, vRetail) = _band(x.mu, x.v, lo, hi);\n        }\n        if (!x.first) {\n            // A later print is retail. Only an interior route is an observation\n            // of the other pool, with explicit observation uncertainty.\n            uint256 fee = x.buy ? x.bid : x.ask;\n            if (fee > 30 * BPS) {\n                uint256 normal = x.buy ? wdiv(wmul(x.spot, WAD-fee), WAD-30*BPS)\n                    : wdiv(wmul(x.spot, WAD-30*BPS), WAD-fee);\n                uint256 residual = wdiv(absDiff(normal, x.mu),x.mu);\n                uint256 noise = 9000000000000 + wmul(residual,residual);\n                uint256 k = wdiv(x.v,x.v+noise);\n                return (_blend(x.mu,normal,k),wmul(x.v,WAD-k),0);\n            }\n            return (x.mu,x.v,0);\n        }\n        uint256 e = wdiv(absDiff(x.obs,x.mu),x.mu);\n        uint256 totalV = x.v + 22500000000;\n        uint256 z = wdiv(wmul(e,e),totalV);\n        uint256 density = _powWad(wdiv(WAD,WAD+z/8),4);\n        uint256 odds = wmul(density,wdiv(4000000000000000,_isqrt(totalV*WAD)));\n        if (x.size > 3000000000000000) odds = wmul(odds,4*WAD/10);\n        if (x.silent > 1) odds = wmul(odds,8*WAD/10);\n        uint256 sd = _isqrt(x.v*WAD);\n        uint256 width = wdiv(hi-lo,x.mu);\n        uint256 distance = x.mu<lo?lo-x.mu:(x.mu>hi?x.mu-hi:0);\n        uint256 zBand = wdiv(wdiv(distance,x.mu),sd);\n        uint256 mass = wmul(wdiv(width,width+2*sd),wdiv(WAD,WAD+wmul(zBand,zBand)));\n        if (mass < WAD/100) mass = WAD/100;\n        odds = wdiv(odds,mass);\n        uint256 prob = wdiv(odds,WAD+odds);\n        uint256 kArb = wdiv(x.v,totalV);\n        uint256 mArb = _blend(x.mu,x.obs,kArb);\n        uint256 mean = _blend(mRetail,mArb,prob);\n        uint256 between = wdiv(absDiff(mArb,mRetail),x.mu);\n        uint256 variance = wmul(prob,wmul(x.v,WAD-kArb)) + wmul(WAD-prob,vRetail)\n            + wmul(wmul(prob,WAD-prob),wmul(between,between));\n        if (variance > 100000000000000) variance = 100000000000000;\n        return (mean,variance,prob);\n    }\n    function _blend(uint256 a,uint256 b,uint256 w) internal pure returns(uint256) {\n        return b>=a ? a+wmul(b-a,w) : a-wmul(a-b,w);\n    }\n    function _band(uint256 mu,uint256 v,uint256 lo,uint256 hi) internal pure returns(uint256,uint256) {\n        // Soft interval likelihood avoids discontinuities at quadrature nodes.\n        uint256 sd=wmul(mu,_isqrt(v*WAD));\n        uint256[3] memory acc;\n        for(uint256 j=0;j<7;j++) {\n            uint256 p=j<3 ? (mu>(3-j)*sd?mu-(3-j)*sd:1) : mu+(j-3)*sd;\n            uint256 w=j==3?72:(j==2||j==4?45:(j==1||j==5?10:1));\n            uint256 distance=p<lo?lo-p:(p>hi?p-hi:0);\n            uint256 z=sd>0?wdiv(distance,sd):0;\n            uint256 likelihood=wdiv(WAD,WAD+4*wmul(z,z));\n            w=wmul(w*WAD,likelihood);\n            acc[0]+=w;acc[1]+=wmul(w,p);\n            uint256 d=wdiv(absDiff(p,mu),mu);\n            acc[2]+=wmul(w,wmul(d,d));\n        }\n        uint256 m=wdiv(acc[1],acc[0]);\n        uint256 d=wdiv(absDiff(m,mu),mu);\n        uint256 second=wdiv(acc[2],acc[0]);\n        return(m,second>wmul(d,d)?second-wmul(d,d):10000000000);\n    }\n\n    function _compressTailWithSlope(uint256 fee, uint256 slope) internal pure returns (uint256) {\n        if (fee <= TAIL_KNEE) return fee;\n        return TAIL_KNEE + wmul(fee - TAIL_KNEE, slope);\n    }\n\n    function _powWad(uint256 factor, uint256 exp) internal pure returns (uint256 result) {\n        result = WAD;\n        while (exp > 0) {\n            if (exp & 1 == 1) result = wmul(result, factor);\n            factor = wmul(factor, factor);\n            exp >>= 1;\n        }\n    }\n\n    function _decayCentered(uint256 centered, uint256 decayFactor, uint256 elapsed) internal pure returns (uint256) {\n        uint256 mul = _powWad(decayFactor, elapsed);\n        if (centered >= WAD) { return WAD + wmul(centered - WAD, mul); }\n        uint256 below = wmul(WAD - centered, mul);\n        return below < WAD ? WAD - below : 0;\n    }\n\n    // Floor square root: bit-length seed and seven Newton steps (all uint256).\n    function _isqrt(uint256 x) internal pure returns (uint256 r) {\n        if (x == 0) return 0;\n        unchecked {\n            uint256 y = x;\n            r = 1;\n            if (y >> 128 != 0) { y >>= 128; r <<= 64; }\n            if (y >> 64 != 0) { y >>= 64; r <<= 32; }\n            if (y >> 32 != 0) { y >>= 32; r <<= 16; }\n            if (y >> 16 != 0) { y >>= 16; r <<= 8; }\n            if (y >> 8 != 0) { y >>= 8; r <<= 4; }\n            if (y >> 4 != 0) { y >>= 4; r <<= 2; }\n            if (y >> 2 != 0) { r <<= 1; }\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            uint256 t = x / r;\n            return r < t ? r : t;\n        }\n    }\n\n    function getName() external pure override returns (string memory) { return \"censored_10\"; }\n}\n","sha256":"f225d339f6f6b3a00d00e3b2d3b3f119084e745f4f79fa67036591406afee50b","params":[0.16509179839500446,0.16509179839500446,0.0,0.9909893448132306,0.6684959838546023,1.5946627692375024,80.0,2.0],"parameter_names":["rate_mix (0..0.8)","size_mix (0..0.8)","activity_mix (0..1)","retention_per_step (0.9..0.999)","rate_scale (0.3..3)","size_scale (0.3..3)","quote_correction_slope (10..400)","inverse_quote_correction_cap (1.5..6)"],"setup":{"repository":"https://github.com/benedictbrady/amm-challenge","commit":"6b6921f8d463314aa7c96234e1be25a25245f704","simulator_wheel_sha256":"aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a","starter_validation":"passed"},"evaluations":6,"log":[{"params":[0.16509179839500446,0.16509179839500446,0.0,0.9909893448132306,0.6684959838546023,1.5946627692375024,80.0,2.0],"sha256":"f225d339f6f6b3a00d00e3b2d3b3f119084e745f4f79fa67036591406afee50b","n":64,"mean_diff":0.03938313755080447,"se":0.036961540584801465,"max_ok":197579,"init_max_ok":243099,"oog":0,"valid":true,"seeds":[730000,730063],"generation":0},{"params":[0.3124381011625434,0.038062796274379807,0.47741160549051814,0.975362839758022,0.8500427720779067,2.926099046841969,71.97948066695484,2.092578556104324],"sha256":"26264638c2c4920cbd42e894c10e957ef340562da3471d6335fd14b113ed25d5","n":64,"mean_diff":-0.9245086359093495,"se":0.12943272853141707,"max_ok":197612,"init_max_ok":243099,"oog":0,"valid":true,"seeds":[730000,730063],"generation":0},{"params":[0.09138114397940815,0.21326361203403918,0.0,0.9794632126637125,1.4918252801130656,1.6973672697800664,63.12402408655229,2.302072074510844],"sha256":"a99876cc7088492b1ce5f488655c44651d8e0ef92786e459d04e8646ee12ec4a","n":64,"mean_diff":-0.5919908932703724,"se":0.09958346382868709,"max_ok":197570,"init_max_ok":243099,"oog":0,"valid":true,"seeds":[730000,730063],"generation":0},{"params":[0.22479517960734818,0.18699466839249757,0.1041458159233787,0.9614153298283588,0.9558460498815091,1.2673287581556687,135.16334511920485,1.9827901752523285],"sha256":"a93ee352e41391a84616e4696199b10ac275bfbdc6f006ceb7749150e373c2f4","n":64,"mean_diff":-0.22518009731632027,"se":0.07595531551395973,"max_ok":197612,"init_max_ok":243099,"oog":0,"valid":true,"seeds":[730000,730063],"generation":0},{"params":[0.02135346946757606,0.15470493539347704,0.0,0.999,0.6545972288932891,2.0092653430572986,10.0,3.311728045008764],"sha256":"6c988673d780d5a6d27f2aa850840dc581e80dc268a83396cd67bc9c0916db28","n":64,"mean_diff":-0.3283431633107492,"se":0.08167882802868424,"max_ok":197570,"init_max_ok":243099,"oog":0,"valid":true,"seeds":[730000,730063],"generation":0},{"params":[0.12173897048207145,0.36169007935104314,0.15372924205691155,0.9713705025096608,0.8255490636440799,1.331031911565217,108.73738704922037,3.1603076263754075],"sha256":"c7977423a7e54db7b050373316a1ad442f6a32363006a6bdc87d6919bf68df3d","n":64,"mean_diff":-0.9538700517297318,"se":0.11106732599982798,"max_ok":197621,"init_max_ok":243099,"oog":0,"valid":true,"seeds":[730000,730063],"generation":0}],"recheck":[{"params":[0.16509179839500446,0.16509179839500446,0.0,0.9909893448132306,0.6684959838546023,1.5946627692375024,80.0,2.0],"sha256":"f225d339f6f6b3a00d00e3b2d3b3f119084e745f4f79fa67036591406afee50b","paired":{"n":256,"mean_diff":0.11099166265306382,"se":0.025628153230262858,"worst":[{"seed":734025,"d":-1.375475240167475},{"seed":734078,"d":-0.9650368624965608},{"seed":734239,"d":-0.8824350515187689},{"seed":734208,"d":-0.8820937253829015},{"seed":734190,"d":-0.8195857543545344}]},"retail_edge_delta":{"mean":0.060188920957621406,"se":0.025955934994311584},"arb_edge_delta":{"mean":0.05080274169544649,"se":0.010715825797761883},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":200652,"init_max_ok":243099,"oog":0,"errors":0},"valid":true},{"params":[0.22479517960734818,0.18699466839249757,0.1041458159233787,0.9614153298283588,0.9558460498815091,1.2673287581556687,135.16334511920485,1.9827901752523285],"sha256":"a93ee352e41391a84616e4696199b10ac275bfbdc6f006ceb7749150e373c2f4","paired":{"n":256,"mean_diff":-0.05118880139133819,"se":0.036883060567722205,"worst":[{"seed":734103,"d":-1.983227473682291},{"seed":734038,"d":-1.8119106315999716},{"seed":734117,"d":-1.67962841310964},{"seed":734208,"d":-1.6004389772599552},{"seed":734020,"d":-1.2515705496532519}]},"retail_edge_delta":{"mean":-0.8118460568556307,"se":0.04332897349083343},"arb_edge_delta":{"mean":0.7606572554642925,"se":0.02214141779112733},"reconciliation_max_abs":1.1368683772161603e-13,"gas":{"max_ok":200694,"init_max_ok":243099,"oog":0,"errors":0},"valid":true},{"params":[0.02135346946757606,0.15470493539347704,0.0,0.999,0.6545972288932891,2.0092653430572986,10.0,3.311728045008764],"sha256":"6c988673d780d5a6d27f2aa850840dc581e80dc268a83396cd67bc9c0916db28","paired":{"n":256,"mean_diff":-0.24635229376062462,"se":0.04385103571010452,"worst":[{"seed":734103,"d":-2.1317838770738717},{"seed":734150,"d":-2.045963034475676},{"seed":734038,"d":-1.9306572471761},{"seed":734232,"d":-1.9078856950001182},{"seed":734161,"d":-1.7935192353403409}]},"retail_edge_delta":{"mean":-1.7259421384604274,"se":0.04478496884217166},"arb_edge_delta":{"mean":1.4795898446998055,"se":0.016230324777410016},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":200652,"init_max_ok":243099,"oog":0,"errors":0},"valid":true}],"held_out":{"seeds":[735000,735511],"vs_v10":{"n":512,"mean_diff":0.09393557961150167,"se":0.01886682624369501,"worst":[{"seed":735415,"d":-1.26315177610104},{"seed":735279,"d":-1.2215255748601521},{"seed":735280,"d":-1.1815692709958512},{"seed":735044,"d":-1.127972606408207},{"seed":735448,"d":-1.0017910313474658}]},"vs_rs1":{"n":512,"mean_diff":0.0,"se":0.0,"worst":[{"seed":735000,"d":0.0},{"seed":735001,"d":0.0},{"seed":735002,"d":0.0},{"seed":735003,"d":0.0},{"seed":735004,"d":0.0}]},"retail_edge_delta":{"mean":0.05434782750466305,"se":0.019785289418002186},"arb_edge_delta":{"mean":0.03958775210684013,"se":0.006938003072995893},"rs1_vs_v10":{"paired":{"n":512,"mean_diff":0.09393557961150167,"se":0.01886682624369501,"worst":[{"seed":735415,"d":-1.26315177610104},{"seed":735279,"d":-1.2215255748601521},{"seed":735280,"d":-1.1815692709958512},{"seed":735044,"d":-1.127972606408207},{"seed":735448,"d":-1.0017910313474658}]},"retail_edge_delta":{"mean":0.05434782750466305,"se":0.019785289418002186},"arb_edge_delta":{"mean":0.03958775210684013,"se":0.006938003072995893},"reconciliation_max_abs":1.1013412404281553e-13},"reconciliation_max_abs":1.1013412404281553e-13,"arms":[{"name":"frozen","sha256":"f225d339f6f6b3a00d00e3b2d3b3f119084e745f4f79fa67036591406afee50b","mean_edge":519.9781383536397,"gas":{"max_ok":202381,"init_max_ok":243099,"oog":0,"errors":0}},{"name":"rs1","sha256":"df2817ba4ec233a456eb45909faa4a706efe0fabd1734a908fe52545f4d07577","mean_edge":519.9781383536397,"gas":{"max_ok":201997,"init_max_ok":243099,"oog":0,"errors":0}},{"name":"v10","sha256":"cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245","mean_edge":519.8842027740282,"gas":{"max_ok":194277,"init_max_ok":220981,"oog":0,"errors":0}}]},"gas":{"max_ok":202381,"init_max_ok":243099,"oog":0,"errors":0},"generator_source":"def original_generate(base,p):\n kind,mix,decay,scale,sscale,correction=p\n mix=int(mix*1e18);decay=int(decay*1e18)\n s=base.replace('(fastHat, uncertainty) = _posterior','uint256 arbProbability;\\n        (fastHat, uncertainty, arbProbability) = _posterior')\n s=s.replace('internal pure returns (uint256, uint256) {\\n        if (x.mu', 'internal pure returns (uint256, uint256, uint256) {\\n        if (x.mu')\n s=s.replace('wmul(x.v,WAD-k));','wmul(x.v,WAD-k),0);').replace('return (x.mu,x.v);','return (x.mu,x.v,0);').replace('return (mean,variance);','return (mean,variance,prob);')\n insert=f'''\n        if ({mix} > 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({decay}, 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 ({kind} == 2) {{\n                uint256 missing = wmul(feeUsed, {int(correction*1e18)});\n                if (missing > WAD/2) missing = WAD/2;\n                correctedWeight = wdiv(weight, WAD-missing);\n            }}\n            count += correctedWeight;\n            uint256 learning = wmul(WAD-{decay}, weight);\n            meanSize = _blend(meanSize, tradeRatio, learning);\n            slots[15]=rate | (count << 80) | (meanSize << 160);\n            uint256 retailRate = wmul(rate, {int(scale*1e18)});\n            uint256 retailSize = {kind} == 0 ? sizeHat : wmul(meanSize,{int(sscale*1e18)});\n            lambdaHat = _blend(lambdaHat,retailRate,{mix});\n            sizeHat = _blend(sizeHat,retailSize,{mix});\n        }}\n'''\n s=s.replace('        uint256 flowSize =', '        uint256 originalLambda = lambdaHat; uint256 originalSize = sizeHat;\\n'+insert+'        uint256 flowSize =')\n s=s.replace('        uint256 dirDev;', '        lambdaHat = originalLambda; sizeHat = originalSize;\\n        uint256 dirDev;')\n s=s.replace(\"slots[13] = 902500000000;\", \"slots[15] = 400000000000000000 | (uint256(2000000000000000) << 160); slots[13] = 902500000000;\") if mix else s\n return s\n\n\ndef generate(base,p):\n    rate_mix,size_mix,activity_mix,retention,rate_scale,size_scale,slope,cap=p\n    # Preserve RS1's posterior, storage packing, and bounded correction structure.\n    s=original_generate(base,[2,rate_mix,retention,rate_scale,size_scale,slope])\n    # The outer guard also covers activity-only and size-only configurations.\n    s=s.replace(f'if ({int(rate_mix*1e18)} > 0)',f'if ({int(max(rate_mix,size_mix,activity_mix)*1e18)} > 0)')\n    s=s.replace('if (missing > WAD/2) missing = WAD/2;',f'if (missing > {int((1-1/cap)*1e18)}) missing = {int((1-1/cap)*1e18)};')\n    s=s.replace(f'sizeHat = _blend(sizeHat,retailSize,{int(rate_mix*1e18)});',f'sizeHat = _blend(sizeHat,retailSize,{int(size_mix*1e18)});\\n            uint256 cleanActivity = wmul(wmul(retailRate, retailSize), 31914893617021276);\\n            feeActivity = _blend(actEma, cleanActivity, {int(activity_mix*1e18)});')\n    s=s.replace('uint256 originalLambda = lambdaHat;', 'uint256 feeActivity = actEma; uint256 originalLambda = lambdaHat;')\n    s=s.replace('wmul(ACT_COEF, actEma)', 'wmul(ACT_COEF, feeActivity)')\n    return s\n","harness_source":"\"\"\"Run from the pinned amm-challenge checkout, with the brief's environment active.\npython harness.py --start 5000000 --n 2000 --out measured.json candidate.sol STACK.sol\nDo not use confirmation seeds to choose or change a strategy.\n\"\"\"\nimport argparse,hashlib,json,math\nfrom pathlib import Path\nimport numpy as np\nimport amm_sim_rs as sim\nfrom amm_competition.evm.compiler import SolidityCompiler\n\n\ndef configs(start,n):\n    configs=[]\n    for seed in range(start,start+n):\n        rng=np.random.default_rng(seed)\n        size=rng.uniform(19.,21.)\n        rate=rng.uniform(.6,1.)\n        sigma=rng.uniform(.000882,.001008)\n        configs.append(sim.SimulationConfig(n_steps=10000,initial_price=100.,\n            initial_x=100.,initial_y=10000.,gbm_mu=0.,gbm_sigma=sigma,gbm_dt=1.,\n            retail_arrival_rate=rate,retail_mean_size=size,retail_size_sigma=1.2,\n            retail_buy_prob=.5,seed=seed))\n    return configs\n\n\ndef decomposition(r,initial_fee=.0004):\n    # Fees are outside reserves, so k stays fixed up to floating-point roundoff.\n    # The arb acts before retail, using the preceding step's final spot and fees.\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\n\n\ndef aggregate(chunks):\n    out={}\n    for chunk in chunks:\n        for row in chunk['raw']:\n            key=(row['role'],row['callback'])\n            dest=out.setdefault(key,{'role':row['role'],'callback':row['callback']})\n            for k,v in row.items():\n                if k in ['role','callback']:continue\n                dest[k]=max(dest.get(k,0),v) if k=='max_ok_gas' else dest.get(k,0)+v\n    return list(out.values())\n\n\ndef run(source,start,n,vanilla,compiler):\n    compiled=compiler.compile(source)\n    assert compiled.success,compiled.errors\n    rows=[];chunks=[]\n    for first in range(start,start+n,20):\n        count=min(20,start+n-first)\n        sim.gas_stats_reset()\n        batch=sim.run_batch(list(compiled.bytecode),list(vanilla),configs(first,count),8)\n        results=batch.results\n        assert sorted(r.seed for r in results)==list(range(first,first+count))\n        for r in results:\n            arb,retail=decomposition(r)\n            rows.append({'seed':r.seed,'edge':r.edges['submission'],'arb':arb,'retail':retail})\n        chunks.append({'start':first,'raw':sim.gas_stats()})\n        del results,batch\n    return {'sha256':hashlib.sha256(source.encode()).hexdigest(),'rows':rows,\n            'raw_counters':aggregate(chunks),'chunks':chunks}\n\n\ndef stats(d):\n    d=np.asarray(d,dtype=float)\n    return {'mean':float(d.mean()),'se':float(d.std(ddof=1)/np.sqrt(len(d)))}\n\n\ndef compare(candidate,stack):\n    a={r['seed']:r for r in candidate['rows']};b={r['seed']:r for r in stack['rows']}\n    assert a.keys()==b.keys()\n    seeds=sorted(a)\n    d=np.array([a[s]['edge']-b[s]['edge'] for s in seeds])\n    arb=np.array([a[s]['arb']-b[s]['arb'] for s in seeds])\n    retail=np.array([a[s]['retail']-b[s]['retail'] for s in seeds])\n    assert np.max(np.abs(d-arb-retail))<1e-8\n    summary=stats(d)\n    return {'paired':{'n':len(d),'mean_diff':summary['mean'],'se':summary['se'],\n                'worst':[{'seed':seeds[i],'d':float(d[i])} for i in np.argsort(d)[:5]]},\n            'retail_edge_delta':stats(retail),'arb_edge_delta':stats(arb),\n            'reconciliation_max_abs':float(np.max(np.abs(d-arb-retail)))}\n\n\nif __name__=='__main__':\n    p=argparse.ArgumentParser()\n    p.add_argument('--start',type=int,required=True);p.add_argument('--n',type=int,required=True)\n    p.add_argument('--out',required=True);p.add_argument('candidate');p.add_argument('stack')\n    args=p.parse_args()\n    compiler=SolidityCompiler()\n    vanilla=compiler.compile(Path('contracts/src/VanillaStrategy.sol').read_text(),'VanillaStrategy')\n    assert vanilla.success,vanilla.errors\n    candidate=run(Path(args.candidate).read_text(),args.start,args.n,vanilla.bytecode,compiler)\n    stack=run(Path(args.stack).read_text(),args.start,args.n,vanilla.bytecode,compiler)\n    out=compare(candidate,stack);out.update(candidate=candidate,stack=stack)\n    errors=['oog','revert','other_halt','tx_error','bad_return']\n    out['valid']=all(not any(row.get(e,0) for e in errors)\n        for arm in [candidate,stack] for row in arm['raw_counters'])\n    Path(args.out).write_text(json.dumps(out,allow_nan=False))\n    print(json.dumps({k:v for k,v in out.items() if k not in ['candidate','stack']}))\n","search_source":"import sys,time,json,hashlib,math\nfrom pathlib import Path\nimport numpy as np\nsys.path.insert(0,'scratch')\nimport harness as h\nfrom generator import generate\nfrom amm_competition.evm.compiler import SolidityCompiler\nbase=Path('scratch/v10.sol').read_text();c=SolidityCompiler();v=c.compile(Path('contracts/src/VanillaStrategy.sol').read_text(),'VanillaStrategy');assert v.success\nlo=np.array([0,0,0,.9,.3,.3,10,1.5]);hi=np.array([.8,.8,1,.999,3,3,400,6])\nwarm=np.array([.16509179839500446,.16509179839500446,0,.9909893448132306,.6684959838546022,1.5946627692375024,80,2])\nrng=np.random.default_rng(14);dim=8;pop=10;mu=5\nweights=np.log(mu+.5)-np.log(np.arange(1,mu+1));weights/=sum(weights);mueff=1/sum(weights**2)\ncc=(4+mueff/dim)/(dim+4+2*mueff/dim);cs=(mueff+2)/(dim+mueff+5)\nc1=2/((dim+1.3)**2+mueff);cmu=min(1-c1,2*(mueff-2+1/mueff)/((dim+2)**2+mueff))\ndamps=1+2*max(0,math.sqrt((mueff-1)/(dim+1))-1)+cs\nmean=(warm-lo)/(hi-lo);sigma=.18;C=np.eye(dim);pc=np.zeros(dim);ps=np.zeros(dim);chi=math.sqrt(dim)*(1-1/(4*dim)+1/(21*dim**2))\n\ndef gas(a):\n rows=[r for r in a['raw_counters'] if r['role']=='Submission'];return {'max_ok':max((r.get('max_ok_gas',0) for r in rows if r['callback']=='afterSwap'),default=0),'init_max_ok':max((r.get('max_ok_gas',0) for r in rows if r['callback']!='afterSwap'),default=0),'oog':sum(r.get('oog',0) for r in rows),'errors':sum(sum(r.get(k,0) for k in ['revert','other_halt','tx_error','bad_return']) for r in rows)}\nlog=[];start_time=time.monotonic();generation=0\nwhile time.monotonic()-start_time<1200:\n first=730000+(generation*64)%3968\n reference=h.run(base,first,64,v.bytecode,c)\n D,B=np.linalg.eigh(C);D=np.sqrt(np.maximum(D,1e-15));inv=B@np.diag(1/D)@B.T\n population=[]\n for j in range(pop):\n  if time.monotonic()-start_time>=1200:break\n  z=rng.normal(size=dim);x=mean+sigma*(B@(D*z));x=np.clip(x,0,1)\n  if generation==0 and j==0:x=(warm-lo)/(hi-lo)\n  p=lo+x*(hi-lo);source=generate(base,p);a=h.run(source,first,64,v.bytecode,c);comparison=h.compare(a,reference);g=gas(a)\n  valid=g['oog']==0 and g['errors']==0 and g['max_ok']<235000 and g['init_max_ok']<245000\n  row={'params':p.tolist(),'sha256':a['sha256'],'n':64,'mean_diff':comparison['paired']['mean_diff'],'se':comparison['paired']['se'],'max_ok':g['max_ok'],'init_max_ok':g['init_max_ok'],'oog':g['oog'],'valid':valid,'seeds':[first,first+63],'generation':generation}\n  log.append(row);Path('scratch/search_log.json').write_text(json.dumps(log));print(json.dumps(row),flush=True)\n  population.append((row['mean_diff'] if valid else -1e10,x))\n if len(population)<mu:break\n population.sort(key=lambda t:-t[0]);old=mean.copy();mean=sum(weights[i]*population[i][1] for i in range(mu));y=(mean-old)/sigma\n ps=(1-cs)*ps+math.sqrt(cs*(2-cs)*mueff)*(inv@y)\n hs=float(np.linalg.norm(ps)/math.sqrt(1-(1-cs)**(2*(generation+1)))<(1.4+2/(dim+1))*chi)\n pc=(1-cc)*pc+hs*math.sqrt(cc*(2-cc)*mueff)*y\n rankmu=sum(weights[i]*np.outer((population[i][1]-old)/sigma,(population[i][1]-old)/sigma) for i in range(mu))\n C=(1-c1-cmu)*C+c1*(np.outer(pc,pc)+(1-hs)*cc*(2-cc)*C)+cmu*rankmu\n sigma*=math.exp((cs/damps)*(np.linalg.norm(ps)/chi-1));generation+=1\nPath('scratch/search_done.json').write_text(json.dumps({'elapsed':time.monotonic()-start_time,'evaluations':len(log),'generations':generation}))\n","calibration":{"n":1000,"mean_edge":525.5258821780834,"expected":525.5258821780834,"difference":0.0,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":1000,"ok":1000,"max_ok_gas":21796,"sum_ok_gas":21796000,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":10741746,"ok":10741746,"max_ok_gas":22592,"sum_ok_gas":242365461576,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":1000,"ok":1000,"max_ok_gas":21526,"sum_ok_gas":21526000,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":1000,"ok":1000,"max_ok_gas":185532,"sum_ok_gas":185532000,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":10445223,"ok":10445223,"max_ok_gas":151647,"sum_ok_gas":811927105393,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":1000,"ok":1000,"max_ok_gas":21530,"sum_ok_gas":21530000,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]},"valid":true,"search_run":{"elapsed":1255.1509127682075,"evaluations":6,"generations":1},"zero_mix_parity":{"seeds":[736000,736031],"n":32,"exact_rows_equal":true,"v10_gas":[{"role":"Baseline","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":21796,"sum_ok_gas":697472,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":345606,"ok":345606,"max_ok_gas":22592,"sum_ok_gas":7797875088,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":32,"ok":32,"max_ok_gas":21526,"sum_ok_gas":688832,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":220981,"sum_ok_gas":7071392,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":328945,"ok":328945,"max_ok_gas":190623,"sum_ok_gas":36375465434,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21594,"sum_ok_gas":691008,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}],"zero_mix_gas":[{"role":"Baseline","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":21796,"sum_ok_gas":697472,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":345606,"ok":345606,"max_ok_gas":22592,"sum_ok_gas":7797875088,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":32,"ok":32,"max_ok_gas":21526,"sum_ok_gas":688832,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":220981,"sum_ok_gas":7071392,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":328945,"ok":328945,"max_ok_gas":190626,"sum_ok_gas":36377204600,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21594,"sum_ok_gas":691008,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]},"notes":["CH calibration ran concurrently with the bounded search, sharing machine compute. No board claim. No seeds >=5000000 were used. This item reports local paired results only.","Pinned RS1 generator rebuilt code byte-for-byte: df2817ba4ec233a456eb45909faa4a706efe0fabd1734a908fe52545f4d07577. Pinned V10 code hash: cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245.","RS1 mix=0 matched V10 per-seed edge, reconstructed arbitrage edge and retail edge exactly on parity seeds 736000..736031 (32 seeds).","CMA-ES: numpy default_rng(14), population 10, mu=5, normalized bounded coordinates, initial sigma=0.18, clipped proposals, warm start RS1 weights/rate/size/retention/slope and cap=2 with activity_mix=0. Search CRN blocks of 64 seeds within 730000..733999. Timer checked before starting each evaluation; any in-flight evaluation finishes before stopping. The log records actual completed evaluations and generations.","Structure 2 uses separate rate/size weights and a cap on inverse missing-flow correction. The activity weight blends the fee contribution from slot 4 with cleaned rate times cleaned size times 0.015/(1-0.53); the original slot 4 state is retained. This is the explicit interpretation of cleaned rate in the activity term.","Best three valid search hashes were rechecked on all 256 seeds 734000..734255. The largest recheck mean vs V10 was frozen before running all three held-out arms on 735000..735511. No held-out selection or retuning.","Each arm independently ran against VanillaStrategy with run_batch(...,8), 10000 steps, configs built with default_rng(seed) draws size, rate, sigma in that order; simulation seed controls price seed=seed and retail seed=seed+1. No seed dropped.","Paired mean is candidate minus reference; SE is sample SD divided by sqrt(n); worst is the five smallest paired edge differences. Retail and arbitrage decomposition reconstructs preceding-step fees/reserves and arbitrage profits as in supplied harness. Gas is read from gas_stats after each chunk and aggregated for the submission role. Selected-hash gas combines search, recheck and held-out observations. Compilation uses pinned SolidityCompiler 0.8.24 viaIR optimizer 200, Paris.","All performance numbers are locally computed measurements, not external source claims. The sources identify the supplied algorithms, calibration contract and simulator configuration method.","The frozen strategy matched RS1 edge, retail edge and arbitrage edge exactly on all 512 held-out seeds: this search did not improve RS1. The selected parameters remain the RS1 warm start, with activity weight zero and cap two.","The 20-minute wall budget ended during the initial population; fewer than ten proposals completed, so no full initial population completed. The search code updates covariance only when at least mu=5 proposals complete; no subsequent population is evaluated after the wall budget. This is not a completed multi-generation optimization."]}