Skip to main content
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 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 Declarative swaps are able to 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.

Frequently Asked Questions

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 built with intents. An intent is a transaction that contains an intention to trade at a guaranteed minimum price with a slippage tolerance.
Quotes come from the DFlow Aggregator. The Aggregator is a server-side program that calculates high-quality routes for a given swap through a series of DEXs including Raydium, Orca, Lifinity, and many more.
The liquidity is sourced exclusively from onchain DEXs.
Declarative Swaps defer route calculation until after the open order transaction is submitted to the DFlow Aggregator. This allows the Aggregator to 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.
If the Jito bundle is unbundled, the Aggregator will automatically close the open order transaction and refund the trader. Traders can also manually close the open order and permissionlessly reclaim their source token funds.

Get Started with the Swap API Today

I