{"blocked":null,"status":"complete","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 (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 > WAD/2) missing = WAD/2;\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        }\n        uint256 flowSize = wmul(lambdaHat, sizeHat);\n        uint256 fBase = BASE_FEE + wmul(SIGMA_COEF, sigmaHat) + wmul(LAMBDA_COEF, lambdaHat) + wmul(FLOW_SIZE_COEF, flowSize);\n        uint256 fMid = fBase + wmul(TOX_COEF, toxSignal) + wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal)) + wmul(ACT_COEF, actEma);\n        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal));\n\n        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":"df2817ba4ec233a456eb45909faa4a706efe0fabd1734a908fe52545f4d07577","seeds_kind":"tuning","reference":{"name":"V10","sha256":"cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245","url":"https://api.imdnotdead.fun/artifacts/33f54e81f3372088e9eced52c0174f310ac348af98ef5727b73785c088679194","verified":true},"mechanism":"V10 posterior returns its existing first-print arb probability without modifying posterior math. Retail weight is 1-prob on first prints and 1 on later prints. One packed slot holds an own-pool count/rate and weighted first size moment. Timestamp gaps decay the rate. Family 0 changes fee lambda only; family 1 also changes fee size; family 2 adds bounded fee-dependent missing-own-flow correction (inverse survival, capped at 2x). Original lambda/size state is restored after fee construction; price, stale, toxicity, directional and activity updates remain V10. This does not identify total market arrival rate.","parameter_names":["structure (0=count,1=count+size,2=bounded correction)","mix","retention_per_step","rate_scale","size_scale","quote_correction_slope"],"params":[2,0.16509179839500446,0.9909893448132306,0.6684959838546022,1.5946627692375024,80.0],"parameter_count":6,"search":{"method":"Seed-402 bounded evolutionary random search: initial uniform draws, then Gaussian mutations of the best valid parent within each structure. Three rotating 32-seed blocks. Two trials per structure per block.","log":[{"params":[0,0.2986014931560619,0.9877857244953427,0.9383586864192068,0.8778191357174046,69.93049558120083],"start":650010,"n":32,"sha256":"fb2570614c5931599449f4951844aeaecdcb57b9f3539febbfe2ba07ea2a3095","valid":true,"paired":{"n":32,"mean_diff":-0.7357136567362961,"se":0.13578600119034234,"worst":[{"seed":650030,"d":-2.309829808212271}]},"retail_edge_delta":{"mean":1.4929700589618484,"se":0.1320396481166428},"arb_edge_delta":{"mean":-2.228683715698144,"se":0.044760827022635785},"reconciliation_max_abs":1.1368683772161603e-13,"gas":{"max_ok":198151,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[0,0.12234817670788067,0.9485785515704916,1.6353235652581364,0.940208776753678,46.667682583161465],"start":650010,"n":32,"sha256":"4fdc5b301c1bd848c0698a66204817fdabadbb094e869f30387bcbf34db47651","valid":true,"paired":{"n":32,"mean_diff":-0.05553049034642754,"se":0.04721423050543607,"worst":[{"seed":650017,"d":-0.5478519426199}]},"retail_edge_delta":{"mean":0.012483031852912774,"se":0.049107788512007595},"arb_edge_delta":{"mean":-0.06801352219933854,"se":0.026827971699530436},"reconciliation_max_abs":7.815970093361102e-14,"gas":{"max_ok":198067,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[1,0.7367922571451401,0.9813797692627302,0.8807445864232928,1.4494645833018374,47.653415467215645],"start":650010,"n":32,"sha256":"e7c2ce42bc24cb931ac1feab0e92cbb41f6a01a0ca3ccf4b3dbc2d8c9b1e2b1e","valid":true,"paired":{"n":32,"mean_diff":-0.45224126880622784,"se":0.1587512085620873,"worst":[{"seed":650035,"d":-2.26889988519315}]},"retail_edge_delta":{"mean":2.0585246277170057,"se":0.13033076073100508},"arb_edge_delta":{"mean":-2.5107658965232327,"se":0.07769732839166862},"reconciliation_max_abs":1.1368683772161603e-13,"gas":{"max_ok":198286,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[1,0.7959932144563971,0.9729840660496506,0.6227153483220847,1.2782736800439518,57.37618866839522],"start":650010,"n":32,"sha256":"a9dea7cb2190b7d07607bb251f56454553e0195e881bf493aeaa919dbcf3aaf5","valid":true,"paired":{"n":32,"mean_diff":-3.0415749508152903,"se":0.30384865340950795,"worst":[{"seed":650040,"d":-6.549989328000095}]},"retail_edge_delta":{"mean":3.515222100669888,"se":0.3086896445238771},"arb_edge_delta":{"mean":-6.556797051485171,"se":0.10486636856344256},"reconciliation_max_abs":8.526512829121202e-14,"gas":{"max_ok":195133,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[2,0.6462408078412729,0.9632225294993331,0.6234315963027439,1.5033798279091801,21.090309028625157],"start":650010,"n":32,"sha256":"c1cdc10713876bbf607ae129302033a9a72b6f0382f2187a874d29797f17fd68","valid":true,"paired":{"n":32,"mean_diff":-0.8399606984642638,"se":0.18656569109410281,"worst":[{"seed":650027,"d":-2.6720535077305385}]},"retail_edge_delta":{"mean":2.324700523792373,"se":0.18185063596643256},"arb_edge_delta":{"mean":-3.1646612222566404,"se":0.06406953779881212},"reconciliation_max_abs":9.947598300641403e-14,"gas":{"max_ok":195480,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[2,0.2770928799252277,0.9627057340597865,1.0206312769804715,1.6515234967661563,79.38593185653228],"start":650010,"n":32,"sha256":"4cd7f80d3a4bf781202c929314cdfb99488f699ef28ac27759630180ba3e89ff","valid":true,"paired":{"n":32,"mean_diff":-0.42244912166763093,"se":0.12859861323196378,"worst":[{"seed":650021,"d":-1.8636367669223546}]},"retail_edge_delta":{"mean":-2.04352790461599,"se":0.17555411208569424},"arb_edge_delta":{"mean":1.6210787829483537,"se":0.08124627063911444},"reconciliation_max_abs":7.815970093361102e-14,"gas":{"max_ok":198849,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[0,0.05,0.974287947678028,1.3414812344318912,1.0012734491424045,26.826843958307318],"start":650042,"n":32,"sha256":"2cb16d6c41afb0ab9f162a6c6e07215de163794e1426780cbedad6eac1c3b2b0","valid":true,"paired":{"n":32,"mean_diff":0.007277086370880426,"se":0.036293343967516954,"worst":[{"seed":650066,"d":-0.7808178748595083}]},"retail_edge_delta":{"mean":0.16574610135054613,"se":0.03307237903215923},"arb_edge_delta":{"mean":-0.15846901497966104,"se":0.010497042035332952},"reconciliation_max_abs":7.105427357601002e-14,"gas":{"max_ok":201982,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[0,0.05,0.984340390961588,1.603734633079657,0.9417118765460197,11.034043104413806],"start":650042,"n":32,"sha256":"cc5d72a8e1c340161363d9135cd8706a07b77975f7bf2b9b20ab23d88608005f","valid":true,"paired":{"n":32,"mean_diff":-0.027510222409786067,"se":0.023016354858205332,"worst":[{"seed":650060,"d":-0.3373198023328996}]},"retail_edge_delta":{"mean":0.022485194080955395,"se":0.02440576933311016},"arb_edge_delta":{"mean":-0.04999541649073025,"se":0.010757228186623976},"reconciliation_max_abs":9.947598300641403e-14,"gas":{"max_ok":201982,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[1,0.5297408755420783,0.9894109681292208,1.1430530419540974,1.603603189672029,70.42413558958151],"start":650042,"n":32,"sha256":"426041750277a0255bb6924d96781e235b3a799c16af2e295ae1e717f2be7fdd","valid":true,"paired":{"n":32,"mean_diff":-0.22356193906015953,"se":0.12890967057733482,"worst":[{"seed":650060,"d":-2.414794525388288}]},"retail_edge_delta":{"mean":-0.6155139589334517,"se":0.174361897972689},"arb_edge_delta":{"mean":0.39195201987329653,"se":0.07671091936986364},"reconciliation_max_abs":7.105427357601002e-14,"gas":{"max_ok":202097,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[1,0.6810198258223017,0.9877083660399961,1.1242335637954521,1.5517332556137993,58.64356999787142],"start":650042,"n":32,"sha256":"57eeeeda5b3cfeabdbd18c3d1da4b53ffbf4a9e464572e2e96dc902ab83b7fd9","valid":true,"paired":{"n":32,"mean_diff":-0.23390192461870463,"se":0.12022152543216162,"worst":[{"seed":650060,"d":-1.8921386548845476}]},"retail_edge_delta":{"mean":-0.1901103172205989,"se":0.1853704025891634},"arb_edge_delta":{"mean":-0.04379160739809862,"se":0.09449743845551056},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":202097,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[2,0.15845359651290036,0.9697116068000732,0.8909084321412568,1.7,58.599794632257115],"start":650042,"n":32,"sha256":"1c349b196e7d3ee0890eec128de05346ceb5c587032353cfbbba1113552dae90","valid":true,"paired":{"n":32,"mean_diff":0.019563473624074845,"se":0.06671893009406792,"worst":[{"seed":650056,"d":-0.6404747391144383}]},"retail_edge_delta":{"mean":-0.5332834839023519,"se":0.08692932889325915},"arb_edge_delta":{"mean":0.5528469575264369,"se":0.040366378393370594},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":202468,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[2,0.16509179839500446,0.9909893448132306,0.6684959838546022,1.5946627692375024,80.0],"start":650042,"n":32,"sha256":"df2817ba4ec233a456eb45909faa4a706efe0fabd1734a908fe52545f4d07577","valid":true,"paired":{"n":32,"mean_diff":0.10624659680053128,"se":0.07539634366105952,"worst":[{"seed":650060,"d":-0.6518207922603096}]},"retail_edge_delta":{"mean":0.11511770212618622,"se":0.08470003650841776},"arb_edge_delta":{"mean":-0.0088711053256475,"se":0.023430130618825592},"reconciliation_max_abs":9.237055564881302e-14,"gas":{"max_ok":202468,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[0,0.05,0.9728105270413419,1.4170794484519622,1.3232972129815381,64.39956769892927],"start":650074,"n":32,"sha256":"3db820fa356c6f2f953683542993b52fc802c810c03ac856970f97b035f9b95a","valid":true,"paired":{"n":32,"mean_diff":0.008132995385754072,"se":0.039663643452373214,"worst":[{"seed":650084,"d":-0.5374620904933636}]},"retail_edge_delta":{"mean":0.1149206427988787,"se":0.04063886601210785},"arb_edge_delta":{"mean":-0.10678764741313462,"se":0.013735501301156819},"reconciliation_max_abs":9.237055564881302e-14,"gas":{"max_ok":196846,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[0,0.05,0.9780854877626458,1.5271815658669454,1.0289074209778577,57.79504611774682],"start":650074,"n":32,"sha256":"36561c1dd5f97fa4e65c3f4ac13f13e5d2b89624155697cab7eb8ed011619fc1","valid":true,"paired":{"n":32,"mean_diff":-0.0157884094911509,"se":0.03136901022039032,"worst":[{"seed":650084,"d":-0.5335670701973072}]},"retail_edge_delta":{"mean":0.04698357678492293,"se":0.03524021650855936},"arb_edge_delta":{"mean":-0.0627719862760654,"se":0.014034068692010486},"reconciliation_max_abs":9.237055564881302e-14,"gas":{"max_ok":196846,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[1,0.48339037908401983,0.995,1.036912240793126,1.7,56.35828782020131],"start":650074,"n":32,"sha256":"06db47c81be507124ec65a4f784c711175b58b0bf5284f46e789dcf3562ec735","valid":true,"paired":{"n":32,"mean_diff":-0.09643788410620857,"se":0.10922773808384507,"worst":[{"seed":650078,"d":-1.9120877842035497}]},"retail_edge_delta":{"mean":-0.24806903230631505,"se":0.12534594860677045},"arb_edge_delta":{"mean":0.15163114820009949,"se":0.05591938282392735},"reconciliation_max_abs":8.881784197001252e-14,"gas":{"max_ok":196961,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[1,0.4321431354353576,0.9893074063381272,0.999864930545884,1.632548477827359,64.32249646539876],"start":650074,"n":32,"sha256":"f93775cf7c664f70ab9fbfd52715c5159ea30b35610ff0e383a8ce0fd7978361","valid":true,"paired":{"n":32,"mean_diff":-0.001486546329886096,"se":0.09316863446014319,"worst":[{"seed":650078,"d":-1.503701030219986}]},"retail_edge_delta":{"mean":0.03589489967595938,"se":0.10269049048087847},"arb_edge_delta":{"mean":-0.0373814460058548,"se":0.05153888275859683},"reconciliation_max_abs":8.881784197001252e-14,"gas":{"max_ok":196961,"oog":0,"init_max_ok":243081,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[2,0.07446021719726988,0.9782455810378826,0.6413701833078813,1.4761358245244,52.70840616254041],"start":650074,"n":32,"sha256":"574c0aa9651b676b18b3029f56d788e5a5d4049edc51bf6f0b53d917964db8a8","valid":true,"paired":{"n":32,"mean_diff":0.05414429135382015,"se":0.038743127059544386,"worst":[{"seed":650100,"d":-0.5863502725206899}]},"retail_edge_delta":{"mean":0.12954285101073637,"se":0.031968690238598836},"arb_edge_delta":{"mean":-0.0753985596569241,"se":0.02534857800188486},"reconciliation_max_abs":7.105427357601002e-14,"gas":{"max_ok":197277,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[2,0.43106084633940867,0.983150125371483,0.6565770520982287,1.6198680199147124,62.65590489208661],"start":650074,"n":32,"sha256":"6a43e9018b3ee263bca9b6e69a2b9ab486b2f609d0b53a5d678d8b345c05f9d3","valid":true,"paired":{"n":32,"mean_diff":0.027409146260996664,"se":0.07592898677192365,"worst":[{"seed":650078,"d":-1.4569947442146258}]},"retail_edge_delta":{"mean":0.5621709117406688,"se":0.07968503974033303},"arb_edge_delta":{"mean":-0.5347617654796818,"se":0.04844512733918763},"reconciliation_max_abs":9.592326932761353e-14,"gas":{"max_ok":197277,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}],"recheck":[{"params":[2,0.16509179839500446,0.9909893448132306,0.6684959838546022,1.5946627692375024,80.0],"valid":true,"paired":{"n":256,"mean_diff":0.0886657754667084,"se":0.023103784618138154,"worst":[{"seed":654234,"d":-1.0971362030973069}]},"retail_edge_delta":{"mean":0.044208080826811935,"se":0.02369389303332037},"arb_edge_delta":{"mean":0.04445769463989953,"se":0.010139658336460288},"reconciliation_max_abs":1.1368683772161603e-13,"gas":{"max_ok":202468,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}},{"params":[2,0.07446021719726988,0.9782455810378826,0.6413701833078813,1.4761358245244,52.70840616254041],"valid":true,"paired":{"n":256,"mean_diff":0.07245766080155969,"se":0.015702776262515327,"worst":[{"seed":654122,"d":-0.7546153053984881}]},"retail_edge_delta":{"mean":0.12863053293666749,"se":0.01596804348958246},"arb_edge_delta":{"mean":-0.056172872135107146,"se":0.005995306393718097},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":202468,"oog":0,"init_max_ok":243099,"all_halts_by_role":{"Submission":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"Baseline":{"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}]},"zero_mix":{"comparison":{"paired":{"n":2,"mean_diff":0.0,"se":0.0,"worst":[{"seed":650000,"d":0.0},{"seed":650001,"d":0.0}]},"retail_edge_delta":{"mean":0.0,"se":0.0},"arb_edge_delta":{"mean":0.0,"se":0.0},"reconciliation_max_abs":0.0},"gas":[[{"role":"Baseline","callback":"afterInitialize","calls":2,"ok":2,"max_ok_gas":21796,"sum_ok_gas":43592,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":23125,"ok":23125,"max_ok_gas":22592,"sum_ok_gas":521773364,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":2,"ok":2,"max_ok_gas":21526,"sum_ok_gas":43052,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":2,"ok":2,"max_ok_gas":220981,"sum_ok_gas":441962,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":21548,"ok":21548,"max_ok_gas":169270,"sum_ok_gas":2370575236,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":2,"ok":2,"max_ok_gas":21594,"sum_ok_gas":43188,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}],[{"role":"Baseline","callback":"afterInitialize","calls":2,"ok":2,"max_ok_gas":21796,"sum_ok_gas":43592,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":23125,"ok":23125,"max_ok_gas":22592,"sum_ok_gas":521773364,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":2,"ok":2,"max_ok_gas":21526,"sum_ok_gas":43052,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":2,"ok":2,"max_ok_gas":220981,"sum_ok_gas":441962,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":21548,"ok":21548,"max_ok_gas":169273,"sum_ok_gas":2370691199,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":2,"ok":2,"max_ok_gas":21594,"sum_ok_gas":43188,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]]},"seed_ledger":{"identity":{"inclusive":[650000,650001],"arms":["V10","zero_mix"]},"search":{"blocks_inclusive":[[650010,650041],[650042,650073],[650074,650105]],"arm_count_per_block":"V10 once plus six candidate arms; same-seed CRN","reuse":"Tuning only. Initial rejected storage layout was retried after packing state; no held-out results used."},"recheck":{"inclusive":[654000,654255],"arms":["V10","top_1","top_2"],"n_per_arm":256},"heldout":{"inclusive":[655000,655511],"arms":["V10","frozen"],"n_per_arm":512,"runs_per_arm":1,"freeze_before_results":true},"no_seeds_at_or_above_5000000":true},"paired":{"n":512,"mean_diff":0.09383374943510048,"se":0.01577346341497711,"worst":[{"seed":655461,"d":-1.0929591855791614},{"seed":655317,"d":-1.0239790528235062},{"seed":655301,"d":-0.9070958354121785},{"seed":655197,"d":-0.856730245214294},{"seed":655329,"d":-0.796666243212826}]},"retail_edge_delta":{"mean":0.03595198876958994,"se":0.016730207906259613},"arb_edge_delta":{"mean":0.05788176066550904,"se":0.006948676901561042},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"candidate":{"max_ok":201968,"oog":0,"init_max_ok":243099,"all_callbacks":[{"role":"Baseline","callback":"afterInitialize","calls":512,"ok":512,"max_ok_gas":21796,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":5586881,"ok":5586881,"max_ok_gas":22592,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":512,"ok":512,"max_ok_gas":21526,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":512,"ok":512,"max_ok_gas":243099,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":5245049,"ok":5245049,"max_ok_gas":201968,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":512,"ok":512,"max_ok_gas":21607,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]},"V10":{"max_ok":194207,"oog":0,"init_max_ok":220981,"all_callbacks":[{"role":"Baseline","callback":"afterInitialize","calls":512,"ok":512,"max_ok_gas":21796,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":5561088,"ok":5561088,"max_ok_gas":22592,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":512,"ok":512,"max_ok_gas":21526,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":512,"ok":512,"max_ok_gas":220981,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":5280643,"ok":5280643,"max_ok_gas":194207,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":512,"ok":512,"max_ok_gas":21594,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]}},"valid":true,"selected_hash_all_observed_gas":{"max_ok":202468,"oog":0},"rejected_storage_layout":[{"params":[0,0.2986014931560619,0.9877857244953427,0.9383586864192068,0.8778191357174046,69.93049558120083],"start":650010,"n":32,"sha256":"2e913a0a170614d53822ff72a375c4279d9a0bdeb9a5f669105847b7e0bce3ad","valid":false,"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":322035,"ok":322035,"max_ok_gas":22592,"sum_ok_gas":7266021552,"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":220975,"sum_ok_gas":7071200,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":332077,"ok":332071,"max_ok_gas":239723,"sum_ok_gas":41908093107,"oog":6,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21588,"sum_ok_gas":690816,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}],"paired":{"n":32,"mean_diff":-0.746264050502349,"se":0.13265311558752277,"worst":[{"seed":650030,"d":-2.309829808212271},{"seed":650027,"d":-2.148319966103827},{"seed":650035,"d":-1.8293524772285537},{"seed":650034,"d":-1.7817575746526586},{"seed":650040,"d":-1.6303097172273056}]},"retail_edge_delta":{"mean":1.4957838317206846,"se":0.13285079204363096},"arb_edge_delta":{"mean":-2.2420478822230296,"se":0.04543373137586908},"reconciliation_max_abs":1.1368683772161603e-13}],"validation":{"setup":"passed: pinned wheel checksum and StarterStrategy validation","frozen_solidity":"Validating strategy...\nCompiling strategy...\nStrategy 'censored_10' validated successfully!\n","zero_mix_equal_on_two_seeds":true,"comparison":"Every arm alone against VanillaStrategy; workers=8; chunks <=20; gas reset/read per chunk; no seed removal; sample SE uses ddof=1."},"calibration":"CH was already verified in the supplied V10 artifact; not independently rerun, as allowed by the item brief.","limitations":["All results are tuning-only; no board or >=5000000 confirmation claim.","Zero-mix equality tested on two seeds, with the original price/stale formulas preserved structurally.","Arb decomposition uses the supplied V10 closed-form reconstruction from prior-step reserves/quotes; retail edge is total edge minus reconstructed arb edge.","Size state models only the first weighted moment; no second moment.","Existing activity and directional fee terms remain V10; intervention replaces lambda/size fee inputs.","The bounded quote correction is a searched sensitivity model, not a calibrated estimate of total arrivals.","Search/recheck V10 callback counters were read per chunk but not retained in the search log; the held-out V10 counters are retained.","An additional unpacked-layout tuning arm was interrupted after the first OOG result; it returned no complete batch result and is not counted.","Runtime dependencies are those in the prescribed setup; they are not bundled in this JSON."],"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","generator_source":"def 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","search_source":"import json,time,hashlib\nfrom pathlib import Path\nimport numpy as np\nfrom harness import *\nfrom generator import generate\nbase=Path('v10.sol').read_text(); compiler=SolidityCompiler()\nv=compiler.compile(Path('contracts/src/VanillaStrategy.sol').read_text(),'VanillaStrategy');assert v.success\nrng=np.random.default_rng(402); log=[]; started=time.monotonic()\ndef arm(s,start,n):return run(s,start,n,v.bytecode,compiler)\ndef valid(a):return all(not any(r.get(k,0) for k in ['oog','revert','other_halt','tx_error','bad_return']) for r in a['raw_counters'])\ndef save():Path('scratch/search.json').write_text(json.dumps(log))\np=[0,0,.98,1,1,0]\na=arm(base,650000,2);b=arm(generate(base,p),650000,2)\nPath('scratch/identity.json').write_text(json.dumps({'comparison':compare(b,a),'gas':[a['raw_counters'],b['raw_counters']]}))\nfor round in range(3):\n start=650010+round*32\n baseline=arm(base,start,32)\n for kind in range(3):\n  for attempt in range(2):\n   prior=[x for x in log if x['valid'] and x['params'][0]==kind]\n   if prior and round>0:\n    parent=max(prior,key=lambda x:x['paired']['mean_diff'])['params']\n    bounds=[(.05,.9),(.94,.995),(.6,2),(.5,1.7),(5,80)]\n    p=[kind]+[float(np.clip(parent[i+1]+rng.normal(0,(hi-lo)*.18),(lo),(hi))) for i,(lo,hi) in enumerate(bounds)]\n   else:\n    p=[kind,float(rng.uniform(.1,.85)),float(rng.uniform(.94,.995)),float(rng.uniform(.6,2)),float(rng.uniform(.5,1.7)),float(rng.uniform(5,80))]\n   s=generate(base,p);a=arm(s,start,32)\n   record={'params':p,'start':start,'n':32,'sha256':a['sha256'],'valid':valid(a),'gas':a['raw_counters'],**compare(a,baseline)}\n   log.append(record);save();print(json.dumps(record),flush=True)\n   if time.monotonic()-started>1100:break\n  if time.monotonic()-started>1100:break\n if time.monotonic()-started>1100:break\nbest=sorted([x for x in log if x['valid']],key=lambda x:x['paired']['mean_diff'],reverse=True)[:2]\nbaseline=arm(base,654000,256); checks=[]\nfor x in best:\n a=arm(generate(base,x['params']),654000,256)\n checks.append({'params':x['params'],'valid':valid(a),'gas':a['raw_counters'],**compare(a,baseline)})\nPath('scratch/recheck.json').write_text(json.dumps(checks))\nwinner=max([x for x in checks if x['valid']],key=lambda x:x['paired']['mean_diff']);s=generate(base,winner['params'])\nPath('scratch/frozen.sol').write_text(s)\nPath('scratch/freeze.json').write_text(json.dumps({'sha256':hashlib.sha256(s.encode()).hexdigest(),'params':winner['params']}))\na=arm(s,655000,512);b=arm(base,655000,512)\nout={'candidate':a,'v10':b,'valid':valid(a) and valid(b),**compare(a,b)}\nPath('scratch/heldout.json').write_text(json.dumps(out));print('DONE',flush=True)\n"}
