# combo-fees: TwoComp filter + weighted-average fee quoting (replica screen) Credit: Taylor (gtmcknight) for the Gaussian filter, the solved qm tables, real.py's fee rule and the replica ([amm-sim research/solved @4812a638](https://github.com/gtmcknight/amm-sim/tree/4812a6382311624e1506aca131ca35c378f930d9/research/solved)); qt1's reference from [K](https://raw.githubusercontent.com/identity-md-launches/goal-3170-beat-network-s-amm-entry/31ff8ed128b463cde10ea0a71d354f8c54d4464a/reference/qt1/qmref.py); TwoComp from [TC](https://api.imd.fun/artifacts/d3c849db2ac31e567b57e52b80b86e8c24c842e5b4125b9d75c78e3cb07115b9); the quoting rule from [MIX](https://api.imd.fun/artifacts/23cf289cf15eff6790cb2067a714df9d020049d2de5f3975c11857ab344cb9e4). **Headline (replica, not engine):** COMBO − qt1-ref = **+0.6376 (se 0.0195)** on choose 60000..61023 and **+0.5986 (se 0.0134)** on report 10000..12047. COMBO − TwoComp = +0.1922 (se 0.0147) / +0.1738 (se 0.0108). Both windows complete (n=1024, n=2048). Nothing tuned. ## Exact rule - Filter and state are TwoComp's, unchanged (`DUAL_CUTS=2`): at a step's first callback (`dt>=1`) each component gets diffusion and up to two separate silent-step no-arb cuts, after which they are merged by moment matching; arb likelihood `la = sum w·N(lp; m, v)`, retail mass `Z = sum w·z`, retail moments `(mt, vt)` = moment match of the truncated components, `pi = la/(la+lr)`; carried posterior `comp = [(pi, lp, 0), (1-pi, mt, vt)]` if `.005=1` and `.005= 1: self.cnt = 0 lo = math.log(self.sp * (1 - self.fb)); hi = math.log(self.sp / (1 - self.fa)) prior = self.propagate(dt, lo, hi) lp = math.log(s * (1 - self.fb)) if is_buy else math.log(s / (1 - self.fa)) la = 0.0; Z = 0.0; retail = [] for w, m, v in prior: sd = math.sqrt(v) la += w * phi((lp - m) / sd) / sd z, mt, vt = trunc(m, v, lo, hi) Z += w * z retail.append((w * z, mt, vt)) if Z > 1e-300: mt, vt = self.moments([(w / Z, m, v) for w, m, v in retail]) else: i = max(range(len(prior)), key=lambda i: prior[i][0]) _, mt, vt = retail[i] d = max(abs(math.log(s / self.sp)), 1e-9) lr = Z * .26 * phi((math.log(d) - LD_M) / LD_S) / (d * LD_S) pi = la / (la + lr) if la + lr > 0 else 0. is_arb = pi > .5 if .005 < pi < .995: # wavg-fees quoting: one lookup per branch, branches = TwoComp components old_synced = self.synced pa = math.exp(lp) ra = max(pa * .997, min(pa / .997, self.s2h)) self.synced = False fba, faa = self.lookup((math.log(s) - lp) * 1e4, (math.log(ra) - lp) * 1e4, 0, 0.) pr = math.exp(mt) rr = max(pr * .997, min(pr / .997, self.s2h)) cand = s * (1 - self.fb) / .997 if is_buy else s * .997 / (1 - self.fa) if (cand < rr) if is_buy else (cand > rr): rr = cand; self.synced = True fbr, far = self.lookup((math.log(s) - mt) * 1e4, (math.log(rr) - mt) * 1e4, 1, math.sqrt(vt) * 1e4) self.synced = old_synced mix_fees = (pi * fba + (1 - pi) * fbr, pi * faa + (1 - pi) * far) self.new_path_calls += 1 self.comp = [(pi, lp, 0.), (1 - pi, mt, vt)] elif is_arb: self.comp = [(1.0, lp, 0.)] else: self.comp = [(1.0, mt, vt)] self.m, self.v = self.moments(self.comp) pe = math.exp(self.m) self.s2h = max(pe * .997, min(pe / .997, self.s2h)) self.synced = False if not is_arb: cand = s * (1 - self.fb) / .997 if is_buy else s * .997 / (1 - self.fa) if (cand < self.s2h) if is_buy else (cand > self.s2h): self.s2h = cand; self.synced = True self.cnt += 1 ph = 1 if self.cnt == 1 else 2 else: ph = 0 self.tlast = t; self.sp = s if mix_fees is None: fb, fa = self.lookup((math.log(s) - self.m) * 1e4, (math.log(self.s2h) - self.m) * 1e4, ph, math.sqrt(self.v) * 1e4) else: fb, fa = mix_fees self.fb, self.fa = min(MAXF, max(0.0, fb)), min(MAXF, max(0.0, fa)) return fb, fa ``` Screen driver `screen.py` (checkpoints one JSON line per (seed, policy); resumes skipping done pairs): ```python import sys, json, time, os from multiprocessing import Pool H=os.path.dirname(os.path.abspath(__file__)); sys.path[:0]=[H, os.path.join(H,'../dl/T/research/solved')] import replica2 as R from qmref import QMRef from twocomp import TwoComp from combo import Combo B=os.path.join(H,'blob.bin') def run(a): seed,pol=a; t0=time.perf_counter() P={'qt1':QMRef,'tc':TwoComp,'combo':Combo}[pol](B) e=R.run(seed,P)['edge'] return [seed,pol,e,time.perf_counter()-t0,getattr(P,'new_path_calls',None)] if __name__=='__main__': a,b,pols=int(sys.argv[1]),int(sys.argv[2]),sys.argv[3].split(',') out=os.path.join(H,sys.argv[4]); done=set() if os.path.exists(out): for l in open(out): r=json.loads(l); done.add((r[0],r[1])) jobs=[(s,p) for s in range(a,b) for p in pols if (s,p) not in done] t0=time.time() with Pool(int(sys.argv[5])) as pool, open(out,'a') as f: for r in pool.imap_unordered(run,jobs): f.write(json.dumps(r)+'\n'); f.flush() print(len(jobs),time.time()-t0) ``` ## Commands ```bash mkdir -p test/scratch/dl && cd test/scratch/dl git clone https://github.com/gtmcknight/amm-sim T && git -C T checkout 4812a6382311624e1506aca131ca35c378f930d9 for h in ; do curl -sL https://api.imd.fun/artifacts/$h -o $h; done curl -sLO /blob.bin; curl -sLO /qmref.py (cd T/research/solved && python3 -I gates.py) # Gate P # twocomp.py = TC "## Code" python block; PC.json/PR.json = "edges" of the json block in PC/PR cd ../w # combo.py, screen.py, blob.bin, qmref.py python3 -I screen.py 10000 10003 qt1,tc,combo spot.jsonl 9 python3 -I screen.py 60000 61024 tc,combo choose.jsonl 2 # repeated (timeout 470) until complete python3 -I screen.py 60000 61024 qt1 choose.jsonl 2 python3 -I screen.py 10000 12048 tc,combo report.jsonl 2 # repeated until complete python3 -I screen.py 10000 12048 qt1 report.jsonl 2 python3 -I s3.py > s2.json # paired stats (both windows checked complete) ``` ## Problems - Replica evidence only: no engine run, no Solidity, no gas or Gate F for COMBO (outside this item). The quote path adds a second paired lookup at ~5,870 callbacks per run on top of TwoComp's filter, whose own gas was only estimated by TC (~239k, not established under the 245k limit); COMBO's gas is likely higher still. - Published PC disagrees with a deterministic recomputation of qt1-ref on 17 of 1024 seeds (see above); scores here pair against my recomputation. - seconds_per_seed are contention-inflated on a 1-CPU cgroup (see Screen). - COMBO worst seeds are worse than TwoComp's (60210: −3.25 vs TwoComp; 10146: −3.54 vs qt1) though the mean gain holds in both windows.