{"item":"table","batch":"e04-edge-table","status":"measured_candidate_underperforms_v2","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 BID_LUT = hex\"00000000000000000000000017171718191c4e4e4e4e50538e8e8e8e9092\";\n    bytes constant ASK_LUT = hex\"8f8f8f8f91944e4e4e4e505317171718191c000000000000000000000000\";\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[2] = 0; slots[3] = WAD; slots[4] = 0;\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]; slots[15] = 0; slots[9] = 0; slots[10] = 0; slots[11] = 0; slots[12] = 0;\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 = 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[16];\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[11] = pHat; 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 = sqrt(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 bidFee; uint256 askFee;\n        int256 signedGap = (int256(spot) - int256(pHat)) * 10000 / int256(pHat);\n        uint256 gapBin = signedGap < -80 ? 0 : signedGap < -30 ? 1 : signedGap <= 30 ? 2 : signedGap <= 80 ? 3 : 4;\n        uint256 sigmaBin = sigmaHat >= WAD / 1000 ? 1 : 0;\n        uint256 countBin = stepTradeCount == 1 ? 0 : stepTradeCount == 2 ? 1 : 2;\n        uint256 lutIndex = (gapBin * 2 + sigmaBin) * 3 + countBin;\n        bidFee = uint256(uint8(BID_LUT[lutIndex])) * BPS;\n        askFee = uint256(uint8(ASK_LUT[lutIndex])) * BPS;\n        slots[0] = bidFee; slots[1] = askFee; slots[2] = trade.timestamp;\n        slots[3] = dirState; slots[4] = actEma; slots[5] = pHat;\n        slots[6] = sigmaHat; slots[7] = lambdaHat; slots[8] = sizeHat;\n        slots[16] = spot;\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    function getName() external pure override returns (string memory) { return \"no_cubic\"; }\n}\n","sha256":"6ca9da3687b27beb75ee30f8af4b7955ffb0f8e96bffe0b0d7ae64278149de65","code_bytes":12614,"baseline_v2_sha256":"28417e116f57f1029fdd1803832e852574902c1ae7253c05657f317db76da4ab","table":{"dimensions":{"signed_gap_bins":5,"sigma_bins":2,"print_count_bins":3},"runtime":{"table_reads_per_callback":2,"fee_grid_or_quadrature_loops":0},"bin_edges_gap_bps":[-80,-30,30,80],"sigma_threshold_wad":"1000000000000000","print_count_buckets":["1","2","3+"],"bid_fee_bps":[0,0,0,0,0,0,0,0,0,0,0,0,23,23,23,24,25,28,78,78,78,78,80,83,142,142,142,142,144,146],"ask_fee_bps":[143,143,143,143,145,148,78,78,78,78,80,83,23,23,23,24,25,28,0,0,0,0,0,0,0,0,0,0,0,0],"encoding":"30 uint8 basis-point entries per side, row-major (gap,sigma,count); fee = byte * 1e14 WAD."},"table_generator":{"language":"Python 3, standard library only","sha256":"6c85a4186baf3ee0bb70d87c555a847e5280b8a5dd419812db4b613ad9bbebf9","code":"\"\"\"Generate a 2-sided fee LUT by exact-router retail edge minus expected arb profit.\nAssumptions: pHat=100; our x=100,y=100*spot; normalizer x=100,y=10000,\nnormalizer fee=30bp; 20 Y retail order notional; retail arrival=.8, sides=.5;\nspot/pHat gap reps [-120,-55,0,55,120]bp; sigma reps [.0005,.0012];\nprint-count reps [1,2,4], with true price quadrature around pHat.\n\"\"\"\nimport math\nfrom pathlib import Path\nZ=(-3,-2,-1,0,1,2,3)\nW=(.005,.06,.24,.39,.24,.06,.005)\nGAPS=(-.012,-.0055,0.,.0055,.012)\nSIGMAS=(.0005,.0012)\nCOUNTS=(1,2,4)\n\ndef clamp(x,lo,hi): return max(lo,min(x,hi))\n\ndef retail_edge(fee, buy_x, spot, fair):\n    x1=100.; y1=100.*spot; x2=100.; y2=10000.; f2=.003; g1=1.-fee; g2=1.-f2\n    k=x1*y1\n    r=math.sqrt(max(0.,x1*g1*y1))/math.sqrt(x2*g2*y2)\n    if buy_x:\n        T=20.\n        split=clamp((r*(y2+g2*T)-y1)/(g1+r*g2),0.,T)\n        out=x1-k/(y1+g1*split) if split>0 else 0.\n        return split-fair*out\n    T=20./fair\n    split=clamp((r*(x2+g2*T)-x1)/(g1+r*g2),0.,T)\n    out=y1-k/(x1+g1*split) if split>0 else 0.\n    return fair*split-out\n\ndef arb_profit(fee, buy_x, spot, fair):\n    x=100.; y=100.*spot; k=x*y\n    if buy_x:\n        g=1.-fee\n        if g<=0 or not (spot<g*fair): return 0.\n        q=min(x-math.sqrt(k/(g*fair)),.99*x)\n        if q<=0: return 0.\n        yin=(k/(x-q)-y)/g\n        profit=fair*q-yin\n    else:\n        g=1.-fee\n        if g<=0 or not (spot>fair/g): return 0.\n        q=(math.sqrt(k*g/fair)-x)/g\n        if q<=0: return 0.\n        yout=y-k/(x+g*q)\n        profit=yout-fair*q\n    return max(0.,profit)\n\ndef optimize(fee_side, gap, sigma, count):\n    spot=100.*(1.+gap); scale=sigma*math.sqrt(count)\n    scenarios=[(math.exp(z*scale)*100.,w) for z,w in zip(Z,W)]\n    best=(-1e99,0)\n    for bp in range(256):\n        fee=bp/10000.\n        gross=0.; loss=0.\n        for fair,w in scenarios:\n            gross += w*retail_edge(fee,fee_side,spot,fair)\n            loss += w*arb_profit(fee,fee_side,spot,fair)\n        utility=.4*gross-loss\n        if utility>best[0]: best=(utility,bp)\n    return best[1]\n\ndef tables():\n    bid=[]; ask=[]\n    for gap in GAPS:\n      for sigma in SIGMAS:\n       for count in COUNTS:\n        bid.append(optimize(False,gap,sigma,count))\n        ask.append(optimize(True,gap,sigma,count))\n    return bytes(bid),bytes(ask)\n\ndef build(base,out):\n    src=Path(base).read_text(); bid,ask=tables()\n    src=src.replace('    uint256 constant ELAPSED_CAP = 8;','    bytes constant BID_LUT = hex\"'+bid.hex()+'\";\\n    bytes constant ASK_LUT = hex\"'+ask.hex()+'\";\\n    uint256 constant ELAPSED_CAP = 8;')\n    start=src.index('        uint256 flowSize = wmul(lambdaHat, sizeHat);')\n    end=src.index('        slots[0] = bidFee;',start)\n    body='''        uint256 bidFee; uint256 askFee;\n        int256 signedGap = (int256(spot) - int256(pHat)) * 10000 / int256(pHat);\n        uint256 gapBin = signedGap < -80 ? 0 : signedGap < -30 ? 1 : signedGap <= 30 ? 2 : signedGap <= 80 ? 3 : 4;\n        uint256 sigmaBin = sigmaHat >= WAD / 1000 ? 1 : 0;\n        uint256 countBin = stepTradeCount == 1 ? 0 : stepTradeCount == 2 ? 1 : 2;\n        uint256 lutIndex = (gapBin * 2 + sigmaBin) * 3 + countBin;\n        bidFee = uint256(uint8(BID_LUT[lutIndex])) * BPS;\n        askFee = uint256(uint8(ASK_LUT[lutIndex])) * BPS;\n'''\n    src=src[:start]+body+src[end:]\n    Path(out).write_text(src)\n    return bid,ask\n\nif __name__=='__main__':\n import sys\n b,a=build(sys.argv[1],sys.argv[2]);print('bid_bps',list(b));print('ask_bps',list(a))\n","objective":"For each fee side independently, maximize 0.4 * expected retail edge at fair value minus expected arbitrageur profit. Retail edge includes gross order flow at fair price, not fee revenue alone.","assumptions":{"our_pool":"x=100, y=100*spot; pHat=100","normalizer":"x=100, y=10000, fee=30 bps","retail_order":"20 Y notional; arrival rate 0.8; buy/sell probability 0.5","gap_representatives_bps":[-120,-55,0,55,120],"sigma_representatives":[0.0005,0.0012],"print_count_representatives":[1,2,4],"fair_price_scenarios":"pHat * exp(z * sigmaHat * sqrt(printCount)); z=[-3,-2,-1,0,1,2,3], weights=[.005,.06,.24,.39,.24,.06,.005]","fee_search_bps":"0..255 inclusive","router_model":"Uses the exact fee-adjusted router share and CFMM swap equations under these representative equal-normalizer assumptions; the fee is selected separately for each input side."}},"tuning":{"seed_range":[30000,30256],"measured_variants":[{"name":"grid_floor25_protect1","parameters":{"floor_bps":25,"protect_premium_multiplier":1,"sigma_add_bps":15,"count_add_bps":[0,5,10]},"paired":{"n":256,"mean_diff":-93.64903797917691,"se":1.6154323382637779,"worst":[{"seed":30121,"diff":-203.23011613038784},{"seed":30203,"diff":-189.56352528761386},{"seed":30031,"diff":-178.27116258888594},{"seed":30082,"diff":-173.0380869929079},{"seed":30087,"diff":-171.02620939974975}]},"gas":{"candidate":{"max_ok":241894,"oog":3,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":1302116,"ok":1302113,"max_ok":241894,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":243625,"oog":3,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2652729,"ok":2652726,"max_ok":243625,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}},{"name":"grid_floor35_protect1","parameters":{"floor_bps":35,"protect_premium_multiplier":1,"sigma_add_bps":15,"count_add_bps":[0,5,10]},"paired":{"n":256,"mean_diff":-101.49572333505184,"se":1.5787036495681377,"worst":[{"seed":30121,"diff":-208.64146781328964},{"seed":30203,"diff":-193.34065002524244},{"seed":30087,"diff":-183.4119456436335},{"seed":30031,"diff":-182.75798542987428},{"seed":30162,"diff":-173.11853125200116}]},"gas":{"candidate":{"max_ok":241894,"oog":3,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":1031526,"ok":1031523,"max_ok":241894,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":243625,"oog":3,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2652729,"ok":2652726,"max_ok":243625,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}},{"name":"grid_floor45_protect1","parameters":{"floor_bps":45,"protect_premium_multiplier":1,"sigma_add_bps":15,"count_add_bps":[0,5,10]},"paired":{"n":256,"mean_diff":-111.94139016209601,"se":1.5760839178883217,"worst":[{"seed":30121,"diff":-220.97269282825806},{"seed":30203,"diff":-202.99676578543642},{"seed":30031,"diff":-195.09921498030116},{"seed":30087,"diff":-193.1969635630523},{"seed":30082,"diff":-181.85541194249117}]},"gas":{"candidate":{"max_ok":241894,"oog":3,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":814692,"ok":814689,"max_ok":241894,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":243625,"oog":3,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2652729,"ok":2652726,"max_ok":243625,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}},{"name":"grid_floor25_protect025","parameters":{"floor_bps":25,"protect_premium_multiplier":0.25,"sigma_add_bps":5,"count_add_bps":[0,2,4]},"paired":{"n":256,"mean_diff":-136.07006522210605,"se":2.3695228278302234,"worst":[{"seed":30203,"diff":-273.41968259532223},{"seed":30121,"diff":-255.50458202420202},{"seed":30031,"diff":-245.3255892605145},{"seed":30217,"diff":-242.13016495949853},{"seed":30054,"diff":-241.44171822348682}]},"gas":{"candidate":{"max_ok":241894,"oog":3,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2776049,"ok":2776046,"max_ok":241894,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":243625,"oog":3,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2652729,"ok":2652726,"max_ok":243625,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}},{"name":"exact_router_utility_lut","parameters":{"offline_optimizer":"exact_router_utility"},"paired":{"n":256,"mean_diff":-81.52673752937073,"se":1.7803254885109567,"worst":[{"seed":30121,"diff":-188.68656851614548},{"seed":30203,"diff":-186.19433988610365},{"seed":30031,"diff":-175.25481814689033},{"seed":30162,"diff":-173.34078818018543},{"seed":30082,"diff":-171.03810134057403}]},"gas":{"candidate":{"max_ok":241912,"oog":3,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2063336,"ok":2063333,"max_ok":241912,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":243625,"oog":3,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":256,"ok":256,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2652729,"ok":2652726,"max_ok":243625,"oog":3,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":256,"ok":256,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}}],"best_mean":"exact_router_utility_lut","note":"Five measured calibrations; all lost to V2. One other parameter surface was generated but not scored."},"selection":{"seed_range":[32000,32512],"top_two":[{"name":"exact_router_utility_lut","seed_range":[32000,32512],"paired":{"n":512,"mean_diff":-85.11739024786255,"se":1.3099206510470272,"worst":[{"seed":32433,"diff":-215.6943375348585},{"seed":32030,"diff":-214.91639317895465},{"seed":32325,"diff":-193.79342627396238},{"seed":32248,"diff":-187.3984840720317},{"seed":32328,"diff":-176.9818725767907}]},"gas":{"candidate":{"max_ok":241886,"oog":8,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":512,"ok":512,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":4163255,"ok":4163247,"max_ok":241886,"oog":8,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":512,"ok":512,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":243734,"oog":8,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":512,"ok":512,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":5340621,"ok":5340613,"max_ok":243734,"oog":8,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":512,"ok":512,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}},{"name":"grid_floor25_protect1","seed_range":[32000,32512],"paired":{"n":512,"mean_diff":-96.54693497677899,"se":1.1989901958450693,"worst":[{"seed":32030,"diff":-218.24071811194835},{"seed":32325,"diff":-214.4645004383359},{"seed":32433,"diff":-208.58260538073432},{"seed":32248,"diff":-201.85444088484076},{"seed":32374,"diff":-184.9737863081076}]},"gas":{"candidate":{"max_ok":241880,"oog":8,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":512,"ok":512,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":2636527,"ok":2636519,"max_ok":241880,"oog":8,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":512,"ok":512,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":243734,"oog":8,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":512,"ok":512,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":5340621,"ok":5340613,"max_ok":243734,"oog":8,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":512,"ok":512,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}}}}],"selected":"exact_router_utility_lut","selection_rule":"Higher paired mean; selected candidate remained negative versus V2."},"freeze_record":{"frozen_before_confirmation":true,"sha256":"6ca9da3687b27beb75ee30f8af4b7955ffb0f8e96bffe0b0d7ae64278149de65","code_bytes":12614,"seed_range_confirmation":[4190000,4192000],"code_changed_after_freeze":false},"seed_ranges":{"tuning":[30000,30256],"top_two_selection":[32000,32512],"confirmation":[4190000,4192000]},"paired":{"n":2000,"mean_diff":-83.43202858965124,"se":0.6936147856954904,"worst":[{"seed":4190811,"diff":-281.13676787082795},{"seed":4191188,"diff":-277.07469848087425},{"seed":4190500,"diff":-264.6861801778454},{"seed":4191046,"diff":-227.62606995788815},{"seed":4191506,"diff":-221.74537688268708}],"volume_terciles":[{"v2_retail_volume_tercile":1,"n":666,"mean_diff":-68.68717254028161,"mean_v2_retail_volume_y":65147.82368369714},{"v2_retail_volume_tercile":2,"n":667,"mean_diff":-82.97269690609141,"mean_v2_retail_volume_y":75966.42733062633},{"v2_retail_volume_tercile":3,"n":667,"mean_diff":-98.61411009162212,"mean_v2_retail_volume_y":87092.29385057565}]},"edge_breakdown":{"unit":"Y per simulation; signed AMM edge accumulated by engine at each trade using contemporaneous true fair price.","candidate":{"retail_mean":537.3799366074069,"arb_mean":-96.39288201965397,"total_mean":440.98705458775294},"v2":{"retail_mean":551.7515844721094,"arb_mean":-27.332501294705217,"total_mean":524.4190831774041}},"gas":{"candidate":{"max_ok":242362,"oog":37,"other_errors":0,"init_max":236386,"call_counts":{"afterInitialize":{"calls":2000,"ok":2000,"max_ok":236386,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":16044708,"ok":16044671,"max_ok":242362,"oog":37,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":2000,"ok":2000,"max_ok":21554,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"v2":{"max_ok":244210,"oog":37,"other_errors":0,"init_max":236377,"call_counts":{"afterInitialize":{"calls":2000,"ok":2000,"max_ok":236377,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"afterSwap":{"calls":20645098,"ok":20645061,"max_ok":244210,"oog":37,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},"getName":{"calls":2000,"ok":2000,"max_ok":21545,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}}},"criterion":"Candidate OOG count is no greater than V2; all other errors are zero. OOG counts are reported for both."},"method":{"simulator_repository":"https://github.com/benedictbrady/amm-challenge","simulator_commit":"6b6921f8d463314aa7c96234e1be25a25245f704","host":"macOS ARM64; the prescribed Linux x86_64 host was unavailable. The pinned simulator and release extension were built and run natively; this is an architecture deviation.","runs":"Separate amm_sim_rs.run_batch(candidate, VanillaStrategy, configs, 8) and amm_sim_rs.run_batch(V2, VanillaStrategy, configs, 8); never head-to-head. Each run processed the exact requested seed interval.","configs":"For each requested seed s only: default_rng(s) draws retail mean size U(19,21), arrival rate U(.6,1), then sigma U(.000882,.001008); n_steps=10000; price seed=s; retail seed=s+1.","patches":["Applied audit instrumentation.patch for callback gas and error counters, including swallowed afterSwap failures.","Changed the scratch harness to construct only requested seed configs directly, avoiding 0..seed_end allocation.","Added separate scratch engine accumulators for retail and arbitrage edge while preserving the existing total edge accumulator.","Rebuilt the release amm_sim_rs extension after instrumentation."],"validation":{"candidate_solidity":"amm-match validate passed","confirmation_complete":true,"other_errors":0},"limitations":["Confirmation is native macOS ARM64, not Linux x86_64.","The analytical table uses representative equal-normalizer states and a discrete price quadrature; results show this model did not predict the simulator’s realized edge.","No post-confirmation tuning or candidate reselection was done."]}}