{"item":"a","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    bytes constant RESIDUAL = hex\"010301fb0402fe0201010002fdfffe0200fffdff\";\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[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            uncertainty += wmul(sigmaForFast, sigmaForFast) * elapsedRaw;\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        {\n            uint256 ret = fastHat > 0 ? wdiv(absDiff(pImplied, fastHat), fastHat) : 0;\n            uint256 alpha;\n            if (firstInStep) {\n                uint256 processSigma = sigmaForFast;\n                uint256 obsVar = uncertainty + wmul(processSigma, processSigma);\n                uint256 probArb;\n                uint256 z2 = wdiv(wmul(ret, ret), obsVar);\n                uint256 density = _powWad(wdiv(WAD, WAD + z2 / 16), 8);\n                uint256 sigmaObs = _isqrt(obsVar * WAD);\n                uint256 odds = wmul(density, wdiv(6700000000000000, sigmaObs));\n                bool arbFlag = ret <= wmul(sigmaForFast, 1220000000000000000);\n                uint256 prior = arbFlag ? 650000000000000000 : 400000000000000000;\n                uint256 tr = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n                if (tr > 3000000000000000) prior = wmul(prior, 6 * WAD / 10);\n                if (silent > 1) prior = wmul(prior, 8 * WAD / 10);\n                odds = wmul(odds, wdiv(prior, WAD - prior));\n                probArb = wdiv(odds, WAD + odds);\n                alpha = wmul(probArb, 600000000000000000) + wmul(WAD - probArb, 80000000000000000);\n                slots[15] = pImplied >= fastHat ? 1 : 2;\n                uncertainty = wmul(uncertainty, WAD - alpha);\n            } else {\n                if ((slots[15] == 1) == (pImplied >= fastHat)) alpha = PHAT_ALPHA_RETAIL;\n            }\n            uint256 gate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (gate < MIN_GATE) gate = MIN_GATE;\n            if (ret <= gate) fastHat = wmul(fastHat, WAD - alpha) + wmul(pImplied, alpha);\n            slots[13] = uncertainty;\n        }\n\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalObs = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            if ((slots[15] == 1) == (normalObs >= fastHat)) {\n                fastHat = wmul(fastHat, 9 * WAD / 10) + wmul(normalObs, WAD / 10);\n            }\n        }\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 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        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        {\n            int256 g = (int256(spot) - int256(fastHat)) * int256(WAD) / int256(fastHat);\n            int256 s = int256(sigmaHat);\n            uint256 ig = g < -2*s ? 0 : g*4 < -3*s ? 1 : g*4 < 3*s ? 2 : g < 2*s ? 3 : 4;\n            uint256 sub = (firstInStep ? 2 : 0) + (silent > 1 ? 1 : 0);\n            int256 db = int256(int8(uint8(RESIDUAL[ig*4 + sub]))) * int256(BPS/2);\n            int256 da = int256(int8(uint8(RESIDUAL[(4-ig)*4 + sub]))) * int256(BPS/2);\n            bidFee = db >= 0 ? bidFee + uint256(db) : bidFee > uint256(-db) ? bidFee - uint256(-db) : 0;\n            askFee = da >= 0 ? askFee + uint256(da) : askFee > uint256(-da) ? askFee - uint256(-da) : 0;\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    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 \"no_cubic\"; }\n}\n","sha256":"1f9110932896a7eda224defaab58e86e3929ed611964cd65a91e203370266751","params":[1,3,1,-5,4,2,-2,2,1,1,0,2,-3,-1,-2,2,0,-1,-3,-1],"evaluations":53,"log":{"columns":["evaluation","generation","Db","mean_diff","se","worst","max_ok","oog","halts","seconds"],"rows":[[1,0,[1,3,1,-5,4,2,-2,2,1,1,0,2,-3,-1,-2,2,0,-1,-3,-1],-0.3146506376940037,0.049337976672252405,-1.2052596950612724,213690,0,0,34.604],[2,0,[0,-1,5,4,-11,-8,-1,-2,1,1,8,-4,-2,8,3,3,-2,-7,1,0],-1.1724875201043465,0.09700416589875745,-4.072782613442882,213531,0,0,68.922],[3,0,[-5,-3,0,-4,0,0,0,-2,2,4,1,-3,3,-2,4,-4,4,0,-5,-1],-0.4990194502399632,0.0668958086909767,-1.7557713908863661,213372,0,0,103.028],[4,0,[0,1,-4,-4,1,-2,1,3,-7,1,5,-1,-3,3,1,4,-1,-6,0,-2],-0.8916288273671737,0.08414824997506644,-4.045551059006129,213372,0,0,137.583],[5,0,[3,1,-7,-5,4,3,-3,0,2,2,4,1,0,-1,4,-9,-1,0,-6,1],-0.7904104778491634,0.08454955807466148,-2.3999153197038368,213525,0,0,170.701],[6,0,[-3,3,-1,3,5,2,-4,-6,7,0,-3,1,-1,3,0,0,-3,2,-4,3],-0.5006701569320313,0.0703898581405022,-1.6008570788653742,213531,0,0,206.061],[7,0,[6,-6,-10,2,10,-4,-5,2,-3,-2,-1,2,-2,1,-1,-3,-1,-4,0,-4],-1.1207263085577424,0.0763418938240416,-3.7050584896555847,213690,0,0,239.936],[8,0,[-4,6,0,0,2,-2,-1,2,1,-5,3,-2,-4,-4,-2,7,-5,1,-9,0],-0.514933855402159,0.07984492064860388,-3.133595418877462,213690,0,0,273.783],[9,0,[4,-1,-3,1,3,3,8,1,-2,-1,0,0,0,1,-7,3,-2,-5,3,5],-1.3290310267152385,0.05986365250295791,-2.627424558049313,213531,0,0,307.513],[10,0,[2,1,-4,11,4,-5,-3,0,-6,1,-2,5,4,-11,0,-6,4,1,2,-4],-1.264240321257831,0.08768607205384217,-2.650723694431747,213531,0,0,341.518],[11,0,[7,8,-4,1,-3,0,-5,7,-4,-1,2,-3,-1,-2,-1,-5,-2,-1,-1,0],-1.0703822950016102,0.08043485127669521,-3.2953229387463807,213690,0,0,376.694],[12,0,[-1,3,-1,-1,-3,-2,-5,2,-5,-3,1,2,-2,-8,2,1,-6,3,-3,-5],-0.456315373281857,0.07502328041294155,-2.620922798571314,213525,0,0,411.626],[13,1,[-3,2,4,-7,1,-3,4,2,2,2,0,4,-5,0,4,1,-2,0,-2,-5],-0.7294838210114687,0.0745386990362274,-1.8502001744824383,213372,0,0,446.303],[14,1,[1,13,1,2,-7,-4,-6,4,5,-2,9,-3,4,-3,3,0,-3,0,-2,-3],-1.1745129256934792,0.1054104314070129,-3.96125461043664,213531,0,0,479.789],[15,1,[2,4,0,-3,2,4,-3,2,2,4,-4,1,-1,-3,-1,2,1,-8,-6,0],-0.5690607080372612,0.055542038661243465,-1.6798146168447943,213690,0,0,513.886],[16,1,[-1,2,5,-5,-2,0,-3,5,-4,0,6,3,-1,-9,0,-2,-6,0,-4,0],-0.8286810341356929,0.08419239184976109,-3.268413199150473,213525,0,0,547.266],[17,1,[-2,-2,2,2,0,-4,-4,7,-1,-3,-2,4,-3,-3,-1,2,-8,4,-1,-4],-0.3876529391877508,0.07160663846539603,-1.7764787675696425,213690,0,0,581.777],[18,1,[-7,1,-1,-3,4,3,-4,2,6,0,-1,-2,2,-2,6,4,-1,3,-1,0],-0.6127569636683363,0.07585564412713584,-1.8620771612589806,213531,0,0,616.057],[19,1,[-3,5,-6,1,2,3,-6,7,0,0,6,-4,-7,-3,0,6,0,5,0,2],-0.8924628779337578,0.0963648200511011,-3.969579255726785,213531,0,0,650.15],[20,1,[1,2,-1,-3,-1,-2,-2,0,0,-1,3,-6,-2,-4,-7,4,-4,3,-7,-3],-0.6860844216231987,0.08362819701460784,-3.478038030054563,213690,0,0,684.627],[21,1,[6,3,0,-1,5,4,-6,-7,4,-4,5,1,6,-7,-2,-2,-1,-4,-8,0],-1.4433081192493642,0.10294086089637139,-4.311876695244337,213690,0,0,718.342],[22,1,[-5,0,-3,0,1,1,-1,4,-2,-4,-2,-2,0,-2,-2,0,0,5,-1,3],-0.32969627827016446,0.05618303285050688,-1.4840637332442839,213690,0,0,752.376],[23,1,[-2,5,-1,-1,11,0,-1,3,-5,-1,4,5,-5,-3,-5,2,-3,4,-3,-3],-1.0609794725417228,0.07928441583289116,-2.882038980893526,213690,0,0,787.483],[24,1,[-1,-3,-4,-2,2,2,-3,-4,-2,3,-1,5,-5,1,-2,3,1,1,-5,0],-0.4214240409678567,0.06379506682166607,-1.956407682209317,213684,0,0,822.557],[25,2,[-9,-3,0,-2,4,1,-8,0,1,-4,-3,-3,1,-9,-3,3,-1,0,-1,5],-0.533265269822266,0.057045919797678604,-1.6580908082681844,213690,0,0,857.443],[26,2,[-1,5,-3,0,-2,6,-8,2,-7,-2,-2,-6,-5,0,4,3,-2,-2,-2,-3],-1.0647166529869088,0.06988722908331799,-2.1329685917847314,213525,0,0,891.833],[27,2,[-8,0,10,0,0,1,-4,4,-2,0,1,3,-3,-8,-4,3,-8,2,7,-1],-1.287734833440803,0.09637455612173715,-3.142089626927259,213690,0,0,927.285],[28,2,[-4,1,-4,-1,-1,-2,-2,-1,-4,0,2,0,-5,1,4,4,-6,6,-1,3],-0.48359506901818516,0.08133631050288562,-2.2171752954379826,213531,0,0,962.063],[29,2,[-2,-3,6,3,4,2,-6,7,2,-3,-8,-5,-2,-2,-8,3,1,2,-6,3],-2.0020644065830826,0.095411589129856,-3.771237910080572,213690,0,0,997.467],[30,2,[1,6,-2,-6,-5,-1,2,1,-3,-2,-3,5,-2,0,2,13,2,0,-2,0],-1.1282712931474395,0.07093051739850904,-2.691393814914136,213372,0,0,1033.048],[31,2,[2,1,2,-2,1,-4,-8,-1,-6,-6,-4,7,-2,0,-1,-3,-2,6,-4,4],-1.0267896701447645,0.07977716179265686,-2.838747443896523,213690,0,0,1067.687],[32,2,[-1,-4,3,0,8,3,2,2,0,-5,-1,-7,-6,-1,-5,4,-7,5,-5,-4],-1.052338169896072,0.09908607161203616,-4.159253656041187,213525,0,0,1102.385],[33,2,[0,5,-2,-5,-1,5,-1,5,5,0,1,6,-8,0,-1,3,1,4,-6,2],-0.6555771839002258,0.0930913457388611,-2.9413594165421273,213690,0,0,1136.306],[34,2,[0,0,-6,6,6,-4,2,0,-3,0,-2,-2,1,0,-2,10,-1,5,0,-4],-0.9596062659538713,0.058840491096488874,-2.5610603801138723,213531,0,0,1170.476],[35,2,[-6,-4,2,-2,-3,3,-5,1,-2,7,-7,-5,2,3,-5,5,0,3,-3,3],-1.278010514050183,0.07626290297593107,-2.590566373036836,213690,0,0,1205.962],[36,2,[-13,4,-6,5,-1,1,2,8,-7,1,-3,4,-5,4,-1,3,-3,-6,-4,-3],-0.9741152376974895,0.07580345538487246,-2.5851462115905406,213531,0,0,1241.181],[37,3,[-2,4,0,1,2,4,-5,-1,0,3,2,-3,-4,-5,-7,6,0,1,-4,3],-0.7365666321830933,0.07227735464503283,-2.8258619647186833,213690,0,0,1275.864],[38,3,[-8,0,-3,-3,8,-1,-2,2,-1,-5,-1,-1,0,-2,3,4,-2,3,-4,0],-0.5237848877517113,0.04990756379955845,-1.4491722641746492,213531,0,0,1311.696],[39,3,[2,-3,2,-9,3,1,-6,1,0,0,-4,1,3,-7,3,4,1,2,-1,-1],-0.75651497766306,0.05476746252548788,-2.0494289279236,213531,0,0,1345.397],[40,3,[-7,5,-1,0,-1,4,-7,6,-1,1,-3,-1,-2,-5,0,-3,-9,4,-7,3],-0.37619522051951826,0.09683687966763221,-2.1052990374219007,213531,0,0,1379.787],[41,3,[-4,-1,1,4,4,2,3,-1,-3,-7,-2,2,-5,-2,1,0,-5,2,-7,2],-0.5712658428958859,0.08296768902104248,-2.278093237175426,213372,0,0,1414.365],[42,3,[-5,2,-2,1,1,2,-3,3,-3,-2,1,-2,0,-6,4,1,-4,-1,-1,3],-0.4316749678554137,0.05368856077404813,-1.4386717635206878,213531,0,0,1449.685],[43,3,[-10,1,-1,-3,3,-3,2,2,-2,4,6,4,-3,-1,2,9,-1,4,-7,1],-1.014174557581585,0.08251762372604936,-2.551448140779371,213372,0,0,1483.81],[44,3,[-2,3,-4,4,2,-1,-13,2,-4,-5,-2,-3,-10,-5,1,3,1,3,2,7],-1.3146483681534002,0.09522947284210732,-3.86397432628587,211482,0,0,1519.275],[45,3,[-5,6,1,-6,1,1,-6,1,-2,-7,-4,5,1,-3,0,-1,0,3,-4,8],-0.5881811345109744,0.06715491438155047,-2.078896216118551,213531,0,0,1554.11],[46,3,[-5,-4,-4,4,5,-1,1,0,-1,-1,0,2,-4,0,-7,0,-8,9,-2,1],-0.42210072658886943,0.07416953072035916,-1.9103739906319106,213531,0,0,1588.671],[47,3,[1,1,-1,-4,0,-2,-6,-1,1,-1,-1,2,0,-1,7,8,0,1,-5,0],-0.67805335740948,0.07466115582035326,-2.822745831585962,213531,0,0,1623.138],[48,3,[-6,1,-3,7,2,0,0,1,1,-2,-1,2,-6,2,7,3,-2,7,1,4],-0.6620418194713436,0.08053350424302638,-2.5248420362269144,213372,0,0,1656.782],[49,4,[-9,0,-2,5,3,-3,1,2,-5,1,3,-1,-1,-1,-2,1,-6,6,-1,-4],-0.5803927941056237,0.07060931492776439,-2.184357171793863,213531,0,0,1691.448],[50,4,[-11,1,0,3,6,4,-2,3,0,-5,3,2,-1,-8,3,-2,-3,1,-3,7],-0.41179425666701963,0.07063958848230464,-1.5675258043826261,213531,0,0,1726.451],[51,4,[-6,-3,-3,-5,10,-1,3,1,-1,2,1,-5,-4,-1,-2,0,-8,2,-9,4],-0.9216636433332175,0.0972141437772112,-3.7596416546610953,213531,0,0,1761.624],[52,4,[-2,0,-1,-5,-4,0,-7,1,-4,-3,1,4,-1,0,1,1,-9,5,-8,2],-0.480682734946666,0.08354419026859104,-2.251594171982674,213531,0,0,1797.622],[53,4,[-10,-3,2,3,7,9,-8,5,-4,4,-2,0,-2,-4,-5,3,-4,5,-3,-3],-0.9369549894982763,0.07707409250948383,-2.331528947968991,213690,0,0,1833.667]]},"recheck":[{"paired":{"n":256,"mean_diff":-0.2890065370527688,"se":0.025422559963927806,"worst":-1.9929983643547757},"retail_edge_delta":0.36334455620196304,"arb_edge_delta":-0.6523510932547318,"gas":{"max_ok":214057,"oog":0,"halts":0},"stack_gas":{"max_ok":211588,"oog":0,"halts":0},"arb_volume_check":{"candidate_abs_max":5.412621612777002e-05,"candidate_rel_max":2.4801556516482352e-09,"stack_abs_max":8.617051207693294e-05,"stack_rel_max":4.139494353929289e-09},"params":[1,3,1,-5,4,2,-2,2,1,1,0,2,-3,-1,-2,2,0,-1,-3,-1],"evaluation":1},{"paired":{"n":256,"mean_diff":-0.31485672337071957,"se":0.02286999906437466,"worst":-1.8597144351056158},"retail_edge_delta":-0.007697514719200507,"arb_edge_delta":-0.3071592086515191,"gas":{"max_ok":214057,"oog":0,"halts":0},"stack_gas":{"max_ok":211588,"oog":0,"halts":0},"arb_volume_check":{"candidate_abs_max":9.86784762062598e-05,"candidate_rel_max":4.133711298714715e-09,"stack_abs_max":8.617051207693294e-05,"stack_rel_max":4.139494353929289e-09},"params":[-5,0,-3,0,1,1,-1,4,-2,-4,-2,-2,0,-2,-2,0,0,5,-1,3],"evaluation":22},{"paired":{"n":256,"mean_diff":-0.44345704223272886,"se":0.038650347784695234,"worst":-2.380217847941367},"retail_edge_delta":2.163968997685549,"arb_edge_delta":-2.607426039918278,"gas":{"max_ok":213898,"oog":0,"halts":0},"stack_gas":{"max_ok":211588,"oog":0,"halts":0},"arb_volume_check":{"candidate_abs_max":7.132426617317833e-05,"candidate_rel_max":2.853627095130488e-09,"stack_abs_max":8.617051207693294e-05,"stack_rel_max":4.139494353929289e-09},"params":[-7,5,-1,0,-1,4,-7,6,-1,1,-3,-1,-2,-5,0,-3,-9,4,-7,3],"evaluation":40}],"held_out":{"paired":{"n":512,"mean_diff":-0.23909302626313944,"se":0.02151175567562457,"worst":-5.601101562553367},"retail_edge_delta":0.41435160324045084,"arb_edge_delta":-0.6534446295035903,"gas":{"max_ok":214045,"oog":0,"halts":0},"stack_gas":{"max_ok":211576,"oog":0,"halts":0},"arb_volume_check":{"candidate_abs_max":0.0001104982293327339,"candidate_rel_max":4.927449010719609e-09,"stack_abs_max":6.786043013562448e-05,"stack_rel_max":3.1603829340931947e-09},"seeds":[530000,530512]},"retail_edge_delta":0.41435160324045084,"arb_edge_delta":-0.6534446295035903,"gas":{"max_ok":214057,"oog":0,"halts":0},"confirm":null,"controls":{"shuffled":{"paired":{"n":512,"mean_diff":-0.5196971455567604,"se":0.021461834174538393,"worst":-2.570266522453835},"retail_edge_delta":-0.17010450774045208,"arb_edge_delta":-0.34959263781630834,"gas":{"max_ok":213886,"oog":0,"halts":0},"stack_gas":{"max_ok":211576,"oog":0,"halts":0},"arb_volume_check":{"candidate_abs_max":8.021506437216885e-05,"candidate_rel_max":3.924356910156284e-09,"stack_abs_max":6.786043013562448e-05,"stack_rel_max":3.1603829340931947e-09},"params":[3,0,-3,0,2,2,-3,-1,2,1,-5,4,2,1,1,1,-2,-1,-2,-1],"seeds":[530000,530512]},"level":{"paired":{"n":512,"mean_diff":-0.01444637617505029,"se":0.003403153167373188,"worst":-0.4630215585827955},"retail_edge_delta":-0.04143431273949018,"arb_edge_delta":0.026987936564439888,"gas":{"max_ok":212740,"oog":0,"halts":0},"stack_gas":{"max_ok":211576,"oog":0,"halts":0},"arb_volume_check":{"candidate_abs_max":9.093573316931725e-05,"candidate_rel_max":4.705000869225384e-09,"stack_abs_max":6.786043013562448e-05,"stack_rel_max":3.1603829340931947e-09},"params":[0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05],"seeds":[530000,530512],"mean_units":0.05,"code_sha256":"05260d5083abd420a7967f826611a182afaa3e1abb61b6c035a03ba4fd8d7c97"}},"table":[{"cell":0,"ig":0,"firstInStep":false,"elapsed_gt_1":false,"Db":1,"Da":0},{"cell":1,"ig":0,"firstInStep":false,"elapsed_gt_1":true,"Db":3,"Da":-1},{"cell":2,"ig":0,"firstInStep":true,"elapsed_gt_1":false,"Db":1,"Da":-3},{"cell":3,"ig":0,"firstInStep":true,"elapsed_gt_1":true,"Db":-5,"Da":-1},{"cell":4,"ig":1,"firstInStep":false,"elapsed_gt_1":false,"Db":4,"Da":-3},{"cell":5,"ig":1,"firstInStep":false,"elapsed_gt_1":true,"Db":2,"Da":-1},{"cell":6,"ig":1,"firstInStep":true,"elapsed_gt_1":false,"Db":-2,"Da":-2},{"cell":7,"ig":1,"firstInStep":true,"elapsed_gt_1":true,"Db":2,"Da":2},{"cell":8,"ig":2,"firstInStep":false,"elapsed_gt_1":false,"Db":1,"Da":1},{"cell":9,"ig":2,"firstInStep":false,"elapsed_gt_1":true,"Db":1,"Da":1},{"cell":10,"ig":2,"firstInStep":true,"elapsed_gt_1":false,"Db":0,"Da":0},{"cell":11,"ig":2,"firstInStep":true,"elapsed_gt_1":true,"Db":2,"Da":2},{"cell":12,"ig":3,"firstInStep":false,"elapsed_gt_1":false,"Db":-3,"Da":4},{"cell":13,"ig":3,"firstInStep":false,"elapsed_gt_1":true,"Db":-1,"Da":2},{"cell":14,"ig":3,"firstInStep":true,"elapsed_gt_1":false,"Db":-2,"Da":-2},{"cell":15,"ig":3,"firstInStep":true,"elapsed_gt_1":true,"Db":2,"Da":2},{"cell":16,"ig":4,"firstInStep":false,"elapsed_gt_1":false,"Db":0,"Da":1},{"cell":17,"ig":4,"firstInStep":false,"elapsed_gt_1":true,"Db":-1,"Da":3},{"cell":18,"ig":4,"firstInStep":true,"elapsed_gt_1":false,"Db":-3,"Da":1},{"cell":19,"ig":4,"firstInStep":true,"elapsed_gt_1":true,"Db":-1,"Da":-5}],"notes":{"source_refs":"Implementation inputs: sources.json entries 0-1; configs/seeds: 2-3; invariant and arb reconstruction: 4-6; compiler settings: 7; fee units: 8. Measurements are this run, not board scores.","setup":"Pinned checkout 6b6921f8d463314aa7c96234e1be25a25245f704; supplied setup.sh passed; wheel SHA-256 verified aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a; SolidityCompiler 0.8.24 viaIR, optimizer 200, paris. No network used by simulation.","base_sha256":"2eaafc7960e520b8a7fd322ec8afaff8fa677c730228a961efb509cc30b25719","reference_check":{"mean":525.5258821780834,"expected":525.5258821780834,"gas":{"max_ok":151647,"oog":0,"halts":0}},"zero_equivalence":{"seeds":[520000,520032],"n":32,"trace_sha256":"ba090b1617844d1aa0784006cee3e6a6ef542efc911d685a3b3882f54a03f472","equal":true,"stack_gas":{"max_ok":211519,"oog":0,"halts":0},"zero_gas":{"max_ok":213309,"oog":0,"halts":0}},"search":{"seed":1,"population":12,"mu":6,"initial_sigma":4,"wall_seconds":1833.6689471961,"generations":4,"evaluations":53,"budget_seconds":1800,"evaluations_completed_by_budget":52,"in_flight_overrun_seconds":33.66894719609991,"top_three_unaffected_by_overrun":true},"search_spec":"Full covariance numpy CMA-ES. m=0, sigma=4, C=I; log(mu+0.5)-log(rank) normalized weights; standard Hansen cc/cs/c1/cmu/damps with mueff; chiN approximation. Latent vectors remain continuous; evaluate np.clip(np.rint(x),-128,127). Seed default_rng(1). Complete evaluations begun before 1800s are retained; partial final generation may be used for top-3 ranking. No external optimizer package.","config":"Each arm alone vs VanillaStrategy; run_batch(bytecode,Vanilla,configs,8), contiguous chunks of 32 for memory. default_rng(seed) samples size U[19,21], then rate U[0.6,1], then sigma U[0.000882,0.001008]. 10000 steps; X=100,Y=10000,p=100,mu=0,dt=1,size_sigma=1.2,buy_prob=0.5; simulator price seed=seed, retail seed=seed+1. Result seed order checked. No seeds dropped.","seed_intervals":"All intervals are half-open. Training [520000,520064); re-check [521000,521256); held-out and controls [530000,530512). Confirmation [5024000,5026000) only when held-out satisfies mean>2se and mean>=0.05. Reused training seeds include the zero-table equivalence test only, which cannot select parameters.","mechanism":"STACK unchanged except bytes constant RESIDUAL and additive residual block immediately before tail compression. g=(spot-fastHat)/fastHat using current updated fastHat; sigmaHat current updated value. Strict lower-bound comparisons at -2,-0.75,0.75,2. silent is timestamp-lastTs, uncapped. Signed additions saturate at zero; subsequent STACK compression/caps untouched. Db int8 half-bps units. Da[ig,sub]=Db[4-ig,sub] without sign inversion. No storage slots added.","selection":"Three distinct highest valid CRN candidates rechecked once. Frozen candidate is highest valid mean on re-check, regardless of held-out or controls. Candidate source validated with amm-match validate before held-out. No post-held-out parameter changes.","decomposition":"Constant product k=X0*Y0 stays unchanged because fees are separate. Rebuild prior reserves x=sqrt(k/priorSpot), y=sqrt(k*priorSpot). For next fair p and prior ask gamma: xOut=max(0,x-sqrt(k/(gamma*p))) capped 99%; profit=xOut*p-(k/(x-xOut)-y)/gamma. For prior bid gamma: xIn=max(0,(sqrt(k*gamma/p)-x)/gamma); profit=y-k/(x+gamma*xIn)-p*xIn. Choose spot<p or spot>p; positive profit only. Arb edge=-sum(profit); retail=totalEdge-arbEdge. First prior spot 100 and fees 4bps. Reconstructed per-seed arb Y volume checked against simulator volume with absolute tolerance 1e-6 plus relative tolerance 1e-8 on decomposed STACK/candidate/control runs.","statistics":"Paired d=candidateEdge-STACKEdge by identical seed; mean arithmetic; se=sample_sd(ddof=1)/sqrt(n); worst=min(d). Retail and arb deltas are means of paired component differences. Training skips decomposition as it is not used for fitness. All fitness and paired total edges use simulator totals; only component breakdowns are reconstructed.","gas_definition":"max_ok refers only to successful Submission.afterSwap gas; afterInitialize/getName also checked for failures. Per-block gas is the named arm; stack_gas is STACK arm. Top-level gas aggregates frozen candidate training/re-check/held-out/confirmation observations; no Vanilla gas substituted. OOG, revert, other_halt, tx_error, bad_return invalidate a candidate.","all_search_gas":{"max_ok":213690,"oog":0,"halts":0},"controls":"Controls run once on held-out seeds and are never used for selection: shuffled is default_rng(1).permutation(20) of frozen Db, with mirrored Da recomputed; level is all cells exactly equal to mean(Db), preserving fractional half-bps units by replacing db with sum(Db)*(BPS/2)/20 and da=db in the same pre-compression residual block. No int8 rounding in the reported level control. Control results compare to same held-out STACK arm.","recovery":"The first re-check STACK chunk failed an overly tight absolute-only volume reconstruction assertion at seed 521022: difference 1.1665361e-5 on total 20933.7783176 (relative 5.57e-10). No candidate re-check had run. Resumed from saved search log, repeated STACK baseline, and retained scale-aware checks and actual error maxima. Search was not repeated.","level_control":{"sum_units":1,"mean_units":0.05,"fractional":true},"rounded_level_diagnostic":{"paired":{"n":512,"mean_diff":0.0,"se":0.0,"worst":0.0},"retail_edge_delta":0.0,"arb_edge_delta":0.0,"gas":{"max_ok":213654,"oog":0,"halts":0},"stack_gas":{"max_ok":211576,"oog":0,"halts":0},"arb_volume_check":{"candidate_abs_max":6.786043013562448e-05,"candidate_rel_max":3.1603829340931947e-09,"stack_abs_max":6.786043013562448e-05,"stack_rel_max":3.1603829340931947e-09},"params":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"seeds":[530000,530512]},"level_note":"An initial rounded-level diagnostic was generated by the pipeline. When the mean was fractional, the requested exact-mean level control was run separately once and is reported under controls.level. Neither diagnostic nor control selected parameters.","decision":"Held-out did not meet confirmation trigger; confirmation block left untouched. Do not claim a reliable improvement or board score from training alone."}}