{"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    int256 constant VQ_GAIN = 500000;\n    uint256 constant VQ_CAP = 300000000000000;\n    int256 constant VQ_MARGIN = 300000000000000;\n\n    uint256 constant ELAPSED_CAP = 8;\n    uint256 constant SIGNAL_THRESHOLD = WAD / 650;\n    uint256 constant DIR_DECAY = 750000000000000000;\n    uint256 constant ACT_DECAY = 530000000000000000;\n    uint256 constant SIZE_DECAY = 530000000000000000;\n    uint256 constant TOX_DECAY = 910000000000000000;\n    uint256 constant SIGMA_DECAY = 690000000000000000;\n    uint256 constant LAMBDA_DECAY = 990000000000000000;\n    uint256 constant SIZE_BLEND_DECAY = 828000000000000000;\n    uint256 constant TOX_BLEND_DECAY = 51000000000000000;\n    uint256 constant ACT_BLEND_DECAY = 985000000000000000;\n    uint256 constant PHAT_ALPHA = 270000000000000000;\n    uint256 constant PHAT_ALPHA_RETAIL = 60000000000000000;\n    uint256 constant PHAT_ALPHA_SAME = 120000000000000000;\n    uint256 constant REVERT_U = 0;\n    uint256 constant DIR_IMPACT_MULT = 4;\n    uint256 constant GATE_SIGMA_MULT = 7200000000000000000;\n    uint256 constant MIN_GATE = 30000000000000000;\n    uint256 constant TRADE_TOX_BOOST = 3500 * BPS;\n    uint256 constant STALE_ATTRACT_FRAC = 1050000000000000000;\n    uint256 constant RET_CAP = WAD / 35;\n    uint256 constant TOX_CAP = WAD / 5;\n    uint256 constant TRADE_RATIO_CAP = WAD / 5;\n    uint256 constant LAMBDA_CAP = 1820000000000000000;\n    uint256 constant STEP_COUNT_CAP = 64;\n    uint256 constant BASE_FEE = 4 * BPS;\n    uint256 constant SIGMA_COEF = 200000000000000000;\n    uint256 constant LAMBDA_COEF = 12 * BPS;\n    uint256 constant FLOW_SIZE_COEF = 4842 * BPS;\n    uint256 constant TOX_COEF = 300 * BPS;\n    uint256 constant TOX_QUAD_COEF = 15000 * BPS;\n    uint256 constant ACT_COEF = 91843 * BPS;\n    uint256 constant DIR_COEF = 20 * BPS;\n    uint256 constant DIR_TOX_COEF = 100 * BPS;\n    uint256 constant STALE_DIR_COEF = 6850 * BPS;\n    uint256 constant SIGMA_TOX_COEF = 500 * BPS;\n    uint256 constant TAIL_KNEE = 600 * BPS;\n    uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000;\n    uint256 constant TAIL_SLOPE_ATTRACT = 850000000000000000;\n\n    function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) {\n        slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[3] = WAD; \n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n        slots[15] = 400000000000000000 | (uint256(2000000000000000) << 160); slots[13] = 902500000000; slots[14] = slots[5]; \n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 prevBidFee = slots[0]; uint256 prevAskFee = slots[1]; uint256 lastTs = uint64(slots[2]);\n        uint256 dirState = slots[3]; uint256 actEma = slots[4]; uint256 pHat = slots[5];\n        uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8];\n        uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10];\n\n        uint256 sigmaForFast = sigmaHat;\n        uint256 fastHat = slots[14];\n        uint256 uncertainty = slots[13];\n        uint256 silent = trade.timestamp > lastTs ? trade.timestamp - lastTs : 0;\n        bool isNewStep = trade.timestamp > lastTs;\n        if (isNewStep) {\n            uint256 elapsedRaw = trade.timestamp - lastTs;\n            uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw;\n            dirState = _decayCentered(dirState, DIR_DECAY, elapsed);\n            actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed));\n            sizeHat = wmul(sizeHat, _powWad(SIZE_DECAY, elapsed));\n            toxEma = wmul(toxEma, _powWad(TOX_DECAY, elapsed));\n            if (stepTradeCount > 0 && elapsedRaw > 0) {\n                uint256 lambdaInst = (stepTradeCount * WAD) / elapsedRaw;\n                if (lambdaInst > LAMBDA_CAP) lambdaInst = LAMBDA_CAP;\n                lambdaHat = wmul(lambdaHat, LAMBDA_DECAY) + wmul(lambdaInst, WAD - LAMBDA_DECAY);\n            }\n            // Process variance is propagated inside the censored update.\n            if (uncertainty > 100000000000000) uncertainty = 100000000000000;\n            stepTradeCount = 0;\n        }\n\n        bool firstInStep = stepTradeCount == 0;\n        uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat;\n        if (pHat == 0) pHat = spot;\n\n        uint256 feeUsed = trade.isBuy ? prevBidFee : prevAskFee;\n        uint256 gamma = feeUsed < WAD ? WAD - feeUsed : 0;\n        uint256 pImplied;\n        if (gamma == 0) { pImplied = spot; }\n        else { pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma); }\n\n        // S: infer a no-trade interval center from the last post-trade spot.\n        uint256 silenceScale = WAD;\n        if (firstInStep && silent > 1) {\n            uint256 g = silent - 1;\n            if (g > 1) g = 1;\n            uint256 w = WAD - _powWad(800000000000000000, g);\n            uint256 s = slots[2] >> 64;\n            if (s == 0) s = pHat;\n            uint256 c = (wmul(s, WAD - prevBidFee) + wdiv(s, WAD - prevAskFee)) / 2;\n            if (c >= pHat) pHat += wmul(w, c - pHat);\n            else pHat -= wmul(w, pHat - c);\n            silenceScale = WAD - wmul(300000000000000000, w);\n        }\n\n        {\n            uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0;\n            uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL;\n            uint256 prePhat = pHat;\n            bool secondPrint = !firstInStep && stepTradeCount == 1;\n            bool sameDir = false; bool oppDir = false;\n            if (secondPrint) {\n                bool up2 = pImplied >= pHat;\n                uint256 d1 = slots[12];\n                if (d1 != 0) { sameDir = (d1 == 1) == up2; oppDir = !sameDir; }\n                if (sameDir) alpha = PHAT_ALPHA_SAME;\n            }\n            if (firstInStep) { slots[12] = pImplied >= pHat ? 1 : 2; }\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            alpha = wmul(alpha, silenceScale);\n            adaptiveGate = wmul(adaptiveGate, silenceScale);\n            if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); }\n            if (oppDir && REVERT_U > 0) {\n                uint256 pre = slots[11];\n                if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U);\n                else pHat = pHat - wmul(pHat - pre, REVERT_U);\n            }\n            if (firstInStep) {\n                if (ret > RET_CAP) ret = RET_CAP;\n                sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY);\n            }\n        }\n\n        // Interior retail routing equalizes fee-adjusted marginal prices.\n        // Subsequent trades in a step cannot be the initial arbitrage trade.\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalSpot = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            pHat = wmul(pHat, 90 * WAD / 100) + wmul(normalSpot, 10 * WAD / 100);\n        }\n\n        // Censored assumed-density posterior. No external or future inputs.\n        uint256 arbProbability;\n        (fastHat, uncertainty, arbProbability) = _posterior(PosteriorInput(\n            fastHat, uncertainty, pImplied, spot, slots[2] >> 64,\n            prevBidFee, prevAskFee, firstInStep, silent, trade.isBuy,\n            trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0\n        ));\n        slots[13] = uncertainty;\n        slots[14] = fastHat;\n        uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n        if (tradeRatio > TRADE_RATIO_CAP) tradeRatio = TRADE_RATIO_CAP;\n\n        if (tradeRatio > SIGNAL_THRESHOLD) {\n            uint256 push = tradeRatio * DIR_IMPACT_MULT;\n            if (push > WAD / 4) push = WAD / 4;\n            if (trade.isBuy) {\n                dirState = dirState + push;\n                if (dirState > 2 * WAD) dirState = 2 * WAD;\n            } else {\n                dirState = dirState > push ? dirState - push : 0;\n            }\n            actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY);\n            sizeHat = wmul(sizeHat, SIZE_BLEND_DECAY) + wmul(tradeRatio, WAD - SIZE_BLEND_DECAY);\n            if (sizeHat > WAD) sizeHat = WAD;\n        }\n\n        uint256 tox = pHat > 0 ? wdiv(absDiff(spot, pHat), pHat) : 0;\n        if (tox > TOX_CAP) tox = TOX_CAP;\n        toxEma = wmul(toxEma, TOX_BLEND_DECAY) + wmul(tox, WAD - TOX_BLEND_DECAY);\n        uint256 toxSignal = toxEma;\n\n        stepTradeCount = stepTradeCount + 1;\n        if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP;\n\n        uint256 originalLambda = lambdaHat; uint256 originalSize = sizeHat;\n\n        if (342406799193418304 > 0) {\n            uint256 packedFlow = slots[15];\n            uint256 rate = uint80(packedFlow);\n            uint256 count = uint80(packedFlow >> 80);\n            uint256 meanSize = uint80(packedFlow >> 160);\n            if (rate == 0) rate = 400000000000000000;\n            if (meanSize == 0) meanSize = 2000000000000000;\n            if (isNewStep) {\n                uint256 inst = count / silent;\n                if (inst > 3 * WAD) inst = 3 * WAD;\n                uint256 retention = _powWad(999000000000000000, silent > 64 ? 64 : silent);\n                rate = wmul(rate, retention) + wmul(inst, WAD-retention);\n                count = 0;\n            }\n            uint256 weight = firstInStep ? WAD-arbProbability : WAD;\n            uint256 correctedWeight = weight;\n            if (2 == 2) {\n                uint256 missing = wmul(feeUsed, 196030880396139429888);\n                if (missing > 333333333333333376) missing = 333333333333333376;\n                correctedWeight = wdiv(weight, WAD-missing);\n            }\n            count += correctedWeight;\n            uint256 learning = wmul(WAD-999000000000000000, weight);\n            meanSize = _blend(meanSize, tradeRatio, learning);\n            slots[15]=rate | (count << 80) | (meanSize << 160);\n            uint256 retailRate = wmul(rate, 366383424913407168);\n            uint256 retailSize = 2 == 0 ? sizeHat : wmul(meanSize,1883296158119298304);\n            lambdaHat = _blend(lambdaHat,retailRate,342406799193418304);\n            sizeHat = _blend(sizeHat,retailSize,342406799193418304);\n        }\n        uint256 flowSize = wmul(lambdaHat, sizeHat);\n        uint256 fBase = BASE_FEE + wmul(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\n        if (VQ_GAIN != 0) {\n            (bidFee, askFee) = _vanillaQuote(trade, spot,\n                wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000),\n                !firstInStep || arbProbability < WAD / 2,\n                feeUsed, bidFee, askFee);\n        }\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\n    // Two virtual reserves; lazily initialized to avoid afterInitialize writes.\n    function _vanillaQuote(TradeInfo calldata t, uint256 spot, uint256 fair,\n        bool retail, uint256 usedFee, uint256 bid, uint256 ask)\n        internal returns (uint256, uint256)\n    {\n        uint256 vx = slots[16];\n        uint256 vy = slots[17];\n        bool firstModel = vx == 0;\n        if (!firstModel && vy == 0) vy = wdiv(wmul(t.reserveX, t.reserveY), vx);\n        uint256 k;\n        uint256 vs;\n        if (vx == 0) {\n            // Both pools started with equal reserves and keep fees outside k.\n            k = wmul(t.reserveX, t.reserveY);\n            vs = slots[5]; // Prior RS2 estimate, still the initial price here.\n        } else {\n            k = wmul(vx, vy);\n            vs = wdiv(vy, vx);\n        }\n        uint256 vg = WAD - 30 * BPS;\n        uint256 lo = wmul(fair, vg);\n        uint256 hi = wdiv(fair, vg);\n        if (vs < lo) vs = lo;\n        else if (vs > hi) vs = hi;\n        if (retail) {\n            // Equal marginal bid: ownSpot*ownGamma = vanillaSpot*vg.\n            // Equal marginal ask: ownSpot/ownGamma = vanillaSpot/vg.\n            vs = t.isBuy ? wdiv(wmul(spot, WAD-usedFee), vg)\n                : wdiv(wmul(spot, vg), WAD-usedFee);\n        }\n        vx = _isqrt(wdiv(k, vs) * WAD);\n        vy = wdiv(k, vx);\n        slots[16] = vx;\n        // Spread zero-to-nonzero writes over two callbacks. Until Y is stored,\n        // recover it from the shared invariant and stored X.\n        if (!firstModel) slots[17] = vy;\n        // Lower fee is RS2's attracting side. Margin is relative quote bps.\n        if (bid < ask) {\n            uint256 requiredGamma = wdiv(wmul(vs, vg), spot);\n            requiredGamma = uint256(int256(requiredGamma) * (int256(WAD) + VQ_MARGIN) / int256(WAD));\n            bid = _vqPull(bid, int256(WAD) - int256(requiredGamma));\n        } else if (ask < bid) {\n            uint256 requiredGamma = wdiv(wmul(spot, vg), vs);\n            requiredGamma = uint256(int256(requiredGamma) * int256(WAD) / (int256(WAD) - VQ_MARGIN));\n            ask = _vqPull(ask, int256(WAD) - int256(requiredGamma));\n        }\n        return (bid, ask);\n    }\n    function _vqPull(uint256 fee, int256 target) internal pure returns (uint256) {\n        // The change, rather than the final fee, is clipped to +/- c bps.\n        int256 delta = VQ_GAIN * (target - int256(fee)) / 1000000;\n        int256 cap = int256(VQ_CAP);\n        if (delta > cap) delta = cap;\n        if (delta < -cap) delta = -cap;\n        int256 next = int256(fee) + delta;\n        return next <= 0 ? 0 : clampFee(uint256(next));\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":"ef486e300c56a8f5c3990a134ec35beec98263fdfbd578397c2c29574a42cf0c","params":{"g":0.5,"c_bps":3,"m_bps":3},"mechanism":"Track Vanilla virtual X/Y reserves in slots 16/17, projecting their spot into the 30 bps arbitrage band around RS2's 70% slow/30% fast estimate and setting spot by equal marginal prices after inferred retail fills. Pull RS2's lower-fee side toward a marginal quote that improves Vanilla's by m relative basis points using signed gain g, clipping the fee change to +/- c basis points and then clamping the fee to [0,10%].","source":{"url":"https://benedict.dev/optimization-arena-learnings","quote":"fully model the competitor AMM"},"search":{"method":"Random-order grid, numpy default_rng(83); complete evaluations until 1500 seconds elapse, checked between evaluations. Same 64-seed block for each group of 12 candidates, with a separate RS2-vs-Vanilla baseline on that block.","rng_seed":83,"grid":{"g":[-2,-1,-0.5,-0.2,0.2,0.5,1,2],"c_bps":[1,3,8,20,50],"m_bps":[0,1,3,10,30]},"evaluations":44,"valid_evaluations":44,"gas_over_all_evaluations":{"max_ok":227692,"init_max_ok":243134,"oog":0,"other_halts":0},"elapsed_seconds":1520.0845695130993,"best":{"params":{"g":0.2,"c_bps":50,"m_bps":10},"seed_start":970192,"paired":{"n":64,"mean_diff":0.1466736447797956,"se":0.05461308282053996,"worst":[{"seed":970216,"d":-0.8038748175719093},{"seed":970222,"d":-0.7883309457939731},{"seed":970228,"d":-0.6148069757622352},{"seed":970201,"d":-0.559180957462786},{"seed":970253,"d":-0.4959536490568439}]},"gas":{"max_ok":224322,"init_max_ok":243134,"oog":0,"other_halts":0}},"log":[{"i":0,"start":970000,"params":{"g":0.5,"c_bps":3,"m_bps":3},"mean_diff":0.14058833080696154,"se":0.055938199344451586,"valid":true,"gas":{"max_ok":227636,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":1,"start":970000,"params":{"g":1,"c_bps":3,"m_bps":1},"mean_diff":-0.1286266175596058,"se":0.05712939732194814,"valid":true,"gas":{"max_ok":227644,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":2,"start":970000,"params":{"g":-0.2,"c_bps":50,"m_bps":1},"mean_diff":-2.258734270186796,"se":0.08055368362177694,"valid":true,"gas":{"max_ok":227365,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":3,"start":970000,"params":{"g":2,"c_bps":50,"m_bps":3},"mean_diff":-23.576822841364514,"se":0.31637876961433903,"valid":true,"gas":{"max_ok":227636,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":4,"start":970000,"params":{"g":-0.5,"c_bps":50,"m_bps":0},"mean_diff":-5.911959197143118,"se":0.14193486908599595,"valid":true,"gas":{"max_ok":227362,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":5,"start":970000,"params":{"g":-0.5,"c_bps":1,"m_bps":10},"mean_diff":-0.5888073076049363,"se":0.031160119184063577,"valid":true,"gas":{"max_ok":227692,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":6,"start":970000,"params":{"g":-0.5,"c_bps":3,"m_bps":0},"mean_diff":-1.3280045292547271,"se":0.046810705531617224,"valid":true,"gas":{"max_ok":227381,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":7,"start":970000,"params":{"g":1,"c_bps":50,"m_bps":0},"mean_diff":-11.595851769348645,"se":0.1990740915872069,"valid":true,"gas":{"max_ok":227622,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":8,"start":970000,"params":{"g":0.2,"c_bps":20,"m_bps":30},"mean_diff":-1.2086316277995959,"se":0.07610469442591525,"valid":true,"gas":{"max_ok":224470,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":9,"start":970000,"params":{"g":-0.2,"c_bps":3,"m_bps":10},"mean_diff":-1.3799652208860982,"se":0.055064485187165994,"valid":true,"gas":{"max_ok":227673,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":10,"start":970000,"params":{"g":2,"c_bps":8,"m_bps":1},"mean_diff":-2.264009587771585,"se":0.10205245891366556,"valid":true,"gas":{"max_ok":227636,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":11,"start":970000,"params":{"g":2,"c_bps":50,"m_bps":1},"mean_diff":-26.686045092842356,"se":0.3803032821714124,"valid":true,"gas":{"max_ok":227636,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":12,"start":970064,"params":{"g":0.5,"c_bps":1,"m_bps":10},"mean_diff":0.07256236344876044,"se":0.03626415821658834,"valid":true,"gas":{"max_ok":227490,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":13,"start":970064,"params":{"g":2,"c_bps":1,"m_bps":1},"mean_diff":0.07687009914173082,"se":0.040716381075558084,"valid":true,"gas":{"max_ok":227490,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":14,"start":970064,"params":{"g":2,"c_bps":8,"m_bps":0},"mean_diff":-2.418663180655824,"se":0.10616759070507022,"valid":true,"gas":{"max_ok":227492,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":15,"start":970064,"params":{"g":-1,"c_bps":3,"m_bps":10},"mean_diff":-2.0146183666881816,"se":0.05599957789211979,"valid":true,"gas":{"max_ok":227527,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":16,"start":970064,"params":{"g":1,"c_bps":50,"m_bps":10},"mean_diff":-5.111936016591536,"se":0.12935390199289282,"valid":true,"gas":{"max_ok":222602,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":17,"start":970064,"params":{"g":-0.5,"c_bps":3,"m_bps":30},"mean_diff":-1.5043922958649558,"se":0.07421739063592173,"valid":true,"gas":{"max_ok":227529,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":18,"start":970064,"params":{"g":-1,"c_bps":3,"m_bps":30},"mean_diff":-1.5108710099591267,"se":0.07307151748208948,"valid":true,"gas":{"max_ok":227529,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":19,"start":970064,"params":{"g":0.2,"c_bps":1,"m_bps":10},"mean_diff":0.09051106573910062,"se":0.03588951364489026,"valid":true,"gas":{"max_ok":227490,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":20,"start":970064,"params":{"g":-0.2,"c_bps":50,"m_bps":0},"mean_diff":-2.091799484901877,"se":0.08096459876771728,"valid":true,"gas":{"max_ok":227510,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":21,"start":970064,"params":{"g":0.5,"c_bps":20,"m_bps":1},"mean_diff":-1.4755770861838773,"se":0.0900874712796674,"valid":true,"gas":{"max_ok":227471,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":22,"start":970064,"params":{"g":2,"c_bps":1,"m_bps":0},"mean_diff":-0.025276261881586493,"se":0.04147525874242823,"valid":true,"gas":{"max_ok":227492,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":23,"start":970064,"params":{"g":0.5,"c_bps":50,"m_bps":10},"mean_diff":-1.2567241220026633,"se":0.09489540907696495,"valid":true,"gas":{"max_ok":222613,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":24,"start":970128,"params":{"g":-2,"c_bps":50,"m_bps":10},"mean_diff":-23.904028465470507,"se":0.6399322633174735,"valid":true,"gas":{"max_ok":224547,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":25,"start":970128,"params":{"g":-2,"c_bps":20,"m_bps":0},"mean_diff":-11.134767431047084,"se":0.2441931047542815,"valid":true,"gas":{"max_ok":224549,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":26,"start":970128,"params":{"g":2,"c_bps":20,"m_bps":10},"mean_diff":-6.57045927644983,"se":0.18204795133744875,"valid":true,"gas":{"max_ok":219652,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":27,"start":970128,"params":{"g":-0.2,"c_bps":8,"m_bps":1},"mean_diff":-1.7638537742659643,"se":0.06160291276766649,"valid":true,"gas":{"max_ok":224528,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":28,"start":970128,"params":{"g":2,"c_bps":20,"m_bps":3},"mean_diff":-9.118407772661687,"se":0.17636465569761095,"valid":true,"gas":{"max_ok":219652,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":29,"start":970128,"params":{"g":-2,"c_bps":50,"m_bps":1},"mean_diff":-18.165579717609354,"se":0.47716185940871847,"valid":true,"gas":{"max_ok":224547,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":30,"start":970128,"params":{"g":0.2,"c_bps":8,"m_bps":10},"mean_diff":0.11862890105767754,"se":0.07509030281630766,"valid":true,"gas":{"max_ok":224491,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":31,"start":970128,"params":{"g":-0.2,"c_bps":20,"m_bps":1},"mean_diff":-2.1211382532577803,"se":0.07439870682785316,"valid":true,"gas":{"max_ok":224528,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":32,"start":970128,"params":{"g":2,"c_bps":20,"m_bps":1},"mean_diff":-9.896825868225585,"se":0.1966243316508703,"valid":true,"gas":{"max_ok":219652,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":33,"start":970128,"params":{"g":1,"c_bps":20,"m_bps":1},"mean_diff":-6.248773964222108,"se":0.1587372707667598,"valid":true,"gas":{"max_ok":219641,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":34,"start":970128,"params":{"g":1,"c_bps":3,"m_bps":0},"mean_diff":-0.2265602514733951,"se":0.08003035876450426,"valid":true,"gas":{"max_ok":224501,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":35,"start":970128,"params":{"g":2,"c_bps":50,"m_bps":10},"mean_diff":-13.83946981123942,"se":0.24649220878737627,"valid":true,"gas":{"max_ok":219652,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":36,"start":970192,"params":{"g":1,"c_bps":8,"m_bps":1},"mean_diff":-1.4751258102195104,"se":0.08863945329306284,"valid":true,"gas":{"max_ok":224650,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":37,"start":970192,"params":{"g":0.2,"c_bps":20,"m_bps":0},"mean_diff":0.14059772655456548,"se":0.055760948601662086,"valid":true,"gas":{"max_ok":224658,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":38,"start":970192,"params":{"g":-0.2,"c_bps":8,"m_bps":3},"mean_diff":-1.8378280982047652,"se":0.07298325491987825,"valid":true,"gas":{"max_ok":224366,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":39,"start":970192,"params":{"g":-1,"c_bps":50,"m_bps":10},"mean_diff":-13.998648439082011,"se":0.361931685577436,"valid":true,"gas":{"max_ok":224698,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":40,"start":970192,"params":{"g":2,"c_bps":8,"m_bps":30},"mean_diff":-2.2002110775848953,"se":0.0891680326243661,"valid":true,"gas":{"max_ok":224341,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":41,"start":970192,"params":{"g":1,"c_bps":3,"m_bps":3},"mean_diff":0.016804720052917332,"se":0.050425068341899464,"valid":true,"gas":{"max_ok":224650,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":42,"start":970192,"params":{"g":0.2,"c_bps":50,"m_bps":10},"mean_diff":0.1466736447797956,"se":0.05461308282053996,"valid":true,"gas":{"max_ok":224322,"init_max_ok":243134,"oog":0,"other_halts":0}},{"i":43,"start":970192,"params":{"g":-0.2,"c_bps":50,"m_bps":10},"mean_diff":-2.6116780173944916,"se":0.08528592658534673,"valid":true,"gas":{"max_ok":224698,"init_max_ok":243134,"oog":0,"other_halts":0}}],"recheck":[{"search_i":42,"rank":0,"params":{"g":0.2,"c_bps":50,"m_bps":10},"paired":{"n":256,"mean_diff":0.07824277047895256,"se":0.028541960010209984,"worst":[{"seed":973220,"d":-1.2035593041346715},{"seed":973043,"d":-1.1887791846364166},{"seed":973158,"d":-1.0390965366286764},{"seed":973212,"d":-0.9224432100169224},{"seed":973103,"d":-0.9222779389099287}]},"retail_edge_delta":{"mean":0.16491167225090053,"se":0.028606937310110762},"arb_edge_delta":{"mean":-0.08666890177194753,"se":0.009693998620373179},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":229588,"init_max_ok":243134,"oog":0,"other_halts":0},"valid":true},{"search_i":37,"rank":1,"params":{"g":0.2,"c_bps":20,"m_bps":0},"paired":{"n":256,"mean_diff":0.0828341214161723,"se":0.027847702444071417,"worst":[{"seed":973043,"d":-1.2623126700064518},{"seed":973237,"d":-1.1299912384240542},{"seed":973168,"d":-1.1233328449957298},{"seed":973103,"d":-1.0009259810162803},{"seed":973238,"d":-0.8901872915555487}]},"retail_edge_delta":{"mean":-0.01401377409305371,"se":0.027879350208453203},"arb_edge_delta":{"mean":0.09684789550922551,"se":0.01017957210651716},"reconciliation_max_abs":1.0658141036401503e-13,"gas":{"max_ok":229585,"init_max_ok":243134,"oog":0,"other_halts":0},"valid":true},{"search_i":0,"rank":2,"params":{"g":0.5,"c_bps":3,"m_bps":3},"paired":{"n":256,"mean_diff":0.1255154907063163,"se":0.025532423039148888,"worst":[{"seed":973043,"d":-1.3658516874006636},{"seed":973158,"d":-1.2444057880278478},{"seed":973132,"d":-0.9653877878774892},{"seed":973057,"d":-0.903526909317236},{"seed":973071,"d":-0.7821622696567374}]},"retail_edge_delta":{"mean":0.06060045447692475,"se":0.025988675914514352},"arb_edge_delta":{"mean":0.06491503622939158,"se":0.009678331020643147},"reconciliation_max_abs":1.0302869668521453e-13,"gas":{"max_ok":229607,"init_max_ok":243134,"oog":0,"other_halts":0},"valid":true}],"selection":"Top three valid search scores rechecked on 973000..973255; highest valid recheck mean frozen before held-out.","frozen_search_i":0},"held_out":{"comparator":"RS2","seed_start":974000,"seed_end":974511,"n":512,"mean_diff":0.10672709108623302,"se":0.017976469621765863,"worst":[{"seed":974204,"d":-1.467038717679202},{"seed":974097,"d":-1.412599418878699},{"seed":974290,"d":-1.1446716689056302},{"seed":974197,"d":-1.0540979367962109},{"seed":974005,"d":-0.963545553320273}],"candidate_mean_edge":523.2357482209928,"rs2_mean_edge":523.1290211299066,"valid":true},"held_out_deltas":{"seed_start":974000,"deltas_in_seed_order":[0.5368416830144156,0.2513405787422016,0.5332771119100244,-0.1297106017277656,0.4039223606048381,-0.963545553320273,0.02107513588657639,0.05426043564983729,0.3913904765793177,-0.13085932851998905,0.046647997768218374,-0.17916100903102006,0.3913536480656603,0.29483528978789764,0.020522571801393497,-0.0022101346764316077,0.44863663744587257,0.13006065118827337,-0.401545871107146,-0.04676856084267911,-0.3937399288013239,0.8366016042436968,-0.12268985076104855,0.290849452703128,0.391086391713543,0.8895237571554162,0.4462163362912861,-0.15484425227589327,0.18975747496796203,0.38467134565019023,-0.0022030011120932613,0.2548242935434928,0.2118147175505669,-0.2999488177188141,0.6173359621055852,-0.4733680799681679,-0.22030197286579778,0.19514866599371317,0.5373974299691326,-0.2677370932907479,0.3865251493865003,0.7643057691612967,0.2800545293177379,0.0713035931999002,0.4383197465929243,0.038368938808162056,0.39690304549105804,0.2160300017566783,0.372354372186237,-0.15931207231079725,-0.06105337214745532,-0.15978266831200472,0.4356955892313863,-0.4126586348791079,0.003929857733055542,-0.01753764103307276,0.4952167044013436,0.41775011346487645,0.4119302615375773,0.6304998761820002,-0.20400774974757496,-0.2067488671865476,0.1304575147197511,0.13834207867319037,0.02902058017411946,0.43491408476518245,0.5439982350882815,0.28517889185150125,-0.3351961500865741,-0.3159477493570648,0.58125839061222,0.11704947689366918,0.043992115179150915,0.46218338242204027,-0.2573435337941419,0.4731107712817675,-0.14488725830847216,0.07511891093724898,0.7797223850207047,0.33448998160821475,-0.3639020962774566,0.715164784218473,1.4300276883346896,0.41217115544037597,0.23779186531180585,0.16923399325889932,0.36176294603524184,0.2467515756144394,0.6741668570201682,-0.38903316982225533,0.2555030078352729,-0.38210436257759284,0.07314775716042732,0.24382319588460177,0.2534227935549893,-0.030139532028670146,0.49909160116715157,-1.412599418878699,0.4070511120560809,0.08902020507173347,0.4305621889801614,0.6384714428339748,-0.11236058398219484,-0.47150102238992986,-0.16110753212467444,0.38267629123106417,-0.20047393303468652,0.08230119994402685,0.5566391368993209,-0.08853428347504178,0.28550591223392985,1.2173808788967335,-0.3867860832990573,0.4183873610857063,0.5052508764806021,-0.15735060166770154,-0.2749914554865427,-0.14559318062742932,-0.22332624260070588,0.10123110051677031,0.17881161919530086,0.8431182133862194,0.1399717194206005,-0.0981746373175838,-0.012339678962746348,0.19882939746048578,0.002883908810531466,-0.5636052506414444,0.324717469025245,0.2548813677221915,0.12919282124551046,-0.17997657000375966,0.016381354421241667,-0.36580377282041354,0.40358626766783345,0.9485599168518775,0.6089740296299055,0.1444908841671122,0.20072008921039242,0.9543752571995583,0.7620591727735473,-0.48648794975076726,0.12455218513093769,-0.12183942254989688,0.10092102756698296,-0.16377175303762215,0.19063060542868016,0.27355571503983356,0.03045424412414377,-0.28145590101388507,0.29794880953465963,-0.35515896512379186,0.22518648271284292,0.41419377012704217,-0.30853685390854935,0.6895774461220299,0.4813680061780019,-0.5783318024095934,0.1889454708377798,-0.054245280372128946,0.2779579355947135,0.18905793492263,0.32086397834160607,-0.42889136116042437,-0.20458976785539562,1.1474466142985875,-0.18407348988358763,0.26100826086951656,0.1198995512535248,0.4653774389429941,0.354189516940437,-0.20494720528125754,0.6129442262551947,-0.8094217403483981,-0.09625532946802196,-0.3601463456614624,0.2676899467301155,0.7935125197543584,0.08155325048426221,0.4840219142076876,0.12511954519595747,-0.22730032950732948,-0.3341833496319282,0.11602203351299067,-0.35291056456810566,-0.010008631974130822,-0.4397961354261497,-0.6093096423436464,-0.03597577554944564,0.4474765277810775,0.14044224204394595,-0.19368777050999597,0.6338230116967907,0.5172174486642689,-0.0877694976222756,-0.13336183022141768,-0.3118021291356854,-1.0540979367962109,0.24599327436590102,0.08687724482422254,0.43659795454340156,-0.3740801018614661,-0.14701433547259057,-0.5058449595272805,-1.467038717679202,0.33255745843996465,-0.016836457986642017,-0.47092594970445134,0.7287822297770958,-0.5184377744299127,-0.08923253715522605,0.024284997518691398,-0.26354405144900284,-0.7251901213196561,0.49333602777937813,1.0235898411262951,0.36134795029943234,0.15824765372713046,0.24198443226742938,-0.3038149446635998,0.3059483867183985,0.6225301095678333,-0.013214450440500514,0.173758436999492,0.04823984576262319,-0.3800810539361237,-0.16139082749680256,0.10470159974681792,-0.18615591738262083,-0.254015139446949,0.2206293787536424,-0.23089599980608,0.16859663154599502,-0.023049055209241942,0.21509559579931192,0.11003145839686113,0.47198774934952326,-0.001712225662970468,0.11364626283420876,-0.3211616337840155,-0.8357129716061991,-0.41773800542569006,-0.1375474017409033,-0.22975320703176294,-0.3729288968362994,0.8560967226877665,-0.1500222706436034,-0.035286413514086234,0.3046730097166801,0.40291758556327295,0.020494798639902,-0.3329876820548634,-0.38290897387150835,-0.3043845278087929,-0.2691323093090432,0.13177213639721685,0.05580104865782687,-0.06575036391603817,-0.7832295410280494,0.8424229255201681,0.21777727951837278,0.08544181695350517,-0.22273539427055766,0.46567135287853034,-0.1851049160219418,0.5177266112602297,0.344168145522076,0.28137511664976955,0.20436654895775064,0.2075212646357727,0.11280322934027254,-0.004270447659337151,-0.24898473388566345,0.85982126543405,0.11270361681835084,0.1040157597169582,-0.46503802534141414,-0.5628284335065246,0.04137236330075211,-0.6629061623297048,-0.03746482205281154,0.32379018335780074,0.8492474405547341,0.15183660105856234,0.35486165186568996,0.0281590639449405,0.02825473288851299,0.5331815321879958,-0.19625877963107996,0.31772994461630333,-1.1446716689056302,-0.28790810476596107,0.28174759103677616,-0.2806912639748589,0.5294150094439374,-0.19794457619627792,0.05077668185481343,0.44229254458150535,0.13150526033314236,0.5296830147032097,0.2677739243400765,-0.011262728473070638,0.5339988271416587,0.7129799008567943,0.22651433888171368,-0.025345425483578765,-0.08442354491745618,-0.0190826927840817,-0.005754153208329171,0.1251476389209074,0.1105329378639226,0.3739492052956166,-0.09273070690926488,0.07545901816178002,0.37758668296828546,0.47423827625573267,0.398039700679476,-0.2779953745260286,-0.027736511874536518,0.3374645793455784,0.3483676763072481,-0.20677393955315893,0.5980241953193399,-0.20586544800386264,0.7507145624929308,-0.22479018879494106,-0.5083863680927152,0.32687031049209736,0.3501736034353371,0.05415556612058481,0.05273091729134194,-0.36373235148812455,-0.17662591308817355,0.14687992537483296,0.13941046824174919,0.4093064350638542,0.501265155481633,0.0004275633073689278,-0.1424199199975078,0.18166224646489582,0.010254907711612304,-0.38219941443276184,0.02879525142930106,-0.0020086637845224686,0.22137072698649263,0.6305492649927373,-0.09397204655738278,-0.13879694455198432,0.4470681220672077,-0.19166445217513228,0.4105748947340544,-0.1504246077067819,0.7312867140093999,-0.0166217446559358,0.21024026940335716,0.7676532537744833,0.17742054864550028,-0.756145057292315,0.11138792597427027,-0.40878987844553194,0.5258850823677221,0.5500075911401154,0.31966537782767546,-0.04318150396505871,-0.051421621710801446,-0.12847676537387542,0.3232415886408262,0.5448662239214173,0.39279326717115737,-0.25929019544992116,0.013110929487083922,0.1555640096512434,0.299591845918485,-0.3280293657250013,0.08368133234944253,-0.010935742159574602,0.1477609644741733,-0.1677503446250057,-0.20173190208362257,0.23855688112337248,0.2638230660309091,0.35300826717104883,0.34020864277738383,-0.16596180626999057,-0.3339337765808068,0.05530376315141439,-0.0995282268244182,0.4569777219865614,0.4712776988358769,0.45281100811394026,0.2770022880279157,1.2517415948275357,-0.8840453353545854,-0.5282572959158642,-0.11489098906270101,0.7826242030823778,-0.4245905031025359,0.6196909232851908,0.39910302853621715,0.4822152886587219,0.05669686104579341,0.35773277808107196,0.8045197897813523,0.3097537397643464,0.3477659526389516,-0.6021842081257773,0.3995775279619238,-0.3705847919313783,-0.8546922932627012,-0.18009064305522315,-0.2774112012348837,0.19480584941038614,0.24112452245486793,-0.46468518786855384,0.32104881815928366,0.02743798220581084,-0.11312437576634693,0.20016621859366523,-0.08355424330244432,-0.10864710833163826,-0.3358754088390583,-0.18725111113224102,0.7476782583380555,0.6548648030656068,-0.6520908550580771,0.1388505644988527,-0.6001420451628974,0.4874723864037378,0.13851072399450004,0.28397551458937187,0.16986500691007222,0.39112364666220856,-0.2856158064136025,-0.014134990695083616,-0.15209630545570008,-0.13058122889060542,-0.3210137966697175,0.4718430300458749,0.5415311231205351,1.7143845459258955,0.8154444737268705,0.19039769492167125,0.13593980278653817,-0.06557262016417553,0.31144145623403574,0.26431003669313213,0.24834897586470106,-0.17912462504176574,1.2388282763474763,-0.2631206817405882,0.4124172569778466,0.1986752849727509,-0.22567159800985337,0.372345214725442,0.26856277245752835,0.3055587738271015,-0.4381098309023628,0.164479649670227,0.7996919572884735,0.10246043501786062,0.4783285664074697,0.9945326503063825,-0.13338799353891773,-0.43459095649905066,0.40109807273825027,0.028303750346140077,-0.19705383992311454,-0.09293903035040785,0.6340204825078217,-0.2150122609345999,-0.16176553432086394,-0.8890424986441303,-0.31637340486912535,0.8042728462075956,0.08799381771257231,0.17452559727132666,-0.14730541593655744,0.4151926874236551,0.36422191430926887,-0.13532231711974418,0.5260514563075276,-0.080313448192328,0.2148602255640526,-0.5145854509926266,-0.18610700263707258,0.2937754767772276,-0.059844945838733565,0.04157275316651976,-0.0368362449628421,-0.26772029554661003,0.07234836623268848,0.5596436719686153,0.11414948123575641,0.25692346710832226,0.19877523410173126,0.28507811559842366,-0.11577986336430968,0.02757327140898269,0.9685239998407837,0.06035808976281487,0.2611862411911261,-0.1798013285616662,0.1798626723293637,0.9705925086125831,0.3123818198520212,0.3075439105654141,0.9677352114719611,0.012413158241145084,-0.0232677025802559,-0.8345421858905411,0.5174408969365913,-0.3145462123924858]},"edge_delta_comparator":"RS2 on held-out seeds 974000..974511","retail_edge_delta":{"mean":0.041726926139538656,"se":0.01823346933036899},"arb_edge_delta":{"mean":0.06500016494669236,"se":0.006814204380471846},"gas":{"max_ok":229745,"init_max_ok":243134,"oog":0,"other_halts":0,"scope":"Frozen candidate: matching search evaluation, 256-seed recheck, 512-seed held-out, and 2000-seed STACK confirmation if present; per-20-seed gas resets. Maxima are Submission callbacks; halt counts include both market roles.","valid":true},"checks":{"calibration":{"strategy":"CH","seed_start":0,"n":1000,"mean":525.5258821780834,"expected":525.5258821780834,"exact_match":true},"neutral":{"seed_start":974600,"n":32,"exact_equal_edges":true,"max_abs_diff":0,"sha256":"33353764264ab2c64dbfbb402daebad2d75e1dfc3a1797cc6f335b079bad0c9e"},"rs2_sha256":"f24b6ca198b744c380842c3a17964a6dc21f311bb04984b26733afa3fee8eaf2","quote_algebra":{"random_cases":10000,"max_relative_residual":4.440892098500626e-16},"held_decomposition_reconciliation_max_abs":1.0658141036401503e-13,"validation":"Validating strategy...\nCompiling strategy...\nStrategy 'censored_10' validated successfully!\n","rejected_initial_implementation":{"archived_evaluations":7,"max_ok":247614,"oog":0,"reason":"afterSwap >= 235000; results rejected before repair"}},"paired":{"n":2000,"mean_diff":0.46142543424383803,"se":0.014421981194200304,"worst":[{"seed":5831523,"d":-2.8535843006764026},{"seed":5830295,"d":-2.504735871013281},{"seed":5831063,"d":-1.803563135098102},{"seed":5830603,"d":-1.7869122000541893},{"seed":5831380,"d":-1.5907545222888757}]},"paired_comparator":"STACK on reserved fresh confirmation seeds 5830000..5831999","stack_confirmation":{"candidate_callback_counts":{"afterInitialize":2000,"afterSwap":20757921,"getName":2000},"source":"https://api.imd.fun/artifacts/c33720874aa1285e9dc766540b8a90410118a8e8b840d949ea0dcc211bdb27c1","seed_start":5830000,"seed_end":5831999,"paired":{"n":2000,"mean_diff":0.46142543424383803,"se":0.014421981194200304,"worst":[{"seed":5831523,"d":-2.8535843006764026},{"seed":5830295,"d":-2.504735871013281},{"seed":5831063,"d":-1.803563135098102},{"seed":5830603,"d":-1.7869122000541893},{"seed":5831380,"d":-1.5907545222888757}]},"retail_edge_delta":{"mean":0.4351998569434834,"se":0.014520802628976544},"arb_edge_delta":{"mean":0.026225577300355102,"se":0.006463521049365987},"reconciliation_max_abs":1.1368683772161603e-13,"gas":{"max_ok":229745,"init_max_ok":243134,"oog":0,"other_halts":0},"stack_gas":{"max_ok":211588,"init_max_ok":220962,"oog":0,"other_halts":0},"valid":true},"generator_source":"from pathlib import Path\nINSERT = '''\n        if (VQ_GAIN != 0) {\n            (bidFee, askFee) = _vanillaQuote(trade, spot,\n                wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000),\n                !firstInStep || arbProbability < WAD / 2,\n                feeUsed, bidFee, askFee);\n        }\n'''\nHELPER = '''\n    // Two virtual reserves; lazily initialized to avoid afterInitialize writes.\n    function _vanillaQuote(TradeInfo calldata t, uint256 spot, uint256 fair,\n        bool retail, uint256 usedFee, uint256 bid, uint256 ask)\n        internal returns (uint256, uint256)\n    {\n        uint256 vx = slots[16];\n        uint256 vy = slots[17];\n        bool firstModel = vx == 0;\n        if (!firstModel && vy == 0) vy = wdiv(wmul(t.reserveX, t.reserveY), vx);\n        uint256 k;\n        uint256 vs;\n        if (vx == 0) {\n            // Both pools started with equal reserves and keep fees outside k.\n            k = wmul(t.reserveX, t.reserveY);\n            vs = slots[5]; // Prior RS2 estimate, still the initial price here.\n        } else {\n            k = wmul(vx, vy);\n            vs = wdiv(vy, vx);\n        }\n        uint256 vg = WAD - 30 * BPS;\n        uint256 lo = wmul(fair, vg);\n        uint256 hi = wdiv(fair, vg);\n        if (vs < lo) vs = lo;\n        else if (vs > hi) vs = hi;\n        if (retail) {\n            // Equal marginal bid: ownSpot*ownGamma = vanillaSpot*vg.\n            // Equal marginal ask: ownSpot/ownGamma = vanillaSpot/vg.\n            vs = t.isBuy ? wdiv(wmul(spot, WAD-usedFee), vg)\n                : wdiv(wmul(spot, vg), WAD-usedFee);\n        }\n        vx = _isqrt(wdiv(k, vs) * WAD);\n        vy = wdiv(k, vx);\n        slots[16] = vx;\n        // Spread zero-to-nonzero writes over two callbacks. Until Y is stored,\n        // recover it from the shared invariant and stored X.\n        if (!firstModel) slots[17] = vy;\n        // Lower fee is RS2's attracting side. Margin is relative quote bps.\n        if (bid < ask) {\n            uint256 requiredGamma = wdiv(wmul(vs, vg), spot);\n            requiredGamma = uint256(int256(requiredGamma) * (int256(WAD) + VQ_MARGIN) / int256(WAD));\n            bid = _vqPull(bid, int256(WAD) - int256(requiredGamma));\n        } else if (ask < bid) {\n            uint256 requiredGamma = wdiv(wmul(spot, vg), vs);\n            requiredGamma = uint256(int256(requiredGamma) * int256(WAD) / (int256(WAD) - VQ_MARGIN));\n            ask = _vqPull(ask, int256(WAD) - int256(requiredGamma));\n        }\n        return (bid, ask);\n    }\n    function _vqPull(uint256 fee, int256 target) internal pure returns (uint256) {\n        // The change, rather than the final fee, is clipped to +/- c bps.\n        int256 delta = VQ_GAIN * (target - int256(fee)) / 1000000;\n        int256 cap = int256(VQ_CAP);\n        if (delta > cap) delta = cap;\n        if (delta < -cap) delta = -cap;\n        int256 next = int256(fee) + delta;\n        return next <= 0 ? 0 : clampFee(uint256(next));\n    }\n'''\ndef build(base, g, c, m):\n    constants = '\\n    int256 constant VQ_GAIN = %d;\\n    uint256 constant VQ_CAP = %d;\\n    int256 constant VQ_MARGIN = %d;\\n' % (round(g*1e6),round(c*1e14),round(m*1e14))\n    src=base.replace('contract Strategy is AMMStrategyBase {', 'contract Strategy is AMMStrategyBase {'+constants)\n    anchor='        slots[0] = bidFee; slots[1] = askFee; slots[2] = (spot << 64) | trade.timestamp;'\n    assert src.count(anchor)==1\n    src=src.replace(anchor,INSERT+'\\n'+anchor)\n    return src.replace('    struct PosteriorInput {', HELPER+'\\n    struct PosteriorInput {')\nif __name__=='__main__':\n    import sys\n    Path(sys.argv[4]).write_text(build(Path('scratch/rs2_code.sol').read_text(),*map(float,sys.argv[1:4])))\n","generator_usage":"build(rs2_artifact[\"code\"], g, c_bps, m_bps); generator_source uses only Python standard library. Baseline source: https://api.imd.fun/artifacts/19f2ec857df536e8ab62ab1da89ec6623332521ce46849f15bccff402c63e1e5","harness_source_url":"https://api.imd.fun/artifacts/33f54e81f3372088e9eced52c0174f310ac348af98ef5727b73785c088679194","conclusion":"The frozen mechanism improves RS2 by 0.10672709108623302 (SE 0.017976469621765863) on 512 held-out seeds and beats STACK by 0.46142543424383803 (SE 0.014421981194200304) on 2000 fresh confirmation seeds. The STACK comparison includes inherited RS2 improvements; the mechanism-specific increment is the RS2 comparison. This is a small positive result, far below the brief's roughly +5 local target; no top-10 or board claim is made.","notes":["All numerical comparisons are local measurements, not board results. Each arm runs alone against VanillaStrategy with run_batch(...,8), configs from the supplied harness; no seed omitted. SE is sample standard deviation of paired differences divided by sqrt(n).","Two added zero-to-nonzero storage writes are staggered: first callback stores X, second stores Y. Until Y is stored it is reconstructed from own pool invariant and virtual X; the two pools start with equal k, and simulator fees are outside reserves. No new slot is written in afterInitialize.","Retail labels are latent: subsequent prints in a step are retail; the first is classified as retail when RS2 arbProbability < 0.5. The equal-marginal observation assumes an interior route; corner allocations and unseen Vanilla-only retail can make the model wrong. No true competitor state or fair price is read.","The model uses marginal quotes, not a guessed finite order size. Attracting means the smaller of the final RS2 bid/ask fees; equal fees are left unchanged. Negative g deliberately moves away from the undercut target. Final fee caps inherited before this adjustment can be exceeded, but the standard 10% cap always applies.","Neutral g=0 compiles out all model work and matches RS2 exactly on the required 32 seeds. The Solidity getName string remains inherited from RS2.","An initial implementation wrote both new slots on the first callback. The 8-seed probe passed, but full 64-seed runs reached about 247600 gas, exceeding 235000, so that implementation and its results were rejected. The staggered-write repair preceded the timed search and all selection/held-out tests.","Search bounds, retail classification, quote interpretation and the staggered initialization are implementation choices for this mechanism, not claims from the cited essay.","The source artifact already used 5000000..5001999, so this run reserves 5830000..5831999 for fresh confirmation.","No strategy changes after freezing; held-out RS2 and fresh STACK confirmation seeds were not used to select parameters. A positive local result does not establish a top-10 board score.","The delivered code uses the challenge standard AMMStrategyBase.sol and IAMMStrategy.sol imports from the pinned checkout; no additional runtime dependency is introduced. Temporary simulator setup and experiment files are confined to disposable test/scratch/."]}
