Overview
Theank-protocol module defines the minimal surface for integrating DeFi protocols with the engine/runtime. It provides the core types and traits that all protocol implementations must use.
Core Types
Action
No operation (useful for smoke tests or heartbeat calls)
Arbitrary JSON payload (protocol-specific schema). In TypeScript this is emitted as
any; individual SDKs can provide strongly-typed builders around it.Event
Human-readable note (for logs/inspection)
Structured/opaque event payload
ExecOutcome
Action on a protocol.
Balance updates in e18 units:
token → i128 (serialized as strings in TS). Positive values credit the user; negatives debit the user. This delta is applied by the engine to the user’s balances after execution (subject to engine policies/fees).Gas consumed for this action (protocol’s estimate/measurement). Wrapped in
U64S so JSON/TS use string representation (safe for JS).Optional events emitted during execution
Protocol Trait
Send + Sync so it can be hosted by multithreaded runners.
Methods
id
"aave-v3", "uniswap-v3").
The protocol identifier
execute
Action at timestamp ts on behalf of user, returning an ExecOutcome.
The implementor is responsible for:
- Validating and applying the action to internal state
- Computing the resulting balance delta
- Estimating/measuring
gas_used - Emitting any events of interest
Simulation timestamp (e.g., block index)
User identifier executing the action
The action to execute
The execution outcome including balance deltas, gas used, and events
view_user
{}.
User identifier to query
Free-form JSON data representing the user’s state in this protocol
view_market
{}.
Free-form JSON data representing the protocol’s market state
apply_historical
Timestamp for the historical data
Optional market identifier hint
Historical data payload
on_tick
Current simulation timestamp
Example Implementation
Notes
- Amounts and balance updates are carried via
BalancesDelta(token → i128, serialized as strings in TS/JSON) - Gas usage is modeled as
U64S(au64serialized as string) to avoid precision loss in JS runtimes