TypeScript, Next.js 16 (App Router, src/), Drizzle + Postgres 16, Vitest +
fast-check, on Node 26 (.node-version, the Dockerfile). The package was a
Python/FastAPI scaffold until 2026-09-23; ignore anything that says otherwise.
It is in production, at https://acceptodds.com, with real users,
real reputation and real mail, served from this host (compose project
acceptodds, .env.production, the repo dir) alongside staging
(acceptodds-staging) and the dev database. Do not disturb production
unless explicitly told to: no deploy, restart, rebuild, docker compose
command against the acceptodds project, migration, seed, script or write
against its database, mail to its users, or change to its env, cron,
Cloudflare or DNS without the owner's explicit go-ahead for that action.
Read-only queries are fine. Try risky changes on staging first. Mind the
compose project and env file in every command: npm run db:seed and the
integration tests wipe whatever database they are pointed at.
-
Two TypeScripts.
tscis TypeScript 7 (@typescript/native), which has no compiler API;typescriptis an alias for@typescript/typescript6, for what imports the API (typescript-eslint,next build's check). Movetypescriptto 7 only once typescript-eslint supports it. -
ESLint stays on 9 until
eslint-config-next'seslint-plugin-reactsupports 10; under 10 it crashes on load. -
Formatting is Prettier (
.prettierrc.json: single quotes, 120 columns). Runnpm run formatafter editing and never hand-format;npm run format:checkis the check. Generated files are in.prettierignore. -
Tests:
npm test(unit + property, no database).npm run test:integrationneeds the dev Postgres up andTEST_DATABASE_URLset; it truncates every table in that database.npm run test:allruns both. -
Dev database:
docker compose -f docker-compose.dev.yml up -d. It publishes on127.0.0.1:55432— never 5432 or 6543, which belong to unrelated Supabase containers on the dev host. -
Migrations: edit
src/db/schema.ts, thennpm run db:generate, thennpm run db:migrate. The generated SQL indrizzle/is checked in and is the thing that actually runs. Never hand-edit an applied migration. Production exists, so only new migrations: never squash, delete or rewrite anything indrizzle/. A migration must run safely against production's live data, and is applied there only on the owner's say.
These came out of a working scaffold and a live research run. They are not style preferences: each one has already been got wrong once. They are repeated as comments where they bind in the code, and as tests where they can be tested.
A holding's mark is shares × price. Closing it pays less, because the
cost function moves against the seller on the way out. engine.quote() is the
only honest answer to "what is this worth", and the only one a trader can get
without committing.
Wherever both numbers appear — portfolio, leaderboard, API response, UI — they must be separate, differently named fields. Never show a mark alone next to a sell button.
A trader marking their own price impact can show a profit while holding only losing positions. This actually happened: a net worth of 1351 from a starting 1000, all of it self-inflicted price impact. Net worth is correct at settlement and meaningless before it. Label it as such in the API, and never rank a leaderboard on it for an open market.
This is about the mark. Net worth at liquidation value — cash plus a
real sell-everything quote per holding (server/valuation.ts) — is not
self-markable: the exit walks back down the curve the buy walked up, and
rounds in the house's favour, so a trader alone in a market can never show a
gain from their own impact. That one may be shown and ranked on.
b is sized from the expected field and the starting balance by
lmsr.liquidityFor(balance, traders, outcomes) — not a global constant. A b
small enough for one trader to pin the price makes the market that trader's
opinion.
But b must never change once trading starts. Recomputing it mid-market
changes the cost function under existing positions and lets a trader extract
reputation from the transition. It is computed once, at creation, stored on the
market row, and read from there forever. (A b that grows with volume is
Othman et al.'s liquidity-sensitive LMSR — a different formula with different
invariants, and out of scope.)
Effects live in orders, positions and ledger_entries. events holds only
what would otherwise leave no trace — above all reads: who looked at which
board, and when. Two rules, both absolute:
eventshas no payload column. Do not add one.- A logging failure must never raise into the caller.
events.log()swallows its own errors.
Reputation (ledger_entries) and real USD costs (usd_costs, model spend and
API bills) live in separate tables with no foreign key between them and no
query that sums across them. They are different kinds of number.
BIGINT columns, Drizzle mode: 'bigint', bigint in TypeScript. 1 unit =
1,000,000 micro. The LMSR cost is irrational by construction, so exactness
inside the maths is unavailable: compute in number, round once, at the
persistence boundary, via src/lib/money.ts. Never float money. Never read a
numeric column into a JS number.
LMSR subsidises a market by at most b · ln(n). That reputation comes from
somewhere: a house account, debited at market creation.
Concretely, every market gets its own maker account — a row in accounts
with is_house, pointed at by markets.maker_account_id:
- at creation the house treasury is debited
b · ln(n)and the maker is credited exactly that, so the maker starts holdingC(0); - every trade moves
costbetween the trader and the maker, so the maker's balance is alwaysC(q); - at settlement the maker pays 1 unit per winning share —
q_winner ≤ C(q)— and its residual is swept back to the treasury.
Every movement is therefore a balanced pair of ledger rows, and the only
place reputation is ever created is wallets.openWallet (§1.8). The sum of all
balances never moves, and the maker can never go negative, which is
b · ln(n) holding in the integers rather than merely in the reals.
tests/integration/engine.concurrency.test.ts asserts all of it.
Money lives in wallets (server/wallets.ts), one per account per venue
(markets.kind), never on accounts. A trade or settlement moves money
only between the trader's and the maker's wallets of that market's
kind, so winnings in one venue are never spent, valued or ranked in
another. Every figure a trader sees — cash, net worth, P&L, rank, the
field curve — is one venue's.
- A trader's wallet in a venue opens on their first trade there, inside
trade()under the trader's account row lock, withstartingBalanceMicro()as asignuprow. Signing up grants nothing. - A maker has one wallet, its market's kind. The treasury has one with
kindnull and subsidises every venue. ledger_entriescarries bothwallet_id(what the balance cache sums) andaccount_id(for per-account reads); a venue's flows are found throughmarket_id→markets.kind.- A venue's leaderboard field is the non-house accounts with a wallet in it: who has traded there.
- The venue is global, and picked in one place: the navbar, beside
the logo (
components/VenueSwitcher), since it scopes everything but the account. A page with no venue of its own (home, leaderboard, portfolio, profile,/people) showscurrentVenue()(server/current-venue.ts: thevenuecookie, elseDEFAULT_MARKET_KIND). A page that has one — a paper, a market, a position,/first-trade(lib/venue.tspageHasVenue) — or a URL naming one (?kind=on the home page, the leaderboard,/welcome) makes it the navbar's withRememberVenue, so the wallet the navbar shows is always the one the page's trade box spends.RememberVenuerefreshes the page when the navbar was drawn in another venue: the root layout is not rendered again on a client navigation. No page has a venue picker of its own; don't add one./portfoliolists every venue but sets back (ui.otherVenue) the rows not in the navbar's, and its summary's venue names switch to that venue (components/SwitchVenue, as the navbar does): a link, not a picker. drizzle/0040split pre-existing balances by replaying the ledger: each row went to its market's venue, rows with no market to the venue of the account's first order, every further venue got its own grant, and a venue that would start negative was topped up to zero (adjustment).
The platform knows nothing about papers. No corpus, no scraper, no arXiv,
no OpenReview. A market is a question, outcomes, an id and a
resolution rule. If a change needs to know what is being traded, it belongs
in ../research, which is just another API client.
One exception, on the owner's call: a listing's market is opened on
demand (below), from its venue (src/venues/, one file per listing
kind: the market's question, contract, outcomes with their colours and
fallback prices, JEV's instructions, and every word the site uses for it —
the home title and abstract, the running head, the headline's name, the
share line), at prices from one JEV call (server/jev.ts) or, for a
venue that asks JEV nothing (jev: null), at its own openingPrices.
server/market-templates.ts turns a venue into what the engine and JEV
take. The venue files and those two are the only ones that know what a
listing is; everything else reads the venue's words by kind and never
branches on a kind's name. JEV is the only model the platform calls. Keep
it that way. To add a venue, copy a venue file, register it in
venues/index.ts and run npm test (tests/unit/venues.test.ts). Its
outcome colours must be what the bar draws by position (paletteSlot);
the UI does not read them yet, and the test says so. A kind with no venue
falls back to the conference wording (runningHead, @ <kind>?) and
the plain headline name.
The venue never goes looking for outcomes either: settlement is an
authenticated admin call made by ../research when it observes a decision.
Listings are opaque subjects. listings holds a title, a summary, a
tldr, names with opaque authorIds (one each, or none), keywords, a
primaryArea, labelled http(s) links and an opaque kind, all supplied whole by
../research (POST /listings, an admin upsert by slug) and never fetched,
checked or interpreted here. A market may belong to one (listing_id); its
listing_rank orders them, and rank 0 is the listing's main market. No
money lives on a listing, and it is written by server/listings.ts in its
own transaction, never by the engine. Only the UI calls a listing a paper.
src/server/engine.ts is the only module that writes market state.
Everything else reads.
The trade() transaction is the whole correctness story of this app:
BEGIN
SELECT * FROM markets WHERE id = $1 FOR UPDATE -- serializes this market only
check status = 'open' and now() < closes_at
read the share vector INSIDE the lock
cost = costToTrade(...) -- recomputed under the lock
if cost > maxCostMicro -> abort, slippage
check balance >= cost
UPDATE outcomes, INSERT orders, INSERT ledger_entries,
UPDATE wallets.balance_micro, UPSERT positions
COMMIT
FOR UPDATEon the market row is what makes concurrent trades correct. Without it two traders read the same share vector and both get the pre-trade price. Different markets still run in parallel.- Re-pricing under the lock plus
maxCostMicrois slippage protection. It falls out of the locking you already need. Do not build a second mechanism. idempotencyKeyis enforced by a unique index inside the transaction; on conflict, return the original fill rather than erroring. Bots retry.- Selling is a trade with negative
shares. There is no separate code path, and adding one would be a bug. - Settlement pays 1 unit per share of the winning outcome and 0 otherwise, and must be idempotent — it will be run twice eventually.
balance_micro on wallets is a cache of sum(ledger_entries.delta_micro)
over the wallet. Write both in the same transaction, always (creditWallet).
Each of these came up while implementing §3–§9 and is load-bearing.
- No naked shorts. A trader may only sell shares they hold. The plan is
silent, and it is not cosmetic: an unbacked short takes the proceeds now and
owes 1 unit per share at settlement, which is exactly how an account reaches
a negative balance and how the maker ends up unable to pay. Keeping every
q_i ≥ 0is also what keeps the maker's balanceC(q) ≥ b·ln(n) > 0. - A market may open at a prior (
openingPricesonPOST /markets,createMarket). The share vector then starts atlmsr.openingShares(q0_i = b·ln(p_i/p_min): non-negative, the rarest outcome at 0), stored both asoutcomes.shares_microand, unchanging, asoutcomes.opening_shares_micro. The maker therefore still holdsC(q)and everyq_i ≥ 0; it starts atC(q0) = b·ln(1/p_min)rather thanb·ln(n), which is what the house is debited. Traders hold none ofq0, so settlement pays only what was traded. The share vector is the opening vector plus the sum of the order shares: any replay from the fills starts fromopening_shares_micro(views.priceHistory,views.sparklines,follows.moves), never from zeros.bis unchanged by a prior (§1.3). - Costs round in the house's favour, by
Math.ceilinlib/money.ts— which rounds a buy up and a sell's proceeds down with one rule. The sub-micro-unit remainder therefore accrues to the venue, an integer round trip can never profit, andb·ln(n)binds in integers. eventscarries no foreign keys. An FK onmarket_idmakes every log insert take aFOR KEY SHARElock on the very market row a trade is holdingFOR UPDATE. That deadlocked the engine against its own log during the concurrency test. The log is not a source of truth; it does not get to block one. For the same reason the engine logs after the commit, never inside the transaction.orders.created_atdefaults toclock_timestamp(), notnow().now()is the transaction start time, and a trade that queued on the market row lock started before the trade that beat it to the lock — so a tape ordered bynow()can be in an order the prices were never in.usd_costs.amount_usd_microisBIGINTmicro-USD, not anumericcalledamount_usd. Real money is an integer for the same reason play money is (§1.6).- Lock order is market, then trader account. Always the same order, so
concurrent trades cannot deadlock.
settle()takes position and account rows ordered by account id for the same reason. - Read Postgres error codes through
db/errors.ts. Drizzle wraps a failed query in aDrizzleQueryErrorwhosecauseholds the SQLSTATE;err.codeon the wrapper is undefined. The engine's idempotency race check once looked only at the top level, so a retry racing its original on a different market (different row locks, so only the unique index can catch it) came back as a 500 instead of the original fill.isUniqueViolation()walks the cause chain; use it, nevererr.code === '23505'.
src/server/api/schemas.tsis the contract. One Zod schema per boundary, used to parse requests, to validate every response on the way out (respond()turns a mismatch into a 500 rather than a surprise in a client), and to generate/api/v1/openapi.json. An endpoint added underapp/api/v1must be added toserver/api/openapi.ts; a test fails otherwise.- Route handlers never write. They read through
server/views.tsand write only by calling the engine. Route files underapp/api/v1only re-export handlers fromserver/api/handlers.ts. - Amounts on the wire are
…Microdecimal strings. Money and share counts go out as strings so no client parses them into a float (§1.6); requests accept a string or a safe JSON integer. The order body is therefore{ outcomeId, sharesMicro, maxCostMicro }, not the plan'sshares: one unit convention per body, the same as everywhere else. - Error codes are a public contract.
server/api/errors.tslists them; renaming one breaks bots. Engine codes map onto HTTP statuses there. - Scopes do not imply each other.
readguards/me*,tradeguardsPOST …/orders,adminguards create/close/settle. An admin bot that also trades carries both. Public endpoints need no scope — but a token that is sent must be valid (401 otherwise, never a silent downgrade to anonymous), and it is counted against its rate-limit bucket and attributed inevents. - Request → account resolution lives only in
server/auth.ts. A bearer API key or the Better Auth session cookie; both resolve to oneaccountsrow. Token management (/me/tokens*) is session-only (requireSession) so a leaked token cannot mint its successor or hide its revocation. - A reused
Idempotency-Keyfor a different order is a 409idempotency_key_reused. The engine returns the original fill for any reused key; answering "filled" to a request for a different order would tell the client an order went through that never did. Same order → the original fill,201,replayed: true, headerIdempotent-Replayed: true. - Settling with a different winner after settlement is a 409
market_already_settled.engine.settleis a silent no-op on a settled market; the handler re-reads the market and refuses rather than answer 200 to a settlement that did not happen. Repeating the same settlement is a 200. - The rate limit is a token bucket per credential in
rate_limit_buckets(key = token:<id>), updated in a short transaction of its own withSELECT … FOR UPDATE, on Postgres's clock. It has no foreign keys, likeevents, so it can never take a lock on a row anything else holds. Every token-authenticated request costs one unit, reads included. Anonymous traffic is the edge's job (§11) and is not limited in-app. A credential with theadminscope has a larger bucket of its own (API_ADMIN_RATE_LIMIT_*, 600 and 50/s by default), for../research's bulk writes; only an operator can mint one. GET /versionreportsGIT_COMMIT, the build arg that also tags the prod image (docker-compose.prod.yml's deploy steps export it): the Docker context has no.git, so a build without it reportscommit: null(outside production it falls back to the checkout)./agent/starttells agents to compare it between sessions to notice a redeploy.- Client IP is read only by
clientIp()inserver/api/http.ts, fromCf-Connecting-Ip. An ESLint rule rejects the header names anywhere else. Nothing is keyed on it yet. - The leaderboard is one venue's (
?kind=, defaultDEFAULT_MARKET_KIND; the page's default is the navbar's,currentVenue()), ranked on that venue's wallets and markets alone (§1.8). - The leaderboard has two bases,
?basis=settled_pnl|net_worth.settled_pnl(the API default, so existing bots see no change) istrade+settlementledger rows on settled markets: exact, and immune to self-marking because a settled market has nothing left to mark.net_worth(the UI default) ranks every non-house trader on liquidation value (§1.2's note), valued in one batch byvaluation.valuations()with the engine's own maths and rounding. Both bases build the whole ranked field (views.leaderboardStandings), then sort and cursor-slice it in JS — fine for the field size; snapshot it if that changes. Every entry carries both, plus unrealized P&L (holdings' exit value +traderows on unsettled markets). Mark-based net worth is never ranked. House accounts (treasury and makers) are excluded, as they are from public profiles. - Price history is replayed from the fills, not sampled:
ordersstores only the traded outcome's price, and LMSR prices are a function of the share vector, which is the running sum of order shares. - Cursors carry Postgres timestamps as text, at microsecond precision. A
JS
Datehas milliseconds; two fills in one millisecond would make a page boundary skip or repeat a row. - Market list filter is
kind, notvenue. There is no venue column and adding one would start to answer §12 Q1;kindis already the opaque grouping string. Drafts are hidden from the list unless asked for. - Search is Postgres full text,
?q=on/listingsand/markets. Each listing and market is its own weighted document (listing: title A, authors B, summary C; market: question A, description C), built by the immutable SQL functions indrizzle/0003_search_functions.sqlinto stored generatedsearch_vectorcolumns with GIN indexes (drizzle/0006). The columns are not inschema.ts, so no row read through Drizzle carries one; refer to them only throughviews.ts'slistingVector/marketVector. They were expression indexes until #12: ranking, and rechecking a lossy GIN match, rebuilt the vector per matching row — 5 s for a query matching 30k papers. Changing a document is a new migration replacing the function and re-adding the column. A listing's or market's rank is the best of its documents, computed in one pass (group byover the hits), never by a correlated subquery per row. The query iswebsearch_to_tsquery('english', q), OR-ed with a last-word prefix query (lib/search.ts) unless quotes,ORor-wordare used, and is always a bound parameter. A listing matches on its text or any visible market's; a market on its text or its listing's. Ranked byts_rank_cd(best of the documents), ties by id, paged with a(rank, id)cursor that time cursors can't be swapped for. Blankqis ignored; over 200 chars is a 400.
- API tokens are Better Auth
apiKey-plugin keys (@better-auth/api-key), not the M4 hand-rolledapi_tokenstable, which is gone. Format is stillpm_live_+ 32 random bytes (a custom key generator). The plugin stores the SHA-256 and looks a presented key up by that hash, so there is no prefix lookup or byte comparison to time; that replaces §7's "look up by prefix, compare in constant time". Scopes live in the plugin'spermissionsas{ api: [...] }and are checked byserver/auth.ts, so a missing scope is a 403, not the plugin's 401. The plugin's own/api/auth/api-key/*routes are indisabledPaths: keys are managed only through/me/tokens, which calls the plugin server-side. Open,/api-key/updatere-enabled revoked keys. - Bots have a Better Auth user, login-less. The plugin keys every token on
a
user, which contradicts §8's "bots have no user_id". A bot gets a user the first time it is issued a token: email<handle>@bots.papermarket.invalid(reserved TLD, never mailed), no credential, no linked provider — nothing can sign in as it.is_botis still what marks a bot. - One rate limiter. The plugin's own per-key limiter is disabled; the M4
token bucket keys on
apikey:<id>oruser:<id>(sessions). - Sessions may
readandtrade;adminonly viaADMIN_EMAILS. The owner asked for the simplest possible admin model: a signed-in user whose email is in the comma-separatedADMIN_EMAILSenv var also getsadmin. No role column, no admin UI; change the list and restart.POST /me/tokensstill mints onlyread/trade; admin tokens come fromnpm run token:mint. People make and revoke their own keys under "API keys" on/profile(profile/ApiKeys.tsx), which shows the secret once and never lists revoked keys. - Cookie-authenticated writes must carry our Origin.
SameSite=Laxalready stops a cross-site POST carrying the cookie;assertSameOrigininserver/auth.tsis the second lock and does not depend on the browser. Better Auth's own origin check turns itself off whenNODE_ENV=test; it is pinned on (advanced.disableOriginCheck: false) so the tests exercise what production runs. - Trading is gated at the API layer, by
requireTradingEligibility(): verified oris_bot, else403 not_verified. Not inengine.trade(), which takes an account id and trusts its caller about who that is. M6's Server Actions must call it too. - Institutional verification is an email-domain allowlist, for now.
config/institution-domains.json(INSTITUTION_DOMAINS_PATHoverrides) maps a domain to an institution name; subdomains match; matching never goes below two labels. Sign-up from any other domain is refused in Better Auth'suser.create.beforehook, before a user row exists or a mail is sent. An address with a+tagis refused everywhere the list is checked (institutionForEmail,lib/email-address.ts), on the owner's call: most servers deliver every tag to one inbox, so they would let one person confirm any number of funded accounts. The forms say so before sending. Confirming the address is the verification. This replaces §8's institutional code + ROR lookup, and ORCID sign-in is deferred too; both were built and then removed on the owner's call (git history has them). The list is generated, permissively on the owner's call (~55k domains):npm run institutions:buildmerges swot, ROR (every type butcompany) and Hipo'sedu/acdomains, dropping public suffixes and free mail, plusconfig/institution-domains.curated.json(research companies, gaps,exclude), which wins. Edit the curated file and rebuild; never the generated one. Sign-up shows a count, not the names. - The refusal is a 422
EMAIL_DOMAIN_NOT_ALLOWED, not a 403. Better Auth answers a 403 from user creation with a fake success (its guard against email enumeration), so the person would wait for a mail that never comes. The list is not secret, so saying no plainly leaks nothing. - Email changes are off (
user.changeEmail.enabled: false): a changed address would bypass the allowlist. - No account, and no reputation, before the email is confirmed.
ensureAccountForUser()creates the trader row and the primary affiliation (below) together — no money: that comes with the first trade in each venue (§1.8) — from Better Auth'semailVerification.afterEmailVerification, and again lazily on every session request (whichserver/auth.tsonly accepts for a confirmed email), so a failed callback costs a retry and never leaves a signed-in user without a trader. The unique index onaccounts.user_iddecides a race, so there is exactly one trader. A domain dropped from the list between sign-up and confirmation gets a funded account that is not verified and cannot trade — until it confirms another address. - An account may have several affiliations, each confirmed by its own
mail (
affiliations, written only byserver/affiliations.ts). The sign-up address is the primary one, confirmed with the account and never removable. More are added at/profile(/me/affiliations*, session-only like tokens: they decide who may trade): only allowlisted domains, re-checked at confirmation; a hashed 6-digit code, an hour, five wrong guesses, re-adding rotates it; at most 5 pending; every add spends one of 10 mails a day from the account's own bucket (affiliation-mail:<id>), without which re-adding is unlimited guessing at someone else's code. A confirmed address belongs to one account (partial unique index; the first to confirm wins,409 affiliation_taken). Adding an address another account has confirmed answers like a free one and mails its owner a note with no code, so nobody learns which addresses have accounts. Signing up with an address another account has confirmed gives an unverified account: one address vouches for one account.accounts.institutions(distinct names, primary's first) andaccounts.verified_at(earliest confirmation, null when none is left) are caches of the confirmed rows, rewritten bysyncAccountin the same transaction with the account row locked first, and every change bumps the standings cache.email_verifiedon Better Auth'suseris still only the login address. - Three pages, one per step:
/welcome,/signin,/verify-email./welcomeis the only sign-up page (below; a paper'sJevPricealso takes an email and its code in place, under "Markets opened on demand");/signinis for people who have an account ("Email me a sign-in link" first, which also makes an account for a new address and says so; the password only after "Use a password")./verify-emailis the one page after an email: every mail's link lands on it and every code is typed on it, and what it shows follows from the session, never from how the person got there. Signed in with nothing owed: on tonext. Signed in and owing a name, a password or a waiting bet:Finishasks for what is missing, places the bet, goes on — except that with no bet and anextasking for JEV's price (asksJevPrice) it goes straight on, the name left to the banner and the password to the next sign-in link. No session and?email=:CodeForm, the 6-digit code (confirming signs in and refreshes the page into the case above). No session and no address: a link opened twice, so/signin?error=. Nothing else asks for a name or password after an email; don't add a second page that does. - Confirming is a link or a 6-digit code, never a dead end (#15). One
mail carries both (
sendVerificationEmailmints the code with the email-OTP plugin's server-onlycreateVerificationOTP, hashed, rotated on every send, an hour like the link).POST /email-otp/verify-emailruns the samebeforeEmailVerification/afterEmailVerificationas the link and signs in. Every other email-OTP route is indisabledPaths— sign-in by code would also sign up past the password, and password codes are not used — so the only code there is is the confirmation one, and the only resend is/send-verification-email. Signing in unconfirmed with the right password (only a user from before sign-up stopped taking passwords has one) resends (sendOnSignIn) and goes to/verify-email. Sign-in and the mail's link return to the page the person came from (?next=,callbackURL), only ever a same-site path (lib/return-to.ts), by way of/verify-email. A viewer already signed in never sees/signin: they go straight tonext, or to/profilewhen there is none. - A broken or used mail link ends on
/signin, saying why. Better Auth sends a dead confirmation or sign-in link back to its return address with?error=(INVALID_TOKEN,TOKEN_EXPIRED, …), and one opened a second time back with no error and no session./verify-email, the return address, passes either on to/signin?error=(LINK_USEDfor the second);/signinshowslib/link-errors.ts's sentence (never the raw code) above the form, and skips its first-visit detour to/welcomeso the message survives a fresh browser. While a code is outstanding a banner follows them round the site, from this browser'slocalStorageonly (lib/pending-confirmation.ts); it grants nothing. There is still no user session, account or reputation before confirmation. - Sign-up takes no password and no name (
POST /onboarding,server/onboarding.ts; there is no other sign-up route): an email, with an optionalbetand an optionalnext(checked bysafeReturnTo, the link's and code's way back through/verify-email), makes a user with no credential and mails the confirmation; the name and password come after confirming, at/verify-email. Better Auth's/sign-up/emailis indisabledPaths. Otherwise anyone could sign up with your address and their password and wait for you to confirm it, which Better Auth's own confirmation does not undo. As a second lock,afterEmailVerificationdrops every password and session the user had before the address was proven (revokeUnprovenAccess); it runs before the confirmation's own session is made. Five sign-up mails per address a day (signup-mail:<email>). - Every auth mail spends a per-address budget,
auth-mail:<email>, 10 a day: confirmations and resets. Over it, nothing is sent and the answer is unchanged — a 429 would tell anyone which addresses have accounts, since Better Auth only mails an existing one. It is checked before a code is minted, so it also caps the fresh 3-guess codes anyone can have made for an inbox. - A password reset ends every other session
(
revokeSessionsOnPasswordReset). - A handle never comes from the email (
handleFrom): it is public, and a local part is often a full name. No usable name givestrader-xxxx; the first name an account without one sets (accounts.setDisplayName) replaces that placeholder, once. Until it has a name (Better Auth'suser.nameblank, the viewer'sneedsName), the layout'scomponents/NameBannerasks for one on every page but the sign-in ones, through the profile'sEditNamedialog; dismissed, it stays away from that browser for a week. - Sign-in links (Better Auth's
magicLinkplugin):/signinoffers "Email me a sign-in link" for the address typed, before any password field (hidden until "Use a password", then under it). The allowlist and a per-address budget (magic-link-mail:<email>, 5 a day) are checked insendMagicLink, before any mail, so an unlisted address is a 422 on the page, never a dead link; otherwise the answer is the same whether or not the address has an account. A link works once, an hour. Every sign-in and confirmation mail links to/signin/link, never to Better Auth's/magic-link/verifyor/verify-email(links.mailLinkUrl,?to=naming which): the first spends its token on a GET and the second confirms and signs in whoever opens it, and institutional mail scanners open every link before the person does, so a direct link was "already used" when clicked. The page is a button, a GET form to that route, which scanners don't submit. A reset link stays Better Auth's: its GET only checks the token, and/set-passwordspends it by POST. Opened, it signs in — and for an address with no user, makes one, confirmed (the link proves the inbox), with no name and no password; the trader account follows lazily as for any session. Every link lands on/verify-email(authHref(VERIFY_EMAIL, next), errors too), which asks for whatmissingFromUsersays is missing, as above. The name isPATCH /me { displayName }(accounts.setDisplayName: the account's display name and Better Auth'suser.nametogether, then the standings cache is bumped); the handle never changes. - Choosing or resetting a password is its own flow, apart from the
above: an account with no password (onboarding makes them) that asks for
a reset (
requestPasswordReset, from/signin's "Forgot your password?", under the password field, or/set-password's "send a new link") gets a Better Auth reset link — one use, an hour, to/set-password(lib/links.tssetPasswordPath), which sets the password with the token (Better Auth creates the missing credential) and signs in.sendResetPasswordwords its mail by whether a password exists. The token decides whose password is set, not the URL: the page names that account (resetTokenEmail, read without consuming the token) and signs in as it;?email=is only a hint for resending. Someone signed in as a different account is warned, by address, that they will be switched to the link's account. - Better Auth's client IP header is
Cf-Connecting-Ip(advanced.ipAddress), via the exportedCLIENT_IP_HEADER; its default isX-Forwarded-For. Its sign-in rate limiter uses in-memory storage, which is correct for the single app container in §11 and wrong for more than one. db/auth-schema.tsis generated bynpm run auth:generate(theauthCLI, readingauth.config.ts). Don't hand-edit it; regenerate after changing plugins, thennpm run db:generate. Its timestamps aretimestampwithout time zone because that is what the CLI emits.drizzle-kit generateprompts "create or rename?" whenever a migration drops one table and creates another, and refuses without a TTY. Run it under a pseudo-terminal (script -qfc) and answer "create".- Mail without
RESEND_API_KEYgoes to an in-process outbox and the server log, outside production; in production a missing key throws. - Every mail is written once, as blocks, and rendered twice
(
lib/mail-html.tsrenderMail): a plain part and an HTML part set like a paper (running head, centred title, a code between booktabs rules, booktabs tables with "Table N.", notes under a footnote rule), inline styles only, colours copied from the tokens. Account mails arelib/auth-mails.ts. Text-only, our long auth links were wrapped at a hyphen and cut (/verify-, now redirected to/verify-email), soMail.htmlis required: never send one without it.
- Style is mockup J, "arXiv digest": every page should read like a
research paper. When designing something new, ask how a paper would set
it (title block, author line, abstract, numbered sections, booktabs
tables, captioned figures) and borrow that before inventing a widget.
Serif for reading, monospace for numbers, one maroon accent. No component library. No invented ids or
numbers on screen: everything shown comes from the database. Reputation
is shown as
1,000.00 $rep(#21): write the unit asREPfromlib/format.ts, never the literal. The API is unchanged (…Micro). Tables are booktabs (ui.table/th/td: heavy top and bottom rules, a light one under the header, nothing vertical or between rows; a body row highlights on hover) with a<caption className={ui.tableCaption}>"Table N." above, and what a column means inTableNotesunder it, keyed by an italic letter on the heading (ui.mark) — never atitletooltip; charts get aui.caption"Figure N." below. Numbered by hand per page, tables and figures separately. - Styling is Tailwind v4, utilities in the markup. The palette and fonts
are
@themetokens inapp/globals.css(text-muted,border-rule,font-mono, …); use a token, not a raw hex, for any colour that has one. The 720px breakpoint is thenarrow:variant. On a phone a table too wide for the screen scrolls sideways insideui.tableScrollrather than dropping columns; every text field is 16px there (narrow:text-base, built intoui.input), or iOS zooms in when it is focused; charts are drawn at their measured width, never a fixedviewBoxscaled down. Patterns used on more than one page (section labels, buttons, box, inputs, table cells) are class lists incomponents/ui.ts. Each is a complete look: add utilities for properties it doesn't set, never override one it does — Tailwind picks the winner by stylesheet order, not class order — so a variant is a parameter (ui.btn({ ghost: true })). Shared behaviour is a component incomponents/:CopyButton,PaperRow(a paper in a list: the home page's and/welcome's search),DetailsTable(label–value rows as a booktabs table), the paper's furniture —TitleBlock(venue line, title, author line,Abstract; papers, traders and/aboutopen with it),RunningHead(the template's line over a rule at the top of a paper's page: the venue'srunningHead, "Under review as a conference paper at " by default),TableNotes,Equation/EqRef(numbered displays, KaTeX) andReferences/Cite(numbered by hand, like tables) — andPopover(Radix, the primitive shadcn wraps, in our tokens) for anything that floats over the page, andModal(Radix Dialog, likewise) for anything that takes it over — withSheetContentfor one that is a bottom sheet on a phone (the[getting started]tutorial) — andScrollLink(a same-page#idlink that scrolls there slowly, instant under reduced motion) andCodeInput(shadcn'sInputOTPoverinput-otp) for a one-time code: one real input under the boxes, so paste and autofill work (CodeEntrywraps it to confirm an address, with "send a new code";SignUpEmailis the email that starts a sign-up, oversignUp.ts'ssendSignUp) — reuse them rather than hand-roll another. Preflight is on: headings,pandhrhave no default margins, andsvgisdisplay: block. - The UI writes through the public API, not Server Actions. §9 suggests
Server Actions; the trade widget and the comment form
fetch/api/v1instead, so the UI gets the same validation, Origin check, trading gate, idempotency and rate limit as every other client, and §0's "the UI is one client of the API" holds literally. Pages are Server Components that read throughserver/views.tsand render the same JSON shapes the API serves (viaserver/api/present.ts), which the client then keeps live. - Adaptive polling with SWR (§9): active boards/tapes every 5 s,
untraded markets every 15 s; closed boards every 30 s for settlement,
no closed tape polling, and no settled/void board polling. Portfolio every
15 s and comments every 30 s; fills refresh immediately. Initial server
data skips a duplicate mount fetch. Public reads go out with
credentials: 'omit', so they are anonymous and don't spend the viewer's rate-limit bucket; only portfolio and comments are fetched as the viewer. The chart starts from the full server-side history and gains a point each time the tape shows a new fill (the board's prices after a fill are the exact post-fill vector).GET /me/portfolio?marketId=<uuid>filters only holdings and their cost-basis reads: summary and unsettled valuations always cover the whole account. Boards are batch-read and validated byengine.boardFromOutcomes; exit values use the engine's maths and rounding. Viewer resolution, holding inputs and trade flows are memoized per RSC render, never globally or inside a caller's transaction. - Server Components identify the viewer with
viewerFromHeaders()inserver/auth.ts: read-only, no rate limit, no Origin check. Anything that writes goes through the API. - The trade widget sends the quote it showed as
maxCostMicro, with a freshIdempotency-Keyper order (kept across a network-error retry of the same order, replaced when the order changes). So the charged cost is the displayed cost or better, or the order is refused — checked end to end. The form only buys, by stake: the viewer enters what to spend inREP,lmsr.sharesForCostturns it into shares on the polled board, and the quote for those shares is what is shown ("pays N if …") and sent as the bound — the API still takes shares. The viewer's positions are a full-width table under the chart (components/PositionsTable, also/portfolio's, with a paper column: the listing's title, one line, cut bycomponents/PaperName, as in closed positions):Bought @(the average price paid, fromHolding.costBasisMicro: average cost over the fills,lib/cost-basis.ts),Payout(shares, 1 each if it wins) andCurrent value, the exit quote against the basis as % orREP(toggled in the header) — never the mark (§1.1), so it is a little negative right after a buy. Selling is per row, in aSellModal(10/50/100% or a custom amount, capped at the holding), quoted live and bounded like a buy, so nothing unheld can be offered. Both send throughuseOrder(components/orders.ts). A row's Sell shows only for a market insellable(views.tradingMarketIds: open and beforecloses_at, the engine's own test). - The navbar shows where the viewer stands (#17,
components/NavWorth), in the navbar's venue (currentVenue(), §1.8): a tiny bell curve of the net-worth field with a line at the viewer (MiniCurve). Hovering it (tapping, on touch) opens aPopoverbelow with net worth at liquidation value, cash and lifetime P&L (unrealized plus realized), nothing more. No field yet: the net worth figure instead. The curve is the shared field snapshot (#10 section), never a per-viewer valuation of the field; the viewer is placed on it by their own live net worth. Beside it, aprofilelink — on a phone, at the foot of that panel instead, and on a phone the logo drops its wordmark (for every viewer, signed in or not), so the header stays one row. A click pins the panel open; hover only peeks./profileopens withcomponents/TraderHeader, a paper's title block (name as title,@handle, Institutionas the author line, the email, then a one-paragraph abstract of the account), then the share button; the standing, the field curve and the P&L live on the leaderboard and portfolio, and it carries none of them. Sign-out is at the bottom. P&L is colouredtext-up/text-downviaui.pnl. /people/<handle>is a trader's public page: whatGET /accounts/{handle}and the net-worth leaderboard already publish (details, rank, net worth at liquidation value, unrealized and settled P&L), plus the positions the trader made public (#36, below), and nothing more. Never other holdings, closed positions or follows: comments show the author's stake, so a public list of someone's positions would unmask their comments. It opens with the sameTraderHeader, never passed the email or admin flag, then the same Figure 1 with that trader dashed and the viewer shaded, as the leaderboard's?around=draws them, then its own Table 1 of standing. House accounts 404. Every trader's name in a list links there;/profilehas a button to it.- A trader's standing is shareable from
/people/<handle>and/profile: "share" (components/ShareProfile) copies the name, the rank on the net-worth board and a plain-ASCII bar of the share of the field below them (lib/profile-share.ts, rounded down like "ahead of"), then the/people/<handle>link. That page'sopengraph-image.tsx(og.profileImage) draws the same rank and the field snapshot's curve with them on it, shaded below, from the board's own figure. Only what the page already shows; never a mark. Satori lays out a fragment as a row, so a card's body is one column box (og.tsxBODY), never<>. /portfoliolists closed positions (#22,accounts.closedPositions): every outcome the viewer traded and now holds none of, one row over all its fills, newest first, 50 a page. Read fromordersalone — positions move only by fills, so the shares held into settlement are the fills' net, and settlement paid exactly that on the winner. P&L is sells + payout − buys, the ledger's own integers; it is not a mark (§1.1).- "Venue" is the market's
kind. The home page lists the navbar's venue (§1.8) when it has papers, else every venue; its links carry nokind, except?kind=all(every venue), which only a search from the every-venue list carries. The platform still knows nothing about venues: it is a string the creating client chose. Sorts: activity (the default: last fill), odds (thelikelihoodsort: the main market's headline (#11, below), highest first, 1/0 once settled, void last), volume, newest. The venue'sclosingsort is not offered; volume and newest sit, with the status and "following" filters, in a⋯Popovermenu, which shows the active one when not the default. A signed-in viewer sees a Following section above the list: the followed subset of that same list (venue, status, sort) the viewer holds no shares in, 10 a page on its own?fpage=, collapsible, the open state in thehome_following_opencookie so the server renders it as left. Then My positions, the papers the viewer holds shares in (any market of the row), followed or not — a position wins over a follow — 10 a page on?hpage=, cookiehome_positions_open. With either shown, a sort's link first scrolls slowly to All papers, a quarter down the window (ScrollingLink), and the re-sorted page keeps that place. Hidden while searching or with?following=1. "All papers" below is the rest: nothing pinned above is repeated, and the exclusion is in SQL so its pages count right. - Comments are pseudonymous, OpenReview-style. Each shows the author's
alias on the paper ("Reviewer k3xm", "(you)" on the viewer's own), their
current position in that market and a bot badge — no handle, no account
id (
server/comments.ts). The alias (comment_aliases,lib/aliases.ts) is random, made on an account's first comment on a paper, shared by all the paper's markets (an unlisted market is its own scope) and unrelated to its alias on any other paper; onlyserver/comments.tswrites it. Bots are the exception: named (author.bot, display name and handle, linked to/people/<handle>) and mentioned as@handle, on any paper, on the owner's call. Only the operator makes bots, so no person is exposed; the name does tie a bot's stake, and so its position, to it, which is accepted for bots and for nobody else. A person's handle is never a mention. Mentions are stored (comment_mentions, written with the comment in its transaction, never the author) and read back byGET /me/mentions(read,?since=, newest first), so an agent can check what it missed when it starts;/agent/starttells it to. Mention mails read the same rows. Comments from beforedrizzle/0038have none.@k3xmmentions one: a comment'smentionslists the aliases in its body that are commenters on the paper, and the UI highlights only those. A mention mails the reviewer (server/mentions.ts), after the commit and never awaited by the request, so a mail failure cannot fail the post: to the login address, naming both sides by alias only, never to the author, a bot, an unconfirmed address or an account withmention_mail_opt_inoff (PATCH /me { mentionMailOptIn }, on/profile), and at most 10 a day per recipient (mention-mail:<account>), else@k3xmrepeated fills an inbox. Posting needs thetradescope and a trading-eligible account, so every comment has something behind it. The stake is read at display time, so it is empty after settlement.commentshas foreign keys (unlikeevents) because it is written in its own tiny transaction, never inside a trade.comment_backingsis the exception (below): the engine trims it insidetrade(). The stake is rounded down to two significant figures (lib/stake.ts), in the API too: the tape has every fill's exact size and the leaderboard every trader's exact net worth, live, and an exact stake matched against both ties the alias to a handle. Never send it exact. - A fill on a market's page offers a comment box (
TradeComment), in aModalover the redrawn page, never in its flow: "Why Accept?" after a buy, "Why sell …?" after a sell, optional; "Skip" or closing it skips. Never after an account's first trade, which goes to/first-trade. The empty top-level box names the outcomes the viewer holds. Agents are asked the same in/agent/start("Explain your trades"). - Replies nest (#31):
comments.parent_idnames the comment answered, on the same market, at any depth; the UI indents each level. A discussion is never read whole:GET /markets/{id}/commentspages top-level comments only (20 a page in the UI, "Load more") and addsreplies, a flat preview of the trees under them — the first 3 replies to each comment, 3 levels down, one recursive query (comments.previewTree).GET /comments/{id}/replies?after=pages a comment's direct replies after the last one loaded (an id, compared in SQL at microseconds), each with a 2-level preview; more remain whilereplyCountexceeds what is loaded. The relevance sort ranks top-level comments only.totalcounts replies too. - Comment bodies are Markdown with TeX math, stored as raw text and
rendered by
components/Markdown.tsx(react-markdown + remark-gfm + remark-math + rehype-katex; KaTeX's CSS is imported inapp/layout.tsx). No raw HTML (never addrehype-raw), links only to absolute http(s) and mailto (lib/markdown.ts,rel="nofollow noopener noreferrer ugc"), and images become links, except an https.gifonGIF_HOSTS(lib/markdown.ts: giphy, tenor), which renders inline — so a comment can make readers fetch only from those CDNs, never an author's own URL. - Backing: traders put shares they hold behind other people's comments
(
POST/DELETE /comments/{id}/backing,server/backings.ts). No reputation moves; the shares stay inpositions. Rules:- For each (account, outcome), Σ backing ≤ position — across all comments.
Over-allocating is
409 insufficient_stake; your own comment is409 own_comment. Open markets only (statusopen, beforecloses_at), the window in which a position can change. Withdrawing is always allowed. - A backing is inserted in a short transaction holding the backer's
accountsrowFOR UPDATE— the rowtrade()locks second — so a backing and a sell on one account serialize. It takes no market lock, so there is no lock-order inversion. Its FK checks take onlyKEY SHAREon the comment, the (already locked) account and the outcome, which trades update without touching its key. - A sell trims backings LIFO, inside
trade()'s transaction, after the position upsert: newest first (created_at desc, id desc, withclock_timestamp()defaults), whole backings then one partial, until Σ ≤ the new position (lib/backing.tslifoTrim, property-tested). A full sell removes them all; buying back restores nothing. This is the engine's only write outside market state: it is bound to the position, not the market. - Settlement zeroes positions but keeps backings, as a frozen record of who stood behind which argument.
- Displayed value is a mark, a relevance weight — never a sale price
(§1.1): Σ backed shares × current price, rounded once per outcome with
costToMicrolike portfolio marks; after settlement 1 per winning share and 0 otherwise; 0 on a void market. Labelled "backing". Backers are anonymous: a comment shows a count and the viewer's own share (yours), and the list carries the viewer's held/allocated per outcome (viewer,nullwhen anonymous). ?sort=relevanceorders the 200 most recent comments by backing value (ties newest first) as a single page;neweststays keyset-paginated.
- For each (account, outcome), Σ backing ≤ position — across all comments.
Over-allocating is
- The home page lists papers, not markets. One row per listing, read
from its main market (status,
kind, closing date, headline price, sparkline), with volume summed and activity taken over all its markets; a market with no listing is still its own row (views.browseListings). A listing nobody has traded has no main market (BrowseRow.mainnull): it is listed with no bar, sparkline or headline, counts asopen, takes its listing'skind, and every sort puts it after the rows with a market. A listing row opens/papers/<slug>: title, authors, links, a collapsible abstract, its markets, and the selected one (?market=, default the main market) rendered by the sameMarketLiveas/markets/<slug>, from the same loader (markets/[slug]/load.ts)./markets/<slug>of a listed market redirects there. - Likelihood colours are the
accept,accept-soft,reject,reject-softandtoss-uptokens, chosen bylib/likelihood.tsfrom a market's headline (≥ 65% accept, ≤ 35% reject; the result once settled; none when void). Muted on purpose: the maroon accent stays the loud colour. Use the helper's class lists, not the tokens ad hoc. - List sparklines are the headline, replayed from the fills
(
views.sparklines):orders.price_afteris only the traded outcome's price, which is not enough once the headline depends on the whole vector. One bounded query per page reads current vectors and only the recent fills from the same SQL snapshot, subtracts those fills in reverse and reverses the prices. Short tapes include the opening headline (including a prior). Per-market results are cached for 30 s and invalidated after fills. - The home page search box is a plain GET form (
?q=, works without JS). It carries the current venue and status, so a search stays inside them — the result line says where — and sorts byrelevance(listed only while searching) unless another sort is picked; every filter link keepsq, "clear" drops it, and so does the box's own × (components/SearchInputsubmits the emptied form). - "Join traders from" (
components/InstitutionStrip, signed out and not searching): a slow strip of institution names under the home page's title, read fromviews.traderInstitutions, only those with at leastMIN_TRADERS(2) traders, so no one person makes their institution show. Names, never logos: a logo reads as an endorsement the institution never gave. - The logo returns to the last home search (
components/HomeLink): the home page keeps its query string (status, sort,q, pages; akindonly whenall, since a named one is already the navbar's) in this tab'ssessionStorage(RememberHomeSearch), and the logo on any other page links back to it. On the home page itself the logo is the plain/, which clears it.
- An admin's messages sit at the top of the home page (
POST /announcements,admin;DELETE /announcements/{id}; publicGET /announcements?kind=), written only byserver/announcements.ts. Markdown, rendered bycomponents/Markdownlike a comment; for one venue (kind) or, null, every venue; shown untilexpiresAtor deleted, and withsignedInOnlyto signed-in readers only (theGETto a caller with a credential). On the server, so readers without JavaScript see them; a reader's × hides one in that browser only, in theannouncements_dismissedcookie (by id,lib/announcements.ts), which the page reads so a dismissed one is never drawn. No admin UI, as elsewhere.
- The market page's "Stats" section (
markets/[slug]/StatsSection, once traded and while trading,figures.showsStats) is Figure 2, the venue's distribution (components/VenueStanding, the chart alone), when there is a field. Prices only, never a value (§1.1). - "among peers" redraws Figure 2 over the paper's peers
(
venue-field.peerField,lib/peers.ts): its related papers in the service's order, then its nearest by the map's vectors (server/vector-index.ts, shared with the recommended sort), counting only papers in the venue's field (trading, traded main markets), up toPEERS(50), in 10-point bins (PEER_BINS). UnderMIN_PEERS(10) there is no switch. Cached per listing for a minute, like the venue field.
- A trader may make a position public, one at a time, and nothing else
about their positions is ever public.
public_positions(account + outcome, a randomidthat is the link), written only byserver/public-positions.ts, in single statements, never the engine.PUT/DELETE /me/positions/{outcomeId}/public, idempotent,tradescope (notread: it discloses who holds what). Only a position held now can be made public (409 insufficient_shares). - It unmasks the holder's comments on that paper, since a comment's
stake ties it to the position and its alias then ties every other. That is accepted, per position, and the Share
modal (
components/SharePosition) says so before the switch is made. Never make a position public on the trader's behalf, and never list one they did not choose. - One flag: public means a link,
/positions/<id>(page, OG image with@handle holds N <label>under the title), and a row on/people/<handle>(GET /accounts/{handle}/positions,GET /positions/{id}). Private again: the row is deleted and the link 404s; public again is a new link. - Read live, from
orders, like closed positions: the net of the fills is what is held now, or what was held into settlement. Onlyshared_shares_microis stored, so "sold since" shows. Valued by the exit quote while trading and the payout once settled, never the mark (§1.1); P&L is sales + payout + exit − buys.
- A listing's bibliography is supplied, never extracted.
../researchsendsreferences: [{ title, authors?, year?, venue?, url?, slug? }]withPOST /listings, replaced whole like every other field (left out, it is cleared). Stored inlisting_references, written only byserver/listings.tsin the upsert's transaction. slugis matched when read, never by a foreign key, so a reference to a paper listed later links up by itself. "Cited by" is the reverse lookup oncited_slug's index. A listing citing itself is left out both ways.GET /listings/{id}/citationsgives both, each listed entry with its main market; the paper page sets them as back matter, "Cited by" then References (components/Citations), as ICLR sets a bibliography (lib/bibliography.ts,Bibliography): unnumbered, author–year, every author ("A, B, and C"), alphabetical by first surname then year, venue in italics, hanging indent. A listed entry links to its page with its odds in its likelihood colour. Prices, never values.References, the numbered list, stays for pages that cite in the text (Cite).- The feed (papers sharing citations with what a trader follows or holds) is not built yet.
- A listing's related list is supplied, never computed. A separate
similarity service (it embeds papers, maybe on a GPU) sends
PUT /listings/{id}/related(admin),[{ slug, score }]best first, replaced whole. Its own call, apart fromPOST /listings, so the service that embeds and the one that lists never overwrite each other. Stored inlisting_related, written only byserver/listings.ts(setRelated) in its own transaction.scoreis stored and never interpreted; the order is the supplied one. - Slugs are matched when read, as citations' are: an unlisted slug is skipped until it is listed. Self and repeated slugs are dropped at write. Directional: A naming B says nothing about B.
GET /listings/{id}/relatedand the paper page's "Related papers" (components/RelatedPapers, a numbered section just before the Discussion, viaMarketLive'sbeforeDiscussion) show each with its main market's odds, in the service's order, not alphabetical. Prices, never values.- Until a paper has a bet, only its first 3 related papers are given
out (
RELATED_UNBET,lib/related.ts):views.listingRelatedToandGET /listings/{id}/relatedsend those and a count,hidden, of the rest. A bet is a fill on any of the listing's markets; per paper, not per viewer. The page (RelatedPapers) draws the hidden ones as blurred placeholders, never their titles, under what unlocks them: "See more related submissions when the market opens" while the paper has none (a sentence, no button), else "Place a bet ↑" (aScrollLink, an eased scroll up until the trade box's outcome buttons sit in the window's lower third), and no minimap. The map's own reads (/map/related, the minimap, via{ all: true }) are not held back, on the owner's call, and its side panel lists only the first 3 for every paper. With a bet, the first 10 and the rest behind "See more" (components/SeeMore).
-
The layout is supplied, never computed, like related papers. A separate service lays the papers out in 2D and names its coarse
regionsand fineclusters, then sends the whole map withPUT /map(admin), replaced in one transaction (server/map.ts,map_points+map_topics). -
One map per venue, or none (
kindon both tables, as onmarkets).PUT /mapnames itskindand replaces only that venue's map; empty removes it. Every read takes?kind=(defaultDEFAULT_MARKET_KIND); a paper's minimap is its own venue's (views.listingVenue: the listing's kind, else its main market's)./mapis a venue's (?kind=, else?paper='s venue, else the navbar's), set as the navbar's like any page naming a venue, and only exists for a venue inviews.mapKinds: otherwise it redirects to that venue's home page, which is also where the venue switcher lands from it, and the navbar has nomaplink. Vectors are compared only within one map: each venue's are its own service run's (recommendations.tskeeps an index per map). Coordinates are in its own units and nothing here interprets them or the groupings. Slugs are matched when read; an unlisted one is skipped until it is listed. The research side's build and push scripts are in../scraping/tags/map/. -
Each point may carry a
vector: the service's embedding, compressed (PCA to 64 dims, int8-range integers, so a minimap's page stays small), every one the same length. Stored asreal[]onmap_points. Only cosine distances between vectors are ever read (lib/vectors.ts), and only for the minimap, below. A point without one is still on the map. -
GET /map(views.paperMap) is the whole map in one response, by column and without titles: slugs, coordinates, groupings, an index intoareasfor the primary area, and the main market's headline (void:null). Prices, never values (§1.1). The titles areGET /map/titles(views.mapTitles, by slug), fetched once the map is drawn: at 40k papers they are 70% of the bytes, and only hover and selection need them. Both public, withCache-Control: public, max-age=300, stale-while-revalidate=3600and an ETag (304onIf-None-Match). -
The map's public reads are cached in process (
server/map-cache.ts), since Cloudflare bypasses/api/*(§11):GET /map,/map/titles,/map/relatedand/listings/{id}/minimapare validated, serialised and compressed once (http.prepare: brotli and gzip, picked byAccept-EncodinginpreparedResponse; nothing downstream compresses a route handler's body) and served from memory.setMap,setRelatedandupsertListingbump its generation after their commit; headlines bump nothing and are covered by an hour's TTL, on the owner's call (the map changes rarely). Like the standings cache, correct for one app container only. -
The page fetches it anonymously and draws it in WebGL with deck.gl (
components/map/MapCanvas, loaded withssr: false). The display maths (scaling, label placement, colours) islib/map.ts.LIKELIHOOD_RGBcopies the likelihood tokens, the same wayTIER_HEXdoes, so keep them in step. Selecting a paper draws lines toGET /listings/{id}/related, so the map and the paper page always agree on what is related.?paper=<slug>opens the map on that paper, selected and flown to, and the selection is kept in the URL (history.replaceState, no navigation), so it can be shared.paperis on the analytics allowlist: it is a public slug, likemarket. The paper page's minimap links every paper there. -
The map's search is the home page's:
GET /map/search?q=runsviews.mapSearchthrough the samebrowseQueryasbrowseListings(every status unless the query saysstatus:) and returns every match's slug, best first. The map keeps those lit and fades the rest. Topic labels the query's positive words (orkeyword:/area:values) name at a word's start turn vivid blue (the accent was lost over reject's red), larger and with a wider halo (no box, on the owner's call), and show at every zoom, regions and clusters alike, in a layer no collision hides; they still clear their space among the rest (lib/map.tslabelTerms,labelMatches). A client-side string match, not the search.components/SearchSyntaxis the help text for both pages. -
"Redraw" (on by default) hides what a search did not find and lays the matches out again, in the browser — display only: never stored or sent, and the supplied map is untouched.
lib/map-layout.tsis a d3-force layout seeded from the supplied positions, linked by the similarity service's related lists between matches (GET /map/related, each listing's best 10, as index pairs, fetched only once a search needs a redraw) and each match's 6 nearest matches on the map. It runs in a Web Worker (lib/map-layout.worker.ts, one job at a time, a newer search ends the last) and is drawn as it settles. The cost is d3's many-body repulsion (about 0.7 s per 100 ticks at 4k papers, 4.4 s at 15k), so aboveMAX_RELAYOUT(10,000) the matches are shown in place instead. If that cap starts to matter, move the simulation to the GPU (cosmos.gl), not into more CPU tuning. -
The paper page's minimap (
components/map/Minimap, inside "Related papers") is a few papers from the same map around one paper, drawn by the sameMapCanvas. It is lazy: the page only checksviews.onMap; the browser fetchesGET /listings/{id}/minimap(and loads deck.gl and the worker) once the figure nears the window, so a crawler or a reader who never scrolls there costs nothing.views.listingMinimappicks them: the paper, itsMINIMAP_NEAREST(100) nearest papers, and its related papers wherever they lie. "Nearest" is by vector: of itsMINIMAP_CANDIDATES(400) nearest on the map (a k-nearest scan of the GiST indexmap_points_xy_idx; the query'spoint(x, y)must match it), the 100 closest by cosine (by the map alone when the paper has no vector). It sends their vectors (nullunless every paper has one) and the related pairs among them. -
The minimap is redrawn from the vectors, not the 2D map, by default, in the map's worker (
lib/map-layout.tsembedAround): UMAP (umap-js) over the piece alone, as the service builds its own map. The kNN graph is by cosine distance, over few neighbours (7) with a lowminDist(0.02), so the piece breaks into groups rather than one even blob, and every related pair (and the paper's own related papers) counts as near as either end's nearest paper, so it is always an edge: the related lists are the better judge, as they are for the service. It is seeded from the map positions (so it keeps the map's orientation) with a fixed RNG (so a paper always looks the same), then dots are pushed apart, animated from the map and framed round the paper (lib/map.tsframeAround). Without vectors there is no redraw, only "as on the map".What was tried first and failed, all from 2D map positions: a graph layout of the whole piece with repulsion (an even ball), a stress layout of map distances, and groups by label propagation set round the paper as discs (related papers ended up on the far side of their disc). Locally the map is an even spread; the structure is only in the vectors.
- Private pages are one list,
lib/private-paths.ts: disallowed inapp/robots.tsand sentX-Robots-Tag: noindexbynext.config.ts(robots.txt stops a crawl, not an index entry). A new personal or auth page goes there.robots.tsalso closes/api/exceptopenapi.json. sitemap.ts,llms.txtand the paper page's JSON-LD (ScholarlyArticle) read only public data (server/seo.ts), andllms.txtshows no value (§1.1). The sitemap has nolastModified: a listing has noupdated_at.
- A paper's views are unique viewers per day, summed (
listings.view_count,listing_views, written only byserver/view-counter.ts). A visitor is the signed-in account (session or key), else the client's network: its IPv4 address or IPv6 /64 (lib/ip-network.ts, fromclientIp()). Never the user agent: the client chooses it, so with it in one machine was any number of visitors. Anonymous readers behind one NAT count once. Stored is an HMAC of the UTC day and that identity underBETTER_AUTH_SECRET: no address or account id, and the day inside the hash means nobody can be followed from one day to the next. One statement inserts the row and bumps the cache only when the row was new. Only the last two days' rows are kept. Likeevents, no foreign keys and not a source of truth. Cloudflare rate-limits the beacon, 10 per 10 s per IP (a zone rule in the dashboard, and the Free plan's only rate-limit rule). - Counted by a beacon, not on render:
components/ViewCountPOSTs/api/v1/listings/{id}/view(credentials: 'same-origin', one unit of a signed-in viewer's bucket), so a page Cloudflare cached still counts and a crawler without JS does not. Shown on the paper page from 10 views up (below that it still counts), and asviewson the listing. Unlisted markets have no count. - Which paper people read next is a total per ordered pair, nothing
more (
listing_transitions, for the similarity service). The beacon adds?from=<listing id>: the paper this tab showed before, within 30 minutes, kept insessionStorage(document.referreris unchanged by a client-side navigation).countTransitioncounts each (from, to) once per visitor per day, like views, but the dedupe hash (listing_transition_visits, two days) has the pair inside it, so a row joins neither tolisting_viewsnor to the same visitor's other pairs: no one's path can be rebuilt. Never store a sequence, a session id or a timestamp per transition. A bad or unknownfromis ignored and never costs the view. Read whole, with slugs, byGET /transitions?min=(admin); the venue computes nothing from it — blending it into the related lists is the similarity service's job, like the lists themselves.
- Only listings can be followed (
listing_follows, pk account + listing, written byserver/follows.ts, one statement, never the engine). A market with no listing has no star. No money, no market state; following needs a signed-in or token principal withreadand no verification.PUT/DELETE /listings/{id}/followare idempotent and return{ following, followers };GET /me/followsgives each followed listing's main-market headline (#11, below;negatedsays it is1 − P(outcome)) now and 24h ago. Listing responses carry afollowerscount, never who;followingis not on the public listing shape, since public reads are anonymous. - A move is a price, not a value (§1.1): the price 24h ago is replayed
exactly from the fills (share vector = Σ order shares up to the cutoff,
follows.moves()), never sampled or estimated. PATCH /me { digestOptIn }(readscope, like the rest of/me);accounts.digest_opt_indefaults to true.mentionMailOptIn(comment mentions, above) is the only other mail setting.- The digest is a script, not a scheduler:
npm run digest:sendfrom the host cron at 07:00 Europe/Zurich (README). Recipients: non-bot, non-house, confirmed email, opted in, with a followed main market (openorclosed) that moved ≥DIGEST_MIN_MOVE_PP(default 5). At most once per account perDIGEST_TIMEZONEday: thedigest_sendsrow is inserted before the mail, so re-runs and concurrent runs send once; a visible send failure deletes the row for a retry, a crash between insert and send loses that day's mail rather than doubling it. The unsubscribe link is/profile#email, not a signed token.digest.sentis logged after the send, no payload.
recommendedis a home-list sort, not a feed, offered to a signed-in viewer who has traded or hasMIN_INTERACTIONS(2) interactions, and then the default sort (activity for everyone else). Scored papers first, then the rest by activity, so paging and filters still work.server/recommendations.tsgathers the inputs;lib/recommend.tsscores.- What is near the viewer's own papers: each paper they acted on (fills,
comments, backings, follows, read markers, opening a market; weighted by
kind, and by order — the k-th newest interaction ×
RECENCY^k, never by date) votes for its related list, its 20 nearest papers by the map's vectors and its citations both ways. A light diversity damping stops one paper's neighbours filling the top. Papers with no market are scored like any other; that is how an unopened paper is found. - Only the viewer's own acts are read: no other trader's activity enters
the score. Never page views (
listing_viewscannot name anyone, on purpose) and never reading lists (a group's, not a person's). - The vectors are held in memory (
map-cache.ts, dropped bysetMap), a viewer's scores for a minute (ReadCache). Like the other caches, one app process.
A venue is ~30k papers (ICLR's last round). Measured on 30k papers with ~300k fills: a list page is ~25 ms at any sort, a typical search 5–45 ms, and a query matching every paper ~130 ms. It was 0.4 s a list query unpaginated, and 5 s for that search.
- The home list is paged by offset, 50 a page (
?page=), with a total, and so are Following and My positions. Offset, not keyset, because every sort butnewestmoves with each fill and a page number is what the list shows; the API stays keyset. A page past the end serves the last page. The pager is plain links. - The total is its own
count(*), nevercount(*) over (): a window pushes every row of the venue, not the page's 50, through the select list and into a tuplestore, which made the page query 4x slower. A shared (non-personal) list caches one count per filter for all its sorts and pages. The full join reads listings throughlistings_kind_id_idx(kind, id), an index-only scan instead of the 76 MB heap, sodrizzle/0042keepslistingsvacuumed often: view counting dirties its visibility map. Row sums arebigint, since sorting onnumericdoubled a deep page's sort. - Sorts never read
orders. The engine keeps caches onmarkets, written intrade()under the market row lock it already holds (so no new lock and no drift), likebalance_micro:volume_micro(Σ |cost|),order_count,last_trade_at(the fill's own timestamp, to the µs) andheadline(marketHeadline: the headline price, set at creation and per fill; 1/0 by the result at settlement). A void market sorts as having no headline whatever the cache holds, since nothing sets void yet.MarketView.volumeMicro/orderCountread the same caches.npm run db:seedmoveslast_trade_atalong with the fills it back-dates. markets.is_mainis the row. True for a visible standalone market and for a listing's main market (lowest rank, ties by age); never a draft. Set only byengine.createMarket, under a per-listing advisory lock taken before the treasury lock (demoting the old main market locks its row, and markets lock before accounts); the new market'screated_atisclock_timestamp()after that lock, so "ties by age" agrees with the flag. A unique partial index allows one per listing. It never changes after creation: nothing turns a draft visible or moves a rank. Add a path that does, and it must maintain the flag too.- A listing's other markets are summed in through
markets_secondary_idx(not is_main and status <> 'draft'), which holds only those few, so a row's volume and activity stay the whole listing's.
- A paper has one market by default:
Accept, Reject, as its main market (rank 0), opened on demand (below). The platform still attaches no meaning to the labels, and a listing may still carry more markets (the paper page lists them only when there is more than one). - Reject also covers a withdrawal (#19): a paper withdrawn or
desk-rejected before the decision settles as
Reject, never void. That is../research's call when it settles, and the market'scontractsays so to traders (the seed'sDECISION_CONTRACT); the platform still interprets no label. - A market carries a
contract(markets.contract,POST /markets): Markdown saying in detail how it resolves, edge cases included. Opaque, supplied whole by the creating client, shown on the market's page under "Contract" and never interpreted here.descriptionis the market's subtitle, one line under the question, so the question can stay short and the detail sit there; a venue sets it withmarket.subtitle. - Outcomes are ordered best first, worst last, and the headline is
1 − P(last)(lib/headline.ts) — for a paper, accepted in any form. For a binary[YES, NO]market that is exactly P(YES), so binary markets mean what they always did. Everything that summarises a market in one number reads it: likelihood colours, the odds sort (the engine'smarkets.headlinecache, #12; its backfill indrizzle/0006is the same formula in SQL, exponents clamped because Postgres raises onexpover- and underflow), sparklines, follows, the digest, badges and previews. On a listing's market the UI calls it by its venue'sheadlineLabel("accept", "verified"); elsewhere, or for a kind with no venue, it is the first label, or "not ". The map mixes venues and its points carry no kind, so it says "chance". A market with more outcomes that are not ordered will get a meaningless headline: that is the convention's price. - The outcome bar draws prices worst on the left in the
tier-1..4tokens (red, amber, green, blue;TIER_HEXmirrors them for SVG and images — keep the two in step). Two outcomes are red/green. More than four get no bar. - Share surfaces are reads (
server/share.ts), never writes, and show prices, never values (§1.1):/s/<n>— a paper'sshort_idor an unlisted market's — 307s to its page and logsshare.opened(no payload, no account). Every link we hand out is this one (links.shortPath).short_idcomes from one sequence,short_ids, shared bylistingsandmarkets, so a number names one row; all digits is a short id, anything else is still read as a slug (old links, and the badge's/badge/<slug>.svg).opengraph-image.tsxon/papers/[slug]and/markets/[slug](server/og.tsx): the question,<title> @ <kind>?(shareTitleLine, ~120 characters, the ending in the accent; the ending is the venue'sshareSuffix, e.g.verified by 2027?), and the outcome bar with each outcome's price and label centred on its segment, alternately below and above the bar, nudged apart only where a row would still collide (placeLabels); no band, trader count or link (the card already shows the link). Settled: the bar all in the winner's colour, "Decided "; void: an empty bar. Five-minuteCache-Control. Its font isassets/fonts/LiberationSerif-Regular.ttf(OFL), read from disk and named inoutputFileTracingIncludesso standalone output carries it. Latin only: no emoji or arrows in the image./<venue>(ICLR2027,OpenAIMath: the kind without spaces or punctuation, any case,venues.venueSlug) 307s to/?kind=<kind>, which sets the navbar's venue; anything else there is a 404. Itsopengraph-imageis the venue's home card, and the only home card: the home page and/mapname their venue's (share.venuePreviewImages), the root layout the default venue's for every page without its own. Never put anopengraph-imageat the app root: a file-based image overrides the home page'sopenGraph.images, so every venue's home link showed the default venue's card./badge/<slug>.svg(lib/badge.ts): site name, headline, a small bar;?style=compact,?bar=0. Public, five-minute cache, an ETag that changes with each fill. An image, not/api/v1, so not in OpenAPI.- The paper page's share button copies a BibTeX
@miscentry (#33,shareText: keyed by the slug;titleis<title> @ <kind>?,howpublishedthe\url{}link,notethe ten squares while open or closed,year), never with the viewer's stake (#18). The⋯beside it opens a popover with only the badge and its Markdown/HTML copy buttons. It reads the same SWR key asMarketLive, so it adds no polling.
- Page analytics are Umami (
components/Analytics, host-wide instance in~/ops), on only whenUMAMI_URLandUMAMI_WEBSITE_IDare set, counting onlyAPP_URL's host, with Web Vitals on (data-performance, Umami ≥ 3.1). Every hit's URL and referrer, performance ones included, passlib/analytics.ts: same-site URLs keep an allowlist of query parameters (browsing state), never a hash; other sites keep origin and path./verify-email?email=is why. A page that puts anything personal in its URL stays out by default; add a parameter to the list only if it is not. The hook is installed before the script is added, never a bare<script>. Product events go throughtrack()inlib/track.ts(typed names, and data limited to codes and flags: never an email, handle, name, id or amount), for Umami funnels:signup_submitted/refused,signin_*,code_*,finish_shown/completed,order_placed/refused,follow_toggled,share_copied,tutorial_opened/step/finished(the[getting started]sheet: no URL of its own, so no page views; each step counted once per opening; hidden from a viewer who has placed an order,views.hasTraded).?step=and?error=are allowlisted for the same funnels. /privacyis the privacy notice (GDPR Art. 13, Swiss FADP), linked from the foot of the home page. It lists what is stored and who else handles it (Resend, Cloudflare, the self-hosted Umami): a new cookie, mail, processor, log or public field goes there in the same change.SITE_NAME(defaultacceptodds) is the badge's label andog:site_name;APP_URL(elseBETTER_AUTH_URL) is the origin in every absolute link.npm run db:seedwipes every table, then loads submissions fromdata/iclr2027.sqliteunderICLR 2027with no markets, the admin, and a treasury sized to open every listing's market at the worst floored prior.--keep-listingspreserves existing listings, bibliography, related papers, view data and the map, without reading SQLite. All trading and account data is still wiped; no bots or trades are seeded. Only a local database without--allow-remote; a remote one also needsSEED_ADMIN_PASSWORD.
- Except where the venue opens them with its listings
(
opensWithListing, OpenAI Math, on the owner's call):POST /listingsopens the listing's market right after the listing's own commit (market-start.openWithListing, throughensureMainMarketand the engine),created_bynull and nobody following it, at the venue'sopeningPrices (50/50) with no JEV call. Re-posting finds the market it made; a failure is the POST's 500, and the client's retry makes it. Such a listing never shows "Open Market". Everything below is for the other venues. - The venue opens with no markets on its listings. Two calls open
one (
tradescope, trading eligibility; the first also with no credential, for/welcome, below), bothserver/market-start.ts:POST /listings/{id}/market(openListingMarket) opens it at JEV's price with no trade; idempotent (created: false, 200, when it exists). Opening spends a subsidy and a model call, so at most 20 an hour per account (market-open:<account>,OPEN_BUDGET), spent by either call that opens one; asking for an existing one is free. This is the UI's: the paper page'sJevPricebutton, "Open Market", set over the odds figure drawn blurred from placeholders (an even bar,??%; never a price), inviting a look rather than saying nobody has traded; while opening it reads "Opening market…". Signed out, it asks for an email in place, in a box over the figure (SignUpEmail:POST /onboardingwith no bet andnextthe paper with?price=jev,jevPricePath), then the code from the mail (CodeEntry). The code step is remembered in this browser (lib/pending-confirmation.ts,nextthe paper), so while any code is outstanding a paper with no market asks for it, not the button (one record, shared with the banner, which stays off the paper that sent it; a code sent elsewhere confirms by way of/verify-email, back to the paper without opening it). Code or link, confirming signs in and lands on?price=jev(the link by way of/verify-email, which goes straight on), which with a session, and so a confirmed address, opens the market by itself, once. The page, read again, showsMarketLive, whose first-bet box asks for the first trade.POST /listings/{id}/orders { outcome, stakeMicro }(buyOnListing,Idempotency-Key) is a buy by stake on the main market, opening it first if there is none. For bots; the UI does not use it.
- A closed listing opens no market (
listings.closed_at,refuseClosedinmarket-start.ts): either call is409 listing_closed, before any budget, subsidy or model call, andcreateFromTemplatereads the flag again from the database just before it makes one. Set and cleared only bylistings.setClosed, throughPUT/DELETE /listings/{id}/closed(admin), its own call so re-posting a listing keeps it. Opaque:../researchcloses a paper that was withdrawn or desk-rejected (scraper/withdrawals.py), since a market opened then is a bet on a known outcome. It touches no market: that watcher closes the existing one (POST /markets/{id}/close) at once and settles it later. The paper page drops "Open Market" and/welcome's search skips it. - Bots never open a market (
refuseBotinmarket-start.ts): either call on a listing with no market is403 bots_cannot_open_marketsfor anis_botaccount, before any budget, subsidy or model call is spent. Which papers have a market is the humans' choice; a bot trades on one once a person has opened it, through either call. - No price shows before the first trade: a market nobody has traded
(JEV's price only) has no bar or headline on the home list
(
orderCount > 0) or the map (headlinenull), and sorts with the listings that have no market, after every traded row. Except a venue that sets its own opening price (jev: null, OpenAI Math's 50/50):venues.pricedBeforeTrade(andpricedBeforeTradeKindsin the SQL) shows it from the start and sorts it with the traded rows. - The market is the kind's template (
market-templates.ts, fromvenues/:ICLR 2027;OpenAI Math, "independently verified by the end of 2027",Verified/Not verified, open until 2028; andNeurIPS 2026, whose decisions were out before it opened, so it trades citations:Top 25%/Not top 25%of the paper's own track by Semantic Scholar count on 2027-12-01, opening at 25% with no JEV call), slug<listing>-decision, rank 0,created_bythe trader who opened it.created_byis stored, never shown: the tape is anonymous, and "opened by @x" would point at the first fill. Whoever opens it follows the listing (follows.follow, after the commit, best-effort), only on the call that made it, so asking again never undoes an unfollow; a visitor's open follows nothing. Opens from before this are backfilled bynpm run follows:backfill-openers(a dry run without--apply). No template, or past itsclosesAt: refused, and nothing is made. - It opens at JEV's rank, never its number (
jev.ranked). JEV orders papers usefully but its level is not a probability (told the 32% base rate, its median answer is ~80% Accept), and a fixed correction for that drifts with the model and the input. So the answer is placed among JEV's answers to a random sample of the venue's listings (the venue'sjev.reference, per read: full text or abstract; measured bynpm run jev:reference, read-only, and re-measured whenever the instructions, criteria or model change), and that percentile opens the market on a logit-normal with meanJEV_TARGET_MEAN(default 0.28), independently of the venue's prior/fallback, andspreadwide in log-odds (ICLR: 0.5, so 10–90% of papers open between ~16% and ~41%). Its center is solved numerically for the mean; finite reference samples, ties, flooring and the papers people choose can shift the realized mean. Deterministic: the same answer always opens at the same price. Floored if it ever falls belowPRICE_FLOOR(0.05;jev.floored), so one market costs the house at mostb·ln(1/PRICE_FLOOR)(§1.7). NoNANOGPT_API_KEY, a timeout, an error or a malformed answer: the template'sfallbackPrices. The order never fails on the model. Each call'susage.costgoes tousd_costs(source = 'jev', §1.5).JEV_OPENING=offswitches JEV off for every venue (on the owner's call, as fairer for now): no model call, every market opens at its venue'sopeningPrices (ICLR: 32% accept). Unset or anything else asks JEV. The price stays hidden until the first trade either way.OPENING_PRIOR_<VENUE SLUG>(OPENING_PRIOR_ICLR2027=0.30) overrides a two-outcome venue's prior, as its headline, for the fallback,JEV_OPENING=offand the venue's home card (market-templates.openingPrices); betweenPRICE_FLOORand1 − PRICE_FLOOR, else it throws. - JEV reads the full text when
../researchsupplied one (PUT /listings/{id}/text, admin, its own call like related papers, so re-posting a listing keeps it;listing_texts, written bylistings.setText), else the abstract, under the title, area and keywords (jev.paperText). Cut at 120k characters (JEV_MAX_CHARS): measured, 120k (~24k tokens, ~$0.001) is answered and 200k is refused with a 400, on which it asks again with the abstract. - Signed-in readers may read that text too (
GET /listings/{id}/text,readscope, any session or token,views.listingText), on the owner's call, so bots can trade on the paper rather than the abstract. Exactly what../researchsupplied,text: nullwhile there is none: the platform never fetches a paper (Scope boundary). Never anonymous, so the edge cannot be scraped for it; never on the listing's own shape or the page. - A text carries its
source(listing_texts.source, e.g.openreview,arxiv): opaque, supplied with the text on the samePUTand replaced with it (left out, null), returned by theGET. Never interpreted here; which source to trust is../research's call. - By stake, because the first trader has seen no price. Shares are
sized on the board read after the market exists, and the stake is
maxCostMicro, so it never costs more than was put up. A fill landing in between re-sizes it, up to 5 times, thenslippage_exceeded. Slippage is stillengine.trade's; this is only its sizing. - One market per listing, however many first trades race: one creation in flight per listing per process, and across processes the unique slug makes the loser read the winner's market. A balance too small for the stake is refused before anything is made, so a failed first order leaves no untraded market.
- Onboarding can pick a paper with no market:
/welcome's search offers it while its kind's template is open (to a visitor, or a viewer who may trade), and picking it opens the market at JEV's price (POST /listings/{id}/market) before the bet step shows a price, so a pending bet still names a market. Its suggestions ("Most traded") and the tutorial's example still passtraded: true. That call takes no credential for this: a visitor's opens come from one shared bucket,market-open:anonymous(ANONYMOUS_OPEN_BUDGET, 200 a day), withcreated_bynull; a credential that is sent still needstradeand trading eligibility.
[onboard your agent](components/OnboardAgent: under the home page's title, signed in only; "Copy the prompt" on the tutorial's unnumbered agent screen (agentPromptStep,/welcome?step=agent-prompt), reached by "Onboard my agent" on its last step, for anyone;/profile's API keys) copieslib/agent-prompt.ts's prompt, which has the agent ask one thing at a time. Signed in, the prompt carries the login address and a one-time code (POST /me/agent-code, session-only, an hour, a new one each press), which the agent redeems at once, then asks which papers the person finds interesting and how to trade. Signed out, it asks for the email, and while the mailed code (below) is on its way, for the papers and how to trade, then for the code. An agent that already has a key skips the sign-in.- An agent signs in by a code mailed to the person
(
server/agent-codes.ts): it asks for their address,POST /agent/codemails a 6-digit code (allowlisted domains only; 5 mails a day per address), the person reads it out, andPOST /agent/token { email, code }mints aread+tradekey namedai-agent. It needs no account: for a new address the request makes an unconfirmed user (as onboarding does), and redeeming the code confirms the address — the inbox is proven as by a confirmation link, sorevokeUnprovenAccessruns first — and makes the account withensureAccountForUser; still none before that. The answer is the same either way; only the mail's wording differs.agent_codes, written only there: keyed on the Better Auth user, since the code precedes the account; one per user, replaced by each request, 30 minutes, used up on success, gone after 5 wrong guesses, every failure the same422 invalid_code. /agent/startis the agent's instructions: plain Markdown like/llms.txt, only what OpenAPI already says, exit quotes over marks (§1.1). It is linked from/llms.txt./agent/updatesis a hand-written list of dated notices for agents, newest first (UPDATESin its route), which/agent/starttells them to read when they start. Add one when something an agent relies on changes; never edit or reorder old ones.- Every order records how it arrived (
orders.via:webfor a session,apifor a key, null in process;orders.is_llm: the body's optionalisLlm, voluntary and unchecked). Set by the handlers throughengine.OrderOrigin, never read by the engine, not on the tape.
- A rank is always a rank in the field.
leaderboardStandingsranks the whole board (afterinstitution, which ranks one institution among itself); a name search (?q=) then only filters it, so every row keeps its real rank.fieldSizein the API is the denominator. The page's?q=also takesinstitution:x(inst:,i:,-or!=to exclude;lib/trader-query.ts), a case-insensitive substring of any of a trader's institutions — a filter like the name, not?institution='s ranking among itself.is:botkeeps the bots and the viewer's own row (-is:botthe rest). The table's unrealized P/L is a percentage of the starting balance (STARTING_BALANCE_MICRO, the same base for every row, so it reads as a return next to net worth) by default,REPon a click of the heading (components/PnlToggle). The API's?q=is still only a name. Institution is matched exactly against any of a trader'sinstitutions, so a trader with two affiliations is ranked at both. - The page opens compact: the top 10, a "…", the viewer (or
?around=<handle>, where people results link) with 2 either side, and a pager into the whole board (?page=, 50 a page).lib/leaderboard.tsmerges windows that touch and never hides a single row behind "…". The viewer's row is highlighted, with "Top N% of traders" from the half-way line up and "Bottom N%" below it (standingBand, never 0%) — from the share of the others scoring strictly lower, rounded down, so ties never flatter. The people page, its share text and OG image say the same, with no field size. Signed out, the page shows only the top 10 (of the board or of a search), says so with a sign-in link and has no pager; it drops the net worth column and P/L is a blurred placeholder (Blurred), never the figure, a link to sign-in with "Sign in to view" over it on hover. UI only: the API and/people/<handle>still publish them. - People search is
views.searchPeople: substring (ILIKE, LIKE characters escaped) orpg_trgmword similarity (<%), overhandle || ' ' || display_name— written exactly that way, since the trigram GIN index indrizzle/0007is on that expression and it is not inschema.ts. Never house accounts. The home page shows up to 5 people above the papers when the query is only positive words (peopleText). - The home search speaks a syntax (
lib/query.ts, modelled on vvzapi.ch):key:valuefilters (title author keyword area venue status accept volume trades, with aliases),!= > < >= <=on numbers,"quotes",-on a word, filter or group,ORand parentheses. A key that is not a field is text, so "BERT: pre-training" still searches; a bad value drops the term with a visible error. Never throws. Only the home page and the map (GET /map/search, the samebrowseQuery) speak it: the API's?q=on/listingsand/marketsis still plain websearch.- Words in one AND merge into one websearch string, so a stop word
among them is dropped rather than matching nothing, and the last word
stays a prefix.
-(a b)is "not both", so a multi-word text node only negates by wrapping. - The text every match needs (
requiredText: the root's, or a root AND's) drives the GIN-indexed hits join and the relevance rank, exactly as before. Text underORor-is a per-row predicate over the stored vectors (rowMatches), unranked; relevance then falls back to closing date. Text that only excludes means no document in the row matches. venue:orstatus:in a query makes the page's own filter of that kind step aside.acceptcompares the headline cache ×100 (a void market fails every comparison, so a negated one includes it);volumecompares innumericmicro-units, never a float.
- Words in one AND merge into one websearch string, so a stop word
among them is dropped rather than matching nothing, and the last word
stays a prefix.
- The net-worth leaderboard shows the field's shape above the table
(Figure 1, unfiltered
net_worthonly):components/StandingChart, maths inlib/distribution.ts— a Gaussian kernel density of every trader's liquidation net worth (never a mark), and for a signed-in viewer the part below them shaded and a line at their exact figure from the board; the?around=trader, when not the viewer, a dashed line, unshaded. Floats there are for plotting only. On the global board underis:bot, every bot is an open circle on the curve, named on hover. A bot's/people/<handle>asks "Can you beat this bot?" with the viewer's rank against its own. - The ranked field is cached in process (
views.rankedField, per basis, frozen rows — never mutate them): the leaderboard and its API need exact live ranks, so it is invalidated, not aged.server/standings-cache.tsholds a generation thatengine.trade,createMarket,settleandaccounts.createAccountbump after their commit; the cache is keyed by venue and basis; an entry computed under an older generation is never served, including one a commit landed in the middle of. A 30 s TTL covers writers outside the process (the seed). Correct for the single container of §11, like Better Auth's limiter. A new write path that moves a balance, a share vector or who is a trader must bump it. Notledger_entries.created_atas a version: it is not commit order. Both bases share valuations. A bounded change journal refreshes only current holders plus the trader after a fill; settlement refreshes all historical participants, including sold-out traders. Account changes, journal gaps and expiry rebuild the full field. Incremental updates never extend the full valuation's 30 s lifetime. - The curves share one snapshot,
field_snapshots(server/field-snapshot.ts), since the field's shape is the same for everyone: the net worth of every trader who has placed an order, sorted, asBIGINTmicro, and its density at 120 points, peaking at 1. Recomputed at most everyFIELD_SNAPSHOT_MAX_AGE_SECONDS(300), stale-while-revalidate: an old row is served at once and one background refresh starts; only a missing row makes a reader wait. Reads share an in-process copy for at most 5 s, cleared when refresh commits; transactions bypass it. An older computation never overwrites a newer row. A cache, not a source of truth: no foreign keys, and ranks never read it.
-
A group is a board of its own:
/leaderboard?group=<id>, ranked among its members exactly as?institution=ranks an institution (leaderboardStandings({ group }), filtering the cached field; the API takes?group=too, and it combines withinstitution). Either board opens like a paper: its name as the title, its members as the author line (components/Authors, affiliations numbered by first appearance,lib/authors.ts), the description as the abstract, then Figure 1 of the members' net worths (field-snapshot.shapeOf, live, uncached) and Table 1. The title is " leaderboard" ("Global leaderboard"), and the board's name iscomponents/BoardPicker, a find box over the boards (global, the viewer's institutions and groups, and once typed any institution with traders,views.traderInstitutions; never a group the viewer is not in). "+ Create reading group" sits under the search. -
Two institutions can be compared (
/leaderboard/compare?a=&b=, one venue), linked as "Compare institutions" under the leaderboard's search. Each name in its title is aBoardPicker, as the board's is, over every institution with traders. Each side is its board's traders who have placed an order, as an institution's Figure 1 draws them: Figure 1 overlays both densities on one axis and scale (lib/compare.ts, accent andtier-4) with each mean dashed, Table 1 their means and median. Liquidation value, never a mark. Signed out, the figures are held back, as on the board. -
Institutions are derived groups: never a row, always
accounts.institutions, so they cannot drift from the affiliations and nobody joins or leaves one by hand. Lab groups were deferred on the owner's call. -
groupsandgroup_membersare written only byserver/groups.ts, in single statements or short transactions of their own, never by the engine; nothing there moves a balance or a share vector, so the standings cache needs no bump. The maker is the admin (admin_account_id) and the first member. The admin renames, rotates the invite code (the old link dies, members stay), removes members and deletes; the admin can never leave or be removed (409 group_admin) — they delete instead. At mostMAX_GROUPS_PER_ADMIN(20) per admin, checked under the admin's account row lock (409 too_many_groups). Writes need onlyread, like follows. -
A group is public by id, its invite code is not.
GET /groups/{id}lists members (their names and institutions are on the public board anyway);inviteCodeonly to members. The invite link is/groups/join?code=(lib/links.groupInvitePath): in the query, which analytics never records, and joining is the page's POST button, never the GET.groupis deliberately not inANALYTICS_PARAMS. -
A signed-out visitor's invite is remembered, then joined. The invite page's "Sign in / Sign up" stores the code in this browser (
lib/pending-invite.ts, a day) — pressing the button, never opening the link — andcomponents/PendingGroupJoin(in the layout) posts the join once anyone is signed in, wherever sign-in or onboarding ends, and says so in a banner. Another browser (a mail opened on a phone) means the invite page's own button. -
Reading groups have shared reading lists, underneath the leaderboard; institutions do not.
server/reading.tswritesgroup_reading_listonly for current members (membership is locked through the write). Any member may add or remove a listing.listing_readsstores deliberate, global account/listing read markers, independent of page views and group membership. The reading-list table and paper quick actions share a clickable reading-glasses icon; only the group table shows a hover panel, naming readers in that group. Removing a listing confirms through a modal and leaves read markers intact. The paper's "+ Reading list" uses the existing group-creation modal with no groups, adds directly with one, or offers a group chooser with several; existing entries are marked.
- One question at a time, each in
components/OnboardingCard, the step in?step=so back works: a visitor's "Get started" first walks the home page's tutorial in line, one step a page (pick,trade,cash-out, fromtutorialSteps, the same steps as the modal), then which paper (search in one venue, the most traded open ones before anything is typed; with more than one venue open, the choice is under the search bar:?kind=, else the one this browser picked last, on/welcomeor the home page's venue filter, in thevenuecookie, elseDEFAULT_MARKET_KIND), the bet (the market's ownTradeBox), then the email alone, which goes on to/verify-email(the name and the password come there, after confirming). No comment step: it was dropped to keep the way in short. A signed-in viewer's bet goes straight through the API and the flow ends at the paper. What the steps collect is client state; a reload falls back to the search. - A visitor who bets on a market's own page skips the paper and the bet
(#39): its trade box hands the choice to
/welcome?step=emailwith the market, outcome and stake in the URL (lib/onboarding.tswelcomeBetHref), sized against the starting balance. The page re-checks it against the market (open, beforecloses_at, its outcome, within the starting balance) and otherwise falls back to the full flow. The steps is then the email alone; back from it is the market's page. Any market works there, not only a paper's main one. - A visitor's bet is stored, never placed, until they confirm
(
pending_bets, one per Better Auth user,server/onboarding.ts).POST /onboardingmakes a Better Auth user with no credential and mails the usual link and code, landing on/verify-email. Confirming creates the account and grant; there is still no account or reputation before it.Finish(on/verify-email) then places the bet as an ordinary order: the stake is kept, not the share count, sized on the board then and bounded by its quote. ThenDELETE /me/pending-bet, and only then a name (PATCH /me) and a password (POST /me/password, Better Auth's server-onlysetPassword). Another onboarding with the same unconfirmed address may replace it, so it is placed unasked only in the browser that chose it (below). Unconfirmed users are pruned weekly (npm run users:prune, host cron,onboarding.pruneUnconfirmedUsers): never confirmed, a week old, no trader account (bots' login-less users have one) and no pending bet stored within the week. - An unmoved bet is placed without asking (
pending_bets.seen_order_count,seenOrderCountinPOST /onboarding): the market'sorderCounton the board the bet was chosen from. Prices move only by fills, so while it is unchanged the same stake buys the same shares at the price the person saw;Finishplaces it on arrival (checking the count again on the fresh board, once, guarded against a double mount), then asks for the rest. A moved market, or a bet stored before the column (null), is shown at the price now to place or skip. The count is client-supplied, so this is also gated on the browser:POST /onboardingsets anonboarding_browsercookie (HttpOnly, a random nonce, so the form posts withcredentials: 'same-origin') and stores its SHA-256 on the bet (browser_hash). Only wherechoseHerematches is it placed unasked; anywhere else — another device, or a bet someone else planted with your unconfirmed address — it is shown, saying so. - Same answer whether or not the address is taken: a confirmed
address is mailed that it already has an account, with a sign-in link
(the magic link, to
/verify-email) and a code for theCodeFormthe page is showing (better-auth.mailExistingAccount), and the bet is stored for that account, to be placed on arrival: unasked only wherechoseHere, else shown to place or skip, so a bet planted with someone's address is never placed unseen. A new address confirms, thenFinishasks for a name and a password and places it. That code is the confirmation one (createVerificationOTP,email-verification), so/email-otp/verify-emailsigns a confirmed user in with it; it is minted only here and in confirmation mails, never on a client's say (the magic link'smetadatamarker is a per-process secret), andbeforeEmailVerificationrevokes passwords only for an address not yet proven./sign-in/email-otpstays off. Five mails per address a day (signup-mail:<email>), since the route is anonymous. - An account's first trade ends on
/first-trade(Fill.firstTrade): the trade asordershas it (views.firstFill), that market to share (its BibTeX entry, as the paper's share button copies; never the stake) or a group, then on to its paper. It opens with confetti from the sides (components/Confetti, none under reduced motion), and "Continue" is a ghost button until something is copied or shared.useOrdergoes there instead ofonFilled. A sign-up's bet comes first inFinish, before the name and password: placed, the pending bet is dropped and a first trade goes to/first-trade, whose "Continue" goes back to/verify-emailwhile a name or password is still owed. /welcomecomes first, once per browser./signinredirects to it (keeping?next=) until thewelcomedcookie is set, which/welcomesets when shown; its intro links back to sign-in. The cookie is a preference, not a credential, and is notlocalStoragebecause the server has to read it to redirect.
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ (resolved from this file's directory; in monorepos the next package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by next dev — verify at node_modules/next/dist/server/lib/generate-agent-files.js. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
server/market-cache.tsshares boards, market references and tape reads for at most one second in bounded in-process caches. Authentication, rate limiting, response validation and event logging still run on every API request; HTTP responses retainno-store. Creation, fills, close and settlement invalidate after commit. The shared home-list pages (browseReads) are the exception: a market write leaves them at mostBROWSE_STALE_AFTER_WRITE_MS(5 s) to live rather than dropping them, since at a fill or an opening every few seconds dropping them made nearly every home page a miss; a listing upsert still drops them. The tests set it to 0.traderInstitutionsis shared for a minute. Failed reads are not cached, in-flight invalidated reads cannot repopulate entries, and transactions always bypass the cache. These caches assume one app process.