OrderManager: API Reference
A detailed breakdown of all public functions in the OrderManager smart contract.Data Types
Order
VwapParams
Functions
Order Creation
Order Creation
| Function | Parameters | Returns | Auth |
|---|---|---|---|
create_twap_order | vault, owner, token_in, token_out, total_amount, num_chunks, interval_seconds, min_price, max_price, fee_reserve_amount | u64 (order ID) | Owner |
create_vwap_order | vault, owner, token_in, token_out, total_amount, vwap_params: VwapParams, min_price, max_price, fee_reserve_amount | u64 (order ID) | Owner |
- Owner must be the vault’s actual owner (prevents vault spoofing)
- All amounts must be positive
min_price <= max_price- Fee reserve must meet minimum (
min_fee_per_execution * num_chunks) - Contract must not be paused
- For VWAP:
min_chunk_size > 0,max_chunk_size >= min_chunk_size,participation_rate_bpsin 1-10,000
Order Execution
Order Execution
| Function | Parameters | Returns | Auth |
|---|---|---|---|
execute_order | order_id: u64, keeper: Address | i128 (output amount) | Keeper |
execute_vwap_order | order_id: u64, keeper: Address, market_volume: i128 | i128 (output amount) | Keeper |
execute_order (TWAP):- Rejects VWAP orders (use
execute_vwap_orderinstead) - Verifies
interval_secondselapsed since last execution - Calculates
min_amount_out = execution_amount * min_price / 10,000,000 - Updates state before external calls
- Pays keeper
fee_per_executionon success - Refunds unused fees if order completes
execute_vwap_order (VWAP):- Rejects non-VWAP orders
- Requires
market_volume > 0 - Calculates chunk:
clamp(market_volume * participation_rate_bps / 10000, min_chunk_size, max_chunk_size) - Same state-before-calls and payment pattern as TWAP
Order Management
Order Management
| Function | Parameters | Returns | Auth |
|---|---|---|---|
cancel_order | order_id: u64, owner: Address | — | Owner |
- Verifies the caller is the order owner
- Sets status to
Cancelled - Refunds unused fees:
fee_reserve - (fee_reserve * executed_chunks / num_chunks)
Query Functions
Query Functions
| Function | Parameters | Returns | Auth |
|---|---|---|---|
get_order | order_id: u64 | Order | Public |
can_execute | order_id: u64 | bool | Public |
can_execute_vwap | order_id: u64 | bool | Public |
get_active_order_ids | — | Vec<u64> (max 100) | Public |
get_order_counter | — | u64 | Public |
can_execute() returns false for VWAP orders. Use can_execute_vwap() for VWAP order checks.Admin Functions
Admin Functions
| Function | Parameters | Returns | Auth |
|---|---|---|---|
set_paused | paused: bool | — | Admin |
is_paused | — | bool | Public |
get_admin | — | Address | Public |
- Order creation is blocked
- Order execution is blocked (emits
ExecutionFailedEvent) - Order cancellation is still allowed (funds are never locked)
Events
| Event | Data | Emitted By |
|---|---|---|
| Order Created | (order_id, order_type, total_amount, num_chunks_or_participation_rate) | create_twap_order, create_vwap_order |
| Order Executed | (execution_amount, output_amount, keeper, executed_chunks) | execute_order |
| VWAP Executed | (execution_amount, output_amount, market_volume, keeper) | execute_vwap_order |
| Order Cancelled | (order_id, owner) | cancel_order |
| Execution Failed | ExecutionFailedEvent { order_id, keeper, reason, timestamp } | execute_order, execute_vwap_order |

