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 aVwapParams struct to configure volume-driven execution:
| Parameter | Type | Description |
|---|---|---|
min_chunk_size | i128 | Minimum chunk size per execution |
max_chunk_size | i128 | Maximum chunk size per execution |
participation_rate_bps | u32 | Target participation rate in basis points (1-10,000) |
min_interval_seconds | u64 | Minimum time between executions |
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:Example
With a participation rate of 500 bps (5%) and market volume of 100,000 tokens:min_chunk_size = 1,000 and max_chunk_size = 10,000, the execution amount is 5,000 (within bounds).
Execution Flow
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.Volume-Driven Execution
A keeper calls
execute_vwap_order(order_id, keeper, market_volume), providing the current market volume. The contract:- Verifies
min_interval_secondshave passed - Validates
market_volume > 0 - Calculates chunk size using the clamping formula
- Updates order state before external calls
- Executes the swap and pays the keeper
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.

