Integration

Finding the pool

Sort the mints ascending, hash them, and derive the pool:

import { PublicKey } from "@solana/web3.js"
import { createHash } from "crypto"

const sorted = mints.slice().sort((a, b) => Buffer.compare(a.toBuffer(), b.toBuffer()))
const mintSet = createHash("sha256").update(Buffer.concat(sorted.map((m) => m.toBuffer()))).digest()
const [pool] = PublicKey.findProgramAddressSync([Buffer.from("pool"), mintSet], PROGRAM_ID)

mint_set_hash in the program uses Solana's hashv (SHA-256 over the concatenated keys), so the two match.

Swapping from your program

Accounts for swap, in order:

#AccountWritableSigner
0traderyes
1poolyes
2mint_in
3mint_out
4vault_in (pool's ATA of mint_in)yes
5vault_out (pool's ATA of mint_out)yes
6trader_inyes
7trader_outyes
8token_program_in
9token_program_out

Arguments: coin_in: u8, coin_out: u8 (indexes into Pool.mints), amount_in: u64, min_out: u64.

Quoting

Read the Pool account and run the same math off chain, or simulate the transaction and read the Swapped event: amount_out, fee and band_crossings.

Events

EventFields
PoolCreatedpool, mints
LiquidityChangedpool, owner, band, added, radius, amounts
Swappedpool, trader, coin_in, coin_out, amount_in, amount_out, fee, band_crossings
FeesCollectedpool, owner, coin, amount

Compute

Swap cost does not grow with the number of coins: the program tracks sums over the reserves, as the paper describes, so a two-coin trade touches only those two. It grows with the number of band edges a trade crosses.

Next: API reference