The battle-tested standard library for writing reactive Solidity handlers on Somnia.
Similar to what @openzeppelin/contracts is for access control and tokens, @somnia-react/autonomous specializes in secure, gas-efficient, composable patterns for on-chain reactive logic.
- π‘οΈ Battle-Tested Patterns β Reentrancy guards, gas limit checks, safe external calls
- β‘ Gas Optimized β <250k gas per
_onEventcall in happy path - π§© Composable β Mix & match handlers, inherit & customize
- π Zero to Hero β Deploy reactive handlers in 5 minutes with tutorials
- π Type-Safe SDK β Full TypeScript support with abitype for contracts
- π§ͺ 85%+ Test Coverage β Foundry + Hardhat comprehensive tests
- π Excellent Docs β VitePress site with examples & security guides
npm install @somnia-react/autonomous
# or
pnpm add @somnia-react/autonomous// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@somnia-react/autonomous/handlers/AutoCompoundHandler.sol";
contract MyAutoCompoundVault is AutoCompoundHandler {
constructor(
address _compoundToken,
address _rewardToken,
address _vault
) {
// Initialize with your parameters
}
function compound() external override {
// Your auto-compound logic
}
}Deploy & subscribe in TypeScript:
import {
deployAutoCompoundHandler,
createAutoCompoundSubscription,
} from "@somnia-react/autonomous";
const handler = await deployAutoCompoundHandler({
compoundToken: "0x...",
rewardToken: "0x...",
vaultAddress: "0x...",
});
const subscription = createAutoCompoundSubscription({
handlerAddress: handler.address,
targetVault: "0x...",
eventSignature: "RewardAdded(indexed address,uint256)",
});
console.log("Deployed & subscribed:", handler.address);| Handler | Purpose | Use Case |
|---|---|---|
BaseReactiveHandler |
Foundation with safety | Inherit for custom handlers |
AutoCompoundHandler |
Auto-compound rewards | Yield farming vaults |
LiquidationGuardian |
Monitor & liquidate | Lending protocols |
CronLikeScheduler |
Time-based triggers | Scheduled execution |
EventFilterThrottle |
Debounce events | Noisy on-chain streams |
CrossCallOrchestrator |
Chain calls atomically | Multi-step automation |
UpgradeableReactiveProxy |
UUPS upgradeable base | Future-proof contracts |
- Getting Started β Install, setup, first handler
- Handlers Guide β Deep dive into each handler
- SDK Documentation β TypeScript SDK for deployment & subscriptions
- Deployment API β Deploy all 6 handler types
- Subscriptions API β Create event subscriptions
- Decoders API β Parse handler events
- API Reference β Complete type definitions
- Security Best Practices β Gas limits, oracles, reentrancy
- API Reference β Full Solidity & TypeScript docs
- Examples β Production-ready code snippets
Live Docs: https://somnia-react.github.io/autonomous
packages/
βββ contracts/ # Solidity handlers (Foundry + Hardhat)
βββ sdk/ # TypeScript deployment & helpers (Vitest)
βββ docs/ # VitePress documentation site
- Node.js β₯18.0.0
- pnpm β₯8.0.0
- Foundry (for Solidity development)
pnpm install
pnpm build
pnpm testpnpm lint
pnpm formatSDK Tests: 88/88 passing β
- 31 subscription tests (fluent API, validators, factory functions)
- 21 integration tests (end-to-end workflows, cross-module testing)
- 18 event decoder tests (all event type parsing)
- 18 deployment tests (all handler deployment functions)
Code Coverage
All files: 85.31% statements | 66.66% branches | 93.87% functions
Decoders: 95.94% statements | 59.25% branches | 100% functions
Subscriptions: 91.46% statements | 82.89% branches | 95.45% functions
Deployment: 71.39% statements | 47.16% branches | 84.61% functions
Solidity Tests: 30+ Foundry tests β
- BaseReactiveHandler tests
- Handler implementation tests
- Integration tests
# All tests
pnpm test
# SDK tests only
cd packages/sdk
pnpm test
# With coverage
pnpm test:coverage
# Solidity tests
cd packages/contracts
pnpm test- Type Safety: Full TypeScript with strict mode
- Linting: ESLint + Prettier for code consistency
- Security: No vulnerable dependencies
- Documentation: Comprehensive inline docs + 4 doc files + README
- SDK Build: Compiles to ESM + CJS in <200ms
- Handler Deployment: <50ms average
- Event Decoding: <1ms per event (v8 decoded logs)
- Bundle Size: ~15KB minified + gzipped
pnpm docs:dev # Live server at localhost:5173
pnpm docs:build # Static site in docs/.vitepress/distWe welcome contributions! Please see CONTRIBUTING.md for guidelines.
For security concerns, please email security@somnia-react.dev or open a private GitHub security advisory.
MIT License β see LICENSE
- v0.1.0 (MVP) β Base + 4 handlers + SDK + docs
- v0.2.0 β Upgradeable patterns, advanced filters
- v1.0.0 β Community handlers, audit, ecosystem promotion
- @somnia-chain/reactivity-contracts β Official Somnia reactivity SDK
- @openzeppelin/contracts β Industry-standard smart contract library
- Somnia Docs β On-chain reactivity guide
Built with β€οΈ for the Somnia ecosystem.