Later-b: later-print filter experiment Confirmation: **0.105127149 edge per seed**, SE **0.009620677**, n=2000, seeds 2810000–2811999. The frozen candidate has a positive independent paired result; this is a modest local gain, not evidence of reaching the top ten. **blocked:** `null`. Setup, calibration, compilation, validation, tuning, hook stress checks, split-counter equivalence checks, and confirmation completed. No board submission was made. **Baseline and sources.** NP2 was reconstructed from [TWO](https://api.imd.fun/artifacts/528a6da78583c6142644a552c86670f9d25c20e39e92f4de44deae05ddc8cecd) by inserting the specified block from [NP](https://api.imd.fun/artifacts/da313379a2e69e9286668865e06b18dfcae25732c82b934b0fd9c2ef0d8c2ff5) immediately before TWO's `uint256 tradeRatio =`. Its exact SHA-256 is `51f1c1a9d4999ee460eb8bbc66880da8074b173399a4f5d71f96671482e18ac0`. The simulator checkout was pinned to `6b6921f8d463314aa7c96234e1be25a25245f704`; the supplied item-specific setup script was run once and passed. Local calibration, with the unmodified engine: [CH](https://raw.githubusercontent.com/ChengHua926/amm-challenge/d34a5199c59a4c44d5336a25f1436b4ae1f21104/contracts/src/Strategy.sol) SHA-256 `6dd68f77a70900319460215374143dbd5d924198450a46d9f5f91f6b1e3d35c3` scored **525.5258821780834** on 0–999; NP2 scored **526.1155722459862** on the same seeds. These are newly measured local means, not quoted scores or board results. **Measurement.** Each seed s uses `g = numpy.random.default_rng(s)`, then size `g.uniform(19,21)`, rate `g.uniform(.6,1)`, sigma `g.uniform(.000882,.001008)` in that order, passed to `build_config(seed=s, gbm_sigma=sigma, retail_arrival_rate=rate, retail_mean_size=size)`. This matches the [match draw order](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/match.py) and [configuration](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/config.py). Price seed is s and retail seed s+1 in the [engine](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/simulation/engine.rs). Every run used the compiled [VanillaStrategy](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/contracts/src/VanillaStrategy.sol) as opponent. Candidate and NP2 were run in separate `amm_sim_rs.run_batch` calls, each of exactly 20 seeds, with 8 workers; never candidate versus NP2. Edge means the `submission` edge, not PnL or edge minus Vanilla. `d_s = cand_edge_s - np2_edge_s`; `se = std(d, ddof=1)/sqrt(n)`. **Filter definition and sweep.** A is `PHAT_ALPHA_RETAIL`: opposite-direction seconds and every third-or-later print. B is `PHAT_ALPHA_SAME`: only same-direction second prints, using NP2's existing comparison of the sign of `pImplied - pHat` against the stored first-print sign. It does not mean trade-side equality and does not classify third-or-later prints by direction. First-print alpha remains 0.27. A=B=0 disables the ordinary pHat update on later prints; the normalizer blend can still update pHat independently under the existing `feeUsed > 30 * BPS && gamma > 0` condition. A=0, B>0 permits only the same-direction second-print ordinary update. The gate, first-print sigma update, direction state, toxicity calculation, and all other mechanisms are unchanged. The full joint grid A,B ∈ {0,.03,.06,.09,.12} and blend ∈ {0,.025,.05,.075,.1} used 60 seeds per point, 10000–10059. At the best grid point, stale coefficient ∈ {5500,6250,6850,7500,8250} BPS and attract fraction ∈ {.85,.95,1.05,1.15,1.25} were swept. Decimal grid labels were converted to integer WAD constants using `int(round(value * 1e18))`; the exact delivered constants are in the code and diff. Duplicate points were skipped. There were 149 distinct screened points. The eight best screened points, plus requested no-update diagnostics if absent, were extended with 10060–10239 to 240 distinct seeds per point. No point exceeded 240 distinct tuning seeds. Tuning is adaptive and selected statistics are optimistic; only the final untouched block supplies independent evidence. At 240 tuning seeds, no ordinary later update without blend gave -1.596765386 (SE 0.225626034); no ordinary later update with 10% blend gave -0.940414117 (SE 0.214525816); same-direction-second-only update at 0.12 with 10% blend gave -0.086131171 (SE 0.048372027). The selected change therefore retains a small general later update rather than removing it. These endpoint comparisons are tuning results, not separately confirmed claims. **Tuning: frozen point.** ```json { "label": "grid_9", "point": [ 0.03, 0.12, 0.1 ], "n": 240, "mean_diff": 0.14140841555304604, "se": 0.030566905263280562, "worst": [ { "seed": 10182, "diff": -1.1714359148659241 }, { "seed": 10001, "diff": -0.9303041464928583 }, { "seed": 10011, "diff": -0.8874544149846315 }, { "seed": 10124, "diff": -0.8327237821450808 }, { "seed": 10151, "diff": -0.7636759724366584 } ], "sha256": "91fe9cb4553c4781f1c6e1ac3d5a036e5c0ebe09bd4ed67a2f4c059647e54fcc", "selection": "Highest mean paired difference on 240 tuning seeds; confirm not opened." } ``` **Tuning finalists (10000–10239, n=240 each).** |label|A|B|blend|stale BPS|attract|mean_diff|se| |---|---:|---:|---:|---:|---:|---:|---:| |grid_9|0.03|0.12|0.1|6850|1.05|0.141408416|0.030566905| |blend_65|0.03|0.12|0.075|6850|1.05|0.107526244|0.030200837| |stale_137|0.03|0.12|0.1|6850|1.15|0.105323302|0.035342161| |grid_8|0.03|0.09|0.1|6850|1.05|0.087042842|0.035468902| |blend_61|0.03|0.09|0.075|6850|1.05|0.061194245|0.034212009| |blend_64|0.03|0.12|0.05|6850|1.05|0.019070003|0.034532728| |grid_13|0.06|0.09|0.1|6850|1.05|0.005839566|0.021553060| |grid_14|0.06|0.12|0.1|6850|1.05|0.000000000|0.000000000| |grid_4|0|0.12|0.1|6850|1.05|-0.086131171|0.048372027| |grid_0|0|0|0.1|6850|1.05|-0.940414117|0.214525816| |grid_25|0|0|0|6850|1.05|-1.596765386|0.225626034| **paired: single frozen confirmation.** ```json { "n": 2000, "mean_diff": 0.10512714860851094, "se": 0.009620677399301244, "worst": [ { "seed": 2811371, "diff": -1.6145708489108301, "cand_edge": 668.6132480799098, "np2_edge": 670.2278189288206 }, { "seed": 2810548, "diff": -1.5130547620678954, "cand_edge": 598.423696308817, "np2_edge": 599.9367510708848 }, { "seed": 2811011, "diff": -1.3616727605543701, "cand_edge": 654.3454290690312, "np2_edge": 655.7071018295856 }, { "seed": 2810965, "diff": -1.3539767901179403, "cand_edge": 614.2804402394594, "np2_edge": 615.6344170295773 }, { "seed": 2811922, "diff": -1.3333322672033887, "cand_edge": 486.42913122053744, "np2_edge": 487.76246348774083 } ], "seed_first": 2810000, "seed_last": 2811999, "cand_mean_edge": 524.379610113548, "np2_mean_edge": 524.2744829649396 } ``` **split: mean edge per seed on that same confirmation block.** ```json { "cand": { "arb": -29.95153982945045, "retail": 554.3311499429985, "edge": 524.379610113548, "max_sum_residual": 6.139089236967266e-12 }, "np2": { "arb": -31.371831741090805, "retail": 555.6463147060304, "edge": 524.2744829649396, "max_sum_residual": 1.6370904631912708e-11 }, "paired": { "arb": { "mean_diff": 1.4202919116403554, "se": 0.008079770503173152 }, "retail": { "mean_diff": -1.3151647630318604, "se": 0.012086730837617717 } } } ``` The confirmed gain comes from reducing arb losses by 1.420291912 edge per seed, offset by a retail-edge change of -1.315164763. Both are measured on the same paired block. The net improvement is small relative to the supplied leaderboard targets; this experiment does not solve the larger mechanism problem. The pinned public result exposes total edge, not the requested arb/retail split. After tuning and freeze, two audit-only floating-point counters were added to the scratch engine: accumulate `-arb_result.profit` when the arb result belongs to `submission`, and accumulate the existing `trade_edge` when the routed trade belongs to `submission`. Their values were inserted into the result edge map under `submission_arb_audit` and `submission_retail_audit` after the simulation loop. Original edge accumulation, market calculations, ordering, RNG, contract inputs, and fee decisions were untouched. The confirmation was run once with this audit build, after these equivalence checks against saved unmodified-engine tuning outputs: ```json [ { "strategy": "NP2", "n": 20, "max_total_edge_difference": 0.0 }, { "strategy": "cand", "n": 20, "max_total_edge_difference": 0.0 } ] ``` The split components sum to total edge up to floating-point accumulation error; maximum per-seed residuals are reported above. No confirmation seeds were used for tuning, and no candidate changes followed confirmation. **delta: exact edit against reconstructed NP2.** The semantic change is `PHAT_ALPHA_RETAIL`: 0.06 to 0.03. The blend expression is written with explicit integer WAD weights but retains exactly the original 90%/10% values. The unified diff below is complete. No state slots, loops, external dependencies, or public interfaces were added. ```diff --- NP2.sol +++ Strategy.sol @@ -17,7 +17,7 @@ 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_RETAIL = 30000000000000000; uint256 constant PHAT_ALPHA_SAME = 120000000000000000; uint256 constant REVERT_U = 0; uint256 constant DIR_IMPACT_MULT = 4; @@ -118,7 +118,7 @@ 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); + pHat = wmul(pHat, WAD - 100000000000000000) + wmul(normalSpot, 100000000000000000); } uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0; ``` **Checks.** `amm-match validate scratch/Frozen.sol` passed. The pinned [compiler](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/evm/compiler.py) compiled with Solidity 0.8.24, optimizer enabled with 200 runs, viaIR, EVM Paris. Separate direct pyrevm hook calls used randomized constant-product reserve paths, both trade sides, timestamp gaps, and groups of eight same-timestamp prints, with seed 59812. Gas below is read from `evm.result.gas_used`, not the executor's estimate. All returned fees were within [0, 0.1 WAD]. This stress test is not an exhaustive proof of all possible inputs; it also matters because [CFMM](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/amm/cfmm.rs) retains old fees on hook failure. ```json { "n_calls": 5000, "initialization_gas": 189944, "max_after_swap_gas": 134363, "min_fee_wad": 0, "max_fee_wad": 100000000000000000, "all_success": true, "gas_limit": 250000 } ``` **next.** Forward this frozen candidate and its measured uncertainty for merge evaluation; do not infer the gain of combining it with other workers' changes. **All screening points (10000–10059, n=60 each).** BPS and WAD fractions as defined above. These are local measurements from this run. |label|A|B|blend|stale BPS|attract|mean_diff|se| |---|---:|---:|---:|---:|---:|---:|---:| |grid_0|0|0|0.1|6850|1.05|-1.546419356|0.830907541| |grid_1|0|0.03|0.1|6850|1.05|-0.644564099|0.286846738| |grid_2|0|0.06|0.1|6850|1.05|-0.329942292|0.170625059| |grid_3|0|0.09|0.1|6850|1.05|-0.140172921|0.103571778| |grid_4|0|0.12|0.1|6850|1.05|-0.162846407|0.112727571| |grid_5|0.03|0|0.1|6850|1.05|-1.412920229|0.796932439| |grid_6|0.03|0.03|0.1|6850|1.05|-0.511150657|0.276318129| |grid_7|0.03|0.06|0.1|6850|1.05|-0.215314673|0.154862872| |grid_8|0.03|0.09|0.1|6850|1.05|-0.007748422|0.092776233| |grid_9|0.03|0.12|0.1|6850|1.05|0.067252696|0.050562810| |grid_10|0.06|0|0.1|6850|1.05|-1.513025966|0.797630154| |grid_11|0.06|0.03|0.1|6850|1.05|-0.386212639|0.071179312| |grid_12|0.06|0.06|0.1|6850|1.05|-0.101538567|0.054863939| |grid_13|0.06|0.09|0.1|6850|1.05|0.015463236|0.042774341| |grid_14|0.06|0.12|0.1|6850|1.05|0.000000000|0.000000000| |grid_15|0.09|0|0.1|6850|1.05|-1.270016082|0.098327720| |grid_16|0.09|0.03|0.1|6850|1.05|-0.835198735|0.083116374| |grid_17|0.09|0.06|0.1|6850|1.05|-0.544396887|0.059564638| |grid_18|0.09|0.09|0.1|6850|1.05|-0.442164822|0.047833701| |grid_19|0.09|0.12|0.1|6850|1.05|-0.430726424|0.047432343| |grid_20|0.12|0|0.1|6850|1.05|-1.907056446|0.126651399| |grid_21|0.12|0.03|0.1|6850|1.05|-1.613561762|0.095717500| |grid_22|0.12|0.06|0.1|6850|1.05|-1.338961580|0.078513696| |grid_23|0.12|0.09|0.1|6850|1.05|-1.228983361|0.069712933| |grid_24|0.12|0.12|0.1|6850|1.05|-1.244360121|0.070679427| |grid_25|0|0|0|6850|1.05|-2.270096520|0.852823599| |grid_26|0|0.12|0|6850|1.05|-0.630457587|0.127404968| |grid_27|0.06|0.12|0|6850|1.05|-0.437507544|0.077204759| |blend_28|0|0|0.025|6850|1.05|-2.056414062|0.846506155| |blend_29|0|0|0.05|6850|1.05|-1.816473892|0.835194193| |blend_30|0|0|0.075|6850|1.05|-1.658210056|0.833085582| |blend_31|0|0.03|0|6850|1.05|-1.394649946|0.391511072| |blend_32|0|0.03|0.025|6850|1.05|-1.237486895|0.382390072| |blend_33|0|0.03|0.05|6850|1.05|-0.965491617|0.383550710| |blend_34|0|0.03|0.075|6850|1.05|-0.855197497|0.384948168| |blend_35|0|0.06|0|6850|1.05|-0.952808073|0.220692903| |blend_36|0|0.06|0.025|6850|1.05|-0.752170698|0.213522178| |blend_37|0|0.06|0.05|6850|1.05|-0.535987756|0.206118300| |blend_38|0|0.06|0.075|6850|1.05|-0.384807517|0.178141319| |blend_39|0|0.09|0|6850|1.05|-0.663943217|0.140434329| |blend_40|0|0.09|0.025|6850|1.05|-0.483977013|0.128107662| |blend_41|0|0.09|0.05|6850|1.05|-0.278438256|0.124318592| |blend_42|0|0.09|0.075|6850|1.05|-0.236266985|0.119448266| |blend_43|0|0.12|0.025|6850|1.05|-0.457774069|0.119533993| |blend_44|0|0.12|0.05|6850|1.05|-0.299131019|0.118169361| |blend_45|0|0.12|0.075|6850|1.05|-0.183345079|0.108482963| |blend_46|0.03|0|0|6850|1.05|-2.062071190|0.843004756| |blend_47|0.03|0|0.025|6850|1.05|-1.871700248|0.836170023| |blend_48|0.03|0|0.05|6850|1.05|-1.650110479|0.833994215| |blend_49|0.03|0|0.075|6850|1.05|-1.525717554|0.830165154| |blend_50|0.03|0.03|0|6850|1.05|-1.238952901|0.387025957| |blend_51|0.03|0.03|0.025|6850|1.05|-1.038080535|0.376452753| |blend_52|0.03|0.03|0.05|6850|1.05|-0.793129672|0.386603441| |blend_53|0.03|0.03|0.075|6850|1.05|-0.559602207|0.280245115| |blend_54|0.03|0.06|0|6850|1.05|-0.770569210|0.211221640| |blend_55|0.03|0.06|0.025|6850|1.05|-0.528839689|0.203520277| |blend_56|0.03|0.06|0.05|6850|1.05|-0.320682330|0.171985760| |blend_57|0.03|0.06|0.075|6850|1.05|-0.211275538|0.164811125| |blend_58|0.03|0.09|0|6850|1.05|-0.424880198|0.096770501| |blend_59|0.03|0.09|0.025|6850|1.05|-0.239660063|0.084163334| |blend_60|0.03|0.09|0.05|6850|1.05|-0.072915784|0.070817265| |blend_61|0.03|0.09|0.075|6850|1.05|0.027324696|0.065487697| |blend_62|0.03|0.12|0|6850|1.05|-0.289606241|0.085054229| |blend_63|0.03|0.12|0.025|6850|1.05|-0.146093058|0.068350579| |blend_64|0.03|0.12|0.05|6850|1.05|-0.014472391|0.062661220| |blend_65|0.03|0.12|0.075|6850|1.05|0.060156617|0.058151961| |blend_66|0.06|0|0|6850|1.05|-1.354021979|0.127726494| |blend_67|0.06|0|0.025|6850|1.05|-1.131071699|0.114750871| |blend_68|0.06|0|0.05|6850|1.05|-1.745878671|0.831551638| |blend_69|0.06|0|0.075|6850|1.05|-1.579965953|0.803539987| |blend_70|0.06|0.03|0|6850|1.05|-1.275885353|0.383908060| |blend_71|0.06|0.03|0.025|6850|1.05|-1.075722557|0.384532126| |blend_72|0.06|0.03|0.05|6850|1.05|-0.526629558|0.088482818| |blend_73|0.06|0.03|0.075|6850|1.05|-0.444030438|0.082615380| |blend_74|0.06|0.06|0|6850|1.05|-0.613359447|0.086175864| |blend_75|0.06|0.06|0.025|6850|1.05|-0.407814012|0.072023281| |blend_76|0.06|0.06|0.05|6850|1.05|-0.251006405|0.063987213| |blend_77|0.06|0.06|0.075|6850|1.05|-0.171445001|0.057584787| |blend_78|0.06|0.09|0|6850|1.05|-0.439302177|0.079831579| |blend_79|0.06|0.09|0.025|6850|1.05|-0.253317621|0.062648172| |blend_80|0.06|0.09|0.05|6850|1.05|-0.122229674|0.051575691| |blend_81|0.06|0.09|0.075|6850|1.05|-0.036327933|0.042967157| |blend_82|0.06|0.12|0.025|6850|1.05|-0.233260381|0.050127041| |blend_83|0.06|0.12|0.05|6850|1.05|-0.100254691|0.033191321| |blend_84|0.06|0.12|0.075|6850|1.05|-0.028068959|0.025263186| |blend_85|0.09|0|0|6850|1.05|-1.867671083|0.122746652| |blend_86|0.09|0|0.025|6850|1.05|-1.570008635|0.116139510| |blend_87|0.09|0|0.05|6850|1.05|-1.459399688|0.102144340| |blend_88|0.09|0|0.075|6850|1.05|-1.323820674|0.098552271| |blend_89|0.09|0.03|0|6850|1.05|-1.367589415|0.108817582| |blend_90|0.09|0.03|0.025|6850|1.05|-1.167217751|0.092035987| |blend_91|0.09|0.03|0.05|6850|1.05|-0.993631429|0.079743369| |blend_92|0.09|0.03|0.075|6850|1.05|-0.919663254|0.083239097| |blend_93|0.09|0.06|0|6850|1.05|-1.048976233|0.088673142| |blend_94|0.09|0.06|0.025|6850|1.05|-0.845995201|0.076076221| |blend_95|0.09|0.06|0.05|6850|1.05|-0.672568486|0.063147469| |blend_96|0.09|0.06|0.075|6850|1.05|-0.587303982|0.058321388| |blend_97|0.09|0.09|0|6850|1.05|-0.842588962|0.086550503| |blend_98|0.09|0.09|0.025|6850|1.05|-0.674435641|0.070116704| |blend_99|0.09|0.09|0.05|6850|1.05|-0.519448840|0.054758138| |blend_100|0.09|0.09|0.075|6850|1.05|-0.475282536|0.047084633| |blend_101|0.09|0.12|0|6850|1.05|-0.768246934|0.078464161| |blend_102|0.09|0.12|0.025|6850|1.05|-0.597166499|0.063660427| |blend_103|0.09|0.12|0.05|6850|1.05|-0.447088808|0.049151964| |blend_104|0.09|0.12|0.075|6850|1.05|-0.428445597|0.044839962| |blend_105|0.12|0|0|6850|1.05|-2.530351785|0.133449945| |blend_106|0.12|0|0.025|6850|1.05|-2.250715624|0.126565141| |blend_107|0.12|0|0.05|6850|1.05|-2.091107871|0.119339031| |blend_108|0.12|0|0.075|6850|1.05|-1.965987430|0.122353315| |blend_109|0.12|0.03|0|6850|1.05|-2.071833814|0.121984909| |blend_110|0.12|0.03|0.025|6850|1.05|-1.898998447|0.104155860| |blend_111|0.12|0.03|0.05|6850|1.05|-1.715815888|0.098866106| |blend_112|0.12|0.03|0.075|6850|1.05|-1.604474526|0.094782358| |blend_113|0.12|0.06|0|6850|1.05|-1.740227846|0.101770001| |blend_114|0.12|0.06|0.025|6850|1.05|-1.531840634|0.092473460| |blend_115|0.12|0.06|0.05|6850|1.05|-1.453424431|0.082247773| |blend_116|0.12|0.06|0.075|6850|1.05|-1.356373919|0.077854421| |blend_117|0.12|0.09|0|6850|1.05|-1.585694641|0.102682402| |blend_118|0.12|0.09|0.025|6850|1.05|-1.424863200|0.090171168| |blend_119|0.12|0.09|0.05|6850|1.05|-1.297892633|0.076754218| |blend_120|0.12|0.09|0.075|6850|1.05|-1.239741585|0.070171762| |blend_121|0.12|0.12|0|6850|1.05|-1.498022889|0.098073663| |blend_122|0.12|0.12|0.025|6850|1.05|-1.331675056|0.087571431| |blend_123|0.12|0.12|0.05|6850|1.05|-1.244381804|0.076894196| |blend_124|0.12|0.12|0.075|6850|1.05|-1.217294977|0.072426311| |stale_125|0.03|0.12|0.1|5500|0.85|-8.631802928|0.277400935| |stale_126|0.03|0.12|0.1|5500|0.95|-7.810662080|0.272729761| |stale_127|0.03|0.12|0.1|5500|1.05|-7.276203024|0.265581148| |stale_128|0.03|0.12|0.1|5500|1.15|-7.001309258|0.265618272| |stale_129|0.03|0.12|0.1|5500|1.25|-6.859920072|0.259266817| |stale_130|0.03|0.12|0.1|6250|0.85|-2.848367486|0.149528326| |stale_131|0.03|0.12|0.1|6250|0.95|-2.189765657|0.138175802| |stale_132|0.03|0.12|0.1|6250|1.05|-1.831805736|0.128674929| |stale_133|0.03|0.12|0.1|6250|1.15|-1.725381601|0.132855573| |stale_134|0.03|0.12|0.1|6250|1.25|-1.772537998|0.129396825| |stale_135|0.03|0.12|0.1|6850|0.85|-0.481976131|0.079346922| |stale_136|0.03|0.12|0.1|6850|0.95|-0.055936578|0.058714017| |stale_137|0.03|0.12|0.1|6850|1.15|0.038605433|0.054574409| |stale_138|0.03|0.12|0.1|6850|1.25|-0.106787714|0.063245331| |stale_139|0.03|0.12|0.1|7500|0.85|-3.773905269|0.988410485| |stale_140|0.03|0.12|0.1|7500|0.95|-3.718836123|0.989206712| |stale_141|0.03|0.12|0.1|7500|1.05|-4.265083137|1.569653287| |stale_142|0.03|0.12|0.1|7500|1.15|-4.516434426|1.560404516| |stale_143|0.03|0.12|0.1|7500|1.25|-4.759463735|1.556792610| |stale_144|0.03|0.12|0.1|8250|0.85|-32.474858375|3.505225354| |stale_145|0.03|0.12|0.1|8250|0.95|-32.769190143|3.558996352| |stale_146|0.03|0.12|0.1|8250|1.05|-33.116967580|3.637173275| |stale_147|0.03|0.12|0.1|8250|1.15|-33.039614972|3.553968162| |stale_148|0.03|0.12|0.1|8250|1.25|-32.608098488|3.408530294| **code: full Strategy.sol.** SHA-256: `91fe9cb4553c4781f1c6e1ac3d5a036e5c0ebe09bd4ed67a2f4c059647e54fcc`. Hash covers the exact UTF-8 Solidity block below, including its final LF after `}`, excluding fence lines. ```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 = 30000000000000000; 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; 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; 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) { 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 (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, WAD - 100000000000000000) + wmul(normalSpot, 100000000000000000); } 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"; } } ```