Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AMAZON-DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Written for engineers shipping software that holds other people's assets, and fo

In the tradition of *TCP/IP Illustrated*, the book teaches the layer that does not change. Frameworks churn, but the account model has been stable since Solana launched, the arithmetic of money will not change, and neither will the desire of adversaries to take your assets.

The book assumes no Solana experience, no finance background, and no programming. Solana and finance are built from first principles, with the people and the dollar amounts on the page, and every program is explained in prose and figures, with its Rust in the companion repository.
The book assumes no Solana experience, no finance background, and no programming. Solana and finance are both taught from first principles, with the people and the dollar amounts on the page, and every program is explained in prose and figures, with its Rust in the companion repository.

The tested programs live in a companion repository, where continuous integration keeps them current in a way paper cannot, and a companion AI plugin applies the book's rules inside AI coding tools. An AI can write a Solana program on request. No AI can understand one on your behalf.

Expand Down
2 changes: 1 addition & 1 deletion PRINT-SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Headers and folios are suppressed on the cover, the title page, chapter openers

## Structure

The title page opens on a right-hand page: page one when the book is built without the cover, page three when it is built with it, the blank page between them being the reverse of the cover. A part title opens on a right-hand page, alone in the upper third of an otherwise empty page, and the reverse of that page is left blank so the part's first chapter also opens on a right-hand page. Every chapter opens on a right-hand page too, which is how a reader flipping through finds where one ends and the next begins. Paged.js fills the verso it skips with a blank page, so the rule costs a page whenever the section before ends on a right-hand page: seven before chapters and part titles in the October 5, 2026 build, a count that moves as chapters grow. Front-matter placeholders are exempt, because they share one flow until they have real content.
The title page opens on a right-hand page: page one when the book is built without the cover, page three when it is built with it, the blank page between them being the reverse of the cover. A part title opens on a right-hand page, alone in the upper third of an otherwise empty page, and the reverse of that page is left blank so the part's first chapter also opens on a right-hand page. Every chapter opens on a right-hand page too, which is how a reader flipping through finds where one ends and the next begins. Paged.js fills the verso it skips with a blank page, so the rule costs a page whenever the section before ends on a right-hand page: nine before chapters and part titles in the October 6, 2026 build, a count that moves as chapters grow. Front-matter placeholders are exempt, because they share one flow until they have real content.

The title page and every part and chapter opening are checked against their page numbers after layout, and the build fails naming any that landed on a left-hand page. It prints the number it checked on success, because a selector that stopped matching would otherwise leave a check that passes without testing anything.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The book's home is [solanabook.org](https://solanabook.org), which hosts the pub

## Status

Drafted: the Introduction, Solana Building Blocks, all of Financial Programming Concepts in Solana, every program chapter, and the Glossary. Every figure is drawn as SVG in the chapters' `figures/` directories. The dedication, acknowledgements, and technical reviewers page are drafted.
Drafted: every chapter from the Introduction to *Where to Go From Here*, the Glossary, and the front and back matter. Every figure is drawn as SVG in the chapters' `figures/` directories.

## License

Expand Down
20 changes: 8 additions & 12 deletions appendices/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ A fundraising rule under which contributions bind only if the full target is rea

### Alpenglow

Solana's consensus mechanism, which replaced Tower BFT. Under it the [commitment levels](#commitment-level) a client asks for are `processed` and `finalized`, and `confirmed` means the same as `finalized`. See the *Operating Financial Software* chapter.
Solana's consensus mechanism, which replaced Tower BFT. Under it the [commitment levels](#commitment-level) a client asks for are `processed` and `finalized`. See the *Operating Financial Software* chapter.

### American option / European option

An American option may be exercised at any time up to its expiry; a European option only at expiry. The *Options* chapter builds the American kind.

### Anchor

