Architecture
Stendar pairs a production DeFi execution engine with public policy contracts, provider adapters, wallet adapters, notifications, CLI tooling, and AI adapter packages. Private product harness and hosted surfaces live under internal/.
Layered model
Section titled “Layered model”- Public interfaces: SDK, CLI, notifications, LangChain, and Vercel AI adapter packages.
- Policy v2 shared decision contract: Shared fail-closed schemas for approvals, limits, and execution constraints.
- Runtime policy enforcement:
PolicyEnginechecks on DeFi execution flows and compatibility adapters. - DeFi execution engine: Deterministic runtime flows through
DeFiRuntime. - Providers, chains, and wallets: The concrete on-chain adapters and signing infrastructure.
Component graph
Section titled “Component graph”graph TD SDK[SDK / Client surface] --> PolicyEngine[PolicyEngine runtime checks] AI[LangChain / Vercel AI adapters] --> SDK CLI[CLI] --> SDK PolicyV2[Policy v2 decision contract] -. fail-closed semantics via adapters .-> PolicyEngine PolicyEngine --> Runtime[DeFiRuntime execution engine]
Runtime --> Providers[Protocol providers] Providers --> Chains[Chain adapters] Runtime --> Wallets[Wallet adapters] Runtime --> Events[TypedEmitter RuntimeEvents] Events --> Notifiers[@stendar/notifications]Runtime lifecycle (conceptual)
Section titled “Runtime lifecycle (conceptual)”This sequence models the public runtime lifecycle and uses conceptual participants, not concrete class names. Runtime execution uses PolicyEngine, while Policy v2 defines the shared structured decision contract for fail-closed adapters.
sequenceDiagram participant Interface as SDK / AI / CLI surface participant Policy as Policy decision contract (Policy v2) participant Runtime as DeFiRuntime participant Provider as Provider participant Wallet as WalletAdapter participant Chain as ChainAdapter
Interface->>Policy: evaluate(intent, context) Policy-->>Interface: allow | deny | review_required | approval_required | blocked_until_evidence alt denied or approval required Interface-->>Interface: block or require approval handling else allowed Interface->>Runtime: execute(intent) Runtime->>Provider: getQuote/buildTransaction Runtime->>Chain: simulateTransaction() alt dryRun Runtime-->>Interface: simulated result else live Runtime->>Wallet: signTransaction() Runtime->>Chain: sendTransaction() Runtime->>Chain: waitForConfirmation() Runtime-->>Interface: confirmed/failed result end endWhy this shape
Section titled “Why this shape”PolicyEngineremains the active execution path today for lower-level access.- Policy v2 schemas provide the shared decision contract now, while compatibility adapters preserve raw runtime evidence and behavior during convergence.
- The DeFi execution engine stays focused on deterministic execution across pluggable chains, providers, and wallets.
- Event emission keeps observability and notification routing first-class.
Continue with Runtime lifecycle and Best execution.