Architecture

One Next.js app on Vercel, one Postgres database (Neon), and two NEAR Intents services, plus Rhea's DCL contract for meme coins. There is no custom smart contract.

sign in, backup key

signed swaps

quotes, submit

execute_intents

daily cron

Wallet
NEAR or EVM

Browser
basket key in IndexedDB

Next.js API

1Click API

Relayer account

intents.near
one account per position

Price sources

Postgres

PartJob
BrowserHolds the basket key, signs every swap, drives the order step by step
Next.js APIQuotes, builds what the browser must sign, checks signed payloads, tracks orders
1ClickCross-chain deposits, swaps and payouts
Rhea DCL (dclv2.ref-labs.near)Meme coin swaps (HOOT, NEARLY), straight from the position account
intents.nearHolds every position's tokens, one implicit account per position
RelayerA NEAR account that pays gas. Holds no user funds and can't sign for users.
PostgresUsers, bags, positions, orders, prices

A buy, step by step

intents.near1ClickServerBrowserintents.near1ClickServerBrowserloop[each leg]create order (bag, amount, pay token)quote: pay token → USDC into the position accountdeposit addressdeposit (wallet transfer)USDC lands in the position accountpoll, order is fundedfee transfers to signsigned feesrelay, after checking they match exactlyprepare legquote USDC → assetswap payload to signsigned swapsubmit, after checking it matches the quote

A sell runs the same legs in reverse (asset → USDC), then one payout leg from USDC to the buyer's chosen token and address. Sells have no fee step.

Meme coin legs (Rhea)

A leg that touches a meme coin (HOOT, NEARLY or IMEME) skips 1Click:

  1. The server quotes it with the DCL contract's quote view (USDC → wNEAR → meme in one multi-hop, or back), and builds one ft_withdraw intent: the input token to dclv2.ref-labs.near, with a Swap message whose min_output_amount is the quote less 2% and whose client_echo is the position account.
  2. The browser signs that payload with the basket key, as for any leg.
  3. The server checks it (one withdrawal, approved pools, planned token, amount and output, client_echo = signer) and relays it with execute_intents.
  4. intents.near sends the token to Rhea, Rhea swaps and sends the output back to intents.near for the same account. If the minimum isn't met, Rhea refuses and the input is credited back.
  5. The server waits for the transaction to finish and reads the result from its logs (mt_mint to the account), with a balance check as fallback.

Rhea legs run one after another, not in parallel. Meme coin prices are the pool's mid × NEAR/USD, checked against DexScreener and GeckoTerminal; daily history comes from GeckoTerminal. Withdrawing a meme coin is a plain ft_withdraw to the holder's NEAR account.

Order states

awaiting_deposit

funded

refunded

fees_paid

legs_running

complete

partial

failed

Orders are buy, sell, reset or withdraw. Each leg has its own status: pending → quoted → submitted → success | refunded | failed. A refunded or failed leg can be retried. A leg quoted but not submitted for over a minute is quoted again.

A new bag starts as pending and goes live when its creator's own buy completes. Creators can then close it. Admins can hide it.

Signing

  • Basket key
    Format
    raw_ed25519
    For
    Every swap and fee transfer
  • EVM wallet
    Format
    erc191
    For
    Sign-in, adding a backup or device key
  • NEAR wallet
    Format
    nep413
    For
    Same
Who signsFormatFor
Basket keyraw_ed25519Every swap and fee transfer
EVM walleterc191Sign-in, adding a backup or device key
NEAR walletnep413Same

The basket key is either derived from one wallet signature (same key on any device) or random per position when the wallet's signatures can't be reproduced. It is stored in IndexedDB, encrypted with a key the browser won't export.

Database

TableHolds
usersWallet address, chain, handle, profile
baskets, basket_assets, basket_editsBags, their weights, and a log of text edits
positionsOne per user per bag, with its intents.near account id
orders, order_legsEvery buy, sell, reset and withdraw, and each swap inside it
fee_eventsCreator and platform fee transfers
price_daily, price_median, dividendsRaw prices per source, the daily median, dividends
snapshotsDaily bag size and holder count
settings, audit_logAdmin switches and every admin action
auth_noncesOne-time sign-in challenges

API

AreaRoutes
Sign-inauth/nonce, auth/verify, auth/me, auth/logout
Bagsbaskets, baskets/[slug], baskets/[slug]/close, analytics/preview
Ordersorders/preflight, orders, orders/[id], orders/[id]/fees, orders/[id]/legs/[seq]/intent, …/submit, orders/sell, orders/reset, orders/withdraw
Keysrelay/recovery, relay/authorize-device
Portfolioportfolio, portfolio/history, positions
Sharingshare/pnl, og/pnl/[token]
Othereligibility, pay-tokens, stats, profile, admin
Croncron/prices, cron/snapshots

All routes are under /api. Pages: /explore, /b/[slug] (bag), /c/[handle] (creator), /create, /portfolio, /profile, /thesis, /risk, /terms, /admin, /s/[token] (shared P&L).

Code map

PathWhat
src/lib/intents/Keys, payload building, signing, RPC reads
src/lib/trade/Order engine, preflight, price check, portfolio, history
src/lib/oneclick.ts, src/lib/relayer.ts1Click client, gas relayer
src/lib/rhea-core.ts, src/lib/rhea.ts, src/lib/trade/rhea-legs.tsMeme coin legs on Rhea: routes, the intent, the relay allowlist, settlement, quotes
src/lib/prices/, src/lib/analytics/Price ingest, medians, total return, backtests
src/lib/client/Browser key store, wallet sign-in, NEAR wallet payment, order runner
src/lib/share/Share links and card images
src/lib/thesis/Explorer API pull and thesis numbers
src/lib/assets.tsThe approved asset list and each asset's minimum swap size
scripts/Migrations, price ingest, seeding, mainnet checks, thesis