{"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 = 64000000000000000;\n    uint256 constant DIR_TOX_COEF = 320000000000000000;\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 skewRatio = tradeRatio;\n            // The previous cleaned retail-size EMA is available before its update.\n            uint256 cleanedSize = uint80(slots[15] >> 160);\n            if (cleanedSize == 0) cleanedSize = 2000000000000000;\n            uint256 skewCap = wmul(cleanedSize, 4000000000000000000);\n            if (skewRatio > skewCap) skewRatio = skewCap;\n            uint256 push = skewRatio * DIR_IMPACT_MULT;\n            if (push > WAD / 4) push = WAD / 4;\n            push = wmul(push, 250000000000000000 + wmul(750000000000000000, arbProbability));\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(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":"9f9c5b4524cc8023de82cc55be34ab64af2c5c2001fa4dfccc0c1a0f00fe401e","params":{"a":0.25,"k":4,"gain":32},"mechanism":"For every trade above RS2’s signal threshold, cap the direction-push ratio at k times the previous cleaned retail-size EMA from slot 15, then multiply the hard-capped push by a + (1-a)*arbProbability. Multiply DIR_COEF and DIR_TOX_COEF by the same gain, leaving activity learning, size learning, posterior updates and all other fee rules unchanged.","source":{"url":"https://benedict.dev/optimization-arena-learnings","quote":"skewing based on information from the arbs"},"search":{"seed":86,"seconds":1511.4995503141545,"evaluations":48,"grid_size":177,"timed_budget_seconds":1500,"method":"Seed-86 randomized grid with eight initial ablations; stop launching evaluations at the 1500-second deadline, finish the in-flight evaluation. Pair every candidate with RS2 on the same 64 seeds. Rank by paired mean; recheck top three on 988000..988255; freeze the valid recheck winner.","all_evaluations_gas":{"max_ok":202855,"init_max_ok":243099,"oog":0,"other_halts":0},"grid":{"a":[0,0.25,0.5,0.75,1],"k":[0.5,1,2,4,8],"gain":[0.5,1,2,4,8,16,32]},"blocks":"start=985000+64*((evaluation_index//6)%8); n=64. Every block lies within 985000..987999. RS2 results cached per block.","best":{"i":23,"params":{"a":0.25,"k":4,"gain":32},"start":985192,"valid":true,"paired":{"n":64,"mean_diff":0.5101363570486663,"se":0.08352158714593695,"worst":[{"seed":985233,"d":-1.140945268964174},{"seed":985193,"d":-1.0944844314880129},{"seed":985249,"d":-0.7369075667731977},{"seed":985219,"d":-0.7035093549669114},{"seed":985210,"d":-0.6037395615404648}]},"retail_edge_delta":{"mean":0.441169265167086,"se":0.08674763070843633},"arb_edge_delta":{"mean":0.06896709188158612,"se":0.050706168384639476},"elapsed":773.8718638112769},"frozen_search":{"i":23,"params":{"a":0.25,"k":4,"gain":32},"start":985192,"valid":true,"paired":{"n":64,"mean_diff":0.5101363570486663,"se":0.08352158714593695,"worst":[{"seed":985233,"d":-1.140945268964174},{"seed":985193,"d":-1.0944844314880129},{"seed":985249,"d":-0.7369075667731977},{"seed":985219,"d":-0.7035093549669114},{"seed":985210,"d":-0.6037395615404648}]},"retail_edge_delta":{"mean":0.441169265167086,"se":0.08674763070843633},"arb_edge_delta":{"mean":0.06896709188158612,"se":0.050706168384639476},"elapsed":773.8718638112769},"recheck":[{"search_i":23,"params":{"a":0.25,"k":4,"gain":32},"valid":true,"paired":{"n":256,"mean_diff":0.4611025465673322,"se":0.038424998994735046,"worst":[{"seed":988187,"d":-2.614016698422688},{"seed":988018,"d":-1.3199764943324226},{"seed":988002,"d":-1.0354090367463868},{"seed":988181,"d":-0.991755525276858},{"seed":988228,"d":-0.9201151673436243}]},"retail_edge_delta":{"mean":0.49364589317614893,"se":0.04003703274148638},"arb_edge_delta":{"mean":-0.03254334660881683,"se":0.024929091469114224},"reconciliation_max_abs":1.0658141036401503e-13,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":256,"ok":256,"max_ok_gas":21796,"sum_ok_gas":5579776,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":2761178,"ok":2761178,"max_ok_gas":22592,"sum_ok_gas":62300325328,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":256,"ok":256,"max_ok_gas":21526,"sum_ok_gas":5510656,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":256,"ok":256,"max_ok_gas":243099,"sum_ok_gas":62233344,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":2680246,"ok":2680246,"max_ok_gas":202647,"sum_ok_gas":315464036941,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":256,"ok":256,"max_ok_gas":21607,"sum_ok_gas":5531392,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]},{"search_i":47,"params":{"a":0.5,"k":1,"gain":32},"valid":true,"paired":{"n":256,"mean_diff":0.3697911565973391,"se":0.034132797809099745,"worst":[{"seed":988013,"d":-2.0814867483715034},{"seed":988187,"d":-1.9557449193086995},{"seed":988018,"d":-1.0456534232179138},{"seed":988179,"d":-0.7990409651067694},{"seed":988069,"d":-0.777600027883409}]},"retail_edge_delta":{"mean":0.35451947087734204,"se":0.03323599138123659},"arb_edge_delta":{"mean":0.015271685719999928,"se":0.017234122710298574},"reconciliation_max_abs":1.0658141036401503e-13,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":256,"ok":256,"max_ok_gas":21796,"sum_ok_gas":5579776,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":2760869,"ok":2760869,"max_ok_gas":22592,"sum_ok_gas":62293380568,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":256,"ok":256,"max_ok_gas":21526,"sum_ok_gas":5510656,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":256,"ok":256,"max_ok_gas":243099,"sum_ok_gas":62233344,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":2677020,"ok":2677020,"max_ok_gas":202696,"sum_ok_gas":315117219404,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":256,"ok":256,"max_ok_gas":21607,"sum_ok_gas":5531392,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]},{"search_i":44,"params":{"a":1,"k":4,"gain":16},"valid":true,"paired":{"n":256,"mean_diff":0.1963716954987087,"se":0.04244022335314634,"worst":[{"seed":988187,"d":-2.6238148287905005},{"seed":988013,"d":-2.1678389856681406},{"seed":988018,"d":-1.8287254803642554},{"seed":988181,"d":-1.7344637881720928},{"seed":988002,"d":-1.5287866197531912}]},"retail_edge_delta":{"mean":2.5977727337550545,"se":0.04987457531899218},"arb_edge_delta":{"mean":-2.4014010382563447,"se":0.029177426847322715},"reconciliation_max_abs":1.1013412404281553e-13,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":256,"ok":256,"max_ok_gas":21796,"sum_ok_gas":5579776,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":2758763,"ok":2758763,"max_ok_gas":22592,"sum_ok_gas":62245684252,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":256,"ok":256,"max_ok_gas":21526,"sum_ok_gas":5510656,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":256,"ok":256,"max_ok_gas":243099,"sum_ok_gas":62233344,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":2718757,"ok":2718757,"max_ok_gas":202436,"sum_ok_gas":319587762781,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":256,"ok":256,"max_ok_gas":21607,"sum_ok_gas":5531392,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]}],"freeze_selection":{"search_i":23,"params":{"a":0.25,"k":4,"gain":32},"recheck_mean_diff":0.4611025465673322},"log":[{"i":0,"params":{"a":0,"k":2,"gain":1},"start":985000,"valid":true,"mean_diff":0.013389723024372024,"se":0.02978452019235706,"error":null},{"i":1,"params":{"a":0.5,"k":2,"gain":1},"start":985000,"valid":true,"mean_diff":0.05288113376980608,"se":0.022957368356947335,"error":null},{"i":2,"params":{"a":1,"k":2,"gain":1},"start":985000,"valid":true,"mean_diff":0.06665121794365714,"se":0.020831622234160112,"error":null},{"i":3,"params":{"a":0,"k":8,"gain":4},"start":985000,"valid":true,"mean_diff":0.10493686998736873,"se":0.03474552160335193,"error":null},{"i":4,"params":{"a":0.25,"k":4,"gain":8},"start":985000,"valid":true,"mean_diff":0.2473429411747503,"se":0.03854661641755557,"error":null},{"i":5,"params":{"a":0.5,"k":1,"gain":16},"start":985000,"valid":true,"mean_diff":0.2733238789312553,"se":0.04691730736364484,"error":null},{"i":6,"params":{"a":0,"k":null,"gain":1},"start":985064,"valid":true,"mean_diff":0.010934519530079179,"se":0.047834849381321924,"error":null},{"i":7,"params":{"a":1,"k":null,"gain":2},"start":985064,"valid":true,"mean_diff":0.03080138103816399,"se":0.028731025510937053,"error":null},{"i":8,"params":{"a":0,"k":4,"gain":1},"start":985064,"valid":true,"mean_diff":0.011852752539133427,"se":0.04823441165063922,"error":null},{"i":9,"params":{"a":0.5,"k":1,"gain":1},"start":985064,"valid":true,"mean_diff":0.04135491767983179,"se":0.041847052212745296,"error":null},{"i":10,"params":{"a":0.75,"k":2,"gain":1},"start":985064,"valid":true,"mean_diff":0.05827101020638992,"se":0.04213690486438527,"error":null},{"i":11,"params":{"a":0.5,"k":4,"gain":0.5},"start":985064,"valid":true,"mean_diff":0.034846337295662444,"se":0.037239671525824365,"error":null},{"i":12,"params":{"a":0,"k":0.5,"gain":4},"start":985128,"valid":true,"mean_diff":0.012233393415097993,"se":0.056306353184598965,"error":null},{"i":13,"params":{"a":0,"k":4,"gain":32},"start":985128,"valid":true,"mean_diff":0.18967616285690791,"se":0.18585256398623393,"error":null},{"i":14,"params":{"a":1,"k":4,"gain":4},"start":985128,"valid":true,"mean_diff":0.16732425416294383,"se":0.042601040097202766,"error":null},{"i":15,"params":{"a":0.25,"k":2,"gain":4},"start":985128,"valid":true,"mean_diff":0.12757453527858953,"se":0.03176633764778866,"error":null},{"i":16,"params":{"a":0.25,"k":8,"gain":16},"start":985128,"valid":true,"mean_diff":0.15391106978378577,"se":0.16288181345360211,"error":null},{"i":17,"params":{"a":0.25,"k":4,"gain":0.5},"start":985128,"valid":true,"mean_diff":0.06021017545520024,"se":0.034809243568973976,"error":null},{"i":18,"params":{"a":0.5,"k":0.5,"gain":1},"start":985192,"valid":true,"mean_diff":-0.007238315930380601,"se":0.027083952384881108,"error":null},{"i":19,"params":{"a":1,"k":1,"gain":0.5},"start":985192,"valid":true,"mean_diff":-0.007667447561701124,"se":0.025845785132432828,"error":null},{"i":20,"params":{"a":0.75,"k":1,"gain":8},"start":985192,"valid":true,"mean_diff":0.14573962008706953,"se":0.034253782883117465,"error":null},{"i":21,"params":{"a":0.75,"k":1,"gain":2},"start":985192,"valid":true,"mean_diff":0.032443889437345774,"se":0.02416062589745341,"error":null},{"i":22,"params":{"a":0.5,"k":1,"gain":2},"start":985192,"valid":true,"mean_diff":0.013654400099071928,"se":0.025846761714229703,"error":null},{"i":23,"params":{"a":0.25,"k":4,"gain":32},"start":985192,"valid":true,"mean_diff":0.5101363570486663,"se":0.08352158714593695,"error":null},{"i":24,"params":{"a":0.5,"k":4,"gain":8},"start":985256,"valid":true,"mean_diff":0.29373740713548546,"se":0.048196863787177205,"error":null},{"i":25,"params":{"a":0.5,"k":4,"gain":1},"start":985256,"valid":true,"mean_diff":0.024221653578694102,"se":0.024371596057723155,"error":null},{"i":26,"params":{"a":0.5,"k":2,"gain":4},"start":985256,"valid":true,"mean_diff":0.13878994087430385,"se":0.028835694722478565,"error":null},{"i":27,"params":{"a":0.5,"k":0.5,"gain":0.5},"start":985256,"valid":true,"mean_diff":-0.02987740828857799,"se":0.02373378642005396,"error":null},{"i":28,"params":{"a":1,"k":2,"gain":2},"start":985256,"valid":true,"mean_diff":0.09283534013797379,"se":0.02479208735634547,"error":null},{"i":29,"params":{"a":0.5,"k":2,"gain":16},"start":985256,"valid":true,"mean_diff":0.3784202479547538,"se":0.06027849911294872,"error":null},{"i":30,"params":{"a":0.5,"k":4,"gain":2},"start":985320,"valid":true,"mean_diff":0.035558906885939656,"se":0.026381118986849663,"error":null},{"i":31,"params":{"a":0.75,"k":2,"gain":4},"start":985320,"valid":true,"mean_diff":0.10417358199214544,"se":0.03140530581711212,"error":null},{"i":32,"params":{"a":0.5,"k":2,"gain":8},"start":985320,"valid":true,"mean_diff":0.18387617902823905,"se":0.04041185359656278,"error":null},{"i":33,"params":{"a":0.25,"k":4,"gain":16},"start":985320,"valid":true,"mean_diff":0.3913283047605782,"se":0.051438105567568886,"error":null},{"i":34,"params":{"a":1,"k":1,"gain":4},"start":985320,"valid":true,"mean_diff":0.05982689309610301,"se":0.025072329033581572,"error":null},{"i":35,"params":{"a":0.75,"k":0.5,"gain":8},"start":985320,"valid":true,"mean_diff":0.04336458482209693,"se":0.025129556255309656,"error":null},{"i":36,"params":{"a":0.75,"k":0.5,"gain":16},"start":985384,"valid":true,"mean_diff":0.16548044003997298,"se":0.03182198573338559,"error":null},{"i":37,"params":{"a":0.5,"k":0.5,"gain":2},"start":985384,"valid":true,"mean_diff":0.02221531296489676,"se":0.02289617562023438,"error":null},{"i":38,"params":{"a":0,"k":8,"gain":1},"start":985384,"valid":true,"mean_diff":0.0013400120640092439,"se":0.03374179095507647,"error":null},{"i":39,"params":{"a":0,"k":8,"gain":8},"start":985384,"valid":true,"mean_diff":0.15866323181118336,"se":0.0371660813529614,"error":null},{"i":40,"params":{"a":0.75,"k":1,"gain":4},"start":985384,"valid":true,"mean_diff":0.067223965642496,"se":0.02100246850221206,"error":null},{"i":41,"params":{"a":0,"k":1,"gain":4},"start":985384,"valid":true,"mean_diff":0.037785395254152476,"se":0.029924233964094233,"error":null},{"i":42,"params":{"a":0,"k":2,"gain":4},"start":985448,"valid":true,"mean_diff":0.10171369912998163,"se":0.028575529558939883,"error":null},{"i":43,"params":{"a":1,"k":8,"gain":8},"start":985448,"valid":true,"mean_diff":0.1908384986709537,"se":0.05125882515909366,"error":null},{"i":44,"params":{"a":1,"k":4,"gain":16},"start":985448,"valid":true,"mean_diff":0.40408197280050384,"se":0.07557459354087034,"error":null},{"i":45,"params":{"a":0.25,"k":1,"gain":8},"start":985448,"valid":true,"mean_diff":0.15791513956725467,"se":0.029793394360817464,"error":null},{"i":46,"params":{"a":0.5,"k":4,"gain":16},"start":985448,"valid":true,"mean_diff":0.39835936005639194,"se":0.0544227028384248,"error":null},{"i":47,"params":{"a":0.5,"k":1,"gain":32},"start":985448,"valid":true,"mean_diff":0.4303663252532708,"se":0.05742392548654295,"error":null}]},"held_out":{"baseline":"RS2","seeds":[989000,989511],"n":512,"mean_diff":0.5088548750349049,"se":0.026955547530927597,"worst":[{"seed":989364,"d":-2.273650116076965},{"seed":989179,"d":-1.291316709736293},{"seed":989026,"d":-1.2518806367831985},{"seed":989328,"d":-1.2341587509985743},{"seed":989208,"d":-1.1092199686360118}],"valid":true,"candidate_mean_edge":518.0949410933333,"rs2_mean_edge":517.5860862182984},"retail_edge_delta":{"mean":0.513390675570966,"se":0.02700951920131768},"arb_edge_delta":{"mean":-0.004535800536059481,"se":0.018317509048345094},"gas":{"max_ok":202817,"init_max_ok":243099,"oog":0,"scope":"Frozen candidate across its 64-seed search evaluation, 256-seed recheck and 512-seed held-out run; error counts include both Submission and VanillaStrategy.","raw_counters":[{"role":"Baseline","callback":"afterInitialize","calls":832,"ok":832,"max_ok_gas":21796,"sum_ok_gas":18134272,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":8871653,"ok":8871653,"max_ok_gas":22592,"sum_ok_gas":200170475464,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":832,"ok":832,"max_ok_gas":21526,"sum_ok_gas":17909632,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":832,"ok":832,"max_ok_gas":243099,"sum_ok_gas":202258368,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":8651197,"ok":8651197,"max_ok_gas":202817,"sum_ok_gas":1019208890770,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":832,"ok":832,"max_ok_gas":21607,"sum_ok_gas":17977024,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}],"held_out":[{"role":"Baseline","callback":"afterInitialize","calls":512,"ok":512,"max_ok_gas":21796,"sum_ok_gas":11159552,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":5421245,"ok":5421245,"max_ok_gas":22592,"sum_ok_gas":122319053644,"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,"sum_ok_gas":11021312,"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,"sum_ok_gas":124466688,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":5301164,"ok":5301164,"max_ok_gas":202817,"sum_ok_gas":624873216315,"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,"sum_ok_gas":11062784,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}],"rs2_held_out":[{"role":"Baseline","callback":"afterInitialize","calls":512,"ok":512,"max_ok_gas":21796,"sum_ok_gas":11159552,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":5415673,"ok":5415673,"max_ok_gas":22592,"sum_ok_gas":122193443216,"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,"sum_ok_gas":11021312,"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,"sum_ok_gas":124466688,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":5267596,"ok":5267596,"max_ok_gas":202398,"sum_ok_gas":620963789450,"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,"sum_ok_gas":11062784,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}],"rejected_evaluations":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"neutral_check":{"edge_for_edge":true,"n":32,"paired":{"paired":{"n":32,"mean_diff":0.0,"se":0.0,"worst":[{"seed":989600,"d":0.0},{"seed":989601,"d":0.0},{"seed":989602,"d":0.0},{"seed":989603,"d":0.0},{"seed":989604,"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":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":350348,"ok":350348,"max_ok_gas":22592,"sum_ok_gas":7904895196,"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":243099,"sum_ok_gas":7779168,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":337192,"ok":337192,"max_ok_gas":195411,"sum_ok_gas":39624813437,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21607,"sum_ok_gas":691424,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]},"calibration":{"strategy_url":"https://raw.githubusercontent.com/ChengHua926/amm-challenge/d34a5199c59a4c44d5336a25f1436b4ae1f21104/contracts/src/Strategy.sol","n":1000,"seeds":[0,999],"mean_edge":525.5258821780834,"expected_mean_edge":525.5258821780834,"abs_error":0.0},"generator_source":"from decimal import Decimal\nWAD=10**18\ndef fixed(x):return int(Decimal(str(x))*WAD)\ndef generate(base,a=1,k=None,gain=1):\n    assert 0<=a<=1 and (k is None or .5<=k<=8) and gain>=0\n    s=base\n    old='uint256 push = tradeRatio * DIR_IMPACT_MULT;'\n    new='uint256 skewRatio = tradeRatio;'\n    if k is not None:\n        new+=f'''\\n            // The previous cleaned retail-size EMA is available before its update.\n            uint256 cleanedSize = uint80(slots[15] >> 160);\n            if (cleanedSize == 0) cleanedSize = 2000000000000000;\n            uint256 skewCap = wmul(cleanedSize, {fixed(k)});\n            if (skewRatio > skewCap) skewRatio = skewCap;'''\n    new+='\\n            uint256 push = skewRatio * DIR_IMPACT_MULT;'\n    assert s.count(old)==1;s=s.replace(old,new)\n    old='if (push > WAD / 4) push = WAD / 4;'\n    if a!=1:\n        s=s.replace(old,old+f'\\n            push = wmul(push, {fixed(a)} + wmul({WAD-fixed(a)}, arbProbability));')\n    for name,val in [('DIR_COEF',20),('DIR_TOX_COEF',100)]:\n        old=f'uint256 constant {name} = {val} * BPS;'\n        assert old in s;s=s.replace(old,f'uint256 constant {name} = {int(Decimal(str(gain))*val*10**14)};')\n    return s\n","generator_usage":"generate(base_RS2_code, a=1, k=None, gain=1) is neutral; code above is generate(base_RS2_code, **params).","harness_url":"https://api.imdnotdead.fun/artifacts/33f54e81f3372088e9eced52c0174f310ac348af98ef5727b73785c088679194","notes":["Held-out measured gain versus RS2; selection was frozen before any held-out run. No held-out retuning or seed removal.","No new storage or initializer slot writes. afterInitialize is unchanged from RS2.","Cap uses the previous unscaled cleaned meanSize (uint80(slots[15] >> 160)), not the decaying raw sizeHat. Fallback matches RS2 at 0.002 WAD. Weight is applied after RS2’s WAD/4 push hard cap; only push uses the capped ratio.","Gain is quantized directly into both coefficient constants with decimal arithmetic. k=None disables the cap. Neutral has exact edge, arb and retail equality on all required seeds; source metadata means bytecode hashes differ.","Each strategy runs alone against VanillaStrategy, with run_batch(...,8), 10000 steps and per-20-seed gas snapshots. Config RNG draws size, rate, sigma in that order; price seed=seed and retail seed=seed+1.","Paired SE is sample standard deviation divided by sqrt(n); worst lists the five smallest per-seed edge differences. Retail and arb decomposition follows the supplied harness; deltas reconcile to total edge with max absolute residual 1.1368683772161603e-13.","No fresh STACK comparison or leaderboard submission was performed: this item’s prescribed experiment compares against RS2 on its specified held-out block. No board-rank claim is made.","Original RS2 sha256: f24b6ca198b744c380842c3a17964a6dc21f311bb04984b26733afa3fee8eaf2. Repository pinned at 6b6921f8d463314aa7c96234e1be25a25245f704; Python 3.12, solc 0.8.24, optimizer 200 runs, viaIR, Paris EVM; wheel checksum verified as supplied."]}
