# unc-a: uncertainty through silence Do not promote: the confirmed paired mean is negative. This is a completed local mechanism experiment, not a claimed leaderboard submission. ## Result The frozen candidate lost **4.4445128993 edge** versus NP2 on the fresh 2,000-seed block (paired SE **0.0461035766**). Mean arb edge fell by **1.7918436082** and mean retail edge by **2.6526692911**. The tested implementation does not advance the leaderboard objective. Frozen Solidity SHA-256 (UTF-8 bytes inside the `solidity` block below, including its final LF): `f624ced07140ad2609ec1b510e6924218ac5824b64b75bddf8195b3c4c23651c`. `blocked: null`. Frozen tuning point and statistics (noise values `arb` and `retail` are observation standard deviations in bps; R is their square in relative-price variance units): ```json { "point": { "q": 0.1, "arb": 45, "retail": 67, "stale": 0.675, "attract": 1.0 }, "n": 128, "mean_diff": -4.455537038627327, "se": 0.1381074665605564, "worst": [ { "seed": 10003, "diff": -9.264760621499704 }, { "seed": 10040, "diff": -8.344627517170807 }, { "seed": 10121, "diff": -7.830176977090673 }, { "seed": 10104, "diff": -7.592736087487765 }, { "seed": 10072, "diff": -7.0746018547118865 } ] } ``` One confirmation of the frozen candidate, seeds **2820000..2821999**, inclusive: ```json { "paired": { "n": 2000, "mean_diff": -4.444512899297684, "se": 0.04610357656289744, "worst": [ { "seed": 2820185, "diff": -63.769365250723695, "cand_edge": 650.1595796231769, "np2_edge": 713.9289448739006 }, { "seed": 2821690, "diff": -27.93165025512519, "cand_edge": 677.641868854156, "np2_edge": 705.5735191092812 }, { "seed": 2820484, "diff": -14.115813566123506, "cand_edge": 570.6364809576204, "np2_edge": 584.7522945237439 }, { "seed": 2821743, "diff": -14.082056403758543, "cand_edge": 682.0196541794734, "np2_edge": 696.1017105832319 }, { "seed": 2821885, "diff": -13.51124356125672, "cand_edge": 742.0724211938116, "np2_edge": 755.5836647550683 } ] }, "cand_mean": 524.4577247105348, "np2_mean": 528.9022376098325, "split": { "cand": { "arb": -33.89955966768248, "retail": 558.3572843782173, "max_residual": 4.774847184307873e-12 }, "np2": { "arb": -32.10771605947848, "retail": 561.009953669311, "max_residual": 9.777068044058979e-12 } } } ``` `worst` lists the five smallest per-seed candidate-minus-NP2 edge differences. Split entries are mean submission edge per simulation from arbitrage and retail respectively; both strategies were separately matched against Vanilla. `max_residual` measures the largest per-seed difference between total edge and arb plus retail, caused by floating-point accumulation order. ## Baseline, method, and evidence Reconstructed NP2 by inserting the specified [NP interior-routing block](https://api.imdnotdead.fun/artifacts/da313379a2e69e9286668865e06b18dfcae25732c82b934b0fd9c2ef0d8c2ff5) into [TWO](https://api.imdnotdead.fun/artifacts/528a6da78583c6142644a552c86670f9d25c20e39e92f4de44deae05ddc8cecd) before `uint256 tradeRatio =`. Its complete SHA-256 is `51f1c1a9d4999ee460eb8bbc66880da8074b173399a4f5d71f96671482e18ac0`. The prescribed setup completed once at simulator commit `6b6921f8d463314aa7c96234e1be25a25245f704`; StarterStrategy validation passed. Local [CH](https://raw.githubusercontent.com/ChengHua926/amm-challenge/d34a5199c59a4c44d5336a25f1436b4ae1f21104/contracts/src/Strategy.sol) calibration on seeds 0..999 gave **525.5258821780834**, matching the required 525.525882178. Local NP2 calibration on the same seeds gave **526.115572245986**. Each configuration uses `g=default_rng(seed)`, then draws size from uniform(19,21), rate from uniform(.6,1), sigma from uniform(.000882,.001008), in that order, and calls `build_config(seed=seed,gbm_sigma=sigma,retail_arrival_rate=rate,retail_mean_size=size)`. The pinned [configuration](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/config.py) supplies the remaining defaults, including 10,000 steps. The engine seeds its price process with seed and retail process with seed+1. Candidate and NP2 each use separate `amm_sim_rs.run_batch(strategy, vanilla, configs, 8)` calls, in chunks of at most 20 (final tuning chunk: 8; every confirmation chunk: 20). Vanilla is the compiled pinned `VanillaStrategy.sol`; candidate is never run against NP2. Means use submission edge. Paired SE is sample standard deviation (`ddof=1`) divided by sqrt(n). All 69 tuning points used only seeds 10000..10127 (128 seeds each). Swept process/observation noise, retuned both stale-price coefficients for the best completed noise points, then checked a smaller coefficient neighborhood for the strongest noise point. Selection maximizes tuning mean difference. These are selection-biased tuning estimates; confirmation data was not inspected until the code was frozen. No candidate revision or rerun followed confirmation. To obtain the requested split, scratch-only instrumentation added `submission_arb` and `submission_retail` keys to the existing result edge map at the two accumulation sites in the pinned [engine](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/simulation/engine.rs). Arb contribution is `-arb_result.profit`; retail contribution is `amount_x * fair_price - amount_y` when the AMM buys X, otherwise `amount_y - amount_x * fair_price`. Trading, random draws, total-edge accumulation and configuration were unchanged. On CH seeds 0..19 instrumented total edge matched stock exactly (maximum absolute difference 0); split residual was below 5e-12. ## Mechanism and limits Slot 13 stores WAD-scaled relative-price variance, initialized to (16 bps)^2. On each new timestamp it grows by `q * sigmaHat^2 * elapsedRaw`, using full elapsed time rather than the flow-decay cap. At each observation accepted by NP2's existing outlier gate, use `w=v/(v+R)` in place of fixed pHat alpha and store `v*(1-w)`. R takes the arb value only for a first print with innovation at most 1.22 times the pre-update sigmaHat; all other prints use retail R. Rejected observations do not contract variance. NP2's normalizer routing observation remains in place and has no separate variance update. This last choice and the hard print classification are model limitations, not measured causes of the result. The estimate still updates only when a trade callback occurs: silence accumulates process variance at the next callback. Existing fee logic then uses the updated pHat. Source retains NP2's obsolete fixed-alpha calculations and disabled revert branch; the variance gain overrides alpha on accepted observations. ## Tuning All table rows use n=128 paired seeds. `arb`/`retail` denote standard deviation in bps; stale and attract are dimensionless coefficients. R is not specified in bps directly. |Stage|q|arb|retail|STALE_DIR_COEF|STALE_ATTRACT_FRAC|n|mean_diff|se| |---|---:|---:|---:|---:|---:|---:|---:|---:| |sweep|0.25|6|45|0.685|1.05|128|-34.845484350|0.693553950| |sweep|0.25|6|67|0.685|1.05|128|-30.200983017|0.528123332| |sweep|0.25|6|90|0.685|1.05|128|-29.947066070|0.527849279| |sweep|0.25|15|45|0.685|1.05|128|-26.774004425|0.612615298| |sweep|0.25|15|67|0.685|1.05|128|-22.429037119|0.433771320| |sweep|0.25|15|90|0.685|1.05|128|-23.228850152|0.401724991| |sweep|0.25|30|45|0.685|1.05|128|-18.350093537|0.441899044| |sweep|0.25|30|67|0.685|1.05|128|-11.858394128|0.299121736| |sweep|0.25|30|90|0.685|1.05|128|-12.485186246|0.251713713| |sweep|1|6|45|0.685|1.05|128|-62.509598567|1.198411255| |sweep|1|6|67|0.685|1.05|128|-46.123374375|0.899278849| |sweep|1|6|90|0.685|1.05|128|-37.209836297|0.706174720| |sweep|1|15|45|0.685|1.05|128|-58.634007175|1.076216499| |sweep|1|15|67|0.685|1.05|128|-41.881462376|0.795817606| |sweep|1|15|90|0.685|1.05|128|-33.695929825|0.689411504| |sweep|1|30|45|0.685|1.05|128|-55.965309077|1.102082289| |sweep|1|30|67|0.685|1.05|128|-35.091915242|0.705379771| |sweep|1|30|90|0.685|1.05|128|-26.771597110|0.613426791| |sweep|4|6|45|0.685|1.05|128|-89.145277116|1.488232107| |sweep|4|6|67|0.685|1.05|128|-75.505211782|1.322954305| |sweep|4|6|90|0.685|1.05|128|-63.340619098|1.193749749| |sweep|4|15|45|0.685|1.05|128|-87.091304399|1.421436513| |sweep|4|15|67|0.685|1.05|128|-74.050996046|1.281723477| |sweep|4|15|90|0.685|1.05|128|-61.670836743|1.201380291| |sweep|4|30|45|0.685|1.05|128|-88.525843487|1.443933802| |sweep|4|30|67|0.685|1.05|128|-71.796567646|1.208396363| |sweep|4|30|90|0.685|1.05|128|-58.627873607|1.075129706| |sweep_low|0.003|15|67|0.685|1.05|128|-22.245837019|0.435350417| |sweep_low|0.003|30|67|0.685|1.05|128|-19.801398251|0.378810157| |sweep_low|0.01|15|67|0.685|1.05|128|-17.680832908|0.365075070| |sweep_low|0.01|30|67|0.685|1.05|128|-12.414038934|0.299055887| |sweep_low|0.03|15|67|0.685|1.05|128|-16.145582042|0.355629759| |sweep_low|0.03|30|67|0.685|1.05|128|-7.986735834|0.244016189| |sweep_low|0.1|15|67|0.685|1.05|128|-17.869213232|0.346396673| |sweep_low|0.1|30|67|0.685|1.05|128|-7.162708757|0.197561010| |wide|0.03|45|67|0.685|1.05|128|-7.780631391|0.207207117| |wide|0.03|60|67|0.685|1.05|128|-9.764388786|0.229183330| |wide|0.1|45|67|0.685|1.05|128|-4.519120684|0.150276526| |wide|0.1|60|67|0.685|1.05|128|-6.031936778|0.145807263| |wide|0.3|45|67|0.685|1.05|128|-9.257256102|0.247095218| |wide|0.3|60|67|0.685|1.05|128|-10.037200136|0.252801571| |stale|0.1|30|67|0.3|0.7|128|-44.884530005|0.803307582| |stale|0.1|30|67|0.3|1.05|128|-40.840490312|0.701234504| |stale|0.1|30|67|0.3|1.4|128|-39.319064506|0.657033368| |stale|0.1|30|67|0.5|0.7|128|-15.048457041|0.283203654| |stale|0.1|30|67|0.5|1.05|128|-11.787461119|0.241901929| |stale|0.1|30|67|0.5|1.4|128|-12.310723612|0.239128657| |stale|0.1|30|67|0.85|0.7|128|-123.077024829|5.206935924| |stale|0.1|30|67|0.85|1.05|128|-123.567161510|5.364694364| |stale|0.1|30|67|0.85|1.4|128|-125.126598944|5.132718380| |stale|0.1|30|67|1.05|0.7|128|-211.238532363|4.715779573| |stale|0.1|30|67|1.05|1.05|128|-213.286379078|4.546730832| |stale|0.1|30|67|1.05|1.4|128|-215.843816508|4.673388551| |stale_wide|0.1|45|67|0.5|0.9|128|-15.390373538|0.289553683| |stale_wide|0.1|45|67|0.5|1.05|128|-14.433392181|0.269196519| |stale_wide|0.1|45|67|0.5|1.2|128|-14.158212214|0.260824792| |stale_wide|0.1|45|67|0.685|0.9|128|-4.589173546|0.149790557| |stale_wide|0.1|45|67|0.685|1.2|128|-4.898846287|0.148048773| |stale_wide|0.1|45|67|0.85|0.9|128|-108.082229937|5.415443407| |stale_wide|0.1|45|67|0.85|1.05|128|-110.622254681|5.730090153| |stale_wide|0.1|45|67|0.85|1.2|128|-110.203752981|5.738695147| |fine|0.1|45|67|0.6|1.0|128|-6.751033934|0.145948305| |fine|0.1|45|67|0.6|1.1|128|-6.622154932|0.138654506| |fine|0.1|45|67|0.625|1.0|128|-5.520911566|0.126908577| |fine|0.1|45|67|0.625|1.1|128|-5.524133189|0.126071777| |fine|0.1|45|67|0.65|1.0|128|-4.750910321|0.116491672| |fine|0.1|45|67|0.65|1.1|128|-4.752431951|0.120617900| |fine|0.1|45|67|0.675|1.0|128|-4.455537039|0.138107467| |fine|0.1|45|67|0.675|1.1|128|-4.543872017|0.134414963| ## Exact edit against NP2 ```diff --- NP2.sol +++ Strategy.sol @@ -5,6 +5,9 @@ import {TradeInfo} from "./IAMMStrategy.sol"; contract Strategy is AMMStrategyBase { + uint256 constant VAR_Q = 100000000000000000; + uint256 constant VAR_R_ARB = 20249999999999; + uint256 constant VAR_R_RETAIL = 44890000000000; uint256 constant ELAPSED_CAP = 8; uint256 constant SIGNAL_THRESHOLD = WAD / 650; uint256 constant DIR_DECAY = 750000000000000000; @@ -24,7 +27,7 @@ uint256 constant GATE_SIGMA_MULT = 7200000000000000000; uint256 constant MIN_GATE = 30000000000000000; uint256 constant TRADE_TOX_BOOST = 3500 * BPS; - uint256 constant STALE_ATTRACT_FRAC = 1050000000000000000; + uint256 constant STALE_ATTRACT_FRAC = 1000000000000000000; uint256 constant RET_CAP = WAD / 35; uint256 constant TOX_CAP = WAD / 5; uint256 constant TRADE_RATIO_CAP = WAD / 5; @@ -39,7 +42,7 @@ uint256 constant ACT_COEF = 91843 * BPS; uint256 constant DIR_COEF = 20 * BPS; uint256 constant DIR_TOX_COEF = 100 * BPS; - uint256 constant STALE_DIR_COEF = 6850 * BPS; + uint256 constant STALE_DIR_COEF = 675000000000000000; uint256 constant SIGMA_TOX_COEF = 500 * BPS; uint256 constant TAIL_KNEE = 600 * BPS; uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000; @@ -50,6 +53,7 @@ slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD; slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000; slots[9] = 0; slots[10] = 0; slots[11] = 0; slots[12] = 0; + slots[13] = 2560000000000; return (BASE_FEE, BASE_FEE); } @@ -62,6 +66,7 @@ bool isNewStep = trade.timestamp > lastTs; if (isNewStep) { uint256 elapsedRaw = trade.timestamp - lastTs; + slots[13] += wmul(VAR_Q, wmul(sigmaHat, sigmaHat)) * elapsedRaw; uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw; dirState = _decayCentered(dirState, DIR_DECAY, elapsed); actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed)); @@ -100,7 +105,14 @@ if (firstInStep) { slots[11] = pHat; slots[12] = pImplied >= pHat ? 1 : 2; } uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT); if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE; - if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); } + if (ret <= adaptiveGate) { + uint256 variance = slots[13]; + uint256 noise = firstInStep && ret <= wmul(sigmaHat, 1220000000000000000) + ? VAR_R_ARB : VAR_R_RETAIL; + alpha = wdiv(variance, variance + noise); + pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); + slots[13] = wmul(variance, WAD - alpha); + } if (oppDir && REVERT_U > 0) { uint256 pre = slots[11]; if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U); ``` ## Full Strategy.sol ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {AMMStrategyBase} from "./AMMStrategyBase.sol"; import {TradeInfo} from "./IAMMStrategy.sol"; contract Strategy is AMMStrategyBase { uint256 constant VAR_Q = 100000000000000000; uint256 constant VAR_R_ARB = 20249999999999; uint256 constant VAR_R_RETAIL = 44890000000000; uint256 constant ELAPSED_CAP = 8; uint256 constant SIGNAL_THRESHOLD = WAD / 650; uint256 constant DIR_DECAY = 750000000000000000; uint256 constant ACT_DECAY = 530000000000000000; uint256 constant SIZE_DECAY = 530000000000000000; uint256 constant TOX_DECAY = 910000000000000000; uint256 constant SIGMA_DECAY = 690000000000000000; uint256 constant LAMBDA_DECAY = 990000000000000000; uint256 constant SIZE_BLEND_DECAY = 828000000000000000; uint256 constant TOX_BLEND_DECAY = 51000000000000000; uint256 constant ACT_BLEND_DECAY = 985000000000000000; uint256 constant PHAT_ALPHA = 270000000000000000; uint256 constant PHAT_ALPHA_RETAIL = 60000000000000000; uint256 constant PHAT_ALPHA_SAME = 120000000000000000; uint256 constant REVERT_U = 0; uint256 constant DIR_IMPACT_MULT = 4; uint256 constant GATE_SIGMA_MULT = 7200000000000000000; uint256 constant MIN_GATE = 30000000000000000; uint256 constant TRADE_TOX_BOOST = 3500 * BPS; uint256 constant STALE_ATTRACT_FRAC = 1000000000000000000; uint256 constant RET_CAP = WAD / 35; uint256 constant TOX_CAP = WAD / 5; uint256 constant TRADE_RATIO_CAP = WAD / 5; uint256 constant LAMBDA_CAP = 1820000000000000000; uint256 constant STEP_COUNT_CAP = 64; uint256 constant BASE_FEE = 4 * BPS; uint256 constant SIGMA_COEF = 200000000000000000; uint256 constant LAMBDA_COEF = 12 * BPS; uint256 constant FLOW_SIZE_COEF = 4842 * BPS; uint256 constant TOX_COEF = 300 * BPS; uint256 constant TOX_QUAD_COEF = 15000 * BPS; uint256 constant ACT_COEF = 91843 * BPS; uint256 constant DIR_COEF = 20 * BPS; uint256 constant DIR_TOX_COEF = 100 * BPS; uint256 constant STALE_DIR_COEF = 675000000000000000; uint256 constant SIGMA_TOX_COEF = 500 * BPS; uint256 constant TAIL_KNEE = 600 * BPS; uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000; uint256 constant TAIL_SLOPE_ATTRACT = 850000000000000000; function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) { slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[2] = 0; slots[3] = WAD; slots[4] = 0; slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD; slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000; slots[9] = 0; slots[10] = 0; slots[11] = 0; slots[12] = 0; slots[13] = 2560000000000; return (BASE_FEE, BASE_FEE); } function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) { uint256 prevBidFee = slots[0]; uint256 prevAskFee = slots[1]; uint256 lastTs = slots[2]; uint256 dirState = slots[3]; uint256 actEma = slots[4]; uint256 pHat = slots[5]; uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8]; uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10]; bool isNewStep = trade.timestamp > lastTs; if (isNewStep) { uint256 elapsedRaw = trade.timestamp - lastTs; slots[13] += wmul(VAR_Q, wmul(sigmaHat, sigmaHat)) * elapsedRaw; uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw; dirState = _decayCentered(dirState, DIR_DECAY, elapsed); actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed)); sizeHat = wmul(sizeHat, _powWad(SIZE_DECAY, elapsed)); toxEma = wmul(toxEma, _powWad(TOX_DECAY, elapsed)); if (stepTradeCount > 0 && elapsedRaw > 0) { uint256 lambdaInst = (stepTradeCount * WAD) / elapsedRaw; if (lambdaInst > LAMBDA_CAP) lambdaInst = LAMBDA_CAP; lambdaHat = wmul(lambdaHat, LAMBDA_DECAY) + wmul(lambdaInst, WAD - LAMBDA_DECAY); } stepTradeCount = 0; } bool firstInStep = stepTradeCount == 0; uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat; if (pHat == 0) pHat = spot; uint256 feeUsed = trade.isBuy ? prevBidFee : prevAskFee; uint256 gamma = feeUsed < WAD ? WAD - feeUsed : 0; uint256 pImplied; if (gamma == 0) { pImplied = spot; } else { pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma); } { uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0; uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL; uint256 prePhat = pHat; bool secondPrint = !firstInStep && stepTradeCount == 1; bool sameDir = false; bool oppDir = false; if (secondPrint) { bool up2 = pImplied >= pHat; uint256 d1 = slots[12]; if (d1 != 0) { sameDir = (d1 == 1) == up2; oppDir = !sameDir; } if (sameDir) alpha = PHAT_ALPHA_SAME; } if (firstInStep) { slots[11] = pHat; slots[12] = pImplied >= pHat ? 1 : 2; } uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT); if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE; if (ret <= adaptiveGate) { uint256 variance = slots[13]; uint256 noise = firstInStep && ret <= wmul(sigmaHat, 1220000000000000000) ? VAR_R_ARB : VAR_R_RETAIL; alpha = wdiv(variance, variance + noise); pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); slots[13] = wmul(variance, WAD - alpha); } if (oppDir && REVERT_U > 0) { uint256 pre = slots[11]; if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U); else pHat = pHat - wmul(pHat - pre, REVERT_U); } if (firstInStep) { if (ret > RET_CAP) ret = RET_CAP; sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY); } } // Interior retail routing equalizes fee-adjusted marginal prices. // Subsequent trades in a step cannot be the initial arbitrage trade. if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) { uint256 normalSpot = trade.isBuy ? wdiv(wmul(spot, gamma), WAD - 30 * BPS) : wdiv(wmul(spot, WAD - 30 * BPS), gamma); pHat = wmul(pHat, 90 * WAD / 100) + wmul(normalSpot, 10 * WAD / 100); } uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0; if (tradeRatio > TRADE_RATIO_CAP) tradeRatio = TRADE_RATIO_CAP; if (tradeRatio > SIGNAL_THRESHOLD) { uint256 push = tradeRatio * DIR_IMPACT_MULT; if (push > WAD / 4) push = WAD / 4; if (trade.isBuy) { dirState = dirState + push; if (dirState > 2 * WAD) dirState = 2 * WAD; } else { dirState = dirState > push ? dirState - push : 0; } actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY); sizeHat = wmul(sizeHat, SIZE_BLEND_DECAY) + wmul(tradeRatio, WAD - SIZE_BLEND_DECAY); if (sizeHat > WAD) sizeHat = WAD; } uint256 tox = pHat > 0 ? wdiv(absDiff(spot, pHat), pHat) : 0; if (tox > TOX_CAP) tox = TOX_CAP; toxEma = wmul(toxEma, TOX_BLEND_DECAY) + wmul(tox, WAD - TOX_BLEND_DECAY); uint256 toxSignal = toxEma; stepTradeCount = stepTradeCount + 1; if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP; uint256 flowSize = wmul(lambdaHat, sizeHat); uint256 fBase = BASE_FEE + wmul(SIGMA_COEF, sigmaHat) + wmul(LAMBDA_COEF, lambdaHat) + wmul(FLOW_SIZE_COEF, flowSize); uint256 fMid = fBase + wmul(TOX_COEF, toxSignal) + wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal)) + wmul(ACT_COEF, actEma); fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal)); uint256 dirDev; bool sellPressure; if (dirState >= WAD) { dirDev = dirState - WAD; sellPressure = true; } else { dirDev = WAD - dirState; sellPressure = false; } uint256 skew = wmul(DIR_COEF, dirDev) + wmul(DIR_TOX_COEF, wmul(dirDev, toxSignal)); uint256 bidFee; uint256 askFee; if (sellPressure) { bidFee = fMid + skew; askFee = fMid > skew ? fMid - skew : 0; } else { askFee = fMid + skew; bidFee = fMid > skew ? fMid - skew : 0; } { uint256 staleShift = wmul(STALE_DIR_COEF, toxSignal); uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC); if (spot >= pHat) { bidFee = bidFee + staleShift; askFee = askFee > attractShift ? askFee - attractShift : 0; } else { askFee = askFee + staleShift; bidFee = bidFee > attractShift ? bidFee - attractShift : 0; } } { bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat); if (tradeAligned) { uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio); if (trade.isBuy) { bidFee = bidFee + tradeBoost; } else { askFee = askFee + tradeBoost; } } } if (sellPressure) { bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_PROTECT)); askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_ATTRACT)); } else { askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_PROTECT)); bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_ATTRACT)); } slots[0] = bidFee; slots[1] = askFee; slots[2] = trade.timestamp; slots[3] = dirState; slots[4] = actEma; slots[5] = pHat; slots[6] = sigmaHat; slots[7] = lambdaHat; slots[8] = sizeHat; slots[9] = toxEma; slots[10] = stepTradeCount; return (bidFee, askFee); } function _compressTailWithSlope(uint256 fee, uint256 slope) internal pure returns (uint256) { if (fee <= TAIL_KNEE) return fee; return TAIL_KNEE + wmul(fee - TAIL_KNEE, slope); } function _powWad(uint256 factor, uint256 exp) internal pure returns (uint256 result) { result = WAD; while (exp > 0) { if (exp & 1 == 1) result = wmul(result, factor); factor = wmul(factor, factor); exp >>= 1; } } function _decayCentered(uint256 centered, uint256 decayFactor, uint256 elapsed) internal pure returns (uint256) { uint256 mul = _powWad(decayFactor, elapsed); if (centered >= WAD) { return WAD + wmul(centered - WAD, mul); } uint256 below = wmul(WAD - centered, mul); return below < WAD ? WAD - below : 0; } function getName() external pure override returns (string memory) { return "no_cubic"; } } ``` ## Checks and next Frozen candidate compiled and passed `amm-match validate`. Fixed-point invariants were checked at representative noise and sigma values and elapsed intervals 1,3,5,6,64,10000: predicted variance never fell, gain stayed in [0,1), and posterior variance stayed in [0,predicted variance]. These arithmetic checks do not establish statistical calibration. All confirmation simulations completed; no board score or gas benchmark is claimed. Next: retain NP2 if confirmation is negative. A follow-up could model the retained normalizer-routing observation's covariance explicitly and replace the hard arb/retail classification with a mixture observation model. This run does not establish that either change helps.