Skip to main content
The auction module handles price discovery for orders during their auction period. Drift uses a Dutch auction mechanism where prices move toward market price over time.

Functions

is_auction_complete

Check if an order’s auction period has ended.
pub fn is_auction_complete(order: &Order, slot: u64) -> bool
Parameters:
  • order - The order to check
  • slot - Current blockchain slot
Returns: true if the auction is complete, false otherwise Notes:
  • Orders with auction_duration == 0 are immediately complete
  • Auction ends when current_slot >= order.slot + order.auction_duration
Example:
if is_auction_complete(&order, current_slot) {
    println!("Order auction complete, can fill at any valid price");
}

get_auction_price

Calculate the current auction price for an order.
pub fn get_auction_price(order: &Order, slot: u64, price: i64) -> i128
Parameters:
  • order - The order being evaluated
  • slot - Current blockchain slot
  • price - Current oracle price (only used for oracle orders)
Returns: Current auction price as i128 Panics: If order type is not supported (must be Market, TriggerMarket, Limit, TriggerLimit, or Oracle) Example:
let current_price = get_auction_price(&order, current_slot, oracle_price);
println!("Current auction price: {}", current_price);

Fixed Auction Mechanism

For Market, Limit, TriggerMarket, and TriggerLimit orders, the auction uses a fixed price range.

Price Calculation

The auction price moves linearly from auction_start_price to auction_end_price over the auction duration. For Long Orders:
// Price increases over time (starts aggressive, becomes less aggressive)
let delta = (auction_end_price - auction_start_price) * slots_elapsed / auction_duration;
price = auction_start_price + delta;
For Short Orders:
// Price decreases over time (starts aggressive, becomes less aggressive)
let delta = (auction_start_price - auction_end_price) * slots_elapsed / auction_duration;
price = auction_start_price - delta;

Example

// Long order with 10 slot auction
// auction_start_price = 90.0 (aggressive, below market)
// auction_end_price = 100.0 (market price)
// After 5 slots (halfway):
// price = 90.0 + (100.0 - 90.0) * 5 / 10 = 95.0

Oracle Offset Auction Mechanism

For Oracle orders, the auction price is calculated as an offset from the current oracle price.

Price Calculation

The offset moves from auction_start_price to auction_end_price, then added to the oracle price. Formula:
let offset = calculate_offset(order, slot); // Similar to fixed auction
final_price = oracle_price + offset;
For Long Orders:
// Offset starts negative (below oracle) and moves toward zero or positive
let delta = (auction_end_price - auction_start_price) * slots_elapsed / auction_duration;
offset = auction_start_price + delta;
price = oracle_price + offset;
For Short Orders:
// Offset starts positive (above oracle) and moves toward zero or negative
let delta = (auction_start_price - auction_end_price) * slots_elapsed / auction_duration;
offset = auction_start_price - delta;
price = oracle_price + offset;

Example

// Oracle order (Long)
// oracle_price = 100.0
// auction_start_price = -5.0 (5 below oracle, aggressive)
// auction_end_price = 0.0 (at oracle, market price)
// After 5 of 10 slots:
// offset = -5.0 + (0.0 - (-5.0)) * 5 / 10 = -2.5
// final_price = 100.0 + (-2.5) = 97.5

Auction Mechanics Overview

Why Auctions?

Auctions serve several purposes:
  1. MEV Protection: Prevents front-running by giving the user time to cancel if price moves unfavorably
  2. Better Execution: Allows market makers to compete for fills, potentially improving user price
  3. Fair Access: Gives all market participants equal opportunity to fill orders
  4. Decentralization: Reduces reliance on specific keepers or market makers

Auction Parameters

Orders specify their auction behavior via:
  • auction_duration - How many slots the auction lasts (0-255)
  • auction_start_price - Starting price (aggressive fill)
  • auction_end_price - Ending price (market price)

Best Practices

For Immediate Fills:
// Set auction_duration to 0
order.auction_duration = 0;
For MEV Protection:
// Use a short auction (10-30 slots ≈ 5-15 seconds)
order.auction_duration = 20;
order.auction_start_price = limit_price; // Your worst acceptable price
order.auction_end_price = oracle_price;  // Market price
For Best Price:
// Use a longer auction (50-100 slots ≈ 25-50 seconds)
order.auction_duration = 100;
// Start aggressive, relax to market

Internal Functions

get_auction_price_for_fixed_auction

Calculate auction price for fixed auction orders.
fn get_auction_price_for_fixed_auction(order: &Order, slot: u64) -> i128

get_auction_price_for_oracle_offset_auction

Calculate auction price for oracle offset orders.
fn get_auction_price_for_oracle_offset_auction(
    order: &Order,
    slot: u64,
    oracle_price: i64
) -> i128

Build docs developers (and LLMs) love