For developers
Architecture
How the on-chain program, the data service and the web app fit together, and how a trade travels through all of them.
On this page
PoffertSwap has four parts. Only the first one is the source of truth. Everything else is built to make it fast and pleasant to use.
| Part | What it is | Where it runs |
|---|---|---|
| The program | The rules: curves, pools, graduation, fees. It holds all the money logic. | On Solana (Rust, built with Anchor) |
| The web app | What you click on. It builds, simulates and sends your transactions, and your wallet signs them. | Cloudflare Pages (React and TypeScript) |
| The data service | Keeps a searchable copy of what happened on chain, serves the API and the live feed, and proxies RPC calls. | A Cloudflare Worker (Rust) |
| Storage | The copy of the data, the pictures and a few caches. | Cloudflare D1, R2 and KV |
The network is the truth. Your balances, every trade and every pool live on Solana. The data service's database is a convenient copy that makes lists, charts and history possible. If the copy is ever wrong or late, the program's real state is unaffected, and a daily check repairs the copy (see below).
The picture#
You ── wallet signs ──┐
▼
Web app ── reads and sends through ──► RPC proxy ──► several Solana RPC providers ──► Solana
▲ │
│ program emits events │
│ ▼
REST API ◄── D1 (indexed copy) ◄── indexer ◄── queue ◄── webhook + minute-by-minute backfill
live feed ◄──────────────────────────────┘
How one trade travels#
- You press Buy. The app builds the transaction from the program's generated client, using the shared math to compute your quote and minimum.
- The app simulates it through the RPC proxy. If the program would refuse, you see the reason and nothing is sent.
- Your wallet signs. The app sends the signed transaction through the proxy, which forwards it to up to three providers at once, and keeps re-sending until it lands or its time runs out.
- The program runs. It checks every account, applies the curve math, moves SOL and tokens, splits the fee and emits an event describing exactly what happened.
- The data service learns about it two ways: a webhook from an RPC provider (fast, usually within seconds), and a job that asks for new transactions every minute (the safety net). Both put the transaction in a queue.
- The indexer decodes it. It reads the program's events from the transaction, verifies they really came from our program, and writes the result to the database in one atomic batch.
- Everyone sees it. The API serves the new state, and the live feed pushes it to every open page, so the trade appears in the list within seconds.
The program#
One program, called poffert, does everything on chain: it creates tokens, runs the bonding curves, runs the pools, migrates curves into pools, and splits fees. Its rules are described on the program page. Two design rules shape it:
- All math lives in one shared library. The program, the data service and the app all use the same formulas, so a quote on screen and the result on chain cannot disagree. See How the curve works.
- Events are emitted through the program itself (a self-call that only the program can make), so they survive even when the network's log output is cut short, and nobody can forge them.
The data service#
One Cloudflare Worker, written in Rust, does several jobs:
| Job | What it does |
|---|---|
| REST API | Tokens, pools, trades, candles, quotes and user data. See API. |
| Live feed | A WebSocket with new trades, prices and tokens. See Live feed. |
| RPC proxy | The only way the app talks to Solana, with failover and limits. See RPC proxy. |
| Ingest | Receives webhooks, runs the minute-by-minute backfill, decodes transactions and writes them to the database. |
| Uploads | Checks and stores token pictures and metadata. See API. |
| Cron jobs | The graduation helper (every minute), price and volume refreshes (every five minutes) and a daily check against the chain. |
The ingest follows a few strict rules that make the data trustworthy:
- Exactly once. Every transaction is recorded in a "seen" table as the first step of its batch. If it arrives twice (the webhook and the backfill both deliver it), the second one fails that first step and changes nothing.
- Order does not matter. Each token and pool row remembers the newest slot it has applied, and older data never overwrites newer data. Candles use the slot and the position inside the transaction to decide which trade opened and closed a bar.
- Missing parents wait. A trade that arrives before its token has been recorded is retried a few seconds later, so nothing is ever stored without its parent.
- Spoofing is rejected. An event only counts when it comes from our program, signed by its event authority.
- A daily check. Once a day, the service compares the recorded reserves of recently active curves and pools with the real accounts on chain and repairs any difference.
- Pruning. One-minute candles older than 30 days and the "seen" records older than 90 days are deleted. Larger candles are kept.
Storage#
| Store | Holds |
|---|---|
| D1 (SQLite database) | Tokens, pools, trades, candles, liquidity events and the "seen" records. |
| R2 (object storage) | Token pictures and metadata files, served from the assets domain with a one-year cache. |
| KV (small key-value store) | The SOL price, notices, and small status values. |
| Queue | The ingest queue between the webhook and the indexer. |
| Durable Object | One object that holds every live-feed connection. |
What is checked by whom#
| Question | Who answers it |
|---|---|
| "Is this trade allowed, and what does it cost?" | The program. Nothing else can override it. |
| "What will I get for this?" | The app computes a quote with the shared math. The program re-checks your minimum on chain. |
| "What happened recently?" | The data service's copy, kept in sync from chain events. |
| "Is a picture or description real?" | Nobody checks. The program only stores the address of a token's metadata. |
For the exact on-chain rules, continue with The program.