Architecture

One Anchor program, programs/squeeth (Anchor 0.31.1). Program id on Solana mainnet: 5sNmL3fVsgLEBEQBiVHDR9gwrdUo2uEn7RWhcWhE8Qf6. Market account: BuUPDFRiV6pcc6UpHxLLKJCndPHscZuVBxRPmwK7auDc.

Accounts

AccountSeedsOwnerHolds
Market["market"]programparameters, NF, pool reserves, price accumulator, total debt, and the pool's SOL as lamports
Power mint["power"]SPL Tokenthe token, 9 decimals, mint authority = Market
Pool tokens["pool_tokens"]SPL Tokenthe pool's tokens, authority = Market
Vault["vault", owner]programone short's SOL collateral (lamports) and debt (token base units)
LP position["lp", owner]programone provider's pool shares
PricePyth account 7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiEPyth receiver rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJSOL/USD, PriceUpdateV2

There is exactly one market per program, because its address is the fixed seed ["market"].

Market fields

FieldMeaning
authoritythe account that created the market (the upgrade authority)
nf_wadnormalization factor × 10^18
last_funding_tslast time funding was applied
funding_periodseconds, set at creation, 60 to 7,776,000 (90 days)
twap_windowseconds, set at creation, 5 to 3,600
pool_sol, pool_tok, lp_totalpool reserves and shares
cum, cum_ts, prev_cum, prev_ts, cur_cum, cur_tsthe pool price accumulator (Q32 lamports per base unit × seconds)
total_debtall tokens minted and not yet repaid

Who may create the market

init_market checks that the signer is the program's upgrade authority, read from the program data account. Nobody else can create a market with different parameters.

The price reader

read_price accepts only:

  1. an account owned by the Pyth receiver, with the PriceUpdateV2 discriminator,
  2. verification level Full (byte 40 = 1),
  3. the SOL/USD feed id at bytes 41 to 72,
  4. a positive price published at most 120 seconds ago,
  5. a confidence at most 2% of the price.

Anyone may post a fresher fully verified update, so a buyer or a liquidator never waits for a keeper.

Compute

Measured on the local validator:

InstructionCompute units
mint_power18,078
buy15,283
poke17,505
liquidate30,997
sell14,070

The mainnet build is 552,328 bytes.

Next: Economics