asdfxsasd/Sequencer_Selection_Mechanism_Design
1
1<!DOCTYPE html>2<html lang="en">3<head>4<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">5<title>Sequencer Reward Allocation Lab</title>6<style>7body{font-family:Arial,sans-serif;margin:0;background:#f6f7fb;color:#152033} .wrap{max-width:1100px;margin:auto;padding:24px}8.card{background:#fff;border:1px solid #dfe3ea;border-radius:14px;padding:18px;margin-bottom:14px}9h1{margin:4px 0 8px}.muted{color:#667085}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:10px}10.players{display:grid;grid-template-columns:repeat(5,minmax(150px,1fr));gap:10px;overflow:auto}11.player{border:1px solid #dfe3ea;border-radius:10px;padding:10px;background:#fbfcfe}.player.active{border:2px solid #315efb}12label{font-size:12px;color:#667085;display:block;margin-top:6px}input,select{width:100%;padding:8px;border:1px solid #dfe3ea;border-radius:8px}13button{padding:10px 14px;border:0;border-radius:9px;cursor:pointer}.primary{background:#315efb;color:white}.secondary{background:#eef1f6}14.metrics{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}.metric{border:1px solid #dfe3ea;border-radius:10px;padding:10px;background:#fbfcfe}15.metric b{display:block;font-size:20px;margin-top:4px}.eq{font-family:monospace;background:#f8fafc;border:1px solid #dfe3ea;border-radius:9px;padding:10px}16table{width:100%;border-collapse:collapse}th,td{padding:8px;border-bottom:1px solid #dfe3ea;text-align:right}th:first-child,td:first-child{text-align:left}17canvas{width:100%;height:240px;border:1px solid #dfe3ea;border-radius:10px;background:#fff}18.note{border-left:4px solid #315efb;padding-left:10px}19</style>20</head>21<body><div class="wrap">22<div class="card">23<h1>Sequencer Reward Allocation Lab</h1>24<p class="muted">Can adaptive reward allocation prevent cumulative advantage from creating long-run sequencer concentration without materially reducing system efficiency?</p>25<p class="note"><b>Behavior module is open:</b> participants may later be RL agents, LLM agents, or humans. This first study isolates the reward-allocation rule.</p>26</div>27 28<div class="card"><h2>1. Five Participants</h2>29<p class="muted">Each participant starts with a different cumulative reward and sequencing advantage.</p>30<div class="players" id="participantInputs"></div></div>31 32<div class="card"><h2>2. Mechanism</h2>33<div class="grid">34<div><label>Mechanism</label><select id="mechanism"><option value="baseline">Baseline: Winner Takes All</option><option value="adaptive">Adaptive Redistribution</option></select></div>35<div><label>Advantage growth β</label><input id="beta" type="number" step="0.01" min="0" max="2" value="0.08"></div>36<div><label>Adaptive strength κ</label><input id="kappa" type="number" step="0.05" min="0" max="2" value="0.80"></div>37<div><label>Max redistribution αmax</label><input id="amax" type="number" step="0.05" min="0" max="0.9" value="0.50"></div>38<div><label>Redistribution friction ρ</label><input id="rho" type="number" step="0.01" min="0" max="0.5" value="0.03"></div>39<div><label>Random seed</label><input id="seed" type="number" value="206"></div>40</div>41<div class="eq" style="margin-top:12px">42Selection: Pᵢ(t)=Aᵢ(t)/ΣAⱼ(t)<br>43Reward pool: R(t)=Transaction Fees+MEV<br>44Advantage update: Aᵢ(t+1)=Aᵢ(t)+β·rewardᵢ(t)<br>45Adaptive share: α(t)=min(αmax, κ·Gini(cumulative rewards))46</div></div>47 48<div class="card"><h2>3. Run</h2>49<div class="grid">50<div><label>Batch rounds</label><input id="batchRounds" type="number" min="1" max="5000" value="100"></div>51<div style="align-self:end"><button class="primary" id="nextBtn">Next Round</button> <button class="primary" id="runBtn">Run Batch</button> <button class="secondary" id="resetBtn">Reset</button></div>52</div><div id="error" style="color:#b42318;margin-top:8px"></div></div>53 54<div class="grid">55<div class="card"><h2>Current Round</h2><div class="metrics">56<div class="metric">Round<b id="roundOut">0</b></div><div class="metric">Fees<b id="feesOut">—</b></div><div class="metric">MEV<b id="mevOut">—</b></div><div class="metric">Reward Pool<b id="poolOut">—</b></div>57</div><p><b>Selected sequencer:</b> <span id="winnerOut">—</span></p><p><b>Redistribution α:</b> <span id="alphaOut">—</span></p></div>58 59<div class="card"><h2>Observed Outputs</h2><div class="metrics">60<div class="metric">Reward Gini<b id="giniOut">—</b></div><div class="metric">Top Reward Share<b id="topShareOut">—</b></div><div class="metric">Sequencer HHI<b id="hhiOut">—</b></div><div class="metric">Efficiency<b id="effOut">—</b></div>61</div></div></div>62 63<div class="card"><h2>4. Participant State</h2><div style="overflow:auto"><table><thead><tr><th>Participant</th><th>Cumulative Reward</th><th>Advantage</th><th>Selection Probability</th><th>Wins</th></tr></thead><tbody id="stateTable"></tbody></table></div></div>64 65<div class="card"><h2>5. Concentration Over Time</h2><canvas id="chart" width="1050" height="240"></canvas><p class="muted">Reward Gini and top reward share show whether the system becomes more concentrated over time.</p></div>66 67<div class="card"><h2>6. Interpretation</h2>68<p><b>Baseline:</b> selected sequencer gets the full reward pool.</p>69<p><b>Adaptive:</b> when cumulative reward concentration rises, a larger fraction of the current pool is redistributed equally to the other four participants.</p>70<p><b>Efficiency proxy:</b> total transaction value minus a small redistribution friction.</p>71<p class="muted">Static browser-only implementation. No backend, database, API key, secret, paid service, or Hugging Face CPU/GPU runtime.</p>72</div>73</div>74 75<script>76const N=5, defaults=[{r:10,a:1.00},{r:14,a:1.15},{r:8,a:0.90},{r:18,a:1.35},{r:11,a:1.05}];77let state=null,rng=null;78function mulberry32(a){return function(){let t=a+=0x6D2B79F5;t=Math.imul(t^t>>>15,t|1);t^=t+Math.imul(t^t>>>7,t|61);return((t^t>>>14)>>>0)/4294967296}}79const sum=a=>a.reduce((x,y)=>x+y,0), fmt=(x,d=3)=>Number(x).toFixed(d), pct=x=>(100*x).toFixed(1)+"%";80function gini(v){let x=v.map(z=>Math.max(0,z)).sort((a,b)=>a-b),n=x.length,s=sum(x);if(!s)return 0;let w=0;x.forEach((z,i)=>w+=(i+1)*z);return 2*w/(n*s)-(n+1)/n}81function hhi(s){return s.reduce((a,x)=>a+x*x,0)}82function weightedChoice(w){let r=rng()*sum(w);for(let i=0;i<w.length;i++){r-=w[i];if(r<=0)return i}return w.length-1}83function buildInputs(){let b=document.getElementById("participantInputs");defaults.forEach((d,i)=>{let x=document.createElement("div");x.className="player";x.innerHTML=`<b>Participant ${i+1}</b><label>Initial reward</label><input id="r${i}" type="number" min="0" step=".1" value="${d.r}"><label>Initial advantage</label><input id="a${i}" type="number" min=".01" step=".05" value="${d.a}">`;b.appendChild(x)})}84function params(){return{mech:mechanism.value,beta:+beta.value,kappa:+kappa.value,amax:+amax.value,rho:+rho.value,seed:+seed.value}}85function reset(){let p=params(),rewards=[],adv=[];for(let i=0;i<N;i++){let r=+document.getElementById("r"+i).value,a=+document.getElementById("a"+i).value;if(r<0||a<=0){error.textContent="Initial reward must be ≥0 and advantage >0.";return}rewards.push(r);adv.push(a)}state={round:0,rewards,adv,wins:Array(N).fill(0),history:[],gross:0,net:0,last:null};rng=mulberry32(p.seed);error.textContent="";render()}86function oneRound(){let p=params(),probs=state.adv.map(a=>a/sum(state.adv)),winner=weightedChoice(probs),fees=6+8*rng(),mev=2+6*rng(),pool=fees+mev,alpha=0;if(p.mech==="adaptive")alpha=Math.min(p.amax,p.kappa*gini(state.rewards));let alloc=Array(N).fill(0);alloc[winner]=(1-alpha)*pool;if(alpha>0){let each=alpha*pool/(N-1);for(let i=0;i<N;i++)if(i!==winner)alloc[i]=each}state.round++;state.wins[winner]++;for(let i=0;i<N;i++){state.rewards[i]+=alloc[i];state.adv[i]+=p.beta*alloc[i]}let friction=p.rho*alpha*pool;state.gross+=pool;state.net+=pool-friction;let shares=state.rewards.map(x=>x/sum(state.rewards)),winShares=state.wins.map(x=>x/state.round),G=gini(state.rewards),top=Math.max(...shares),H=hhi(winShares),eff=state.net/state.gross;state.last={fees,mev,pool,winner,alpha,G,top,H,eff};state.history.push({round:state.round,gini:G,top});render()}87function render(){document.querySelectorAll(".player").forEach((el,i)=>el.classList.toggle("active",state.last&&state.last.winner===i));roundOut.textContent=state.round;if(state.last){feesOut.textContent=fmt(state.last.fees,2);mevOut.textContent=fmt(state.last.mev,2);poolOut.textContent=fmt(state.last.pool,2);winnerOut.textContent="Participant "+(state.last.winner+1);alphaOut.textContent=pct(state.last.alpha);giniOut.textContent=fmt(state.last.G);topShareOut.textContent=pct(state.last.top);hhiOut.textContent=fmt(state.last.H);effOut.textContent=pct(state.last.eff)}let probs=state.adv.map(a=>a/sum(state.adv));stateTable.innerHTML="";for(let i=0;i<N;i++){let tr=document.createElement("tr");tr.innerHTML=`<td>Participant ${i+1}</td><td>${fmt(state.rewards[i],2)}</td><td>${fmt(state.adv[i],3)}</td><td>${pct(probs[i])}</td><td>${state.wins[i]}</td>`;stateTable.appendChild(tr)}draw()}88function draw(){let c=chart,ctx=c.getContext("2d"),W=c.width,H=c.height,p={l:50,r:20,t:20,b:30};ctx.clearRect(0,0,W,H);ctx.strokeStyle="#dfe3ea";for(let j=0;j<=4;j++){let y=p.t+(H-p.t-p.b)*j/4;ctx.beginPath();ctx.moveTo(p.l,y);ctx.lineTo(W-p.r,y);ctx.stroke()}if(!state.history.length)return;let m=state.history.at(-1).round;function plot(k,col){ctx.strokeStyle=col;ctx.lineWidth=2.5;ctx.beginPath();state.history.forEach((d,i)=>{let x=p.l+(W-p.l-p.r)*(d.round/m),y=p.t+(H-p.t-p.b)*(1-d[k]);i?ctx.lineTo(x,y):ctx.moveTo(x,y)});ctx.stroke()}plot("gini","#315efb");plot("top","#16794a")}89nextBtn.onclick=()=>oneRound();runBtn.onclick=()=>{let n=+batchRounds.value;if(!Number.isInteger(n)||n<1||n>5000){error.textContent="Batch rounds must be 1–5000.";return}for(let i=0;i<n;i++)oneRound()};resetBtn.onclick=reset;90buildInputs();reset();91</script>92</body></html>