Skip to main content

VWAP: Volume-Weighted Average Price

VWAP is a strategy that sizes each execution chunk based on current market volume, aiming to participate at a target percentage of market activity. This approach ensures your trades are proportional to market liquidity, reducing impact during low-volume periods.

Why Use VWAP?

Volume-Adaptive

Chunk sizes dynamically adjust to market conditions — larger chunks during high volume, smaller chunks during quiet periods.

Reduced Impact

By participating at a fixed percentage of volume, VWAP avoids dominating the order book during thin markets.

VWAP Parameters

VWAP orders use a VwapParams struct to configure volume-driven execution:
ParameterTypeDescription
min_chunk_sizei128Minimum chunk size per execution
max_chunk_sizei128Maximum chunk size per execution
participation_rate_bpsu32Target participation rate in basis points (1-10,000)
min_interval_secondsu64Minimum time between executions
In addition to the standard order parameters (vault, owner, token_in, token_out, total_amount, min_price, max_price, fee_reserve_amount).

Chunk Sizing Formula

Each execution calculates the chunk size based on the reported market volume:
target_chunk = market_volume * participation_rate_bps / 10,000

execution_amount = clamp(target_chunk, min_chunk_size, max_chunk_size)
execution_amount = min(execution_amount, remaining_amount)

Example

With a participation rate of 500 bps (5%) and market volume of 100,000 tokens:
target_chunk = 100,000 * 500 / 10,000 = 5,000 tokens
If min_chunk_size = 1,000 and max_chunk_size = 10,000, the execution amount is 5,000 (within bounds).

Execution Flow

1

Order Creation

The owner calls create_vwap_order() with the token pair, total amount, VwapParams, price bounds, and fee reserve. The contract estimates num_chunks = (total_amount / min_chunk_size) + 1 for fee calculation.
2

Volume-Driven Execution

A keeper calls execute_vwap_order(order_id, keeper, market_volume), providing the current market volume. The contract:
  1. Verifies min_interval_seconds have passed
  2. Validates market_volume > 0
  3. Calculates chunk size using the clamping formula
  4. Updates order state before external calls
  5. Executes the swap and pays the keeper
3

Completion

The order completes when executed_amount >= total_amount. Unused fees are refunded.
Keepers can check can_execute_vwap(order_id) to verify timing conditions before submitting an execution transaction. Note that can_execute() returns false for VWAP orders — use the VWAP-specific check.

Clamping Logic

The clamping ensures execution stays within safe bounds:
  • Below min_chunk_size: The target is raised to the minimum, preventing dust-sized trades that waste gas.
  • Above max_chunk_size: The target is capped at the maximum, preventing outsized chunks from moving the market.
  • Remaining amount: The final chunk is automatically adjusted to execute only the remaining order amount.