Skip to content

API Reference

This page is the public export map for @stendar/core (from sdk/core/src/index.ts) and the SDK-safe trust contracts in @stendar/policy-contracts.

@stendar/policy-contracts publishes stable validation schemas and a versioned manifest for public control-plane trust summaries:

  • PUBLIC_TRUST_CONTRACT_VERSION
  • PublicTrustContractManifestSchema
  • DEFAULT_PUBLIC_TRUST_CONTRACT_MANIFEST
  • Policy contracts: PolicyV2EvaluationResultSchema, PermissionGrantSchema, PolicyV2DefiTransactionAdapterInputSchema
  • Tool and action contracts: CanonicalToolManifestSchema, ActionLifecycleRequestSchema, ActionLifecycleResponseSchema
  • Audit contracts: AuditEntrySummarySchema, AuditVerificationResultSchema
  • Controlled module/sandbox contracts: ControlledModuleManifestSchema, StrongerSandboxReadinessSummarySchema, SandboxPromotionReadinessSummarySchema
  • Boundary and governance contracts: ExecutionBoundarySummarySchema, GovernanceDecisionSummarySchema
  • Wallet, package, and remote MCP contracts: WalletSigningReadinessSummarySchema, WalletActionPreviewSummarySchema, OfficialPackageChannelEntrySummarySchema, OfficialPackageChannelReadinessSummarySchema, RemoteMcpSessionSummarySchema, RemoteMcpReadinessSummarySchema

These exports are public summaries only. Private local-runtime DTOs, raw payloads, secret references, and operational internals are not public API.

  • DeFiRuntime (DeFiRuntimeConfig): runtime lifecycle, routing, policy checks, and execution orchestration.
  • StrategyEngine (StrategyEngineConfig): YAML strategy execution with pause/resume/stop lifecycle control.
  • StepRunner (StepResult): low-level step execution helper used by strategy internals.
  • ApprovalManager (ApprovalConfig, ApprovalRequest, ApprovalDecision): approval-gated strategy actions.
  • PolicyEngine: evaluates PolicyRule sets against TransactionIntent.
  • BestExecutionRouter (BestExecutionConfig, BestExecutionRequest, BestExecutionResult, CrossChainPath, RouteScore): provider and route ranking.
  • TokenRegistry: symbol/address resolution helper for Solana and EVM tokens.
  • PluginRegistry: runtime plugin registration and lookup.

Logging, audit, events, state, and reliability

Section titled “Logging, audit, events, state, and reliability”
  • ConsoleLogger (ConsoleLoggerOptions, LogLevel, Logger): lightweight console logging.
  • PinoLogger (PinoLoggerOptions): structured JSON logging for production pipelines.
  • AuditLogger (AuditActor, AuditEntry): hash-chained audit trail with integrity verification.
  • TypedEmitter (RuntimeEvents): strongly typed runtime and strategy event bus.
  • InMemoryJsonStore (StateStore): runtime persistence adapter for execution state.
  • RateLimiter (RateLimiterConfig, RateLimiterPreset, RATE_LIMITER_PRESETS): token-bucket limiting for provider/RPC calls.
  • RequestDeduplicator (RequestDeduplicatorConfig): in-flight request coalescing by key.

Strategy parsing and persistence functions

