Skip to main content
With declarative trades, users define what they want to trade (an intent), while DFlow determines how the trade executes as close to execution time as possible. This has greater sandwich protection, is more flexible than imperative trades, and helps users get the best prices possible. Instead of committing to a fixed route at quote time, users submit a trade intent. Final routing decisions are evaluated at execution time using current onchain prices.

What Makes a Trade Declarative

In a declarative trade, users do not specify an execution path. They specify:
  • The assets to trade.
  • The minimum acceptable outcome.
  • The slippage tolerance.
DFlow is responsible for selecting the best available route that satisfies those constraints at execution time. This separates trade constraints from execution mechanics.

How Declarative Trades Execute

Declarative trades use an open-order + fill structure, executed using Jito bundles.
A Jito bundle groups multiple transactions for ordered, atomic execution within the same slot. If any transaction in the bundle fails, none are processed.
Here’s how it works:
  1. The user signs an open order transaction signaling an intent to trade.
  2. Funds are temporarily escrowed onchain in the DFlow Swap Orchestrator contract.
  3. The user then signs the open order transaction and submits it to the DFlow Aggregator to be filled.
  4. Routing is evaluated immediately before execution.
  5. The open-order and fill transactions execute together as a bundle.
If any transaction fails, no state changes are applied.

Why Declarative Trades Reduce Slippage

Slippage occurs when prices change between quote and execution. Declarative trades reduce slippage by:
  • Delaying route finalization until execution.
  • Evaluating prices onchain immediately before execution.
  • Avoiding stale routes embedded at quote time.
Instead of following a fixed plan, the trade adapts while still enforcing user-defined limits.

Why Declarative Trades Improve Reliability

Many failed trades occur when prices move beyond slippage tolerance before execution. Declarative trades improve reliability by:
  • Reducing price drift between routing and execution.
  • Lowering the chance of slippage violations.
  • Avoiding retries and wasted fees.
This is especially important in fast-moving or latency-sensitive markets.

Why Declarative Trades Reduce Sandwich Risk

Sandwich attacks exploit the gap between when a route is revealed and when execution happens. Declarative trades reduce this risk by avoiding fixed routes at quote time. Because routing is finalized at execution and submitted as a bundled transaction, there is less opportunity for third parties to react to a known path and insert transactions around it. This does not eliminate sandwich risk entirely, but it significantly reduces exposure compared to trades with pre-committed routes.

When Declarative Trades Make Sense

Declarative trades are a good fit when:
  • Prices move quickly.
  • Liquidity is fragmented.
  • Minimizing slippage matters more than route control.
  • Execution reliability is critical.
They are the default choice for user-facing trading flows.

Code Recipes