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.Frequently Asked Questions
What are Declarative Swaps?
What are Declarative Swaps?
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.
How are Declarative Swaps different from regular swaps?
How are Declarative Swaps different from regular 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.
Where do quotes come from?
Where do quotes come from?
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.
Where does the liquidity come from?
Where does the liquidity come from?
The liquidity is sourced exclusively from onchain DEXs.
How do Declarative Swaps achieve lower slippage?
How do Declarative Swaps achieve lower slippage?
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.
What happens if the Jito bundle is unbundled?
What happens if the Jito bundle is unbundled?
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.