Section titled “Strategy parsing and persistence functions”
  • parseStrategyFromYaml: parse and validate YAML into a Strategy.
  • strategyToYaml: serialize a Strategy back into YAML.
  • serializeStrategy / deserializeStrategy: JSON-safe strategy persistence helpers.
  • serializeExecutionState / deserializeExecutionState: JSON-safe execution-state persistence helpers.
  • evaluateCondition: evaluate Condition trees (time, price, balance) during strategy execution.
  • Single-rule evaluators: evaluateSpendingLimitRule, evaluateRequireApprovalRule, evaluateRateLimitRule, evaluateProtocolAllowlistRule, evaluateTokenAllowlistRule, evaluateMaxSlippageRule, evaluateMaxDrawdownRule, evaluatePortfolioExposureRule, evaluateTimeWindowRule.
  • Generic evaluator surface: evaluateRule, ruleEvaluators, RuleEvaluationResult, RuleEvaluator.
  • Primary rule/data types: PolicyRule, PolicyRuleType, BasePolicyRule, PolicyDecision, PolicyDecisionType, EvaluatedRule, PolicyContext, SpendingLimitRule, RequireApprovalRule, RateLimitRule, ProtocolAllowlistRule, TokenAllowlistRule, MaxSlippageRule, MaxDrawdownRule, PortfolioExposureRule, TimeWindowRule.
  • Provider contracts: BaseProvider, ProtocolProvider, SwapProvider, YieldProvider, BridgeProvider.
  • Bridge model types: BridgeQuoteRequest, BridgeQuote, BridgeResultV2, BridgeStatus.
  • Chain and wallet contracts: ChainAdapter, WalletAdapter, TypedDataDomain, TypedDataField.
  • Capability exports: ProviderCapability, ProviderCapabilityType.
  • Errors: StendarError, ErrorCode, ErrorPayload.
  • Helpers: normalizeError, parseAmount, serializeForJson, toErrorPayload.
  • Quote and pricing: QuoteRequest, Quote, PriceQuote, YieldQuery, YieldRate, Position.
  • Execution intents/results: TransactionIntent, TransactionResult, SwapRequest, SwapResult, SwapStatus, BridgeRequest, BridgeResult, DepositRequest, DepositResult, WithdrawRequest, WithdrawResult.
  • Chain tx representations: UnsignedTransaction, SignedTransaction, BaseUnsignedTransaction, SolanaUnsignedTransaction, SolanaSignedTransaction, EvmUnsignedTransaction, EvmSignedTransaction.
  • Confirmation/simulation: ConfirmOpts, ConfirmationResult, SimulationResult, TokenBalance.
  • Strategy graph types: Strategy, StrategyStep, ActionStep, ActionDef, SwapActionDef, DepositActionDef, WithdrawActionDef, WatchStep, ConditionalStep, MeanwhileStep.
  • Conditions and repetition: Condition, ConditionOperator, PriceCondition, TimeCondition, BalanceCondition, RepeatConfig.
  • Execution tracking: StrategyStatus, StepStatus, StepState, StrategyExecutionState, StrategyExecutionStatus.
  • Persistence DTOs: SerializedStrategy, SerializedExecutionState.
  • validatePlugin, PluginManifest, PluginValidationResult: plugin contract validation before registration.
import {
AuditLogger,
PinoLogger,
RateLimiter,
RequestDeduplicator,
type BridgeProvider,
type PolicyRule,
type WalletAdapter,
} from '@stendar/core';
const logger = new PinoLogger({
component: 'runtime',
level: 'info',
});
const audit = new AuditLogger({
enabled: true,
filePath: './audit.jsonl',
});
const limiter = new RateLimiter({ maxTokens: 60, refillRateMs: 1_000, name: 'jupiter' });
const deduper = new RequestDeduplicator({ ttlMs: 2_000, maxEntries: 1_000 });
const advancedPolicies: PolicyRule[] = [
{ id: 'approval-large', type: 'require_approval', enabled: true, aboveAmount: 2_000, currency: 'USD' },
{ id: 'allow-protocols', type: 'protocol_allowlist', enabled: true, allowedProtocols: ['jupiter', 'lifi'] },
{ id: 'portfolio-cap', type: 'portfolio_exposure', enabled: true, scope: 'protocol', maxExposurePercent: 35 },
{ id: 'max-dd', type: 'max_drawdown', enabled: true, maxDrawdownPercent: 15 },
];
async function quoteBridge(provider: BridgeProvider, wallet: WalletAdapter): Promise<void> {
const quote = await provider.getBridgeQuote({
fromChain: 'ethereum-mainnet',
toChain: 'solana-mainnet',
fromToken: 'USDC',
toToken: 'USDC',
amount: 1_000_000n,
fromAddress: await wallet.getAddress(),
});
console.log(quote.provider, quote.toAmount.toString());
}
await limiter.acquire();
await deduper.dedupe('price:sol:usd', async () => 123.45);
await audit.verify();

For runnable end-to-end flows, see Examples, Runtime lifecycle, and Policies.