A framework for writing Solana programs in Rust. A program declares the checks each account must pass as constraints, and Anchor generates the code that performs them, the [discriminator](#discriminator), and the [IDL](#idl). The companion repository ships every program in Anchor 1, Anchor 2, and Quasar versions; see the *Adversary* chapter for the checks.
A framework for writing Solana programs in Rust. A program declares the checks each account must pass as constraints, and Anchor generates the code that performs them, the [discriminator](#discriminator), and the [IDL](#idl). The companion repository ships the program behind each program chapter in Anchor 1, Anchor 2, and Quasar versions; see the *Adversary* chapter for the checks.

### arbitrage

Expand Down Expand Up @@ -74,7 +74,7 @@ See [base token](#base-token).

### base token

The thing a market buys and sells (NVDAx), and the unit a **base amount** is denominated in: five NVDAx is a base amount. It is the first token of a [pair](#pair) written base/quote, and a price on the pair is how many units of the [quote token](#quote-token) buy one unit of the base. In the written pair NVDAx/USDC the base comes first, but the price is quoted in USDC per one NVDAx, so the base is the unit being priced, not the unit of the price.
The thing a market buys and sells (NVDAx), and the unit a **base amount** is denominated in: five NVDAx is a base amount. It is the first token of a [pair](#pair) written base/quote, and it is the unit being priced, not the unit of the price: a price on NVDAx/USDC is how many USDC, the [quote token](#quote-token), buy one NVDAx.

### basis point (bps)

Expand Down Expand Up @@ -204,10 +204,6 @@ The number of decimal places in one major unit of a token, declared on the mint:

A value at which a formula or a check stops meaning what it usually means, almost always zero or empty. An AMM reserve of zero lets the [K](#k) check pass vacuously (the *Constant-Product AMM* chapter); a price of zero or below means a broken price feed (the *Offchain Truth* chapter); an escrow offer with nothing on one side is refused by `make_offer()` with `ZeroAmount`. See [invariant](#invariant).

### discretization

Representing a continuous quantity as discrete integer steps. Onchain amounts are integers in [minor units](#minor-unit), so there is no such thing as half a lamport, and every division must decide what happens to the fraction the result cannot represent. See [dust](#dust) and the *Arithmetic of Money* chapter.

### discriminator

The 8 bytes Anchor writes at the start of an account's data identifying its type, so a program cannot be fed one kind of account where another belongs.
Expand Down Expand Up @@ -382,11 +378,11 @@ An order with a price it refuses to cross: buy at or below, sell at or above.

### liquidation

Forcibly repaying part of an unhealthy loan out of its collateral, at a bonus to the liquidator, to keep the market solvent. The close factor caps how much one call repays.
Forcibly repaying part of an unhealthy loan in return for some of its collateral at a bonus to the liquidator, to keep the market solvent. The close factor caps how much one call repays.

### liquidation bonus

The discount a liquidator receives on the collateral it seizes, which pays for the service of repaying an unhealthy loan. The *Lending and Borrowing* chapter's market sets it at 5% per reserve.
The discount a liquidator receives on the collateral they seize, which pays them for repaying an unhealthy loan. The *Lending and Borrowing* chapter's market sets it at 5% per reserve.

### liquidation threshold

Expand Down Expand Up @@ -474,7 +470,7 @@ The total current value of everything a fund holds, computed from fresh prices.

### Newton's method (integer square root)

The iterative algorithm programs use to take a square root using only integers, converging in about seventy loop iterations at most for a 128-bit input. AMMs use it to mint initial LP tokens as the square root of the two reserves' product. See the *Arithmetic of Money* chapter.
The iterative algorithm programs use to take a square root using only integers, converging within seventy loop iterations for any product of two u64s. AMMs use it to mint initial LP tokens as the square root of the two reserves' product. See the *Arithmetic of Money* chapter.

### NFT (non-fungible token)

Expand Down Expand Up @@ -646,7 +642,7 @@ What `saturating_sub` (and its `_add` and `_mul` siblings) does when a result wi

### seed

One of the inputs a program combines with its program ID to derive a [PDA](#pda-program-derived-address). The seeds are the key of a key/value store and the PDA is the address that key leads to. See the *PDAs* chapter.
One of the inputs a program combines with its program ID to derive a [PDA](#pda-program-derived-address). The seeds work like the lookup key of a database's key/value store, a different word from a private or public key, and the PDA is the address that lookup leads to. See the *PDAs* chapter.

### segmenting flow

Expand Down Expand Up @@ -766,7 +762,7 @@ The wall-clock time in the Clock [sysvar](#sysvar), in whole seconds. The previo

### unsettled balance

An amount an exchange owes a trader, recorded as a counter on the trader's account rather than paid out at each fill, and claimed with one transfer later. See the *Order Book Exchange* chapter.
An amount an exchange owes a trader, recorded as a counter on the trader's account rather than paid out at each fill. The trader claims it later with `settle_funds()`, which pays out each token's balance in one transfer however many fills built it up. See the *Order Book Exchange* chapter.

### utilization

Expand Down
2 changes: 1 addition & 1 deletion building-financial-products-in-solana/betting-market.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ This chapter added six concepts:
- **Terms locked before bettors commit stakes.** The outcome list, the fee, and the close time are all fixed before the first stake lands, so the question bettors staked on cannot be rewritten.
- **Account closure as the double-claim defense.** A paid-out bet has no account left to claim with.
- **Cancellation refunds every stake.** Draft and Open events can be canceled, and stakes in a canceled event are refunded in full, so a voided event strands nobody's stake.
- **Children close before parents.** Each close refuses while an account that names it is still open, so bets close before their outcomes and outcomes before their event, and counters on the event track what is still open.
- **Children close before parents.** `close_outcome()` refuses while any bet of the event is open, and `close_event()` refuses while any bet or outcome is, so bets close before outcomes and outcomes before their event; counters on the event track what is still open.

In the *Order Book Exchange* chapter we will build an exchange. Instead of paying into one pool, traders post orders at the prices they want, backed by tokens moved into a vault when the order is placed, and the program matches each new order against the best resting one. You will see how orders are stored, matched, and paid out onchain, where every step costs compute. The pooled payout formula and the trusted signer both return later, in the *Lending and Borrowing* and *Perpetual Futures* chapters, where the trusted signature is a price feed and settlement runs continuously instead of once.

Expand Down
4 changes: 2 additions & 2 deletions building-financial-products-in-solana/constant-product-amm.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Bob is early and bullish. He runs `swap_tokens()` to spend 100 USDC on ACME, a t

**The curve prices the trade.** It prices against Y plus the taxed input, 1,224.70, so X must fall to K ÷ 1,224.70 ≈ 459.3; the vault itself receives all 100 USDC. Bob receives about 40.7 ACME. He paid an *average* of about $2.46 per token while the quoted price before his trade was $2.25 and the spot price after it is about $2.67: his own trade moved along the curve as it executed.

**The invariant is re-checked.** After the transfers land, the handler reads both vault balances again and requires the new effective product to be at least the old one, failing with `InvariantViolated` otherwise. The program's own comment calls this the most important defensive check in the file: it catches any bug above it that would overpay a trader, the *Arithmetic of Money* chapter's rule to assert after the math. The check tolerates growth, because growth is just LP fees enriching the pool.
**The invariant is re-checked.** After the transfers land, the handler reads both vault balances again and requires the new effective product to be at least the old one, failing with `InvariantViolated` otherwise. The program's own comment calls this the most important defensive check in the file: a bug above it that overpays a trader by more than the LP fee is worth leaves the effective product below the old one, and the swap fails. That is the *Arithmetic of Money* chapter's rule to assert after the math. The check tolerates growth, because growth is just LP fees enriching the pool.

The curve priced the trade with K held fixed. The 25 cents of LP fees it did not price against raised K once the input landed, so K after Bob's trade is about 562,615.

Expand Down Expand Up @@ -142,7 +142,7 @@ The order book needed a tree, a matching engine, and maker accounts, because hum
Seven concepts came with the curve:

- **A formula as the market maker.** Output = taxed input × other reserve ÷ (this reserve + taxed input); the first deposit sets the price, and every trade pays its own price impact.
- **How K changes.** Held fixed while a trade is priced, raised by the LP fee once the input lands.
- **How K changes.** Deposits raise it without moving the price and withdrawals lower it; during a swap it is held fixed while the trade is priced, then raised by the LP fee once the input lands.
- **A product check needs both factors positive.** If either is zero, the product is zero and any trade passes the check.
- **Assert after the math.** The post-trade K check re-reads both vaults after the transfers; the *Arithmetic of Money* chapter's rule, applied to a swap.
- **Effective reserves.** The raw vault balance minus the admin's owed slice, which is what every piece of LP-facing math uses.
Expand Down
2 changes: 1 addition & 1 deletion building-financial-products-in-solana/escrow.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chapter 11: Escrow

Escrow lets two people swap tokens without trusting each other or paying a middleman, with three instruction handlers. It also teaches program custody, terms stored in an account, a closing handler for every state, and amounts counted in minor units, which every later program reuses.
Escrow lets two people swap tokens without trusting each other or paying a middleman, with three instruction handlers. It also teaches what later programs reuse: a vault only the program can sign for, terms stored in an account, a closing handler for every state, and amounts counted in minor units.

The chapters that follow add what escrow does not have: a formula that sets a price, an outcome that decides a payout, time and interest, and an operator who must be constrained.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading