{
 "credit": "Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved: replica, Gaussian filter, fee rule, qm tables, arb/retail tell and the LEANBASE policy this item perturbs are his. Fast replica fastlean (artifact a88ff982eba7e078bc6ccb1555b90a211c00c9fd76ec90a62ab13a4074f2c3d0) ports them.",
 "mech": "post-arb-skew: after a callback read as arbitrage (fair price at the edge of our band), add a one-sided skew on top of LEANBASE's table fees: the edge side (the side the arb hit: bid when the pool bought X, ask when it sold X) moves by k_edge, the other side by k_other. Tested at the arb callback only (mode at_arb_only) and persisting with exp(-age/L) decay on later callbacks until the next arb (mode persist_decay).",
 "already_present": {
  "value": false,
  "where": "Not as written: no additive skew exists in leanbase.py, stalerival.py, real.py or tellpol.py, and no state keeps the last arb's side past the callback that read it. Related, already there: on a callback read as arb, real.RealPolicy.on_trade sets m = lp_arb (ln of post-trade spot through the fee in force; fastlean on_trade sf[0] = lp) and looks up phase 0 (tables A0c/B0c, tag '0c') at w = (ln s - m)*1e4, which is the fee-in-force edge with the side's sign, so the bid and ask set right after an arb are already a separately-chosen, side-dependent pair. The at_arb_only mode therefore perturbs a table optimum; the persist_decay mode (S10-S12) is the nearest variant no code has: it carries the arb side to later callbacks, where the phase 1/2 tables do not know it."
 },
 "definition": {
  "formula": "on each afterSwap callback, after LEANBASE's lookup (and rival pull) and before stalerival.fee() rounding/clamp: if is_arb: side = +1 if is_buy (pool bought X) else -1; t_arb = t. dec = (1 if is_arb else 0) in mode at_arb_only, exp(-(t - t_arb)/L) in mode persist_decay; nothing before the first arb. If side > 0: fb += k_edge*dec, fa += k_other*dec; else fa += k_edge*dec, fb += k_other*dec. Then fee() as in LEANBASE (wad clamp [0, 1e17], stepped off Vanilla's gamma).",
  "parameters": "k_edge, k_other (fee units, 1e-4 = 1 bp), L (steps), mode in {at_arb_only, persist_decay}",
  "state_kept": "mode at_arb_only: none (side and is_arb are known in the callback). mode persist_decay: side of the last arb read (1 bit) and its timestamp; fastlean sf[9], sf[10].",
  "inputs": "only is_buy, timestamp and LEANBASE's own arb read (from amounts, its reserves and its own state): what afterSwap is handed"
 },
 "settings_tried": [
  {
   "id": "S1",
   "parameters": {
    "k_edge_bps": 2.0,
    "k_other_bps": -2.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -0.2704,
   "se": 0.0389,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.2391,
    "se": 0.0132
   }
  },
  {
   "id": "S2",
   "parameters": {
    "k_edge_bps": -2.0,
    "k_other_bps": 2.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -0.636,
   "se": 0.0333,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.6265,
    "se": 0.0125
   }
  },
  {
   "id": "S3",
   "parameters": {
    "k_edge_bps": 6.0,
    "k_other_bps": -6.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -1.8921,
   "se": 0.0876,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -1.7924,
    "se": 0.0307
   }
  },
  {
   "id": "S4",
   "parameters": {
    "k_edge_bps": -6.0,
    "k_other_bps": 6.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -3.3768,
   "se": 0.0795,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -3.4065,
    "se": 0.0266
   }
  },
  {
   "id": "S5",
   "parameters": {
    "k_edge_bps": 4.0,
    "k_other_bps": 0.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -0.7548,
   "se": 0.062,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.7228,
    "se": 0.0224
   }
  },
  {
   "id": "S6",
   "parameters": {
    "k_edge_bps": -4.0,
    "k_other_bps": 0.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -0.77,
   "se": 0.0594,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.7374,
    "se": 0.02
   }
  },
  {
   "id": "S7",
   "parameters": {
    "k_edge_bps": 0.0,
    "k_other_bps": 4.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -1.1808,
   "se": 0.0211,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -1.2102,
    "se": 0.009
   }
  },
  {
   "id": "S8",
   "parameters": {
    "k_edge_bps": 0.0,
    "k_other_bps": -4.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -0.1791,
   "se": 0.014,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.1892,
    "se": 0.0057
   }
  },
  {
   "id": "S9",
   "parameters": {
    "k_edge_bps": 0.0,
    "k_other_bps": -1.0,
    "mode": "at_arb_only",
    "L_steps": null
   },
   "n": 128,
   "mean_diff": -0.034,
   "se": 0.0101,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.0266,
    "se": 0.0032
   }
  },
  {
   "id": "S10",
   "parameters": {
    "k_edge_bps": 1.0,
    "k_other_bps": -1.0,
    "mode": "persist_decay",
    "L_steps": 2
   },
   "n": 128,
   "mean_diff": -0.1237,
   "se": 0.0283,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.1087,
    "se": 0.0112
   }
  },
  {
   "id": "S11",
   "parameters": {
    "k_edge_bps": -1.0,
    "k_other_bps": 1.0,
    "mode": "persist_decay",
    "L_steps": 2
   },
   "n": 128,
   "mean_diff": -0.5597,
   "se": 0.0286,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.5275,
    "se": 0.0105
   }
  },
  {
   "id": "S12",
   "parameters": {
    "k_edge_bps": 0.0,
    "k_other_bps": -1.0,
    "mode": "persist_decay",
    "L_steps": 4
   },
   "n": 128,
   "mean_diff": -0.0667,
   "se": 0.0177,
   "dropped_early": true,
   "dropped_at_n": 128,
   "info_all_1024_choose_seeds": {
    "n": 1024,
    "mean_diff": -0.0592,
    "se": 0.0077
   }
  }
 ],
 "method": "Paired with LEAN (fastlean, a0=0.35 ainf=0.35, weights None) on the same seeds 64000..65023 in rounds of 128; drop when mean_diff + 3*se < 0, se = sd(n-1)/sqrt(n). S1-S8 were set first; S9-S12 were chosen after S1-S8 had all dropped (smaller sizes and the persistent variant). The replica computed all 1024 choose seeds for each setting in one batch; the drop decision uses the first 128 only, and the 1024-seed figures are shown for information.",
 "chosen": {
  "id": "S9",
  "parameters": {
   "k_edge_bps": 0.0,
   "k_other_bps": -1.0,
   "mode": "at_arb_only",
   "L_steps": null
  },
  "why": "all 12 settings were dropped at the first round of 128; S9 had the least negative mean_diff, so it is the one run on the report seeds as the brief's method asks. It is not a gain."
 },
 "report": {
  "vs_lean": {
   "n": 2048,
   "mean_diff": -0.022,
   "se": 0.0023,
   "seeds_positive": 805,
   "seeds": "10000..12047",
   "baseline": "LEAN a0=0.35 ainf=0.35"
  },
  "on_age": {
   "n": 2048,
   "mean_diff": -0.0228,
   "se": 0.0024,
   "seeds_positive": 837,
   "seeds": "10000..12047",
   "baseline": "AGE a0=0 ainf=0.7 tau=1, skew stacked on it"
  },
  "info_age_minus_lean_same_seeds": {
   "n": 2048,
   "mean_diff": 0.0198,
   "se": 0.0041,
   "seeds_positive": 1141
  }
 },
 "promote": false,
 "conclusion": "No. Every post-arb skew tried costs edge on the fast LEAN replica: 2-6 bps symmetric skews -0.24..-3.41, one-sided 4 bps -0.19..-1.21, 1 bp -0.03..-0.06, persistent 1 bp -0.06..-0.53 (1024-seed figures). The cost grows with size in both directions, which says the phase-0 table already sits near the best post-arb pair for this replica. Do not pipeline.",
 "contract_cost": {
  "basis": "estimates from the change's shape, not measured: no Solidity was written or compiled for this item",
  "at_arb_only (S9, chosen)": {
   "storage_words": 0,
   "gas": "about +30..60 on arb callbacks (one branch on the arb read and one add/sub on the other-side fee), ~+10 elsewhere",
   "runtime_bytes": "about +20..50",
   "source_characters": "about +60..120",
   "fits": "yes: about 208,060 of 245,000 peak gas, about 22,490 of 24,576 bytes, about 47,350 of 50,000 characters"
  },
  "persist_decay (S10-S12)": {
   "storage_words": "1 new (side bit + 64-bit t_arb) or 0 if packed into a slot the contract already writes each call",
   "gas": "own slot: SLOAD 2,100 cold per callback + SSTORE about 2,900 on arb callbacks (20,000 first nonzero write); packed into an already-written slot: about +100..200; plus a fixed-point exp(-age/L) about +300..800 (a small lookup over integer ages is cheaper)",
   "runtime_bytes": "about +250..450",
   "source_characters": "about +400..700",
   "fits": "peak about 211,000..214,000 of 245,000 with its own slot; bytes and characters fit"
  }
 },
 "patch_zb64": "eNrFVm1v4zYM/rz8CqL9MLuRU8t2Xpoih/aGFjigOwy4Aj0gCALZlhsvjuVZSnP59yNl5/V62LANmAIkqkSRfMiHZD3PA3GdCW0KKcr9pldtfwr8YOBx7nEf+HAcRuMo6IWBPwoHo34Inj/w/U6324X4nz+/uwO8H7EBdOknGMLdXQdo1dKs6xJSwyBVHcBP9678PTdOIpKFnDzXa+l2uqnMQC/lxtkw0HkqGYhX/Mr1XNSxO+50SdXFxUWltPHwyCNhcFQJRlWgMngW20LV4LyaVbIs89eFcX/W8PRw//nj/ZcHMCIuSOlq5el8dReNeCAG4SgIOR8EkeR9fyASwUOeiLCfhMNRdhP66Y3bayxvYALT5Vym5NRyrsxC1gyeGKxUKmeQl5BJCesyN7pn/U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2wJxynT+xdieU1oyl34mODcdzxjuVTZFRKjFogoxyCwWDjnk4oGms9vRCVtBAnEJ2NsBNF+/+4KBVsH+eGYJxY2f4DdqrjbLz9hX8nMllMWNP4lmqDdqK5p5rP4pqCJOXcNkIni9vHgi7F2aVwO38Ckibtnw==",
 "patch_info": {
  "against": "fastlean/fastlean.py from code_zb64 of artifact a88ff982eba7e078bc6ccb1555b90a211c00c9fd76ec90a62ab13a4074f2c3d0 (sha256 of that file d9c758bb280fe24e09c039496f84ab0804173ff70cec24c332f8683f28efa582)",
  "apply": "from the unpacked tree: patch -p1 < diff (paths a/fastlean/fastlean.py, b/fastlean/fastlean.py)",
  "use": "call fastlean.sim_batch with w = float64[4] [k_edge, k_other, L, mode] and hon=True; run_batch's validate_weights does not accept length 4. Zero skew ([0,0,L,mode]) gives LEAN bit for bit (checked on 64000..64063, both modes).",
  "parity_checked": "unpatched baseline on 64000..64063 and 10000..10063 mean 527.8724874783702, equal to the artifact's mean_edge_fast"
 },
 "environment": "CPython 3.10.12, numpy 2.2.6, llvmlite 0.44.0, numba 0.61.2 (cp310 manylinux wheels), Linux x86_64 (WSL2). The artifact was built on CPython 3.12.3; parity of the baseline mean held here.",
 "not_done": [
  "No engine run, no Solidity port, no gas/size measurement: contract_cost is an estimate.",
  "Only one item's mechanism on the replica; no re-tune of the tables around the skew (spent line: table refit).",
  "The 128-seed drop decisions are final; the extra 896 choose seeds per setting were computed in the same batch and are reported for information only.",
  "Settings S9-S12 were picked after S1-S8's results (adaptive within the 12-setting budget).",
  "Edge-side and other-side directions were both tried because the brief's 'the side the price came from against the other' does not fix a sign."
 ]
}