Runtime Lifecycle
DeFiRuntime is the execution orchestrator in @stendar/core.
Construction
Section titled “Construction”At minimum you provide:
chains: one or moreChainAdapterimplementationsproviders: protocol providers (SwapProvider,YieldProvider,BridgeProvider)wallet: one adapter or an array of adapters
Optional config includes policies, dryRun, bestExecution, stateStore, logger, and mutexTimeoutMs.
const runtime = new DeFiRuntime({ chains, providers, wallet, policies, bestExecution: { timeoutMs: 10_000, crossChain: { enabled: true, maxPaths: 3 }, },});Lifecycle contract
Section titled “Lifecycle contract”await runtime.start();try { // runtime.getQuote / executeSwap / executeBridge / executeDeposit / executeWithdraw} finally { await runtime.stop();}start()loads state and emitsruntime:startedstop()persists state and emitsruntime:stopped- operations throw
RUNTIME_NOT_STARTEDif called beforestart()
Runtime operations
Section titled “Runtime operations”- Discovery:
getBalance,getQuote,getBestRoute,getTokenPrice,getYieldRates,getPositions - Execution:
executeSwap,executeBridge,executeDeposit,executeWithdraw - Bridging status:
getBridgeStatus
Each execution method can return policy-driven statuses like denied and approval_required, not just chain failures.
Concurrency model
Section titled “Concurrency model”Runtime serializes state-mutating executions behind an internal mutex so cumulative policy checks (for example daily spend/rate windows) stay consistent.
For detailed policy behavior, see Policies.