Skip to main content
An rfqOrder quote settles async, in two transactions. The user’s transaction opens an RFQ order onchain that escrows the user’s input, the settlement mint. The maker fills the order in a later transaction, on its own schedule before the deadline. DFlow does not call /submit-transaction for an rfqOrder quote.

Selected Quote

DFlow calls POST /selected when it hands the transaction to the user. The call is a notification: DFlow does not wait for the answer, and the maker declines an order by not filling it.
The maker checks that quoteId is one of its live quotes and records or queues orderAddress for filling. The call is idempotent per quoteId and orderAddress, and is delivered with the same retry as an rfqFill selection. The notification arrives before the user signs. The order account may not exist yet, and may never exist if the user declines or the transaction fails or expires. The maker does not refuse the notification because the account is missing. It watches the chain for the account until the open transaction’s blockhash expires, about 150 slots after DFlow built it. When the account appears, the maker checks it before it acquires the equity. The order must name this maker, its mints must be the quote’s tokenIn and tokenOut, and its quoted_in and quoted_out must equal the values the quote implies, as in the last look checks. The fill instruction only has to match or improve on the order’s own values, so this check is what ties the order to the maker’s quote. DFlow does not send a signature for it.

Fill Deadline

An order account stores a last_fillable_slot, inclusive. It is the earlier of the slot of the quote’s expiry and the open slot plus up to 150 slots. DFlow sets the quote’s expiry, 60 seconds after the quote by default, and the maker cannot change it. A maker that needs a different window declines the quote. After last_fillable_slot the order can only be closed and refunded.

RFQ Order Program

Orders live on the RFQ order program, 8dybMBo3dhQR49ACuWzZej9WiRzPpNkmpdjH7iBk6ip3. Each address below derives from that program ID. An instruction or account discriminator is the first 8 bytes of the SHA-256 of its Anchor name.

Order Account Layout

The order account is 312 bytes: the 8-byte discriminator, then a 304-byte body. The offsets below start after the discriminator. platform_fee_ubps is the fee rate, where 1000000 is 100%. In flags, bit 0 charges the fee on the input instead of the output. Bit 1 requires the fill in the same transaction as the open, which is set for rfqFill orders and never for rfqOrder orders.

Fill an Order

The maker fills the order with its own transaction before the deadline, using fill_rfq_order. Read the Fill Instruction describes the data both fill instructions share. The accounts are under Fill Instruction Accounts.
  1. Read the order account and check it as described above.
  2. Build the fill from the order’s fields: the mints, the destination, refund and rent recipient accounts, and the quoted_in and quoted_out values.
  3. Add compute budget instructions, set the maker as signer and fee payer, and sign.
  4. Submit the transaction before last_fillable_slot.
The fill instruction carries quoted_in and quoted_out. The maker starts from the order’s values, which it reads from the order account. They are the maker’s own quote:
  • Input: a fill takes the lesser of the escrowed input and the amount that leaves the maker quoted_in after an input-side platform fee. The maker can state a quoted_in below the order’s to take less.
  • Output: the maker pays received × quoted_out ÷ quoted_in, rounded down, where received is the input its token account gained. The price does not change with the size of the fill. A platform fee or a Token-2022 transfer fee on the input reduces received and so reduces the payment.
  • Result: a fill closes the order. Input the fill does not consume returns to the user in the same transaction. The events report the measured amounts.

Price Improvement

A maker can fill at a better price than the order’s. The program accepts a fill when:
  • quoted_in is above zero and at most the order’s quoted_in.
  • quoted_out is at least the order’s quoted_out.
The fill’s price, quoted_out ÷ quoted_in, is then never below the order’s, so the user gets the order’s price or better and never less. A fill with a lower quoted_out or a higher quoted_in reverts.
  • Higher quoted_out: the maker pays more for the same input.
  • Lower quoted_in: the maker takes less input and the rest returns to the user as a refund. The payment is still received × quoted_out ÷ quoted_in, so taking quoted_in of input pays the whole quoted_out.
For an order with quoted_in 201,000,000 and quoted_out 1,005,000,000, a fill that states the same quoted_in and a quoted_out of 1,010,000,000 pays 1,010,000,000 for 201,000,000 of input. A fill that states a quoted_in of 100,000,000 and a quoted_out of 1,005,000,000 takes 100,000,000 of input, pays 1,005,000,000, and refunds the remaining input to the user. The maker reads the escrowed amount from the order’s escrow token account. The maker is responsible for stating a quoted_in the escrow covers. A fill that states a quoted_in above what the escrow holds takes the whole escrow and pays in proportion to it, as in the formula above.

Fill Instruction Accounts

The instruction has 18 fixed accounts. The program pins each one to the order or to a known program id, except the maker’s own token accounts, 12 and 13. When the order has a platform fee, the next three accounts are the fee recipient, which must be the order’s fee account, DFlow’s fee token account, and DFlow’s fee authority. To pay the fee straight to the order’s fee account, pass that account again as DFlow’s fee token account and the RFQ order program ID as DFlow’s fee authority. Any Token-2022 transfer hook accounts follow.

Fill Conditions

A fill succeeds only when all of these hold. Otherwise the transaction reverts and nothing moves.
  • The maker signs, and the slot is at or before last_fillable_slot.
  • Every account is the one the order names, apart from the maker’s two token accounts.
  • The fill’s quoted_in is above zero and at most the order’s, and its quoted_out is at least the order’s.
  • The maker’s input account gains something. A Token-2022 transfer fee or an input-side platform fee cannot take the whole input.
  • The payment is at least one unit: received × quoted_out must be at least quoted_in.
  • The maker’s output account holds the payment, and its balances move by exactly the payment and received.
  • The user’s account receives the whole payment less any output-side platform fee. The destination is not frozen and the output mint has no transfer fee.
  • Any refund, when the escrow exceeds what the fill takes, can reach the user’s refund account.
  • Each Token-2022 mint’s transfer hook gets its extra accounts.
A fee account that is missing, frozen, or of another mint never blocks a fill. The fee is skipped and the user keeps it.

Close an Order

Before last_fillable_slot, only the order’s maker can close the order. A close refunds the whole escrow to the user. The maker closes an order it cannot fill, for example when it cannot acquire the equity. The user cannot close an order. After last_fillable_slot, anyone can close it. The close_rfq_order instruction data is its discriminator alone. It takes 12 accounts, followed by any Token-2022 transfer hook accounts for the refund.

Order Events

Each transition of an order emits one RfqOrderEvent: open, fill, cancel (a close before the deadline) and expire (a close after it). The open event names the order and its maker. Onchain Fill Parsing describes how to read the events.