Settlement
The one transaction that settles an accepted quote: what the desk builds, what the program checks, and what moves.
When the taker accepts a quote, the desk builds the settlement transaction, simulates it, and hands it to the taker’s wallet with a review of both legs and the fee. The taker’s signature is the only one on it. Its instructions run in the order below, and if any one fails, nothing moves.
The transaction
Compute budget
A compute unit limit and a priority price.
The taker’s token accounts
Two idempotent instructions that create the taker’s associated token accounts for the base and the quote mint if they do not exist yet. The taker pays their rent.
Wrap SOL, when the taker pays in SOL
A transfer of the exact payment into the taker’s wrapped SOL account, then a sync, so the program can move it as a token.
Ed25519 verify
The native Ed25519 program checks the maker’s signature over the quote message with the maker’s quote key.
settle
The program instruction, given the position of the Ed25519 instruction above. It checks the quote, records it as used, and moves both legs and the fee.
Unwrap SOL, when the taker receives SOL
The taker’s wrapped SOL account is closed, which returns its whole balance to the wallet as SOL, including any wrapped SOL it held before.
The position of the Ed25519 instruction is written into settle before signing. A wallet that inserts instructions ahead of it changes that position, and settle then fails with QuoteSignatureInvalid; the desk reports it as the wallet changing the transaction.
What settle checks
In this order, each failure with the program error named:
| Check | Error |
|---|---|
| The maker is active | MakerInactive |
| The side is 0 or 1, and both amounts are above zero | InvalidSide, InvalidAmount |
| The base and quote mints differ, and both are allowed | SameMint, MintNotAllowed |
| The cluster time is at or before the quote’s expiry | QuoteExpired |
The Ed25519 instruction comes earlier in the transaction, verifies one signature by the maker’s current quote key, and its message is exactly this quote rebuilt from the settle arguments | QuoteSignatureInvalid |
| The used-quote account is the one derived from this quote’s hash, and the quote has not settled before | InvalidUsedQuote, QuoteAlreadyUsed |
| The fee account is the fee recipient’s associated token account for the quote mint | InvalidFeeAccount |
| Each vault that exists is an SPL Token account of its mint, held by the maker account | InvalidTokenAccount |
| The vault the maker pays from exists and holds the maker’s leg | MakerInventoryShort |
Because the program rebuilds the signed message from the accounts and arguments of this transaction, a quote cannot be settled by another taker, against another maker, in other mints, or for other amounts.
What moves
The fee is the quote amount times the configured fee in basis points (5 bps today), divided by 10,000 and rounded down. Fees and the token says where it goes.
When the taker buys:
| From | To | Amount |
|---|---|---|
| Taker’s quote token account | Maker’s quote vault | the quote amount |
| Taker’s quote token account | Fee recipient | the fee |
| Maker’s base vault | Taker’s base token account | the base amount |
When the taker sells:
| From | To | Amount |
|---|---|---|
| Taker’s base token account | Maker’s base vault | the base amount |
| Maker’s quote vault | Taker’s quote token account | the quote amount minus the fee |
| Maker’s quote vault | Fee recipient | the fee |
The maker’s vaults always move exactly the amounts in the quote. The vault the maker pays out of must already exist and hold the maker’s leg. The vault it receives into is created by settle if it does not exist yet, and the taker pays its rent, so a maker can quote one side of a pair after depositing only that side.
The used-quote account
settle creates a small account at the address derived from ["quote", quote hash], holding the maker, the taker and the slot. The taker pays its rent, at the Rent sysvar’s current rate. Its existence is what makes a second settlement of the same quote fail with QuoteAlreadyUsed. If someone sends lamports to that address in advance, settle tops it up and takes it over, so this cannot block a fill.
The event
settle emits Settled with the quote hash, both parties, both mints, the side, both amounts and the fee. The desk’s indexer reads it to record the fill that appears in history. Its fields are in the Program reference.
Compute
Measured in compute units on the project’s local validator, on the current program. Compute units are the same on mainnet for the same program and accounts.
| Case | settle instruction | Whole transaction |
|---|---|---|
| Taker buys SOL, maker vaults exist, wSOL unwrapped to native SOL | 40,739 | 61,060 |
| Taker sells JitoSOL, maker vaults exist | 37,753 | 48,881 |
| Taker buys, maker's receiving vault created in the settle | 40,613 | 52,439 |
| Taker sells, maker's receiving vault created in the settle | 40,610 | 52,436 |
Creating the taker’s token accounts or wrapping SOL also adds to the whole transaction.