{
 "credit": "Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved: LEAN policy, phase tables, replica, filter, tell. Fast replica fastlean from artifact a88ff982eba7e078bc6ccb1555b90a211c00c9fd76ec90a62ab13a4074f2c3d0.",
 "mech": "same-step",
 "already_present": {
  "value": true,
  "where": "Yes, in its basic form. LEAN already sets different fees after the first and after later non-arb fills of a timestamp: real.py (Taylor) lines 167-168 'self.cnt += 1; phs = 1 if self.cnt <= 1 else 2' and stalerival.py line 63 'phs=1 if self.cnt<=1 else 2' choose phase-1 tables (A1s/A1c) or phase-2 tables (A2s/A2c) in qm_k1e-5.json; fastlean.py on_trade does the same (si[1] counter, phs). The rival estimate s2h is also updated within the step. So I tested the nearest variant that is not in it: a fill-count-dependent shift beyond phase 2 (cnt = 2, 3, 4, ... in the same timestamp), in both flat-from-the-3rd-fill and linear-in-count forms."
 },
 "definition": {
  "formula": "After LEANBASE's lookup, before fee rounding, on a non-arb callback with cnt >= cnt0 (cnt = this step's non-arb fills of ours, including this one): k = 1 if C == 0 else min(cnt-1, C); own side (bid if the pool bought X, else ask) += k*d_own; other side += k*d_oth.",
  "parameters": "cnt0 in {2,3}; d_own, d_oth in bps; C (0 = flat, else count-scaled with cap C)",
  "state_kept": "none new: uses LEAN's existing cnt and tlast (timestamp of the last callback). Inputs: side, timestamp, own state only."
 },
 "settings_tried": [
  {
   "parameters": {
    "cnt0": 2,
    "d_own_bps": 1.0,
    "d_oth_bps": 0.0,
    "C": 4
   },
   "dropped_early": true,
   "n": 128,
   "mean_diff": -0.1134431719198501,
   "se": 0.01942670104801911
  },
  {
   "parameters": {
    "cnt0": 2,
    "d_own_bps": -1.0,
    "d_oth_bps": 0.0,
    "C": 4
   },
   "dropped_early": true,
   "n": 256,
   "mean_diff": -0.04443466479840996,
   "se": 0.011535282420590237
  },
  {
   "parameters": {
    "cnt0": 2,
    "d_own_bps": 0.0,
    "d_oth_bps": 1.0,
    "C": 4
   },
   "dropped_early": true,
   "n": 256,
   "mean_diff": -0.050064176187341713,
   "se": 0.014528127394312834
  },
  {
   "parameters": {
    "cnt0": 2,
    "d_own_bps": 0.0,
    "d_oth_bps": -1.0,
    "C": 4
   },
   "dropped_early": true,
   "n": 256,
   "mean_diff": -0.049305538044916775,
   "se": 0.013697449004068472
  },
  {
   "parameters": {
    "cnt0": 2,
    "d_own_bps": 1.0,
    "d_oth_bps": 1.0,
    "C": 4
   },
   "dropped_early": true,
   "n": 128,
   "mean_diff": -0.1786824095005901,
   "se": 0.027137979389516564
  },
  {
   "parameters": {
    "cnt0": 2,
    "d_own_bps": -1.0,
    "d_oth_bps": -1.0,
    "C": 4
   },
   "dropped_early": true,
   "n": 128,
   "mean_diff": -0.11390943453798963,
   "se": 0.019772723851185035
  },
  {
   "parameters": {
    "cnt0": 3,
    "d_own_bps": 2.0,
    "d_oth_bps": 0.0,
    "C": 0
   },
   "dropped_early": true,
   "n": 256,
   "mean_diff": -0.04315888109500432,
   "se": 0.008833350053973626
  },
  {
   "parameters": {
    "cnt0": 3,
    "d_own_bps": -2.0,
    "d_oth_bps": 0.0,
    "C": 0
   },
   "dropped_early": true,
   "n": 384,
   "mean_diff": -0.022301470180637217,
   "se": 0.006660403566887787
  },
  {
   "parameters": {
    "cnt0": 3,
    "d_own_bps": 0.0,
    "d_oth_bps": 2.0,
    "C": 0
   },
   "dropped_early": true,
   "n": 256,
   "mean_diff": -0.02965825565288105,
   "se": 0.009653929444958145
  },
  {
   "parameters": {
    "cnt0": 3,
    "d_own_bps": 0.0,
    "d_oth_bps": -2.0,
    "C": 0
   },
   "dropped_early": true,
   "n": 384,
   "mean_diff": -0.023286854122620475,
   "se": 0.007686593063311715
  },
  {
   "parameters": {
    "cnt0": 3,
    "d_own_bps": 2.0,
    "d_oth_bps": 2.0,
    "C": 0
   },
   "dropped_early": true,
   "n": 128,
   "mean_diff": -0.07550210780785749,
   "se": 0.017771508083652
  },
  {
   "parameters": {
    "cnt0": 3,
    "d_own_bps": -2.0,
    "d_oth_bps": -2.0,
    "C": 0
   },
   "dropped_early": true,
   "n": 256,
   "mean_diff": -0.056136385832780133,
   "se": 0.011128549096629635
  }
 ],
 "selection_note": "seeds 64000..65023 in 128-seed rounds paired with LEAN (a0=0.35 ainf=0.35); drop when mean_diff+3*se<0. Every setting was dropped by the end of round 3 (n<=384), so the 1,024 seeds were not all used. 'chosen' is the least negative setting when it was dropped (the last two survivors were dropped together in round 3, chosen = the smaller loss).",
 "chosen": {
  "cnt0": 3,
  "d_own_bps": -2.0,
  "d_oth_bps": 0.0,
  "C": 0,
  "engine_params": [
   3,
   -0.0002,
   0,
   0
  ]
 },
 "report": {
  "vs_lean": {
   "n": 2048,
   "mean_diff": -0.014588337746420238,
   "se": 0.0028563254563184217,
   "seeds_positive": 913
  },
  "on_age": {
   "n": 2048,
   "mean_diff": -0.010747124174305539,
   "se": 0.0027241726578222424,
   "seeds_positive": 899
  },
  "seeds": "10000..12047",
  "lean_mean_edge": 536.603390956178,
  "age_mean_edge": 536.6231002985178,
  "age": "a0=0 ainf=0.7 tau=1"
 },
 "promote": false,
 "conclusion": "Negative. Every in-step count shift, in either sign and on either side, loses compared with LEAN's two phase tables (best -0.0146 se 0.0029 vs LEAN, -0.0107 se 0.0027 on AGE, over 2,048 seeds). The phase-1/phase-2 split already captures the same-step effect, and adding dependence on the fill count does not help.",
 "contract_cost": {
  "storage_words": "0 new if the step-fill counter shares a packed slot with the timestamp (LEAN keeps cnt); 1 SSTORE-warm slot otherwise",
  "gas": "estimate, not measured: about 150-300 gas per afterSwap (one compare, one conditional add on one fee) and +0 if it is packed with the existing state; peak about 208,300 of 245,000",
  "runtime_bytes": "estimate about +40..80 bytes (22,520 of 24,576)",
  "source_chars": "estimate about +150..250 characters (about 47,450 of 50,000)",
  "note": "estimates from the size of the logic, not compiled; moot since not promoted"
 },
 "patch_zb64": "eNq1VUuP4zYMPje/gpg9xB4/Itl5D7KYdoFpF2gXKBpgD0EQ0La81savkZSm+fellGQy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Us9b069WNEG6pzp2B9E1ubpjc2ZOOvN8Csbbv0rkWj+2y7r9SsVsptIdXuZUOV8F7CLcHtpzB/rBALwarovPa192/+a/oU02BvJcsd1NGy216JduuTnECg3f4W3uGxAye/D14ly7ihVIXymXLoW+hcCrDNM",
 "patch_note": "unified diff against fastlean.py from a88ff982...; disabled (bit-identical to LEANBASE) unless load(..., ss=[cnt0,d_own,d_oth,C]) is passed; verified: ss with cnt0=99 reproduces LEAN edges exactly on 64000..64015",
 "environment": "CPython 3.12.3, numpy 2.2.6, llvmlite 0.44.0, numba 0.61.2, Linux x86_64; research files via Taylor's fetch.sh at 66604b3426d8e97a73e2c39940b9b4dece51cc73 (34 files, 0 sha mismatches)",
 "not_done": [
  "No engine run, no Solidity, so the gas/bytes/characters are estimates only",
  "Only 12 settings tried: magnitudes 1-2 bp; no signed-flow or size-conditioned in-step variant",
  "Selection stopped early because every setting was dropped; the 64000..65023 range was not fully used",
  "Nothing submitted"
 ]
}