Skip to main content

OrderManager: API Reference

A detailed breakdown of all public functions in the OrderManager smart contract.

Data Types

Order

struct Order {
    id: u64,
    vault: Address,
    owner: Address,
    token_in: Address,
    token_out: Address,
    total_amount: i128,
    chunk_size: i128,
    executed_amount: i128,
    num_chunks: u32,
    executed_chunks: u32,
    interval_seconds: u64,
    start_time: u64,
    last_execution: u64,
    min_price: i128,          // 7 decimal precision
    max_price: i128,          // 7 decimal precision
    fee_reserve_amount: i128,
    fee_per_execution: i128,
    order_type: OrderType,    // TWAP or VWAP
    status: OrderStatus,      // Active, Completed, Cancelled
    // VWAP-specific fields
    min_chunk_size: i128,
    max_chunk_size: i128,
    participation_rate_bps: u32,
}

VwapParams

struct VwapParams {
    min_chunk_size: i128,
    max_chunk_size: i128,
    participation_rate_bps: u32,  // 1-10,000 basis points
    min_interval_seconds: u64,
}

Functions

FunctionParametersReturnsAuth
create_twap_ordervault, owner, token_in, token_out, total_amount, num_chunks, interval_seconds, min_price, max_price, fee_reserve_amountu64 (order ID)Owner
create_vwap_ordervault, owner, token_in, token_out, total_amount, vwap_params: VwapParams, min_price, max_price, fee_reserve_amountu64 (order ID)Owner
Validations:
  • 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_bps in 1-10,000
FunctionParametersReturnsAuth
execute_orderorder_id: u64, keeper: Addressi128 (output amount)Keeper
execute_vwap_orderorder_id: u64, keeper: Address, market_volume: i128i128 (output amount)Keeper
execute_order (TWAP):
  • Rejects VWAP orders (use execute_vwap_order instead)
  • Verifies interval_seconds elapsed since last execution
  • Calculates min_amount_out = execution_amount * min_price / 10,000,000
  • Updates state before external calls
  • Pays keeper fee_per_execution on 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
FunctionParametersReturnsAuth
cancel_orderorder_id: u64, owner: AddressOwner
  • Verifies the caller is the order owner
  • Sets status to Cancelled
  • Refunds unused fees: fee_reserve - (fee_reserve * executed_chunks / num_chunks)
FunctionParametersReturnsAuth
get_orderorder_id: u64OrderPublic
can_executeorder_id: u64boolPublic
can_execute_vwaporder_id: u64boolPublic
get_active_order_idsVec<u64> (max 100)Public
get_order_counteru64Public
can_execute() returns false for VWAP orders. Use can_execute_vwap() for VWAP order checks.
FunctionParametersReturnsAuth
set_pausedpaused: boolAdmin
is_pausedboolPublic
get_adminAddressPublic
When paused:
  • Order creation is blocked
  • Order execution is blocked (emits ExecutionFailedEvent)
  • Order cancellation is still allowed (funds are never locked)

Events

EventDataEmitted 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 FailedExecutionFailedEvent { order_id, keeper, reason, timestamp }execute_order, execute_vwap_order