nico commited on
Commit
033b658
·
1 Parent(s): 7c735db

Cashout-mid-seat: queued_for_cashout + auto-poll, default to CF gateway URL

Browse files

- topup completes: now defaults CASINO_URL to https://casino-gateway.agentlabel.workers.dev
- cashout: when seated, server returns queued_for_cashout; CLI polls
/api/twitch/cashout/status until settled, prints final withdrawn USDC.
Closes audit finding #9.
- wallet new: unchanged but referenced as the recommended onboarding path.

Files changed (2) hide show
  1. .env-example +3 -1
  2. src/index.ts +16 -1
.env-example CHANGED
@@ -7,7 +7,9 @@ PRIVATE_KEY=0xYourPrivateKeyHere
7
  CASINO_TOKEN=my-agent-secret
8
 
9
  # Required: where the casino is running.
10
- CASINO_URL=http://localhost:8000
 
 
11
 
12
  # Optional: the OpenRouter (or other OpenAI-compatible) model your agent will play as.
13
  MODEL=openai/gpt-5-nano
 
7
  CASINO_TOKEN=my-agent-secret
8
 
9
  # Required: where the casino is running.
10
+ # Public gateway (stable CF Worker → proxies + rate-limits):
11
+ CASINO_URL=https://casino-gateway.agentlabel.workers.dev
12
+ # Local dev: CASINO_URL=http://localhost:8000
13
 
14
  # Optional: the OpenRouter (or other OpenAI-compatible) model your agent will play as.
15
  MODEL=openai/gpt-5-nano
src/index.ts CHANGED
@@ -125,7 +125,22 @@ async function cmdState() {
125
  async function cmdCashout(wallet = CASHOUT_WALLET) {
126
  requireToken();
127
  const r: any = await api("/api/twitch/cashout", { token: TOKEN, wallet });
128
- console.log(chalk.cyan(JSON.stringify(r, null, 2)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
 
131
  async function cmdWalletNew(force = false) {
 
125
  async function cmdCashout(wallet = CASHOUT_WALLET) {
126
  requireToken();
127
  const r: any = await api("/api/twitch/cashout", { token: TOKEN, wallet });
128
+ if (!r.queued_for_cashout) {
129
+ console.log(chalk.green(`✓ withdrawn ${r.withdrawn_usdc} USDC${r.note ? ` (${r.note})` : ""}`));
130
+ return;
131
+ }
132
+ // Seated → poll status until settled or 30s timeout.
133
+ console.log(chalk.yellow(`→ queued (seat ${r.seat}, chips ${r.current_chips}, max ~$${r.estimated_max_usdc})`));
134
+ console.log(chalk.gray(" waiting for current hand to end..."));
135
+ for (let i = 0; i < 60; i++) {
136
+ await new Promise(res => setTimeout(res, 500));
137
+ const s: any = await api(`/api/twitch/cashout/status?token=${encodeURIComponent(TOKEN)}`);
138
+ if (!s.pending && s.last_settled) {
139
+ console.log(chalk.green.bold(`✓ withdrawn ${s.last_settled.withdrawn_usdc} USDC → ${s.last_settled.wallet}`));
140
+ return;
141
+ }
142
+ }
143
+ console.log(chalk.red("⚠ still pending after 30s — re-poll later with: cashout (no args, just to check)"));
144
  }
145
 
146
  async function cmdWalletNew(force = false) {