Serum swapped base tokens through two markets with a shared quote token
Serum's legacy swap program exchanged different base tokens through two Solana markets sharing the same quote token. It sold the starting token for that intermediary, then spent the proceeds buying the destination token. Both markets needed compatible token accounts and executable orders. This transitive route removed the need for a direct pair between the endpoints. The original mainnet DEX program became defunct after FTX and Alameda Research collapsed in November 2022.
Could a swap work without a direct token pair?
A transitive swap worked when both base tokens had usable markets against the same quote mint. The base token was the asset each market traded, and the quote token denominated its prices. The connection depended on the actual mint address, so similarly named quote tokens did not create a compatible route. Different quote mints required another conversion mechanism; the legacy transitive instruction did not connect them automatically.
Token flow within the transitive instruction
The transitive instruction ran its sell and buy legs sequentially, settling each leg before continuing. Settlement transferred the first market's proceeds into the quote account the second market used. The account connected the markets without combining their order books.
| Program stage | Token movement and market scope |
|---|---|
| Sell the starting base token | An immediate-or-cancel ask traded against bids in the starting token's market. |
| Settle the first market | Quote-token proceeds moved into the shared quote account. |
| Buy the destination base token | An immediate-or-cancel bid used those proceeds against asks in the destination token's market. |
| Settle the second market | Purchased base tokens moved into the destination token account; unused quote tokens remained in the shared account. |
| Atomic swap | These operations belonged to one swap instruction on Solana, subject to its final checks. |
A failure during this instruction reverted its token transfers with the rest of the transaction. The sell leg could not commit independently when the buy leg or final rate check failed.
Liquidity across both trading legs
A shared quote token connected the markets, while executable bids and asks determined how much the route could exchange. Liquidity on one book did not supply missing orders on the other. The combined exchange rate reflected both legs and the trading fees affecting their proceeds.
Bids funding the sell leg
The first trade sold into bids for the starting base token. Available bid quantities limited the amount the order could fill. A price at the top of the book described that level's orders; a larger sale could reach lower bids. Net quote proceeds then set the second leg's spending budget.
Immediate-or-cancel orders took available matches and cancelled their unfilled remainder. They did not leave that remainder waiting as a resting order.
Asks limiting the buy leg
The second trade bought from asks for the destination base token. Its spending limit came from the first leg's proceeds. Insufficient ask depth could leave some quote tokens unspent, even after a substantial sale. Market lot sizes also constrained purchasable quantities. A partial fill could still pass the final rate check under its configured valuation rule.
Quote-token spill and exchange-rate limits
The minimum exchange-rate check determined whether the instruction could succeed under the caller's chosen valuation setting. The legacy implementation supported strict and non-strict treatment of unspent quote tokens, which it called spill.
Strict treatment of destination tokens
A strict check compared the destination tokens received with the actual starting tokens spent. It excluded surplus quote tokens from the output valuation. This setting suited an interpretation focused on the destination balance, even when the route also returned value in the intermediary asset.
Receiving no destination tokens triggered an error before the rate comparison. Leftover quote tokens alone could not satisfy a swap with zero output.
Effective valuation of quote leftovers
When strict was false, the program valued leftover quote tokens at the buy leg's executed exchange rate. It added that equivalent value to the destination amount for the acceptance calculation. This accounting adjustment did not purchase additional destination tokens. A successful non-strict swap could therefore leave value divided between the destination asset and the shared quote token.
Requested input and recorded token amounts
The swap's recorded amounts separated the requested budget from token-account changes during execution. Its DidSwap event carried distinct fields for sold input, purchased output, intermediate quote proceeds, and quote surplus.
The budget and actual input
The given_amount field recorded the maximum starting amount the caller supplied. The from_amount field recorded the starting-token account's decrease across the sell leg and settlement. Partial execution could make these amounts differ. The rate check used actual input spent, so an accepted swap did not imply consumption of the entire requested budget.
Output, proceeds, and surplus
The to_amount field represented the destination-token account's increase. The quote_amount field recorded proceeds received from the first leg, while spill_amount represented those proceeds minus the second leg's spending. Each amount used its own mint's integer token units. Comparing raw integers across different mints without their decimal precision could misstate the exchanged quantities.
Account boundaries for the route
Each market required its own OpenOrders account, while the transitive instruction used one quote-token account across both legs. OpenOrders recorded the owner's trading balances and orders for a particular market. The signer needed authority over both OpenOrders accounts. Each leg also supplied its own market vaults, bids, asks, and settlement accounts; sharing a quote token did not make these market-specific accounts interchangeable.
The destination and starting token accounts needed the mints their respective markets expected. The shared quote account needed the quote mint common to both markets. Account setup could increase an application's transaction count without splitting the two trading legs across separate swap instructions. A route's account requirements therefore extended beyond the token pair an interface displayed.
Client defaults and broader program support
The historical TypeScript client simplified market selection, while the on-chain program defined the execution requirements. The v0.1.0-alpha.20 client documented USDC or USDT quote accounts for transitive swaps. Supplying explicit market objects could avoid additional network requests. Its routing method returned market addresses or no route, using token-list information to identify the markets.
The program linked both market account sets through one quote account. That structural requirement was broader than the client's documented stablecoin choices. A client default described that client's behavior, without establishing a universal restriction on every integration. Equally, a returned market address did not establish sufficient executable liquidity. The markets' actual orders still determined whether a proposed route could fill.
Legacy deployment and replacement markets
The original mainnet DEX program became defunct in November 2022 after the collapse of FTX and Alameda Research. FTX held its upgrade authority, creating concerns over who could change the executable program. A minimum-rate check addressed the swap's exchange outcome under the implemented rules. It did not resolve the separate risk of changes to those rules through program upgrades.
OpenBook emerged as a community fork of Serum v3 with a separate deployment. Copying program code did not transfer the original markets' orders or make old account addresses interchangeable with new ones. An interface targeting the original program remained a legacy integration. For an active swap, select a replacement whose own implementation supports the intended token route.
Questions and answers about Serum
Did the intermediate quote account need an existing trading balance?
The second leg spent quote-token proceeds from the first leg, without adding the account's pre-existing balance to its budget. A valid intermediate token account was still required. A pre-existing quote-token balance was unnecessary; network fees and any required account creation still needed SOL.
Was SRM mandatory as the intermediate token in a legacy swap?
SRM was not a mandatory intermediary; the route depended on the quote mint both markets shared. The historical TypeScript client documented USDC or USDT quote accounts for transitive swaps. A token's use elsewhere in the exchange did not make it the connecting asset for every route.
Does exchanging a mint for itself fit the legacy transitive method?
The legacy instruction rejected swaps whose starting and destination token accounts had the same mint. Holding the same token in different accounts did not satisfy its requirement for distinct endpoint assets. The shared quote token connected markets for different base tokens.
Which token did a transitive swap's referral account receive?
The optional referral account received the shared quote token. The historical client required the referral account's mint to match the route's quote currency. Supplying a destination-token account as the referral recipient did not meet that requirement, even when the destination token was the asset the swap purchased.
Why could a sell amount smaller than one market lot fail?
A sell amount below the market's base lot size could fail because the helper converted input into whole lots, leaving no valid nonzero order quantity. The threshold varied with the selected market's lot configuration and its base token's units.
Was a DidSwap event proof that the token exchange succeeded?
A DidSwap event alone did not establish that the transaction succeeded. The program emitted the event before completing its final risk checks. A later error could revert the token changes even though the execution logs contained the event. The transaction's final execution status determined whether those changes committed.
Could the required OpenOrders accounts be initialized in the swap transaction?
Account initialization could accompany a swap, although the historical client sometimes split setup across transactions. In the v0.1.0-alpha.20 client, creating both OpenOrders accounts for a first transitive swap caused transaction splitting to avoid size limits. The two trading legs still belonged to one transitive swap instruction.
How did a failed transitive swap affect its network fee?
An executed Solana transaction could incur its network fee even when the transitive swap failed. Atomic rollback reversed the swap's token transfers, while the network still charged for processing the failed transaction. A local error before submission did not itself establish an on-chain transaction or fee.