Overview
Theank-exec module provides stateless execution helpers for calling protocols. It defines transaction types and execution callbacks that allow the engine (or other callers) to handle balances, fees, and metrics.
Design
The exec layer is stateless: it only looks up the target protocol and callsProtocol::execute, returning the ExecOutcome. Any stateful concerns (fees, balance mutations, metrics, rollback, etc.) must be implemented by the caller via the callback supplied to *_with_cb functions.
Core Types
Tx
exec layer does not interpret the action; it is passed through to the target protocol.
Target protocol id (e.g.,
"aave-v3", "uniswap-v3")Opaque action payload. Each protocol parses and validates its own actions. When
ts-bindings are enabled, this is exported as any to TypeScript.Optional gas limit for precharge/refund flows. If
Some(limit), callers can precharge limit * gas_price at ExecStage::PreTx and refund the unused portion after execution. If None, callers typically post-charge by outcome.gas_used at ExecStage::PostTx.TxBundle
Ordered list of transactions
ExecStage
*_with_cb helpers.
The callback is invoked:
- once with
ExecStage::PreTxbefore callingProtocol::execute - once with
ExecStage::PostTxafter obtaining theExecOutcome
Pre-execution hook — ideal for preflight checks and precharge of gas
Post-execution hook — ideal for applying deltas and charging/refunding fees
Execution Functions
execute_tx_with_cb
Map of protocol instances
Current simulation timestamp
User identifier
Transaction to execute
Callback invoked at PreTx and PostTx stages
Execution outcome or error from either the protocol or callback
execute_bundle_with_cb
Protocol::execute or from the callback).
Map of protocol instances
Current simulation timestamp
User identifier
Bundle of transactions to execute
Callback invoked at PreTx and PostTx stages for each transaction
Vector of execution outcomes (one per transaction)
execute_bundle
ExecOutcome values.
Map of protocol instances
Current simulation timestamp
User identifier
Bundle of transactions to execute
Vector of execution outcomes (one per transaction)
Usage Example: Execution with Callbacks
Gas Semantics
- If
Tx::gas_limitisSome, callers typically prechargegas_limit * gas_priceatExecStage::PreTxand refund onExecStage::PostTxusingoutcome.gas_used - If
gas_limitisNone, callers often post-charge byoutcome.gas_usedinPostTx
Engine) via the execution callback.