# unc-b: Uncertainty through silence Decision: reject this candidate as an NP2 replacement. The frozen variance-filter candidate has paired mean delta **-4.549225**, SE **0.068304**, on the prescribed 2,000-seed confirmation block. This is a local experiment, not a leaderboard result. A negative result applies to this tested implementation and search, not every possible uncertainty mechanism. `blocked = null` (setup, compilation, calibration and measurements completed). ## Provenance and calibration NP2 was reconstructed from [TWO](https://api.imd.fun/artifacts/528a6da78583c6142644a552c86670f9d25c20e39e92f4de44deae05ddc8cecd) with the specified interior-routing block from [NP](https://api.imd.fun/artifacts/da313379a2e69e9286668865e06b18dfcae25732c82b934b0fd9c2ef0d8c2ff5). Its exact source SHA-256 is `51f1c1a9d4999ee460eb8bbc66880da8074b173399a4f5d71f96671482e18ac0`. Local measured calibration (10,000 steps per seed, seeds 0..999): ```json { "CH": { "n": 1000, "mean_edge": 525.5258821780834, "se": 2.7894264590251843 }, "NP2": { "n": 1000, "mean_edge": 526.1155722459862, "se": 2.7896004178197593 } } ``` CH uses [this pinned source](https://raw.githubusercontent.com/ChengHua926/amm-challenge/d34a5199c59a4c44d5336a25f1436b4ae1f21104/contracts/src/Strategy.sol). CH matches the required 525.525882178 to the stated precision; NP2 matches the supplied rounded 526.1156. These numbers and all trial statistics below are measurements made in this run. ## Mechanism and units Slot 13 holds relative price variance in WAD units: a 16-bps RMS initial error means `v = 2560000000000`. On each new timestamp, add `q * sigmaHat^2 * elapsedRaw`, using the previous sigma estimate and uncapped actual elapsed time. At every print, compute `w = v/(v+R)`. A first print with relative implied-price residual at most `1.22 * sigmaHat` gets the arb-like observation variance; all other prints get the retail observation variance. Update pHat and `v *= 1-w` only if the existing adaptive outlier gate accepts the print. A rejected print retains its uncertainty. The existing NP interior-routing blend remains after this update and does not separately reduce v. The filter replaces NP2's fixed-alpha update, including the special same-direction second-print alpha. Unused inherited alpha/revert constants and initializations of slots 11/12 remain in the source; the old second-print/revert branches are removed. This preserves the requested bounded experiment, but also means its measured delta includes replacing that second-print mechanism. Point coordinates below are `[q, arb_observation_RMS_bps, retail_observation_RMS_bps, STALE_DIR_COEF_in_BPS, STALE_ATTRACT_FRAC]`. Observation RMS values are squared to obtain R. Both R values and q were swept; both stale coefficients were re-tuned. ## Tuning All search points used the same 100 tuning seeds, 10000..10099. The initial aggressive sweep was intentionally stopped after its completed losing points; incomplete work is excluded. The revised variance sweep and fee sweep completed. Search comparisons therefore have selection bias. A separate 156-seed tuning check (18000..18155) evaluated the selected point without changing it. Together with the search block, this is 256 unique tuning seeds at the selected point. No confirmation seeds were used for tuning. Selected point: `[0.1, 45, 67, 6850, 1.05]`. Selected point across both tuning blocks: ```json { "point": [ 0.1, 45, 67, 6850, 1.05 ], "n": 256, "mean_diff": -4.3779266674661965, "se": 0.09831328488199974 } ``` Independent tuning check: ```json [ { "point": [ 0.1, 45, 67, 6850, 1.05 ], "n": 156, "mean_diff": -4.3353237908209445, "se": 0.1166635534527296 } ] ``` All completed search points (SE uses sample standard deviation, ddof=1): | phase | q | arb RMS bps | retail RMS bps | stale BPS | attract | n | mean_diff | se | |---|---:|---:|---:|---:|---:|---:|---:|---:| | initial | 0.1 | 8 | 50 | 6850 | 1.05 | 100 | -24.232342688 | 0.538304740 | | initial | 0.1 | 8 | 67 | 6850 | 1.05 | 100 | -25.877855506 | 0.541505405 | | initial | 0.1 | 8 | 90 | 6850 | 1.05 | 100 | -28.576631119 | 0.597327246 | | initial | 0.1 | 16 | 50 | 6850 | 1.05 | 100 | -14.696639552 | 0.337188782 | | initial | 0.1 | 16 | 67 | 6850 | 1.05 | 100 | -16.760059202 | 0.369287999 | | variance | 0.003 | 16 | 50 | 6850 | 1.05 | 100 | -16.875374912 | 0.418275835 | | variance | 0.003 | 16 | 67 | 6850 | 1.05 | 100 | -21.883594112 | 0.504170891 | | variance | 0.003 | 16 | 90 | 6850 | 1.05 | 100 | -28.126816740 | 0.678179309 | | variance | 0.003 | 28 | 50 | 6850 | 1.05 | 100 | -16.364671809 | 0.386936840 | | variance | 0.003 | 28 | 67 | 6850 | 1.05 | 100 | -19.889696084 | 0.446091039 | | variance | 0.003 | 28 | 90 | 6850 | 1.05 | 100 | -24.293790517 | 0.517379664 | | variance | 0.003 | 45 | 50 | 6850 | 1.05 | 100 | -18.592994827 | 0.384705820 | | variance | 0.003 | 45 | 67 | 6850 | 1.05 | 100 | -20.788063131 | 0.424875237 | | variance | 0.003 | 45 | 90 | 6850 | 1.05 | 100 | -23.994300086 | 0.499403496 | | variance | 0.01 | 16 | 50 | 6850 | 1.05 | 100 | -12.248535545 | 0.345494894 | | variance | 0.01 | 16 | 67 | 6850 | 1.05 | 100 | -17.043139526 | 0.413257778 | | variance | 0.01 | 16 | 90 | 6850 | 1.05 | 100 | -22.801630725 | 0.524027939 | | variance | 0.01 | 28 | 50 | 6850 | 1.05 | 100 | -9.724879626 | 0.297790751 | | variance | 0.01 | 28 | 67 | 6850 | 1.05 | 100 | -12.769565758 | 0.342593959 | | variance | 0.01 | 28 | 90 | 6850 | 1.05 | 100 | -16.889544823 | 0.433869891 | | variance | 0.01 | 45 | 50 | 6850 | 1.05 | 100 | -12.398627597 | 0.291110316 | | variance | 0.01 | 45 | 67 | 6850 | 1.05 | 100 | -13.417936729 | 0.331718282 | | variance | 0.01 | 45 | 90 | 6850 | 1.05 | 100 | -15.956873259 | 0.380680927 | | variance | 0.03 | 16 | 50 | 6850 | 1.05 | 100 | -10.677735584 | 0.294297041 | | variance | 0.03 | 16 | 67 | 6850 | 1.05 | 100 | -15.220441213 | 0.406874765 | | variance | 0.03 | 16 | 90 | 6850 | 1.05 | 100 | -20.217744574 | 0.449410525 | | variance | 0.03 | 28 | 50 | 6850 | 1.05 | 100 | -5.433599213 | 0.230417098 | | variance | 0.03 | 28 | 67 | 6850 | 1.05 | 100 | -8.294256783 | 0.284511537 | | variance | 0.03 | 28 | 90 | 6850 | 1.05 | 100 | -12.995602691 | 0.361252247 | | variance | 0.03 | 45 | 50 | 6850 | 1.05 | 100 | -7.598931567 | 0.224480832 | | variance | 0.03 | 45 | 67 | 6850 | 1.05 | 100 | -7.817527478 | 0.241706256 | | variance | 0.03 | 45 | 90 | 6850 | 1.05 | 100 | -10.105696873 | 0.301167609 | | variance | 0.1 | 16 | 50 | 6850 | 1.05 | 100 | -14.696639552 | 0.337188782 | | variance | 0.1 | 16 | 67 | 6850 | 1.05 | 100 | -16.760059202 | 0.369287999 | | variance | 0.1 | 16 | 90 | 6850 | 1.05 | 100 | -20.042839025 | 0.421327554 | | variance | 0.1 | 28 | 50 | 6850 | 1.05 | 100 | -6.595605368 | 0.207119474 | | variance | 0.1 | 28 | 67 | 6850 | 1.05 | 100 | -7.764770132 | 0.229784919 | | variance | 0.1 | 28 | 90 | 6850 | 1.05 | 100 | -11.204639860 | 0.314906493 | | variance | 0.1 | 45 | 50 | 6850 | 1.05 | 100 | -6.894628347 | 0.212443956 | | variance | 0.1 | 45 | 67 | 6850 | 1.05 | 100 | -4.444387155 | 0.174408098 | | variance | 0.1 | 45 | 90 | 6850 | 1.05 | 100 | -5.891116579 | 0.231176484 | | fees | 0.1 | 45 | 67 | 2000 | 0.6 | 100 | -68.924363478 | 1.340564283 | | fees | 0.1 | 45 | 67 | 2000 | 0.85 | 100 | -67.533847980 | 1.307742658 | | fees | 0.1 | 45 | 67 | 2000 | 1.05 | 100 | -66.305324317 | 1.282102683 | | fees | 0.1 | 45 | 67 | 2000 | 1.3 | 100 | -64.701157767 | 1.238357838 | | fees | 0.1 | 45 | 67 | 3500 | 0.6 | 100 | -40.541410343 | 0.817881031 | | fees | 0.1 | 45 | 67 | 3500 | 0.85 | 100 | -36.730184802 | 0.715598207 | | fees | 0.1 | 45 | 67 | 3500 | 1.05 | 100 | -34.896571833 | 0.665238362 | | fees | 0.1 | 45 | 67 | 3500 | 1.3 | 100 | -33.766021573 | 0.634962963 | | fees | 0.1 | 45 | 67 | 5000 | 0.6 | 100 | -19.723619929 | 0.401315560 | | fees | 0.1 | 45 | 67 | 5000 | 0.85 | 100 | -15.914121239 | 0.334331554 | | fees | 0.1 | 45 | 67 | 5000 | 1.05 | 100 | -14.448933338 | 0.298196304 | | fees | 0.1 | 45 | 67 | 5000 | 1.3 | 100 | -14.236591846 | 0.281439404 | | fees | 0.1 | 45 | 67 | 6850 | 0.6 | 100 | -7.630597453 | 0.216998944 | | fees | 0.1 | 45 | 67 | 6850 | 0.85 | 100 | -4.782167461 | 0.176229724 | | fees | 0.1 | 45 | 67 | 6850 | 1.05 | 100 | -4.444387155 | 0.174408098 | | fees | 0.1 | 45 | 67 | 6850 | 1.3 | 100 | -5.079884750 | 0.168811470 | | fees | 0.1 | 45 | 67 | 8500 | 0.6 | 100 | -107.851515268 | 5.840177360 | | fees | 0.1 | 45 | 67 | 8500 | 0.85 | 100 | -106.600239659 | 5.845255194 | | fees | 0.1 | 45 | 67 | 8500 | 1.05 | 100 | -110.072081092 | 5.916736100 | | fees | 0.1 | 45 | 67 | 8500 | 1.3 | 100 | -108.714682938 | 5.958979314 | | refine | 0.05 | 31.5 | 53.6 | 6850 | 1.05 | 100 | -4.707386679 | 0.173252746 | | refine | 0.05 | 31.5 | 67 | 6850 | 1.05 | 100 | -6.530781104 | 0.234221350 | | refine | 0.05 | 31.5 | 80.4 | 6850 | 1.05 | 100 | -8.621632346 | 0.284586077 | | refine | 0.05 | 45 | 53.6 | 6850 | 1.05 | 100 | -5.924872384 | 0.215831444 | | refine | 0.05 | 45 | 67 | 6850 | 1.05 | 100 | -5.780364319 | 0.230650798 | | refine | 0.05 | 45 | 80.4 | 6850 | 1.05 | 100 | -6.833601933 | 0.256485216 | | refine | 0.05 | 63 | 67 | 6850 | 1.05 | 100 | -8.310112248 | 0.227537990 | | refine | 0.05 | 63 | 80.4 | 6850 | 1.05 | 100 | -8.045891628 | 0.242627516 | | refine | 0.1 | 31.5 | 53.6 | 6850 | 1.05 | 100 | -5.610794589 | 0.192642348 | | refine | 0.1 | 31.5 | 67 | 6850 | 1.05 | 100 | -6.605027027 | 0.239572205 | | refine | 0.1 | 31.5 | 80.4 | 6850 | 1.05 | 100 | -8.182975127 | 0.237346861 | | refine | 0.1 | 45 | 53.6 | 6850 | 1.05 | 100 | -5.756636479 | 0.183929014 | | refine | 0.1 | 45 | 67 | 6850 | 1.05 | 100 | -4.444387155 | 0.174408098 | | refine | 0.1 | 45 | 80.4 | 6850 | 1.05 | 100 | -5.059469779 | 0.178725521 | | refine | 0.1 | 63 | 67 | 6850 | 1.05 | 100 | -6.581058881 | 0.166236086 | | refine | 0.1 | 63 | 80.4 | 6850 | 1.05 | 100 | -5.631246848 | 0.213520254 | | refine | 0.2 | 31.5 | 53.6 | 6850 | 1.05 | 100 | -10.535219225 | 0.343709344 | | refine | 0.2 | 31.5 | 67 | 6850 | 1.05 | 100 | -9.214490503 | 0.264113899 | | refine | 0.2 | 31.5 | 80.4 | 6850 | 1.05 | 100 | -10.163335263 | 0.266549433 | | refine | 0.2 | 45 | 53.6 | 6850 | 1.05 | 100 | -9.857614699 | 0.304858872 | | refine | 0.2 | 45 | 67 | 6850 | 1.05 | 100 | -6.081202447 | 0.209702406 | | refine | 0.2 | 45 | 80.4 | 6850 | 1.05 | 100 | -5.594203576 | 0.188964633 | | refine | 0.2 | 63 | 67 | 6850 | 1.05 | 100 | -7.700370301 | 0.211447390 | | refine | 0.2 | 63 | 80.4 | 6850 | 1.05 | 100 | -4.986272314 | 0.168063241 | ## Frozen confirmation and split The source was frozen before either confirmation run. Seeds **2830000..2831999** were used once per strategy, in separate `run_batch(candidate, vanilla, cfgs)` and `run_batch(np2, vanilla, cfgs)` calls, each containing 20 seeds. No candidate-vs-NP2 market was run. The paired statistic is the candidate submission edge minus NP2 submission edge for the same seed; `se = sd(d, ddof=1)/sqrt(n)`. Worst five are sorted by this difference. ```json { "frozen": { "point": [ 0.1, 45, 67, 6850, 1.05 ], "sha256": "1b8478a435142e4161cfe0c9cca0f09e7d05a2f75af7a9403d1c29c2bd251453" }, "paired": { "n": 2000, "mean_diff": -4.549225241541906, "se": 0.06830355015885502, "worst5": [ { "seed": 2830526, "diff": -111.12981941336011, "cand": 518.929864305896, "np2": 630.0596837192561 }, { "seed": 2830107, "diff": -54.82429413129927, "cand": 479.1120802365545, "np2": 533.9363743678538 }, { "seed": 2831734, "diff": -12.651076094096993, "cand": 572.0773673004599, "np2": 584.7284433945568 }, { "seed": 2830147, "diff": -12.100142597754825, "cand": 505.9574590829794, "np2": 518.0576016807343 }, { "seed": 2830228, "diff": -11.52463871684597, "cand": 770.4244353122745, "np2": 781.9490740291204 } ] }, "split": { "cand": { "edge": 519.8530047173576, "arb": -31.990153751821534, "retail": 551.8431584691792, "max_split_residual": 5.343281372915953e-12 }, "np2": { "edge": 524.4022299588995, "arb": -31.174194141646304, "retail": 555.576424100546, "max_split_residual": 5.5706550483591855e-12 } } } ``` Split values are mean per-seed edge, not trade volume or PnL. Candidate-minus-NP2 arb contribution is -0.815959610; retail contribution is -3.733265631. Both contributions declined. The worst two paired losses are much larger than the other three reported tail observations; those observations remain included in the mean and SE. Arb edge is negative arbitrageur profit; retail edge uses the existing trade-edge formula in the [pinned simulator engine](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/simulation/engine.rs). To expose the split, a scratch-only diagnostic build separately accumulated those existing arb and retail contributions and appended them to the result edges map. It did not change market or strategy logic. Before use, total edge was compared with the unmodified build on 20 NP2 seeds (10000..10019): `{"n": 20, "max_edge_diff": 0, "max_split_residual": 2.5011104298755527e-12}`. NP2's 1,000-seed calibration above also used that diagnostic build; CH and the initial variance search used the original build. Split roundoff residuals on confirmation are reported above. ## Reproduction and checks Simulator commit: `6b6921f8d463314aa7c96234e1be25a25245f704`. The supplied item-specific setup script ran once successfully from the scratch checkout root; StarterStrategy validation passed. Subsequent simulator commands sourced `scratch/env.sh`. Solidity compilation used the pinned compiler's [0.8.24, optimizer 200, viaIR, Paris settings](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/evm/compiler.py). The frozen strategy also passed `amm-match validate`. The [MatchRunner draw order](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/match.py) was reproduced explicitly. Vanilla is the compiled [30-bps VanillaStrategy](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/contracts/src/VanillaStrategy.sol). Each seed used the following configuration: ```python rng = numpy.random.default_rng(seed) size = rng.uniform(19, 21) rate = rng.uniform(.6, 1) sigma = rng.uniform(.000882, .001008) cfg = amm_sim_rs.SimulationConfig( n_steps=10000, initial_price=100, initial_x=100, initial_y=10000, gbm_mu=0, gbm_sigma=sigma, gbm_dt=1, retail_arrival_rate=rate, retail_mean_size=size, retail_size_sigma=1.2, retail_buy_prob=.5, seed=seed) # Engine price RNG uses seed; retail RNG uses seed + 1. # Each batch is at most 20 configs, n_workers=8. candidate_results = amm_sim_rs.run_batch(list(candidate_bytecode), list(vanilla_bytecode), configs, 8) reference_results = amm_sim_rs.run_batch(list(np2_bytecode), list(vanilla_bytecode), configs, 8) d = numpy.array([a.edges['submission'] - b.edges['submission'] for a, b in zip(candidate_results.results, reference_results.results)]) mean_diff = d.mean() se = d.std(ddof=1) / len(d)**.5 ``` The machine's scratch simulator/dependencies are experiment tooling, not part of the delivered strategy. The full source below imports the competition's standard base/interface. The arb-like classifier is observable-only; it never reads fair price or actor type. Confirmation rows were checked for exact seed coverage/order; arb+retail sums were checked against totals. The Markdown source block hash and final LF, output byte bound, JSON validity and quote presence were checked locally. ## Delta (exact edit against reconstructed NP2) ```diff --- NP2.sol +++ Strategy.sol @@ -49,7 +49,7 @@ 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[9] = 0; slots[10] = 0; slots[11] = 0; slots[12] = 0; slots[13] = 2560000000000; return (BASE_FEE, BASE_FEE); } @@ -59,9 +59,11 @@ uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8]; uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10]; + uint256 variance = slots[13]; bool isNewStep = trade.timestamp > lastTs; if (isNewStep) { uint256 elapsedRaw = trade.timestamp - lastTs; + variance += wmul(100000000000000000, 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)); @@ -87,24 +89,16 @@ { 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; } + // Relative price variance in WAD units; first small-residual prints + // receive the lower observation variance. + uint256 observationVariance = firstInStep && ret <= wmul(sigmaHat, 1220000000000000000) + ? 20250000000000 : 44890000000000; + uint256 alpha = wdiv(variance, variance + observationVariance); 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 (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 (ret <= adaptiveGate) { + pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); + variance = wmul(variance, WAD - alpha); } if (firstInStep) { if (ret > RET_CAP) ret = RET_CAP; @@ -197,7 +191,7 @@ 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; + slots[9] = toxEma; slots[10] = stepTradeCount; slots[13] = variance; return (bidFee, askFee); } @@ -223,5 +217,5 @@ return below < WAD ? WAD - below : 0; } - function getName() external pure override returns (string memory) { return "no_cubic"; } + function getName() external pure override returns (string memory) { return "silence_variance"; } } ``` ## Full Strategy.sol SHA-256 of exactly the following Solidity block, including its final LF: `1b8478a435142e4161cfe0c9cca0f09e7d05a2f75af7a9403d1c29c2bd251453`. ```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 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 = 1050000000000000000; 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 = 6850 * BPS; 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]; uint256 variance = slots[13]; bool isNewStep = trade.timestamp > lastTs; if (isNewStep) { uint256 elapsedRaw = trade.timestamp - lastTs; variance += wmul(100000000000000000, 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; // Relative price variance in WAD units; first small-residual prints // receive the lower observation variance. uint256 observationVariance = firstInStep && ret <= wmul(sigmaHat, 1220000000000000000) ? 20250000000000 : 44890000000000; uint256 alpha = wdiv(variance, variance + observationVariance); 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); variance = wmul(variance, WAD - alpha); } 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; slots[13] = variance; 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 "silence_variance"; } } ``` ## Next Keep NP2. The tested variance/Kalman replacement does not justify a leaderboard submission. A separate future experiment could preserve NP2’s second-print update and use silence uncertainty only to modulate fee skew; do not treat that untested idea as a measured gain.