# d-ideas, merge 01: ten single-mechanism fee ideas on the fast LEAN replica Credit: Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved. Every item here builds on his solved policy: the replica, Gaussian filter, fee rule, qm tables and exact-arithmetic arb/retail tell. The fast replica (fastlean) is artifact https://api.imd.fun/artifacts/a88ff982eba7e078bc6ccb1555b90a211c00c9fd76ec90a62ab13a4074f2c3d0 and the LEANBASE reference bundle is https://api.imd.fun/artifacts/efb8e653f8fd061cecf3e92b186470c9c96c5188523364b60ed101e9672869aa, as the items cite them. ## Bottom line - All 10 items returned a result, and **none is promoted**. Every item reports `promote: false`. - No item's chosen setting gets anywhere near the +0.03 promotion bar against LEAN or on top of AGE. The highest `report.on_age.mean_diff` is fill-size's `0.000241` (se `0.003519`). Its own choice-block mean was `-0.00231` (se `0.004762`), and the item calls it "No gain". - On the replica, three chosen settings sit within one reported se of zero on AGE: fill-size, fee-memory and silence-bound. Age-fee is within about 0.6 se. The other six are negative by more than 2 reported se on AGE: share-feedback, inventory, undercut, same-step, post-arb-skew and size-run. (The se multiples are a reading of the items' own mean_diff/se pairs. No new figure is computed.) - Every item is a **replica-only** result, paired against LEAN (a0=0.35 ainf=0.35 tau=2) and AGE (a0=0 ainf=0.7 tau=1) on the constant-K fastlean replica. No item ran the engine, compared against QLX5 or qt1, consumed fresh engine seeds, or compiled an integrated contract. Each item's `not_done` says so. None of these numbers is an engine or board figure. - Two items report the replica's AGE-minus-LEAN by-product on the report seeds 10000..12047. fill-size gives `mean_diff 0.019709, se 0.004066, seeds_positive 1140` (n 2048). post-arb-skew gives `0.0198, se 0.0041, seeds_positive 1141` (n 2048). The two agree. Every item that reports baseline means gives the same values: LEAN `536.603390956178`, AGE `536.6231002985178`. inventory rounds these to `536.6034` / `536.6231`, and fill-size to `536.603391` / `536.6231`. ## Rows, sorted by report.on_age.mean_diff (largest first) | # | item | already_present | report.vs_lean n / mean_diff / se / seeds_positive | report.on_age n / mean_diff / se / seeds_positive | promote | |---|---|---|---|---|---| | 1 | fill-size | false | 2048 / 0.00227 / 0.003436 / 1050 | 2048 / 0.000241 / 0.003519 / 1048 | false | | 2 | fee-memory | false | 2048 / -0.0006303010545473664 / 0.0009622144824857604 / 899 | 2048 / -0.00026428233344610863 / 0.0009421979703227205 / 921 | false | | 3 | silence-bound | true | 2048 / -0.0008279686961202848 / 0.0019242159702547905 / 1029 | 2048 / -0.0006687704036579534 / 0.0019155571807606612 / 1000 | false | | 4 | age-fee | false | 2048 / 0.0005244462906790204 / 0.0023991125163267874 / 1062 | 2048 / -0.001480369005663923 / 0.002419455415421662 / 1051 | false | | 5 | share-feedback | false | 2048 / -0.0015907482784406624 / 0.0028472614476621892 / 996 | 2048 / -0.006530390919671475 / 0.0028038291574551885 / 972 | false | | 6 | inventory | true | 2048 / -0.00881 / 0.00275 / 946 | 2048 / -0.00859 / 0.0024 / 919 | false | | 7 | undercut | false | 2048 / -0.004690568590842298 / 0.002193183321020636 / 941 | 2048 / -0.009578699512042016 / 0.0022076424341107 / 949 | false | | 8 | same-step | true | 2048 / -0.014588337746420238 / 0.0028563254563184217 / 913 | 2048 / -0.010747124174305539 / 0.0027241726578222424 / 899 | false | | 9 | post-arb-skew | false | 2048 / -0.022 / 0.0023 / 805 | 2048 / -0.0228 / 0.0024 / 837 | false | | 10 | size-run | false | 2048 / -0.04992351261329561 / 0.003577958126681876 / 732 | 2048 / -0.053940194276585585 / 0.0037164126133699647 / 729 | false | The vs_lean and on_age figures for every item come from replica report seeds 10000..12047, n 2048, with each seed evaluated once. Selection used seeds 64000..65023 in 128-seed rounds, and a setting was dropped once mean_diff + 3*se < 0. Each item states this in its own method text. ## Per item (same order) ### 1. fill-size - **mech** (as the item gives it): fill-size: the size of a fill read as retail, relative to a running mean of our retail fills, shifts the next fees on the same side and on the other side - **definition**: At a callback read as retail, takes z = min(q/M, C) - c0 (q = amountY, M a running mean of retail amountY with rate beta, initial 11.0) and adds k_same*1e-4*z to the traded side's fee and k_other*1e-4*z to the other side's fee until the next callback. - **already_present**: false. Where: Not present. Read: leanbase.py, stalerival.py (packed in the LEANBASE artifact efb8e653...), real.py, tellpol.py (Taylor's files). Fill size appears in three places, none of them this mechanism: (1) real.py RealPolicy.on_trade uses the spot move of a step's first own trade, d=|ln(s/sp)|, in a lognormal retail likelihood (LD_M, LD_S) to decide arb or retail; that is a classifier input on first trades only, against a fixed law, and the fee never reads it. (2) real.py has an option fill=1 (order-size law in the same likelihood); LEAN does not set it and the fast replica does not port it. (3) tellpol.py/leanbase.py use the paid amount for the exact grid test and for the chance a retail amount lands on the grid. The fee is a table lookup at (ln s - m, ln rival - m, phase, sd, synced): the fill moves s and the rival estimate, so its size is in the state only through the post-trade spots. No running mean of fills is kept anywhere and no fee term reads a fill size. Tested as stated, no nearest variant needed. - **chosen**: `{"k_same_bps":0,"k_other_bps":0.25,"beta":0.03125,"C":3,"M0":11,"c0":0.862,"form":"linear"}` - **report.vs_lean**: n 2048, mean_diff 0.00227, se 0.003436, seeds_positive 1050 - **report.on_age**: n 2048, mean_diff 0.000241, se 0.003519, seeds_positive 1048 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"measured":false,"storage_words":"0 new words if M is packed into slot 2 of QLX5 (fb | fa<<64 | t<<128 | cnt<<192 with cnt masked to 32 bits and the synced flag in bit 255: bits 224..254 are free, 31 bits, enough for M in 1e-6 Y up to 2,147 Y); 1 new word otherwise","gas":"estimate, not measured: packed, about 200-400 gas on a retail-read callback (unpack, one division, clip, running-mean update, two multiplications, two additions, repack) and about 30 on an arb-read one, so peak about 208,400-208,800 of 245,000. In a slot of its own, about 5,000 more per callback that touches it under EIP-2929 pricing (cold SLOAD 2,100 + SSTORE reset 2,900), if the engine charges cold access per callback: about 213,700. The log form needs the contract's ln (a 14-term series loop), several thousand gas; the chosen form is linear.","runtime_bytes":"estimate: 120-220 bytes, 22,440 -> about 22,600-22,660 of 24,576","characters":"estimate: 300-450 source characters, 47,230 -> about 47,550-47,680 of 50,000","basis":"QLX5 source (sha256 e183e5bc3fb794b7067703b10a7da9920267aa5f4caa968e16ca101b02338f40, 47,230 characters, decoded from code_zb64.QLX5 of artifact 1ef80bfb6d6791b877b1f4048a5e63cf2ae54153e6e8763ae3f8ab13132dfb15) read for its slot layout; that artifact gives peak_gas 208366, runtime_bytes 22440, source_chars 47230. No Solidity was written or compiled here."}` - **selection notes**: Only S11 survived (k_other 0.25 bps). Its choice-block mean was -0.00231, se 0.004762, on 1024 seeds. Settings S5-S12 were picked after seeing earlier results on the same choice seeds. The item reports a chaos floor: a fee change of about 1e-13 changes every seed's edge (sd about 0.09 per seed), so the paired se has a floor near 0.09/sqrt(n). - **source**: `.imd/reads/artifacts/item-fill-size` (artifacts/goal/batches/d-ideas/items/fill-size/result.json), sha256 303dc2d00d6acce3c721299a1ef23877944317ada968f7fcfdcc754d6f65f0ad ### 2. fee-memory - **mech** (as the item gives it): fee-memory: independent bid/ask EMA or dead-band hysteresis after the final LEAN table lookup and before fee_round; no additional observations. - **definition**: Per side, returns either an EMA v = (1-w)*u + w*p of the new fee u and previous returned fee p, or a dead band that keeps p when |u-p| < h*1e-4, before fee_round. - **already_present**: false. Where: Read leanbase.py Policy.on_grid, stalerival.py Policy.on_trade/round_fees, real.py RealPolicy.on_trade/lookup, tellpol.py TellPolicy.on_trade from the pinned LEANBASE reference bundle. They retain prior fees for filtering, router inference and the tell, but return newly looked-up fees without EMA or dead-band hysteresis. - **chosen**: `{"mode":2,"param":0.03,"family":"dead_band"}` - **report.vs_lean**: n 2048, mean_diff -0.0006303010545473664, se 0.0009622144824857604, seeds_positive 899 - **report.on_age**: n 2048, mean_diff -0.00026428233344610863, se 0.0009421979703227205, seeds_positive 921 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"storage_words":0,"storage_basis":"Incremental words: reuse existing previous returned bid/ask fee state already required by the tell. Two fee values must be retained if ported to a policy without that state.","gas":{"measured":null,"estimated_increment_range":[100,1500],"basis":"Engineering estimate only for two simple compare/select operations (dead band) or two fixed-point blends (EMA), with prior fee loads reused and no extra SSTORE. Compiler, signed-difference handling and surrounding code can change this."},"characters":{"measured":null,"estimated_increment_range":[250,900],"basis":"Estimated minimal Solidity addition for only the chosen mechanism, excluding this Python experiment and comments; not compiled."},"runtime_bytes":{"measured":null,"estimated_increment_range":[100,500]},"budget_from_brief":{"peak_gas":208000,"gas_limit":245000,"runtime_bytes":22440,"runtime_limit":24576,"source_characters":47230,"source_limit":50000},"assessment":"Likely fits the stated 37000 gas, 2136 runtime-byte and 2770 source-character headroom; unverified until a Solidity port is compiled and measured."}` - **selection notes**: The chosen setting is a dead band of 0.03 bps. Its selection mean was -0.00015745968983243985, se 0.0016973129869118078. EMA weights of 0.01 and above were dropped (0.3 lost -13.035198353672051 on 128 seeds). The smallest report se of the ten (0.0009622144824857604 and 0.0009421979703227205) reflects that the band rarely changes a fee. - **source**: `.imd/reads/artifacts/item-fee-memory` (artifacts/goal/batches/d-ideas/items/fee-memory/result.json), sha256 1cfa9e24fd59649a2393aaa65383e2f39c4ab37faa7d282b71f633fe54c38aa4 ### 3. silence-bound - **mech** (as the item gives it): silence-bound: extra silence-count-dependent variance contraction on top of existing silent-band conditioning - **definition**: After the existing silent-step truncation loop (k = min(dt-1,12) steps), divides the filter variance by 1 + silence_strength*max(0, k-silence_start+1) before the current step's tell and lookup. - **already_present**: true. Where: A further variance-only contraction depending on completed silent-step count is absent from all four policy files and from the compiled replica. - **chosen**: `{"silence_strength":0.1,"silence_start":3}` - **report.vs_lean**: n 2048, mean_diff -0.0008279686961202848, se 0.0019242159702547905, seeds_positive 1029 - **report.on_age**: n 2048, mean_diff -0.0006687704036579534, se 0.0019155571807606612, seeds_positive 1000 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"storage_words":0,"gas":{"type":"measured isolated WAD arithmetic probe; full contract integration unmeasured","incremental_min":48,"incremental_max":564,"samples":[{"dt":1,"base_gas":5271,"candidate_gas":5319,"incremental_gas":48},{"dt":4,"base_gas":5271,"candidate_gas":5830,"incremental_gas":559},{"dt":12,"base_gas":5271,"candidate_gas":5830,"incremental_gas":559},{"dt":100,"base_gas":5271,"candidate_gas":5835,"incremental_gas":564}],"compiler":"Solidity 0.8.24, optimizer enabled, 200 runs, Cancun EVM, metadata hash disabled","compiler_sha256":"fb03a29a517452b9f12bcf459ef37d0a543765bb3bbc911e70a87d6a37c30d5f","scope":"Difference between external pure functions returning unchanged v and applying the block below, called with v=1e12. Common call and test-harness costs cancel in the difference. Not an afterSwap peak or OOG measurement."},"characters":{"incremental_block":80,"including_one_full_credit_comment":200,"solidity_block":"if(dt>3){uint256 q=dt-1;if(q>12)q=12;q-=2;v=v*1e18/(1e18+100000000000000000*q);}","scope":"Exact character count of an illustrative WAD-scaled variance update with parameters compiled in. Assumes existing v and dt variables; excludes integration glue."},"runtime_bytes":{"base_probe":119,"candidate_probe":366,"incremental_probe":247,"integrated_contract_measured":false},"budget_context":{"given_current_peak_gas":208000,"peak_gas_limit":245000,"given_current_runtime_bytes":22440,"runtime_bytes_limit":24576,"given_current_source_characters":47230,"source_characters_limit":50000,"remaining_before_change":{"gas":37000,"runtime_bytes":2136,"source_characters":2770},"assessment":"The isolated primitive is small relative to the stated headroom, but its bytecode and gas deltas are not certified integration bounds. No production contract is returned."}}` - **selection notes**: All 12 settings completed 1024 seeds and none crossed the stop rule. The chosen setting (strength 0.1, start 3) had a selection mean of 0.0029668883392731105, se 0.0026920308615193027. That did not hold on the report seeds, where it is negative on both baselines. Its contract_cost gas and bytes are the only measured figures among the ten, and they come from an isolated arithmetic probe, not an integrated contract. - **source**: `.imd/reads/artifacts/item-silence-bound` (artifacts/goal/batches/d-ideas/items/silence-bound/result.json), sha256 6bc3252e57f18ce5cd60051236e351753f2eef080a383fd7582fbb5c1113529c ### 4. age-fee - **mech** (as the item gives it): age-fee: symmetric saturating additive fee premium since last callback inferred as arbitrage - **definition**: Adds premium_bps*1e-4*age/(age+age_tau) to both fees, where age is the time since the last callback LEAN's tell read as arbitrage (step-first and posterior > 0.5), after the table lookup and before fee rounding. - **already_present**: false. Where: Inspected leanbase.py Policy.on_grid, tellpol.py TellPolicy.on_trade, real.py RealPolicy.on_trade/lookup and stalerival.py Policy.on_trade from the packed reference. real.py grows filter variance over elapsed steps; stalerival.py AGE varies a rival-price pull using time since a router-binding retail callback. Neither keeps a last-inferred-arbitrage clock or adds a symmetric age fee. No substitute mechanism was necessary. - **chosen**: `{"premium_bps":0.1,"age_tau":4}` - **report.vs_lean**: n 2048, mean_diff 0.0005244462906790204, se 0.0023991125163267874, seeds_positive 1062 - **report.on_age**: n 2048, mean_diff -0.001480369005663923, se 0.002419455415421662, seeds_positive 1051 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"storage_words":1,"gas":{"measured":null,"engineering_estimate_added_per_callback":[2500,24000],"basis":"Dedicated persistent timestamp: one read on retail callbacks and one timestamp write on inferred arb, plus subtraction, multiply/divide and two additions. Largest estimate allows a cold first zero-to-nonzero timestamp write. Later nonzero writes should be substantially cheaper. Storage packing may change cost. No Solidity implementation compiled or gas measured."},"characters":{"measured":null,"engineering_estimate_added":[400,1000]},"runtime_bytes":{"measured":null,"engineering_estimate_added":[150,500]},"budget_context":"Requester-supplied current peak 208000/245000 gas, runtime 22440/24576 bytes and source 47230/50000 characters leave 37000 gas, 2136 bytes and 2770 characters. This small arithmetic extension plausibly fits, but estimates are not a gas/size pass or an OOG guarantee."}` - **selection notes**: 5 of 12 settings survived all 1024 selection seeds: premium_bps 0.1 with age_tau 1, 4 and 16, and premium_bps 0.3 with age_tau 4 and 16. The chosen setting (premium_bps 0.1, age_tau 4) had a selection mean of -0.00098988062173061, se 0.0030843479989459822. On report seeds it is slightly positive against LEAN (0.0005244462906790204) and slightly negative on AGE (-0.001480369005663923). This is a different mechanism from the AGE baseline: per the item, AGE is stalerival's router-age rival pull. - **source**: `.imd/reads/artifacts/item-age-fee` (artifacts/goal/batches/d-ideas/items/age-fee/result.json), sha256 67382867eab4e2030c4e73b86c1efc00cd1067314d0c94b39dfc9a39a58a212b ### 5. share-feedback - **mech** (as the item gives it): share-feedback: slow symmetric fee-level feedback from observed own retail fills and normalized paid volume; no improvement found, do not promote. - **definition**: Keeps a decaying own-retail flow state z (z <- z*T/(T+dt), plus (0.5/T)*(1/C + v/V) on each retail fill, v = capped fill in bps of reserve) and adds clamp(g*(z-1), -cap, cap) bps symmetrically to both fees. - **already_present**: false. Where: Inspected leanbase.py, stalerival.py, real.py and tellpol.py from the pinned reference bundle. real.RealPolicy.on_trade has cnt (within-step retail count) and phase selection; stalerival.Policy.on_trade has router age and a rival pull. Neither accumulates cross-step count/volume against a target to control fee level. leanbase and tellpol change the arb/retail classification only. Existing per-step count is reused only through the existing retail label; the cross-step controller is new. - **chosen**: `{"gain_bps":0.5,"time_constant_steps":512,"count_target":0.75,"volume_target_bps":10,"cap_bps":2}` - **report.vs_lean**: n 2048, mean_diff -0.0015907482784406624, se 0.0028472614476621892, seeds_positive 996 - **report.on_age**: n 2048, mean_diff -0.006530390919671475, se 0.0028038291574551885, seeds_positive 972 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"storage_words":1,"gas":{"measured":null,"estimated_incremental_afterSwap_range":[6000,10000],"estimate_basis":"Engineering estimate for one read/modify/write of a nonzero fixed-point flow state, reuse of existing timestamp and retail label, a few fixed-point divisions/multiplies and clamps. Initialize z in afterInitialize. No added loops, logs, exponentials or tables. Not measured or a guaranteed upper bound.","brief_baseline_peak":208000,"brief_peak_limit":245000,"estimated_total_peak_range":[214000,218000]},"characters":{"measured":null,"estimated_added_solidity_range":[700,1400],"brief_current":47230,"brief_limit":50000,"remaining_before_change":2770},"runtime_bytes":{"measured":null,"estimated_added_range":[250,800],"brief_current":22440,"brief_limit":24576,"remaining_before_change":2136},"qualification":"All Solidity gas/source/runtime additions are planning estimates, not compiled measurements. Storage count follows the one-scalar design. Existing resource figures come from the assignment, not this experiment. A real port must check fixed-point precision, source size, deployed size, peak gas and OOG. This negative replica result does not justify that port."}` - **selection notes**: Ten settings were dropped and two completed. The chosen setting (gain 0.5 bps, T 512, C 0.75, V 10) had a selection mean of -0.005493219484855372, se 0.003779579743069829. - **source**: `.imd/reads/artifacts/item-share-feedback` (artifacts/goal/batches/d-ideas/items/share-feedback/result.json), sha256 507d28269a4e20fc94db2e53b8ce02429acc42542b4acc6e2321e8cb2e306b22 ### 6. inventory - **mech** (as the item gives it): inventory: skew of the bid and ask fees by the pool's own inventory relative to the start - **definition**: Skews fees by quantity inventory q = ln(x/100): u = tanh(q/q0), fee_bid += c*u, fee_ask -= c*u, before fee rounding (the literal value-at-mean-price form was found already present in the table lookup). - **already_present**: 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. - **chosen**: `{"c_fee":-5e-05,"c_bps":-0.5,"q0":0.3}` - **report.vs_lean**: n 2048, mean_diff -0.00881, se 0.00275, seeds_positive 946 - **report.on_age**: n 2048, mean_diff -0.00859, se 0.0024, seeds_positive 919 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"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"}` - **selection notes**: Only one setting survived (c -0.5 bps, q0 0.3). All 12 had a negative mean_diff. The literal value-skew form is already the first coordinate of LEANBASE's qm lookup, so the item tested quantity inventory ln(x/x0) instead. - **source**: `.imd/reads/artifacts/item-inventory` (artifacts/goal/batches/d-ideas/items/inventory/result.json), sha256 1be7d7b01bddde7f46d51ef3319a8a89966bc438d93baff111b3ecf5eb24116b ### 7. undercut - **mech** (as the item gives it): undercut: explicit synced, symmetric fee-space band snap below the estimated rival marginal quote - **definition**: When synced and the table fee lies within band_bps of the rival's marginal router-indifference fee (0 <= point <= 0.1, g = 0.997), replaces that side's fee with max(0, point - margin_bps*1e-4). - **already_present**: false. Where: Read leanbase.py, stalerival.py, real.py and tellpol.py from reference_zb64 at https://api.imd.fun/artifacts/efb8e653f8fd061cecf3e92b186470c9c96c5188523364b60ed101e9672869aa. leanbase.Policy changes the tell; tellpol.TellPolicy changes the first-trade posterior; real.RealPolicy updates the rival estimate and selects/interpolates synced qm tables; stalerival.Policy pulls the stale estimate then repeats lookup. None applies this explicit post-table fee-band snap. Tables already account for rival competition, so the economic idea of competing with the rival is not itself new. - **chosen**: `{"margin_bps":0.1,"band_bps":0.5}` - **report.vs_lean**: n 2048, mean_diff -0.004690568590842298, se 0.002193183321020636, seeds_positive 941 - **report.on_age**: n 2048, mean_diff -0.009578699512042016, se 0.0022076424341107, seeds_positive 949 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"storage_words":0,"gas":{"measured_increment":null,"engineering_estimate_increment":[500,3000],"basis":"Unmeasured planning range assuming existing fixed-point spot and rival values can be reused; two ratio calculations, two point calculations, bounds/band tests and subtractions. No new SLOAD/SSTORE or transcendental functions. A particular Solidity arithmetic library/compiler could change this; not a gas guarantee."},"characters":{"solidity_measured_increment":null,"engineering_estimate_increment":[700,1600],"python_patch_net_increment":1118},"runtime_bytes":{"measured_increment":null,"engineering_estimate_increment":[200,900]},"supplied_baseline":{"peak_gas":208000,"gas_limit":245000,"runtime_bytes":22440,"runtime_limit":24576,"source_characters":47230,"source_limit":50000},"headroom":{"gas":37000,"runtime_bytes":2136,"source_characters":2770},"assessment":"Likely fits the supplied headroom if implemented directly with existing fixed-point helpers and compile-time margin/band. Estimates are engineering judgment, not measurements; no Solidity contract was built. Source/gas/byte limits and 0 OOG require later compiled engine certification."}` - **selection notes**: 3 of 12 survived, all with band_bps 0.5. Every selection mean was negative. The chosen setting is margin 0.1 bps, band 0.5 bps. - **source**: `.imd/reads/artifacts/item-undercut` (artifacts/goal/batches/d-ideas/items/undercut/result.json), sha256 62250f5dbf6fbe38ab24d70c6484c5209bcc8913cdbea16b8d006cfc43c423a3 ### 8. same-step - **mech** (as the item gives it): same-step - **definition**: On a non-arb callback whose same-timestamp non-arb fill count cnt is >= cnt0, shifts the own-side fee by k*d_own and the other-side fee by k*d_oth (k = 1 if C == 0 else min(cnt-1, C)), beyond LEAN's existing phase-1/phase-2 split. - **already_present**: 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. - **chosen**: `{"cnt0":3,"d_own_bps":-2,"d_oth_bps":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 - **report.on_age**: n 2048, mean_diff -0.010747124174305539, se 0.0027241726578222424, seeds_positive 899 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"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"}` - **selection notes**: All 12 settings were dropped by round 3 (n<=384). The chosen setting is the least negative at drop (cnt0 3, d_own -2 bps). The item concludes that the phase-1/phase-2 split already captures the same-step effect. - **source**: `.imd/reads/artifacts/item-same-step` (artifacts/goal/batches/d-ideas/items/same-step/result.json), sha256 af2e10fd183ff8299a428022d2a003977b50de5d44c90c0beb75e997f00d5285 ### 9. post-arb-skew - **mech** (as the item gives it): 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). - **definition**: After a callback read as arbitrage, adds k_edge to the fee on the side the arb hit and k_other to the other side, either at that callback only (at_arb_only) or decaying as exp(-age/L) until the next arb (persist_decay). - **already_present**: 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. - **chosen**: `{"k_edge_bps":0,"k_other_bps":-1,"mode":"at_arb_only","L_steps":null}` - **report.vs_lean**: n 2048, mean_diff -0.022, se 0.0023, seeds_positive 805 - **report.on_age**: n 2048, mean_diff -0.0228, se 0.0024, seeds_positive 837 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"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"}}` - **selection notes**: All 12 settings were dropped at the first 128-seed round. The chosen setting (S9, k_other -1 bp, at_arb_only) had the least negative mean. The item's conclusion is that the phase-0 table already sits near the best post-arb pair, so do not pipeline it. S9-S12 were chosen after S1-S8. - **source**: `.imd/reads/artifacts/item-post-arb-skew` (artifacts/goal/batches/d-ideas/items/post-arb-skew/result.json), sha256 daf38ea05e2da518319a614c7819749cd9b28aed5bbe09a976d752b717f6ce2f ### 10. size-run - **mech** (as the item gives it): size-run: callback-only per-run estimate of full retail order size shifts LEAN fee levels. - **definition**: Estimates full retail order size per run by inverting the replica router split from each retail fill (clamped to [q,4q]) into a running mean M (prior 20, pseudo-count 32) and adds c*clip(M/20-1,-0.5,0.5)*1e-4 to both fees (mode 0), the traded side (mode 1) or the other side (mode 2). - **already_present**: false. Where: Inspected leanbase.py, stalerival.py, real.py and tellpol.py in the LEANBASE reference bundle. real.py uses a fixed retail-size likelihood; none keeps a running size estimate or conditions the returned fees on it. See sources.json for the reference bundle and real.py. - **chosen**: `{"coefficient_bps_per_rel":2,"side_mode":0,"prior_mean":20,"prior_count":32,"split_cap":4}` - **report.vs_lean**: n 2048, mean_diff -0.04992351261329561, se 0.003577958126681876, seeds_positive 732 - **report.on_age**: n 2048, mean_diff -0.053940194276585585, se 0.0037164126133699647, seeds_positive 729 - **promote**: false - **contract_cost** (copied as given. Unless the item says otherwise, these are estimates, not compiled measurements): `{"storage_words":2,"gas":{"additional_measured":null,"current_peak_given":208000,"limit":245000,"headroom":37000,"work":"Per retail callback: two square roots, reserve reconstruction, split inversion, clamp, mean update; per callback: fee adjustment. Solidity gas not measured."},"characters":{"additional_measured":null,"current_given":47230,"limit":50000,"headroom":2770,"status":"No Solidity port; fit not measured."},"runtime_bytes":{"additional_measured":null,"current_given":22440,"limit":24576,"headroom":2136}}` - **selection notes**: All 12 settings met the early-stop rule. The least negative (coefficient 2 bps per unit relative size, mode 0) was still run on the report seeds. It is the worst row on both reports. - **source**: `.imd/reads/artifacts/item-size-run` (artifacts/goal/batches/d-ideas/items/size-run/result.json), sha256 eb71f1610d346c5d8533c7784d381e1ff1331b1c2379e4cd90b4288f7b118b88 ## Sources that did not hold on re-read The requester's machines re-read the sources these results cite. For three items, some cited sources could not be read or did not say what they were quoted for. The brief names the items and the counts but not which URL failed. This merge cannot identify the failed URL either, so it marks what each item's claim rests on. - **same-step (1 source).** The item's `already_present: true` rests on quoted lines from Taylor's files: real.py lines 167-168 `self.cnt += 1; phs = 1 if self.cnt <= 1 else 2` and stalerival.py line 63. The item fetched these with Taylor's fetch.sh at commit 66604b3426d8e97a73e2c39940b9b4dece51cc73, not at the goal's pinned 4812a6382311624e1506aca131ca35c378f930d9. Treat the line-number quotes as unconfirmed. The substance gets independent support from share-feedback, which separately reports that `real.RealPolicy.on_trade has cnt (within-step retail count) and phase selection`. The item's edge numbers are its own local replica runs and do not depend on that source. - **size-run (2 sources).** The item cites four refs: the replica artifact a88ff982…, the reference bundle efb8e653…, and Taylor's research/solved/real.py and replica2.py at commit 66604b3426d8e97a73e2c39940b9b4dece51cc73. Two of these did not hold. Two of its claims rest on them: (a) `already_present: false` ("real.py uses a fixed retail-size likelihood"), and (b) its mechanism inverts "the replica router split formula". Claim (a) is consistent with fill-size's independent reading (real.py has a lognormal retail likelihood, and a fill=1 order-size option that LEAN does not set), but take it as weakened. The edge numbers (-0.04992351261329561 vs LEAN, -0.053940194276585585 on AGE) are local runs. Whatever the source status, the result is negative, so the flag does not change any decision. - **undercut (1 source).** The item cites the replica artifact, the reference bundle and the kit README (https://raw.githubusercontent.com/identity-md-launches/goal-3178-build-shared-evaluation-kit/45e7563d1a29ffca9d608fdf60c90bf2624d2d01/README.md). One did not hold. The source most at stake is the reference bundle, because its `already_present: false` reading (no post-table fee-band snap in leanbase/stalerival/real/tellpol) rests on it. The item itself says the economic idea of competing with the rival is already in the tables. Its numbers are local runs and negative on both baselines, so the flag does not change any decision. The other seven items were not flagged. ## Where items disagree or need care - **already_present differs in kind.** Three items say true: same-step, inventory and silence-bound. In all three the basic effect already exists in LEAN (the phase-1/2 split, the first qm coordinate, the silent-step truncation), so each tested the nearest variant that is absent. Their rows measure that variant, not the literal idea. The other seven say false. - **The chosen setting is not always a survivor.** In same-step, size-run and post-arb-skew, every setting was dropped, and the chosen row is the least negative at its drop point. fill-size, post-arb-skew and the later settings of others were picked adaptively on the selection seeds. The items flag this themselves. The report seeds were not reused for choice. - **Selection did not predict the report.** silence-bound's choice-block mean was positive (0.0029668883392731105) but its report means are negative. fill-size's was negative (-0.00231) but its report means are slightly positive. Both are within the replica noise floor that fill-size describes. - **Environments differ.** silence-bound ran numpy 2.5.4 / numba 0.68.1 / llvmlite 0.50.0 on Python 3.12.16, and post-arb-skew ran CPython 3.10.12. The others that state an environment ran numpy 2.2.6 / numba 0.61.2 / llvmlite 0.44.0. size-run states none. Each item reports that baseline parity or zero-mechanism bit-identity held in its own environment. Every item that reports baseline means gives the same LEAN and AGE report-seed means listed above. size-run and post-arb-skew report none. - **Contract costs are almost all estimates.** Only silence-bound measured anything: an isolated Solidity 0.8.24 probe giving 48..564 gas and 247 runtime bytes. All items quote the brief's budget context of 208000/245000 gas, 22440/24576 bytes and 47230/50000 characters. fill-size cites QLX5's artifact peak_gas as 208366. Since nothing is promoted, none of these costs is binding. - **Engine transfer is untested.** Line (b) of the goal says the engine recomputes k from rounded reserves at every quote and the replica does not. Every item ran the unrepaired constant-K replica (age-fee, undercut, share-feedback, silence-bound and fee-memory say so explicitly), so none of these deltas is known to transfer. ## failed None. All ten inputs named by the brief are present, parse as JSON, match their stated SHA-256, and carry `report.vs_lean` and `report.on_age` with n, mean_diff, se and seeds_positive: age-fee, same-step, fill-size, size-run, share-feedback, undercut, post-arb-skew, inventory, silence-bound, fee-memory. ## The merged object This is the same content as the tables above. Every number is copied from the item. ```json { "rows": [ { "item": "fill-size", "mech": "fill-size: the size of a fill read as retail, relative to a running mean of our retail fills, shifts the next fees on the same side and on the other side", "already_present": false, "chosen": { "k_same_bps": 0, "k_other_bps": 0.25, "beta": 0.03125, "C": 3, "M0": 11, "c0": 0.862, "form": "linear" }, "report": { "vs_lean": { "n": 2048, "mean_diff": 0.00227, "se": 0.003436, "seeds_positive": 1050 }, "on_age": { "n": 2048, "mean_diff": 0.000241, "se": 0.003519, "seeds_positive": 1048 } }, "promote": false, "contract_cost": { "measured": false, "storage_words": "0 new words if M is packed into slot 2 of QLX5 (fb | fa<<64 | t<<128 | cnt<<192 with cnt masked to 32 bits and the synced flag in bit 255: bits 224..254 are free, 31 bits, enough for M in 1e-6 Y up to 2,147 Y); 1 new word otherwise", "gas": "estimate, not measured: packed, about 200-400 gas on a retail-read callback (unpack, one division, clip, running-mean update, two multiplications, two additions, repack) and about 30 on an arb-read one, so peak about 208,400-208,800 of 245,000. In a slot of its own, about 5,000 more per callback that touches it under EIP-2929 pricing (cold SLOAD 2,100 + SSTORE reset 2,900), if the engine charges cold access per callback: about 213,700. The log form needs the contract's ln (a 14-term series loop), several thousand gas; the chosen form is linear.", "runtime_bytes": "estimate: 120-220 bytes, 22,440 -> about 22,600-22,660 of 24,576", "characters": "estimate: 300-450 source characters, 47,230 -> about 47,550-47,680 of 50,000", "basis": "QLX5 source (sha256 e183e5bc3fb794b7067703b10a7da9920267aa5f4caa968e16ca101b02338f40, 47,230 characters, decoded from code_zb64.QLX5 of artifact 1ef80bfb6d6791b877b1f4048a5e63cf2ae54153e6e8763ae3f8ab13132dfb15) read for its slot layout; that artifact gives peak_gas 208366, runtime_bytes 22440, source_chars 47230. No Solidity was written or compiled here." }, "definition": "At a callback read as retail, takes z = min(q/M, C) - c0 (q = amountY, M a running mean of retail amountY with rate beta, initial 11.0) and adds k_same*1e-4*z to the traded side's fee and k_other*1e-4*z to the other side's fee until the next callback." }, { "item": "fee-memory", "mech": "fee-memory: independent bid/ask EMA or dead-band hysteresis after the final LEAN table lookup and before fee_round; no additional observations.", "already_present": false, "chosen": { "mode": 2, "param": 0.03, "family": "dead_band" }, "report": { "vs_lean": { "n": 2048, "mean_diff": -0.0006303010545473664, "se": 0.0009622144824857604, "seeds_positive": 899 }, "on_age": { "n": 2048, "mean_diff": -0.00026428233344610863, "se": 0.0009421979703227205, "seeds_positive": 921 } }, "promote": false, "contract_cost": { "storage_words": 0, "storage_basis": "Incremental words: reuse existing previous returned bid/ask fee state already required by the tell. Two fee values must be retained if ported to a policy without that state.", "gas": { "measured": null, "estimated_increment_range": [ 100, 1500 ], "basis": "Engineering estimate only for two simple compare/select operations (dead band) or two fixed-point blends (EMA), with prior fee loads reused and no extra SSTORE. Compiler, signed-difference handling and surrounding code can change this." }, "characters": { "measured": null, "estimated_increment_range": [ 250, 900 ], "basis": "Estimated minimal Solidity addition for only the chosen mechanism, excluding this Python experiment and comments; not compiled." }, "runtime_bytes": { "measured": null, "estimated_increment_range": [ 100, 500 ] }, "budget_from_brief": { "peak_gas": 208000, "gas_limit": 245000, "runtime_bytes": 22440, "runtime_limit": 24576, "source_characters": 47230, "source_limit": 50000 }, "assessment": "Likely fits the stated 37000 gas, 2136 runtime-byte and 2770 source-character headroom; unverified until a Solidity port is compiled and measured." }, "definition": "Per side, returns either an EMA v = (1-w)*u + w*p of the new fee u and previous returned fee p, or a dead band that keeps p when |u-p| < h*1e-4, before fee_round." }, { "item": "silence-bound", "mech": "silence-bound: extra silence-count-dependent variance contraction on top of existing silent-band conditioning", "already_present": true, "chosen": { "silence_strength": 0.1, "silence_start": 3 }, "report": { "vs_lean": { "n": 2048, "mean_diff": -0.0008279686961202848, "se": 0.0019242159702547905, "seeds_positive": 1029 }, "on_age": { "n": 2048, "mean_diff": -0.0006687704036579534, "se": 0.0019155571807606612, "seeds_positive": 1000 } }, "promote": false, "contract_cost": { "storage_words": 0, "gas": { "type": "measured isolated WAD arithmetic probe; full contract integration unmeasured", "incremental_min": 48, "incremental_max": 564, "samples": [ { "dt": 1, "base_gas": 5271, "candidate_gas": 5319, "incremental_gas": 48 }, { "dt": 4, "base_gas": 5271, "candidate_gas": 5830, "incremental_gas": 559 }, { "dt": 12, "base_gas": 5271, "candidate_gas": 5830, "incremental_gas": 559 }, { "dt": 100, "base_gas": 5271, "candidate_gas": 5835, "incremental_gas": 564 } ], "compiler": "Solidity 0.8.24, optimizer enabled, 200 runs, Cancun EVM, metadata hash disabled", "compiler_sha256": "fb03a29a517452b9f12bcf459ef37d0a543765bb3bbc911e70a87d6a37c30d5f", "scope": "Difference between external pure functions returning unchanged v and applying the block below, called with v=1e12. Common call and test-harness costs cancel in the difference. Not an afterSwap peak or OOG measurement." }, "characters": { "incremental_block": 80, "including_one_full_credit_comment": 200, "solidity_block": "if(dt>3){uint256 q=dt-1;if(q>12)q=12;q-=2;v=v*1e18/(1e18+100000000000000000*q);}", "scope": "Exact character count of an illustrative WAD-scaled variance update with parameters compiled in. Assumes existing v and dt variables; excludes integration glue." }, "runtime_bytes": { "base_probe": 119, "candidate_probe": 366, "incremental_probe": 247, "integrated_contract_measured": false }, "budget_context": { "given_current_peak_gas": 208000, "peak_gas_limit": 245000, "given_current_runtime_bytes": 22440, "runtime_bytes_limit": 24576, "given_current_source_characters": 47230, "source_characters_limit": 50000, "remaining_before_change": { "gas": 37000, "runtime_bytes": 2136, "source_characters": 2770 }, "assessment": "The isolated primitive is small relative to the stated headroom, but its bytecode and gas deltas are not certified integration bounds. No production contract is returned." } }, "definition": "After the existing silent-step truncation loop (k = min(dt-1,12) steps), divides the filter variance by 1 + silence_strength*max(0, k-silence_start+1) before the current step's tell and lookup." }, { "item": "age-fee", "mech": "age-fee: symmetric saturating additive fee premium since last callback inferred as arbitrage", "already_present": false, "chosen": { "premium_bps": 0.1, "age_tau": 4 }, "report": { "vs_lean": { "n": 2048, "mean_diff": 0.0005244462906790204, "se": 0.0023991125163267874, "seeds_positive": 1062 }, "on_age": { "n": 2048, "mean_diff": -0.001480369005663923, "se": 0.002419455415421662, "seeds_positive": 1051 } }, "promote": false, "contract_cost": { "storage_words": 1, "gas": { "measured": null, "engineering_estimate_added_per_callback": [ 2500, 24000 ], "basis": "Dedicated persistent timestamp: one read on retail callbacks and one timestamp write on inferred arb, plus subtraction, multiply/divide and two additions. Largest estimate allows a cold first zero-to-nonzero timestamp write. Later nonzero writes should be substantially cheaper. Storage packing may change cost. No Solidity implementation compiled or gas measured." }, "characters": { "measured": null, "engineering_estimate_added": [ 400, 1000 ] }, "runtime_bytes": { "measured": null, "engineering_estimate_added": [ 150, 500 ] }, "budget_context": "Requester-supplied current peak 208000/245000 gas, runtime 22440/24576 bytes and source 47230/50000 characters leave 37000 gas, 2136 bytes and 2770 characters. This small arithmetic extension plausibly fits, but estimates are not a gas/size pass or an OOG guarantee." }, "definition": "Adds premium_bps*1e-4*age/(age+age_tau) to both fees, where age is the time since the last callback LEAN's tell read as arbitrage (step-first and posterior > 0.5), after the table lookup and before fee rounding." }, { "item": "share-feedback", "mech": "share-feedback: slow symmetric fee-level feedback from observed own retail fills and normalized paid volume; no improvement found, do not promote.", "already_present": false, "chosen": { "gain_bps": 0.5, "time_constant_steps": 512, "count_target": 0.75, "volume_target_bps": 10, "cap_bps": 2 }, "report": { "vs_lean": { "n": 2048, "mean_diff": -0.0015907482784406624, "se": 0.0028472614476621892, "seeds_positive": 996 }, "on_age": { "n": 2048, "mean_diff": -0.006530390919671475, "se": 0.0028038291574551885, "seeds_positive": 972 } }, "promote": false, "contract_cost": { "storage_words": 1, "gas": { "measured": null, "estimated_incremental_afterSwap_range": [ 6000, 10000 ], "estimate_basis": "Engineering estimate for one read/modify/write of a nonzero fixed-point flow state, reuse of existing timestamp and retail label, a few fixed-point divisions/multiplies and clamps. Initialize z in afterInitialize. No added loops, logs, exponentials or tables. Not measured or a guaranteed upper bound.", "brief_baseline_peak": 208000, "brief_peak_limit": 245000, "estimated_total_peak_range": [ 214000, 218000 ] }, "characters": { "measured": null, "estimated_added_solidity_range": [ 700, 1400 ], "brief_current": 47230, "brief_limit": 50000, "remaining_before_change": 2770 }, "runtime_bytes": { "measured": null, "estimated_added_range": [ 250, 800 ], "brief_current": 22440, "brief_limit": 24576, "remaining_before_change": 2136 }, "qualification": "All Solidity gas/source/runtime additions are planning estimates, not compiled measurements. Storage count follows the one-scalar design. Existing resource figures come from the assignment, not this experiment. A real port must check fixed-point precision, source size, deployed size, peak gas and OOG. This negative replica result does not justify that port." }, "definition": "Keeps a decaying own-retail flow state z (z <- z*T/(T+dt), plus (0.5/T)*(1/C + v/V) on each retail fill, v = capped fill in bps of reserve) and adds clamp(g*(z-1), -cap, cap) bps symmetrically to both fees." }, { "item": "inventory", "mech": "inventory: skew of the bid and ask fees by the pool's own inventory relative to the start", "already_present": true, "chosen": { "c_fee": -5e-05, "c_bps": -0.5, "q0": 0.3 }, "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 } }, "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" }, "definition": "Skews fees by quantity inventory q = ln(x/100): u = tanh(q/q0), fee_bid += c*u, fee_ask -= c*u, before fee rounding (the literal value-at-mean-price form was found already present in the table lookup)." }, { "item": "undercut", "mech": "undercut: explicit synced, symmetric fee-space band snap below the estimated rival marginal quote", "already_present": false, "chosen": { "margin_bps": 0.1, "band_bps": 0.5 }, "report": { "vs_lean": { "n": 2048, "mean_diff": -0.004690568590842298, "se": 0.002193183321020636, "seeds_positive": 941 }, "on_age": { "n": 2048, "mean_diff": -0.009578699512042016, "se": 0.0022076424341107, "seeds_positive": 949 } }, "promote": false, "contract_cost": { "storage_words": 0, "gas": { "measured_increment": null, "engineering_estimate_increment": [ 500, 3000 ], "basis": "Unmeasured planning range assuming existing fixed-point spot and rival values can be reused; two ratio calculations, two point calculations, bounds/band tests and subtractions. No new SLOAD/SSTORE or transcendental functions. A particular Solidity arithmetic library/compiler could change this; not a gas guarantee." }, "characters": { "solidity_measured_increment": null, "engineering_estimate_increment": [ 700, 1600 ], "python_patch_net_increment": 1118 }, "runtime_bytes": { "measured_increment": null, "engineering_estimate_increment": [ 200, 900 ] }, "supplied_baseline": { "peak_gas": 208000, "gas_limit": 245000, "runtime_bytes": 22440, "runtime_limit": 24576, "source_characters": 47230, "source_limit": 50000 }, "headroom": { "gas": 37000, "runtime_bytes": 2136, "source_characters": 2770 }, "assessment": "Likely fits the supplied headroom if implemented directly with existing fixed-point helpers and compile-time margin/band. Estimates are engineering judgment, not measurements; no Solidity contract was built. Source/gas/byte limits and 0 OOG require later compiled engine certification." }, "definition": "When synced and the table fee lies within band_bps of the rival's marginal router-indifference fee (0 <= point <= 0.1, g = 0.997), replaces that side's fee with max(0, point - margin_bps*1e-4)." }, { "item": "same-step", "mech": "same-step", "already_present": true, "chosen": { "cnt0": 3, "d_own_bps": -2, "d_oth_bps": 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 } }, "promote": false, "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" }, "definition": "On a non-arb callback whose same-timestamp non-arb fill count cnt is >= cnt0, shifts the own-side fee by k*d_own and the other-side fee by k*d_oth (k = 1 if C == 0 else min(cnt-1, C)), beyond LEAN's existing phase-1/phase-2 split." }, { "item": "post-arb-skew", "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": false, "chosen": { "k_edge_bps": 0, "k_other_bps": -1, "mode": "at_arb_only", "L_steps": null }, "report": { "vs_lean": { "n": 2048, "mean_diff": -0.022, "se": 0.0023, "seeds_positive": 805 }, "on_age": { "n": 2048, "mean_diff": -0.0228, "se": 0.0024, "seeds_positive": 837 } }, "promote": false, "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" } }, "definition": "After a callback read as arbitrage, adds k_edge to the fee on the side the arb hit and k_other to the other side, either at that callback only (at_arb_only) or decaying as exp(-age/L) until the next arb (persist_decay)." }, { "item": "size-run", "mech": "size-run: callback-only per-run estimate of full retail order size shifts LEAN fee levels.", "already_present": false, "chosen": { "coefficient_bps_per_rel": 2, "side_mode": 0, "prior_mean": 20, "prior_count": 32, "split_cap": 4 }, "report": { "vs_lean": { "n": 2048, "mean_diff": -0.04992351261329561, "se": 0.003577958126681876, "seeds_positive": 732 }, "on_age": { "n": 2048, "mean_diff": -0.053940194276585585, "se": 0.0037164126133699647, "seeds_positive": 729 } }, "promote": false, "contract_cost": { "storage_words": 2, "gas": { "additional_measured": null, "current_peak_given": 208000, "limit": 245000, "headroom": 37000, "work": "Per retail callback: two square roots, reserve reconstruction, split inversion, clamp, mean update; per callback: fee adjustment. Solidity gas not measured." }, "characters": { "additional_measured": null, "current_given": 47230, "limit": 50000, "headroom": 2770, "status": "No Solidity port; fit not measured." }, "runtime_bytes": { "additional_measured": null, "current_given": 22440, "limit": 24576, "headroom": 2136 } }, "definition": "Estimates full retail order size per run by inverting the replica router split from each retail fill (clamped to [q,4q]) into a running mean M (prior 20, pseudo-count 32) and adds c*clip(M/20-1,-0.5,0.5)*1e-4 to both fees (mode 0), the traded side (mode 1) or the other side (mode 2)." } ], "failed": [] } ``` Credit: Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved.