{"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 originalLambda = lambdaHat; uint256 originalSize = sizeHat;\n\n        if (342406799193418304 > 0) {\n            uint256 packedFlow = slots[15];\n            uint256 rate = uint80(packedFlow);\n            uint256 count = uint80(packedFlow >> 80);\n            uint256 meanSize = uint80(packedFlow >> 160);\n            if (rate == 0) rate = 400000000000000000;\n            if (meanSize == 0) meanSize = 2000000000000000;\n            if (isNewStep) {\n                uint256 inst = count / silent;\n                if (inst > 3 * WAD) inst = 3 * WAD;\n                uint256 retention = _powWad(999000000000000000, silent > 64 ? 64 : silent);\n                rate = wmul(rate, retention) + wmul(inst, WAD-retention);\n                count = 0;\n            }\n            uint256 weight = firstInStep ? WAD-arbProbability : WAD;\n            uint256 correctedWeight = weight;\n            if (2 == 2) {\n                uint256 missing = wmul(feeUsed, 196030880396139429888);\n                if (missing > 333333333333333376) missing = 333333333333333376;\n                correctedWeight = wdiv(weight, WAD-missing);\n            }\n            count += correctedWeight;\n            uint256 learning = wmul(WAD-999000000000000000, weight);\n            meanSize = _blend(meanSize, tradeRatio, learning);\n            slots[15]=rate | (count << 80) | (meanSize << 160);\n            uint256 retailRate = wmul(rate, 366383424913407168);\n            uint256 retailSize = 2 == 0 ? sizeHat : wmul(meanSize,1883296158119298304);\n            lambdaHat = _blend(lambdaHat,retailRate,342406799193418304);\n            sizeHat = _blend(sizeHat,retailSize,342406799193418304);\n        }\n        uint256 flowSize = wmul(lambdaHat, sizeHat);\n        uint256 fBase = BASE_FEE + wmul(wmul(SIGMA_COEF, sigmaHat), 836164282547267160) + wmul(wmul(LAMBDA_COEF, lambdaHat), 1173645092718954790) + wmul(wmul(FLOW_SIZE_COEF, flowSize), 1173645092718954790);\n        uint256 fMid = fBase + wmul(TOX_COEF, toxSignal) + wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal)) + wmul(wmul(ACT_COEF, actEma), 1173645092718954790);\n        fMid = fMid + wmul(wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal)), 836164282547267160);\n\n        fMid = fMid > 151739363253247 ? fMid - 151739363253247 : 0;\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":"9faa436b667bb9308ff9330df82dbc5dcf53e369d86ffd43f16f594f9e46f66c","params":[-0.16383571745273284,-0.17364509271895479,1.5173936325324675],"log":[{"params":[0.2763125565215532,0.3870028722399491,2.67592049833671],"n":64,"mean_diff":-8.679417171149925,"se":0.15089777049739,"fitness":-8.679417171149925,"generation":0,"index":0,"seeds":[930064,930127],"gas":{"max_ok":197708,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197209,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":59.24880865192972,"sha256":"80376e470073fc083c9973f9083bd37273452d561962f98b24de9993e32e1295"},{"params":[-0.476916924844111,0.38297840079725853,1.2472080268992887],"n":64,"mean_diff":-18.06050780437264,"se":0.26017890144564015,"fitness":-18.06050780437264,"generation":0,"index":1,"seeds":[930128,930191],"gas":{"max_ok":197812,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197288,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":54.65509981289506,"sha256":"842439d6d17933e7956476aa12b495954c6c9dbb5eda98f6c870f17be9e2a508"},{"params":[0.22570313850460222,-0.009230485828840118,0.9138676607224161],"n":64,"mean_diff":-0.2753447690880204,"se":0.07391709540071337,"fitness":-0.2753447690880204,"generation":0,"index":2,"seeds":[930192,930255],"gas":{"max_ok":197708,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197184,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":52.38553990400396,"sha256":"bf2f9e775ceb6dbb8f35bb16558a945d6ebb4c2af1c741ecd07249efaaaf06c2"},{"params":[2.4930679643062756,0.18313245781879361,0.6572384460794609],"n":64,"mean_diff":-54.845661984118436,"se":1.3462433014880817,"fitness":-54.845661984118436,"generation":0,"index":3,"seeds":[930256,930319],"gas":{"max_ok":200787,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200175,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":41.0860706618987,"sha256":"9b63c3987090e7ac389220c880ce276546e1500fa7358d9f1eafce1aeb11cf41"},{"params":[-0.44583808635945044,0.5964425104510906,0.6857987981264952],"n":64,"mean_diff":-30.30817408253253,"se":0.3394449809258121,"fitness":-30.30817408253253,"generation":0,"index":4,"seeds":[930320,930383],"gas":{"max_ok":197801,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197277,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":56.26897771283984,"sha256":"ada121456be4a166b2be21d2090ca1b4b2ebd9679abaa2dc4980195b01525d34"},{"params":[0.41468279935696617,-0.04182761981261718,0.19091452254548003],"n":64,"mean_diff":-1.986969279663784,"se":0.15871662777342074,"fitness":-1.986969279663784,"generation":0,"index":5,"seeds":[930384,930447],"gas":{"max_ok":202792,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200268,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":49.50645279092714,"sha256":"c5e2f1011f9afd223c69338491b512d4ccbf88cad64b40dd986ac33e4fc5b046"},{"params":[-0.031193533335624912,0.32173747393200003,2.205058745701699],"n":64,"mean_diff":-9.771880926153866,"se":0.18679613318682828,"fitness":-9.771880926153866,"generation":0,"index":6,"seeds":[930448,930511],"gas":{"max_ok":200781,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200257,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":53.11263355589472,"sha256":"58968467ca36e030a31cf6ca2eafab94fe5a3365352402b287e4bab7bdb884ed"},{"params":[1.0525484774182532,0.3384930238070539,-0.43469118195166345],"n":64,"mean_diff":-3.325705087002788,"se":0.19298511233396368,"fitness":-3.325705087002788,"generation":1,"index":7,"seeds":[930512,930575],"gas":{"max_ok":200746,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200233,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":49.062997553963214,"sha256":"05d48a8b064e4e618ff7bd1a220973f56d4a88f3d59f71f343a5e01f00096268"},{"params":[1.4452415141925283,0.15618215635080968,0.11701337493050445],"n":64,"mean_diff":-13.496918381622995,"se":0.3858157528720198,"fitness":-13.496918381622995,"generation":1,"index":8,"seeds":[930576,930639],"gas":{"max_ok":200768,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200244,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":46.745946190087125,"sha256":"1e5d84219b2eeb53111efe5d037f698b1df0aee7c412fc5bfa1dbfdc0bfe31e2"},{"params":[0.1020320681552529,-0.46942727476784923,1.6839614791918889],"n":64,"mean_diff":-3.9263226981302495,"se":0.2515062927346365,"fitness":-3.9263226981302495,"generation":1,"index":9,"seeds":[930640,930703],"gas":{"max_ok":200947,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197195,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":48.85248692985624,"sha256":"f50c3b8ac954e06b173e318e25e4b82fc926073ee34c9a7c7dc3ee397e57b255"},{"params":[-0.36594566120184524,0.4256555500022714,-0.181936989154877],"n":64,"mean_diff":-13.430658279242344,"se":0.2208933655446938,"fitness":-13.430658279242344,"generation":1,"index":10,"seeds":[930704,930767],"gas":{"max_ok":197778,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200175,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":52.98892160807736,"sha256":"1491125c887877c56806c57fd7ddd9bd1d408989fcfc5364745d1af56a741ed4"},{"params":[0.7308736546662984,0.037001042972161446,-0.11367426597760955],"n":64,"mean_diff":-4.116393572414534,"se":0.24192468845453916,"fitness":-4.116393572414534,"generation":1,"index":11,"seeds":[930768,930831],"gas":{"max_ok":197790,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197277,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":48.714902063133195,"sha256":"8baa70a7dee60b9e442cb80ba62d84e0eee9ce30e4e3297ad4cc16c92b2c8627"},{"params":[0.2945076707480898,0.08731713736569768,1.422086576586667],"n":64,"mean_diff":-0.35235912812680414,"se":0.04049159969247052,"fitness":-0.35235912812680414,"generation":1,"index":12,"seeds":[930832,930895],"gas":{"max_ok":200687,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200163,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":51.6101866599638,"sha256":"280d2daa2e49e9524a16edc48b1667a1010ff2af370795f94ae6c673011450e9"},{"params":[0.05014274876457614,-0.08553193765187717,0.29299196114621884],"n":64,"mean_diff":-0.32463674136970333,"se":0.06644036441274512,"fitness":-0.32463674136970333,"generation":1,"index":13,"seeds":[930896,930959],"gas":{"max_ok":200687,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200163,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":51.42061585187912,"sha256":"98adf19953b1b2628bc0be22e2dc5a0edfb5441801a93564474ad4bf397a0907"},{"params":[0.20412518147446357,0.16804412697287208,0.5131711140813398],"n":64,"mean_diff":-0.6237448430842862,"se":0.06812384984842028,"fitness":-0.6237448430842862,"generation":2,"index":14,"seeds":[930960,931023],"gas":{"max_ok":200781,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200257,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":53.12900953600183,"sha256":"c011d871fd2a1a078c365313353a869ac76d6827944bdb8a310100499b03b7f2"},{"params":[0.2999139291369932,0.1447776225208144,2.122593105789125],"n":64,"mean_diff":-1.1034423377069738,"se":0.08445781208010865,"fitness":-1.1034423377069738,"generation":2,"index":15,"seeds":[931024,931087],"gas":{"max_ok":197708,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197184,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":52.78150170110166,"sha256":"2736cbdf0844deda2896e4e0d012f6677107d9838d17930c34258eb45643516e"},{"params":[-0.3405139702622635,-0.11906759853651061,0.48015797686512274],"n":64,"mean_diff":-0.17785374664152354,"se":0.06298353817582497,"fitness":-0.17785374664152354,"generation":2,"index":16,"seeds":[931088,931151],"gas":{"max_ok":197789,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197265,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":50.60398630495183,"sha256":"6687e536076f38c6c4358527e4b118e09e076155d997065a33b7b23c4c7b8199"},{"params":[0.19461384213603017,0.3218003378419029,0.6947417823157749],"n":64,"mean_diff":-3.1244151939527116,"se":0.12944074286518992,"fitness":-3.1244151939527116,"generation":2,"index":17,"seeds":[931152,931215],"gas":{"max_ok":200688,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200164,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":50.40388833801262,"sha256":"2ddf0bf9d1d09df8427d4df46165a2b3eb11eff89a0fca979123c46044be77b7"},{"params":[0.0531571956964888,-0.11443187876865157,0.9309428795265982],"n":64,"mean_diff":-0.2240263181257678,"se":0.07034613229734918,"fitness":-0.2240263181257678,"generation":2,"index":18,"seeds":[931216,931279],"gas":{"max_ok":203015,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":202491,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":49.94577785115689,"sha256":"ffceca0ed488d8c520ab2fc08f46316b4723c37346f4338ffe226cc7b53ea65f"},{"params":[0.1096109908347297,-0.16109596808587273,-0.5288448188836288],"n":64,"mean_diff":-1.7680279274870943,"se":0.17073928871088445,"fitness":-1.7680279274870943,"generation":2,"index":19,"seeds":[931280,931343],"gas":{"max_ok":197801,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197288,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":49.40709833218716,"sha256":"cf4d3d7ea00319d268e6f04fbfeeccf45fe80ee96ed756bd33cc2b272d471512"},{"params":[-0.16383571745273284,-0.17364509271895479,1.5173936325324675],"n":64,"mean_diff":-0.005589592783615593,"se":0.04982043955545807,"fitness":-0.005589592783615593,"generation":2,"index":20,"seeds":[931344,931407],"gas":{"max_ok":200700,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":200176,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":51.46001338795759,"sha256":"9faa436b667bb9308ff9330df82dbc5dcf53e369d86ffd43f16f594f9e46f66c"},{"params":[-0.2785845099541334,0.2686265642749217,0.5709703799317918],"n":64,"mean_diff":-7.312664530848828,"se":0.1673273038759799,"fitness":-7.312664530848828,"generation":3,"index":21,"seeds":[931408,931471],"gas":{"max_ok":198146,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":199202,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":53.86237752600573,"sha256":"993dc3284842eab9fd9817f9c98cc0a1a6b6000d3a953bc10014a1cd2d4335fd"},{"params":[-0.48355765189711397,-0.4158213008275922,0.5834387078490924],"n":64,"mean_diff":-0.4144164525489691,"se":0.10266723468989324,"fitness":-0.4144164525489691,"generation":3,"index":22,"seeds":[931472,931535],"gas":{"max_ok":197801,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197277,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":50.334790769033134,"sha256":"78a2d6a8d82e825ed9698c91b4dc58fa6c278d828a4de749e8f59b49cda63f8b"},{"params":[-0.30891758431688243,-0.39560408060649066,0.8988108210020425],"n":64,"mean_diff":-0.7191882251918669,"se":0.11711896455347749,"fitness":-0.7191882251918669,"generation":3,"index":23,"seeds":[931536,931599],"gas":{"max_ok":198849,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":198364,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":50.331948986975476,"sha256":"463acdcdbd0d5ae5e4ce7aa018a5b966c847fd10a3e2c1752886ee1c510c2fdb"},{"params":[0.09951780307760161,0.27797804255289205,0.9623579072657726],"n":64,"mean_diff":-3.633258318779447,"se":0.12038099289319285,"fitness":-3.633258318779447,"generation":3,"index":24,"seeds":[931600,931663],"gas":{"max_ok":197696,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197172,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":51.95517724216916,"sha256":"d977a286bd7d8971ac5bfd6afe2012f3cdca3aeb1904334ef80bfab927c739df"},{"params":[0.6909121302508265,-0.42643683503044505,0.9879339557959375],"n":64,"mean_diff":-10.492697041196521,"se":0.43016197535601286,"fitness":-10.492697041196521,"generation":3,"index":25,"seeds":[931664,931727],"gas":{"max_ok":197812,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":198608,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":46.83852229011245,"sha256":"63de1c9ae41f1a18f18ccc8c119b12097eca5af35e282957f06832e706520a30"},{"params":[-0.1329974074851547,0.3220779487861152,0.9598538614649348],"n":64,"mean_diff":-8.42323010245783,"se":0.1598709121646535,"fitness":-8.42323010245783,"generation":3,"index":26,"seeds":[931728,931791],"gas":{"max_ok":190161,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":193824,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":53.601035765139386,"sha256":"5e7ea5830c659c17a93fe59245c887fa4838f6a0d4ad85a51baf24d130c38946"},{"params":[-0.21566720935755013,-0.49900716815483454,1.5761762636370142],"n":64,"mean_diff":-1.5281707793010542,"se":0.18218296056960984,"fitness":-1.5281707793010542,"generation":3,"index":27,"seeds":[931792,931855],"gas":{"max_ok":197695,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":197171,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":48.915011040866375,"sha256":"4c219d97e679f1516a1b36dfbb5d9c938e65c66450f5cdf76eac8ceb30590e7a"},{"params":[-0.4986562284648844,-0.05511661212581609,-1.9306974783104287],"n":64,"mean_diff":-0.11373117649021491,"se":0.05774270526654039,"fitness":-0.11373117649021491,"generation":4,"index":28,"seeds":[931856,931919],"gas":{"max_ok":199172,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2_gas":{"max_ok":198980,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"seconds":49.96690475498326,"sha256":"6562efd85359a01a9147b11be6cbfc298b919128f7fa25b2b0392cd36b761f72"}],"recheck":{"seeds":[933000,933255],"candidates":[{"params":[-0.16383571745273284,-0.17364509271895479,1.5173936325324675],"search_index":20,"search_mean_diff":-0.005589592783615593,"vs_rs2":{"n":256,"mean_diff":-0.0009811337255314356,"se":0.021435651630418332,"worst":[{"seed":933216,"d":-1.2400223071566643},{"seed":933233,"d":-1.150508503455626},{"seed":933206,"d":-1.121042147768776},{"seed":933085,"d":-1.1106928290414544},{"seed":933056,"d":-1.003888495006322}]},"gas":{"max_ok":202910,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"sha256":"9faa436b667bb9308ff9330df82dbc5dcf53e369d86ffd43f16f594f9e46f66c"},{"params":[-0.4986562284648844,-0.05511661212581609,-1.9306974783104287],"search_index":28,"search_mean_diff":-0.11373117649021491,"vs_rs2":{"n":256,"mean_diff":-0.08932599925136397,"se":0.031281245540167806,"worst":[{"seed":933184,"d":-1.4025687712343142},{"seed":933233,"d":-1.3531653898353397},{"seed":933166,"d":-1.2898743278636857},{"seed":933180,"d":-1.1472690770170857},{"seed":933049,"d":-1.0794675693060753}]},"gas":{"max_ok":202899,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"sha256":"6562efd85359a01a9147b11be6cbfc298b919128f7fa25b2b0392cd36b761f72"},{"params":[-0.3405139702622635,-0.11906759853651061,0.48015797686512274],"search_index":16,"search_mean_diff":-0.17785374664152354,"vs_rs2":{"n":256,"mean_diff":-0.17777297413400062,"se":0.030774509874993583,"worst":[{"seed":933180,"d":-1.637920166256663},{"seed":933206,"d":-1.5879852204265035},{"seed":933184,"d":-1.4915176740084917},{"seed":933049,"d":-1.309482911714099},{"seed":933094,"d":-1.2246762465672418}]},"gas":{"max_ok":202910,"init_max_ok":243099,"oog":0,"other_halts":0},"valid":true,"sha256":"6687e536076f38c6c4358527e4b118e09e076155d997065a33b7b23c4c7b8199"}],"rs2_gas":{"max_ok":202386,"init_max_ok":243099,"oog":0,"other_halts":0}},"held_out":{"seeds":[934000,934511],"vs_rs2":{"n":512,"mean_diff":-0.03716374129388622,"se":0.017536324390119,"worst":[{"seed":934172,"d":-2.1076599411775305},{"seed":934147,"d":-1.8438348548268664},{"seed":934490,"d":-1.6649228500199342},{"seed":934282,"d":-1.6059945909011049},{"seed":934307,"d":-1.3405661482477171}]},"retail_edge_delta":{"mean":-0.39612494948503507,"se":0.018484935885295366},"arb_edge_delta":{"mean":0.358961208191148,"se":0.010429564792701192},"reconciliation_max_abs":1.4210854715202004e-13,"arm_mean_edge":{"frozen":528.3813995994826,"rs2":528.4185633407767},"gas":{"frozen":{"max_ok":200781,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2":{"max_ok":200257,"init_max_ok":243099,"oog":0,"other_halts":0}},"valid":true},"gas":{"max_ok":202910,"init_max_ok":243099,"oog":0,"other_halts":0,"all_tested":{"max_ok":203015,"init_max_ok":243099,"oog":0,"other_halts":0},"search_max_ok":203015,"search_oog":0},"parity":{"seeds":[934600,934631],"n":32,"source_equal":true,"bytecode_equal":true,"exact_equal_edges":true,"exact_equal_step_traces":true,"max_abs_diff":0.0,"gas":{"overlay_off":{"max_ok":197184,"init_max_ok":243099,"oog":0,"other_halts":0},"rs2":{"max_ok":197184,"init_max_ok":243099,"oog":0,"other_halts":0}},"valid":true,"paired":{"n":32,"mean_diff":0.0,"se":0.0,"worst":[{"seed":934600,"d":0.0},{"seed":934601,"d":0.0},{"seed":934602,"d":0.0},{"seed":934603,"d":0.0},{"seed":934604,"d":0.0}]}},"generator_source":"from decimal import Decimal, ROUND_HALF_EVEN\n\ndef generate(base, p):\n    \"\"\"Fee-level overlay on the exact pinned RS2 source; a,b dimensionless, c in bps.\"\"\"\n    a, b, c = (Decimal(str(x)) for x in p)\n    assert Decimal('-.5') <= a <= 3\n    assert Decimal('-.5') <= b <= 1\n    assert -2 <= c <= 3\n    s = base\n    for value, factor, terms in [\n        (a, 1+a, ['wmul(SIGMA_COEF, sigmaHat)', 'wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal))']),\n        (b, 1-b, ['wmul(LAMBDA_COEF, lambdaHat)', 'wmul(FLOW_SIZE_COEF, flowSize)', 'wmul(ACT_COEF, actEma)'])\n    ]:\n        if value == 0:\n            continue\n        fixed = int((factor * 10**18).to_integral_value(rounding=ROUND_HALF_EVEN))\n        for term in terms:\n            assert s.count(term) == 1, term\n            s = s.replace(term, f'wmul({term}, {fixed})')\n    offset = int((abs(c) * 10**14).to_integral_value(rounding=ROUND_HALF_EVEN))\n    if offset:\n        marker = '        lambdaHat = originalLambda; sizeHat = originalSize;'\n        assert s.count(marker) == 1\n        line = (f'        fMid = fMid > {offset} ? fMid - {offset} : 0;\\n' if c > 0\n                else f'        fMid += {offset};\\n')\n        s = s.replace(marker, line + marker)\n    # No state, initialization, estimator, skew, clamp or routing changes.\n    return s\n","notes":{"parameter_order":["a","b","c_bps"],"overlay":"Only fMid fee level changes: sigma contributions multiplied by 1+a; flow contributions by 1-b; then c bps subtracted with a saturating floor at zero. Each multiplier is rounded to nearest WAD integer, ties to even. No new storage writes or changes to afterInitialize; c does not change initial quoted fees.","rs2_sha256":"f24b6ca198b744c380842c3a17964a6dc21f311bb04984b26733afa3fee8eaf2","rs2_source":"https://api.imdnotdead.fun/artifacts/19f2ec857df536e8ab62ab1da89ec6623332521ce46849f15bccff402c63e1e5","measurement_source":"https://api.imdnotdead.fun/artifacts/33f54e81f3372088e9eced52c0174f310ac348af98ef5727b73785c088679194","simulator_commit":"6b6921f8d463314aa7c96234e1be25a25245f704","simulator_wheel_sha256":"aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a","frozen_amm_match_validate":"passed","compiler":"solc 0.8.24, optimizer runs=200, viaIR=true, evmVersion=paris, pinned SolidityCompiler","method":"Each arm runs alone against VanillaStrategy via run_batch(arm, VanillaStrategy, configs, 8). Configs sample default_rng(seed) in size, rate, sigma order; 10,000 steps; price seed=seed; retail seed=seed+1. Batches chunked at 16 seeds to bound memory. Gas counters reset before each batch and aggregated per arm. Halt or gas-limit violation makes search fitness -1000. Paired SE uses sample SD / sqrt(n); worst lists five smallest per-seed edge differences.","decomposition":"Held-out retail/arb split uses decomposition() from the cited harness, reconstructed from per-step fair price, spot and fees; retail=edge-arb. This is the harness reconstruction, not a separately instrumented trade-type counter.","calibration":{"mean_edge":525.5258821780834,"expected":525.5258821780834,"exact_match":true},"parity_definition":"generate(RS2,[0,0,0]) returns the exact RS2 source; separate simulations on all 32 parity seeds additionally check bytecode, edges and hashes of every step timestamp, fair price, both spots, fees and PnLs.","search":{"cma_seed":51,"cma_package":"4.5.0","numpy_version":"2.5.4","bounds":[[-0.5,3],[-0.5,1],[-2,3]],"initial_params":[0.5,0.35,1.3],"normalized_sigma":0.22,"population":7,"evaluations":29,"seconds":1479.2795853449497,"stop":"25-minute budget or assigned seed range","fresh_block_per_evaluation":true,"smoke_seed":930000,"first_search_seed":930064},"freeze":{"params":[-0.16383571745273284,-0.17364509271895479,1.5173936325324675],"sha256":"9faa436b667bb9308ff9330df82dbc5dcf53e369d86ffd43f16f594f9e46f66c","selection":"highest valid 256-seed recheck paired mean","recheck_index":0},"gas_scope":"Primary gas fields cover the frozen candidate across its search, recheck and held-out runs: Submission callback maxima, with all-role halt counts within those runs. all_tested covers every search, recheck, held-out and parity arm, including RS2. CH calibration and presearch one-seed smoke are excluded. Per-arm held-out gas is in held_out.gas. The smoke had zero OutOfGas calls and zero other halts.","selection":"Best three valid search means rechecked on the same 256-seed block; highest valid recheck mean frozen before opening the held-out block. No held-out tuning or selection.","limitations":"One CMA-ES run with a fixed seed and time budget; the search does not establish a global optimum. Reported gas maxima apply to tested calls.","board_claim":"None. All experiment seeds are below 5,000,000 under this item-specific restriction. No STACK confirmation or board submission was performed.","measurement_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_driver_source":"from engine import *\nfrom generate import generate\nimport cma\n\nassert json.loads(Path('scratch/calibration.json').read_text())['exact_match']\nlow=np.array([-.5,-.5,-2.]);width=np.array([3.5,1.5,5.])\ndef decode(x):return [float(v) for v in low+width*np.asarray(x)]\nes=cma.CMAEvolutionStrategy(((np.array([.5,.35,1.3])-low)/width).tolist(),.22,\n    dict(seed=51,bounds=[0,1],popsize=7,verbose=-9,maxiter=100))\nstarted=time.monotonic();log=[];eval_times=[];block=0\nfor generation in range(6):\n    points=es.ask(); fitness=[]\n    for x in points:\n        elapsed=time.monotonic()-started\n        estimate=max(eval_times[-5:] or [75])\n        if block>=45 or elapsed+1.25*estimate>1500:\n            save('scratch/search.json',dict(log=log,seconds=elapsed,generations=generation,stop='25-minute budget or assigned seed range'))\n            print('SEARCH FINISHED',len(log),elapsed,flush=True);sys.exit(0)\n        p=decode(x);source=generate(BASE,p);start=930064+64*block;t=time.monotonic()\n        ref=run(BASE,start,64)\n        candidate=run(source,start,64)\n        m=paired(candidate,ref);valid=ref['valid'] and candidate['valid']\n        score=m['mean_diff'] if valid else -1000.\n        entry=dict(params=p,n=64,mean_diff=m['mean_diff'],se=m['se'],fitness=score,\n           generation=generation,index=block,seeds=[start,start+63],gas=candidate['gas'],rs2_gas=ref['gas'],valid=valid,\n           seconds=time.monotonic()-t,sha256=candidate['sha256'])\n        log.append(entry);fitness.append(-score);eval_times.append(entry['seconds']);block+=1\n        save(f'scratch/eval_{block:02}.json',dict(candidate=candidate,rs2=ref))\n        save('scratch/search.json',dict(log=log,seconds=time.monotonic()-started,generations=generation,stop=None))\n        print(json.dumps(entry),flush=True)\n    es.tell(points,fitness)\nsave('scratch/search.json',dict(log=log,seconds=time.monotonic()-started,generations=6,stop='six full generations'))\nprint('SEARCH FINISHED',len(log),time.monotonic()-started,flush=True)\n","local_engine_source":"import sys, time, json, hashlib, gc\nfrom pathlib import Path\nimport numpy as np\nimport amm_sim_rs as sim\nfrom amm_competition.evm.compiler import SolidityCompiler\nsys.path.insert(0, str(Path(__file__).resolve().parents[2]))\nfrom method_harness_source import configs, decomposition, aggregate, compare, stats\nC=SolidityCompiler()\nV=C.compile(Path('contracts/src/VanillaStrategy.sol').read_text(),'VanillaStrategy')\nassert V.success,V.errors\nBASE=Path('../rs2_code.txt').read_text()\nCACHE={}\ndef compile_source(source):\n    h=hashlib.sha256(source.encode()).hexdigest()\n    if h not in CACHE:\n        comp=C.compile(source);assert comp.success,comp.errors\n        CACHE[h]=comp\n    return CACHE[h]\ndef gas_summary(raw):\n    return dict(max_ok=max([r.get('max_ok_gas',0) for r in raw if r['role']=='Submission' and r['callback']=='afterSwap'] or [0]),\n       init_max_ok=max([r.get('max_ok_gas',0) for r in raw if r['role']=='Submission' and r['callback']=='afterInitialize'] or [0]),\n       oog=sum(r.get('oog',0) for r in raw),\n       other_halts=sum(r.get(k,0) for r in raw for k in ['revert','other_halt','tx_error','bad_return']))\ndef run(source,start,n,detail=False,trace=False,label=''):\n    t=time.monotonic();comp=compile_source(source);rows=[];chunks=[]\n    for first in range(start,start+n,16):\n        count=min(16,start+n-first);sim.gas_stats_reset()\n        batch=sim.run_batch(list(comp.bytecode),list(V.bytecode),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            row=dict(seed=r.seed,edge=r.edges['submission'])\n            if detail: row['arb'],row['retail']=decomposition(r)\n            if trace:\n                h=hashlib.sha256()\n                for st in r.steps:\n                    h.update(repr((st.timestamp,st.fair_price,sorted(st.spot_prices.items()),sorted(st.fees.items()),sorted(st.pnls.items()))).encode())\n                row['trace']=h.hexdigest()\n            rows.append(row)\n        chunks.append({'raw':sim.gas_stats()})\n        del results,batch\n        if label and ((first-start)%64==0 or first+count==start+n):\n            print(json.dumps(dict(progress=label,done=first+count-start,n=n,seconds=round(time.monotonic()-t,2))),flush=True)\n    raw=aggregate(chunks)\n    out=dict(sha256=hashlib.sha256(source.encode()).hexdigest(),rows=sorted(rows,key=lambda x:x['seed']),raw_counters=raw,gas=gas_summary(raw),seconds=time.monotonic()-t)\n    g=out['gas'];out['valid']=g['oog']==0 and g['other_halts']==0 and g['max_ok']<235000 and g['init_max_ok']<245000\n    return out\n\ndef paired(a,b):\n    aa={x['seed']:x['edge'] for x in a['rows']};bb={x['seed']:x['edge'] for x in b['rows']};assert aa.keys()==bb.keys()\n    seeds=sorted(aa);d=np.array([aa[s]-bb[s] for s in seeds]);st=stats(d)\n    return dict(n=len(d),mean_diff=st['mean'],se=st['se'],worst=[dict(seed=seeds[i],d=float(d[i])) for i in np.argsort(d)[:5]])\ndef save(path,obj):Path(path).write_text(json.dumps(obj,allow_nan=False))\n","decision":"No clear held-out improvement over RS2 in this run; retain RS2 rather than promote this candidate. The exact point estimate and standard error are reported above."}}