Declarative Swaps
The core concepts behind DFlow’s suite of next-generation trading products
Declarative Swaps are lightweight multi-transaction swaps that offer a new trading paradigm on Solana that incurs less slippage, has greater sandwich protection, and is more flexible than imperative swaps. Declarative Swaps are a form of intent-based trading.
DFlow Swap API allows traders on Solana to swap tokens with Declarative Swaps. Read the Declarative Swaps Token Quickstart to learn how to programmatically send Declarative Swaps on Solana.
Declarative Swaps Transaction Structure
Declarative Swaps are built on top of Jito bundles. The bundle structure contains an open order transaction followed by a fill transaction.
Open Order Transaction
The open order transaction is a trader-signed intention to trade. It contains a guaranteed minimum quote and slippage tolerance that must be met when the fill transaction is executed. The guaranteed minimum quote is calculated by a sophisticated split-route algorithm hosted by the DFlow Aggregator at the time of the quote request, and exclusively uses onchain prices from reliable DEXs like Raydium, Orca, Phoenix, Lifinity, and many more.
The open order transaction transfers the the trader’s funds to an escrow contract until the fill transaction is executed. The DFlow Swap Orchestrator contract acts as an escrow for the source token until the fill transaction is executed.
DFlow Swap API’s quote endpoint returns an open order transaction that can be signed and sent to the DFlow Aggregator to be filled.
When submitting the open order transaction to the DFlow Aggregator, the submit endpoint returns which program ID will act as the escrow for the source token. Developers should avoid hardcoding the Swap Orchestrator Program ID in their codebase.
Fill Order Transaction
After the open order transaction is submitted to the DFlow Aggregator through the submit-intent endpoint, the DFlow Aggregator will construct a fill transaction containing a fresh route plan. The fill transaction is then bundled with the open order transaction and sent to the network as a Jito bundle.
This sequence of events minimizes latency between the route plan calculation and the transaction execution.
An example of a Declarative Swap transaction can be found on Solscan.
Sequence of Events
Declarative swaps, in contrast to imperative swaps, allow traders to declare an intent to swap, and then use a filler to execute the swap.
Declarative swaps are able to aggregate conditional liquidity, incur less slippage, and are protected against sandwiches. These swaps calculate a final route adhering to the promised quote server-side immediately prior to the transaction being sent to the network. These swap transactions incur significantly less slippage due to the minimal latency between route calculation and the transaction execution onchain.