{
 "credit": "Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved: the LEAN policy, replica, Gaussian filter, qm tables and exact-arithmetic arb/retail tell; fast replica fastlean from artifact a88ff982eba7e078bc6ccb1555b90a211c00c9fd76ec90a62ab13a4074f2c3d0",
 "mech": "inventory: skew of the bid and ask fees by the pool's own inventory relative to the start",
 "already_present": {
  "value": true,
  "where": "As literally specified (X value against Y value at the filter's mean price, relative to the start) it is already in the policy: x*exp(m)/y = exp(m)/s since s=y/x, and the start ratio is 100*100/10000 = 1, so ln of that ratio is -(ln s - m), the first coordinate of LEANBASE's qm table lookup (fastlean.py on_trade: lookup(..., (ls - sf[0]) * 1e4, ...); feature 3). No separate inventory term exists in real.py/tellpol.py/stalerival as ported (grep for inventory/skew found none). Tested instead the nearest variant not present: quantity inventory q = ln(x/x0), x0 = 100 (the X reserve afterInitialize is handed), which also moves with k growth and is not a function of the spot-vs-mean gap alone."
 },
 "definition": {
  "formula": "q = ln(x / 100); u = tanh(q / q0); fee_bid += c*u; fee_ask -= c*u (fee units, 1e-4 = 1 bp), applied at the hook call site after LEANBASE's two fees, before fee rounding/clamp. c>0 makes the pool dearer to sell X into when already long X; c<0 is the opposite.",
  "parameters": {
   "c": "fee units, tried +-0.5, +-1, +-2 bp",
   "q0": "0.1 or 0.3"
  },
  "state_kept": "none beyond constants; x is the reserve afterSwap is handed"
 },
 "settings_tried": [
  {
   "parameters": {
    "c_fee": 5e-05,
    "c_bps": 0.5,
    "q0": 0.1
   },
   "n": 256,
   "mean_diff": -0.03956,
   "se": 0.00886,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": 0.0001,
    "c_bps": 1.0,
    "q0": 0.1
   },
   "n": 128,
   "mean_diff": -0.07722,
   "se": 0.0175,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": 0.0002,
    "c_bps": 2.0,
    "q0": 0.1
   },
   "n": 128,
   "mean_diff": -0.20223,
   "se": 0.02628,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": -5e-05,
    "c_bps": -0.5,
    "q0": 0.1
   },
   "n": 128,
   "mean_diff": -0.04899,
   "se": 0.01119,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": -0.0001,
    "c_bps": -1.0,
    "q0": 0.1
   },
   "n": 128,
   "mean_diff": -0.08586,
   "se": 0.01338,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": -0.0002,
    "c_bps": -2.0,
    "q0": 0.1
   },
   "n": 128,
   "mean_diff": -0.18257,
   "se": 0.02423,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": 5e-05,
    "c_bps": 0.5,
    "q0": 0.3
   },
   "n": 512,
   "mean_diff": -0.01552,
   "se": 0.00512,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": 0.0001,
    "c_bps": 1.0,
    "q0": 0.3
   },
   "n": 256,
   "mean_diff": -0.02881,
   "se": 0.00801,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": 0.0002,
    "c_bps": 2.0,
    "q0": 0.3
   },
   "n": 256,
   "mean_diff": -0.05994,
   "se": 0.01134,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": -5e-05,
    "c_bps": -0.5,
    "q0": 0.3
   },
   "n": 1024,
   "mean_diff": -0.00632,
   "se": 0.00339,
   "dropped_early": false
  },
  {
   "parameters": {
    "c_fee": -0.0001,
    "c_bps": -1.0,
    "q0": 0.3
   },
   "n": 384,
   "mean_diff": -0.02354,
   "se": 0.00716,
   "dropped_early": true
  },
  {
   "parameters": {
    "c_fee": -0.0002,
    "c_bps": -2.0,
    "q0": 0.3
   },
   "n": 128,
   "mean_diff": -0.06602,
   "se": 0.01232,
   "dropped_early": true
  }
 ],
 "chosen": {
  "parameters": {
   "c_fee": -5e-05,
   "c_bps": -0.5,
   "q0": 0.3
  },
  "why": "the only setting not dropped early on 64000..65023 (all 12 had negative mean_diff)"
 },
 "report": {
  "vs_lean": {
   "n": 2048,
   "mean_diff": -0.00881,
   "se": 0.00275,
   "seeds_positive": 946
  },
  "on_age": {
   "n": 2048,
   "mean_diff": -0.00859,
   "se": 0.0024,
   "seeds_positive": 919
  },
  "seeds": "replica seeds 10000..12047, paired same seeds",
  "lean": "a0=0.35 ainf=0.35",
  "age": "a0=0 ainf=0.7 tau=1",
  "lean_base_mean_edge": 536.6034,
  "age_base_mean_edge": 536.6231
 },
 "promote": false,
 "contract_cost": {
  "storage_words": 0,
  "gas": "estimate, not measured: one ln (existing log routine) of x/x0 plus a tanh (or a clipped linear stand-in) and two adds; roughly 1,500-3,000 gas on top of ~208,000 peak, within 245,000",
  "runtime_bytes": "estimate, not measured: ~300-600 bytes on top of 22,440 (limit 24,576)",
  "source_characters": "estimate: ~250-400 characters on top of 47,230 (limit 50,000)",
  "note": "moot: not promoted"
 },
 "patch_zb64": "eNptUsFuozAQvfMVT9oLFJzApu1WiVpx3XsPK6FoNQQbrICd2l5o+vW1yW5FovXBfjNv5o3tGcYYBFnXc1Lrf2B1Okdpmv6fKEuwh82P7AlpOIocZRnhdkkBgRdYR66SGTb77QLjGeI6ZeZUhnyP9BnFKo+WSp1W24gt45s6Q0Nep9P6GAtOLsOUXMeIOmg19c6/Y0YUpUv+G6QauXLanGGPfELcMNlwsusv/w41WY6T7uXhjFc699ogbt1wOCrZdi4BDQOzcijvn4rv9LiB4ZaTOXRrq/uRN8n2tuabv3Sv4nes8Z4nmd+8o8hzxCHVjBwkHDc/lXSSevnB0cqR22SHXqsWv8Be4C9puEEtmwyHjtPJG2SP16XeRi88kOtWjlQXz6jX7VzZ11vliQdTVeyT67zLt02Vb8WdF5l/jy0cl87UU+YjTegk57+N/qOaWNTJhaRA0g1Jf0krq4cwAfW0C/gxYApYVJfJqM1s3M8GmegTZnS2hQ==",
 "not_done": [
  "Mechanism is negative on the replica at every tried setting; no engine, Solidity, gas or size measurement was run",
  "Hook was replaced by an edit at the hook call site (needs x, which the default hook features do not carry); the diff's hook-weight array carries c in w[0] and q0 in w[1] and must be length 42",
  "Value-weighted variants (e.g. ln(pool value at mean price / start value) vs hold) were not tested",
  "Ran with numpy 2.2.6, llvmlite 0.44.0, numba 0.61.2 wheels on CPython 3.12; zero-skew run reproduced LEAN edges exactly on 16 seeds"
 ]
}